Commit 0317ac288355fd17282735cbe273c753c0bd9f25
1 parent
c06ff6da
Exists in
master
and in
32 other branches
Adapts InVesalius to run with VTK6 (#35)
* Showing the slices * cursor was not displayed correctly * Watershed using vtk6 * generating surface with vtk6 * generating preview in vtk6 * Showing raycasting with vtk6 * Showing measures with vtk6 * saving project * Saving screenshots with vtk6 * Saving meshes with vtk6 * It was not showing surfaces created with greatest region, selected region and all regions filters
Showing
16 changed files
with
190 additions
and
173 deletions
Show diff stats
.gitignore
invesalius/data/converters.py
| ... | ... | @@ -43,16 +43,16 @@ def to_vtk(n_array, spacing, slice_number, orientation): |
| 43 | 43 | image = vtk.vtkImageData() |
| 44 | 44 | image.SetOrigin(0, 0, 0) |
| 45 | 45 | image.SetSpacing(spacing) |
| 46 | - image.SetNumberOfScalarComponents(1) | |
| 47 | 46 | image.SetDimensions(dx, dy, dz) |
| 47 | + # SetNumberOfScalarComponents and SetScalrType were replaced by | |
| 48 | + # AllocateScalars | |
| 49 | + # image.SetNumberOfScalarComponents(1) | |
| 50 | + # image.SetScalarType(numpy_support.get_vtk_array_type(n_array.dtype)) | |
| 51 | + image.AllocateScalars(numpy_support.get_vtk_array_type(n_array.dtype), 1) | |
| 48 | 52 | image.SetExtent(extent) |
| 49 | - image.SetScalarType(numpy_support.get_vtk_array_type(n_array.dtype)) | |
| 50 | - image.AllocateScalars() | |
| 51 | 53 | image.GetPointData().SetScalars(v_image) |
| 52 | - image.Update() | |
| 53 | 54 | |
| 54 | 55 | image_copy = vtk.vtkImageData() |
| 55 | 56 | image_copy.DeepCopy(image) |
| 56 | - image_copy.Update() | |
| 57 | 57 | |
| 58 | 58 | return image_copy | ... | ... |
invesalius/data/cursor_actors.py
| ... | ... | @@ -55,19 +55,19 @@ def to_vtk(n_array, spacing, slice_number, orientation): |
| 55 | 55 | image = vtk.vtkImageData() |
| 56 | 56 | image.SetOrigin(0, 0, 0) |
| 57 | 57 | image.SetSpacing(spacing) |
| 58 | - image.SetNumberOfScalarComponents(1) | |
| 59 | 58 | image.SetDimensions(dx, dy, dz) |
| 60 | 59 | image.SetExtent(extent) |
| 61 | - image.SetScalarType(numpy_support.get_vtk_array_type(n_array.dtype)) | |
| 62 | - image.AllocateScalars() | |
| 63 | - image.Update() | |
| 60 | + # image.SetNumberOfScalarComponents(1) | |
| 61 | + # image.SetScalarType(numpy_support.get_vtk_array_type(n_array.dtype)) | |
| 62 | + image.AllocateScalars(numpy_support.get_vtk_array_type(n_array.dtype), 1) | |
| 63 | + # image.Update() | |
| 64 | 64 | image.GetCellData().SetScalars(v_image) |
| 65 | 65 | image.GetPointData().SetScalars(v_image) |
| 66 | - image.Update() | |
| 66 | + # image.Update() | |
| 67 | 67 | |
| 68 | 68 | image_copy = vtk.vtkImageData() |
| 69 | 69 | image_copy.DeepCopy(image) |
| 70 | - image_copy.Update() | |
| 70 | + # image_copy.Update() | |
| 71 | 71 | |
| 72 | 72 | return image_copy |
| 73 | 73 | |
| ... | ... | @@ -224,7 +224,7 @@ class CursorBase(object): |
| 224 | 224 | img_colours_mask = vtk.vtkImageMapToColors() |
| 225 | 225 | img_colours_mask.SetLookupTable(lut_mask) |
| 226 | 226 | img_colours_mask.SetOutputFormatToRGBA() |
| 227 | - img_colours_mask.SetInput(imagedata) | |
| 227 | + img_colours_mask.SetInputData(imagedata) | |
| 228 | 228 | img_colours_mask.Update() |
| 229 | 229 | |
| 230 | 230 | return img_colours_mask.GetOutput() |
| ... | ... | @@ -274,12 +274,12 @@ class CursorCircle(CursorBase): |
| 274 | 274 | circle_ci = self._set_colour(circle_i, self.colour) |
| 275 | 275 | |
| 276 | 276 | if self.mapper is None: |
| 277 | - self.actor.SetInput(circle_ci) | |
| 277 | + self.actor.SetInputData(circle_ci) | |
| 278 | 278 | self.actor.InterpolateOff() |
| 279 | 279 | self.actor.PickableOff() |
| 280 | 280 | self.actor.SetDisplayExtent(circle_ci.GetExtent()) |
| 281 | 281 | else: |
| 282 | - self.mapper.SetInput(circle_ci) | |
| 282 | + self.mapper.SetInputData(circle_ci) | |
| 283 | 283 | self.mapper.BorderOn() |
| 284 | 284 | |
| 285 | 285 | self.mapper.SetOrientation(ORIENTATION[self.orientation]) |
| ... | ... | @@ -347,12 +347,12 @@ class CursorRectangle(CursorBase): |
| 347 | 347 | rectangle_ci = self._set_colour(rectangle_i, self.colour) |
| 348 | 348 | |
| 349 | 349 | if self.mapper is None: |
| 350 | - self.actor.SetInput(rectangle_ci) | |
| 350 | + self.actor.SetInputData(rectangle_ci) | |
| 351 | 351 | self.actor.InterpolateOff() |
| 352 | 352 | self.actor.PickableOff() |
| 353 | 353 | self.actor.SetDisplayExtent(rectangle_ci.GetExtent()) |
| 354 | 354 | else: |
| 355 | - self.mapper.SetInput(rectangle_ci) | |
| 355 | + self.mapper.SetInputData(rectangle_ci) | |
| 356 | 356 | self.mapper.BorderOn() |
| 357 | 357 | self.mapper.SetOrientation(ORIENTATION[self.orientation]) |
| 358 | 358 | ... | ... |
invesalius/data/measures.py
| ... | ... | @@ -341,8 +341,8 @@ class CrossPointRepresentation(object): |
| 341 | 341 | sv.SetPoint2(p4) |
| 342 | 342 | |
| 343 | 343 | cruz = vtk.vtkAppendPolyData() |
| 344 | - cruz.AddInput(sv.GetOutput()) | |
| 345 | - cruz.AddInput(sh.GetOutput()) | |
| 344 | + cruz.AddInputData(sv.GetOutput()) | |
| 345 | + cruz.AddInputData(sh.GetOutput()) | |
| 346 | 346 | |
| 347 | 347 | c = vtk.vtkCoordinate() |
| 348 | 348 | c.SetCoordinateSystemToWorld() |
| ... | ... | @@ -563,9 +563,11 @@ class AngularMeasure(object): |
| 563 | 563 | arc = self.DrawArc() |
| 564 | 564 | |
| 565 | 565 | line = vtk.vtkAppendPolyData() |
| 566 | - line.AddInput(line1.GetOutput()) | |
| 567 | - line.AddInput(line2.GetOutput()) | |
| 568 | - line.AddInput(arc.GetOutput()) | |
| 566 | + line.AddInputConnection(line1.GetOutputPort()) | |
| 567 | + line.AddInputConnection(line2.GetOutputPort()) | |
| 568 | + line.AddInputConnection(arc.GetOutputPort()) | |
| 569 | + | |
| 570 | + print line | |
| 569 | 571 | |
| 570 | 572 | c = vtk.vtkCoordinate() |
| 571 | 573 | c.SetCoordinateSystemToWorld() | ... | ... |
invesalius/data/polydata_utils.py
| ... | ... | @@ -36,7 +36,7 @@ def ApplyDecimationFilter(polydata, reduction_factor): |
| 36 | 36 | # Important: vtkQuadricDecimation presented better results than |
| 37 | 37 | # vtkDecimatePro |
| 38 | 38 | decimation = vtk.vtkQuadricDecimation() |
| 39 | - decimation.SetInput(polydata) | |
| 39 | + decimation.SetInputData(polydata) | |
| 40 | 40 | decimation.SetTargetReduction(reduction_factor) |
| 41 | 41 | decimation.GetOutput().ReleaseDataFlagOn() |
| 42 | 42 | decimation.AddObserver("ProgressEvent", lambda obj, evt: |
| ... | ... | @@ -48,7 +48,7 @@ def ApplySmoothFilter(polydata, iterations, relaxation_factor): |
| 48 | 48 | Smooth given vtkPolyData surface, based on iteration and relaxation_factor. |
| 49 | 49 | """ |
| 50 | 50 | smoother = vtk.vtkSmoothPolyDataFilter() |
| 51 | - smoother.SetInput(polydata) | |
| 51 | + smoother.SetInputData(polydata) | |
| 52 | 52 | smoother.SetNumberOfIterations(iterations) |
| 53 | 53 | smoother.SetFeatureAngle(80) |
| 54 | 54 | smoother.SetRelaxationFactor(relaxation_factor) |
| ... | ... | @@ -69,7 +69,7 @@ def FillSurfaceHole(polydata): |
| 69 | 69 | # Filter used to detect and fill holes. Only fill |
| 70 | 70 | print "Filling polydata" |
| 71 | 71 | filled_polydata = vtk.vtkFillHolesFilter() |
| 72 | - filled_polydata.SetInput(polydata) | |
| 72 | + filled_polydata.SetInputData(polydata) | |
| 73 | 73 | filled_polydata.SetHoleSize(500) |
| 74 | 74 | return filled_polydata.GetOutput() |
| 75 | 75 | |
| ... | ... | @@ -79,7 +79,7 @@ def CalculateSurfaceVolume(polydata): |
| 79 | 79 | """ |
| 80 | 80 | # Filter used to calculate volume and area from a polydata |
| 81 | 81 | measured_polydata = vtk.vtkMassProperties() |
| 82 | - measured_polydata.SetInput(polydata) | |
| 82 | + measured_polydata.SetInputData(polydata) | |
| 83 | 83 | return measured_polydata.GetVolume() |
| 84 | 84 | |
| 85 | 85 | def CalculateSurfaceArea(polydata): |
| ... | ... | @@ -88,7 +88,7 @@ def CalculateSurfaceArea(polydata): |
| 88 | 88 | """ |
| 89 | 89 | # Filter used to calculate volume and area from a polydata |
| 90 | 90 | measured_polydata = vtk.vtkMassProperties() |
| 91 | - measured_polydata.SetInput(polydata) | |
| 91 | + measured_polydata.SetInputData(polydata) | |
| 92 | 92 | return measured_polydata.GetSurfaceArea() |
| 93 | 93 | |
| 94 | 94 | def Merge(polydata_list): |
| ... | ... | @@ -96,11 +96,11 @@ def Merge(polydata_list): |
| 96 | 96 | |
| 97 | 97 | for polydata in polydata_list: |
| 98 | 98 | triangle = vtk.vtkTriangleFilter() |
| 99 | - triangle.SetInput(polydata) | |
| 100 | - append.AddInput(triangle.GetOutput()) | |
| 99 | + triangle.SetInputData(polydata) | |
| 100 | + append.AddInputData(triangle.GetOutput()) | |
| 101 | 101 | |
| 102 | 102 | clean = vtk.vtkCleanPolyData() |
| 103 | - clean.SetInput(append.GetOutput()) | |
| 103 | + clean.SetInputData(append.GetOutput()) | |
| 104 | 104 | |
| 105 | 105 | return append.GetOutput() |
| 106 | 106 | |
| ... | ... | @@ -112,7 +112,7 @@ def Export(polydata, filename, bin=False): |
| 112 | 112 | writer.SetDataModeToBinary() |
| 113 | 113 | else: |
| 114 | 114 | writer.SetDataModeToAscii() |
| 115 | - writer.SetInput(polydata) | |
| 115 | + writer.SetInputData(polydata) | |
| 116 | 116 | writer.Write() |
| 117 | 117 | |
| 118 | 118 | def Import(filename): |
| ... | ... | @@ -130,7 +130,7 @@ def JoinSeedsParts(polydata, point_id_list): |
| 130 | 130 | from vtkPolyData. |
| 131 | 131 | """ |
| 132 | 132 | conn = vtk.vtkPolyDataConnectivityFilter() |
| 133 | - conn.SetInput(polydata) | |
| 133 | + conn.SetInputData(polydata) | |
| 134 | 134 | conn.SetExtractionModeToPointSeededRegions() |
| 135 | 135 | UpdateProgress = vu.ShowProgress(1 + len(point_id_list)) |
| 136 | 136 | pos = 1 |
| ... | ... | @@ -145,7 +145,6 @@ def JoinSeedsParts(polydata, point_id_list): |
| 145 | 145 | |
| 146 | 146 | result = vtk.vtkPolyData() |
| 147 | 147 | result.DeepCopy(conn.GetOutput()) |
| 148 | - result.Update() | |
| 149 | 148 | return result |
| 150 | 149 | |
| 151 | 150 | def SelectLargestPart(polydata): |
| ... | ... | @@ -153,7 +152,7 @@ def SelectLargestPart(polydata): |
| 153 | 152 | """ |
| 154 | 153 | UpdateProgress = vu.ShowProgress(1) |
| 155 | 154 | conn = vtk.vtkPolyDataConnectivityFilter() |
| 156 | - conn.SetInput(polydata) | |
| 155 | + conn.SetInputData(polydata) | |
| 157 | 156 | conn.SetExtractionModeToLargestRegion() |
| 158 | 157 | conn.AddObserver("ProgressEvent", lambda obj, evt: |
| 159 | 158 | UpdateProgress(conn, "Getting largest part...")) |
| ... | ... | @@ -161,14 +160,13 @@ def SelectLargestPart(polydata): |
| 161 | 160 | |
| 162 | 161 | result = vtk.vtkPolyData() |
| 163 | 162 | result.DeepCopy(conn.GetOutput()) |
| 164 | - result.Update() | |
| 165 | 163 | return result |
| 166 | 164 | |
| 167 | 165 | def SplitDisconectedParts(polydata): |
| 168 | 166 | """ |
| 169 | 167 | """ |
| 170 | 168 | conn = vtk.vtkPolyDataConnectivityFilter() |
| 171 | - conn.SetInput(polydata) | |
| 169 | + conn.SetInputData(polydata) | |
| 172 | 170 | conn.SetExtractionModeToAllRegions() |
| 173 | 171 | conn.Update() |
| 174 | 172 | |
| ... | ... | @@ -191,7 +189,6 @@ def SplitDisconectedParts(polydata): |
| 191 | 189 | |
| 192 | 190 | p = vtk.vtkPolyData() |
| 193 | 191 | p.DeepCopy(conn.GetOutput()) |
| 194 | - p.Update() | |
| 195 | 192 | |
| 196 | 193 | polydata_collection.append(p) |
| 197 | 194 | if progress: | ... | ... |
invesalius/data/slice_.py
| ... | ... | @@ -964,18 +964,18 @@ class Slice(object): |
| 964 | 964 | img = self.buffer_slices[orientation].vtk_image |
| 965 | 965 | original_orientation = Project().original_orientation |
| 966 | 966 | cast = vtk.vtkImageCast() |
| 967 | - cast.SetInput(img) | |
| 967 | + cast.SetInputData(img) | |
| 968 | 968 | cast.SetOutputScalarTypeToDouble() |
| 969 | 969 | cast.ClampOverflowOn() |
| 970 | 970 | cast.Update() |
| 971 | 971 | |
| 972 | 972 | #if (original_orientation == const.AXIAL): |
| 973 | 973 | flip = vtk.vtkImageFlip() |
| 974 | - flip.SetInput(cast.GetOutput()) | |
| 974 | + flip.SetInputConnection(cast.GetOutputPort()) | |
| 975 | 975 | flip.SetFilteredAxis(1) |
| 976 | 976 | flip.FlipAboutOriginOn() |
| 977 | 977 | flip.Update() |
| 978 | - widget.SetInput(flip.GetOutput()) | |
| 978 | + widget.SetInputConnection(flip.GetOutputPort()) | |
| 979 | 979 | #else: |
| 980 | 980 | #widget.SetInput(cast.GetOutput()) |
| 981 | 981 | |
| ... | ... | @@ -1044,7 +1044,7 @@ class Slice(object): |
| 1044 | 1044 | i += 1 |
| 1045 | 1045 | |
| 1046 | 1046 | colorer = vtk.vtkImageMapToColors() |
| 1047 | - colorer.SetInput(image) | |
| 1047 | + colorer.SetInputData(image) | |
| 1048 | 1048 | colorer.SetLookupTable(lut) |
| 1049 | 1049 | colorer.SetOutputFormatToRGB() |
| 1050 | 1050 | colorer.Update() |
| ... | ... | @@ -1059,12 +1059,12 @@ class Slice(object): |
| 1059 | 1059 | |
| 1060 | 1060 | colorer = vtk.vtkImageMapToColors() |
| 1061 | 1061 | colorer.SetLookupTable(lut) |
| 1062 | - colorer.SetInput(image) | |
| 1062 | + colorer.SetInputData(image) | |
| 1063 | 1063 | colorer.SetOutputFormatToRGB() |
| 1064 | 1064 | colorer.Update() |
| 1065 | 1065 | else: |
| 1066 | 1066 | colorer = vtk.vtkImageMapToWindowLevelColors() |
| 1067 | - colorer.SetInput(image) | |
| 1067 | + colorer.SetInputData(image) | |
| 1068 | 1068 | colorer.SetWindow(self.window_width) |
| 1069 | 1069 | colorer.SetLevel(self.window_level) |
| 1070 | 1070 | colorer.SetOutputFormatToRGB() |
| ... | ... | @@ -1148,7 +1148,7 @@ class Slice(object): |
| 1148 | 1148 | img_colours_bg = vtk.vtkImageMapToColors() |
| 1149 | 1149 | img_colours_bg.SetOutputFormatToRGB() |
| 1150 | 1150 | img_colours_bg.SetLookupTable(lut_bg) |
| 1151 | - img_colours_bg.SetInput(imagedata) | |
| 1151 | + img_colours_bg.SetInputData(imagedata) | |
| 1152 | 1152 | img_colours_bg.Update() |
| 1153 | 1153 | |
| 1154 | 1154 | return img_colours_bg.GetOutput() |
| ... | ... | @@ -1179,7 +1179,7 @@ class Slice(object): |
| 1179 | 1179 | img_colours_mask = vtk.vtkImageMapToColors() |
| 1180 | 1180 | img_colours_mask.SetLookupTable(lut_mask) |
| 1181 | 1181 | img_colours_mask.SetOutputFormatToRGBA() |
| 1182 | - img_colours_mask.SetInput(imagedata) | |
| 1182 | + img_colours_mask.SetInputData(imagedata) | |
| 1183 | 1183 | img_colours_mask.Update() |
| 1184 | 1184 | # self.img_colours_mask = img_colours_mask |
| 1185 | 1185 | |
| ... | ... | @@ -1211,7 +1211,7 @@ class Slice(object): |
| 1211 | 1211 | img_colours_mask = vtk.vtkImageMapToColors() |
| 1212 | 1212 | img_colours_mask.SetLookupTable(lut_mask) |
| 1213 | 1213 | img_colours_mask.SetOutputFormatToRGBA() |
| 1214 | - img_colours_mask.SetInput(imagedata) | |
| 1214 | + img_colours_mask.SetInputData(imagedata) | |
| 1215 | 1215 | img_colours_mask.Update() |
| 1216 | 1216 | # self.img_colours_mask = img_colours_mask |
| 1217 | 1217 | |
| ... | ... | @@ -1225,8 +1225,8 @@ class Slice(object): |
| 1225 | 1225 | blend_imagedata.SetBlendModeToNormal() |
| 1226 | 1226 | # blend_imagedata.SetOpacity(0, 1.0) |
| 1227 | 1227 | blend_imagedata.SetOpacity(1, 0.8) |
| 1228 | - blend_imagedata.SetInput(imagedata) | |
| 1229 | - blend_imagedata.AddInput(mask) | |
| 1228 | + blend_imagedata.SetInputData(imagedata) | |
| 1229 | + blend_imagedata.AddInputData(mask) | |
| 1230 | 1230 | blend_imagedata.Update() |
| 1231 | 1231 | |
| 1232 | 1232 | return blend_imagedata.GetOutput() | ... | ... |
invesalius/data/slice_data.py
| ... | ... | @@ -55,7 +55,7 @@ class SliceData(object): |
| 55 | 55 | |
| 56 | 56 | def __create_line_actor(self, line): |
| 57 | 57 | line_mapper = vtk.vtkPolyDataMapper2D() |
| 58 | - line_mapper.SetInput(line.GetOutput()) | |
| 58 | + line_mapper.SetInputConnection(line.GetOutputPort()) | |
| 59 | 59 | |
| 60 | 60 | line_actor = vtk.vtkActor2D() |
| 61 | 61 | line_actor.SetMapper(line_mapper) | ... | ... |
invesalius/data/styles.py
| ... | ... | @@ -59,10 +59,14 @@ WATERSHED_OPERATIONS = {_("Erase"): BRUSH_ERASE, |
| 59 | 59 | _("Background"): BRUSH_BACKGROUND,} |
| 60 | 60 | |
| 61 | 61 | def get_LUT_value(data, window, level): |
| 62 | - return np.piecewise(data, | |
| 63 | - [data <= (level - 0.5 - (window-1)/2), | |
| 64 | - data > (level - 0.5 + (window-1)/2)], | |
| 65 | - [0, window, lambda data: ((data - (level - 0.5))/(window-1) + 0.5)*(window)]) | |
| 62 | + shape = data.shape | |
| 63 | + data_ = data.ravel() | |
| 64 | + data = np.piecewise(data_, | |
| 65 | + [data_ <= (level - 0.5 - (window-1)/2), | |
| 66 | + data_ > (level - 0.5 + (window-1)/2)], | |
| 67 | + [0, window, lambda data_: ((data_ - (level - 0.5))/(window-1) + 0.5)*(window)]) | |
| 68 | + data.shape = shape | |
| 69 | + return data | |
| 66 | 70 | |
| 67 | 71 | class BaseImageInteractorStyle(vtk.vtkInteractorStyleImage): |
| 68 | 72 | def __init__(self, viewer): | ... | ... |
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,13 @@ 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() |
| 248 | + normals.Update() | |
| 246 | 249 | |
| 247 | 250 | mapper = vtk.vtkPolyDataMapper() |
| 248 | - mapper.SetInput(normals.GetOutput()) | |
| 251 | + mapper.SetInputData(normals.GetOutput()) | |
| 249 | 252 | mapper.ScalarVisibilityOff() |
| 250 | 253 | mapper.ImmediateModeRenderingOn() # improve performance |
| 251 | 254 | |
| ... | ... | @@ -289,11 +292,12 @@ class SurfaceManager(): |
| 289 | 292 | # The following lines have to be here, otherwise all volumes disappear |
| 290 | 293 | if not volume: |
| 291 | 294 | triangle_filter = vtk.vtkTriangleFilter() |
| 292 | - triangle_filter.SetInput(polydata) | |
| 295 | + triangle_filter.SetInputData(polydata) | |
| 293 | 296 | triangle_filter.Update() |
| 294 | 297 | |
| 295 | 298 | measured_polydata = vtk.vtkMassProperties() |
| 296 | - measured_polydata.SetInput(triangle_filter.GetOutput()) | |
| 299 | + measured_polydata.SetInputConnection(triangle_filter.GetOutputPort()) | |
| 300 | + measured_polydata.Update() | |
| 297 | 301 | volume = measured_polydata.GetVolume() |
| 298 | 302 | surface.volume = volume |
| 299 | 303 | print ">>>>", surface.volume |
| ... | ... | @@ -338,19 +342,19 @@ class SurfaceManager(): |
| 338 | 342 | surface = surface_dict[key] |
| 339 | 343 | # Map polygonal data (vtkPolyData) to graphics primitives. |
| 340 | 344 | normals = vtk.vtkPolyDataNormals() |
| 341 | - normals.SetInput(surface.polydata) | |
| 345 | + normals.SetInputData(surface.polydata) | |
| 342 | 346 | normals.SetFeatureAngle(80) |
| 343 | 347 | normals.AutoOrientNormalsOn() |
| 344 | - normals.GetOutput().ReleaseDataFlagOn() | |
| 348 | + # normals.GetOutput().ReleaseDataFlagOn() | |
| 345 | 349 | |
| 346 | 350 | # Improve performance |
| 347 | 351 | stripper = vtk.vtkStripper() |
| 348 | - stripper.SetInput(normals.GetOutput()) | |
| 352 | + stripper.SetInputData(normals.GetOutput()) | |
| 349 | 353 | stripper.PassThroughCellIdsOn() |
| 350 | 354 | stripper.PassThroughPointIdsOn() |
| 351 | 355 | |
| 352 | 356 | mapper = vtk.vtkPolyDataMapper() |
| 353 | - mapper.SetInput(stripper.GetOutput()) | |
| 357 | + mapper.SetInputData(stripper.GetOutput()) | |
| 354 | 358 | mapper.ScalarVisibilityOff() |
| 355 | 359 | mapper.ImmediateModeRenderingOn() # improve performance |
| 356 | 360 | |
| ... | ... | @@ -490,30 +494,30 @@ class SurfaceManager(): |
| 490 | 494 | break |
| 491 | 495 | |
| 492 | 496 | polydata_append = vtk.vtkAppendPolyData() |
| 493 | - polydata_append.ReleaseDataFlagOn() | |
| 497 | + # polydata_append.ReleaseDataFlagOn() | |
| 494 | 498 | t = n_pieces |
| 495 | 499 | while t: |
| 496 | 500 | filename_polydata = q_out.get() |
| 497 | 501 | |
| 498 | 502 | reader = vtk.vtkXMLPolyDataReader() |
| 499 | 503 | reader.SetFileName(filename_polydata) |
| 500 | - reader.ReleaseDataFlagOn() | |
| 504 | + # reader.ReleaseDataFlagOn() | |
| 501 | 505 | reader.Update() |
| 502 | - reader.GetOutput().ReleaseDataFlagOn() | |
| 506 | + # reader.GetOutput().ReleaseDataFlagOn() | |
| 503 | 507 | |
| 504 | 508 | polydata = reader.GetOutput() |
| 505 | - polydata.SetSource(None) | |
| 509 | + # polydata.SetSource(None) | |
| 506 | 510 | |
| 507 | - polydata_append.AddInput(polydata) | |
| 511 | + polydata_append.AddInputData(polydata) | |
| 508 | 512 | del reader |
| 509 | 513 | del polydata |
| 510 | 514 | t -= 1 |
| 511 | 515 | |
| 512 | 516 | polydata_append.Update() |
| 513 | - polydata_append.GetOutput().ReleaseDataFlagOn() | |
| 517 | + # polydata_append.GetOutput().ReleaseDataFlagOn() | |
| 514 | 518 | polydata = polydata_append.GetOutput() |
| 515 | 519 | #polydata.Register(None) |
| 516 | - polydata.SetSource(None) | |
| 520 | + # polydata.SetSource(None) | |
| 517 | 521 | del polydata_append |
| 518 | 522 | |
| 519 | 523 | if algorithm == 'ca_smoothing': |
| ... | ... | @@ -521,31 +525,31 @@ class SurfaceManager(): |
| 521 | 525 | normals_ref = weakref.ref(normals) |
| 522 | 526 | normals_ref().AddObserver("ProgressEvent", lambda obj,evt: |
| 523 | 527 | UpdateProgress(normals_ref(), _("Creating 3D surface..."))) |
| 524 | - normals.SetInput(polydata) | |
| 525 | - normals.ReleaseDataFlagOn() | |
| 528 | + normals.SetInputData(polydata) | |
| 529 | + # normals.ReleaseDataFlagOn() | |
| 526 | 530 | #normals.SetFeatureAngle(80) |
| 527 | 531 | #normals.AutoOrientNormalsOn() |
| 528 | 532 | normals.ComputeCellNormalsOn() |
| 529 | - normals.GetOutput().ReleaseDataFlagOn() | |
| 533 | + # normals.GetOutput().ReleaseDataFlagOn() | |
| 530 | 534 | normals.Update() |
| 531 | 535 | del polydata |
| 532 | 536 | polydata = normals.GetOutput() |
| 533 | - polydata.SetSource(None) | |
| 537 | + # polydata.SetSource(None) | |
| 534 | 538 | del normals |
| 535 | 539 | |
| 536 | 540 | clean = vtk.vtkCleanPolyData() |
| 537 | - clean.ReleaseDataFlagOn() | |
| 538 | - clean.GetOutput().ReleaseDataFlagOn() | |
| 541 | + # clean.ReleaseDataFlagOn() | |
| 542 | + # clean.GetOutput().ReleaseDataFlagOn() | |
| 539 | 543 | clean_ref = weakref.ref(clean) |
| 540 | 544 | clean_ref().AddObserver("ProgressEvent", lambda obj,evt: |
| 541 | 545 | UpdateProgress(clean_ref(), _("Creating 3D surface..."))) |
| 542 | - clean.SetInput(polydata) | |
| 546 | + clean.SetInputData(polydata) | |
| 543 | 547 | clean.PointMergingOn() |
| 544 | 548 | clean.Update() |
| 545 | 549 | |
| 546 | 550 | del polydata |
| 547 | 551 | polydata = clean.GetOutput() |
| 548 | - polydata.SetSource(None) | |
| 552 | + # polydata.SetSource(None) | |
| 549 | 553 | del clean |
| 550 | 554 | |
| 551 | 555 | try: |
| ... | ... | @@ -556,7 +560,7 @@ class SurfaceManager(): |
| 556 | 560 | options['max distance'], |
| 557 | 561 | options['min weight'], |
| 558 | 562 | options['steps']) |
| 559 | - polydata.SetSource(None) | |
| 563 | + # polydata.SetSource(None) | |
| 560 | 564 | polydata.DebugOn() |
| 561 | 565 | |
| 562 | 566 | else: |
| ... | ... | @@ -565,7 +569,7 @@ class SurfaceManager(): |
| 565 | 569 | smoother_ref = weakref.ref(smoother) |
| 566 | 570 | smoother_ref().AddObserver("ProgressEvent", lambda obj,evt: |
| 567 | 571 | UpdateProgress(smoother_ref(), _("Creating 3D surface..."))) |
| 568 | - smoother.SetInput(polydata) | |
| 572 | + smoother.SetInputData(polydata) | |
| 569 | 573 | smoother.SetNumberOfIterations(smooth_iterations) |
| 570 | 574 | smoother.SetRelaxationFactor(smooth_relaxation_factor) |
| 571 | 575 | smoother.SetFeatureAngle(80) |
| ... | ... | @@ -575,21 +579,21 @@ class SurfaceManager(): |
| 575 | 579 | smoother.FeatureEdgeSmoothingOn() |
| 576 | 580 | #smoother.NormalizeCoordinatesOn() |
| 577 | 581 | #smoother.NonManifoldSmoothingOn() |
| 578 | - smoother.ReleaseDataFlagOn() | |
| 579 | - smoother.GetOutput().ReleaseDataFlagOn() | |
| 582 | + # smoother.ReleaseDataFlagOn() | |
| 583 | + # smoother.GetOutput().ReleaseDataFlagOn() | |
| 580 | 584 | smoother.Update() |
| 581 | 585 | del polydata |
| 582 | 586 | polydata = smoother.GetOutput() |
| 583 | 587 | #polydata.Register(None) |
| 584 | - polydata.SetSource(None) | |
| 588 | + # polydata.SetSource(None) | |
| 585 | 589 | del smoother |
| 586 | 590 | |
| 587 | 591 | |
| 588 | 592 | if decimate_reduction: |
| 589 | 593 | print "Decimating", decimate_reduction |
| 590 | 594 | decimation = vtk.vtkQuadricDecimation() |
| 591 | - decimation.ReleaseDataFlagOn() | |
| 592 | - decimation.SetInput(polydata) | |
| 595 | + # decimation.ReleaseDataFlagOn() | |
| 596 | + decimation.SetInputData(polydata) | |
| 593 | 597 | decimation.SetTargetReduction(decimate_reduction) |
| 594 | 598 | decimation_ref = weakref.ref(decimation) |
| 595 | 599 | decimation_ref().AddObserver("ProgressEvent", lambda obj,evt: |
| ... | ... | @@ -597,31 +601,31 @@ class SurfaceManager(): |
| 597 | 601 | #decimation.PreserveTopologyOn() |
| 598 | 602 | #decimation.SplittingOff() |
| 599 | 603 | #decimation.BoundaryVertexDeletionOff() |
| 600 | - decimation.GetOutput().ReleaseDataFlagOn() | |
| 604 | + # decimation.GetOutput().ReleaseDataFlagOn() | |
| 601 | 605 | decimation.Update() |
| 602 | 606 | del polydata |
| 603 | 607 | polydata = decimation.GetOutput() |
| 604 | 608 | #polydata.Register(None) |
| 605 | - polydata.SetSource(None) | |
| 609 | + # polydata.SetSource(None) | |
| 606 | 610 | del decimation |
| 607 | 611 | |
| 608 | 612 | to_measure = polydata |
| 609 | 613 | #to_measure.Register(None) |
| 610 | - to_measure.SetSource(None) | |
| 614 | + # to_measure.SetSource(None) | |
| 611 | 615 | |
| 612 | 616 | if keep_largest: |
| 613 | 617 | conn = vtk.vtkPolyDataConnectivityFilter() |
| 614 | - conn.SetInput(polydata) | |
| 618 | + conn.SetInputData(polydata) | |
| 615 | 619 | conn.SetExtractionModeToLargestRegion() |
| 616 | 620 | conn_ref = weakref.ref(conn) |
| 617 | 621 | conn_ref().AddObserver("ProgressEvent", lambda obj,evt: |
| 618 | 622 | UpdateProgress(conn_ref(), _("Creating 3D surface..."))) |
| 619 | 623 | conn.Update() |
| 620 | - conn.GetOutput().ReleaseDataFlagOn() | |
| 624 | + # conn.GetOutput().ReleaseDataFlagOn() | |
| 621 | 625 | del polydata |
| 622 | 626 | polydata = conn.GetOutput() |
| 623 | 627 | #polydata.Register(None) |
| 624 | - polydata.SetSource(None) | |
| 628 | + # polydata.SetSource(None) | |
| 625 | 629 | del conn |
| 626 | 630 | |
| 627 | 631 | #Filter used to detect and fill holes. Only fill boundary edges holes. |
| ... | ... | @@ -629,59 +633,59 @@ class SurfaceManager(): |
| 629 | 633 | #polydata_utils.FillSurfaceHole, we need to review this. |
| 630 | 634 | if fill_holes: |
| 631 | 635 | filled_polydata = vtk.vtkFillHolesFilter() |
| 632 | - filled_polydata.ReleaseDataFlagOn() | |
| 633 | - filled_polydata.SetInput(polydata) | |
| 636 | + # filled_polydata.ReleaseDataFlagOn() | |
| 637 | + filled_polydata.SetInputData(polydata) | |
| 634 | 638 | filled_polydata.SetHoleSize(300) |
| 635 | 639 | filled_polydata_ref = weakref.ref(filled_polydata) |
| 636 | 640 | filled_polydata_ref().AddObserver("ProgressEvent", lambda obj,evt: |
| 637 | 641 | UpdateProgress(filled_polydata_ref(), _("Creating 3D surface..."))) |
| 638 | 642 | filled_polydata.Update() |
| 639 | - filled_polydata.GetOutput().ReleaseDataFlagOn() | |
| 643 | + # filled_polydata.GetOutput().ReleaseDataFlagOn() | |
| 640 | 644 | del polydata |
| 641 | 645 | polydata = filled_polydata.GetOutput() |
| 642 | 646 | #polydata.Register(None) |
| 643 | - polydata.SetSource(None) | |
| 647 | + # polydata.SetSource(None) | |
| 644 | 648 | polydata.DebugOn() |
| 645 | 649 | del filled_polydata |
| 646 | 650 | |
| 647 | 651 | normals = vtk.vtkPolyDataNormals() |
| 648 | - normals.ReleaseDataFlagOn() | |
| 652 | + # normals.ReleaseDataFlagOn() | |
| 649 | 653 | normals_ref = weakref.ref(normals) |
| 650 | 654 | normals_ref().AddObserver("ProgressEvent", lambda obj,evt: |
| 651 | 655 | UpdateProgress(normals_ref(), _("Creating 3D surface..."))) |
| 652 | - normals.SetInput(polydata) | |
| 656 | + normals.SetInputData(polydata) | |
| 653 | 657 | normals.SetFeatureAngle(80) |
| 654 | 658 | normals.AutoOrientNormalsOn() |
| 655 | - normals.GetOutput().ReleaseDataFlagOn() | |
| 659 | + # normals.GetOutput().ReleaseDataFlagOn() | |
| 656 | 660 | normals.Update() |
| 657 | 661 | del polydata |
| 658 | 662 | polydata = normals.GetOutput() |
| 659 | 663 | #polydata.Register(None) |
| 660 | - polydata.SetSource(None) | |
| 664 | + # polydata.SetSource(None) | |
| 661 | 665 | del normals |
| 662 | 666 | |
| 663 | 667 | # Improve performance |
| 664 | 668 | stripper = vtk.vtkStripper() |
| 665 | - stripper.ReleaseDataFlagOn() | |
| 669 | + # stripper.ReleaseDataFlagOn() | |
| 666 | 670 | stripper_ref = weakref.ref(stripper) |
| 667 | 671 | stripper_ref().AddObserver("ProgressEvent", lambda obj,evt: |
| 668 | 672 | UpdateProgress(stripper_ref(), _("Creating 3D surface..."))) |
| 669 | - stripper.SetInput(polydata) | |
| 673 | + stripper.SetInputData(polydata) | |
| 670 | 674 | stripper.PassThroughCellIdsOn() |
| 671 | 675 | stripper.PassThroughPointIdsOn() |
| 672 | - stripper.GetOutput().ReleaseDataFlagOn() | |
| 676 | + # stripper.GetOutput().ReleaseDataFlagOn() | |
| 673 | 677 | stripper.Update() |
| 674 | 678 | del polydata |
| 675 | 679 | polydata = stripper.GetOutput() |
| 676 | 680 | #polydata.Register(None) |
| 677 | - polydata.SetSource(None) | |
| 681 | + # polydata.SetSource(None) | |
| 678 | 682 | del stripper |
| 679 | 683 | |
| 680 | 684 | # Map polygonal data (vtkPolyData) to graphics primitives. |
| 681 | 685 | mapper = vtk.vtkPolyDataMapper() |
| 682 | - mapper.SetInput(polydata) | |
| 686 | + mapper.SetInputData(polydata) | |
| 683 | 687 | mapper.ScalarVisibilityOff() |
| 684 | - mapper.ReleaseDataFlagOn() | |
| 688 | + # mapper.ReleaseDataFlagOn() | |
| 685 | 689 | mapper.ImmediateModeRenderingOn() # improve performance |
| 686 | 690 | |
| 687 | 691 | # Represent an object (geometry & properties) in the rendered scene |
| ... | ... | @@ -720,8 +724,8 @@ class SurfaceManager(): |
| 720 | 724 | |
| 721 | 725 | # The following lines have to be here, otherwise all volumes disappear |
| 722 | 726 | measured_polydata = vtk.vtkMassProperties() |
| 723 | - measured_polydata.ReleaseDataFlagOn() | |
| 724 | - measured_polydata.SetInput(to_measure) | |
| 727 | + # measured_polydata.ReleaseDataFlagOn() | |
| 728 | + measured_polydata.SetInputData(to_measure) | |
| 725 | 729 | volume = float(measured_polydata.GetVolume()) |
| 726 | 730 | surface.volume = volume |
| 727 | 731 | self.last_surface_index = surface.index |
| ... | ... | @@ -858,14 +862,15 @@ class SurfaceManager(): |
| 858 | 862 | if filetype in (const.FILETYPE_STL, const.FILETYPE_PLY): |
| 859 | 863 | # Invert normals |
| 860 | 864 | normals = vtk.vtkPolyDataNormals() |
| 861 | - normals.SetInput(polydata) | |
| 865 | + normals.SetInputData(polydata) | |
| 862 | 866 | normals.SetFeatureAngle(80) |
| 863 | 867 | normals.AutoOrientNormalsOn() |
| 864 | - normals.GetOutput().ReleaseDataFlagOn() | |
| 868 | + # normals.GetOutput().ReleaseDataFlagOn() | |
| 865 | 869 | normals.UpdateInformation() |
| 870 | + normals.Update() | |
| 866 | 871 | polydata = normals.GetOutput() |
| 867 | 872 | |
| 868 | 873 | filename = filename.encode(wx.GetDefaultPyEncoding()) |
| 869 | 874 | writer.SetFileName(filename) |
| 870 | - writer.SetInput(polydata) | |
| 875 | + writer.SetInputData(polydata) | |
| 871 | 876 | 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 | ... | ... |
invesalius/data/viewer_slice.py
| ... | ... | @@ -753,6 +753,7 @@ class Viewer(wx.Panel): |
| 753 | 753 | image = vtk.vtkRenderLargeImage() |
| 754 | 754 | image.SetInput(ren) |
| 755 | 755 | image.SetMagnification(1) |
| 756 | + image.Update() | |
| 756 | 757 | |
| 757 | 758 | image = image.GetOutput() |
| 758 | 759 | |
| ... | ... | @@ -769,8 +770,8 @@ class Viewer(wx.Panel): |
| 769 | 770 | elif (filetype == const.FILETYPE_TIF): |
| 770 | 771 | writer = vtk.vtkTIFFWriter() |
| 771 | 772 | filename = "%s.tif"%filename.strip(".tif") |
| 772 | - | |
| 773 | - writer.SetInput(image) | |
| 773 | + | |
| 774 | + writer.SetInputData(image) | |
| 774 | 775 | writer.SetFileName(filename) |
| 775 | 776 | writer.Write() |
| 776 | 777 | |
| ... | ... | @@ -919,7 +920,7 @@ class Viewer(wx.Panel): |
| 919 | 920 | c.SetCoordinateSystemToWorld() |
| 920 | 921 | |
| 921 | 922 | cross_mapper = vtk.vtkPolyDataMapper() |
| 922 | - cross_mapper.SetInput(cross.GetOutput()) | |
| 923 | + cross_mapper.SetInputConnection(cross.GetOutputPort()) | |
| 923 | 924 | #cross_mapper.SetTransformCoordinate(c) |
| 924 | 925 | |
| 925 | 926 | p = vtk.vtkProperty() |
| ... | ... | @@ -1176,7 +1177,7 @@ class Viewer(wx.Panel): |
| 1176 | 1177 | border_size = self.mip_ctrls.border_spin.GetValue() |
| 1177 | 1178 | image = self.slice_.GetSlices(self.orientation, index, |
| 1178 | 1179 | self.number_slices, inverted, border_size) |
| 1179 | - self.slice_data.actor.SetInput(image) | |
| 1180 | + self.slice_data.actor.SetInputData(image) | |
| 1180 | 1181 | for actor in self.actors_by_slice_number.get(self.slice_data.number, []): |
| 1181 | 1182 | self.slice_data.renderer.RemoveActor(actor) |
| 1182 | 1183 | for actor in self.actors_by_slice_number.get(index, []): | ... | ... |
invesalius/data/viewer_volume.py
| ... | ... | @@ -318,6 +318,7 @@ class Viewer(wx.Panel): |
| 318 | 318 | image = vtk.vtkRenderLargeImage() |
| 319 | 319 | image.SetInput(self.ren) |
| 320 | 320 | image.SetMagnification(1) |
| 321 | + image.Update() | |
| 321 | 322 | |
| 322 | 323 | image = image.GetOutput() |
| 323 | 324 | |
| ... | ... | @@ -333,12 +334,12 @@ class Viewer(wx.Panel): |
| 333 | 334 | elif (filetype == const.FILETYPE_TIF): |
| 334 | 335 | writer = vtk.vtkTIFFWriter() |
| 335 | 336 | filename = "%s.tif"%filename.strip(".tif") |
| 336 | - | |
| 337 | - writer.SetInput(image) | |
| 337 | + | |
| 338 | + writer.SetInputData(image) | |
| 338 | 339 | writer.SetFileName(filename) |
| 339 | 340 | writer.Write() |
| 340 | 341 | Publisher.sendMessage('End busy cursor') |
| 341 | - | |
| 342 | + | |
| 342 | 343 | def OnCloseProject(self, pubsub_evt): |
| 343 | 344 | if self.raycasting_volume: |
| 344 | 345 | self.raycasting_volume = False | ... | ... |
invesalius/data/volume.py
| ... | ... | @@ -224,7 +224,7 @@ class Volume(): |
| 224 | 224 | # Update convolution filter |
| 225 | 225 | original_imagedata = self.imagedata.GetOutput() |
| 226 | 226 | imagedata = self.ApplyConvolution(original_imagedata) |
| 227 | - self.volume_mapper.SetInput(imagedata) | |
| 227 | + self.volume_mapper.SetInputData(imagedata) | |
| 228 | 228 | |
| 229 | 229 | # Update other information |
| 230 | 230 | self.SetShading() |
| ... | ... | @@ -484,7 +484,7 @@ class Volume(): |
| 484 | 484 | update_progress = vtk_utils.ShowProgress(number_filters) |
| 485 | 485 | for filter in self.config['convolutionFilters']: |
| 486 | 486 | convolve = vtk.vtkImageConvolve() |
| 487 | - convolve.SetInput(imagedata) | |
| 487 | + convolve.SetInputData(imagedata) | |
| 488 | 488 | convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]]) |
| 489 | 489 | convolve.ReleaseDataFlagOn() |
| 490 | 490 | |
| ... | ... | @@ -530,7 +530,7 @@ class Volume(): |
| 530 | 530 | update_progress= vtk_utils.ShowProgress(2 + number_filters) |
| 531 | 531 | # Flip original vtkImageData |
| 532 | 532 | flip = vtk.vtkImageFlip() |
| 533 | - flip.SetInput(image) | |
| 533 | + flip.SetInputData(image) | |
| 534 | 534 | flip.SetFilteredAxis(1) |
| 535 | 535 | flip.FlipAboutOriginOn() |
| 536 | 536 | flip.ReleaseDataFlagOn() |
| ... | ... | @@ -545,7 +545,7 @@ class Volume(): |
| 545 | 545 | self.scale = scale |
| 546 | 546 | |
| 547 | 547 | cast = vtk.vtkImageShiftScale() |
| 548 | - cast.SetInput(image) | |
| 548 | + cast.SetInputData(image) | |
| 549 | 549 | cast.SetShift(abs(scale[0])) |
| 550 | 550 | cast.SetOutputScalarTypeToUnsignedShort() |
| 551 | 551 | cast.ReleaseDataFlagOn() |
| ... | ... | @@ -589,7 +589,7 @@ class Volume(): |
| 589 | 589 | self.volume_mapper = volume_mapper |
| 590 | 590 | |
| 591 | 591 | self.SetTypeRaycasting() |
| 592 | - volume_mapper.SetInput(image2) | |
| 592 | + volume_mapper.SetInputData(image2) | |
| 593 | 593 | |
| 594 | 594 | # TODO: Look to this |
| 595 | 595 | #volume_mapper_hw = vtk.vtkVolumeTextureMapper3D() |
| ... | ... | @@ -657,7 +657,7 @@ class Volume(): |
| 657 | 657 | image = self.image |
| 658 | 658 | r = int(image.GetScalarRange()[1] - image.GetScalarRange()[0]) |
| 659 | 659 | accumulate = vtk.vtkImageAccumulate() |
| 660 | - accumulate.SetInput(image) | |
| 660 | + accumulate.SetInputData(image) | |
| 661 | 661 | accumulate.SetComponentExtent(0, r -1, 0, 0, 0, 0) |
| 662 | 662 | accumulate.SetComponentOrigin(image.GetScalarRange()[0], 0, 0) |
| 663 | 663 | accumulate.ReleaseDataFlagOn() | ... | ... |
invesalius/data/watershed_process.py
| 1 | -import numpy as np | |
| 2 | -from scipy import ndimage | |
| 3 | -from scipy.ndimage import watershed_ift, generate_binary_structure | |
| 4 | -from skimage.morphology import watershed | |
| 5 | -from skimage import filter | |
| 6 | - | |
| 7 | - | |
| 8 | -def get_LUT_value(data, window, level): | |
| 9 | - return np.piecewise(data, | |
| 10 | - [data <= (level - 0.5 - (window-1)/2), | |
| 11 | - data > (level - 0.5 + (window-1)/2)], | |
| 12 | - [0, 255, lambda data: ((data - (level - 0.5))/(window-1) + 0.5)*(255-0)]) | |
| 13 | - | |
| 14 | - | |
| 15 | - | |
| 16 | -def do_watershed(image, markers, tfile, shape, bstruct, algorithm, mg_size, use_ww_wl, wl, ww, q): | |
| 17 | - mask = np.memmap(tfile, shape=shape, dtype='uint8', mode='r+') | |
| 18 | - | |
| 19 | - if use_ww_wl: | |
| 20 | - if algorithm == 'Watershed': | |
| 21 | - tmp_image = ndimage.morphological_gradient( | |
| 22 | - get_LUT_value(image, ww, wl).astype('uint16'), | |
| 23 | - mg_size) | |
| 24 | - tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) | |
| 25 | - else: | |
| 26 | - tmp_image = get_LUT_value(image, ww, wl).astype('uint16') | |
| 27 | - #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) | |
| 28 | - #tmp_image = ndimage.morphological_gradient( | |
| 29 | - #get_LUT_value(image, ww, wl).astype('uint16'), | |
| 30 | - #self.config.mg_size) | |
| 31 | - tmp_mask = watershed_ift(tmp_image, markers.astype('int16'), bstruct) | |
| 32 | - else: | |
| 33 | - if algorithm == 'Watershed': | |
| 34 | - tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), mg_size) | |
| 35 | - tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) | |
| 36 | - else: | |
| 37 | - tmp_image = (image - image.min()).astype('uint16') | |
| 38 | - #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) | |
| 39 | - #tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) | |
| 40 | - tmp_mask = watershed_ift(tmp_image, markers.astype('int8'), bstruct) | |
| 41 | - mask[:] = tmp_mask | |
| 42 | - mask.flush() | |
| 43 | - q.put(1) | |
| 1 | +import numpy as np | |
| 2 | +from scipy import ndimage | |
| 3 | +from scipy.ndimage import watershed_ift, generate_binary_structure | |
| 4 | +from skimage.morphology import watershed | |
| 5 | +from skimage import filter | |
| 6 | + | |
| 7 | + | |
| 8 | +def get_LUT_value(data, window, level): | |
| 9 | + shape = data.shape | |
| 10 | + data_ = data.ravel() | |
| 11 | + data = np.piecewise(data_, | |
| 12 | + [data_ <= (level - 0.5 - (window-1)/2), | |
| 13 | + data_ > (level - 0.5 + (window-1)/2)], | |
| 14 | + [0, window, lambda data_: ((data_ - (level - 0.5))/(window-1) + 0.5)*(window)]) | |
| 15 | + data.shape = shape | |
| 16 | + return data | |
| 17 | + | |
| 18 | + | |
| 19 | +def do_watershed(image, markers, tfile, shape, bstruct, algorithm, mg_size, use_ww_wl, wl, ww, q): | |
| 20 | + mask = np.memmap(tfile, shape=shape, dtype='uint8', mode='r+') | |
| 21 | + | |
| 22 | + if use_ww_wl: | |
| 23 | + if algorithm == 'Watershed': | |
| 24 | + tmp_image = ndimage.morphological_gradient( | |
| 25 | + get_LUT_value(image, ww, wl).astype('uint16'), | |
| 26 | + mg_size) | |
| 27 | + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) | |
| 28 | + else: | |
| 29 | + tmp_image = get_LUT_value(image, ww, wl).astype('uint16') | |
| 30 | + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) | |
| 31 | + #tmp_image = ndimage.morphological_gradient( | |
| 32 | + #get_LUT_value(image, ww, wl).astype('uint16'), | |
| 33 | + #self.config.mg_size) | |
| 34 | + tmp_mask = watershed_ift(tmp_image, markers.astype('int16'), bstruct) | |
| 35 | + else: | |
| 36 | + if algorithm == 'Watershed': | |
| 37 | + tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), mg_size) | |
| 38 | + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) | |
| 39 | + else: | |
| 40 | + tmp_image = (image - image.min()).astype('uint16') | |
| 41 | + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) | |
| 42 | + #tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) | |
| 43 | + tmp_mask = watershed_ift(tmp_image, markers.astype('int8'), bstruct) | |
| 44 | + mask[:] = tmp_mask | |
| 45 | + mask.flush() | |
| 46 | + q.put(1) | ... | ... |
invesalius/gui/dicom_preview_panel.py
| ... | ... | @@ -848,12 +848,12 @@ class SingleImagePreview(wx.Panel): |
| 848 | 848 | window_level = dicom.image.level |
| 849 | 849 | window_width = dicom.image.window |
| 850 | 850 | colorer = vtk.vtkImageMapToWindowLevelColors() |
| 851 | - colorer.SetInput(rdicom.GetOutput()) | |
| 851 | + colorer.SetInputConnection(rdicom.GetOutputPort()) | |
| 852 | 852 | colorer.SetWindow(float(window_width)) |
| 853 | 853 | colorer.SetLevel(float(window_level)) |
| 854 | 854 | |
| 855 | 855 | # PLOT IMAGE INTO VIEWER |
| 856 | - self.actor.SetInput(colorer.GetOutput()) | |
| 856 | + self.actor.SetInputData(colorer.GetOutput()) | |
| 857 | 857 | self.renderer.ResetCamera() |
| 858 | 858 | self.interactor.Render() |
| 859 | 859 | ... | ... |
invesalius/reader/dicom_reader.py
| ... | ... | @@ -195,14 +195,14 @@ class LoadDicom: |
| 195 | 195 | window = 2000.0 |
| 196 | 196 | |
| 197 | 197 | colorer = vtk.vtkImageMapToWindowLevelColors() |
| 198 | - colorer.SetInput(rvtk.GetOutput()) | |
| 198 | + colorer.SetInputConnection(rvtk.GetOutputPort()) | |
| 199 | 199 | colorer.SetWindow(float(window)) |
| 200 | 200 | colorer.SetLevel(float(level)) |
| 201 | 201 | colorer.SetOutputFormatToRGB() |
| 202 | 202 | colorer.Update() |
| 203 | 203 | |
| 204 | 204 | resample = vtk.vtkImageResample() |
| 205 | - resample.SetInput(colorer.GetOutput()) | |
| 205 | + resample.SetInputConnection(colorer.GetOutputPort()) | |
| 206 | 206 | resample.SetAxisMagnificationFactor ( 0, 0.25 ) |
| 207 | 207 | resample.SetAxisMagnificationFactor ( 1, 0.25 ) |
| 208 | 208 | resample.SetAxisMagnificationFactor ( 2, 1 ) |
| ... | ... | @@ -211,7 +211,7 @@ class LoadDicom: |
| 211 | 211 | thumbnail_path = tempfile.mktemp() |
| 212 | 212 | |
| 213 | 213 | write_png = vtk.vtkPNGWriter() |
| 214 | - write_png.SetInput(resample.GetOutput()) | |
| 214 | + write_png.SetInputConnection(resample.GetOutputPort()) | |
| 215 | 215 | write_png.SetFileName(thumbnail_path) |
| 216 | 216 | write_png.Write() |
| 217 | 217 | ... | ... |