]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/include/marSimpleDicom.cpp
97b70f27fcf591f53119edc354489e41b48fa5a5
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / include / marSimpleDicom.cpp
1 /*=========================================================================
2
3  Program:   wxMaracas
4  Module:    $RCSfile: marSimpleDicom.cpp,v $
5  Language:  C++
6  Date:      $Date: 2009/05/14 13:55:08 $
7  Version:   $Revision: 1.1 $
8
9   Copyright: (c) 2002, 2003
10   License:
11
12    This software is distributed WITHOUT ANY WARRANTY; without even
13    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14    PURPOSE.  See the above copyright notice for more information.
15
16 =========================================================================*/
17
18 #ifdef _MSC_VER
19 #pragma warning ( disable : 4786 )
20 #pragma warning ( disable : 4251 )
21 #endif //_MSC_VER
22
23 // PS -> #include "gdcm.h"
24 #include "marSimpleDicom.h"
25 #include <wx/file.h>
26 #include <wx/filename.h>
27 #include <wx/dir.h>
28 #include <vector>
29 #include <string>
30 // PS -> #include "vtkGdcmReader.h"
31 #include <vtkImageChangeInformation.h>
32 #include <vtkImageCast.h>
33 #include <vtkImageResample.h>
34 #include <vtkImageShiftScale.h>
35 // PS -> #include <gdcmHeaderHelper.h>
36 #include <vtkCommand.h>
37 #include <vtkUnsignedShortArray.h>
38 #include <vtkPointData.h>
39
40 #include <wx/gauge.h>
41 #include <wx/app.h>
42
43
44
45 //----------------------------------------------------------------------------
46 // Callback for the interaction
47 class marProgressObserver : public vtkCommand
48 {
49 public:
50         static marProgressObserver *New()
51     { return new marProgressObserver; }
52     marProgressObserver()
53     {
54                 this->FrameGauge = NULL;
55     }
56         virtual void Execute(vtkObject *wdg, unsigned long event, void* calldata)
57     {
58                 if ( this->FrameGauge )
59         {
60                         int val = this->FrameGauge->GetValue();
61                         this->FrameGauge->SetValue( val + 1);
62                         //wxYield();
63                         //wxSafeYield();
64                         //wxYieldIfNeeded();
65                         //wxWakeUpIdle();
66                         //wxSafeYield( this->FrameGauge, FALSE);
67         }
68     }
69         wxGauge *FrameGauge;
70 };
71 //----------------------------------------------------------------------------
72
73
74 static char* DicomTagsNames[] = {
75     "ID_File_Name",
76                 "ID_SOP_Class_UID",                     //!0008 0016 UI ID SOP Class UID
77                 "ID_SOP_Instance_UID",                  //!0008 0018 UI ID SOP Instance UID
78                 "ID_Study_Date",                        //!0008 0020 DA ID Study Date
79                 "ID_Series_Date",                       //!0008 0021 DA ID Series Date
80                 "ID_Acquisition_Date",                  //!0008 0022 DA ID Acquisition Date
81                 "ID_Image_Date",                        //!0008 0023 DA ID Image Date
82                 "ID_Study_Time",                        //!0008 0030 TM ID Study Time
83                 "ID_Series_Time",                       //!0008 0031 TM ID Series Time
84                 "ID_Acquisition_Time",                  //!0008 0032 TM ID Acquisition Time
85                 "ID_Image_Time",                        //!0008 0033 TM ID Image Time
86                 "ID_Modality",                          //!0008 0060 CS ID Modality
87                 "ID_Manufacturer",                      //!0008 0070 LO ID Manufacturer
88                 "ID_Institution_Name",                  //!0008 0080 LO ID Institution Name
89                 "ID_Study_Description",                 //!0008 1030 LO ID Study Description
90                 "ID_Series_Description",                //!0008 103e LO ID Series Description
91                 "ID_Admitting_Diagnoses_Description",   //!0008 1080 LO ID Admitting Diagnoses Description
92                 "ID_Patient_Name",                      //!0010 0010 PN PAT Patient Name
93                 "ID_Patient_ID",                        //!0010 0020 LO PAT Patient ID
94                 "ID_Body_Part_Examined",                //!0018 0015 CS ACQ Body Part Examined
95                 "ID_Scanning_Sequence",                 //!0018 0020 CS ACQ Scanning Sequence
96                 "ID_Sequence_Variant",                  //!0018 0021 CS ACQ Sequence Variant
97                 "ID_Scan_Options",                      //!0018 0022 CS ACQ Scan Options
98                 "ID_MR_Acquisition_Type",               //!0018 0023 CS ACQ MR Acquisition Type
99                 "ID_Sequence_Name",                     //!0018 0024 SH ACQ Sequence Name
100                 "ID_Slice_Thickness",                   //!0018 0050 DS ACQ Slice Thickness
101                 "ID_Repetition_Time",                   //!0018 0080 DS ACQ Repetition Time
102                 "ID_Echo_Time",                         //!0018 0081 DS ACQ Echo Time
103                 "ID_Inversion_Time",                    //!0018 0082 DS ACQ Inversion Time
104                 "ID_Number_of_Averages",                //!0018 0083 DS ACQ Number of Averages
105                 "ID_Imaging_Frequency",                 //!0018 0084 DS ACQ Imaging Frequency
106                 "ID_Imaged_Nucleus",                    //!0018 0085 SH ACQ Imaged Nucleus
107                 "ID_Echo_Number",                       //!0018 0086 IS ACQ Echo Number
108                 "ID_Magnetic_Field_Strength",           //!0018 0087 DS ACQ Magnetic Field Strength
109                 "ID_Spacing_Between_Slices",            //!0018 0088 DS ACQ Spacing Between Slices
110                 "ID_Echo_Train_Length",                 //!0018 0091 IS ACQ Echo Train Length
111                 "ID_Percent_Sampling",                  //!0018 0093 DS ACQ Percent Sampling
112                 "ID_Percent_Phase_Field_of_View",       //!0018 0094 DS ACQ Percent Phase Field of View
113                 "ID_Receiving_Coil",                    //!0018 1250 SH ACQ Receiving Coil
114                 "ID_Patient_Position",                  //!0018 5100 CS ACQ Patient Position
115                 "ID_Study_Instance_UID",                //!0020 000d UI REL Study Instance UID
116                 "ID_Series_Instance_UID",               //!0020 000e UI REL Series Instance UID
117                 "ID_Study_ID",                          //!0020 0010 SH REL Study ID
118                 "ID_Series_Number",                     //!0020 0011 IS REL Series Number
119                 "ID_Acquisition_Number",                //!0020 0012 IS REL Acquisition Number
120                 "ID_Image_Number",                      //!0020 0013 IS REL Image Number
121                 "ID_Patient_Orientation",               //!0020 0020 CS REL Patient Orientation
122                 "ID_Image_Position",                    //!0020 0030 RET REL Image Position
123                 "ID_Image_Position_Patient",            //!0020 0032 DS REL Image Position Patient
124                 "ID_Image_Orientation",                 //!0020 0035 RET REL Image Orientation
125                 "ID_Image_Orientation_Patient",         //!0020 0037 DS REL Image Orientation (Patient)
126                 "ID_Location",                          //!0020 0050 RET REL Location
127                 "ID_Frame_of_Reference_UID",            //!0020 0052 UI REL Frame of Reference UID
128                 "ID_Slice_Location",                    //!0020 1041 DS REL Slice Location
129                 "ID_Image_Comments",                    //!0020 4000 LT REL Image Comments
130                 "ID_Pixel_Spacing",                     //!0028 0030 DS IMG Pixel Spacing
131                 "ID_Window_Center",                     //!0028 1050 DS IMG Window Center
132                 "ID_Window_Width",                      //!0028 1051 DS IMG Window Width
133 };
134
135 // -------------------------------------------------------------------------
136 marSimpleDicom::marSimpleDicom( marParameters* p )
137 : marFilesBase( p ), m_pSlicesPixels(NULL),
138 m_ActualStudy(0), m_ActualSerie(0)
139 // PS -> ,helper(NULL)
140 {
141         // FillDicomInfo( );
142 }
143
144 // -------------------------------------------------------------------------
145 marSimpleDicom::~marSimpleDicom(){
146         reset( );
147 }
148
149
150
151 /** Conversion de wxString en string. */
152 //#define ws2s(as) (string(as.GetData()))
153 /** Conversion de string en wxString. */
154 #define s2ws(s) (wxString((s).c_str()))
155 /** Conversion de C-string en wxString. */
156 //#define cs2ws(s) (wxString(s))
157
158 // -------------------------------------------------------------------------
159 // PS -> wxArrayString marGdcmDicom::gdcmGetExamInfo( wxString directoryname )
160 // PS -> {
161 // PS ->        wxArrayString temparray;
162 // PS ->        temparray.Alloc( 58 );
163 // PS ->
164 // PS ->        wxDir dir(directoryname);
165 // PS ->        wxString filename;
166 // PS ->        bool cont = dir.GetFirst( &filename, "*", wxDIR_FILES );
167 // PS ->        filename = directoryname + "/" + filename;
168 // PS ->
169 // PS ->        std::string val;
170 // PS ->
171 // PS ->        gdcmHeader GdcmHeader( filename.c_str() );
172 // PS ->        temparray.Add( filename );                                             //    "ID_File_Name",
173 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0016).c_str() );//    "ID_SOP_Class_UID",         //0008 0016 UI ID SOP Class UID
174 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0018).c_str() );//    "ID_SOP_Instance_UID",      //0008 0018 UI ID SOP Instance UID
175 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0020).c_str() );//    "ID_Study_Date",            //0008 0020 DA ID Study Date
176 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0021).c_str() );//    "ID_Series_Date",           //0008 0021 DA ID Series Date
177 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0022).c_str() );//    "ID_Acquisition_Date",      //0008 0022 DA ID Acquisition Date
178 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0023).c_str() );//    "ID_Image_Date",            //0008 0023 DA ID Image Date
179 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0030).c_str() );//    "ID_Study_Time",            //0008 0030 TM ID Study Time
180 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0031).c_str() );//    "ID_Series_Time",           //0008 0031 TM ID Series Time
181 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0032).c_str() );//    "ID_Acquisition_Time",      //0008 0032 TM ID Acquisition Time
182 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0033).c_str() );//    "ID_Image_Time",            //0008 0033 TM ID Image Time
183 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0060).c_str() );//    "ID_Modality",              //0008 0060 CS ID Modality
184 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0070).c_str() );//    "ID_Manufacturer",          //0008 0070 LO ID Manufacturer
185 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0080).c_str() );//    "ID_Institution_Name",      //0008 0080 LO ID Institution Name
186 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x1030).c_str() );//    "ID_Study_Description",     //0008 1030 LO ID Study Description
187 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x103e).c_str() );//    "ID_Series_Description",    //0008 103e LO ID Series Description
188 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x1080).c_str() );//    "ID_Admitting_Diagnoses_Description", //0008 1080 LO ID Admitting Diagnoses Description
189 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0010,0x0010).c_str() );//    "ID_Patient_Name",          //0010 0010 PN PAT Patient Name
190 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0010,0x0020).c_str() );//    "ID_Patient_ID",            //0010 0020 LO PAT Patient ID
191 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0015).c_str() );//    "ID_Body_Part_Examined",    //0018 0015 CS ACQ Body Part Examined
192 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0020).c_str() );//    "ID_Scanning_Sequence",     //0018 0020 CS ACQ Scanning Sequence
193 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0021).c_str() );//    "ID_Sequence_Variant",      //0018 0021 CS ACQ Sequence Variant
194 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0022).c_str() );//    "ID_Scan_Options",          //0018 0022 CS ACQ Scan Options
195 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0023).c_str() );//    "ID_MR_Acquisition_Type",   //0018 0023 CS ACQ MR Acquisition Type
196 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0024).c_str() );//    "ID_Sequence_Name",         //0018 0024 SH ACQ Sequence Name
197 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0050).c_str() );//    "ID_Slice_Thickness",       //0018 0050 DS ACQ Slice Thickness
198 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0080).c_str() );//    "ID_Repetition_Time",       //0018 0080 DS ACQ Repetition Time
199 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0081).c_str() );//    "ID_Echo_Time",             //0018 0081 DS ACQ Echo Time
200 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0082).c_str() );//    "ID_Inversion_Time",        //0018 0082 DS ACQ Inversion Time
201 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0083).c_str() );//    "ID_Number_of_Averages",    //0018 0083 DS ACQ Number of Averages
202 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0084).c_str() );//    "ID_Imaging_Frequency",     //0018 0084 DS ACQ Imaging Frequency
203 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0085).c_str() );//    "ID_Imaged_Nucleus",        //0018 0085 SH ACQ Imaged Nucleus
204 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0086).c_str() );//    "ID_Echo_Number",           //0018 0086 IS ACQ Echo Number
205 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0087).c_str() );//    "ID_Magnetic_Field_Strength", //0018 0087 DS ACQ Magnetic Field Strength
206 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0088).c_str() );//    "ID_Spacing_Between_Slices",  //0018 0088 DS ACQ Spacing Between Slices
207 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0091).c_str() );//    "ID_Echo_Train_Length",     //0018 0091 IS ACQ Echo Train Length
208 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0093).c_str() );//    "ID_Percent_Sampling",      //0018 0093 DS ACQ Percent Sampling
209 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0094).c_str() );//    "ID_Percent_Phase_Field_of_View", //0018 0094 DS ACQ Percent Phase Field of View
210 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x1250).c_str() );//    "ID_Receiving_Coil",        //0018 1250 SH ACQ Receiving Coil
211 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x5100).c_str() );//    "ID_Patient_Position",      //0018 5100 CS ACQ Patient Position
212 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x000d).c_str() );//    "ID_Study_Instance_UID",    //0020 000d UI REL Study Instance UID
213 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x000e).c_str() );//    "ID_Series_Instance_UID",   //0020 000e UI REL Series Instance UID
214 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0010).c_str() );//    "ID_Study_ID",              //0020 0010 SH REL Study ID
215 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0011).c_str() );//    "ID_Series_Number",         //0020 0011 IS REL Series Number
216 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0012).c_str() );//    "ID_Acquisition_Number",    //0020 0012 IS REL Acquisition Number
217 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0013).c_str() );//    "ID_Image_Number",          //0020 0013 IS REL Image Number
218 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0020).c_str() );//    "ID_Patient_Orientation",   //0020 0020 CS REL Patient Orientation
219 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0030).c_str() );//    "ID_Image_Position",        //0020 0030 RET REL Image Position
220 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0032).c_str() );//    "ID_Image_Position_Patient",  //0020 0032 DS REL Image Position Patient
221 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0035).c_str() );//    "ID_Image_Orientation",     //0020 0035 RET REL Image Orientation
222 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0037).c_str() );//    "ID_Image_Orientation_Patient", //0020 0037 DS REL Image Orientation (Patient)
223 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0050).c_str() );//    "ID_Location",              //0020 0050 RET REL Location
224 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0052).c_str() );//    "ID_Frame_of_Reference_UID",  //0020 0052 UI REL Frame of Reference UID
225 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x1041).c_str() );//    "ID_Slice_Location",        //0020 1041 DS REL Slice Location
226 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x4000).c_str() );//    "ID_Image_Comments",        //0020 4000 LT REL Image Comments
227 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0028,0x0030).c_str() );//    "ID_Pixel_Spacing",         //0028 0030 DS IMG Pixel Spacing
228 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0028,0x1050).c_str() );//    "ID_Window_Center",         //0028 1050 DS IMG Window Center
229 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0028,0x1051).c_str() );//    "ID_Window_Width",          //0028 1051 DS IMG Window Width
230 // PS ->
231 // PS ->        return temparray;
232 // PS ->
233 // PS -> }
234 #undef s2ws
235 // ----------------------------------------------------------------------------
236 // PS -> void marGdcmDicom::FillDicomInfo()
237 // PS -> {
238 // PS ->        reset();
239 // PS ->
240 // PS ->        //!\todo FIXME : m_DicomInfo.size() == 0
241 // PS ->        //if( m_DicomInfo.size() == 0 )
242 // PS ->        {
243 // PS ->                wxString file,subsubdir, subdir, rootdir = getParameters( )->getStringParam( marParameters::e_dicom_images_directory );
244 // PS ->                wxDir dir(rootdir);
245 // PS ->                bool cont = dir.GetFirst( &subdir, "*", wxDIR_DIRS );
246 // PS ->                while ( cont )
247 // PS ->                {
248 // PS ->                        subdir = rootdir + "/" + subdir;
249 // PS ->
250 // PS ->                        SerieInfo tempserie;
251 // PS ->                        wxDir dir2( subdir );
252 // PS ->                        bool cont2 = dir2.GetFirst( &subsubdir, "*", wxDIR_DIRS );
253 // PS ->                        while ( cont2 )
254 // PS ->                        {
255 // PS ->                                subsubdir = subdir + "/" + subsubdir;
256 // PS ->                                wxArrayString temptemp(gdcmGetExamInfo(subsubdir));
257 // PS ->                                tempserie.push_back(temptemp);
258 // PS ->                                cont2 = dir2.GetNext(&subsubdir);
259 // PS ->                        }
260 // PS ->
261 // PS ->                        m_DicomInfo.push_back( tempserie );
262 // PS ->                        cont = dir.GetNext(&subdir);
263 // PS ->                }
264 // PS ->        }
265 // PS -> }
266 //-------------------------------------------------------------------------
267 void marSimpleDicom::loadActualSerie( wxGauge* gauge)
268 {
269         // PS ->   #ifdef DXMM
270         loadVolumeDXMM( true , gauge);
271         // PS ->   #else
272         // PS ->   loadVolume( true , gauge);
273         // PS ->   #endif
274 }
275
276 // -------------------------------------------------------------------------
277 // PS -> void marGdcmDicom::loadVolume( bool force , wxGauge *gauge)
278 // PS -> {
279 // PS ->   float spacing[3];
280 // PS ->   vtkGdcmReader *gdcmReader = NULL;
281 // PS ->
282 // PS ->   if( force || !_volume )
283 // PS ->   {
284 // PS ->     freeVolume( );
285 // PS ->
286 // PS ->     wxFileName temp(m_DicomInfo[m_ActualStudy][m_ActualSerie][ID_File_Name]);
287 // PS ->
288 // PS ->     helper = new gdcmSerieHeaderHelper();
289 // PS ->     helper->SetDirectory( temp.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR ).c_str() );
290 // PS ->     helper->OrderGdcmFileList();
291 // PS ->
292 // PS ->     std::list<gdcmHeaderHelper*> flist = helper->GetGdcmFileList();
293 // PS ->     if( flist.size() > 0)
294 // PS ->     {
295 // PS ->       gdcmReader = vtkGdcmReader::New();
296 // PS ->       for(std::list<gdcmHeaderHelper*>::iterator it = flist.begin(); it != flist.end(); it++ )
297 // PS ->       {
298 // PS ->         gdcmReader->AddFileName( (*it)->GetFileName().c_str() );
299 // PS ->       }
300 // PS ->     } // fi
301 // PS ->   } // fi
302 // PS ->
303 // PS ->   marProgressObserver *progressEvent = marProgressObserver::New();
304 // PS ->   progressEvent->FrameGauge = gauge;
305 // PS ->   //gdcmReader->AddObserver( vtkCommand::ProgressEvent, progressEvent);
306 // PS ->   progressEvent->Delete();
307 // PS ->
308 // PS ->   //To simplyfy calculation later I turn Origin to (0, 0, 0)
309 // PS ->   //this shouldn't be 'trop grave'
310 // PS ->   vtkImageChangeInformation *change = vtkImageChangeInformation::New();
311 // PS ->   change->SetInput( gdcmReader->GetOutput() );
312 // PS ->   change->SetOutputOrigin( 0, 0, 0);
313 // PS ->   change->Update();
314 // PS ->
315 // PS ->   float *range = change->GetOutput()->GetScalarRange();
316 // PS ->
317 // PS ->   //Our algorithm are made based on unsigned short pixel/voxel:
318 // PS ->   //We need to cast our imagedata
319 // PS ->   vtkImageCast *cast = vtkImageCast::New();
320 // PS ->   cast->SetInput( change->GetOutput() );
321 // PS ->   cast->SetOutputScalarTypeToUnsignedShort();
322 // PS ->   cast->Update(); //important
323 // PS ->
324 // PS ->   //As I need to shift & scale I don't need anymore vtkImageCast:
325 // PS -> /*  vtkImageShiftScale *shift = vtkImageShiftScale::New();
326 // PS ->   shift->SetInput( change->GetOutput() );
327 // PS ->   shift->SetShift( -range[0] );
328 // PS ->   shift->SetScale( VTK_UNSIGNED_SHORT_MAX / (range[1] - range[0]) );
329 // PS ->   shift->SetOutputScalarTypeToUnsignedShort();
330 // PS ->   shift->Update();*/
331 // PS ->
332 // PS ->   cast->GetOutput()->GetSpacing( spacing );
333 // PS ->   getParameters( )->setDoubleParam( marParameters::e_voxel_x_dimension, spacing[0] );
334 // PS ->   getParameters( )->setDoubleParam( marParameters::e_voxel_y_dimension, spacing[1] );
335 // PS ->   getParameters( )->setDoubleParam( marParameters::e_voxel_z_dimension, spacing[2] );
336 // PS ->
337 // PS ->   //FIXME: kVolume doesn't need to be -again- matrix rotated (done in vtkGdcmReader)!!
338 // PS ->   _volume = new kVolume( cast->GetOutput() );
339 // PS ->
340 // PS ->   //!\todo thanks
341 // PS ->   if(gdcmReader) gdcmReader->Delete();
342 // PS ->   cast->Delete();
343 // PS ->   change->Delete();
344 // PS -> }
345
346 void marSimpleDicom::loadVolumeDXMM( bool force , wxGauge *gauge)
347 {
348 // PS ->
349 // PS ->  FILE *stream;
350 // PS ->  char string[20];
351 // PS ->  wxString prefix, fileParam, fileVol, rootdir;
352 // PS ->  rootdir=wxString("c:/temp");
353 // PS ->  wxDir dir(rootdir);
354 // PS ->  int dimX, dimY, dimZ;
355 // PS ->  float spacing[3];
356 // PS ->  vtkImageReader *volVTK = NULL;
357 // PS ->
358 // PS ->  fileParam = rootdir + "/" + "paramDxMM.txt";
359 // PS ->  stream = fopen(fileParam.c_str(),"r");
360 // PS ->
361 // PS ->  wxString errorMsg;
362 // PS ->  errorMsg= "Cannot open file "+fileParam;
363 // PS ->  wxASSERT_MSG(stream!=NULL,errorMsg);
364 // PS ->
365 // PS ->  fscanf(stream,"%s", string);
366 // PS ->  dimX = atoi(string);
367 // PS ->  fscanf(stream,"%s", string);
368 // PS ->  dimY = atoi(string);
369 // PS ->  fscanf(stream,"%s", string);
370 // PS ->  dimZ = atoi(string);
371 // PS ->  fscanf(stream,"%s", string);
372 // PS ->  spacing[0] = atof(string);
373 // PS ->  fscanf(stream,"%s", string);
374 // PS ->  spacing[1] = atof(string);
375 // PS ->  fscanf(stream,"%s", string);
376 // PS ->  spacing[2] = atof(string);
377 // PS ->  fclose(stream);
378 // PS ->
379 // PS ->  getParameters( )->setDoubleParam( marParameters::e_voxel_x_dimension, spacing[0] );
380 // PS ->  getParameters( )->setDoubleParam( marParameters::e_voxel_y_dimension, spacing[1] );
381 // PS ->  getParameters( )->setDoubleParam( marParameters::e_voxel_z_dimension, spacing[2] );
382 // PS ->
383 // PS ->  if( force || !_volume )
384 // PS ->  {
385 // PS ->        freeVolume( );
386 // PS ->  } // fi
387 // PS ->
388 // PS ->  marProgressObserver *progressEvent = marProgressObserver::New();
389 // PS ->  progressEvent->FrameGauge = gauge;
390 // PS ->  progressEvent->Delete();
391 // PS ->
392 // PS ->  prefix = rootdir + "/" + "imaDxMM";
393 // PS ->  volVTK = vtkImageReader::New();
394 // PS ->  volVTK->SetDataByteOrderToLittleEndian();
395 // PS ->  volVTK->SetDataScalarTypeToUnsignedShort();
396 // PS ->  volVTK->SetDataExtent(0, dimX-1, 0, dimY-1, 0, dimZ-1);
397 // PS ->  volVTK->SetFilePrefix( prefix.c_str() );
398 // PS ->  volVTK->SetFilePattern( "%s%d.raw");
399 // PS ->  volVTK->SetDataSpacing(spacing[0],spacing[1],spacing[2]);
400 // PS ->  volVTK->Update();
401 // PS ->  vtkImageResample* ir = vtkImageResample::New( );
402 // PS ->  ir->SetInput(volVTK->GetOutput());
403 // PS ->  ir->SetDimensionality( 3 );
404 // PS ->  ir->SetAxisOutputSpacing( 0, getParameters( )->getVoxelSize( ) );
405 // PS ->  ir->SetAxisOutputSpacing( 1, getParameters( )->getVoxelSize( ) );
406 // PS ->  ir->SetAxisOutputSpacing( 2, getParameters( )->getVoxelSize( ) );
407 // PS ->  ir->InterpolateOn( );
408 // PS ->  ir->Update( );    //important
409 // PS ->
410 // PS ->  _volume = new kVolume( ir->GetOutput( ) );
411 // PS ->
412 // PS ->  //!\todo thanks
413 // PS ->  if (ir) ir->Delete( );
414 // PS ->  if(volVTK) volVTK->Delete();
415
416         if (m_pSlicesPixels!=NULL)
417         {
418                 vtkUnsignedShortArray * dataArray=vtkUnsignedShortArray::New();
419
420                 int iRow,iColumn,iSlice,iPixel;
421
422                 int iiSlice;
423                 for (iiSlice=0;iiSlice<m_nSlices;iiSlice++)
424                 {
425                         if (_investSliceOrder==false) {
426                                 iSlice=iiSlice;
427                         } else {
428                                 iSlice=(iiSlice*(-1)) + m_nSlices - 1;
429                         }
430
431                         for (iRow=0;iRow<m_nY;iRow++)
432                         {
433                                 for (iColumn=0;iColumn<m_nX;iColumn++)
434                                 {
435                                         iPixel=(m_nSlices-1-iSlice)*m_nX*m_nY + (m_nY-1-iRow)*m_nX + iColumn;
436                                         dataArray->InsertNextValue(m_pSlicesPixels[iPixel]);
437                                 }                               
438                         }
439                 }
440                 vtkImageData*imgData=vtkImageData::New();
441                 imgData->SetDimensions(m_nX,m_nY,m_nSlices);
442                 imgData->SetSpacing(m_PixelSpacingRow,m_PixelSpacingColumn,m_PixelSpacingSlice);
443                 imgData->SetOrigin(0,0,0);
444                 imgData->SetScalarTypeToUnsignedShort();
445                 imgData->GetPointData()->SetScalars(dataArray);
446
447
448                 // TO DO : remplir le vtkImageResample
449                 vtkImageResample* ir = vtkImageResample::New();
450                 ir->SetInput(imgData);
451                 ir->SetDimensionality( 3 );
452                 ir->SetAxisOutputSpacing( 0, getParameters()->getVoxelSize() );
453                 ir->SetAxisOutputSpacing( 1, getParameters()->getVoxelSize() );
454                 ir->SetAxisOutputSpacing( 2, getParameters()->getVoxelSize() );
455                 ir->InterpolateOn( );
456                 ir->Update( );    //important
457
458 // EED
459 //              _volume = new kVolume( ir->GetOutput( ) );
460                 SetVolume( new kVolume( ir->GetOutput()  )  );
461
462                 //!\todo thanks
463                 if (ir) ir->Delete();
464                 if(imgData) imgData->Delete();
465                 if(dataArray) dataArray->Delete();
466         getParameters( )->setDoubleParam( marParameters::e_RescaleSlope    , m_RescaleSlope     );
467         getParameters( )->setDoubleParam( marParameters::e_RescaleIntercept, m_RescaleIntercept );
468         }
469
470 }
471
472
473 // -------------------------------------------------------------------------
474 void marSimpleDicom::copyFrom( const marObject& from )
475 { //!\todo TODO
476 }
477
478 // -------------------------------------------------------------------------
479 bool marSimpleDicom::save( std::ofstream& os )
480 {
481 /*  int s = _actualStudy.length( );
482
483  os.write( ( const char* )&s, sizeof( int ) );
484  os.write( ( char* )_actualStudy.c_str( ), s * sizeof( char ) );
485
486   s = _actualSerie.length( );
487
488    os.write( ( const char* )&s, sizeof( int ) );
489         os.write( ( char* )_actualSerie.c_str( ), s * sizeof( char ) );*/
490
491         for(std::vector<SerieInfo>::iterator it1 = m_DicomInfo.begin();
492         it1 != m_DicomInfo.end(); it1++ )
493     {
494                 for(std::vector<wxArrayString>::iterator it2 = it1->begin();
495                 it2 != it1->end(); it2++ )
496         {
497             for(int i=0; i<it2->GetCount(); i++)
498                         {
499                 //wxString temp( it2->Item(i) );
500                 os << it2->Item(i); //temp;
501                         }
502         }
503     }
504
505
506
507         return( true );
508 }
509
510 // -------------------------------------------------------------------------
511 bool marSimpleDicom::load( std::ifstream& is )
512 {
513 /*  int s;
514
515  reset( );
516
517   is.read( ( char* )&s, sizeof( int ) );
518   _actualStudy.resize( s );
519   is.read( ( char* )_actualStudy.c_str( ), s * sizeof( char ) );
520   is.read( ( char* )&s, sizeof( int ) );
521   _actualSerie.resize( s );
522         is.read( ( char* )_actualSerie.c_str( ), s * sizeof( char ) );*/
523
524         for(std::vector<SerieInfo>::iterator it1 = m_DicomInfo.begin();
525         it1 != m_DicomInfo.end(); it1++ )
526     {
527                 for(std::vector<wxArrayString>::iterator it2 = it1->begin();
528                 it2 != it1->end(); it2++ )
529         {
530             for(int i=0; i<it2->GetCount(); i++)
531                         {
532                 std::string temp;
533                 is >> temp ;
534                 it2->Add( temp.c_str() );
535                         }
536         }
537     }
538
539
540         return( true );
541 }
542
543 // -------------------------------------------------------------------------
544 void marSimpleDicom::SetVolumeData( int dimX, 
545                                                                     int dimY, 
546                                                                         int dimZ, 
547                                                                         float spacingX, 
548                                                                         float spacingY, 
549                                                                         float spacingZ,
550                                                                         float rescaleSlope,
551                                                                         float rescaleIntercept,
552                                                                         unsigned short *pixels)
553 {
554         m_pSlicesPixels         = pixels;
555         m_nX                            = dimX;
556         m_nY                            = dimY;
557         m_nSlices                       = dimZ;
558         m_PixelSpacingColumn= spacingX;
559         m_PixelSpacingRow       = spacingY;
560         m_PixelSpacingSlice     = spacingZ;
561         m_RescaleSlope          = rescaleSlope;
562         m_RescaleIntercept      = rescaleIntercept;
563 }
564
565 // -------------------------------------------------------------------------
566 void marSimpleDicom::reset( ){
567 //              freeVolume( );
568                 //_imageFileNames.Clear( );
569                 
570                 int n = m_DicomInfo.size();
571                 ///\todo does this clear evrythg ?
572                 for(int i=0; i<n; i++) {
573                         m_DicomInfo[i].clear();
574                 }
575                 m_DicomInfo.clear();
576                 
577 // PS ->                if(helper)
578 // PS ->                        delete helper;
579 // PS ->                helper = NULL;
580                 m_pSlicesPixels         =       NULL;
581                 m_nX                            =       0;
582                 m_nY                            =       0;
583                 m_nSlices                       =       0;
584                 m_PixelSpacingColumn=   0;
585                 m_PixelSpacingRow       =       0;
586                 m_PixelSpacingSlice     =       0;
587                 m_RescaleSlope          =       1;
588                 m_RescaleIntercept      =       0;
589     }
590
591 // -------------------------------------------------------------------------
592 void marSimpleDicom::SetInvestSliceOrder(bool investSliceOrder){
593         _investSliceOrder=investSliceOrder;
594 }
595 // -------------------------------------------------------------------------
596