]> Creatis software - bbtk.git/blob - packages/demo/bbs/appli/demoFiltering1.bbs
Feature #1774
[bbtk.git] / packages / demo / bbs / appli / demoFiltering1.bbs
1  # ---------------------------------------------------------------------
2  #
3  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4  #                        pour la SantÈ)
5  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8  #
9  #  This software is governed by the CeCILL-B license under French law and
10  #  abiding by the rules of distribution of free software. You can  use,
11  #  modify and/ or redistribute the software under the terms of the CeCILL-B
12  #  license as circulated by CEA, CNRS and INRIA at the following URL
13  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14  #  or in the file LICENSE.txt.
15  #
16  #  As a counterpart to the access to the source code and  rights to copy,
17  #  modify and redistribute granted by the license, users are provided only
18  #  with a limited warranty  and the software's author,  the holder of the
19  #  economic rights,  and the successive licensors  have only  limited
20  #  liability.
21  #
22  #  The fact that you are presently reading this means that you have had
23  #  knowledge of the CeCILL-B license and that you accept its terms.
24  # ------------------------------------------------------------------------ */
25  
26
27 description "Basic segmentation and filtering of an image"
28 author "jpr@creatis.insa-lyon.fr"
29 category "demo, filter"
30
31 // 3 Slices, 2 volumes
32
33 include std
34 include vtk
35 include wx
36 include itk
37 include itkvtk
38 include wxvtk
39
40 //
41 // Get the image and determine Slice number, slider size, ...
42 // ----------------------------------------------------------
43
44 # Here loads hola.mhd
45 # -------------------
46 # Don't forget to comment out the following 2 lines
47 # If you want to check someting else.
48
49 include vtk/boxes/bbLoadHola
50 new LoadHola reader
51
52 # uncomment next lines to have a file selector
53 # --------------------------------------------
54 /*
55 new FileSelector openFileDialog
56 new ImageReader reader
57   connect openFileDialog.Out reader.In
58 */
59
60 # uncomment next lines to use Gimmick
61 # -----------------------------------
62 /*
63 load creaImageIO
64 new Gimmick reader
65 */
66
67 # uncomment next lines to Read a MHD file (and nothing else !)
68 # ------------------------------------------------------------
69 /*
70 new FileSelector openFileDialog
71 new MetaImageReader reader
72    connect openFileDialog.Out reader.In
73 */
74
75 # uncomment the following lines to read a 3D images stack
76 # (only if file name order is meaningfull)
77 # -------------------------------------------------------
78 /*
79 // To choose the directory
80 new DirectorySelector ds
81 // To get the image names into a vector
82 new FilesFromDirectory fd
83 // To read all the files, as a bbitk::ImagePointer
84 new ImageSeriesReader reader
85 // user choosen directory as input
86 connect ds.Out fd.In
87 set fd.Recursive false
88 // list of files as input
89 #print "Files found in $ds.Out$\n
90 connect fd.Out reader.FileNames
91 */
92
93 # uncomment the following lines to read a 3D images stack
94 # (if the directory contains a 'XCoherent" Serie)
95 # -------------------------------------------------------
96 /*
97 // To choose the directory
98 new DirectorySelector ds
99 // To get the image names into a vector
100 new FilesFromDirectory fd
101 // user choosen directory as input
102 connect ds.Out fd.In 
103 // order the files, computes an accurate ZSpacing
104 new GetXCoherentInfoGdcmReader reader
105 connect fd.Out reader.In
106 */
107
108 # uncomment the following lines to read a 3D images stack
109 # (with DICOMDirReader)
110 # -------------------------------------------------------
111 /*
112 include itk/boxes/bbDICOMDirReader
113 // To choose the directory
114 new DirectorySelector ds
115 new DICOMDirReader reader
116    connect ds.Out reader.In
117 */
118
119 // We need that to set Sliders sizes
120
121 #Get image dimensions, ...
122 new ImageProperties mc
123    connect reader.Out mc.In
124
125 #Get number of planes  (Z)
126 new GetVectorIntElement gveZ
127    connect mc.Size gveZ.In
128    set gveZ.I 2
129    
130 #Compute the number of the 'middle' slice on Z axis
131 new Div div2
132   connect   gveZ.Out div2.In1
133   set div2.In2 2
134
135 //
136 // Graphical organization
137 // ----------------------
138
139 new LayoutSplit mainSplit
140   set mainSplit.Proportion 60
141   set mainSplit.WinHeight  1000
142   set mainSplit.WinWidth   1400
143   set mainSplit.WinTitle "Processing / Viewing example (demoFiltering1.bbs) "
144
145    new LayoutSplit splitUp
146      set splitUp.Proportion 38
147      connect splitUp.Widget  mainSplit.Widget1
148
149       new LayoutLine toolLayout
150         set toolLayout.Orientation H
151         connect toolLayout.Widget splitUp.Widget1
152
153            new LayoutLine sliderLayout
154               set sliderLayout.Orientation V
155               connect sliderLayout.Widget toolLayout.Widget1
156
157                  new Slider sliceSlider
158                     set sliceSlider.Title "Slice"
159                     set sliceSlider.ReactiveOnTrack true
160                     connect sliceSlider.Widget sliderLayout.Widget1
161
162                  new Slider lowerThresholdSlider
163                     set lowerThresholdSlider.Title "LowerThreshold"
164                     set lowerThresholdSlider.Max        200
165                     set lowerThresholdSlider.In         10
166                     set lowerThresholdSlider.ChangeResolution 1
167                     connect lowerThresholdSlider.Widget sliderLayout.Widget2
168
169                  new Slider upperThresholdSlider
170                     set upperThresholdSlider.Title "UpperThreshold"
171                     set upperThresholdSlider.Max        500
172                     set upperThresholdSlider.In         150
173                     set upperThresholdSlider.ChangeResolution 1
174                     connect upperThresholdSlider.Widget sliderLayout.Widget3
175
176                  new Slider smoothSlider
177                     set smoothSlider.Title "Smooth"
178                     set smoothSlider.Max        10
179                     set smoothSlider.In         3
180                     set smoothSlider.ChangeResolution 1
181                     connect  smoothSlider.Widget sliderLayout.Widget4
182
183            new LayoutLine buttonLayout
184               set buttonLayout.Orientation H
185               connect buttonLayout.Widget toolLayout.Widget2
186
187               new ColourSelectorButton colourThreshold
188                  set colourThreshold.In "1 0 0"
189                  connect colourThreshold.Widget buttonLayout.Widget1
190
191               new ColourSelectorButton colourSmooth
192                  set colourSmooth.In "1 1 0"
193                  connect colourSmooth.Widget buttonLayout.Widget2
194
195 /*
196               new CommandButton refresh
197                  set refresh.Label "Refresh (to be used once at start time)"
198                  connect refresh.Widget buttonLayout.Widget3
199 */
200       new LayoutLine layout2D
201          set layout2D.Orientation H
202          connect layout2D.Widget splitUp.Widget2
203
204          new Viewer2D viewer2DImageOriginal
205             connect viewer2DImageOriginal.Widget layout2D.Widget1
206
207          new Viewer2D viewer2DImageSegmented
208             connect viewer2DImageSegmented.Widget layout2D.Widget2
209
210          new Viewer2D viewer2DImageSmooth
211             connect viewer2DImageSmooth.Widget layout2D.Widget3
212
213    new LayoutSplit layout3D
214      set layout3D.Orientation H
215      set layout3D.Proportion 90
216      connect layout3D.Widget  mainSplit.Widget2
217
218         new LayoutSplit layoutSurfaces
219            set layoutSurfaces.Orientation H
220            set layoutSurfaces.Proportion 50
221            connect layoutSurfaces.Widget layout3D.Widget1
222
223            new Viewer3D  viewer3DSurfaceThreshold
224            connect viewer3DSurfaceThreshold.Widget layoutSurfaces.Widget1
225
226            new Viewer3D  viewer3DSurfaceSmooth
227            connect viewer3DSurfaceSmooth.Widget layoutSurfaces.Widget2
228
229         new LayoutLine vSliderLayout
230            connect vSliderLayout.Widget layout3D.Widget2
231
232            new Slider lowerOpacitySlider
233               set lowerOpacitySlider.Title "Opacity"
234               set lowerOpacitySlider.Min        1
235               set lowerOpacitySlider.Max        100
236               set lowerOpacitySlider.In         50
237               set lowerOpacitySlider.Orientation V
238               connect lowerOpacitySlider.Widget vSliderLayout.Widget1
239
240 /*
241            new Slider upperOpacitySlider
242               set upperOpacitySlider.Title "UpperOpacity"
243               set upperOpacitySlider.Max        100
244               set upperOpacitySlider.In         100
245               set upperOpacitySlider.Orientation V
246               connect upperOpacitySlider.Widget vSliderLayout.Widget2
247 */
248
249 //
250 // End of Graphical organization
251 // -----------------------------
252
253 //
254 // Processing pipeline
255 // -------------------
256
257   connect reader.Out                    viewer2DImageOriginal.In
258   connect sliceSlider.Out               viewer2DImageOriginal.Slice
259
260   #Slider size is the number of planes
261   connect gveZ.Out     sliceSlider.Max
262   #initial slice is the middle one
263   connect div2.Out sliceSlider.In
264   set sliceSlider.ChangeResolution 1
265   
266 // Images 2D
267
268  new BinaryThresholdImageFilter threshold
269   set threshold.InsideValue 255
270   set threshold.OutsideValue 0
271
272   connect upperThresholdSlider.Out threshold.UpperThreshold
273   connect lowerThresholdSlider.Out threshold.LowerThreshold
274   connect reader.Out threshold.In
275
276   connect threshold.Out                 viewer2DImageSegmented.In
277   connect sliceSlider.Out               viewer2DImageSegmented.Slice
278
279 new ImageGaussianSmooth smooth
280   connect threshold.Out smooth.In
281   connect smoothSlider.Out smooth.StdDevX
282   connect smoothSlider.Out smooth.StdDevY
283   connect smoothSlider.Out smooth.StdDevZ
284
285   connect smooth.Out            viewer2DImageSmooth.In
286   connect sliceSlider.Out       viewer2DImageSmooth.Slice
287
288
289 // Planes
290 new ImagePlanes planes
291   connect reader.Out planes.In
292   connect planes.PlaneX viewer3DSurfaceSmooth.Obs1
293   connect planes.PlaneY viewer3DSurfaceSmooth.Obs2
294   connect planes.PlaneZ viewer3DSurfaceSmooth.Obs3
295
296 // Surfaces 3D 
297
298 new IsoSurfaceExtractor  isoextractorThreshold
299   connect threshold.Out isoextractorThreshold.In
300   set isoextractorThreshold.Opacity 1  
301   set isoextractorThreshold.Isovalue 100
302   connect colourThreshold.Out isoextractorThreshold.Colour
303   connect isoextractorThreshold.Out  viewer3DSurfaceThreshold.In1
304
305 new Div div3
306    connect lowerOpacitySlider.Out div3.In1
307    set div3.In2 100
308
309 new IsoSurfaceExtractor  isoextractorSmooth
310   connect smooth.Out isoextractorSmooth.In
311   connect div3.Out isoextractorSmooth.Opacity
312   set isoextractorSmooth.Isovalue 200
313   connect colourSmooth.Out isoextractorSmooth.Colour
314   connect isoextractorSmooth.Out  viewer3DSurfaceSmooth.In2
315
316 // Refresh issues
317
318 new MultipleInputs multInForImageOriginal
319   connect sliceSlider.BoxChange multInForImageOriginal.In1
320 #  connect refresh.BoxChange     multInForImageOriginal.In2
321
322
323  new MultipleInputs multInForImageSegmented
324   connect lowerThresholdSlider.BoxChange multInForImageSegmented.In1
325   connect upperThresholdSlider.BoxChange multInForImageSegmented.In2
326 #  connect refresh.BoxChange              multInForImageSegmented.In3
327   connect sliceSlider.BoxChange  multInForImageSegmented.In4    
328     
329  new MultipleInputs multInForImageSmooth
330   connect lowerThresholdSlider.BoxChange multInForImageSmooth.In1
331   connect upperThresholdSlider.BoxChange multInForImageSmooth.In2 
332   connect smoothSlider.BoxChange         multInForImageSmooth.In3
333 #  connect refresh.BoxChange              multInForImageSmooth.In4
334   connect sliceSlider.BoxChange multInForImageSmooth.In5
335
336  new MultipleInputs multInForSurfaceThreshold
337 #  connect refresh.BoxChange multInForSurfaceThreshold.In1
338   connect colourThreshold.BoxChange multInForSurfaceThreshold.In2
339   connect lowerThresholdSlider.BoxChange multInForSurfaceThreshold.In3
340   connect upperThresholdSlider.BoxChange multInForSurfaceThreshold.In4 
341
342  new MultipleInputs multInForSurfaceSmooth
343 #  connect refresh.BoxChange multInForSurfaceSmooth.In1
344   connect lowerOpacitySlider.BoxChange multInForSurfaceSmooth.In1
345   connect colourSmooth.BoxChange multInForSurfaceSmooth.In2
346   connect lowerThresholdSlider.BoxChange multInForSurfaceSmooth.In3
347   connect upperThresholdSlider.BoxChange multInForSurfaceSmooth.In4
348   connect smoothSlider.BoxChange         multInForSurfaceSmooth.In5
349
350   connect multInForImageOriginal.BoxChange     viewer2DImageOriginal.BoxExecute
351   connect multInForImageSegmented.BoxChange    viewer2DImageSegmented.BoxExecute
352   connect multInForImageSmooth.BoxChange       viewer2DImageSmooth.BoxExecute
353
354   connect multInForSurfaceThreshold.BoxChange  viewer3DSurfaceThreshold.BoxExecute
355   connect multInForSurfaceSmooth.BoxChange     viewer3DSurfaceSmooth.BoxExecute
356
357  
358
359   exec mainSplit