Commit 49ec5b18018f576f9437ffe5f98aa40e91bae63d

Authored by Thiago Franco de Moraes
1 parent 09915b7f
Exists in vtk6

generating surface with vtk6

invesalius/data/surface.py
... ... @@ -42,6 +42,8 @@ try:
42 42 except ImportError:
43 43 import data.ca_smoothing as ca_smoothing
44 44  
  45 +# TODO: Verificar ReleaseDataFlagOn and SetSource
  46 +
45 47 class Surface():
46 48 """
47 49 Represent both vtkPolyData and associated properties.
... ... @@ -240,12 +242,12 @@ class SurfaceManager():
240 242 name=None, colour=None,
241 243 transparency=None, volume=None):
242 244 normals = vtk.vtkPolyDataNormals()
243   - normals.SetInput(polydata)
  245 + normals.SetInputData(polydata)
244 246 normals.SetFeatureAngle(80)
245 247 normals.AutoOrientNormalsOn()
246 248  
247 249 mapper = vtk.vtkPolyDataMapper()
248   - mapper.SetInput(normals.GetOutput())
  250 + mapper.SetInputData(normals.GetOutput())
249 251 mapper.ScalarVisibilityOff()
250 252 mapper.ImmediateModeRenderingOn() # improve performance
251 253  
... ... @@ -289,11 +291,11 @@ class SurfaceManager():
289 291 # The following lines have to be here, otherwise all volumes disappear
290 292 if not volume:
291 293 triangle_filter = vtk.vtkTriangleFilter()
292   - triangle_filter.SetInput(polydata)
  294 + triangle_filter.SetInputData(polydata)
293 295 triangle_filter.Update()
294 296  
295 297 measured_polydata = vtk.vtkMassProperties()
296   - measured_polydata.SetInput(triangle_filter.GetOutput())
  298 + measured_polydata.SetInputData(triangle_filter.GetOutput())
297 299 volume = measured_polydata.GetVolume()
298 300 surface.volume = volume
299 301 print ">>>>", surface.volume
... ... @@ -338,19 +340,19 @@ class SurfaceManager():
338 340 surface = surface_dict[key]
339 341 # Map polygonal data (vtkPolyData) to graphics primitives.
340 342 normals = vtk.vtkPolyDataNormals()
341   - normals.SetInput(surface.polydata)
  343 + normals.SetInputData(surface.polydata)
342 344 normals.SetFeatureAngle(80)
343 345 normals.AutoOrientNormalsOn()
344   - normals.GetOutput().ReleaseDataFlagOn()
  346 + # normals.GetOutput().ReleaseDataFlagOn()
345 347  
346 348 # Improve performance
347 349 stripper = vtk.vtkStripper()
348   - stripper.SetInput(normals.GetOutput())
  350 + stripper.SetInputData(normals.GetOutput())
349 351 stripper.PassThroughCellIdsOn()
350 352 stripper.PassThroughPointIdsOn()
351 353  
352 354 mapper = vtk.vtkPolyDataMapper()
353   - mapper.SetInput(stripper.GetOutput())
  355 + mapper.SetInputData(stripper.GetOutput())
354 356 mapper.ScalarVisibilityOff()
355 357 mapper.ImmediateModeRenderingOn() # improve performance
356 358  
... ... @@ -490,30 +492,30 @@ class SurfaceManager():
490 492 break
491 493  
492 494 polydata_append = vtk.vtkAppendPolyData()
493   - polydata_append.ReleaseDataFlagOn()
  495 + # polydata_append.ReleaseDataFlagOn()
494 496 t = n_pieces
495 497 while t:
496 498 filename_polydata = q_out.get()
497 499  
498 500 reader = vtk.vtkXMLPolyDataReader()
499 501 reader.SetFileName(filename_polydata)
500   - reader.ReleaseDataFlagOn()
  502 + # reader.ReleaseDataFlagOn()
501 503 reader.Update()
502   - reader.GetOutput().ReleaseDataFlagOn()
  504 + # reader.GetOutput().ReleaseDataFlagOn()
503 505  
504 506 polydata = reader.GetOutput()
505   - polydata.SetSource(None)
  507 + # polydata.SetSource(None)
506 508  
507   - polydata_append.AddInput(polydata)
  509 + polydata_append.AddInputData(polydata)
508 510 del reader
509 511 del polydata
510 512 t -= 1
511 513  
512 514 polydata_append.Update()
513   - polydata_append.GetOutput().ReleaseDataFlagOn()
  515 + # polydata_append.GetOutput().ReleaseDataFlagOn()
514 516 polydata = polydata_append.GetOutput()
515 517 #polydata.Register(None)
516   - polydata.SetSource(None)
  518 + # polydata.SetSource(None)
517 519 del polydata_append
518 520  
519 521 if algorithm == 'ca_smoothing':
... ... @@ -521,31 +523,31 @@ class SurfaceManager():
521 523 normals_ref = weakref.ref(normals)
522 524 normals_ref().AddObserver("ProgressEvent", lambda obj,evt:
523 525 UpdateProgress(normals_ref(), _("Creating 3D surface...")))
524   - normals.SetInput(polydata)
525   - normals.ReleaseDataFlagOn()
  526 + normals.SetInputData(polydata)
  527 + # normals.ReleaseDataFlagOn()
526 528 #normals.SetFeatureAngle(80)
527 529 #normals.AutoOrientNormalsOn()
528 530 normals.ComputeCellNormalsOn()
529   - normals.GetOutput().ReleaseDataFlagOn()
  531 + # normals.GetOutput().ReleaseDataFlagOn()
530 532 normals.Update()
531 533 del polydata
532 534 polydata = normals.GetOutput()
533   - polydata.SetSource(None)
  535 + # polydata.SetSource(None)
534 536 del normals
535 537  
536 538 clean = vtk.vtkCleanPolyData()
537   - clean.ReleaseDataFlagOn()
538   - clean.GetOutput().ReleaseDataFlagOn()
  539 + # clean.ReleaseDataFlagOn()
  540 + # clean.GetOutput().ReleaseDataFlagOn()
539 541 clean_ref = weakref.ref(clean)
540 542 clean_ref().AddObserver("ProgressEvent", lambda obj,evt:
541 543 UpdateProgress(clean_ref(), _("Creating 3D surface...")))
542   - clean.SetInput(polydata)
  544 + clean.SetInputData(polydata)
543 545 clean.PointMergingOn()
544 546 clean.Update()
545 547  
546 548 del polydata
547 549 polydata = clean.GetOutput()
548   - polydata.SetSource(None)
  550 + # polydata.SetSource(None)
549 551 del clean
550 552  
551 553 try:
... ... @@ -556,7 +558,7 @@ class SurfaceManager():
556 558 options['max distance'],
557 559 options['min weight'],
558 560 options['steps'])
559   - polydata.SetSource(None)
  561 + # polydata.SetSource(None)
560 562 polydata.DebugOn()
561 563  
562 564 else:
... ... @@ -565,7 +567,7 @@ class SurfaceManager():
565 567 smoother_ref = weakref.ref(smoother)
566 568 smoother_ref().AddObserver("ProgressEvent", lambda obj,evt:
567 569 UpdateProgress(smoother_ref(), _("Creating 3D surface...")))
568   - smoother.SetInput(polydata)
  570 + smoother.SetInputData(polydata)
569 571 smoother.SetNumberOfIterations(smooth_iterations)
570 572 smoother.SetRelaxationFactor(smooth_relaxation_factor)
571 573 smoother.SetFeatureAngle(80)
... ... @@ -575,21 +577,21 @@ class SurfaceManager():
575 577 smoother.FeatureEdgeSmoothingOn()
576 578 #smoother.NormalizeCoordinatesOn()
577 579 #smoother.NonManifoldSmoothingOn()
578   - smoother.ReleaseDataFlagOn()
579   - smoother.GetOutput().ReleaseDataFlagOn()
  580 + # smoother.ReleaseDataFlagOn()
  581 + # smoother.GetOutput().ReleaseDataFlagOn()
580 582 smoother.Update()
581 583 del polydata
582 584 polydata = smoother.GetOutput()
583 585 #polydata.Register(None)
584   - polydata.SetSource(None)
  586 + # polydata.SetSource(None)
585 587 del smoother
586 588  
587 589  
588 590 if decimate_reduction:
589 591 print "Decimating", decimate_reduction
590 592 decimation = vtk.vtkQuadricDecimation()
591   - decimation.ReleaseDataFlagOn()
592   - decimation.SetInput(polydata)
  593 + # decimation.ReleaseDataFlagOn()
  594 + decimation.SetInputData(polydata)
593 595 decimation.SetTargetReduction(decimate_reduction)
594 596 decimation_ref = weakref.ref(decimation)
595 597 decimation_ref().AddObserver("ProgressEvent", lambda obj,evt:
... ... @@ -597,31 +599,31 @@ class SurfaceManager():
597 599 #decimation.PreserveTopologyOn()
598 600 #decimation.SplittingOff()
599 601 #decimation.BoundaryVertexDeletionOff()
600   - decimation.GetOutput().ReleaseDataFlagOn()
  602 + # decimation.GetOutput().ReleaseDataFlagOn()
601 603 decimation.Update()
602 604 del polydata
603 605 polydata = decimation.GetOutput()
604 606 #polydata.Register(None)
605   - polydata.SetSource(None)
  607 + # polydata.SetSource(None)
606 608 del decimation
607 609  
608 610 to_measure = polydata
609 611 #to_measure.Register(None)
610   - to_measure.SetSource(None)
  612 + # to_measure.SetSource(None)
611 613  
612 614 if keep_largest:
613 615 conn = vtk.vtkPolyDataConnectivityFilter()
614   - conn.SetInput(polydata)
  616 + conn.SetInputData(polydata)
615 617 conn.SetExtractionModeToLargestRegion()
616 618 conn_ref = weakref.ref(conn)
617 619 conn_ref().AddObserver("ProgressEvent", lambda obj,evt:
618 620 UpdateProgress(conn_ref(), _("Creating 3D surface...")))
619 621 conn.Update()
620   - conn.GetOutput().ReleaseDataFlagOn()
  622 + # conn.GetOutput().ReleaseDataFlagOn()
621 623 del polydata
622 624 polydata = conn.GetOutput()
623 625 #polydata.Register(None)
624   - polydata.SetSource(None)
  626 + # polydata.SetSource(None)
625 627 del conn
626 628  
627 629 #Filter used to detect and fill holes. Only fill boundary edges holes.
... ... @@ -629,59 +631,59 @@ class SurfaceManager():
629 631 #polydata_utils.FillSurfaceHole, we need to review this.
630 632 if fill_holes:
631 633 filled_polydata = vtk.vtkFillHolesFilter()
632   - filled_polydata.ReleaseDataFlagOn()
633   - filled_polydata.SetInput(polydata)
  634 + # filled_polydata.ReleaseDataFlagOn()
  635 + filled_polydata.SetInputData(polydata)
634 636 filled_polydata.SetHoleSize(300)
635 637 filled_polydata_ref = weakref.ref(filled_polydata)
636 638 filled_polydata_ref().AddObserver("ProgressEvent", lambda obj,evt:
637 639 UpdateProgress(filled_polydata_ref(), _("Creating 3D surface...")))
638 640 filled_polydata.Update()
639   - filled_polydata.GetOutput().ReleaseDataFlagOn()
  641 + # filled_polydata.GetOutput().ReleaseDataFlagOn()
640 642 del polydata
641 643 polydata = filled_polydata.GetOutput()
642 644 #polydata.Register(None)
643   - polydata.SetSource(None)
  645 + # polydata.SetSource(None)
644 646 polydata.DebugOn()
645 647 del filled_polydata
646 648  
647 649 normals = vtk.vtkPolyDataNormals()
648   - normals.ReleaseDataFlagOn()
  650 + # normals.ReleaseDataFlagOn()
649 651 normals_ref = weakref.ref(normals)
650 652 normals_ref().AddObserver("ProgressEvent", lambda obj,evt:
651 653 UpdateProgress(normals_ref(), _("Creating 3D surface...")))
652   - normals.SetInput(polydata)
  654 + normals.SetInputData(polydata)
653 655 normals.SetFeatureAngle(80)
654 656 normals.AutoOrientNormalsOn()
655   - normals.GetOutput().ReleaseDataFlagOn()
  657 + # normals.GetOutput().ReleaseDataFlagOn()
656 658 normals.Update()
657 659 del polydata
658 660 polydata = normals.GetOutput()
659 661 #polydata.Register(None)
660   - polydata.SetSource(None)
  662 + # polydata.SetSource(None)
661 663 del normals
662 664  
663 665 # Improve performance
664 666 stripper = vtk.vtkStripper()
665   - stripper.ReleaseDataFlagOn()
  667 + # stripper.ReleaseDataFlagOn()
666 668 stripper_ref = weakref.ref(stripper)
667 669 stripper_ref().AddObserver("ProgressEvent", lambda obj,evt:
668 670 UpdateProgress(stripper_ref(), _("Creating 3D surface...")))
669   - stripper.SetInput(polydata)
  671 + stripper.SetInputData(polydata)
670 672 stripper.PassThroughCellIdsOn()
671 673 stripper.PassThroughPointIdsOn()
672   - stripper.GetOutput().ReleaseDataFlagOn()
  674 + # stripper.GetOutput().ReleaseDataFlagOn()
673 675 stripper.Update()
674 676 del polydata
675 677 polydata = stripper.GetOutput()
676 678 #polydata.Register(None)
677   - polydata.SetSource(None)
  679 + # polydata.SetSource(None)
678 680 del stripper
679 681  
680 682 # Map polygonal data (vtkPolyData) to graphics primitives.
681 683 mapper = vtk.vtkPolyDataMapper()
682   - mapper.SetInput(polydata)
  684 + mapper.SetInputData(polydata)
683 685 mapper.ScalarVisibilityOff()
684   - mapper.ReleaseDataFlagOn()
  686 + # mapper.ReleaseDataFlagOn()
685 687 mapper.ImmediateModeRenderingOn() # improve performance
686 688  
687 689 # Represent an object (geometry & properties) in the rendered scene
... ... @@ -720,8 +722,8 @@ class SurfaceManager():
720 722  
721 723 # The following lines have to be here, otherwise all volumes disappear
722 724 measured_polydata = vtk.vtkMassProperties()
723   - measured_polydata.ReleaseDataFlagOn()
724   - measured_polydata.SetInput(to_measure)
  725 + # measured_polydata.ReleaseDataFlagOn()
  726 + measured_polydata.SetInputData(to_measure)
725 727 volume = float(measured_polydata.GetVolume())
726 728 surface.volume = volume
727 729 self.last_surface_index = surface.index
... ... @@ -858,14 +860,14 @@ class SurfaceManager():
858 860 if filetype in (const.FILETYPE_STL, const.FILETYPE_PLY):
859 861 # Invert normals
860 862 normals = vtk.vtkPolyDataNormals()
861   - normals.SetInput(polydata)
  863 + normals.SetInputData(polydata)
862 864 normals.SetFeatureAngle(80)
863 865 normals.AutoOrientNormalsOn()
864   - normals.GetOutput().ReleaseDataFlagOn()
  866 + # normals.GetOutput().ReleaseDataFlagOn()
865 867 normals.UpdateInformation()
866 868 polydata = normals.GetOutput()
867 869  
868 870 filename = filename.encode(wx.GetDefaultPyEncoding())
869 871 writer.SetFileName(filename)
870   - writer.SetInput(polydata)
  872 + writer.SetInputData(polydata)
871 873 writer.Write()
... ...
invesalius/data/surface_process.py
... ... @@ -26,7 +26,7 @@ def ResampleImage3D(imagedata, value):
26 26 resolution = (height/(extent[1]-extent[0])+1)*spacing[1]
27 27  
28 28 resample = vtk.vtkImageResample()
29   - resample.SetInput(imagedata)
  29 + resample.SetInputData(imagedata)
30 30 resample.SetAxisMagnificationFactor(0, resolution)
31 31 resample.SetAxisMagnificationFactor(1, resolution)
32 32  
... ... @@ -106,7 +106,7 @@ class SurfaceProcess(multiprocessing.Process):
106 106 "AXIAL")
107 107  
108 108 gauss = vtk.vtkImageGaussianSmooth()
109   - gauss.SetInput(image)
  109 + gauss.SetInputData(image)
110 110 gauss.SetRadiusFactor(0.3)
111 111 gauss.ReleaseDataFlagOn()
112 112 gauss.Update()
... ... @@ -125,7 +125,7 @@ class SurfaceProcess(multiprocessing.Process):
125 125 image = ResampleImage3D(image, self.imagedata_resolution)
126 126  
127 127 flip = vtk.vtkImageFlip()
128   - flip.SetInput(image)
  128 + flip.SetInputData(image)
129 129 flip.SetFilteredAxis(1)
130 130 flip.FlipAboutOriginOn()
131 131 flip.ReleaseDataFlagOn()
... ... @@ -148,7 +148,7 @@ class SurfaceProcess(multiprocessing.Process):
148 148 #if self.mode == "CONTOUR":
149 149 #print "Contour"
150 150 contour = vtk.vtkContourFilter()
151   - contour.SetInput(image)
  151 + contour.SetInputData(image)
152 152 #contour.SetInput(flip.GetOutput())
153 153 if self.from_binary:
154 154 contour.SetValue(0, 127) # initial threshold
... ... @@ -202,7 +202,7 @@ class SurfaceProcess(multiprocessing.Process):
202 202  
203 203 filename = tempfile.mktemp(suffix='_%s.vtp' % (self.pid))
204 204 writer = vtk.vtkXMLPolyDataWriter()
205   - writer.SetInput(polydata)
  205 + writer.SetInputData(polydata)
206 206 writer.SetFileName(filename)
207 207 writer.Write()
208 208  
... ...