Commit c00a783831e9e39f2d8e3a4b0fa9a7d4c5df5b92

Authored by ruppert
1 parent 1de98e05
Exists in invesalius-libift

Added image processing tools (with ift library)

.gitattributes
@@ -154,6 +154,20 @@ icons/zh_TW.bmp -text @@ -154,6 +154,20 @@ icons/zh_TW.bmp -text
154 invesalius/.svnignore -text 154 invesalius/.svnignore -text
155 invesalius/data/bases.py -text 155 invesalius/data/bases.py -text
156 invesalius/data/co_registration.py -text 156 invesalius/data/co_registration.py -text
  157 +invesalius/libc/__init__.py -text
  158 +invesalius/libc/libalign/__init__.py -text
  159 +invesalius/libc/libalign/libalign.py -text
  160 +invesalius/libc/libift/Makefile -text
  161 +invesalius/libc/libift/__init__.py -text
  162 +invesalius/libc/libift/libift.c -text
  163 +invesalius/libc/libift/libift.i -text
  164 +invesalius/libc/libift/makefile.vc -text
  165 +invesalius/libc/libscnvtk/Makefile -text
  166 +invesalius/libc/libscnvtk/__init__.py -text
  167 +invesalius/libc/libscnvtk/libscnvtk.py -text
  168 +invesalius/libc/libscnvtk/makefile.vc -text
  169 +invesalius/libc/libscnvtk/scnvtk.cxx -text
  170 +invesalius/libc/libscnvtk/scnvtk.i -text
157 locale/de/LC_MESSAGES/invesalius.mo -text 171 locale/de/LC_MESSAGES/invesalius.mo -text
158 locale/el/LC_MESSAGES/invesalius.mo -text 172 locale/el/LC_MESSAGES/invesalius.mo -text
159 locale/en/LC_MESSAGES/invesalius.mo -text 173 locale/en/LC_MESSAGES/invesalius.mo -text
invesalius/constants.py
@@ -430,7 +430,16 @@ VTK_WARNING = 0 @@ -430,7 +430,16 @@ VTK_WARNING = 0
430 430
431 [ID_DICOM_IMPORT, ID_PROJECT_OPEN, ID_PROJECT_SAVE_AS, ID_PROJECT_SAVE, 431 [ID_DICOM_IMPORT, ID_PROJECT_OPEN, ID_PROJECT_SAVE_AS, ID_PROJECT_SAVE,
432 ID_PROJECT_CLOSE, ID_PROJECT_INFO, ID_SAVE_SCREENSHOT, ID_DICOM_LOAD_NET, 432 ID_PROJECT_CLOSE, ID_PROJECT_INFO, ID_SAVE_SCREENSHOT, ID_DICOM_LOAD_NET,
433 -ID_PRINT_SCREENSHOT, ID_EXIT, ID_IMPORT_OTHERS_FILES, ID_ANALYZE_IMPORT] = [wx.NewId() for number in range(12)] 433 +ID_ALIGN, ID_PRINT_SCREENSHOT, ID_EXIT, ID_IMPORT_OTHERS_FILES, ID_EXPORT_OTHERS_FILES, ID_ANALYZE_IMPORT, ID_ANALYZE_EXPORT] = [wx.NewId() for number in range(15)]
  434 +
  435 +ID_GAUSSIAN = wx.NewId()
  436 +ID_MEDIAN = wx.NewId()
  437 +ID_MODE = wx.NewId()
  438 +ID_SOBEL = wx.NewId()
  439 +ID_HISTEQ = wx.NewId()
  440 +ID_INTERP = wx.NewId()
  441 +ID_ERASEBG = wx.NewId()
  442 +ID_ERASESUP = wx.NewId()
434 443
435 444
436 [ID_EDIT_UNDO, ID_EDIT_REDO, ID_EDIT_LIST] =\ 445 [ID_EDIT_UNDO, ID_EDIT_REDO, ID_EDIT_LIST] =\
@@ -493,3 +502,4 @@ STYLE_LEVEL = {SLICE_STATE_EDITOR: 1, @@ -493,3 +502,4 @@ STYLE_LEVEL = {SLICE_STATE_EDITOR: 1,
493 STATE_ZOOM_SL: 2, 502 STATE_ZOOM_SL: 2,
494 STATE_PAN:2, 503 STATE_PAN:2,
495 VOLUME_STATE_SEED:1} 504 VOLUME_STATE_SEED:1}
  505 +
invesalius/control.py
@@ -35,6 +35,9 @@ import reader.analyze_reader as analyze @@ -35,6 +35,9 @@ import reader.analyze_reader as analyze
35 import reader.dicom_grouper as dg 35 import reader.dicom_grouper as dg
36 import reader.dicom_reader as dcm 36 import reader.dicom_reader as dcm
37 import session as ses 37 import session as ses
  38 +import libc.libalign.libalign as libalign
  39 +import libc.libift.libift as libift
  40 +import libc.libscnvtk.libscnvtk as libscnvtk
38 41
39 from utils import debug 42 from utils import debug
40 43
@@ -63,6 +66,16 @@ class Controller(): @@ -63,6 +66,16 @@ class Controller():
63 66
64 ps.Publisher().subscribe(self.OnShowDialogSaveProject, 'Show save dialog') 67 ps.Publisher().subscribe(self.OnShowDialogSaveProject, 'Show save dialog')
65 68
  69 + ps.Publisher().subscribe(self.OnAlignVolume, 'Align volume')
  70 + ps.Publisher().subscribe(self.Tools_Gaussian, 'Tools gaussian')
  71 + ps.Publisher().subscribe(self.Tools_Median, 'Tools median')
  72 + ps.Publisher().subscribe(self.Tools_Mode, 'Tools mode')
  73 + ps.Publisher().subscribe(self.Tools_Sobel, 'Tools sobel')
  74 + ps.Publisher().subscribe(self.Tools_EraseBackground, 'Tools erase background')
  75 + ps.Publisher().subscribe(self.Tools_EraseSupport, 'Tools erase support')
  76 + ps.Publisher().subscribe(self.Tools_HistogramEqualization, 'Tools histogram equalization')
  77 + ps.Publisher().subscribe(self.Tools_Interpolation, 'Tools interpolation')
  78 +
