From 0317ac288355fd17282735cbe273c753c0bd9f25 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Fri, 15 Apr 2016 14:58:18 -0300 Subject: [PATCH] Adapts InVesalius to run with VTK6 (#35) --- .gitignore | 4 ++++ invesalius/data/converters.py | 10 +++++----- invesalius/data/cursor_actors.py | 22 +++++++++++----------- invesalius/data/measures.py | 12 +++++++----- invesalius/data/polydata_utils.py | 27 ++++++++++++--------------- invesalius/data/slice_.py | 22 +++++++++++----------- invesalius/data/slice_data.py | 2 +- invesalius/data/styles.py | 12 ++++++++---- invesalius/data/surface.py | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------- invesalius/data/surface_process.py | 10 +++++----- invesalius/data/viewer_slice.py | 9 +++++---- invesalius/data/viewer_volume.py | 7 ++++--- invesalius/data/volume.py | 12 ++++++------ invesalius/data/watershed_process.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------- invesalius/gui/dicom_preview_panel.py | 4 ++-- invesalius/reader/dicom_reader.py | 6 +++--- 16 files changed, 190 insertions(+), 173 deletions(-) diff --git a/.gitignore b/.gitignore index 8aa7a97..d1b6ccc 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,7 @@ invesalius/reader/*.pyc *.so tags *.c + +build +*.patch +*.tgz diff --git a/invesalius/data/converters.py b/invesalius/data/converters.py index c9c6b24..93df985 100644 --- a/invesalius/data/converters.py +++ b/invesalius/data/converters.py @@ -43,16 +43,16 @@ def to_vtk(n_array, spacing, slice_number, orientation): image = vtk.vtkImageData() image.SetOrigin(0, 0, 0) image.SetSpacing(spacing) - image.SetNumberOfScalarComponents(1) image.SetDimensions(dx, dy, dz) + # SetNumberOfScalarComponents and SetScalrType were replaced by + # AllocateScalars + # image.SetNumberOfScalarComponents(1) + # image.SetScalarType(numpy_support.get_vtk_array_type(n_array.dtype)) + image.AllocateScalars(numpy_support.get_vtk_array_type(n_array.dtype), 1) image.SetExtent(extent) - image.SetScalarType(numpy_support.get_vtk_array_type(n_array.dtype)) - image.AllocateScalars() image.GetPointData().SetScalars(v_image) - image.Update() image_copy = vtk.vtkImageData() image_copy.DeepCopy(image) - image_copy.Update() return image_copy diff --git a/invesalius/data/cursor_actors.py b/invesalius/data/cursor_actors.py index 657de4b..d8f765c 100644 --- a/invesalius/data/cursor_actors.py +++ b/invesalius/data/cursor_actors.py @@ -55,19 +55,19 @@ def to_vtk(n_array, spacing, slice_number, orientation): image = vtk.vtkImageData() image.SetOrigin(0, 0, 0) image.SetSpacing(spacing) - image.SetNumberOfScalarComponents(1) image.SetDimensions(dx, dy, dz) image.SetExtent(extent) - image.SetScalarType(numpy_support.get_vtk_array_type(n_array.dtype)) - image.AllocateScalars() - image.Update() + # image.SetNumberOfScalarComponents(1) + # image.SetScalarType(numpy_support.get_vtk_array_type(n_array.dtype)) + image.AllocateScalars(numpy_support.get_vtk_array_type(n_array.dtype), 1) + # image.Update() image.GetCellData().SetScalars(v_image) image.GetPointData().SetScalars(v_image) - image.Update() + # image.Update() image_copy = vtk.vtkImageData() image_copy.DeepCopy(image) - image_copy.Update() + # image_copy.Update() return image_copy @@ -224,7 +224,7 @@ class CursorBase(object): img_colours_mask = vtk.vtkImageMapToColors() img_colours_mask.SetLookupTable(lut_mask) img_colours_mask.SetOutputFormatToRGBA() - img_colours_mask.SetInput(imagedata) + img_colours_mask.SetInputData(imagedata) img_colours_mask.Update() return img_colours_mask.GetOutput() @@ -274,12 +274,12 @@ class CursorCircle(CursorBase): circle_ci = self._set_colour(circle_i, self.colour) if self.mapper is None: - self.actor.SetInput(circle_ci) + self.actor.SetInputData(circle_ci) self.actor.InterpolateOff() self.actor.PickableOff() self.actor.SetDisplayExtent(circle_ci.GetExtent()) else: - self.mapper.SetInput(circle_ci) + self.mapper.SetInputData(circle_ci) self.mapper.BorderOn() self.mapper.SetOrientation(ORIENTATION[self.orientation]) @@ -347,12 +347,12 @@ class CursorRectangle(CursorBase): rectangle_ci = self._set_colour(rectangle_i, self.colour) if self.mapper is None: - self.actor.SetInput(rectangle_ci) + self.actor.SetInputData(rectangle_ci) self.actor.InterpolateOff() self.actor.PickableOff() self.actor.SetDisplayExtent(rectangle_ci.GetExtent()) else: - self.mapper.SetInput(rectangle_ci) + self.mapper.SetInputData(rectangle_ci) self.mapper.BorderOn() self.mapper.SetOrientation(ORIENTATION[self.orientation]) diff --git a/invesalius/data/measures.py b/invesalius/data/measures.py index 4a65928..c0d0692 100644 --- a/invesalius/data/measures.py +++ b/invesalius/data/measures.py @@ -341,8 +341,8 @@ class CrossPointRepresentation(object): sv.SetPoint2(p4) cruz = vtk.vtkAppendPolyData() - cruz.AddInput(sv.GetOutput()) - cruz.AddInput(sh.GetOutput()) + cruz.AddInputData(sv.GetOutput()) + cruz.AddInputData(sh.GetOutput()) c = vtk.vtkCoordinate() c.SetCoordinateSystemToWorld() @@ -563,9 +563,11 @@ class AngularMeasure(object): arc = self.DrawArc() line = vtk.vtkAppendPolyData() - line.AddInput(line1.GetOutput()) - line.AddInput(line2.GetOutput()) - line.AddInput(arc.GetOutput()) + line.AddInputConnection(line1.GetOutputPort()) + line.AddInputConnection(line2.GetOutputPort()) + line.AddInputConnection(arc.GetOutputPort()) + + print line c = vtk.vtkCoordinate() c.SetCoordinateSystemToWorld() diff --git a/invesalius/data/polydata_utils.py b/invesalius/data/polydata_utils.py index 9732580..0295c97 100644 --- a/invesalius/data/polydata_utils.py +++ b/invesalius/data/polydata_utils.py @@ -36,7 +36,7 @@ def ApplyDecimationFilter(polydata, reduction_factor): # Important: vtkQuadricDecimation presented better results than # vtkDecimatePro decimation = vtk.vtkQuadricDecimation() - decimation.SetInput(polydata) + decimation.SetInputData(polydata) decimation.SetTargetReduction(reduction_factor) decimation.GetOutput().ReleaseDataFlagOn() decimation.AddObserver("ProgressEvent", lambda obj, evt: @@ -48,7 +48,7 @@ def ApplySmoothFilter(polydata, iterations, relaxation_factor): Smooth given vtkPolyData surface, based on iteration and relaxation_factor. """ smoother = vtk.vtkSmoothPolyDataFilter() - smoother.SetInput(polydata) + smoother.SetInputData(polydata) smoother.SetNumberOfIterations(iterations) smoother.SetFeatureAngle(80) smoother.SetRelaxationFactor(relaxation_factor) @@ -69,7 +69,7 @@ def FillSurfaceHole(polydata): # Filter used to detect and fill holes. Only fill print "Filling polydata" filled_polydata = vtk.vtkFillHolesFilter() - filled_polydata.SetInput(polydata) + filled_polydata.SetInputData(polydata) filled_polydata.SetHoleSize(500) return filled_polydata.GetOutput() @@ -79,7 +79,7 @@ def CalculateSurfaceVolume(polydata): """ # Filter used to calculate volume and area from a polydata measured_polydata = vtk.vtkMassProperties() - measured_polydata.SetInput(polydata) + measured_polydata.SetInputData(polydata) return measured_polydata.GetVolume() def CalculateSurfaceArea(polydata): @@ -88,7 +88,7 @@ def CalculateSurfaceArea(polydata): """ # Filter used to calculate volume and area from a polydata measured_polydata = vtk.vtkMassProperties() - measured_polydata.SetInput(polydata) + measured_polydata.SetInputData(polydata) return measured_polydata.GetSurfaceArea() def Merge(polydata_list): @@ -96,11 +96,11 @@ def Merge(polydata_list): for polydata in polydata_list: triangle = vtk.vtkTriangleFilter() - triangle.SetInput(polydata) - append.AddInput(triangle.GetOutput()) + triangle.SetInputData(polydata) + append.AddInputData(triangle.GetOutput()) clean = vtk.vtkCleanPolyData() - clean.SetInput(append.GetOutput()) + clean.SetInputData(append.GetOutput()) return append.GetOutput() @@ -112,7 +112,7 @@ def Export(polydata, filename, bin=False): writer.SetDataModeToBinary() else: writer.SetDataModeToAscii() - writer.SetInput(polydata) + writer.SetInputData(polydata) writer.Write() def Import(filename): @@ -130,7 +130,7 @@ def JoinSeedsParts(polydata, point_id_list): from vtkPolyData. """ conn = vtk.vtkPolyDataConnectivityFilter() - conn.SetInput(polydata) + conn.SetInputData(polydata) conn.SetExtractionModeToPointSeededRegions() UpdateProgress = vu.ShowProgress(1 + len(point_id_list)) pos = 1 @@ -145,7 +145,6 @@ def JoinSeedsParts(polydata, point_id_list): result = vtk.vtkPolyData() result.DeepCopy(conn.GetOutput()) - result.Update() return result def SelectLargestPart(polydata): @@ -153,7 +152,7 @@ def SelectLargestPart(polydata): """ UpdateProgress = vu.ShowProgress(1) conn = vtk.vtkPolyDataConnectivityFilter() - conn.SetInput(polydata) + conn.SetInputData(polydata) conn.SetExtractionModeToLargestRegion() conn.AddObserver("ProgressEvent", lambda obj, evt: UpdateProgress(conn, "Getting largest part...")) @@ -161,14 +160,13 @@ def SelectLargestPart(polydata): result = vtk.vtkPolyData() result.DeepCopy(conn.GetOutput()) - result.Update() return result def SplitDisconectedParts(polydata): """ """ conn = vtk.vtkPolyDataConnectivityFilter() - conn.SetInput(polydata) + conn.SetInputData(polydata) conn.SetExtractionModeToAllRegions() conn.Update() @@ -191,7 +189,6 @@ def SplitDisconectedParts(polydata): p = vtk.vtkPolyData() p.DeepCopy(conn.GetOutput()) - p.Update() polydata_collection.append(p) if progress: diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index 4101cbb..318de5e 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -964,18 +964,18 @@ class Slice(object): img = self.buffer_slices[orientation].vtk_image original_orientation = Project().original_orientation cast = vtk.vtkImageCast() - cast.SetInput(img) + cast.SetInputData(img) cast.SetOutputScalarTypeToDouble() cast.ClampOverflowOn() cast.Update() #if (original_orientation == const.AXIAL): flip = vtk.vtkImageFlip() - flip.SetInput(cast.GetOutput()) + flip.SetInputConnection(cast.GetOutputPort()) flip.SetFilteredAxis(1) flip.FlipAboutOriginOn() flip.Update() - widget.SetInput(flip.GetOutput()) + widget.SetInputConnection(flip.GetOutputPort()) #else: #widget.SetInput(cast.GetOutput()) @@ -1044,7 +1044,7 @@ class Slice(object): i += 1 colorer = vtk.vtkImageMapToColors() - colorer.SetInput(image) + colorer.SetInputData(image) colorer.SetLookupTable(lut) colorer.SetOutputFormatToRGB() colorer.Update() @@ -1059,12 +1059,12 @@ class Slice(object): colorer = vtk.vtkImageMapToColors() colorer.SetLookupTable(lut) - colorer.SetInput(image) + colorer.SetInputData(image) colorer.SetOutputFormatToRGB() colorer.Update() else: colorer = vtk.vtkImageMapToWindowLevelColors() - colorer.SetInput(image) + colorer.SetInputData(image) colorer.SetWindow(self.window_width) colorer.SetLevel(self.window_level) colorer.SetOutputFormatToRGB() @@ -1148,7 +1148,7 @@ class Slice(object): img_colours_bg = vtk.vtkImageMapToColors() img_colours_bg.SetOutputFormatToRGB() img_colours_bg.SetLookupTable(lut_bg) - img_colours_bg.SetInput(imagedata) + img_colours_bg.SetInputData(imagedata) img_colours_bg.Update() return img_colours_bg.GetOutput() @@ -1179,7 +1179,7 @@ class Slice(object): img_colours_mask = vtk.vtkImageMapToColors() img_colours_mask.SetLookupTable(lut_mask) img_colours_mask.SetOutputFormatToRGBA() - img_colours_mask.SetInput(imagedata) + img_colours_mask.SetInputData(imagedata) img_colours_mask.Update() # self.img_colours_mask = img_colours_mask @@ -1211,7 +1211,7 @@ class Slice(object): img_colours_mask = vtk.vtkImageMapToColors() img_colours_mask.SetLookupTable(lut_mask) img_colours_mask.SetOutputFormatToRGBA() - img_colours_mask.SetInput(imagedata) + img_colours_mask.SetInputData(imagedata) img_colours_mask.Update() # self.img_colours_mask = img_colours_mask @@ -1225,8 +1225,8 @@ class Slice(object): blend_imagedata.SetBlendModeToNormal() # blend_imagedata.SetOpacity(0, 1.0) blend_imagedata.SetOpacity(1, 0.8) - blend_imagedata.SetInput(imagedata) - blend_imagedata.AddInput(mask) + blend_imagedata.SetInputData(imagedata) + blend_imagedata.AddInputData(mask) blend_imagedata.Update() return blend_imagedata.GetOutput() diff --git a/invesalius/data/slice_data.py b/invesalius/data/slice_data.py index 55da72b..92d2929 100644 --- a/invesalius/data/slice_data.py +++ b/invesalius/data/slice_data.py @@ -55,7 +55,7 @@ class SliceData(object): def __create_line_actor(self, line): line_mapper = vtk.vtkPolyDataMapper2D() - line_mapper.SetInput(line.GetOutput()) + line_mapper.SetInputConnection(line.GetOutputPort()) line_actor = vtk.vtkActor2D() line_actor.SetMapper(line_mapper) diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index 4c7c13a..b258afc 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -59,10 +59,14 @@ WATERSHED_OPERATIONS = {_("Erase"): BRUSH_ERASE, _("Background"): BRUSH_BACKGROUND,} def get_LUT_value(data, window, level): - return np.piecewise(data, - [data <= (level - 0.5 - (window-1)/2), - data > (level - 0.5 + (window-1)/2)], - [0, window, lambda data: ((data - (level - 0.5))/(window-1) + 0.5)*(window)]) + shape = data.shape + data_ = data.ravel() + data = np.piecewise(data_, + [data_ <= (level - 0.5 - (window-1)/2), + data_ > (level - 0.5 + (window-1)/2)], + [0, window, lambda data_: ((data_ - (level - 0.5))/(window-1) + 0.5)*(window)]) + data.shape = shape + return data class BaseImageInteractorStyle(vtk.vtkInteractorStyleImage): def __init__(self, viewer): diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index 138d943..762e9fb 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -42,6 +42,8 @@ try: except ImportError: import data.ca_smoothing as ca_smoothing +# TODO: Verificar ReleaseDataFlagOn and SetSource + class Surface(): """ Represent both vtkPolyData and associated properties. @@ -240,12 +242,13 @@ class SurfaceManager(): name=None, colour=None, transparency=None, volume=None): normals = vtk.vtkPolyDataNormals() - normals.SetInput(polydata) + normals.SetInputData(polydata) normals.SetFeatureAngle(80) normals.AutoOrientNormalsOn() + normals.Update() mapper = vtk.vtkPolyDataMapper() - mapper.SetInput(normals.GetOutput()) + mapper.SetInputData(normals.GetOutput()) mapper.ScalarVisibilityOff() mapper.ImmediateModeRenderingOn() # improve performance @@ -289,11 +292,12 @@ class SurfaceManager(): # The following lines have to be here, otherwise all volumes disappear if not volume: triangle_filter = vtk.vtkTriangleFilter() - triangle_filter.SetInput(polydata) + triangle_filter.SetInputData(polydata) triangle_filter.Update() measured_polydata = vtk.vtkMassProperties() - measured_polydata.SetInput(triangle_filter.GetOutput()) + measured_polydata.SetInputConnection(triangle_filter.GetOutputPort()) + measured_polydata.Update() volume = measured_polydata.GetVolume() surface.volume = volume print ">>>>", surface.volume @@ -338,19 +342,19 @@ class SurfaceManager(): surface = surface_dict[key] # Map polygonal data (vtkPolyData) to graphics primitives. normals = vtk.vtkPolyDataNormals() - normals.SetInput(surface.polydata) + normals.SetInputData(surface.polydata) normals.SetFeatureAngle(80) normals.AutoOrientNormalsOn() - normals.GetOutput().ReleaseDataFlagOn() + # normals.GetOutput().ReleaseDataFlagOn() # Improve performance stripper = vtk.vtkStripper() - stripper.SetInput(normals.GetOutput()) + stripper.SetInputData(normals.GetOutput()) stripper.PassThroughCellIdsOn() stripper.PassThroughPointIdsOn() mapper = vtk.vtkPolyDataMapper() - mapper.SetInput(stripper.GetOutput()) + mapper.SetInputData(stripper.GetOutput()) mapper.ScalarVisibilityOff() mapper.ImmediateModeRenderingOn() # improve performance @@ -490,30 +494,30 @@ class SurfaceManager(): break polydata_append = vtk.vtkAppendPolyData() - polydata_append.ReleaseDataFlagOn() + # polydata_append.ReleaseDataFlagOn() t = n_pieces while t: filename_polydata = q_out.get() reader = vtk.vtkXMLPolyDataReader() reader.SetFileName(filename_polydata) - reader.ReleaseDataFlagOn() + # reader.ReleaseDataFlagOn() reader.Update() - reader.GetOutput().ReleaseDataFlagOn() + # reader.GetOutput().ReleaseDataFlagOn() polydata = reader.GetOutput() - polydata.SetSource(None) + # polydata.SetSource(None) - polydata_append.AddInput(polydata) + polydata_append.AddInputData(polydata) del reader del polydata t -= 1 polydata_append.Update() - polydata_append.GetOutput().ReleaseDataFlagOn() + # polydata_append.GetOutput().ReleaseDataFlagOn() polydata = polydata_append.GetOutput() #polydata.Register(None) - polydata.SetSource(None) + # polydata.SetSource(None) del polydata_append if algorithm == 'ca_smoothing': @@ -521,31 +525,31 @@ class SurfaceManager(): normals_ref = weakref.ref(normals) normals_ref().AddObserver("ProgressEvent", lambda obj,evt: UpdateProgress(normals_ref(), _("Creating 3D surface..."))) - normals.SetInput(polydata) - normals.ReleaseDataFlagOn() + normals.SetInputData(polydata) + # normals.ReleaseDataFlagOn() #normals.SetFeatureAngle(80) #normals.AutoOrientNormalsOn() normals.ComputeCellNormalsOn() - normals.GetOutput().ReleaseDataFlagOn() + # normals.GetOutput().ReleaseDataFlagOn() normals.Update() del polydata polydata = normals.GetOutput() - polydata.SetSource(None) + # polydata.SetSource(None) del normals clean = vtk.vtkCleanPolyData() - clean.ReleaseDataFlagOn() - clean.GetOutput().ReleaseDataFlagOn() + # clean.ReleaseDataFlagOn() + # clean.GetOutput().ReleaseDataFlagOn() clean_ref = weakref.ref(clean) clean_ref().AddObserver("ProgressEvent", lambda obj,evt: UpdateProgress(clean_ref(), _("Creating 3D surface..."))) - clean.SetInput(polydata) + clean.SetInputData(polydata) clean.PointMergingOn() clean.Update() del polydata polydata = clean.GetOutput() - polydata.SetSource(None) + # polydata.SetSource(None) del clean try: @@ -556,7 +560,7 @@ class SurfaceManager(): options['max distance'], options['min weight'], options['steps']) - polydata.SetSource(None) + # polydata.SetSource(None) polydata.DebugOn() else: @@ -565,7 +569,7 @@ class SurfaceManager(): smoother_ref = weakref.ref(smoother) smoother_ref().AddObserver("ProgressEvent", lambda obj,evt: UpdateProgress(smoother_ref(), _("Creating 3D surface..."))) - smoother.SetInput(polydata) + smoother.SetInputData(polydata) smoother.SetNumberOfIterations(smooth_iterations) smoother.SetRelaxationFactor(smooth_relaxation_factor) smoother.SetFeatureAngle(80) @@ -575,21 +579,21 @@ class SurfaceManager(): smoother.FeatureEdgeSmoothingOn() #smoother.NormalizeCoordinatesOn() #smoother.NonManifoldSmoothingOn() - smoother.ReleaseDataFlagOn() - smoother.GetOutput().ReleaseDataFlagOn() + # smoother.ReleaseDataFlagOn() + # smoother.GetOutput().ReleaseDataFlagOn() smoother.Update() del polydata polydata = smoother.GetOutput() #polydata.Register(None) - polydata.SetSource(None) + # polydata.SetSource(None) del smoother if decimate_reduction: print "Decimating", decimate_reduction decimation = vtk.vtkQuadricDecimation() - decimation.ReleaseDataFlagOn() - decimation.SetInput(polydata) + # decimation.ReleaseDataFlagOn() + decimation.SetInputData(polydata) decimation.SetTargetReduction(decimate_reduction) decimation_ref = weakref.ref(decimation) decimation_ref().AddObserver("ProgressEvent", lambda obj,evt: @@ -597,31 +601,31 @@ class SurfaceManager(): #decimation.PreserveTopologyOn() #decimation.SplittingOff() #decimation.BoundaryVertexDeletionOff() - decimation.GetOutput().ReleaseDataFlagOn() + # decimation.GetOutput().ReleaseDataFlagOn() decimation.Update() del polydata polydata = decimation.GetOutput() #polydata.Register(None) - polydata.SetSource(None) + # polydata.SetSource(None) del decimation to_measure = polydata #to_measure.Register(None) - to_measure.SetSource(None) + # to_measure.SetSource(None) if keep_largest: conn = vtk.vtkPolyDataConnectivityFilter() - conn.SetInput(polydata) + conn.SetInputData(polydata) conn.SetExtractionModeToLargestRegion() conn_ref = weakref.ref(conn) conn_ref().AddObserver("ProgressEvent", lambda obj,evt: UpdateProgress(conn_ref(), _("Creating 3D surface..."))) conn.Update() - conn.GetOutput().ReleaseDataFlagOn() + # conn.GetOutput().ReleaseDataFlagOn() del polydata polydata = conn.GetOutput() #polydata.Register(None) - polydata.SetSource(None) + # polydata.SetSource(None) del conn #Filter used to detect and fill holes. Only fill boundary edges holes. @@ -629,59 +633,59 @@ class SurfaceManager(): #polydata_utils.FillSurfaceHole, we need to review this. if fill_holes: filled_polydata = vtk.vtkFillHolesFilter() - filled_polydata.ReleaseDataFlagOn() - filled_polydata.SetInput(polydata) + # filled_polydata.ReleaseDataFlagOn() + filled_polydata.SetInputData(polydata) filled_polydata.SetHoleSize(300) filled_polydata_ref = weakref.ref(filled_polydata) filled_polydata_ref().AddObserver("ProgressEvent", lambda obj,evt: UpdateProgress(filled_polydata_ref(), _("Creating 3D surface..."))) filled_polydata.Update() - filled_polydata.GetOutput().ReleaseDataFlagOn() + # filled_polydata.GetOutput().ReleaseDataFlagOn() del polydata polydata = filled_polydata.GetOutput() #polydata.Register(None) - polydata.SetSource(None) + # polydata.SetSource(None) polydata.DebugOn() del filled_polydata normals = vtk.vtkPolyDataNormals() - normals.ReleaseDataFlagOn() + # normals.ReleaseDataFlagOn() normals_ref = weakref.ref(normals) normals_ref().AddObserver("ProgressEvent", lambda obj,evt: UpdateProgress(normals_ref(), _("Creating 3D surface..."))) - normals.SetInput(polydata) + normals.SetInputData(polydata) normals.SetFeatureAngle(80) normals.AutoOrientNormalsOn() - normals.GetOutput().ReleaseDataFlagOn() + # normals.GetOutput().ReleaseDataFlagOn() normals.Update() del polydata polydata = normals.GetOutput() #polydata.Register(None) - polydata.SetSource(None) + # polydata.SetSource(None) del normals # Improve performance stripper = vtk.vtkStripper() - stripper.ReleaseDataFlagOn() + # stripper.ReleaseDataFlagOn() stripper_ref = weakref.ref(stripper) stripper_ref().AddObserver("ProgressEvent", lambda obj,evt: UpdateProgress(stripper_ref(), _("Creating 3D surface..."))) - stripper.SetInput(polydata) + stripper.SetInputData(polydata) stripper.PassThroughCellIdsOn() stripper.PassThroughPointIdsOn() - stripper.GetOutput().ReleaseDataFlagOn() + # stripper.GetOutput().ReleaseDataFlagOn() stripper.Update() del polydata polydata = stripper.GetOutput() #polydata.Register(None) - polydata.SetSource(None) + # polydata.SetSource(None) del stripper # Map polygonal data (vtkPolyData) to graphics primitives. mapper = vtk.vtkPolyDataMapper() - mapper.SetInput(polydata) + mapper.SetInputData(polydata) mapper.ScalarVisibilityOff() - mapper.ReleaseDataFlagOn() + # mapper.ReleaseDataFlagOn() mapper.ImmediateModeRenderingOn() # improve performance # Represent an object (geometry & properties) in the rendered scene @@ -720,8 +724,8 @@ class SurfaceManager(): # The following lines have to be here, otherwise all volumes disappear measured_polydata = vtk.vtkMassProperties() - measured_polydata.ReleaseDataFlagOn() - measured_polydata.SetInput(to_measure) + # measured_polydata.ReleaseDataFlagOn() + measured_polydata.SetInputData(to_measure) volume = float(measured_polydata.GetVolume()) surface.volume = volume self.last_surface_index = surface.index @@ -858,14 +862,15 @@ class SurfaceManager(): if filetype in (const.FILETYPE_STL, const.FILETYPE_PLY): # Invert normals normals = vtk.vtkPolyDataNormals() - normals.SetInput(polydata) + normals.SetInputData(polydata) normals.SetFeatureAngle(80) normals.AutoOrientNormalsOn() - normals.GetOutput().ReleaseDataFlagOn() + # normals.GetOutput().ReleaseDataFlagOn() normals.UpdateInformation() + normals.Update() polydata = normals.GetOutput() filename = filename.encode(wx.GetDefaultPyEncoding()) writer.SetFileName(filename) - writer.SetInput(polydata) + writer.SetInputData(polydata) writer.Write() diff --git a/invesalius/data/surface_process.py b/invesalius/data/surface_process.py index 6b1909f..63a1378 100644 --- a/invesalius/data/surface_process.py +++ b/invesalius/data/surface_process.py @@ -26,7 +26,7 @@ def ResampleImage3D(imagedata, value): resolution = (height/(extent[1]-extent[0])+1)*spacing[1] resample = vtk.vtkImageResample() - resample.SetInput(imagedata) + resample.SetInputData(imagedata) resample.SetAxisMagnificationFactor(0, resolution) resample.SetAxisMagnificationFactor(1, resolution) @@ -106,7 +106,7 @@ class SurfaceProcess(multiprocessing.Process): "AXIAL") gauss = vtk.vtkImageGaussianSmooth() - gauss.SetInput(image) + gauss.SetInputData(image) gauss.SetRadiusFactor(0.3) gauss.ReleaseDataFlagOn() gauss.Update() @@ -125,7 +125,7 @@ class SurfaceProcess(multiprocessing.Process): image = ResampleImage3D(image, self.imagedata_resolution) flip = vtk.vtkImageFlip() - flip.SetInput(image) + flip.SetInputData(image) flip.SetFilteredAxis(1) flip.FlipAboutOriginOn() flip.ReleaseDataFlagOn() @@ -148,7 +148,7 @@ class SurfaceProcess(multiprocessing.Process): #if self.mode == "CONTOUR": #print "Contour" contour = vtk.vtkContourFilter() - contour.SetInput(image) + contour.SetInputData(image) #contour.SetInput(flip.GetOutput()) if self.from_binary: contour.SetValue(0, 127) # initial threshold @@ -202,7 +202,7 @@ class SurfaceProcess(multiprocessing.Process): filename = tempfile.mktemp(suffix='_%s.vtp' % (self.pid)) writer = vtk.vtkXMLPolyDataWriter() - writer.SetInput(polydata) + writer.SetInputData(polydata) writer.SetFileName(filename) writer.Write() diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 2952694..3423ef1 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -753,6 +753,7 @@ class Viewer(wx.Panel): image = vtk.vtkRenderLargeImage() image.SetInput(ren) image.SetMagnification(1) + image.Update() image = image.GetOutput() @@ -769,8 +770,8 @@ class Viewer(wx.Panel): elif (filetype == const.FILETYPE_TIF): writer = vtk.vtkTIFFWriter() filename = "%s.tif"%filename.strip(".tif") - - writer.SetInput(image) + + writer.SetInputData(image) writer.SetFileName(filename) writer.Write() @@ -919,7 +920,7 @@ class Viewer(wx.Panel): c.SetCoordinateSystemToWorld() cross_mapper = vtk.vtkPolyDataMapper() - cross_mapper.SetInput(cross.GetOutput()) + cross_mapper.SetInputConnection(cross.GetOutputPort()) #cross_mapper.SetTransformCoordinate(c) p = vtk.vtkProperty() @@ -1176,7 +1177,7 @@ class Viewer(wx.Panel): border_size = self.mip_ctrls.border_spin.GetValue() image = self.slice_.GetSlices(self.orientation, index, self.number_slices, inverted, border_size) - self.slice_data.actor.SetInput(image) + self.slice_data.actor.SetInputData(image) for actor in self.actors_by_slice_number.get(self.slice_data.number, []): self.slice_data.renderer.RemoveActor(actor) for actor in self.actors_by_slice_number.get(index, []): diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index 0fec3e8..cee8553 100755 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -318,6 +318,7 @@ class Viewer(wx.Panel): image = vtk.vtkRenderLargeImage() image.SetInput(self.ren) image.SetMagnification(1) + image.Update() image = image.GetOutput() @@ -333,12 +334,12 @@ class Viewer(wx.Panel): elif (filetype == const.FILETYPE_TIF): writer = vtk.vtkTIFFWriter() filename = "%s.tif"%filename.strip(".tif") - - writer.SetInput(image) + + writer.SetInputData(image) writer.SetFileName(filename) writer.Write() Publisher.sendMessage('End busy cursor') - + def OnCloseProject(self, pubsub_evt): if self.raycasting_volume: self.raycasting_volume = False diff --git a/invesalius/data/volume.py b/invesalius/data/volume.py index 9935faf..3f2ee4d 100644 --- a/invesalius/data/volume.py +++ b/invesalius/data/volume.py @@ -224,7 +224,7 @@ class Volume(): # Update convolution filter original_imagedata = self.imagedata.GetOutput() imagedata = self.ApplyConvolution(original_imagedata) - self.volume_mapper.SetInput(imagedata) + self.volume_mapper.SetInputData(imagedata) # Update other information self.SetShading() @@ -484,7 +484,7 @@ class Volume(): update_progress = vtk_utils.ShowProgress(number_filters) for filter in self.config['convolutionFilters']: convolve = vtk.vtkImageConvolve() - convolve.SetInput(imagedata) + convolve.SetInputData(imagedata) convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]]) convolve.ReleaseDataFlagOn() @@ -530,7 +530,7 @@ class Volume(): update_progress= vtk_utils.ShowProgress(2 + number_filters) # Flip original vtkImageData flip = vtk.vtkImageFlip() - flip.SetInput(image) + flip.SetInputData(image) flip.SetFilteredAxis(1) flip.FlipAboutOriginOn() flip.ReleaseDataFlagOn() @@ -545,7 +545,7 @@ class Volume(): self.scale = scale cast = vtk.vtkImageShiftScale() - cast.SetInput(image) + cast.SetInputData(image) cast.SetShift(abs(scale[0])) cast.SetOutputScalarTypeToUnsignedShort() cast.ReleaseDataFlagOn() @@ -589,7 +589,7 @@ class Volume(): self.volume_mapper = volume_mapper self.SetTypeRaycasting() - volume_mapper.SetInput(image2) + volume_mapper.SetInputData(image2) # TODO: Look to this #volume_mapper_hw = vtk.vtkVolumeTextureMapper3D() @@ -657,7 +657,7 @@ class Volume(): image = self.image r = int(image.GetScalarRange()[1] - image.GetScalarRange()[0]) accumulate = vtk.vtkImageAccumulate() - accumulate.SetInput(image) + accumulate.SetInputData(image) accumulate.SetComponentExtent(0, r -1, 0, 0, 0, 0) accumulate.SetComponentOrigin(image.GetScalarRange()[0], 0, 0) accumulate.ReleaseDataFlagOn() diff --git a/invesalius/data/watershed_process.py b/invesalius/data/watershed_process.py index 41ff61b..af3de65 100644 --- a/invesalius/data/watershed_process.py +++ b/invesalius/data/watershed_process.py @@ -1,43 +1,46 @@ -import numpy as np -from scipy import ndimage -from scipy.ndimage import watershed_ift, generate_binary_structure -from skimage.morphology import watershed -from skimage import filter - - -def get_LUT_value(data, window, level): - return np.piecewise(data, - [data <= (level - 0.5 - (window-1)/2), - data > (level - 0.5 + (window-1)/2)], - [0, 255, lambda data: ((data - (level - 0.5))/(window-1) + 0.5)*(255-0)]) - - - -def do_watershed(image, markers, tfile, shape, bstruct, algorithm, mg_size, use_ww_wl, wl, ww, q): - mask = np.memmap(tfile, shape=shape, dtype='uint8', mode='r+') - - if use_ww_wl: - if algorithm == 'Watershed': - tmp_image = ndimage.morphological_gradient( - get_LUT_value(image, ww, wl).astype('uint16'), - mg_size) - tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) - else: - tmp_image = get_LUT_value(image, ww, wl).astype('uint16') - #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) - #tmp_image = ndimage.morphological_gradient( - #get_LUT_value(image, ww, wl).astype('uint16'), - #self.config.mg_size) - tmp_mask = watershed_ift(tmp_image, markers.astype('int16'), bstruct) - else: - if algorithm == 'Watershed': - tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), mg_size) - tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) - else: - tmp_image = (image - image.min()).astype('uint16') - #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) - #tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) - tmp_mask = watershed_ift(tmp_image, markers.astype('int8'), bstruct) - mask[:] = tmp_mask - mask.flush() - q.put(1) +import numpy as np +from scipy import ndimage +from scipy.ndimage import watershed_ift, generate_binary_structure +from skimage.morphology import watershed +from skimage import filter + + +def get_LUT_value(data, window, level): + shape = data.shape + data_ = data.ravel() + data = np.piecewise(data_, + [data_ <= (level - 0.5 - (window-1)/2), + data_ > (level - 0.5 + (window-1)/2)], + [0, window, lambda data_: ((data_ - (level - 0.5))/(window-1) + 0.5)*(window)]) + data.shape = shape + return data + + +def do_watershed(image, markers, tfile, shape, bstruct, algorithm, mg_size, use_ww_wl, wl, ww, q): + mask = np.memmap(tfile, shape=shape, dtype='uint8', mode='r+') + + if use_ww_wl: + if algorithm == 'Watershed': + tmp_image = ndimage.morphological_gradient( + get_LUT_value(image, ww, wl).astype('uint16'), + mg_size) + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) + else: + tmp_image = get_LUT_value(image, ww, wl).astype('uint16') + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) + #tmp_image = ndimage.morphological_gradient( + #get_LUT_value(image, ww, wl).astype('uint16'), + #self.config.mg_size) + tmp_mask = watershed_ift(tmp_image, markers.astype('int16'), bstruct) + else: + if algorithm == 'Watershed': + tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), mg_size) + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) + else: + tmp_image = (image - image.min()).astype('uint16') + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) + #tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) + tmp_mask = watershed_ift(tmp_image, markers.astype('int8'), bstruct) + mask[:] = tmp_mask + mask.flush() + q.put(1) diff --git a/invesalius/gui/dicom_preview_panel.py b/invesalius/gui/dicom_preview_panel.py index 10cb4d5..3504db4 100644 --- a/invesalius/gui/dicom_preview_panel.py +++ b/invesalius/gui/dicom_preview_panel.py @@ -848,12 +848,12 @@ class SingleImagePreview(wx.Panel): window_level = dicom.image.level window_width = dicom.image.window colorer = vtk.vtkImageMapToWindowLevelColors() - colorer.SetInput(rdicom.GetOutput()) + colorer.SetInputConnection(rdicom.GetOutputPort()) colorer.SetWindow(float(window_width)) colorer.SetLevel(float(window_level)) # PLOT IMAGE INTO VIEWER - self.actor.SetInput(colorer.GetOutput()) + self.actor.SetInputData(colorer.GetOutput()) self.renderer.ResetCamera() self.interactor.Render() diff --git a/invesalius/reader/dicom_reader.py b/invesalius/reader/dicom_reader.py index af3292d..c006d0f 100644 --- a/invesalius/reader/dicom_reader.py +++ b/invesalius/reader/dicom_reader.py @@ -195,14 +195,14 @@ class LoadDicom: window = 2000.0 colorer = vtk.vtkImageMapToWindowLevelColors() - colorer.SetInput(rvtk.GetOutput()) + colorer.SetInputConnection(rvtk.GetOutputPort()) colorer.SetWindow(float(window)) colorer.SetLevel(float(level)) colorer.SetOutputFormatToRGB() colorer.Update() resample = vtk.vtkImageResample() - resample.SetInput(colorer.GetOutput()) + resample.SetInputConnection(colorer.GetOutputPort()) resample.SetAxisMagnificationFactor ( 0, 0.25 ) resample.SetAxisMagnificationFactor ( 1, 0.25 ) resample.SetAxisMagnificationFactor ( 2, 1 ) @@ -211,7 +211,7 @@ class LoadDicom: thumbnail_path = tempfile.mktemp() write_png = vtk.vtkPNGWriter() - write_png.SetInput(resample.GetOutput()) + write_png.SetInputConnection(resample.GetOutputPort()) write_png.SetFileName(thumbnail_path) write_png.Write() -- libgit2 0.21.2