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