66 ps.Publisher().subscribe(self.LoadRaycastingPreset, 79 ps.Publisher().subscribe(self.LoadRaycastingPreset,
67 'Load raycasting preset') 80 'Load raycasting preset')
68 ps.Publisher().subscribe(self.SaveRaycastingPreset, 81 ps.Publisher().subscribe(self.SaveRaycastingPreset,
@@ -75,7 +88,8 @@ class Controller(): @@ -75,7 +88,8 @@ class Controller():
75 ps.Publisher().subscribe(self.OnShowDialogCloseProject, 'Close Project') 88 ps.Publisher().subscribe(self.OnShowDialogCloseProject, 'Close Project')
76 ps.Publisher().subscribe(self.OnOpenProject, 'Open project') 89 ps.Publisher().subscribe(self.OnOpenProject, 'Open project')
77 ps.Publisher().subscribe(self.OnOpenRecentProject, 'Open recent project') 90 ps.Publisher().subscribe(self.OnOpenRecentProject, 'Open recent project')
78 - ps.Publisher().subscribe(self.OnShowAnalyzeFile, 'Show analyze dialog') 91 + ps.Publisher().subscribe(self.OnShowImportAnalyzeFile, 'Show analyze import dialog')
  92 + ps.Publisher().subscribe(self.OnShowExportAnalyzeFile, 'Show analyze export dialog')
79 93
80 94
81 def OnCancelImport(self, pubsub_evt): 95 def OnCancelImport(self, pubsub_evt):
@@ -84,11 +98,146 @@ class Controller(): @@ -84,11 +98,146 @@ class Controller():
84 98
85 99
86 ########################### 100 ###########################
  101 +
  102 + def OnAlignVolume(self, pubsub_evt):
  103 + #bi = wx.BusyInfo("Working, please wait...", self)
  104 + proj = prj.Project()
  105 + newimg = libalign.VolumeAlign(proj.imagedata)
  106 + #bi.Destroy()
  107 + self.CloseProject()
  108 + self.CreateAnalyzeProject(newimg)
  109 + self.LoadProject()
  110 + ps.Publisher().sendMessage("Enable state project", True)
  111 +
  112 +
  113 +###########################
  114 +
  115 + def Tools_Gaussian(self, pubsub_evt):
  116 + print "Running gaussian smoothing..."
  117 + adj=libift.Spheric(2)
  118 + kernel = libift.GaussianKernel3(adj,2)
  119 + kernel2 = libift.NormalizeKernel3(kernel)
  120 + scn = libscnvtk.VtkImageDataToScene(prj.Project().imagedata)
  121 + flag=libift.ShiftScene(scn)
  122 + scn2 = libift.LinearFilter3(scn,kernel2)
  123 + libift.NewDestroyScene(scn)
  124 + libift.UnShiftScene(scn2,flag)
  125 + newimg = libscnvtk.SceneToVtkImageData(scn2)
  126 + libift.NewDestroyScene(scn2)
  127 + self.CloseProject()
  128 + self.CreateAnalyzeProject(newimg)
  129 + self.LoadProject()
  130 + ps.Publisher().sendMessage("Enable state project", True)
  131 +
  132 + def Tools_Median(self, pubsub_evt):
  133 + print "Running median filter..."
  134 + adj=libift.Spheric(2)
  135 + scn = libscnvtk.VtkImageDataToScene(prj.Project().imagedata)
  136 + flag=libift.ShiftScene(scn)
  137 + scn2 = libift.MedianFilter3(scn,adj)
  138 + libift.NewDestroyScene(scn)
  139 + libift.UnShiftScene(scn2,flag)
  140 + newimg = libscnvtk.SceneToVtkImageData(scn2)
  141 + libift.NewDestroyScene(scn2)
  142 + self.CloseProject()
  143 + self.CreateAnalyzeProject(newimg)
  144 + self.LoadProject()
  145 + ps.Publisher().sendMessage("Enable state project", True)
  146 +
  147 + def Tools_Mode(self, pubsub_evt):
  148 + print "Running mode filter..."
  149 + adj=libift.Spheric(2)
  150 + scn = libscnvtk.VtkImageDataToScene(prj.Project().imagedata)
  151 + flag=libift.ShiftScene(scn)
  152 + scn2 = libift.ModeFilter3(scn,adj)
  153 + libift.NewDestroyScene(scn)
  154 + libift.UnShiftScene(scn2,flag)
  155 + newimg = libscnvtk.SceneToVtkImageData(scn2)
  156 + libift.NewDestroyScene(scn2)
  157 + self.CloseProject()
  158 + self.CreateAnalyzeProject(newimg)
  159 + self.LoadProject()
  160 + ps.Publisher().sendMessage("Enable state project", True)
  161 +
  162 + def Tools_Sobel(self, pubsub_evt):
  163 + print "Running sobel filter..."
  164 + scn = libscnvtk.VtkImageDataToScene(prj.Project().imagedata)
  165 + flag=libift.ShiftScene(scn)
  166 + scn2 = libift.SobelFilter3(scn)
  167 + libift.NewDestroyScene(scn)
  168 + libift.UnShiftScene(scn2,flag)
  169 + newimg = libscnvtk.SceneToVtkImageData(scn2)
  170 + libift.NewDestroyScene(scn2)
  171 + self.CloseProject()
  172 + self.CreateAnalyzeProject(newimg)
  173 + self.LoadProject()
  174 + ps.Publisher().sendMessage("Enable state project", True)
  175 +
  176 + def Tools_EraseBackground(self, pubsub_evt):
  177 + print "Running erase background..."
  178 + scn = libscnvtk.VtkImageDataToScene(prj.Project().imagedata)
  179 + flag=libift.ShiftScene(scn)
  180 + scn2 = libift.EraseBackground(scn)
  181 + libift.NewDestroyScene(scn)
  182 + libift.UnShiftScene(scn2,flag)
  183 + newimg = libscnvtk.SceneToVtkImageData(scn2)
  184 + libift.NewDestroyScene(scn2)
  185 + self.CloseProject()
  186 + self.CreateAnalyzeProject(newimg)
  187 + self.LoadProject()
  188 + ps.Publisher().sendMessage("Enable state project", True)
  189 +
  190 + def Tools_EraseSupport(self, pubsub_evt):
  191 + print "Running erase support..."
  192 + scn = libscnvtk.VtkImageDataToScene(prj.Project().imagedata)
  193 + flag=libift.ShiftScene(scn)
  194 + scn2 = libift.EraseSupport(scn)
  195 + libift.NewDestroyScene(scn)
  196 + libift.UnShiftScene(scn2,flag)
  197 + newimg = libscnvtk.SceneToVtkImageData(scn2)
  198 + libift.NewDestroyScene(scn2)
  199 + self.CloseProject()
  200 + self.CreateAnalyzeProject(newimg)
  201 + self.LoadProject()
  202 + ps.Publisher().sendMessage("Enable state project", True)
  203 +
  204 + def Tools_HistogramEqualization(self, pubsub_evt):
  205 + print "Running histogram equalization..."
  206 + scn = libscnvtk.VtkImageDataToScene(prj.Project().imagedata)
  207 + flag=libift.ShiftScene(scn)
  208 + scn2 = libift.Equalize3(scn,4095)
  209 + libift.NewDestroyScene(scn)
  210 + libift.UnShiftScene(scn2,flag)
  211 + newimg = libscnvtk.SceneToVtkImageData(scn2)
  212 + libift.NewDestroyScene(scn2)
  213 + self.CloseProject()
  214 + self.CreateAnalyzeProject(newimg)
  215 + self.LoadProject()
  216 + ps.Publisher().sendMessage("Enable state project", True)
  217 +
  218 + def Tools_Interpolation(self, pubsub_evt):
  219 + print "Running histogram equalization..."
  220 + scn = libscnvtk.VtkImageDataToScene(prj.Project().imagedata)
  221 + scn2 = libift.LinearInterp(scn,0,0,0)
  222 + libift.NewDestroyScene(scn)
  223 + newimg = libscnvtk.SceneToVtkImageData(scn2)
  224 + libift.NewDestroyScene(scn2)
  225 + self.CloseProject()
  226 + self.CreateAnalyzeProject(newimg)
  227 + self.LoadProject()
  228 + ps.Publisher().sendMessage("Enable state project", True)
  229 +
  230 +
  231 +
  232 +###########################
87 ########################### 233 ###########################
88 234
89 def OnShowDialogImportDirectory(self, pubsub_evt): 235 def OnShowDialogImportDirectory(self, pubsub_evt):
90 self.ShowDialogImportDirectory() 236 self.ShowDialogImportDirectory()
91 237
  238 + # def OnShowDialogImportAnalyze(self, pubsub_evt):
  239 + # self.ShowDialogImportAnalyze()
  240 +
92 def OnShowDialogOpenProject(self, pubsub_evt): 241 def OnShowDialogOpenProject(self, pubsub_evt):
93 self.ShowDialogOpenProject() 242 self.ShowDialogOpenProject()
94 243
@@ -99,15 +248,24 @@ class Controller(): @@ -99,15 +248,24 @@ class Controller():
99 def OnShowDialogCloseProject(self, pubsub_evt): 248 def OnShowDialogCloseProject(self, pubsub_evt):
100 self.ShowDialogCloseProject() 249 self.ShowDialogCloseProject()
101 250
102 - def OnShowAnalyzeFile(self, pubsub_evt): 251 + def OnShowImportAnalyzeFile(self, pubsub_evt):
103 dirpath = dialog.ShowOpenAnalyzeDialog() 252 dirpath = dialog.ShowOpenAnalyzeDialog()
104 imagedata = analyze.ReadAnalyze(dirpath) 253 imagedata = analyze.ReadAnalyze(dirpath)
105 if imagedata: 254 if imagedata:
106 self.CreateAnalyzeProject(imagedata) 255 self.CreateAnalyzeProject(imagedata)
107 -  
108 self.LoadProject() 256 self.LoadProject()
109 ps.Publisher().sendMessage("Enable state project", True) 257 ps.Publisher().sendMessage("Enable state project", True)
110 258
  259 + def OnShowExportAnalyzeFile(self, pubsub_evt):
  260 + dirpath = dialog.ShowSaveAnalyzeDialog()
  261 + proj = prj.Project()
  262 + name=dirpath.encode('utf-8')
  263 + libalign.libscnvtk.WriteVtkImageData(proj.imagedata,name)
  264 + wx.MessageBox(_("Written successfully!"), 'Info')
  265 +
  266 +
  267 +
  268 +
111 269
112 ########################### 270 ###########################
113 271
@@ -127,7 +285,8 @@ class Controller(): @@ -127,7 +285,8 @@ class Controller():
127 dialog.ImportEmptyDirectory(dirpath) 285 dialog.ImportEmptyDirectory(dirpath)
128 elif dirpath: 286 elif dirpath:
129 self.StartImportPanel(dirpath) 287 self.StartImportPanel(dirpath)
130 - ps.Publisher().sendMessage("Load data to import panel", dirpath) 288 + #ps.Publisher().sendMessage("Load data to import panel", dirpath)
  289 +
131 290
132 def ShowDialogOpenProject(self): 291 def ShowDialogOpenProject(self):
133 # Offer to save current project if necessary 292 # Offer to save current project if necessary
invesalius/gui/dialogs.py
@@ -192,6 +192,34 @@ def ShowOpenAnalyzeDialog(): @@ -192,6 +192,34 @@ def ShowOpenAnalyzeDialog():
192 os.chdir(current_dir) 192 os.chdir(current_dir)
193 return filepath 193 return filepath
194 194
  195 +def ShowSaveAnalyzeDialog():
  196 + # Default system path
  197 + current_dir = os.path.abspath(".")
  198 + dlg = wx.FileDialog(None, message=_("Export Analyze File..."),
  199 + defaultDir="",
  200 + defaultFile="", wildcard=WILDCARD_ANALYZE,
  201 + style=wx.SAVE|wx.CHANGE_DIR)
  202 +
  203 + # inv3 filter is default
  204 + dlg.SetFilterIndex(0)
  205 +
  206 + # Show the dialog and retrieve the user response. If it is the OK response,
  207 + # process the data.
  208 + filepath = None
  209 + try:
  210 + if dlg.ShowModal() == wx.ID_OK:
  211 + # This returns a Python list of files that were selected.
  212 + filepath = dlg.GetPath()
  213 + except(wx._core.PyAssertionError): #FIX: win64
  214 + filepath = dlg.GetPath()
  215 +
  216 + # Destroy the dialog. Don't do this until you are done with it!
  217 + # BAD things can happen otherwise!
  218 + dlg.Destroy()
  219 + os.chdir(current_dir)
  220 + return filepath
  221 +
  222 +
195 223
196 def ShowImportDirDialog(): 224 def ShowImportDirDialog():
197 current_dir = os.path.abspath(".") 225 current_dir = os.path.abspath(".")
invesalius/gui/frame.py
@@ -145,11 +145,13 @@ class Frame(wx.Frame): @@ -145,11 +145,13 @@ class Frame(wx.Frame):
145 t2 = LayoutToolBar(self) 145 t2 = LayoutToolBar(self)
146 t3 = ObjectToolBar(self) 146 t3 = ObjectToolBar(self)
147 t4 = SliceToolBar(self) 147 t4 = SliceToolBar(self)
  148 + t5 = ImageProcessingToolBar(self)
148 else: 149 else:
149 - t4 = ProjectToolBar(self)  
150 - t3 = LayoutToolBar(self)  
151 - t2 = ObjectToolBar(self)  
152 - t1 = SliceToolBar(self) 150 + t5 = ProjectToolBar(self)
  151 + t4 = LayoutToolBar(self)
  152 + t3 = ObjectToolBar(self)
  153 + t2 = SliceToolBar(self)
  154 + t1 = ImageProcessingToolBar(self)
153 155
154 aui_manager.AddPane(t1, wx.aui.AuiPaneInfo(). 156 aui_manager.AddPane(t1, wx.aui.AuiPaneInfo().
155 Name("General Features Toolbar"). 157 Name("General Features Toolbar").
@@ -171,6 +173,11 @@ class Frame(wx.Frame): @@ -171,6 +173,11 @@ class Frame(wx.Frame):
171 ToolbarPane().Top().Floatable(False). 173 ToolbarPane().Top().Floatable(False).
172 LeftDockable(False).RightDockable(False)) 174 LeftDockable(False).RightDockable(False))
173 175
  176 + aui_manager.AddPane(t5, wx.aui.AuiPaneInfo().
  177 + Name("Image Processing Toolbar").
  178 + ToolbarPane().Top().Floatable(False).
  179 + LeftDockable(False).RightDockable(False))
  180 +
174 aui_manager.Update() 181 aui_manager.Update()
175 self.aui_manager = aui_manager 182 self.aui_manager = aui_manager
176 183
@@ -296,12 +303,32 @@ class Frame(wx.Frame): @@ -296,12 +303,32 @@ class Frame(wx.Frame):
296 self.ShowOpenProject() 303 self.ShowOpenProject()
297 elif id == const.ID_ANALYZE_IMPORT: 304 elif id == const.ID_ANALYZE_IMPORT:
298 self.ShowAnalyzeImporter() 305 self.ShowAnalyzeImporter()
  306 + elif id == const.ID_ANALYZE_EXPORT:
  307 + self.ShowAnalyzeExporter()
299 elif id == const.ID_PROJECT_SAVE: 308 elif id == const.ID_PROJECT_SAVE:
300 session = ses.Session() 309 session = ses.Session()
301 if session.temp_item: 310 if session.temp_item:
302 self.ShowSaveAsProject() 311 self.ShowSaveAsProject()
303 else: 312 else:
304 self.SaveProject() 313 self.SaveProject()
  314 + elif id == const.ID_ALIGN:
  315 + self.AlignVolume()
  316 + elif id == const.ID_GAUSSIAN:
  317 + self.Tools_Gaussian()
  318 + elif id == const.ID_MEDIAN:
  319 + self.Tools_Median()
  320 + elif id == const.ID_MODE:
  321 + self.Tools_Mode()
  322 + elif id == const.ID_SOBEL:
  323 + self.Tools_Sobel()
  324 + elif id == const.ID_ERASEBG:
  325 + self.Tools_EraseBackground()
  326 + elif id == const.ID_ERASESUP:
  327 + self.Tools_EraseSupport()
  328 + elif id == const.ID_HISTEQ:
  329 + self.Tools_HistogramEqualization()
  330 + elif id == const.ID_INTERP:
  331 + self.Tools_Interpolation()
305 elif id == const.ID_PROJECT_SAVE_AS: 332 elif id == const.ID_PROJECT_SAVE_AS:
306 self.ShowSaveAsProject() 333 self.ShowSaveAsProject()
307 elif id == const.ID_PROJECT_CLOSE: 334 elif id == const.ID_PROJECT_CLOSE:
@@ -326,6 +353,60 @@ class Frame(wx.Frame): @@ -326,6 +353,60 @@ class Frame(wx.Frame):
326 """ 353 """
327 dlg.ShowAboutDialog(self) 354 dlg.ShowAboutDialog(self)
328 355
  356 + def AlignVolume(self):
  357 + """
  358 + Align the image.
  359 + """
  360 + ps.Publisher().sendMessage('Align volume')
  361 +
  362 + def Tools_Gaussian(self):
  363 + """
  364 + Gaussian Smoothing.
  365 + """
  366 + ps.Publisher().sendMessage('Tools gaussian')
  367 +
  368 + def Tools_Median(self):
  369 + """
  370 + Median Filter
  371 + """
  372 + ps.Publisher().sendMessage('Tools median')
  373 +
  374 + def Tools_Mode(self):
  375 + """
  376 + Mode Filter
  377 + """
  378 + ps.Publisher().sendMessage('Tools mode')
  379 +
  380 + def Tools_Sobel(self):
  381 + """
  382 + Sobel Filter
  383 + """
  384 + ps.Publisher().sendMessage('Tools sobel')
  385 +
  386 + def Tools_EraseBackground(self):
  387 + """
  388 + Erase background
  389 + """
  390 + ps.Publisher().sendMessage('Tools erase background')
  391 +
  392 + def Tools_EraseSupport(self):
  393 + """
  394 + Erase support
  395 + """
  396 + ps.Publisher().sendMessage('Tools erase support')
  397 +
  398 + def Tools_HistogramEqualization(self):
  399 + """
  400 + Histogram Equalization
  401 + """
  402 + ps.Publisher().sendMessage('Tools histogram equalization')
  403 +
  404 + def Tools_Interpolation(self):
  405 + """
  406 + Interpolation
  407 + """
  408 + ps.Publisher().sendMessage('Tools interpolation')
  409 +
329 def SaveProject(self): 410 def SaveProject(self):
330 """ 411 """
331 Save project. 412 Save project.
@@ -362,7 +443,13 @@ class Frame(wx.Frame): @@ -362,7 +443,13 @@ class Frame(wx.Frame):
362 """ 443 """
363 Show save as dialog. 444 Show save as dialog.
364 """ 445 """
365 - ps.Publisher().sendMessage('Show analyze dialog', True) 446 + ps.Publisher().sendMessage('Show analyze import dialog', True)
  447 +
  448 + def ShowAnalyzeExporter(self):
  449 + """
  450 + Show save as dialog.
  451 + """
  452 + ps.Publisher().sendMessage('Show analyze export dialog', True)
366 453
367 # ------------------------------------------------------------------ 454 # ------------------------------------------------------------------
368 # ------------------------------------------------------------------ 455 # ------------------------------------------------------------------
@@ -406,14 +493,19 @@ class MenuBar(wx.MenuBar): @@ -406,14 +493,19 @@ class MenuBar(wx.MenuBar):
406 # TODO: This definetely needs improvements... ;) 493 # TODO: This definetely needs improvements... ;)
407 494
408 #Import Others Files 495 #Import Others Files
409 - others_file_menu = wx.Menu()  
410 - others_file_menu.Append(const.ID_ANALYZE_IMPORT, "Analyze") 496 + others_import_file_menu = wx.Menu()
  497 + others_import_file_menu.Append(const.ID_ANALYZE_IMPORT, "Analyze")
  498 +
  499 + #Import Others Files
  500 + others_export_file_menu = wx.Menu()
  501 + others_export_file_menu.Append(const.ID_ANALYZE_EXPORT, "Analyze")
411 502
412 # FILE 503 # FILE
413 file_menu = wx.Menu() 504 file_menu = wx.Menu()
414 app = file_menu.Append 505 app = file_menu.Append
415 app(const.ID_DICOM_IMPORT, _("Import DICOM...\tCtrl+I")) 506 app(const.ID_DICOM_IMPORT, _("Import DICOM...\tCtrl+I"))
416 - file_menu.AppendMenu(const.ID_IMPORT_OTHERS_FILES, _("Import Others Files"), others_file_menu) 507 + file_menu.AppendMenu(const.ID_IMPORT_OTHERS_FILES, _("Import Other Files"), others_import_file_menu)
  508 + file_menu.AppendMenu(const.ID_EXPORT_OTHERS_FILES, _("Export Other Files"), others_export_file_menu)
417 app(const.ID_PROJECT_OPEN, _("Open Project...\tCtrl+O")) 509 app(const.ID_PROJECT_OPEN, _("Open Project...\tCtrl+O"))
418 app(const.ID_PROJECT_SAVE, _("Save Project\tCtrl+S")) 510 app(const.ID_PROJECT_SAVE, _("Save Project\tCtrl+S"))
419 app(const.ID_PROJECT_SAVE_AS, _("Save Project As...")) 511 app(const.ID_PROJECT_SAVE_AS, _("Save Project As..."))
@@ -461,7 +553,16 @@ class MenuBar(wx.MenuBar): @@ -461,7 +553,16 @@ class MenuBar(wx.MenuBar):
461 #app(const.ID_VIEW_3D_BACKGROUND, "3D Background Colour") 553 #app(const.ID_VIEW_3D_BACKGROUND, "3D Background Colour")
462 554
463 # TOOLS 555 # TOOLS
464 - #tools_menu = wx.Menu() 556 + tools_menu = wx.Menu()
  557 + tools_menu.Append(const.ID_ALIGN, _("Symmetry Alignment"))
  558 + tools_menu.Append(const.ID_GAUSSIAN, _("Gaussian Smoothing"))
  559 + tools_menu.Append(const.ID_MEDIAN, _("Median Filter"))
  560 + tools_menu.Append(const.ID_MODE, _("Mode Filter"))
  561 + tools_menu.Append(const.ID_SOBEL, _("Sobel Filter"))
  562 + tools_menu.Append(const.ID_HISTEQ, _("Histogram Equalization"))
  563 + tools_menu.Append(const.ID_INTERP, _("Isotropic Interpolation"))
  564 + tools_menu.Append(const.ID_ERASEBG, _("Erase Background"))
  565 + tools_menu.Append(const.ID_ERASESUP, _("Erase Head Support"))
465 566
466 # OPTIONS 567 # OPTIONS
467 #options_menu = wx.Menu() 568 #options_menu = wx.Menu()
@@ -491,7 +592,7 @@ class MenuBar(wx.MenuBar): @@ -491,7 +592,7 @@ class MenuBar(wx.MenuBar):
491 self.Append(file_menu, _("File")) 592 self.Append(file_menu, _("File"))
492 #self.Append(file_edit, "Edit") 593 #self.Append(file_edit, "Edit")
493 #self.Append(view_menu, "View") 594 #self.Append(view_menu, "View")
494 - #self.Append(tools_menu, "Tools") 595 + self.Append(tools_menu, "Tools")
495 #self.Append(options_menu, "Options") 596 #self.Append(options_menu, "Options")
496 self.Append(help_menu, _("Help")) 597 self.Append(help_menu, _("Help"))
497 598
@@ -644,6 +745,8 @@ class TaskBarIcon(wx.TaskBarIcon): @@ -644,6 +745,8 @@ class TaskBarIcon(wx.TaskBarIcon):
644 def OnTaskBarActivate(self, evt): 745 def OnTaskBarActivate(self, evt):
645 pass 746 pass
646 747
  748 +
  749 +
647 # ------------------------------------------------------------------ 750 # ------------------------------------------------------------------
648 # ------------------------------------------------------------------ 751 # ------------------------------------------------------------------
649 # ------------------------------------------------------------------ 752 # ------------------------------------------------------------------
@@ -771,11 +874,11 @@ class ProjectToolBar(wx.ToolBar): @@ -771,11 +874,11 @@ class ProjectToolBar(wx.ToolBar):
771 self.EnableTool(tool, True) 874 self.EnableTool(tool, True)
772 875
773 876
774 -  
775 # ------------------------------------------------------------------ 877 # ------------------------------------------------------------------
776 # ------------------------------------------------------------------ 878 # ------------------------------------------------------------------
777 # ------------------------------------------------------------------ 879 # ------------------------------------------------------------------
778 880
  881 +
779 class ObjectToolBar(wx.ToolBar): 882 class ObjectToolBar(wx.ToolBar):
780 """ 883 """
781 Toolbar related to general object operations, including: zoom 884 Toolbar related to general object operations, including: zoom
@@ -1307,3 +1410,87 @@ class LayoutToolBar(wx.ToolBar): @@ -1307,3 +1410,87 @@ class LayoutToolBar(wx.ToolBar):
1307 ps.Publisher().sendMessage('Update AUI') 1410 ps.Publisher().sendMessage('Update AUI')
1308 self.ontool_text = True 1411 self.ontool_text = True
1309 1412
  1413 +# ------------------------------------------------------------------
  1414 +# ------------------------------------------------------------------
  1415 +# ------------------------------------------------------------------
  1416 +
  1417 +class ImageProcessingToolBar(wx.ToolBar):
  1418 + """
  1419 + Toolbar related to general project operations, including: import,
  1420 + open, save and saveas, among others.
  1421 + """
  1422 + def __init__(self, parent):
  1423 + style = wx.TB_FLAT|wx.TB_NODIVIDER| wx.TB_DOCKABLE
  1424 + wx.ToolBar.__init__(self, parent, -1, wx.DefaultPosition,
  1425 + wx.DefaultSize,
  1426 + style)
  1427 + self.SetToolBitmapSize(wx.Size(32,32))
  1428 +
  1429 + self.parent = parent
  1430 +
  1431 + # Used to enable/disable menu items if project is opened or
  1432 + # not. Eg. save should only be available if a project is open
  1433 + self.enable_items = [const.ID_ALIGN]
  1434 +
  1435 + self.__init_items()
  1436 + self.__bind_events()
  1437 +
  1438 + self.Realize()
  1439 + self.SetStateProjectClose()
  1440 +
  1441 + def __bind_events(self):
  1442 + """
  1443 + Bind events related to pubsub.
  1444 + """
  1445 + sub = ps.Publisher().subscribe
  1446 + sub(self._EnableState, "Enable state project")
  1447 +
  1448 + def __init_items(self):
  1449 + """
  1450 + Add tools into toolbar.
  1451 + """
  1452 + # Load bitmaps
  1453 + d = const.ICON_DIR
  1454 + if sys.platform == 'darwin':
  1455 + path = os.path.join(d, "ip_align_original.png")
  1456 + BMP_SAVE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
  1457 + else:
  1458 + path = os.path.join(d, "ip_align.png")
  1459 + BMP_SAVE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
  1460 +
  1461 + # Create tool items based on bitmaps
  1462 + self.AddLabelTool(const.ID_ALIGN,
  1463 + "",
  1464 + shortHelp = _("Symmetry Alignment"),
  1465 + bitmap=BMP_SAVE)
  1466 +
  1467 +
  1468 + def _EnableState(self, pubsub_evt):
  1469 + """
  1470 + Based on given state, enable or disable menu items which
  1471 + depend if project is open or not.
  1472 + """
  1473 + state = pubsub_evt.data
  1474 + if state:
  1475 + self.SetStateProjectOpen()
  1476 + else:
  1477 + self.SetStateProjectClose()
  1478 +
  1479 + def SetStateProjectClose(self):
  1480 + """
  1481 + Disable menu items (e.g. save) when project is closed.
  1482 + """
  1483 + for tool in self.enable_items:
  1484 + self.EnableTool(tool, False)
  1485 +
  1486 + def SetStateProjectOpen(self):
  1487 + """
  1488 + Enable menu items (e.g. save) when project is opened.
  1489 + """
  1490 + for tool in self.enable_items:
  1491 + self.EnableTool(tool, True)
  1492 +
  1493 +
  1494 +# ------------------------------------------------------------------
  1495 +# ------------------------------------------------------------------
  1496 +# ------------------------------------------------------------------
invesalius/gui/task_importer.py
@@ -28,6 +28,7 @@ import constants as const @@ -28,6 +28,7 @@ import constants as const
28 import gui.dialogs as dlg 28 import gui.dialogs as dlg
29 29
30 BTN_IMPORT_LOCAL = wx.NewId() 30 BTN_IMPORT_LOCAL = wx.NewId()
  31 +#BTN_IMPORT_ANA = wx.NewId()
31 BTN_IMPORT_PACS = wx.NewId() 32 BTN_IMPORT_PACS = wx.NewId()
32 BTN_OPEN_PROJECT = wx.NewId() 33 BTN_OPEN_PROJECT = wx.NewId()
33 34
@@ -61,8 +62,8 @@ class InnerTaskPanel(wx.Panel): @@ -61,8 +62,8 @@ class InnerTaskPanel(wx.Panel):
61 self.float_hyper_list = [] 62 self.float_hyper_list = []
62 63
63 # Fixed hyperlink items 64 # Fixed hyperlink items
64 - tooltip = wx.ToolTip(_("Select DICOM or Analyze files to be reconstructed"))  
65 - link_import_local = hl.HyperLinkCtrl(self, -1, _("Import medical images...")) 65 + tooltip = wx.ToolTip(_("Select DICOM to be reconstructed"))
  66 + link_import_local = hl.HyperLinkCtrl(self, -1, _("Import DICOM image..."))
66 link_import_local.SetUnderlines(False, False, False) 67 link_import_local.SetUnderlines(False, False, False)
67 link_import_local.SetColours("BLACK", "BLACK", "BLACK") 68 link_import_local.SetColours("BLACK", "BLACK", "BLACK")
68 link_import_local.SetToolTip(tooltip) 69 link_import_local.SetToolTip(tooltip)
@@ -70,6 +71,15 @@ class InnerTaskPanel(wx.Panel): @@ -70,6 +71,15 @@ class InnerTaskPanel(wx.Panel):
70 link_import_local.UpdateLink() 71 link_import_local.UpdateLink()
71 link_import_local.Bind(hl.EVT_HYPERLINK_LEFT, self.OnLinkImport) 72 link_import_local.Bind(hl.EVT_HYPERLINK_LEFT, self.OnLinkImport)
72 73
  74 + #tooltip = wx.ToolTip(_("Select Analyze file to be reconstructed"))
  75 + #link_import_ana = hl.HyperLinkCtrl(self, -1, _("Import Analyze image..."))
  76 + #link_import_ana.SetUnderlines(False, False, False)
  77 + #link_import_ana.SetColours("BLACK", "BLACK", "BLACK")
  78 + #link_import_ana.SetToolTip(tooltip)
  79 + #link_import_ana.AutoBrowse(False)
  80 + #link_import_ana.UpdateLink()
  81 + #link_import_ana.Bind(hl.EVT_HYPERLINK_LEFT, self.OnLinkImportAnalyze)
  82 +
73 #tooltip = wx.ToolTip("Import DICOM files from PACS server") 83 #tooltip = wx.ToolTip("Import DICOM files from PACS server")
74 #link_import_pacs = hl.HyperLinkCtrl(self, -1,"Load from PACS server...") 84 #link_import_pacs = hl.HyperLinkCtrl(self, -1,"Load from PACS server...")
75 #link_import_pacs.SetUnderlines(False, False, False) 85 #link_import_pacs.SetUnderlines(False, False, False)
@@ -105,6 +115,8 @@ class InnerTaskPanel(wx.Panel): @@ -105,6 +115,8 @@ class InnerTaskPanel(wx.Panel):
105 # style=button_style) 115 # style=button_style)
106 button_import_local = pbtn.PlateButton(self, BTN_IMPORT_LOCAL, "", 116 button_import_local = pbtn.PlateButton(self, BTN_IMPORT_LOCAL, "",
107 BMP_IMPORT, style=button_style) 117 BMP_IMPORT, style=button_style)
  118 + #button_import_ana = pbtn.PlateButton(self, BTN_IMPORT_ANA, "",
  119 + # BMP_IMPORT, style=button_style)
108 button_open_proj = pbtn.PlateButton(self, BTN_OPEN_PROJECT, "", 120 button_open_proj = pbtn.PlateButton(self, BTN_OPEN_PROJECT, "",
109 BMP_OPEN_PROJECT, style=button_style) 121 BMP_OPEN_PROJECT, style=button_style)
110 122
@@ -122,6 +134,8 @@ class InnerTaskPanel(wx.Panel): @@ -122,6 +134,8 @@ class InnerTaskPanel(wx.Panel):
122 #(button_import_pacs, 0, flag_button), 134 #(button_import_pacs, 0, flag_button),
123 (link_import_local, 1, flag_link, 3), 135 (link_import_local, 1, flag_link, 3),
124 (button_import_local, 0, flag_button), 136 (button_import_local, 0, flag_button),
  137 + #(link_import_ana, 1, flag_link, 3),
  138 + #(button_import_ana, 0, flag_button),
125 (link_open_proj, 1, flag_link, 3), 139 (link_open_proj, 1, flag_link, 3),
126 (button_open_proj, 0, flag_button) ]) 140 (button_open_proj, 0, flag_button) ])
127 141
@@ -202,6 +216,10 @@ class InnerTaskPanel(wx.Panel): @@ -202,6 +216,10 @@ class InnerTaskPanel(wx.Panel):
202 self.ImportDicom() 216 self.ImportDicom()
203 event.Skip() 217 event.Skip()
204 218
  219 + def OnLinkImportAnalyze(self, event):
  220 + self.ImportAnalyze()
  221 + event.Skip()
  222 +
