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