]> Creatis software - bbtk.git/blob - packages/demo/bbs/appli/SaveAsMhd.bbs
Use ImagesChooserDialogBox
[bbtk.git] / packages / demo / bbs / appli / SaveAsMhd.bbs
1
2 description "Reads and image file /  stack of image files, writes it as a MHD file"
3 author "jpr@creatis.insa-lyon.fr"
4 category "tool, read/write"
5
6 load vtk
7 include wxvtk
8 load std
9 load itk
10 include vtk
11 include wx
12 load itkvtk
13
14 new LayoutLine  main
15
16 # Use new box (choose the way you want to select images)
17 # -----------------------------------------------------
18 load creaImageIO
19 new ImagesChooserDialogBox chooser
20
21 # Concatenate all the supposed-to-be consistent 2D images into a single vtkImageData
22 # WARNING : File names alphabetical order is suposed to be meaningful ...
23
24 new ConcatImages reader
25    connect chooser.Out reader.In
26
27
28
29
30 // Normally (?) the following lines {== BEGIN == / ==END ==}
31 // are now useless; let here as a reminder/example
32 // Don't remove them. JPRx
33
34 // ==== BEGIN ======================================================
35
36 /* 
37 # Dummy way to get only the first image from the chooser
38 # ------------------------------------------------------
39 load creaImageIO
40 new ImagesChooserDialogBox chooser
41
42 new GetVectorVtkImageDataElement reader
43    set reader.I 0
44    connect chooser.Out reader.In
45 */
46
47 # Here loads 'hola.mhd'
48 # ---------------------
49
50 # Don't forget to comment out the following 2 lines
51 # If you want to check someting else.
52
53 /*
54 include vtk/boxes/bbLoadHola
55 new LoadHola reader
56 */
57
58 # uncomment next lines to have a file selector
59 # --------------------------------------------
60 /*
61 new FileSelector openFileDialog
62 new ImageReader reader
63   connect openFileDialog.Out reader.In
64 */
65
66 # uncomment next lines to use a vtkgdcmReader
67 # -------------------------------------
68 /*
69 new FileSelector openFileDialog
70 new GetInfoGdcmReader reader
71   connect openFileDialog.Out reader.In
72 */
73
74 # uncomment next lines to use Gimmick
75 # -----------------------------------
76 /*
77 load creaImageIO
78 new Gimmick reader
79 */
80
81 # uncomment next lines to Read a MHD file (and nothing else !)
82 # ------------------------------------------------------------
83 /*
84 new FileSelector openFileDialog
85  set openFileDialog.Wildcard  "(*.mhd)|*.mhd"
86 new MetaImageReader reader
87    connect openFileDialog.Out reader.In
88 */
89
90 # uncomment the following lines to read a 3D images stack
91 # (only if file name order is meaningfull)
92 # -------------------------------------------------------
93 /*
94 // To choose the directory
95 new DirectorySelector ds
96 // To get the image names into a vector
97 new FilesFromDirectory fd
98 // To read all the files, as a bbitk::ImagePointer
99 new ImageSeriesReader reader
100 // user choosen directory as input
101 connect ds.Out fd.In
102 set fd.Recursive false
103 // list of files as input
104 #print "Files found in $ds.Out$\n
105 connect fd.Out reader.FileNames
106 */
107
108 # uncomment the following lines to read a 3D images stack
109 # (if the directory contains a 'XCoherent" Serie)
110 # -------------------------------------------------------
111 /*
112 // To choose the directory
113 new DirectorySelector ds
114 // To get the image names into a vector
115 new FilesFromDirectory fd
116 // user choosen directory as input
117 connect ds.Out fd.In 
118 // order the files, computes an accurate ZSpacing
119 new GetXCoherentInfoGdcmReader reader
120 connect fd.Out reader.In
121 */
122
123 # uncomment the following lines to read a 3D images stack
124 # (with DICOMDirReader)
125 # -------------------------------------------------------
126 /*
127 include itk/boxes/bbDICOMDirReader
128 // To choose the directory
129 new DirectorySelector ds
130 new DICOMDirReader reader
131    connect ds.Out reader.In
132 */
133
134 // ==== END ======================================================
135
136
137
138
139 new CommandButton cb1
140    set cb1.Label "1) Select File"
141    set cb1.WinDialog true
142    connect cb1.Widget main.Widget1
143  
144 connect cb1.BoxChange reader.BoxExecute
145
146 new SimpleSlicer slc
147    set slc.Orientation 2
148    set slc.SliderReactiveOnTrack 1   
149    connect reader.Out slc.In
150    // It doesn't work ?!?, needs to "exec slc" // JPR
151    connect reader.BoxChange slc.BoxExecute
152
153 exec slc
154
155 new CommandButton cb
156    connect cb.Widget main.Widget2
157    set cb.Label "2) Write (no '.mhd' extention needed!"
158    set cb.WinDialog true
159    
160 new CommandButton next
161    connect next.Widget main.Widget3
162    set next.Label "Next !"
163    set next.WinDialog true
164    // It doesn't work : <<the black box "main" is still connected">>
165    set next.In "delete main"
166
167 # Choose where you want to write
168 # ------------------------------
169 new FileSelector fileDialog
170   set fileDialog.OpenSave Save
171   set fileDialog.Wildcard "*.mhd"
172   
173 new  MakeFileName mfn
174    connect fileDialog.Out mfn.File
175    set mfn.Extent ".mhd"
176     
177 # Write!
178 # ------
179    
180 new MetaImageWriter writer
181   connect reader.Out writer.In 
182   connect mfn.Out writer.Filename
183   connect cb.BoxChange writer.BoxExecute
184    
185 exec main
186