marSimpleDicom.cpp

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003  Program:   wxMaracas
00004  Module:    $RCSfile: marSimpleDicom.cpp,v $
00005  Language:  C++
00006  Date:      $Date: 2009/05/14 13:55:08 $
00007  Version:   $Revision: 1.1 $
00008 
00009   Copyright: (c) 2002, 2003
00010   License:
00011 
00012    This software is distributed WITHOUT ANY WARRANTY; without even
00013    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014    PURPOSE.  See the above copyright notice for more information.
00015 
00016 =========================================================================*/
00017 
00018 #ifdef _MSC_VER
00019 #pragma warning ( disable : 4786 )
00020 #pragma warning ( disable : 4251 )
00021 #endif //_MSC_VER
00022 
00023 // PS -> #include "gdcm.h"
00024 #include "marSimpleDicom.h"
00025 #include <wx/file.h>
00026 #include <wx/filename.h>
00027 #include <wx/dir.h>
00028 #include <vector>
00029 #include <string>
00030 // PS -> #include "vtkGdcmReader.h"
00031 #include <vtkImageChangeInformation.h>
00032 #include <vtkImageCast.h>
00033 #include <vtkImageResample.h>
00034 #include <vtkImageShiftScale.h>
00035 // PS -> #include <gdcmHeaderHelper.h>
00036 #include <vtkCommand.h>
00037 #include <vtkUnsignedShortArray.h>
00038 #include <vtkPointData.h>
00039 
00040 #include <wx/gauge.h>
00041 #include <wx/app.h>
00042 
00043 
00044 
00045 //----------------------------------------------------------------------------
00046 // Callback for the interaction
00047 class marProgressObserver : public vtkCommand
00048 {
00049 public:
00050         static marProgressObserver *New()
00051     { return new marProgressObserver; }
00052     marProgressObserver()
00053     {
00054                 this->FrameGauge = NULL;
00055     }
00056         virtual void Execute(vtkObject *wdg, unsigned long event, void* calldata)
00057     {
00058                 if ( this->FrameGauge )
00059         {
00060                         int val = this->FrameGauge->GetValue();
00061                         this->FrameGauge->SetValue( val + 1);
00062                         //wxYield();
00063                         //wxSafeYield();
00064                         //wxYieldIfNeeded();
00065                         //wxWakeUpIdle();
00066                         //wxSafeYield( this->FrameGauge, FALSE);
00067         }
00068     }
00069         wxGauge *FrameGauge;
00070 };
00071 //----------------------------------------------------------------------------
00072 
00073 
00074 static char* DicomTagsNames[] = {
00075     "ID_File_Name",
00076                 "ID_SOP_Class_UID",                     
00077                 "ID_SOP_Instance_UID",                  
00078                 "ID_Study_Date",                        
00079                 "ID_Series_Date",                       
00080                 "ID_Acquisition_Date",                  
00081                 "ID_Image_Date",                        
00082                 "ID_Study_Time",                        
00083                 "ID_Series_Time",                       
00084                 "ID_Acquisition_Time",                  
00085                 "ID_Image_Time",                        
00086                 "ID_Modality",                          
00087                 "ID_Manufacturer",                      
00088                 "ID_Institution_Name",                  
00089                 "ID_Study_Description",                 
00090                 "ID_Series_Description",                
00091                 "ID_Admitting_Diagnoses_Description",   
00092                 "ID_Patient_Name",                      
00093                 "ID_Patient_ID",                        
00094                 "ID_Body_Part_Examined",                
00095                 "ID_Scanning_Sequence",                 
00096                 "ID_Sequence_Variant",                  
00097                 "ID_Scan_Options",                      
00098                 "ID_MR_Acquisition_Type",               
00099                 "ID_Sequence_Name",                     
00100                 "ID_Slice_Thickness",                   
00101                 "ID_Repetition_Time",                   
00102                 "ID_Echo_Time",                         
00103                 "ID_Inversion_Time",                    
00104                 "ID_Number_of_Averages",                
00105                 "ID_Imaging_Frequency",                 
00106                 "ID_Imaged_Nucleus",                    
00107                 "ID_Echo_Number",                       
00108                 "ID_Magnetic_Field_Strength",           
00109                 "ID_Spacing_Between_Slices",            
00110                 "ID_Echo_Train_Length",                 
00111                 "ID_Percent_Sampling",                  
00112                 "ID_Percent_Phase_Field_of_View",       
00113                 "ID_Receiving_Coil",                    
00114                 "ID_Patient_Position",                  
00115                 "ID_Study_Instance_UID",                
00116                 "ID_Series_Instance_UID",               
00117                 "ID_Study_ID",                          
00118                 "ID_Series_Number",                     
00119                 "ID_Acquisition_Number",                
00120                 "ID_Image_Number",                      
00121                 "ID_Patient_Orientation",               
00122                 "ID_Image_Position",                    
00123                 "ID_Image_Position_Patient",            
00124                 "ID_Image_Orientation",                 
00125                 "ID_Image_Orientation_Patient",         
00126                 "ID_Location",                          
00127                 "ID_Frame_of_Reference_UID",            
00128                 "ID_Slice_Location",                    
00129                 "ID_Image_Comments",                    
00130                 "ID_Pixel_Spacing",                     
00131                 "ID_Window_Center",                     
00132                 "ID_Window_Width",                      
00133 };
00134 
00135 // -------------------------------------------------------------------------
00136 marSimpleDicom::marSimpleDicom( marParameters* p )
00137 : marFilesBase( p ), m_pSlicesPixels(NULL),
00138 m_ActualStudy(0), m_ActualSerie(0)
00139 // PS -> ,helper(NULL)
00140 {
00141         // FillDicomInfo( );
00142 }
00143 
00144 // -------------------------------------------------------------------------
00145 marSimpleDicom::~marSimpleDicom(){
00146         reset( );
00147 }
00148 
00149 
00150 
00152 //#define ws2s(as) (string(as.GetData()))
00154 #define s2ws(s) (wxString((s).c_str()))
00155 
00156 //#define cs2ws(s) (wxString(s))
00157 
00158 // -------------------------------------------------------------------------
00159 // PS -> wxArrayString marGdcmDicom::gdcmGetExamInfo( wxString directoryname )
00160 // PS -> {
00161 // PS ->        wxArrayString temparray;
00162 // PS ->        temparray.Alloc( 58 );
00163 // PS ->
00164 // PS ->        wxDir dir(directoryname);
00165 // PS ->        wxString filename;
00166 // PS ->        bool cont = dir.GetFirst( &filename, "*", wxDIR_FILES );
00167 // PS ->        filename = directoryname + "/" + filename;
00168 // PS ->
00169 // PS ->        std::string val;
00170 // PS ->
00171 // PS ->        gdcmHeader GdcmHeader( filename.c_str() );
00172 // PS ->        temparray.Add( filename );                                             //    "ID_File_Name",
00173 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0016).c_str() );//    "ID_SOP_Class_UID",         //0008 0016 UI ID SOP Class UID
00174 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0018).c_str() );//    "ID_SOP_Instance_UID",      //0008 0018 UI ID SOP Instance UID
00175 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0020).c_str() );//    "ID_Study_Date",            //0008 0020 DA ID Study Date
00176 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0021).c_str() );//    "ID_Series_Date",           //0008 0021 DA ID Series Date
00177 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0022).c_str() );//    "ID_Acquisition_Date",      //0008 0022 DA ID Acquisition Date
00178 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0023).c_str() );//    "ID_Image_Date",            //0008 0023 DA ID Image Date
00179 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0030).c_str() );//    "ID_Study_Time",            //0008 0030 TM ID Study Time
00180 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0031).c_str() );//    "ID_Series_Time",           //0008 0031 TM ID Series Time
00181 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0032).c_str() );//    "ID_Acquisition_Time",      //0008 0032 TM ID Acquisition Time
00182 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0033).c_str() );//    "ID_Image_Time",            //0008 0033 TM ID Image Time
00183 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0060).c_str() );//    "ID_Modality",              //0008 0060 CS ID Modality
00184 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0070).c_str() );//    "ID_Manufacturer",          //0008 0070 LO ID Manufacturer
00185 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x0080).c_str() );//    "ID_Institution_Name",      //0008 0080 LO ID Institution Name
00186 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x1030).c_str() );//    "ID_Study_Description",     //0008 1030 LO ID Study Description
00187 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x103e).c_str() );//    "ID_Series_Description",    //0008 103e LO ID Series Description
00188 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0008,0x1080).c_str() );//    "ID_Admitting_Diagnoses_Description", //0008 1080 LO ID Admitting Diagnoses Description
00189 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0010,0x0010).c_str() );//    "ID_Patient_Name",          //0010 0010 PN PAT Patient Name
00190 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0010,0x0020).c_str() );//    "ID_Patient_ID",            //0010 0020 LO PAT Patient ID
00191 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0015).c_str() );//    "ID_Body_Part_Examined",    //0018 0015 CS ACQ Body Part Examined
00192 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0020).c_str() );//    "ID_Scanning_Sequence",     //0018 0020 CS ACQ Scanning Sequence
00193 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0021).c_str() );//    "ID_Sequence_Variant",      //0018 0021 CS ACQ Sequence Variant
00194 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0022).c_str() );//    "ID_Scan_Options",          //0018 0022 CS ACQ Scan Options
00195 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0023).c_str() );//    "ID_MR_Acquisition_Type",   //0018 0023 CS ACQ MR Acquisition Type
00196 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0024).c_str() );//    "ID_Sequence_Name",         //0018 0024 SH ACQ Sequence Name
00197 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0050).c_str() );//    "ID_Slice_Thickness",       //0018 0050 DS ACQ Slice Thickness
00198 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0080).c_str() );//    "ID_Repetition_Time",       //0018 0080 DS ACQ Repetition Time
00199 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0081).c_str() );//    "ID_Echo_Time",             //0018 0081 DS ACQ Echo Time
00200 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0082).c_str() );//    "ID_Inversion_Time",        //0018 0082 DS ACQ Inversion Time
00201 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0083).c_str() );//    "ID_Number_of_Averages",    //0018 0083 DS ACQ Number of Averages
00202 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0084).c_str() );//    "ID_Imaging_Frequency",     //0018 0084 DS ACQ Imaging Frequency
00203 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0085).c_str() );//    "ID_Imaged_Nucleus",        //0018 0085 SH ACQ Imaged Nucleus
00204 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0086).c_str() );//    "ID_Echo_Number",           //0018 0086 IS ACQ Echo Number
00205 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0087).c_str() );//    "ID_Magnetic_Field_Strength", //0018 0087 DS ACQ Magnetic Field Strength
00206 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0088).c_str() );//    "ID_Spacing_Between_Slices",  //0018 0088 DS ACQ Spacing Between Slices
00207 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0091).c_str() );//    "ID_Echo_Train_Length",     //0018 0091 IS ACQ Echo Train Length
00208 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0093).c_str() );//    "ID_Percent_Sampling",      //0018 0093 DS ACQ Percent Sampling
00209 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x0094).c_str() );//    "ID_Percent_Phase_Field_of_View", //0018 0094 DS ACQ Percent Phase Field of View
00210 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x1250).c_str() );//    "ID_Receiving_Coil",        //0018 1250 SH ACQ Receiving Coil
00211 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0018,0x5100).c_str() );//    "ID_Patient_Position",      //0018 5100 CS ACQ Patient Position
00212 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x000d).c_str() );//    "ID_Study_Instance_UID",    //0020 000d UI REL Study Instance UID
00213 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x000e).c_str() );//    "ID_Series_Instance_UID",   //0020 000e UI REL Series Instance UID
00214 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0010).c_str() );//    "ID_Study_ID",              //0020 0010 SH REL Study ID
00215 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0011).c_str() );//    "ID_Series_Number",         //0020 0011 IS REL Series Number
00216 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0012).c_str() );//    "ID_Acquisition_Number",    //0020 0012 IS REL Acquisition Number
00217 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0013).c_str() );//    "ID_Image_Number",          //0020 0013 IS REL Image Number
00218 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0020).c_str() );//    "ID_Patient_Orientation",   //0020 0020 CS REL Patient Orientation
00219 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0030).c_str() );//    "ID_Image_Position",        //0020 0030 RET REL Image Position
00220 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0032).c_str() );//    "ID_Image_Position_Patient",  //0020 0032 DS REL Image Position Patient
00221 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0035).c_str() );//    "ID_Image_Orientation",     //0020 0035 RET REL Image Orientation
00222 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0037).c_str() );//    "ID_Image_Orientation_Patient", //0020 0037 DS REL Image Orientation (Patient)
00223 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0050).c_str() );//    "ID_Location",              //0020 0050 RET REL Location
00224 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x0052).c_str() );//    "ID_Frame_of_Reference_UID",  //0020 0052 UI REL Frame of Reference UID
00225 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x1041).c_str() );//    "ID_Slice_Location",        //0020 1041 DS REL Slice Location
00226 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0020,0x4000).c_str() );//    "ID_Image_Comments",        //0020 4000 LT REL Image Comments
00227 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0028,0x0030).c_str() );//    "ID_Pixel_Spacing",         //0028 0030 DS IMG Pixel Spacing
00228 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0028,0x1050).c_str() );//    "ID_Window_Center",         //0028 1050 DS IMG Window Center
00229 // PS ->        temparray.Add( GdcmHeader.GetPubElValByNumber(0x0028,0x1051).c_str() );//    "ID_Window_Width",          //0028 1051 DS IMG Window Width
00230 // PS ->
00231 // PS ->        return temparray;
00232 // PS ->
00233 // PS -> }
00234 #undef s2ws
00235 // ----------------------------------------------------------------------------
00236 // PS -> void marGdcmDicom::FillDicomInfo()
00237 // PS -> {
00238 // PS ->        reset();
00239 // PS ->
00240 // PS ->        //!\todo FIXME : m_DicomInfo.size() == 0
00241 // PS ->        //if( m_DicomInfo.size() == 0 )
00242 // PS ->        {
00243 // PS ->                wxString file,subsubdir, subdir, rootdir = getParameters( )->getStringParam( marParameters::e_dicom_images_directory );
00244 // PS ->                wxDir dir(rootdir);
00245 // PS ->                bool cont = dir.GetFirst( &subdir, "*", wxDIR_DIRS );
00246 // PS ->                while ( cont )
00247 // PS ->                {
00248 // PS ->                        subdir = rootdir + "/" + subdir;
00249 // PS ->
00250 // PS ->                        SerieInfo tempserie;
00251 // PS ->                        wxDir dir2( subdir );
00252 // PS ->                        bool cont2 = dir2.GetFirst( &subsubdir, "*", wxDIR_DIRS );
00253 // PS ->                        while ( cont2 )
00254 // PS ->                        {
00255 // PS ->                                subsubdir = subdir + "/" + subsubdir;
00256 // PS ->                                wxArrayString temptemp(gdcmGetExamInfo(subsubdir));
00257 // PS ->                                tempserie.push_back(temptemp);
00258 // PS ->                                cont2 = dir2.GetNext(&subsubdir);
00259 // PS ->                        }
00260 // PS ->
00261 // PS ->                        m_DicomInfo.push_back( tempserie );
00262 // PS ->                        cont = dir.GetNext(&subdir);
00263 // PS ->                }
00264 // PS ->        }
00265 // PS -> }
00266 //-------------------------------------------------------------------------
00267 void marSimpleDicom::loadActualSerie( wxGauge* gauge)
00268 {
00269         // PS ->   #ifdef DXMM
00270         loadVolumeDXMM( true , gauge);
00271         // PS ->   #else
00272         // PS ->   loadVolume( true , gauge);
00273         // PS ->   #endif
00274 }
00275 
00276 // -------------------------------------------------------------------------
00277 // PS -> void marGdcmDicom::loadVolume( bool force , wxGauge *gauge)
00278 // PS -> {
00279 // PS ->   float spacing[3];
00280 // PS ->   vtkGdcmReader *gdcmReader = NULL;
00281 // PS ->
00282 // PS ->   if( force || !_volume )
00283 // PS ->   {
00284 // PS ->     freeVolume( );
00285 // PS ->
00286 // PS ->     wxFileName temp(m_DicomInfo[m_ActualStudy][m_ActualSerie][ID_File_Name]);
00287 // PS ->
00288 // PS ->     helper = new gdcmSerieHeaderHelper();
00289 // PS ->     helper->SetDirectory( temp.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR ).c_str() );
00290 // PS ->     helper->OrderGdcmFileList();
00291 // PS ->
00292 // PS ->     std::list<gdcmHeaderHelper*> flist = helper->GetGdcmFileList();
00293 // PS ->     if( flist.size() > 0)
00294 // PS ->     {
00295 // PS ->       gdcmReader = vtkGdcmReader::New();
00296 // PS ->       for(std::list<gdcmHeaderHelper*>::iterator it = flist.begin(); it != flist.end(); it++ )
00297 // PS ->       {
00298 // PS ->         gdcmReader->AddFileName( (*it)->GetFileName().c_str() );
00299 // PS ->       }
00300 // PS ->     } // fi
00301 // PS ->   } // fi
00302 // PS ->
00303 // PS ->   marProgressObserver *progressEvent = marProgressObserver::New();
00304 // PS ->   progressEvent->FrameGauge = gauge;
00305 // PS ->   //gdcmReader->AddObserver( vtkCommand::ProgressEvent, progressEvent);
00306 // PS ->   progressEvent->Delete();
00307 // PS ->
00308 // PS ->   //To simplyfy calculation later I turn Origin to (0, 0, 0)
00309 // PS ->   //this shouldn't be 'trop grave'
00310 // PS ->   vtkImageChangeInformation *change = vtkImageChangeInformation::New();
00311 // PS ->   change->SetInput( gdcmReader->GetOutput() );
00312 // PS ->   change->SetOutputOrigin( 0, 0, 0);
00313 // PS ->   change->Update();
00314 // PS ->
00315 // PS ->   float *range = change->GetOutput()->GetScalarRange();
00316 // PS ->
00317 // PS ->   //Our algorithm are made based on unsigned short pixel/voxel:
00318 // PS ->   //We need to cast our imagedata
00319 // PS ->   vtkImageCast *cast = vtkImageCast::New();
00320 // PS ->   cast->SetInput( change->GetOutput() );
00321 // PS ->   cast->SetOutputScalarTypeToUnsignedShort();
00322 // PS ->   cast->Update(); //important
00323 // PS ->
00324 // PS ->   //As I need to shift & scale I don't need anymore vtkImageCast:
00325 // PS -> /*  vtkImageShiftScale *shift = vtkImageShiftScale::New();
00326 // PS ->   shift->SetInput( change->GetOutput() );
00327 // PS ->   shift->SetShift( -range[0] );
00328 // PS ->   shift->SetScale( VTK_UNSIGNED_SHORT_MAX / (range[1] - range[0]) );
00329 // PS ->   shift->SetOutputScalarTypeToUnsignedShort();
00330 // PS ->   shift->Update();*/
00331 // PS ->
00332 // PS ->   cast->GetOutput()->GetSpacing( spacing );
00333 // PS ->   getParameters( )->setDoubleParam( marParameters::e_voxel_x_dimension, spacing[0] );
00334 // PS ->   getParameters( )->setDoubleParam( marParameters::e_voxel_y_dimension, spacing[1] );
00335 // PS ->   getParameters( )->setDoubleParam( marParameters::e_voxel_z_dimension, spacing[2] );
00336 // PS ->
00337 // PS ->   //FIXME: kVolume doesn't need to be -again- matrix rotated (done in vtkGdcmReader)!!
00338 // PS ->   _volume = new kVolume( cast->GetOutput() );
00339 // PS ->
00340 // PS ->   //!\todo thanks
00341 // PS ->   if(gdcmReader) gdcmReader->Delete();
00342 // PS ->   cast->Delete();
00343 // PS ->   change->Delete();
00344 // PS -> }
00345 
00346 void marSimpleDicom::loadVolumeDXMM( bool force , wxGauge *gauge)
00347 {
00348 // PS ->
00349 // PS ->  FILE *stream;
00350 // PS ->  char string[20];
00351 // PS ->  wxString prefix, fileParam, fileVol, rootdir;
00352 // PS ->  rootdir=wxString("c:/temp");
00353 // PS ->  wxDir dir(rootdir);
00354 // PS ->  int dimX, dimY, dimZ;
00355 // PS ->  float spacing[3];
00356 // PS ->  vtkImageReader *volVTK = NULL;
00357 // PS ->
00358 // PS ->  fileParam = rootdir + "/" + "paramDxMM.txt";
00359 // PS ->  stream = fopen(fileParam.c_str(),"r");
00360 // PS ->
00361 // PS ->  wxString errorMsg;
00362 // PS ->  errorMsg= "Cannot open file "+fileParam;
00363 // PS ->  wxASSERT_MSG(stream!=NULL,errorMsg);
00364 // PS ->
00365 // PS ->  fscanf(stream,"%s", string);
00366 // PS ->  dimX = atoi(string);
00367 // PS ->  fscanf(stream,"%s", string);
00368 // PS ->  dimY = atoi(string);
00369 // PS ->  fscanf(stream,"%s", string);
00370 // PS ->  dimZ = atoi(string);
00371 // PS ->  fscanf(stream,"%s", string);
00372 // PS ->  spacing[0] = atof(string);
00373 // PS ->  fscanf(stream,"%s", string);
00374 // PS ->  spacing[1] = atof(string);
00375 // PS ->  fscanf(stream,"%s", string);
00376 // PS ->  spacing[2] = atof(string);
00377 // PS ->  fclose(stream);
00378 // PS ->
00379 // PS ->  getParameters( )->setDoubleParam( marParameters::e_voxel_x_dimension, spacing[0] );
00380 // PS ->  getParameters( )->setDoubleParam( marParameters::e_voxel_y_dimension, spacing[1] );
00381 // PS ->  getParameters( )->setDoubleParam( marParameters::e_voxel_z_dimension, spacing[2] );
00382 // PS ->
00383 // PS ->  if( force || !_volume )
00384 // PS ->  {
00385 // PS ->        freeVolume( );
00386 // PS ->  } // fi
00387 // PS ->
00388 // PS ->  marProgressObserver *progressEvent = marProgressObserver::New();
00389 // PS ->  progressEvent->FrameGauge = gauge;
00390 // PS ->  progressEvent->Delete();
00391 // PS ->
00392 // PS ->  prefix = rootdir + "/" + "imaDxMM";
00393 // PS ->  volVTK = vtkImageReader::New();
00394 // PS ->  volVTK->SetDataByteOrderToLittleEndian();
00395 // PS ->  volVTK->SetDataScalarTypeToUnsignedShort();
00396 // PS ->  volVTK->SetDataExtent(0, dimX-1, 0, dimY-1, 0, dimZ-1);
00397 // PS ->  volVTK->SetFilePrefix( prefix.c_str() );
00398 // PS ->  volVTK->SetFilePattern( "%s%d.raw");
00399 // PS ->  volVTK->SetDataSpacing(spacing[0],spacing[1],spacing[2]);
00400 // PS ->  volVTK->Update();
00401 // PS ->  vtkImageResample* ir = vtkImageResample::New( );
00402 // PS ->  ir->SetInput(volVTK->GetOutput());
00403 // PS ->  ir->SetDimensionality( 3 );
00404 // PS ->  ir->SetAxisOutputSpacing( 0, getParameters( )->getVoxelSize( ) );
00405 // PS ->  ir->SetAxisOutputSpacing( 1, getParameters( )->getVoxelSize( ) );
00406 // PS ->  ir->SetAxisOutputSpacing( 2, getParameters( )->getVoxelSize( ) );
00407 // PS ->  ir->InterpolateOn( );
00408 // PS ->  ir->Update( );    //important
00409 // PS ->
00410 // PS ->  _volume = new kVolume( ir->GetOutput( ) );
00411 // PS ->
00412 // PS ->  //!\todo thanks
00413 // PS ->  if (ir) ir->Delete( );
00414 // PS ->  if(volVTK) volVTK->Delete();
00415 
00416         if (m_pSlicesPixels!=NULL)
00417         {
00418                 vtkUnsignedShortArray * dataArray=vtkUnsignedShortArray::New();
00419 
00420                 int iRow,iColumn,iSlice,iPixel;
00421 
00422                 int iiSlice;
00423                 for (iiSlice=0;iiSlice<m_nSlices;iiSlice++)
00424                 {
00425                         if (_investSliceOrder==false) {
00426                                 iSlice=iiSlice;
00427                         } else {
00428                                 iSlice=(iiSlice*(-1)) + m_nSlices - 1;
00429                         }
00430 
00431                         for (iRow=0;iRow<m_nY;iRow++)
00432                         {
00433                                 for (iColumn=0;iColumn<m_nX;iColumn++)
00434                                 {
00435                                         iPixel=(m_nSlices-1-iSlice)*m_nX*m_nY + (m_nY-1-iRow)*m_nX + iColumn;
00436                                         dataArray->InsertNextValue(m_pSlicesPixels[iPixel]);
00437                                 }                               
00438                         }
00439                 }
00440                 vtkImageData*imgData=vtkImageData::New();
00441                 imgData->SetDimensions(m_nX,m_nY,m_nSlices);
00442                 imgData->SetSpacing(m_PixelSpacingRow,m_PixelSpacingColumn,m_PixelSpacingSlice);
00443                 imgData->SetOrigin(0,0,0);
00444                 imgData->SetScalarTypeToUnsignedShort();
00445                 imgData->GetPointData()->SetScalars(dataArray);
00446 
00447 
00448                 // TO DO : remplir le vtkImageResample
00449                 vtkImageResample* ir = vtkImageResample::New();
00450                 ir->SetInput(imgData);
00451                 ir->SetDimensionality( 3 );
00452                 ir->SetAxisOutputSpacing( 0, getParameters()->getVoxelSize() );
00453                 ir->SetAxisOutputSpacing( 1, getParameters()->getVoxelSize() );
00454                 ir->SetAxisOutputSpacing( 2, getParameters()->getVoxelSize() );
00455                 ir->InterpolateOn( );
00456                 ir->Update( );    //important
00457 
00458 // EED
00459 //              _volume = new kVolume( ir->GetOutput( ) );
00460                 SetVolume( new kVolume( ir->GetOutput()  )  );
00461 
00463                 if (ir) ir->Delete();
00464                 if(imgData) imgData->Delete();
00465                 if(dataArray) dataArray->Delete();
00466         getParameters( )->setDoubleParam( marParameters::e_RescaleSlope    , m_RescaleSlope     );
00467         getParameters( )->setDoubleParam( marParameters::e_RescaleIntercept, m_RescaleIntercept );
00468         }
00469 
00470 }
00471 
00472 
00473 // -------------------------------------------------------------------------
00474 void marSimpleDicom::copyFrom( const marObject& from )
00475 { 
00476 }
00477 
00478 // -------------------------------------------------------------------------
00479 bool marSimpleDicom::save( std::ofstream& os )
00480 {
00481 /*  int s = _actualStudy.length( );
00482 
00483  os.write( ( const char* )&s, sizeof( int ) );
00484  os.write( ( char* )_actualStudy.c_str( ), s * sizeof( char ) );
00485 
00486   s = _actualSerie.length( );
00487 
00488    os.write( ( const char* )&s, sizeof( int ) );
00489         os.write( ( char* )_actualSerie.c_str( ), s * sizeof( char ) );*/
00490 
00491         for(std::vector<SerieInfo>::iterator it1 = m_DicomInfo.begin();
00492         it1 != m_DicomInfo.end(); it1++ )
00493     {
00494                 for(std::vector<wxArrayString>::iterator it2 = it1->begin();
00495                 it2 != it1->end(); it2++ )
00496         {
00497             for(int i=0; i<it2->GetCount(); i++)
00498                         {
00499                 //wxString temp( it2->Item(i) );
00500                 os << it2->Item(i); //temp;
00501                         }
00502         }
00503     }
00504 
00505 
00506 
00507         return( true );
00508 }
00509 
00510 // -------------------------------------------------------------------------
00511 bool marSimpleDicom::load( std::ifstream& is )
00512 {
00513 /*  int s;
00514 
00515  reset( );
00516 
00517   is.read( ( char* )&s, sizeof( int ) );
00518   _actualStudy.resize( s );
00519   is.read( ( char* )_actualStudy.c_str( ), s * sizeof( char ) );
00520   is.read( ( char* )&s, sizeof( int ) );
00521   _actualSerie.resize( s );
00522         is.read( ( char* )_actualSerie.c_str( ), s * sizeof( char ) );*/
00523 
00524         for(std::vector<SerieInfo>::iterator it1 = m_DicomInfo.begin();
00525         it1 != m_DicomInfo.end(); it1++ )
00526     {
00527                 for(std::vector<wxArrayString>::iterator it2 = it1->begin();
00528                 it2 != it1->end(); it2++ )
00529         {
00530             for(int i=0; i<it2->GetCount(); i++)
00531                         {
00532                 std::string temp;
00533                 is >> temp ;
00534                 it2->Add( temp.c_str() );
00535                         }
00536         }
00537     }
00538 
00539 
00540         return( true );
00541 }
00542 
00543 // -------------------------------------------------------------------------
00544 void marSimpleDicom::SetVolumeData( int dimX, 
00545                                                                     int dimY, 
00546                                                                         int dimZ, 
00547                                                                         float spacingX, 
00548                                                                         float spacingY, 
00549                                                                         float spacingZ,
00550                                                                         float rescaleSlope,
00551                                                                         float rescaleIntercept,
00552                                                                         unsigned short *pixels)
00553 {
00554         m_pSlicesPixels         = pixels;
00555         m_nX                            = dimX;
00556         m_nY                            = dimY;
00557         m_nSlices                       = dimZ;
00558         m_PixelSpacingColumn= spacingX;
00559         m_PixelSpacingRow       = spacingY;
00560         m_PixelSpacingSlice     = spacingZ;
00561         m_RescaleSlope          = rescaleSlope;
00562         m_RescaleIntercept      = rescaleIntercept;
00563 }
00564 
00565 // -------------------------------------------------------------------------
00566 void marSimpleDicom::reset( ){
00567 //              freeVolume( );
00568                 //_imageFileNames.Clear( );
00569                 
00570                 int n = m_DicomInfo.size();
00572                 for(int i=0; i<n; i++) {
00573                         m_DicomInfo[i].clear();
00574                 }
00575                 m_DicomInfo.clear();
00576                 
00577 // PS ->                if(helper)
00578 // PS ->                        delete helper;
00579 // PS ->                helper = NULL;
00580                 m_pSlicesPixels         =       NULL;
00581                 m_nX                            =       0;
00582                 m_nY                            =       0;
00583                 m_nSlices                       =       0;
00584                 m_PixelSpacingColumn=   0;
00585                 m_PixelSpacingRow       =       0;
00586                 m_PixelSpacingSlice     =       0;
00587                 m_RescaleSlope          =       1;
00588                 m_RescaleIntercept      =       0;
00589     }
00590 
00591 // -------------------------------------------------------------------------
00592 void marSimpleDicom::SetInvestSliceOrder(bool investSliceOrder){
00593         _investSliceOrder=investSliceOrder;
00594 }
00595 // -------------------------------------------------------------------------
00596 

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1