205 def OnLinkImportPACS(self, event): 223 def OnLinkImportPACS(self, event):
206 self.ImportPACS() 224 self.ImportPACS()
207 event.Skip() 225 event.Skip()
@@ -219,6 +237,9 @@ class InnerTaskPanel(wx.Panel): @@ -219,6 +237,9 @@ class InnerTaskPanel(wx.Panel):
219 def ImportDicom(self): 237 def ImportDicom(self):
220 ps.Publisher().sendMessage('Show import directory dialog') 238 ps.Publisher().sendMessage('Show import directory dialog')
221 239
  240 + def ImportAnalyze(self):
  241 + ps.Publisher().sendMessage('Show import analyze dialog')
  242 +
222 def OpenProject(self, path=None): 243 def OpenProject(self, path=None):
223 if path: 244 if path:
224 ps.Publisher().sendMessage('Open recent project', path) 245 ps.Publisher().sendMessage('Open recent project', path)
@@ -240,6 +261,8 @@ class InnerTaskPanel(wx.Panel): @@ -240,6 +261,8 @@ class InnerTaskPanel(wx.Panel):
240 261
241 if id == BTN_IMPORT_LOCAL: 262 if id == BTN_IMPORT_LOCAL:
242 self.ImportDicom() 263 self.ImportDicom()
  264 + #elif id == BTN_IMPORT_ANA:
  265 + # self.ImportAnalyze()
