Commit a84bfc2023ffaaa389d599e862112e8e9c80b084
1 parent
5323e991
Exists in
master
and in
68 other branches
FIX: Inverted 3D from Coronal Slice (#240)
Showing
3 changed files
with
43 additions
and
25 deletions
Show diff stats
invesalius/data/surface.py
| @@ -431,11 +431,16 @@ class SurfaceManager(): | @@ -431,11 +431,16 @@ class SurfaceManager(): | ||
| 431 | writer.Write() | 431 | writer.Write() |
| 432 | 432 | ||
| 433 | language = ses.Session().language | 433 | language = ses.Session().language |
| 434 | - | 434 | + |
| 435 | + if (prj.Project().original_orientation == const.AXIAL): | ||
| 436 | + flip_image = True | ||
| 437 | + else: | ||
| 438 | + flip_image = False | ||
| 439 | + | ||
| 435 | pipe_in, pipe_out = multiprocessing.Pipe() | 440 | pipe_in, pipe_out = multiprocessing.Pipe() |
| 436 | sp = surface_process.SurfaceProcess(pipe_in, filename_img, mode, min_value, max_value, | 441 | sp = surface_process.SurfaceProcess(pipe_in, filename_img, mode, min_value, max_value, |
| 437 | decimate_reduction, smooth_relaxation_factor, | 442 | decimate_reduction, smooth_relaxation_factor, |
| 438 | - smooth_iterations, language, fill_holes, keep_largest) | 443 | + smooth_iterations, language, fill_holes, keep_largest, flip_image) |
| 439 | sp.start() | 444 | sp.start() |
| 440 | 445 | ||
| 441 | while 1: | 446 | while 1: |
invesalius/data/surface_process.py
| @@ -8,7 +8,8 @@ class SurfaceProcess(multiprocessing.Process): | @@ -8,7 +8,8 @@ class SurfaceProcess(multiprocessing.Process): | ||
| 8 | 8 | ||
| 9 | def __init__(self, pipe, filename, mode, min_value, max_value, | 9 | def __init__(self, pipe, filename, mode, min_value, max_value, |
| 10 | decimate_reduction, smooth_relaxation_factor, | 10 | decimate_reduction, smooth_relaxation_factor, |
| 11 | - smooth_iterations, language, fill_holes, keep_largest): | 11 | + smooth_iterations, language, fill_holes, keep_largest, |
| 12 | + flip_image): | ||
| 12 | 13 | ||
| 13 | multiprocessing.Process.__init__(self) | 14 | multiprocessing.Process.__init__(self) |
| 14 | self.pipe = pipe | 15 | self.pipe = pipe |
| @@ -22,6 +23,7 @@ class SurfaceProcess(multiprocessing.Process): | @@ -22,6 +23,7 @@ class SurfaceProcess(multiprocessing.Process): | ||
| 22 | self.language = language | 23 | self.language = language |
| 23 | self.fill_holes = fill_holes | 24 | self.fill_holes = fill_holes |
| 24 | self.keep_largest = keep_largest | 25 | self.keep_largest = keep_largest |
| 26 | + self.flip_image = flip_image | ||
| 25 | 27 | ||
| 26 | 28 | ||
| 27 | def run(self): | 29 | def run(self): |
| @@ -37,17 +39,21 @@ class SurfaceProcess(multiprocessing.Process): | @@ -37,17 +39,21 @@ class SurfaceProcess(multiprocessing.Process): | ||
| 37 | reader = vtk.vtkXMLImageDataReader() | 39 | reader = vtk.vtkXMLImageDataReader() |
| 38 | reader.SetFileName(self.filename) | 40 | reader.SetFileName(self.filename) |
| 39 | reader.Update() | 41 | reader.Update() |
| 40 | - | ||
| 41 | - # Flip original vtkImageData | ||
| 42 | - flip = vtk.vtkImageFlip() | ||
| 43 | - flip.SetInput(reader.GetOutput()) | ||
| 44 | - flip.SetFilteredAxis(1) | ||
| 45 | - flip.FlipAboutOriginOn() | ||
| 46 | - | 42 | + |
| 43 | + image = reader.GetOutput() | ||
| 44 | + | ||
| 45 | + if (self.flip_image): | ||
| 46 | + # Flip original vtkImageData | ||
| 47 | + flip = vtk.vtkImageFlip() | ||
| 48 | + flip.SetInput(reader.GetOutput()) | ||
| 49 | + flip.SetFilteredAxis(1) | ||
| 50 | + flip.FlipAboutOriginOn() | ||
| 51 | + image = flip.GetOutput() | ||
| 52 | + | ||
| 47 | # Create vtkPolyData from vtkImageData | 53 | # Create vtkPolyData from vtkImageData |
| 48 | if self.mode == "CONTOUR": | 54 | if self.mode == "CONTOUR": |
| 49 | contour = vtk.vtkContourFilter() | 55 | contour = vtk.vtkContourFilter() |
| 50 | - contour.SetInput(flip.GetOutput()) | 56 | + contour.SetInput(image) |
| 51 | contour.SetValue(0, self.min_value) # initial threshold | 57 | contour.SetValue(0, self.min_value) # initial threshold |
| 52 | contour.SetValue(1, self.max_value) # final threshold | 58 | contour.SetValue(1, self.max_value) # final threshold |
| 53 | contour.GetOutput().ReleaseDataFlagOn() | 59 | contour.GetOutput().ReleaseDataFlagOn() |
| @@ -56,7 +62,7 @@ class SurfaceProcess(multiprocessing.Process): | @@ -56,7 +62,7 @@ class SurfaceProcess(multiprocessing.Process): | ||
| 56 | polydata = contour.GetOutput() | 62 | polydata = contour.GetOutput() |
| 57 | else: #mode == "GRAYSCALE": | 63 | else: #mode == "GRAYSCALE": |
| 58 | mcubes = vtk.vtkMarchingCubes() | 64 | mcubes = vtk.vtkMarchingCubes() |
| 59 | - mcubes.SetInput(flip.GetOutput()) | 65 | + mcubes.SetInput(image) |
| 60 | mcubes.SetValue(0, 255) | 66 | mcubes.SetValue(0, 255) |
| 61 | mcubes.ComputeScalarsOn() | 67 | mcubes.ComputeScalarsOn() |
| 62 | mcubes.ComputeGradientsOn() | 68 | mcubes.ComputeGradientsOn() |
invesalius/data/volume.py
| @@ -450,19 +450,26 @@ class Volume(): | @@ -450,19 +450,26 @@ class Volume(): | ||
| 450 | image = proj.imagedata | 450 | image = proj.imagedata |
| 451 | 451 | ||
| 452 | number_filters = len(self.config['convolutionFilters']) | 452 | number_filters = len(self.config['convolutionFilters']) |
| 453 | - update_progress= vtk_utils.ShowProgress(2 + number_filters) | ||
| 454 | - | ||
| 455 | - # Flip original vtkImageData | ||
| 456 | - flip = vtk.vtkImageFlip() | ||
| 457 | - flip.SetInput(image) | ||
| 458 | - flip.SetFilteredAxis(1) | ||
| 459 | - flip.FlipAboutOriginOn() | ||
| 460 | - flip.AddObserver("ProgressEvent", lambda obj,evt: | ||
| 461 | - update_progress(flip, "Rendering...")) | ||
| 462 | - flip.Update() | ||
| 463 | - | ||
| 464 | - image = flip.GetOutput() | ||
| 465 | - | 453 | + |
| 454 | + if (prj.Project().original_orientation == const.AXIAL): | ||
| 455 | + flip_image = True | ||
| 456 | + else: | ||
| 457 | + flip_image = False | ||
| 458 | + | ||
| 459 | + if (flip_image): | ||
| 460 | + update_progress= vtk_utils.ShowProgress(2 + number_filters) | ||
| 461 | + # Flip original vtkImageData | ||
| 462 | + flip = vtk.vtkImageFlip() | ||
| 463 | + flip.SetInput(image) | ||
| 464 | + flip.SetFilteredAxis(1) | ||
| 465 | + flip.FlipAboutOriginOn() | ||
| 466 | + flip.AddObserver("ProgressEvent", lambda obj,evt: | ||
| 467 | + update_progress(flip, "Rendering...")) | ||
| 468 | + flip.Update() | ||
| 469 | + image = flip.GetOutput() | ||
| 470 | + else: | ||
| 471 | + update_progress= vtk_utils.ShowProgress(1 + number_filters) | ||
| 472 | + | ||
| 466 | scale = image.GetScalarRange() | 473 | scale = image.GetScalarRange() |
| 467 | self.scale = scale | 474 | self.scale = scale |
| 468 | 475 |