X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vtk%2FvtkGdcmWriter.cxx;h=4d0168780397b00aba09bb2ca9e0d774ef05adb8;hb=8f38e5061bcb7bebaea78024d8d743ab973e2dab;hp=720b1fc67d101caaa8b083fc3ac33e9c6e7ada45;hpb=a462ce9f1af0894cd930ab04f2e65cd80dfa7084;p=gdcm.git diff --git a/vtk/vtkGdcmWriter.cxx b/vtk/vtkGdcmWriter.cxx index 720b1fc6..4d016878 100644 --- a/vtk/vtkGdcmWriter.cxx +++ b/vtk/vtkGdcmWriter.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: vtkGdcmWriter.cxx,v $ Language: C++ - Date: $Date: 2005/01/08 15:04:00 $ - Version: $Revision: 1.9 $ + Date: $Date: 2005/01/28 10:07:35 $ + Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -16,9 +16,10 @@ =========================================================================*/ -#include "gdcmHeader.h" #include "gdcmFile.h" +#include "gdcmFileHelper.h" #include "gdcmDebug.h" +#include "gdcmUtil.h" #include "vtkGdcmWriter.h" #include @@ -26,7 +27,7 @@ #include #include -vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.9 $"); +vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.16 $"); vtkStandardNewMacro(vtkGdcmWriter); //----------------------------------------------------------------------------- @@ -36,6 +37,11 @@ vtkGdcmWriter::vtkGdcmWriter() this->LookupTable = NULL; this->FileDimensionality = 3; this->WriteType = VTK_GDCM_WRITE_TYPE_EXPLICIT_VR; + + UIDPrefix = ""; + StudyInstanceUID = ""; + SeriesInstanceUID = ""; + FrameOfReferenceInstanceUID = ""; } vtkGdcmWriter::~vtkGdcmWriter() @@ -70,6 +76,31 @@ const char *vtkGdcmWriter::GetWriteTypeAsString() } } +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 /** @@ -120,7 +151,7 @@ size_t ReverseData(vtkImageData *image,unsigned char **data) /** * Set the datas informations in the file */ -void SetImageInformation(gdcm::File *file,vtkImageData *image) +void SetImageInformation(gdcm::FileHelper *file,vtkImageData *image) { std::ostringstream str; @@ -132,29 +163,29 @@ void SetImageInformation(gdcm::File *file,vtkImageData *image) str.str(""); str << dim[0]; - file->ReplaceOrCreate(str.str(),0x0028,0x0011); // Columns + file->InsertValEntry(str.str(),0x0028,0x0011); // Columns str.str(""); str << dim[1]; - file->ReplaceOrCreate(str.str(),0x0028,0x0010); // Rows + file->InsertValEntry(str.str(),0x0028,0x0010); // Rows if(dim[2]>1) { str.str(""); str << dim[2]; - //file->ReplaceOrCreate(str.str(),0x0028,0x0012); // Planes - file->ReplaceOrCreate(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->ReplaceOrCreate(str.str(),0x0028,0x0100); // Bits Allocated - file->ReplaceOrCreate(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->ReplaceOrCreate(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 @@ -171,39 +202,39 @@ void SetImageInformation(gdcm::File *file,vtkImageData *image) { str << "1"; // Signed } - file->ReplaceOrCreate(str.str(),0x0028,0x0103); // Pixel Representation + file->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation // Samples per pixel str.str(""); str << image->GetNumberOfScalarComponents(); - file->ReplaceOrCreate(str.str(),0x0028,0x0002); // Samples per Pixel + file->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel // Spacing double *sp = image->GetSpacing(); str.str(""); str << sp[0] << "\\" << sp[1]; - file->ReplaceOrCreate(str.str(),0x0028,0x0030); // Pixel Spacing + file->InsertValEntry(str.str(),0x0028,0x0030); // Pixel Spacing str.str(""); str << sp[2]; - file->ReplaceOrCreate(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->ReplaceOrCreate(str.str(),0x0020,0x0032); // Image Position Patient + file->InsertValEntry(str.str(),0x0020,0x0032); // Image Position Patient // Window / Level double *rng=image->GetScalarRange(); str.str(""); str << rng[1]-rng[0]; - file->ReplaceOrCreate(str.str(),0x0028,0x1051); // Window Width + file->InsertValEntry(str.str(),0x0028,0x1051); // Window Width str.str(""); str << (rng[1]+rng[0])/2.0; - file->ReplaceOrCreate(str.str(),0x0028,0x1050); // Window Center + file->InsertValEntry(str.str(),0x0028,0x1050); // Window Center // Pixels unsigned char *data; @@ -312,7 +343,22 @@ void vtkGdcmWriter::RecursiveWrite(int axis, vtkImageData *cache, 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); @@ -340,7 +386,6 @@ void vtkGdcmWriter::WriteDcmFile(char *fileName,vtkImageData *image) { vtkErrorMacro( << "File " << this->FileName << "couldn't be written by " << " the gdcm library"); - std::cerr << "not written \n"; } // Clean up