243 elif id == BTN_IMPORT_PACS: 266 elif id == BTN_IMPORT_PACS:
244 self.ImportPACS() 267 self.ImportPACS()
245 else: #elif id == BTN_OPEN_PROJECT: 268 else: #elif id == BTN_OPEN_PROJECT:
invesalius/libc/__init__.py 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +#--------------------------------------------------------------------------
  2 +# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
  3 +# Copyright: (C) 2001 Centro de Pesquisas Renato Archer
  4 +# Homepage: http://www.softwarepublico.gov.br
  5 +# Contact: invesalius@cti.gov.br
  6 +# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
  7 +#--------------------------------------------------------------------------
  8 +# Este programa e software livre; voce pode redistribui-lo e/ou
  9 +# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
  10 +# publicada pela Free Software Foundation; de acordo com a versao 2
  11 +# da Licenca.
  12 +#
  13 +# Este programa eh distribuido na expectativa de ser util, mas SEM
  14 +# QUALQUER GARANTIA; sem mesmo a garantia implicita de
  15 +# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
  16 +# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
  17 +# detalhes.
  18 +#--------------------------------------------------------------------------
invesalius/libc/libalign/__init__.py 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +#--------------------------------------------------------------------------
  2 +# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
  3 +# Copyright: (C) 2001 Centro de Pesquisas Renato Archer
  4 +# Homepage: http://www.softwarepublico.gov.br
  5 +# Contact: invesalius@cti.gov.br
  6 +# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
  7 +#--------------------------------------------------------------------------
  8 +# Este programa e software livre; voce pode redistribui-lo e/ou
  9 +# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
  10 +# publicada pela Free Software Foundation; de acordo com a versao 2
  11 +# da Licenca.
  12 +#
  13 +# Este programa eh distribuido na expectativa de ser util, mas SEM
  14 +# QUALQUER GARANTIA; sem mesmo a garantia implicita de
  15 +# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
  16 +# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
  17 +# detalhes.
  18 +#--------------------------------------------------------------------------
