X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vtk%2FvtkGdcmWriter.cxx;h=2b5764734e7bf721b050436b65e9f878b76bfac8;hb=6f03d7978c122dfc2c7a0ee6bc9f2fd019d98ca3;hp=9a17fa60feae44df8d59973869540e10e9a5571b;hpb=d735b22c6656c1b5d05d560ff9773a016a8514f9;p=gdcm.git diff --git a/vtk/vtkGdcmWriter.cxx b/vtk/vtkGdcmWriter.cxx index 9a17fa60..2b576473 100644 --- a/vtk/vtkGdcmWriter.cxx +++ b/vtk/vtkGdcmWriter.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: vtkGdcmWriter.cxx,v $ Language: C++ - Date: $Date: 2006/05/02 10:09:43 $ - Version: $Revision: 1.29 $ + Date: $Date: 2007/12/13 15:16:19 $ + Version: $Revision: 1.36 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -33,19 +33,19 @@ #define vtkFloatingPointType float #endif -vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.29 $") +vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.36 $") vtkStandardNewMacro(vtkGdcmWriter) -vtkCxxSetObjectMacro(vtkGdcmWriter,LookupTable,vtkLookupTable); +vtkCxxSetObjectMacro(vtkGdcmWriter,LookupTable,vtkLookupTable) #if (VTK_MAJOR_VERSION >= 5) -vtkCxxSetObjectMacro(vtkGdcmWriter,MedicalImageProperties,vtkMedicalImageProperties); +vtkCxxSetObjectMacro(vtkGdcmWriter,MedicalImageProperties,vtkMedicalImageProperties) #endif //----------------------------------------------------------------------------- // Constructor / Destructor vtkGdcmWriter::vtkGdcmWriter() { this->LookupTable = NULL; - this->MedicalImageProperties = NULL; + this->MedicalImageProperties = NULL; this->FileDimensionality = 3; this->WriteType = VTK_GDCM_WRITE_TYPE_EXPLICIT_VR; this->GdcmFile = 0; @@ -94,7 +94,11 @@ const char *vtkGdcmWriter::GetWriteTypeAsString() // The output data must be deleted by the user of the method !!! size_t ReverseData(vtkImageData *image,unsigned char **data) { +#if (VTK_MAJOR_VERSION >= 5) + vtkIdType inc[3]; +#else int inc[3]; +#endif int *extent = image->GetUpdateExtent(); int dim[3] = {extent[1]-extent[0]+1, extent[3]-extent[2]+1, @@ -133,54 +137,67 @@ size_t ReverseData(vtkImageData *image,unsigned char **data) return size; } - /** - * Set the medical informations in the file, based on the user passed - * vtkMedicalImageProperties - */ -#if (VTK_MAJOR_VERSION >= 5) -void SetMedicalImageInformation(gdcm::FileHelper *file, vtkMedicalImageProperties *medprop) +/** + * Set the medical informations in the file, based on the user passed + * vtkMedicalImageProperties + */ +#if (VTK_MAJOR_VERSION >= 5) +void SetMedicalImageInformation(GDCM_NAME_SPACE::FileHelper *file, vtkMedicalImageProperties *medprop) { // For now only do: // PatientName, PatientID, PatientAge, PatientSex, PatientBirthDate, StudyID - std::ostringstream str; + std::ostringstream str; if( medprop ) - { - str.str(""); - str << medprop->GetPatientName(); - file->InsertValEntry(str.str(),0x0010,0x0010); // PN 1 Patient's Name - - str.str(""); - str << medprop->GetPatientID(); - file->InsertValEntry(str.str(),0x0010,0x0020); // LO 1 Patient ID - - str.str(""); - str << medprop->GetPatientAge(); - file->InsertValEntry(str.str(),0x0010,0x1010); // AS 1 Patient's Age - - str.str(""); - str << medprop->GetPatientSex(); - file->InsertValEntry(str.str(),0x0010,0x0040); // CS 1 Patient's Sex - - str.str(""); - str << medprop->GetPatientBirthDate(); - file->InsertValEntry(str.str(),0x0010,0x0030); // DA 1 Patient's Birth Date - - str.str(""); - str << medprop->GetStudyID(); - file->InsertValEntry(str.str(),0x0020,0x0010); // SH 1 Study ID - } - } - -#else -void SetMedicalImageInformation(gdcm::FileHelper *, vtkMedicalImageProperties *) -{ + { + if (medprop->GetPatientName()) + { + str.str(""); + str << medprop->GetPatientName(); + file->InsertEntryString(str.str(),0x0010,0x0010,"PN"); // PN 1 Patient's Name + } + + if (medprop->GetPatientID()) + { + str.str(""); + str << medprop->GetPatientID(); + file->InsertEntryString(str.str(),0x0010,0x0020,"LO"); // LO 1 Patient ID + } + + if (medprop->GetPatientAge()) + { + str.str(""); + str << medprop->GetPatientAge(); + file->InsertEntryString(str.str(),0x0010,0x1010,"AS"); // AS 1 Patient's Age + } + + if (medprop->GetPatientSex()) + { + str.str(""); + str << medprop->GetPatientSex(); + file->InsertEntryString(str.str(),0x0010,0x0040,"CS"); // CS 1 Patient's Sex + } + + if (medprop->GetPatientBirthDate()) + { + str.str(""); + str << medprop->GetPatientBirthDate(); + file->InsertEntryString(str.str(),0x0010,0x0030,"DA"); // DA 1 Patient's Birth Date + } + + if (medprop->GetStudyID()) + { + str.str(""); + str << medprop->GetStudyID(); + file->InsertEntryString(str.str(),0x0020,0x0010,"SH"); // SH 1 Study ID + } + } } #endif /** * Set the data informations in the file */ -void SetImageInformation(gdcm::FileHelper *file, vtkImageData *image) +void SetImageInformation(GDCM_NAME_SPACE::FileHelper *file, vtkImageData *image) { std::ostringstream str; @@ -192,29 +209,29 @@ void SetImageInformation(gdcm::FileHelper *file, vtkImageData *image) str.str(""); str << dim[0]; - file->InsertEntryString(str.str(),0x0028,0x0011); // Columns + file->InsertEntryString(str.str(),0x0028,0x0011,"US"); // Columns str.str(""); str << dim[1]; - file->InsertEntryString(str.str(),0x0028,0x0010); // Rows + file->InsertEntryString(str.str(),0x0028,0x0010,"US"); // Rows if(dim[2]>1) { str.str(""); str << dim[2]; //file->Insert(str.str(),0x0028,0x0012); // Planes - file->InsertEntryString(str.str(),0x0028,0x0008); // Number of Frames + file->InsertEntryString(str.str(),0x0028,0x0008,"IS"); // Number of Frames } // Pixel type str.str(""); str << image->GetScalarSize()*8; - file->InsertEntryString(str.str(),0x0028,0x0100); // Bits Allocated - file->InsertEntryString(str.str(),0x0028,0x0101); // Bits Stored + file->InsertEntryString(str.str(),0x0028,0x0100,"US"); // Bits Allocated + file->InsertEntryString(str.str(),0x0028,0x0101,"US"); // Bits Stored str.str(""); str << image->GetScalarSize()*8-1; - file->InsertEntryString(str.str(),0x0028,0x0102); // High Bit + file->InsertEntryString(str.str(),0x0028,0x0102,"US"); // High Bit // Pixel Repr // FIXME : what do we do when the ScalarType is @@ -231,12 +248,12 @@ void SetImageInformation(gdcm::FileHelper *file, vtkImageData *image) { str << "1"; // Signed } - file->InsertEntryString(str.str(),0x0028,0x0103); // Pixel Representation + file->InsertEntryString(str.str(),0x0028,0x0103,"US"); // Pixel Representation // Samples per pixel str.str(""); str << image->GetNumberOfScalarComponents(); - file->InsertEntryString(str.str(),0x0028,0x0002); // Samples per Pixel + file->InsertEntryString(str.str(),0x0028,0x0002,"US"); // Samples per Pixel /// \todo : Spacing Between Slices is meaningfull ONLY for CT an MR modality /// We should perform some checkings before forcing the Entry creation @@ -250,10 +267,10 @@ void SetImageInformation(gdcm::FileHelper *file, vtkImageData *image) // thus forcing to fixed point value str.setf( std::ios::fixed ); str << sp[1] << "\\" << sp[0]; - file->InsertEntryString(str.str(),0x0028,0x0030); // Pixel Spacing + file->InsertEntryString(str.str(),0x0028,0x0030,"DS"); // Pixel Spacing str.str(""); str << sp[2]; - file->InsertEntryString(str.str(),0x0018,0x0088); // Spacing Between Slices + file->InsertEntryString(str.str(),0x0018,0x0088,"DS"); // Spacing Between Slices // Origin vtkFloatingPointType *org = image->GetOrigin(); @@ -263,7 +280,7 @@ void SetImageInformation(gdcm::FileHelper *file, vtkImageData *image) str.str(""); str << org[0] << "\\" << org[1] << "\\" << org[2]; - file->InsertEntryString(str.str(),0x0020,0x0032); // Image Position Patient + file->InsertEntryString(str.str(),0x0020,0x0032,"DS"); // Image Position Patient str.unsetf( std::ios::fixed ); //done with floating point values // Window / Level @@ -271,10 +288,10 @@ void SetImageInformation(gdcm::FileHelper *file, vtkImageData *image) str.str(""); str << rng[1]-rng[0]; - file->InsertEntryString(str.str(),0x0028,0x1051); // Window Width + file->InsertEntryString(str.str(),0x0028,0x1051,"DS"); // Window Width str.str(""); str << (rng[1]+rng[0])/2.0; - file->InsertEntryString(str.str(),0x0028,0x1050); // Window Center + file->InsertEntryString(str.str(),0x0028,0x1050,"DS"); // Window Center // Pixels unsigned char *data; @@ -386,18 +403,19 @@ void vtkGdcmWriter::RecursiveWrite(int axis, vtkImageData *cache, void vtkGdcmWriter::WriteDcmFile(char *fileName, vtkImageData *image) { - gdcm::FileHelper *dcmFile; + GDCM_NAME_SPACE::FileHelper *dcmFile; if ( GdcmFile != 0) - dcmFile = gdcm::FileHelper::New(GdcmFile); + dcmFile = GDCM_NAME_SPACE::FileHelper::New(GdcmFile); else - dcmFile = gdcm::FileHelper::New(); + dcmFile = GDCM_NAME_SPACE::FileHelper::New(); // From here, the write of the file begins - // Set the medical informations: +#if (VTK_MAJOR_VERSION >= 5) SetMedicalImageInformation(dcmFile, this->MedicalImageProperties); - +#endif + // Set the image informations SetImageInformation(dcmFile, image); @@ -420,7 +438,7 @@ void vtkGdcmWriter::WriteDcmFile(char *fileName, vtkImageData *image) dcmFile->SetWriteTypeToDcmExplVR(); } - dcmFile->SetContentType((gdcm::ImageContentType)ContentType); + dcmFile->SetContentType((GDCM_NAME_SPACE::ImageContentType)ContentType); if(!dcmFile->Write(fileName)) {