Commit 19c511ef7177e0b53cfb1e843140e0c6bfc966ed
1 parent
cfadc616
Exists in
master
and in
67 other branches
ENH: Some tests with smoothing in surface generation
Showing
1 changed file
with
30 additions
and
26 deletions
Show diff stats
invesalius/data/surface_process.py
| @@ -50,32 +50,32 @@ class SurfaceProcess(multiprocessing.Process): | @@ -50,32 +50,32 @@ class SurfaceProcess(multiprocessing.Process): | ||
| 50 | self.pipe.send([prog, msg]) | 50 | self.pipe.send([prog, msg]) |
| 51 | 51 | ||
| 52 | def CreateSurface(self, roi): | 52 | def CreateSurface(self, roi): |
| 53 | - smoothed = ndimage.gaussian_filter(self.mask[roi], (1, 1, 1)) | 53 | + smoothed = numpy.array(self.mask[roi]) |
| 54 | image = imagedata_utils.to_vtk(smoothed, self.spacing, roi.start, | 54 | image = imagedata_utils.to_vtk(smoothed, self.spacing, roi.start, |
| 55 | "AXIAL") | 55 | "AXIAL") |
| 56 | 56 | ||
| 57 | # Create vtkPolyData from vtkImageData | 57 | # Create vtkPolyData from vtkImageData |
| 58 | - print "Generating Polydata" | ||
| 59 | - if self.mode == "CONTOUR": | ||
| 60 | - print "Contour" | ||
| 61 | - contour = vtk.vtkContourFilter() | ||
| 62 | - contour.SetInput(image) | ||
| 63 | - contour.SetValue(0, 127.5) # initial threshold | ||
| 64 | - contour.ComputeScalarsOn() | ||
| 65 | - contour.ComputeGradientsOn() | ||
| 66 | - contour.ComputeNormalsOn() | ||
| 67 | - polydata = contour.GetOutput() | ||
| 68 | - else: #mode == "GRAYSCALE": | ||
| 69 | - mcubes = vtk.vtkMarchingCubes() | ||
| 70 | - mcubes.SetInput(image) | ||
| 71 | - mcubes.SetValue(0, 127.5) | ||
| 72 | - mcubes.ComputeScalarsOn() | ||
| 73 | - mcubes.ComputeGradientsOn() | ||
| 74 | - mcubes.ComputeNormalsOn() | ||
| 75 | - polydata = mcubes.GetOutput() | 58 | + #print "Generating Polydata" |
| 59 | + #if self.mode == "CONTOUR": | ||
| 60 | + #print "Contour" | ||
| 61 | + #contour = vtk.vtkContourFilter() | ||
| 62 | + #contour.SetInput(image) | ||
| 63 | + #contour.SetValue(0, 127.5) # initial threshold | ||
| 64 | + #contour.ComputeScalarsOn() | ||
| 65 | + #contour.ComputeGradientsOn() | ||
| 66 | + #contour.ComputeNormalsOn() | ||
| 67 | + #polydata = contour.GetOutput() | ||
| 68 | + #else: #mode == "GRAYSCALE": | ||
| 69 | + mcubes = vtk.vtkDiscreteMarchingCubes() | ||
| 70 | + mcubes.SetInput(image) | ||
| 71 | + mcubes.SetValue(0, 255) | ||
| 72 | + mcubes.ComputeScalarsOn() | ||
| 73 | + mcubes.ComputeGradientsOn() | ||
| 74 | + mcubes.ComputeNormalsOn() | ||
| 75 | + polydata = mcubes.GetOutput() | ||
| 76 | 76 | ||
| 77 | print "Decimating" | 77 | print "Decimating" |
| 78 | - if self.decimate_reduction: | 78 | + if not self.decimate_reduction: |
| 79 | decimation = vtk.vtkDecimatePro() | 79 | decimation = vtk.vtkDecimatePro() |
| 80 | decimation.SetInput(polydata) | 80 | decimation.SetInput(polydata) |
| 81 | decimation.SetTargetReduction(self.decimate_reduction) | 81 | decimation.SetTargetReduction(self.decimate_reduction) |
| @@ -83,19 +83,23 @@ class SurfaceProcess(multiprocessing.Process): | @@ -83,19 +83,23 @@ class SurfaceProcess(multiprocessing.Process): | ||
| 83 | decimation.SplittingOff() | 83 | decimation.SplittingOff() |
| 84 | polydata = decimation.GetOutput() | 84 | polydata = decimation.GetOutput() |
| 85 | 85 | ||
| 86 | - print "Smoothing" | ||
| 87 | if self.smooth_iterations and self.smooth_relaxation_factor: | 86 | if self.smooth_iterations and self.smooth_relaxation_factor: |
| 88 | - smoother = vtk.vtkSmoothPolyDataFilter() | 87 | + print "Smoothing" |
| 88 | + smoother = vtk.vtkWindowedSincPolyDataFilter() | ||
| 89 | smoother.SetInput(polydata) | 89 | smoother.SetInput(polydata) |
| 90 | smoother.SetNumberOfIterations(self.smooth_iterations) | 90 | smoother.SetNumberOfIterations(self.smooth_iterations) |
| 91 | - smoother.SetFeatureAngle(80) | ||
| 92 | - smoother.SetRelaxationFactor(self.smooth_relaxation_factor) | ||
| 93 | - smoother.FeatureEdgeSmoothingOn() | 91 | + smoother.SetFeatureAngle(120) |
| 92 | + smoother.SetNumberOfIterations(30) | ||
| 94 | smoother.BoundarySmoothingOn() | 93 | smoother.BoundarySmoothingOn() |
| 94 | + smoother.SetPassBand(0.1) | ||
| 95 | + smoother.FeatureEdgeSmoothingOn() | ||
| 96 | + smoother.NonManifoldSmoothingOn() | ||
| 97 | + smoother.NormalizeCoordinatesOn() | ||
| 98 | + smoother.Update() | ||
| 95 | polydata = smoother.GetOutput() | 99 | polydata = smoother.GetOutput() |
| 96 | 100 | ||
| 97 | print "Saving" | 101 | print "Saving" |
| 98 | - filename = tempfile.mktemp() | 102 | + filename = tempfile.mktemp(suffix='_%s.vtp' % (self.pid)) |
| 99 | writer = vtk.vtkXMLPolyDataWriter() | 103 | writer = vtk.vtkXMLPolyDataWriter() |
| 100 | writer.SetInput(polydata) | 104 | writer.SetInput(polydata) |
| 101 | writer.SetFileName(filename) | 105 | writer.SetFileName(filename) |