invesalius/libc/libalign/libalign.py 0 → 100644
@@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
  1 +
  2 +
  3 +from ..libift import libift as libift
  4 +from ..libscnvtk import libscnvtk as libscnvtk
  5 +
  6 +
  7 +def VolumeAlign(img):
  8 + scn = libscnvtk.VtkImageDataToScene(img)
  9 + print "VolumeAlign()"
  10 + scn2 = libift.MSP_Align(scn,None,0,1)
  11 + return libscnvtk.SceneToVtkImageData(scn2)
  12 +
  13 +
  14 +
  15 +def Interp(img):
  16 + scn = libscnvtk.VtkImageDataToScene(img)
  17 + scn2=libift.LinearInterp(scn,0,0,0)
  18 + return libscnvtk.SceneToVtkImageData(scn2)
  19 +
invesalius/libc/libift/Makefile 0 → 100644
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
  1 +
  2 +
  3 +PROG=libift
  4 +#IFT_DIR=~/ift
  5 +#VTK_DIR=/hd2/lib/VTK
  6 +
  7 +
  8 +all: _${PROG}.so
  9 +
  10 +_${PROG}.so: ${PROG}.i ${PROG}.c
  11 + @echo "Generating wrappers..."
  12 + @swig -python ${PROG}.i
  13 + @echo "Compiling..."
  14 + @gcc -c ${PROG}.c ${PROG}_wrap.c -I/usr/include/python2.6 -I${OPF_DIR}/include -I${IFT_DIR}/include -L${IFT_DIR}/lib/ -lift -Wno-deprecated
  15 + @echo "Linking..."
  16 + @gcc -shared ${PROG}.o ${PROG}_wrap.o -o _${PROG}.so -L${IFT_DIR}/lib/ -lift
  17 + @echo "Done."
  18 +
  19 +
  20 +clean:
  21 + rm ${PROG}.o ${PROG}.py ${PROG}_wrap.c ${PROG}_wrap.o ${PROG}.py _${PROG}.so *.pyc *.obj *.pyd *.exp *.lib *~
  22 +
  23 +
  24 +
  25 +
