]> Creatis software - gdcm.git/blobdiff - Example/Volume2Dicom.cxx
* Fix bug when reading the DicomVR.dic file
[gdcm.git] / Example / Volume2Dicom.cxx
index 05eeeb84f8b5a075f0523744f0474ad723eccdc5..8d18a440b81fd7d75749fb605a9a19d8b3203dd1 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: Volume2Dicom.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/12/04 08:57:19 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2005/10/18 08:35:43 $
+  Version:   $Revision: 1.9 $
                                                                                  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
  * It's aim is to show people how to write their data volume into DICOM slices
  */
 
-#include "gdcmHeader.h"
-#include "gdcmDocEntry.h"
-#include "gdcmBinEntry.h"
 #include "gdcmFile.h"
+#include "gdcmDocEntry.h"
+#include "gdcmFileHelper.h"
 #include "gdcmUtil.h"
 
 #define USAGE "USAGE: Input3DImage OutputDirectory"
    #define stat _stat
 #endif
 
-const unsigned int Dimension = 3;
+//const unsigned int Dimension = 3;
 
 void gdcmwrite(const char *inputfile, std::string directory);
-void GetFileDateAndTime(const char *inputfile, std::string &date, std::string &time);
+void GetFileDateAndTime(const char *inputfile, 
+                        std::string &date, std::string &time);
 
-int main( int argc, char * argv[] )
+int main( int argc, char *argv[] )
 {
    if (argc < 2) 
    {
@@ -87,8 +87,8 @@ int main( int argc, char * argv[] )
        if (val < min) 
           min = val;
     }
-    float wcenter = (max+min) / 2.;
-    float wwidth  = (max-min)>0 ? (max-min) : 1.;
+    //float wcenter = (max+min) / 2.;
+    //float wwidth  = (max-min)>0 ? (max-min) : 1.;
 
     ////////////////////////////////////////////////////////////
     // Get file date and time                                 //
@@ -99,33 +99,33 @@ int main( int argc, char * argv[] )
     ////////////////////////////////////////////////////////////
     // Create a new dicom header and fill in some info        //
     ////////////////////////////////////////////////////////////
-    gdcm::Header *h1 = new gdcm::Header();
-
-    //h1->SetDateAndTime(filedate, filetime);
-    //h1->SetModality("CT");
-    //h1->SetPatientName( "TestPatient");
-    //h1->SetPatientID( "TestID");
-    //h1->SetStudyID( "1");
-    //h1->SetSeriesNumber( "1");
-    //h1->SetSliceThickness(spacing[2]);
-    //h1->SetSpaceBetweenSlices(spacing[2]);
-    //h1->SetXYSpacing( spacing[0], spacing[1]);
-    //h1->SetXSize(sizex);
-    //h1->SetYSize(sizey);
-    //h1->SetNbBitsAllocated(16);
-    //h1->SetNbBitsStored(12);
-    //h1->SetNbBitsStored(12);
-    //h1->SetPixelSigned(true);
-    //h1->SetCenter( wcenter);
-    //h1->SetWindow( wwidth);
+    gdcm::File *f = new gdcm::File();
+
+    //f->SetDateAndTime(filedate, filetime);
+    //f->SetModality("CT");
+    //f->SetPatientName( "TestPatient");
+    //f->SetPatientID( "TestID");
+    //f->SetStudyID( "1");
+    //f->SetSeriesNumber( "1");
+    //f->SetSliceThickness(spacing[2]);
+    //f->SetSpaceBetweenSlices(spacing[2]);
+    //f->SetXYSpacing( spacing[0], spacing[1]);
+    //f->SetXSize(sizex);
+    //f->SetYSize(sizey);
+    //f->SetNbBitsAllocated(16);
+    //f->SetNbBitsStored(12);
+    //f->SetNbBitsStored(12);
+    //f->SetPixelSigned(true);
+    //f->SetCenter( wcenter);
+    //f->SetWindow( wwidth);
 
     ////////////////////////////////////////////////////////////
     // Create a new dicom file object from the header         //
     ////////////////////////////////////////////////////////////
-    gdcm::File  *f1 = new gdcm::File(h1);
-    uint8_t *myData = f1->GetImageData(); // Get an Image pointer
-    f1->SetImageData( myData, sliceSize); // This callback ensures that the internal
-                                          // Pixel_Data of f1 is set correctly
+    gdcm::FileHelper  *fh = new gdcm::FileHelper(f);
+    uint8_t *myData = fh->GetImageData(); // Get an Image pointer
+    fh->SetImageData( myData, sliceSize); // This callback ensures that the internal
+                                          // Pixel_Data of fh is set correctly
 
     
     ////////////////////////////////////////////////////////////
@@ -134,8 +134,8 @@ int main( int argc, char * argv[] )
     for (int z=0; z<sizez; z++) 
     {
        // Set dicom relevant information for that slice
-       //h1->SetImageUIDFromSliceNumber(z);
-       //h1->SetImageLocation(orig[0],orig[1],orig[2]+z*spacing[2]);
+       //f->SetImageUIDFromSliceNumber(z);
+       //f->SetImageLocation(orig[0],orig[1],orig[2]+z*spacing[2]);
 
        // copy image slice content
        memcpy(myData,imageData+z*sizex*sizey,sliceSize);
@@ -143,22 +143,23 @@ int main( int argc, char * argv[] )
        // write the image
        std::string filename = directory + gdcm::Util::Format("%Image_%05d.dcm", z);
        std::cout << "Writing file " << filename;
-       f1->WriteDcmExplVR(filename);
+       fh->WriteDcmExplVR(filename);
        std::cout << " OK" << std::endl;
     }
 
     ////////////////////////////////////////////////////////////
     // Free the allocated objects                             //
     ////////////////////////////////////////////////////////////
-    // delete f1; // FIXME: these calls sometimes crashes under .NET ????
-    // delete h1;
+    // delete fh; // FIXME: these calls sometimes crashes under .NET ????
+    // delete f;
 
     return 0;
 }
 
 
 // just an utility function to retrieve date and time of a file
-void GetFileDateAndTime(const char *inputfile, std::string &date, std::string &time)
+void GetFileDateAndTime(const char *inputfile, std::string &date, 
+                                               std::string &time)
 {
    struct stat buf;    
    if (stat(inputfile, &buf) == 0)