Program: gdcm
Module: $RCSfile: vtkGdcmWriter.cxx,v $
Language: C++
- Date: $Date: 2004/12/10 13:49:08 $
- Version: $Revision: 1.8 $
+ Date: $Date: 2005/02/25 19:54:06 $
+ Version: $Revision: 1.17 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
=========================================================================*/
-#include "gdcmHeader.h"
#include "gdcmFile.h"
+#include "gdcmFileHelper.h"
#include "gdcmDebug.h"
+#include "gdcmUtil.h"
#include "vtkGdcmWriter.h"
#include <vtkObjectFactory.h>
#include <vtkPointData.h>
#include <vtkLookupTable.h>
-vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.8 $");
+vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.17 $");
vtkStandardNewMacro(vtkGdcmWriter);
//-----------------------------------------------------------------------------
this->LookupTable = NULL;
this->FileDimensionality = 3;
this->WriteType = VTK_GDCM_WRITE_TYPE_EXPLICIT_VR;
+
+ UIDPrefix = "";
+ StudyInstanceUID = "";
+ SeriesInstanceUID = "";
+ FrameOfReferenceInstanceUID = "";
}
vtkGdcmWriter::~vtkGdcmWriter()
}
}
+void vtkGdcmWriter::SetUIDPrefix(const char *prefix)
+{
+ UIDPrefix = prefix;
+}
+
+const char *vtkGdcmWriter::GetUIDPrefix()
+{
+ return UIDPrefix.c_str();
+}
+
+void vtkGdcmWriter::NewStudyInstanceUID()
+{
+ StudyInstanceUID = "";
+}
+
+void vtkGdcmWriter::NewSeriesInstanceUID()
+{
+ SeriesInstanceUID = "";
+}
+
+void vtkGdcmWriter::NewFrameOfReferenceInstanceUID()
+{
+ FrameOfReferenceInstanceUID = "";
+}
+
//-----------------------------------------------------------------------------
// Protected
/**
/**
* Set the datas informations in the file
*/
-void SetImageInformation(gdcm::File *file,vtkImageData *image)
+void SetImageInformation(gdcm::FileHelper *file,vtkImageData *image)
{
std::ostringstream str;
str.str("");
str << dim[0];
- file->ReplaceOrCreateByNumber(str.str(),0x0028,0x0011); // Columns
+ file->InsertValEntry(str.str(),0x0028,0x0011); // Columns
str.str("");
str << dim[1];
- file->ReplaceOrCreateByNumber(str.str(),0x0028,0x0010); // Rows
+ file->InsertValEntry(str.str(),0x0028,0x0010); // Rows
if(dim[2]>1)
{
str.str("");
str << dim[2];
- //file->ReplaceOrCreateByNumber(str.str(),0x0028,0x0012); // Planes
- file->ReplaceOrCreateByNumber(str.str(),0x0028,0x0008); // Number of Frames
+ //file->Insert(str.str(),0x0028,0x0012); // Planes
+ file->InsertValEntry(str.str(),0x0028,0x0008); // Number of Frames
}
// Pixel type
str.str("");
str << image->GetScalarSize()*8;
- file->ReplaceOrCreateByNumber(str.str(),0x0028,0x0100); // Bits Allocated
- file->ReplaceOrCreateByNumber(str.str(),0x0028,0x0101); // Bits Stored
+ file->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated
+ file->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored
str.str("");
str << image->GetScalarSize()*8-1;
- file->ReplaceOrCreateByNumber(str.str(),0x0028,0x0102); // High Bit
+ file->InsertValEntry(str.str(),0x0028,0x0102); // High Bit
// Pixel Repr
// FIXME : what do we do when the ScalarType is
{
str << "1"; // Signed
}
- file->ReplaceOrCreateByNumber(str.str(),0x0028,0x0103); // Pixel Representation
+ file->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation
// Samples per pixel
str.str("");
str << image->GetNumberOfScalarComponents();
- file->ReplaceOrCreateByNumber(str.str(),0x0028,0x0002); // Samples per Pixel
+ file->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel
// Spacing
double *sp = image->GetSpacing();
str.str("");
+ // We are about to enter floating point value. By default ostringstream are smart and don't do fixed point
+ // thus forcing to fixed point value
+ str.setf( std::ios::fixed );
str << sp[0] << "\\" << sp[1];
- file->ReplaceOrCreateByNumber(str.str(),0x0028,0x0030); // Pixel Spacing
+ file->InsertValEntry(str.str(),0x0028,0x0030); // Pixel Spacing
str.str("");
str << sp[2];
- file->ReplaceOrCreateByNumber(str.str(),0x0018,0x0088); // Spacing Between Slices
+ file->InsertValEntry(str.str(),0x0018,0x0088); // Spacing Between Slices
// Origin
double *org = image->GetOrigin();
str.str("");
str << org[0] << "\\" << org[1] << "\\" << org[2];
- file->ReplaceOrCreateByNumber(str.str(),0x0020,0x0032); // Image Position Patient
+ file->InsertValEntry(str.str(),0x0020,0x0032); // Image Position Patient
+ str.unsetf( std::ios::fixed ); //done with floating point values
// Window / Level
double *rng=image->GetScalarRange();
str.str("");
str << rng[1]-rng[0];
- file->ReplaceOrCreateByNumber(str.str(),0x0028,0x1051); // Window Width
+ file->InsertValEntry(str.str(),0x0028,0x1051); // Window Width
str.str("");
str << (rng[1]+rng[0])/2.0;
- file->ReplaceOrCreateByNumber(str.str(),0x0028,0x1050); // Window Center
+ file->InsertValEntry(str.str(),0x0028,0x1050); // Window Center
// Pixels
unsigned char *data;
void vtkGdcmWriter::WriteDcmFile(char *fileName,vtkImageData *image)
{
// From here, the write of the file begins
- gdcm::File *dcmFile = new gdcm::File();
+ gdcm::FileHelper *dcmFile = new gdcm::FileHelper();
+
+ // Set the image UID
+ if( StudyInstanceUID.empty() )
+ StudyInstanceUID = gdcm::Util::CreateUniqueUID( UIDPrefix );
+ if( SeriesInstanceUID.empty() )
+ SeriesInstanceUID = gdcm::Util::CreateUniqueUID( UIDPrefix );
+ if( FrameOfReferenceInstanceUID.empty() )
+ FrameOfReferenceInstanceUID = gdcm::Util::CreateUniqueUID( UIDPrefix );
+ std::string uid = gdcm::Util::CreateUniqueUID( UIDPrefix );
+
+ dcmFile->InsertValEntry(uid,0x0008,0x0018); //[SOP Instance UID]
+ dcmFile->InsertValEntry(uid,0x0002,0x0003); //[Media Stored SOP Instance UID]
+ dcmFile->InsertValEntry(StudyInstanceUID,0x0020,0x000d); //[Study Instance UID]
+ dcmFile->InsertValEntry(SeriesInstanceUID,0x0020,0x000e); //[Series Instance UID]
+ dcmFile->InsertValEntry(FrameOfReferenceInstanceUID,0x0020, 0x0052); //[Frame of Reference UID]
// Set the image informations
SetImageInformation(dcmFile,image);
{
vtkErrorMacro( << "File " << this->FileName << "couldn't be written by "
<< " the gdcm library");
- std::cerr << "not written \n";
}
// Clean up