invesalius/libc/libift/__init__.py 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +#--------------------------------------------------------------------------
  2 +# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
  3 +# Copyright: (C) 2001 Centro de Pesquisas Renato Archer
  4 +# Homepage: http://www.softwarepublico.gov.br
  5 +# Contact: invesalius@cti.gov.br
  6 +# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
  7 +#--------------------------------------------------------------------------
  8 +# Este programa e software livre; voce pode redistribui-lo e/ou
  9 +# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
  10 +# publicada pela Free Software Foundation; de acordo com a versao 2
  11 +# da Licenca.
  12 +#
  13 +# Este programa eh distribuido na expectativa de ser util, mas SEM
  14 +# QUALQUER GARANTIA; sem mesmo a garantia implicita de
  15 +# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
  16 +# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
  17 +# detalhes.
  18 +#--------------------------------------------------------------------------
invesalius/libc/libift/libift.c 0 → 100644
@@ -0,0 +1,115 @@ @@ -0,0 +1,115 @@
  1 +
  2 +
  3 +//extern "C" {
  4 + #include "ift.h"
  5 +//}
  6 +
  7 +
  8 +
  9 +
  10 +
  11 +// Prototypes
  12 +
  13 +void NewDestroyScene(Scene *scn);
  14 +
  15 +
  16 +
  17 +
  18 +void NewDestroyScene(Scene *scn)
  19 +{
  20 + if(scn != NULL){
  21 + if (scn->data != NULL) free(scn->data);
  22 + if (scn->tby != NULL) free(scn->tby);
  23 + if (scn->tbz != NULL) free(scn->tbz);
  24 + free(scn);
  25 + }
  26 +}
  27 +
  28 +
  29 +Scene* EraseBackground(Scene *scn)
  30 +{
  31 + int otsu = (int)(Otsu3(scn)*0.8); // Get 80% of Otsu's threshold
  32 + int i,n = scn->xsize*scn->ysize*scn->zsize;
  33 + Scene *out = CopyScene(scn);
  34 + for (i=0; i < n; i++) {
  35 + if (out->data[i]<otsu) out->data[i]=0;
  36 + }
  37 + return out;
  38 +}
  39 +
  40 +Scene* EraseSupport(Scene *scn)
  41 +{
  42 + // Check if RemoveBackground was already ran (workaround)
  43 + int c=0,i,n = scn->xsize*scn->ysize*scn->zsize;
  44 + Scene *scn2;
  45 + Scene *labels,*bin;
  46 + AdjRel3 *A;
  47 + int total[2000],p;
  48 + Voxel v;
  49 + int max;
  50 + Scene *out;
  51 +
  52 + for (i=0; i < n; i++) {
  53 + if (scn->data[i]==0) c++; // count zero voxels
  54 + }
  55 + if (c<(n*0.15))
  56 + scn2 = EraseBackground(scn);
  57 + else
  58 + scn2 = CopyScene(scn);
  59 +
  60 + // Get max connected component
  61 + A=Spheric(1.5);
  62 + bin = Threshold3(scn2,1,50000);
  63 + labels = LabelBinComp3(bin,A);
  64 + DestroyAdjRel3(&A);
  65 + // Count labels
  66 + for (i=0;i<2000;i++) total[i]=0;
  67 + for (v.z=0; v.z < scn->zsize; v.z++)
  68 + for (v.y=0; v.y < scn->ysize; v.y++)
  69 + for (v.x=0; v.x < scn->xsize; v.x++) {
  70 + p = labels->tbz[v.z] + labels->tby[v.y] + v.x;
  71 + if (labels->data[p]<2000) total[labels->data[p]]++;
  72 + if (bin->data[p]==0) total[labels->data[p]]=0; // exclude background
  73 + }
  74 + DestroyScene(&bin);
  75 + max=0;
  76 + for (i=0;i<2000;i++)
  77 + if (total[i]>total[max]) max=i;
  78 +
  79 + // copy the maxcc to out
  80 + n = scn->xsize*scn->ysize*scn->zsize;
  81 + out = CreateScene(scn->xsize,scn->ysize,scn->zsize);
  82 + out->dx=scn->dx;
  83 + out->dy=scn->dy;
  84 + out->dz=scn->dz;
  85 + for (i=0; i < n; i++) {
  86 + if (labels->data[i]==max) out->data[i]=scn2->data[i];
  87 + }
  88 + DestroyScene(&labels);
  89 + DestroyScene(&scn2);
  90 + return out;
  91 +}
  92 +
  93 +
  94 +
  95 +int ShiftScene(Scene *scn)
  96 +{
  97 + int n,i, min = MinimumValue3(scn);
  98 + if (min<0) {
  99 + n = scn->xsize*scn->ysize*scn->zsize;
  100 + for (i=0; i < n; i++)
  101 + scn->data[i] += 1024;
  102 + return 1;
  103 + }
  104 + return 0;
  105 +}
  106 +
  107 +void UnShiftScene(Scene *scn, int flag)
  108 +{
  109 + int i,n;
  110 + if (flag!=0) {
  111 + n = scn->xsize*scn->ysize*scn->zsize;
  112 + for (i=0; i < n; i++)
  113 + scn->data[i] -= 1024;
  114 + }
  115 +}
