]> Creatis software - bbtk.git/blob - packages/demo/bbs/appli/SaveAsMhd.bbs
small tools
[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 ImagesReader 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 // Normally (?) the following lines {== BEGIN == / ==END ==}
28 // are now useless; let here as a reminder/example
29 // Don't remove them . JPRx
30
31 // ==== BEGIN ======================================================
32
33 /* 
34 # Dummy way to get only the first image from the chooser
35 # ------------------------------------------------------
36 load creaImageIO
37 new ImagesReader chooser
38
39 new GetVectorVtkImageDataElement reader
40    set reader.I 0
41    connect chooser.Out reader.In
42 */
43
44 # Here loads 'hola.mhd'
45 # ---------------------
46
47 # Don't forget to comment out the following 2 lines
48 # If you want to check someting else.
49
50 /*
51 include vtk/boxes/bbLoadHola
52 new LoadHola reader
53 */
54
55 # uncomment next lines to have a file selector
56 # --------------------------------------------
57 /*
58 new FileSelector openFileDialog
59 new ImageReader reader
60   connect openFileDialog.Out reader.In
61 */
62
63 # uncomment next lines to use a vtkgdcmReader
64 # -------------------------------------
65 /*
66 new FileSelector openFileDialog
67 new GetInfoGdcmReader reader
68   connect openFileDialog.Out reader.In
69 */
70
71 # uncomment next lines to use Gimmick
72 # -----------------------------------
73 /*
74 load creaImageIO
75 new Gimmick reader
76 */
77
78 # uncomment next lines to Read a MHD file (and nothing else !)
79 # ------------------------------------------------------------
80 /*
81 new FileSelector openFileDialog
82  set openFileDialog.Wildcard  "(*.mhd)|*.mhd"
83 new MetaImageReader reader
84    connect openFileDialog.Out reader.In
85 */
86
87 # uncomment the following lines to read a 3D images stack
88 # (only if file name order is meaningfull)
89 # -------------------------------------------------------
90 /*
91 // To choose the directory
92 new DirectorySelector ds
93 // To get the image names into a vector
94 new FilesFromDirectory fd
95 // To read all the files, as a bbitk::ImagePointer
96 new ImageSeriesReader reader
97 // user choosen directory as input
98 connect ds.Out fd.In
99 set fd.Recursive false
100 // list of files as input
101 #print "Files found in $ds.Out$\n
102 connect fd.Out reader.FileNames
103 */
104
105 # uncomment the following lines to read a 3D images stack
106 # (if the directory contains a 'XCoherent" Serie)
107 # -------------------------------------------------------
108 /*
109 // To choose the directory
110 new DirectorySelector ds
111 // To get the image names into a vector
112 new FilesFromDirectory fd
113 // user choosen directory as input
114 connect ds.Out fd.In 
115 // order the files, computes an accurate ZSpacing
116 new GetXCoherentInfoGdcmReader reader
117 connect fd.Out reader.In
118 */
119
120 # uncomment the following lines to read a 3D images stack
121 # (with DICOMDirReader)
122 # -------------------------------------------------------
123 /*
124 include itk/boxes/bbDICOMDirReader
125 // To choose the directory
126 new DirectorySelector ds
127 new DICOMDirReader reader
128    connect ds.Out reader.In
129 */
130
131 // ==== END ======================================================
132
133
134
135 new CommandButton cb1
136    connect cb1.Widget main.Widget1
137    set cb1.Label "1) Select File"
138    set cb1.WinDialog true
139
140 connect cb1.BoxChange reader.BoxExecute
141    
142 new CommandButton cb
143    connect cb.Widget main.Widget2
144    set cb.Label "2) Write (no '.mhd' extention needed!"
145    set cb.WinDialog true
146
147 # Choose where you want to write
148 # ------------------------------
149 new FileSelector fileDialog
150   set fileDialog.OpenSave Save
151   set fileDialog.Wildcard "*.mhd"
152   
153 new  MakeFileName mfn
154    connect fileDialog.Out mfn.File
155    set mfn.Extent ".mhd"
156     
157 # Write!
158 # ------
159    
160 new MetaImageWriter writer
161   connect reader.Out writer.In 
162   connect mfn.Out writer.Filename
163   connect cb.BoxChange writer.BoxExecute
164    
165 exec main
166