]> Creatis software - gdcm.git/blobdiff - Example/Volume2Dicom.cxx
Display some more usefull Orientation/Position info
[gdcm.git] / Example / Volume2Dicom.cxx
index a4721fff2563c5e3cf5abca43a28292b5fa4da9e..facc30a4a43de64a12cf66b4921a6f8ee5aa60f8 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: Volume2Dicom.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/20 16:16:58 $
-  Version:   $Revision: 1.4 $
+  Date:      $Date: 2005/09/07 08:35:20 $
+  Version:   $Revision: 1.8 $
                                                                                  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -23,7 +23,7 @@
  * It's aim is to show people how to write their data volume into DICOM slices
  */
 
-#include "gdcmHeader.h"
+#include "gdcmFile.h"
 #include "gdcmDocEntry.h"
 #include "gdcmBinEntry.h"
 #include "gdcmFileHelper.h"
    #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) 
    {
@@ -99,33 +100,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::FileHelper  *f1 = new gdcm::FileHelper(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 +135,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 +144,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)