From 1b2d60347e197d3eca70741aa8bba2de45c92a4a Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Wed, 26 Aug 2015 14:14:51 -0300 Subject: [PATCH] tests --- invesalius/data/smooth_cy.pyx | 26 +++++++++++++------------- invesalius/data/surface.py | 38 ++++++++++++++++++++++++++++++++++---- invesalius/data/surface_process.py | 6 +++--- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/invesalius/data/smooth_cy.pyx b/invesalius/data/smooth_cy.pyx index 66fb39f..133bfee 100644 --- a/invesalius/data/smooth_cy.pyx +++ b/invesalius/data/smooth_cy.pyx @@ -118,7 +118,7 @@ def smooth(np.ndarray[DTYPE8_t, ndim=3] image, cdef np.ndarray[DTYPE8_t, ndim=3] _mask = np.zeros_like(image) cdef np.ndarray[DTYPEF64_t, ndim=3] aux = np.zeros_like(out) - cdef int i, x, y, z, S; + cdef int i, x, y, z, S cdef DTYPEF64_t H, v, cn cdef DTYPEF64_t diff=0.0 cdef DTYPEF64_t dt=1/6.0 @@ -152,31 +152,31 @@ def smooth(np.ndarray[DTYPE8_t, ndim=3] image, S += 1 for i in xrange(n): - replicate(out, aux); - diff = 0.0; + replicate(out, aux) + diff = 0.0 for z in xrange(dz): for y in xrange(dy): for x in xrange(dx): if mask[z, y, x]: - H = calculate_H(aux, z, y, x); - v = aux[z, y, x] + dt*H; + H = calculate_H(aux, z, y, x) + v = aux[z, y, x] + dt*H if image[z, y, x]: - if v > 0: - out[z, y, x] = v - else: - out[z, y, x] = 0.0001 - else: if v < 0: + out[z, y, x] = 0.0 + else: out[z, y, x] = v + else: + if v > 0: + out[z, y, x] = 0.0 else: - out[z, y, x] = -0.0001 + out[z, y, x] = v diff += (out[z, y, x] - aux[z, y, x])*(out[z, y, x] - aux[z, y, x]) - cn = sqrt((1.0/S) * diff); + cn = sqrt((1.0/S) * diff) print "%d - CN: %.28f - diff: %.28f\n" % (i, cn, diff) if cn <= E: - break; + break diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index 272720e..d946f63 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -472,11 +472,9 @@ class SurfaceManager(): iteractions = 10 bsize = 4 mask_tfile = tempfile.mktemp() + mmask = np.memmap(mask_tfile, shape=mask.matrix.shape, dtype='float64', mode='w+') - smooth_cy.smooth(mask.matrix, iteractions, bsize, mmask) - mmask[0, :, :] = -1 - mmask[:, 0, :] = -1 - mmask[:, :, 0] = -1 + smooth_cy.smooth((mask.matrix > 127).astype('uint8'), iteractions, bsize, mmask) else: mask_tfile = mask.temp_file @@ -592,6 +590,38 @@ class SurfaceManager(): # polydata.SetSource(None) # polydata.DebugOn() + elif algorithm == 'Whitaker': + normals = vtk.vtkPolyDataNormals() + normals_ref = weakref.ref(normals) + normals_ref().AddObserver("ProgressEvent", lambda obj,evt: + UpdateProgress(normals_ref(), _("Creating 3D surface..."))) + normals.SetInput(polydata) + normals.ReleaseDataFlagOn() + #normals.SetFeatureAngle(80) + #normals.AutoOrientNormalsOn() + normals.ComputeCellNormalsOn() + normals.GetOutput().ReleaseDataFlagOn() + normals.Update() + del polydata + polydata = normals.GetOutput() + polydata.SetSource(None) + del normals + + clean = vtk.vtkCleanPolyData() + 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.PointMergingOn() + clean.Update() + + del polydata + polydata = clean.GetOutput() + polydata.SetSource(None) + del clean + else: #smoother = vtk.vtkWindowedSincPolyDataFilter() smoother = vtk.vtkSmoothPolyDataFilter() diff --git a/invesalius/data/surface_process.py b/invesalius/data/surface_process.py index 7df5e51..efdffee 100644 --- a/invesalius/data/surface_process.py +++ b/invesalius/data/surface_process.py @@ -158,9 +158,9 @@ class SurfaceProcess(multiprocessing.Process): else: contour.SetValue(0, self.min_value) # initial threshold contour.SetValue(1, self.max_value) # final threshold - contour.ComputeScalarsOn() - contour.ComputeGradientsOn() - contour.ComputeNormalsOn() + # contour.ComputeScalarsOn() + # contour.ComputeGradientsOn() + # contour.ComputeNormalsOn() contour.ReleaseDataFlagOn() contour.Update() #contour.AddObserver("ProgressEvent", lambda obj,evt: -- libgit2 0.21.2