invesalius/libc/libift/libift.i 0 → 100644
@@ -0,0 +1,83 @@ @@ -0,0 +1,83 @@
  1 +
  2 +
  3 +/* example.i */
  4 +%module libift
  5 +
  6 +%{
  7 +/* Put header files here or function declarations like below */
  8 +
  9 +#include "ift.h"
  10 +
  11 +extern void NewDestroyScene(Scene *scn);
  12 +extern Scene* EraseBackground(Scene *scn);
  13 +extern Scene* EraseSupport(Scene *scn);
  14 +extern int ShiftScene(Scene *scn);
  15 +extern void UnShiftScene(Scene *scn, int flag);
  16 +
  17 +/* From ift library */
  18 +extern float GetDx(Scene *scn);
  19 +extern float GetDy(Scene *scn);
  20 +extern float GetDz(Scene *scn);
  21 +extern int GetXSize(Scene *scn);
  22 +extern int GetYSize(Scene *scn);
  23 +extern int GetZSize(Scene *scn);
  24 +extern Scene *CreateScene(int xsize,int ysize,int zsize);
  25 +extern void SetDx(Scene *scn, float dx);
  26 +extern void SetDy(Scene *scn, float dy);
  27 +extern void SetDz(Scene *scn, float dz);
  28 +extern Scene* ReadScene(char *filename);
  29 +extern void WriteScene(Scene *scn, char *filename);
  30 +extern Scene* MSP_Align(Scene *in, Scene *mask, int input_ori, int quality);
  31 +extern Scene *LinearInterp(Scene *scn,float dx,float dy,float dz);
  32 +extern Kernel3 *NormalizeKernel3(Kernel3 *K);
  33 +extern Kernel3 *GaussianKernel3(AdjRel3 *A, float stddev);
  34 +extern Kernel3 *LaplacianKernel3(AdjRel3 *A, float stddev);
  35 +extern void DestroyKernel3(Kernel3 **K);
  36 +extern Scene *LinearFilter3(Scene *scn, Kernel3 *K);
  37 +extern Scene *SobelFilter3(Scene *scn);
  38 +extern Scene *MedianFilter3(Scene *scn, AdjRel3 *A);
  39 +extern Scene *ModeFilter3(Scene *scn, AdjRel3 *A);
  40 +extern AdjRel3 *Spheric(float r);
  41 +extern Scene *Equalize3(Scene *scn, int Imax);
  42 +extern int Otsu3(Scene *scn);
  43 +
  44 +
  45 +
  46 +%}
  47 +
  48 +
  49 +
  50 +#include "ift.h"
  51 +
  52 +extern void NewDestroyScene(Scene *scn);
  53 +extern Scene* EraseBackground(Scene *scn);
  54 +extern Scene* EraseSupport(Scene *scn);
  55 +extern int ShiftScene(Scene *scn);
  56 +extern void UnShiftScene(Scene *scn, int flag);
  57 +
  58 +/* From ift library */
  59 +extern float GetDx(Scene *scn);
  60 +extern float GetDy(Scene *scn);
  61 +extern float GetDz(Scene *scn);
  62 +extern int GetXSize(Scene *scn);
  63 +extern int GetYSize(Scene *scn);
  64 +extern int GetZSize(Scene *scn);
  65 +extern Scene *CreateScene(int xsize,int ysize,int zsize);
  66 +extern void SetDx(Scene *scn, float dx);
  67 +extern void SetDy(Scene *scn, float dy);
  68 +extern void SetDz(Scene *scn, float dz);
  69 +extern Scene* ReadScene(char *filename);
  70 +extern void WriteScene(Scene *scn, char *filename);
  71 +extern Scene* MSP_Align(Scene *in, Scene *mask, int input_ori, int quality);
  72 +extern Scene *LinearInterp(Scene *scn,float dx,float dy,float dz);
  73 +extern Kernel3 *NormalizeKernel3(Kernel3 *K);
  74 +extern Kernel3 *GaussianKernel3(AdjRel3 *A, float stddev);
  75 +extern Kernel3 *LaplacianKernel3(AdjRel3 *A, float stddev);
  76 +extern void DestroyKernel3(Kernel3 **K);
  77 +extern Scene *LinearFilter3(Scene *scn, Kernel3 *K);
  78 +extern Scene *SobelFilter3(Scene *scn);
  79 +extern Scene *MedianFilter3(Scene *scn, AdjRel3 *A);
  80 +extern Scene *ModeFilter3(Scene *scn, AdjRel3 *A);
  81 +extern AdjRel3 *Spheric(float r);
  82 +extern Scene *Equalize3(Scene *scn, int Imax);
  83 +
invesalius/libc/libift/makefile.vc 0 → 100644
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +
  2 +#----------------------------------------------------------------------
  3 +# This is the Makefile to compile lib-ift with MS Visual C++ (cl.exe)
  4 +# using the GNU make or NMAKE.
  5 +#
  6 +# Instruction: Open the "Visual Studio Command Prompt" and type
  7 +# "C:\ift> make -f makefile.vc" or
  8 +# "C:\ift> nmake -f makefile.vc"
  9 +#
  10 +#----------------------------------------------------------------------
  11 +
  12 +# Set these variables first
  13 +IFT_DIR="C:\ift"
  14 +PY_INC="C:\Python26\include"
  15 +PY_LIB="C:\Python26\libs\python26.lib"
  16 +
  17 +
  18 +PROG=libift
  19 +
  20 +all: _$(PROG).pyd
  21 +
  22 +_$(PROG).pyd: $(PROG).i $(PROG).c
  23 + @echo Generating wrappers...
  24 + @swig -python $(PROG).i
  25 + @echo Compiling...
  26 + @cl.exe /nologo -c $(PROG).c $(PROG)_wrap.c -I $(PY_INC) -I $(IFT_DIR)\include
  27 + @echo Linking...
  28 + @link.exe /nologo -dll $(PROG).obj $(PROG)_wrap.obj $(PY_LIB) $(IFT_DIR)\lib\libift.lib -out:_$(PROG).pyd
  29 + @echo Done.
  30 +
  31 +
  32 +clean:
  33 + del $(PROG).o $(PROG).py $(PROG)_wrap.c $(PROG)_wrap.o $(PROG).py _$(PROG).so *.pyc *.obj *.pyd *.exp *.lib *~
  34 +
  35 +
  36 +
  37 +
invesalius/libc/libscnvtk/Makefile 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +
  2 +
  3 +PROG=scnvtk
  4 +#IFT_DIR=~/ift
  5 +#VTK_DIR=/hd2/lib/VTK
  6 +
  7 +
  8 +all: _${PROG}.so
  9 +
  10 +_${PROG}.so: ${PROG}.i ${PROG}.cxx
  11 + @echo "Generating wrappers..."
  12 + @swig -c++ -python ${PROG}.i
  13 + @echo "Compiling..."
  14 + @c++ -c ${PROG}.cxx ${PROG}_wrap.cxx -I/usr/include/python2.6 -I${OPF_DIR}/include -I${IFT_DIR}/include -L${IFT_DIR}/lib/ -lift -I${VTK_DIR} -I${VTK_DIR}/Common -I${VTK_DIR}/Utilities -I${VTK_DIR}/VolumeRendering -I${VTK_DIR}/Rendering -I${VTK_DIR}/Utilities/vtkalglib -I${VTK_DIR}/Infovis -I${VTK_DIR}/Geovis -I${VTK_DIR}/Views -I${VTK_DIR}/Hybrid -I${VTK_DIR}/Widgets -I${VTK_DIR}/Rendering/Testing/Cxx -I${VTK_DIR}/IO -I${VTK_DIR}/Imaging -I${VTK_DIR}/Graphics -I${VTK_DIR}/GenericFiltering -I${VTK_DIR}/Filtering -I${VTK_DIR}/Common/Testing/Cxx -I${VTK_DIR}/Utilities/vtklibproj4 -I${VTK_DIR}/Utilities/DICOMParser -I${VTK_DIR}/Utilities/vtkfreetype/include -I${VTK_DIR}/Utilities/vtknetcdf -I${VTK_DIR}/Utilities/vtkexodus2/include -I${VTK_DIR}/Utilities/MaterialLibrary -I${VTK_DIR}/Utilities/verdict -I/usr/include/tcl8.4 -Wno-deprecated
  15 + @echo "Linking..."
  16 + @c++ -shared ${PROG}.o ${PROG}_wrap.o -o _${PROG}.so -L${IFT_DIR}/lib/ -lift #-L${VTK_DIR}/bin -lvtkRendering -lift -lvtkGraphics -lvtkverdict -lvtkImaging -lvtkIO -lvtkFiltering -lvtkCommon -lpthread -lm -lvtkDICOMParser -lvtkNetCDF -lvtkmetaio -lvtksqlite -lvtkpng -lvtktiff -lvtkzlib -lvtkjpeg -lvtkexpat -lvtksys -ldl -lvtkftgl -lvtkfreetype -lGL -lOSMesa -lXt -lSM -lICE -lX11 -lXext
  17 + @echo "Done."
  18 +
  19 +clean:
  20 + rm ${PROG}.o ${PROG}.py ${PROG}_wrap.cxx ${PROG}_wrap.o ${PROG}.py _${PROG}.so *.pyc *.obj *.exp *.pyd *.lib *~
  21 +
  22 +
  23 +
  24 +
invesalius/libc/libscnvtk/__init__.py 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +#--------------------------------------------------------------------------
  2 +# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
  3 +# Copyright: (C) 2001 Centro de Pesquisas Renato Archer
  4 +# Homepage: http://www.softwarepublico.gov.br
  5 +# Contact: invesalius@cti.gov.br
  6 +# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
  7 +#--------------------------------------------------------------------------
  8 +# Este programa e software livre; voce pode redistribui-lo e/ou
  9 +# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
  10 +# publicada pela Free Software Foundation; de acordo com a versao 2
  11 +# da Licenca.
  12 +#
  13 +# Este programa eh distribuido na expectativa de ser util, mas SEM
  14 +# QUALQUER GARANTIA; sem mesmo a garantia implicita de
  15 +# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
  16 +# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
  17 +# detalhes.
  18 +#--------------------------------------------------------------------------
