Commit 55dd5d8d1e6f5ee614eb8988f1b865435c5ff492

Authored by Paulo Henrique Junqueira Amorim
1 parent ee5249f9

ENH: Removed ItkVtkGlue from main process FIX #85

Showing 1 changed file with 61 additions and 16 deletions   Show diff stats
invesalius/reader/analyze_reader.py
... ... @@ -20,29 +20,32 @@
20 20 import os
21 21  
22 22 import itk
23   -import ItkVtkGlue
  23 +import multiprocessing
  24 +import tempfile
24 25 import vtk
25 26  
26 27  
27 28 def ReadAnalyze(filename):
28   - reader = itk.ImageFileReader.IUC3.New()
  29 +
  30 + pipe_in, pipe_out = multiprocessing.Pipe()
  31 +
  32 + sp = ItktoVtk(pipe_in, filename)
  33 + sp.start()
  34 +
  35 + while 1:
  36 + msg = pipe_out.recv()
  37 + if(msg is None):
  38 + break
  39 +
  40 + filename = pipe_out.recv()
  41 +
  42 + reader = vtk.vtkXMLImageDataReader()
29 43 reader.SetFileName(filename)
30 44 reader.Update()
31   -
32   - x_spacing = reader.GetOutput().GetSpacing().GetElement(0)
33   - y_spacing = reader.GetOutput().GetSpacing().GetElement(1)
34   - z_spacing = reader.GetOutput().GetSpacing().GetElement(2)
35   - spacing = (x_spacing, y_spacing, z_spacing)
36   -
37   - glue = ItkVtkGlue.ImageToVTKImageFilter.IUC3.New()
38   - glue.SetInput(reader.GetOutput())
39   - glue.Update()
40 45  
41   - imagedata = vtk.vtkImageData()
42   - imagedata.DeepCopy(glue.GetOutput())
43   - imagedata.SetSpacing(spacing)
44   -
45   - return imagedata
  46 + os.remove(filename)
  47 +
  48 + return reader.GetOutput()
46 49  
47 50 def ReadDirectory(dir_):
48 51 file_list = []
... ... @@ -54,3 +57,45 @@ def ReadDirectory(dir_):
54 57 imagedata = ReadAnalyze(filename)
55 58 return imagedata
56 59 return imagedata
  60 +
  61 +
  62 +class ItktoVtk(multiprocessing.Process):
  63 +
  64 + def __init__(self, pipe, filename):
  65 + multiprocessing.Process.__init__(self)
  66 + self.filename = filename
  67 + self.pipe = pipe
  68 +
  69 + def run(self):
  70 + self.Convert()
  71 +
  72 + def Convert(self):
  73 +
  74 + import ItkVtkGlue
  75 +
  76 + reader = itk.ImageFileReader.IUC3.New()
  77 + reader.SetFileName(self.filename)
  78 + reader.Update()
  79 +
  80 + x_spacing = reader.GetOutput().GetSpacing().GetElement(0)
  81 + y_spacing = reader.GetOutput().GetSpacing().GetElement(1)
  82 + z_spacing = reader.GetOutput().GetSpacing().GetElement(2)
  83 + spacing = (x_spacing, y_spacing, z_spacing)
  84 +
  85 + glue = ItkVtkGlue.ImageToVTKImageFilter.IUC3.New()
  86 + glue.SetInput(reader.GetOutput())
  87 + glue.Update()
  88 +
  89 + imagedata = vtk.vtkImageData()
  90 + imagedata.DeepCopy(glue.GetOutput())
  91 + imagedata.SetSpacing(spacing)
  92 +
  93 + filename = tempfile.mktemp()
  94 + writer = vtk.vtkXMLImageDataWriter()
  95 + writer.SetInput(imagedata)
  96 + writer.SetFileName(filename)
  97 + writer.Write()
  98 +
  99 + self.pipe.send(None)
  100 + self.pipe.send(filename)
  101 +
57 102 \ No newline at end of file
... ...