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
* 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)
{
////////////////////////////////////////////////////////////
// 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
////////////////////////////////////////////////////////////
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);
// 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)