invesalius/libc/libscnvtk/libscnvtk.py 0 → 100644
@@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
  1 +
  2 +
  3 +
  4 +import scnvtk
  5 +import vtk
  6 +from ..libift import libift as libift
  7 +
  8 +
  9 +
  10 +def Interp(img):
  11 + scn = VtkImageDataToScene(img)
  12 + scn2=libift.LinearInterp(scn,0,0,0)
  13 + libift.NewDestroyScene(scn)
  14 + return SceneToVtkImageData(scn2)
  15 +
  16 +
  17 +def SceneToVtkImageData(scn):
  18 + dx = libift.GetDx(scn)
  19 + dy = libift.GetDy(scn)
  20 + dz = libift.GetDz(scn)
  21 + xsize = libift.GetXSize(scn)
  22 + ysize = libift.GetYSize(scn)
  23 + zsize = libift.GetZSize(scn)
  24 + img = vtk.vtkImageData()
  25 + img.SetSpacing(dx,dy,dz)
  26 + img.SetOrigin(0,0,0)
  27 + img.SetDimensions(xsize,ysize,zsize)
  28 + img.SetScalarTypeToUnsignedShort()
  29 + img.SetNumberOfScalarComponents(1)
  30 + img.AllocateScalars()
  31 + scnvtk.CopyImageBufferScnToVtk(img.GetScalarPointer(),scn)
  32 + return img
  33 +
  34 +def VtkImageDataToScene(img):
  35 + d = img.GetSpacing()
  36 + dx=d[0]
  37 + dy=d[1]
  38 + dz=d[2]
  39 + d = img.GetDimensions()
  40 + xsize=d[0]
  41 + ysize=d[1]
  42 + zsize=d[2]
  43 + scn=libift.CreateScene(xsize,ysize,zsize)
  44 + libift.SetDx(scn,dx)
  45 + libift.SetDy(scn,dy)
  46 + libift.SetDz(scn,dz)
  47 + scnvtk.CopyImageBufferVtkToScn(scn,img.GetScalarPointer())
  48 + return scn
  49 +
  50 +
  51 +
  52 +def WriteVtkImageData(img,filename):
  53 + scn = VtkImageDataToScene(img)
  54 + libift.WriteScene(scn,filename)
  55 + libift.NewDestroyScene(scn)
  56 +
  57 +def ReadVtkImageData(filename):
  58 + scn = libift.ReadScene(filename)
  59 + img=SceneToVtkImageData(scn)
  60 + libift.NewDestroyScene(scn)
  61 + return img
  62 +
  63 +
invesalius/libc/libscnvtk/makefile.vc 0 → 100644
@@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
  1 +
  2 +#----------------------------------------------------------------------
  3 +# This is the Makefile to compile lib-ift with MS Visual C++ (cl.exe)
  4 +# using the GNU make or NMAKE.
  5 +#
  6 +# Instruction: Open the "Visual Studio Command Prompt" and type
  7 +# "C:\ift> make -f makefile.vc" or
  8 +# "C:\ift> nmake -f makefile.vc"
  9 +#
  10 +#----------------------------------------------------------------------
  11 +
  12 +# Set these variables first
  13 +IFT_DIR="C:\ift"
  14 +PY_INC="C:\Python26\include"
  15 +PY_LIB="C:\Python26\libs\python26.lib"
  16 +VTK_INC="C:\Arquivos de programas\VTK\include\vtk-5.4"
  17 +
  18 +PROG=scnvtk
  19 +
  20 +all: _$(PROG).pyd
  21 +
  22 +_$(PROG).pyd: $(PROG).i $(PROG).cxx
  23 + @echo Generating wrappers...
  24 + @swig -c++ -python $(PROG).i
  25 + @echo Compiling...
  26 + @cl.exe /nologo /EHsc -c $(PROG).cxx $(PROG)_wrap.cxx -I $(PY_INC) -I $(VTK_INC) -I $(IFT_DIR)\include
  27 + @echo Linking...
  28 + @link.exe /nologo -dll $(PROG).obj $(PROG)_wrap.obj $(PY_LIB) $(IFT_DIR)\lib\libift.lib -out:_$(PROG).pyd
  29 + @echo Done.
  30 +
  31 +clean:
  32 + del $(PROG).o $(PROG).py $(PROG)_wrap.c $(PROG)_wrap.o $(PROG).py _$(PROG).so *.pyc *.obj *.pyd *.exp *.lib *~
  33 +
  34 +
  35 +
  36 +
invesalius/libc/libscnvtk/scnvtk.cxx 0 → 100644
@@ -0,0 +1,86 @@ @@ -0,0 +1,86 @@
  1 +
  2 +#include "vtkImageData.h"
  3 +
  4 +
  5 +extern "C" {
  6 + #include "ift.h"
  7 +}
  8 +
  9 +
  10 +// Prototypes
  11 +
  12 +
  13 +char *PointerToString(void *ptr, const char *type);
  14 +void *StringToPointer(char *ptrText, int len, const char *type);
  15 +void CopyImageBufferScnToVtk(char *ptrvtk, Scene *scn);
  16 +void CopyImageBufferVtkToScn(Scene *scn, char *ptrvtk);
  17 +
  18 +
  19 +
  20 +
  21 +
  22 +//#if defined ( _MSC_VER )
  23 +//# define vtkConvertPtrToLong(x) ((long)(PtrToUlong(x)))
  24 +//#else
  25 +# define vtkConvertPtrToLong(x) ((long)(x))
  26 +//#endif
  27 +
  28 +//--------------------------------------------------------------------
  29 +// mangle a void pointer into a SWIG-style string
  30 +char *PointerToString(void *ptr, const char *type)
  31 +{
  32 + static char ptrText[128];
  33 + sprintf(ptrText,"_%*.*lx_%s",2*(int)sizeof(void *),2*(int)sizeof(void *),
  34 + vtkConvertPtrToLong(ptr),type);
  35 + return ptrText;
  36 +}
  37 +
  38 +//--------------------------------------------------------------------
  39 +// unmangle a void pointer from a SWIG-style string
  40 +void *StringToPointer(char *ptrText, int len, const char *type)
  41 +{
  42 + int i;
  43 + void *ptr;
  44 + char typeCheck[128];
  45 + if (len < 128) {
  46 + i = sscanf(ptrText,"_%lx_%s",(long *)&ptr,typeCheck);
  47 + if (strcmp(type,typeCheck) == 0) {
  48 + // sucessfully unmangle
  49 + return ptr;
  50 + }
  51 + }
  52 + return NULL;
  53 +}
  54 +
  55 +
  56 +
  57 +void CopyImageBufferScnToVtk(char *ptrvtk, Scene *scn) {
  58 + int i;
  59 + int n = scn->xsize*scn->ysize*scn->zsize;
  60 + short int *ptr = (short int *) StringToPointer(ptrvtk,strlen(ptrvtk),"void_p");
  61 + if (ptr==NULL) {
  62 + printf("CopyImageBufferScnToVtk() error! Null Pointer!\n");
  63 + return;
  64 + }
  65 + for (i=0;i<n;i++)
  66 + *(ptr+i)=(short int) scn->data[i];
  67 +}
  68 +
  69 +
  70 +void CopyImageBufferVtkToScn(Scene *scn, char *ptrvtk) {
  71 + int i;
  72 + int n = scn->xsize*scn->ysize*scn->zsize;
  73 + short int *ptr = (short int *) StringToPointer(ptrvtk,strlen(ptrvtk),"void_p");
  74 + if (ptr==NULL) {
  75 + printf("CopyImageBufferVtkToScn() error! Null Pointer!\n");
  76 + return;
  77 + }
  78 + for (i=0;i<n;i++)
  79 + scn->data[i] = (int) *(ptr+i);
  80 +}
  81 +
  82 +
  83 +
  84 +
  85 +
  86 +
invesalius/libc/libscnvtk/scnvtk.i 0 → 100644
@@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
  1 +
  2 +
  3 +/* example.i */
  4 +%module scnvtk
  5 +
  6 +%{
  7 +/* Put header files here or function declarations like below */
  8 +
  9 +extern "C" {
  10 + #include "ift.h"
  11 +}
  12 +#include "vtkImageData.h"
  13 +
  14 +extern char *PointerToString(void *ptr, const char *type);
  15 +extern void *StringToPointer(char *ptrText, int len, const char *type);
  16 +extern void CopyImageBufferScnToVtk(char *ptrvtk, Scene *scn);
  17 +extern void CopyImageBufferVtkToScn(Scene *scn, char *ptrvtk);
  18 +
  19 +%}
  20 +
  21 +
  22 +extern "C" {
  23 + #include "ift.h"
  24 +}
  25 +#include "vtkImageData.h"
  26 +
  27 +extern char *PointerToString(void *ptr, const char *type);
  28 +extern void *StringToPointer(char *ptrText, int len, const char *type);
  29 +extern void CopyImageBufferScnToVtk(char *ptrvtk, Scene *scn);
  30 +extern void CopyImageBufferVtkToScn(Scene *scn, char *ptrvtk);
  31 +
  32 +
  33 +