From a84bfc2023ffaaa389d599e862112e8e9c80b084 Mon Sep 17 00:00:00 2001 From: paulojamorim Date: Fri, 14 May 2010 18:16:10 +0000 Subject: [PATCH] FIX: Inverted 3D from Coronal Slice (#240) --- invesalius/data/surface.py | 9 +++++++-- invesalius/data/surface_process.py | 26 ++++++++++++++++---------- invesalius/data/volume.py | 33 ++++++++++++++++++++------------- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index cb3265e..17fb481 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -431,11 +431,16 @@ class SurfaceManager(): writer.Write() language = ses.Session().language - + + if (prj.Project().original_orientation == const.AXIAL): + flip_image = True + else: + flip_image = False + pipe_in, pipe_out = multiprocessing.Pipe() sp = surface_process.SurfaceProcess(pipe_in, filename_img, mode, min_value, max_value, decimate_reduction, smooth_relaxation_factor, - smooth_iterations, language, fill_holes, keep_largest) + smooth_iterations, language, fill_holes, keep_largest, flip_image) sp.start() while 1: diff --git a/invesalius/data/surface_process.py b/invesalius/data/surface_process.py index bb5c8c4..1c0d31a 100644 --- a/invesalius/data/surface_process.py +++ b/invesalius/data/surface_process.py @@ -8,7 +8,8 @@ class SurfaceProcess(multiprocessing.Process): def __init__(self, pipe, filename, mode, min_value, max_value, decimate_reduction, smooth_relaxation_factor, - smooth_iterations, language, fill_holes, keep_largest): + smooth_iterations, language, fill_holes, keep_largest, + flip_image): multiprocessing.Process.__init__(self) self.pipe = pipe @@ -22,6 +23,7 @@ class SurfaceProcess(multiprocessing.Process): self.language = language self.fill_holes = fill_holes self.keep_largest = keep_largest + self.flip_image = flip_image def run(self): @@ -37,17 +39,21 @@ class SurfaceProcess(multiprocessing.Process): reader = vtk.vtkXMLImageDataReader() reader.SetFileName(self.filename) reader.Update() - - # Flip original vtkImageData - flip = vtk.vtkImageFlip() - flip.SetInput(reader.GetOutput()) - flip.SetFilteredAxis(1) - flip.FlipAboutOriginOn() - + + image = reader.GetOutput() + + if (self.flip_image): + # Flip original vtkImageData + flip = vtk.vtkImageFlip() + flip.SetInput(reader.GetOutput()) + flip.SetFilteredAxis(1) + flip.FlipAboutOriginOn() + image = flip.GetOutput() + # Create vtkPolyData from vtkImageData if self.mode == "CONTOUR": contour = vtk.vtkContourFilter() - contour.SetInput(flip.GetOutput()) + contour.SetInput(image) contour.SetValue(0, self.min_value) # initial threshold contour.SetValue(1, self.max_value) # final threshold contour.GetOutput().ReleaseDataFlagOn() @@ -56,7 +62,7 @@ class SurfaceProcess(multiprocessing.Process): polydata = contour.GetOutput() else: #mode == "GRAYSCALE": mcubes = vtk.vtkMarchingCubes() - mcubes.SetInput(flip.GetOutput()) + mcubes.SetInput(image) mcubes.SetValue(0, 255) mcubes.ComputeScalarsOn() mcubes.ComputeGradientsOn() diff --git a/invesalius/data/volume.py b/invesalius/data/volume.py index 9263f25..0aa369a 100755 --- a/invesalius/data/volume.py +++ b/invesalius/data/volume.py @@ -450,19 +450,26 @@ class Volume(): image = proj.imagedata number_filters = len(self.config['convolutionFilters']) - update_progress= vtk_utils.ShowProgress(2 + number_filters) - - # Flip original vtkImageData - flip = vtk.vtkImageFlip() - flip.SetInput(image) - flip.SetFilteredAxis(1) - flip.FlipAboutOriginOn() - flip.AddObserver("ProgressEvent", lambda obj,evt: - update_progress(flip, "Rendering...")) - flip.Update() - - image = flip.GetOutput() - + + if (prj.Project().original_orientation == const.AXIAL): + flip_image = True + else: + flip_image = False + + if (flip_image): + update_progress= vtk_utils.ShowProgress(2 + number_filters) + # Flip original vtkImageData + flip = vtk.vtkImageFlip() + flip.SetInput(image) + flip.SetFilteredAxis(1) + flip.FlipAboutOriginOn() + flip.AddObserver("ProgressEvent", lambda obj,evt: + update_progress(flip, "Rendering...")) + flip.Update() + image = flip.GetOutput() + else: + update_progress= vtk_utils.ShowProgress(1 + number_filters) + scale = image.GetScalarRange() self.scale = scale -- libgit2 0.21.2