From d735b22c6656c1b5d05d560ff9773a016a8514f9 Mon Sep 17 00:00:00 2001 From: jpr Date: Tue, 2 May 2006 10:09:43 +0000 Subject: [PATCH] Propagate Mathieu's modif from 1.2 to CVS version. ENH: A few stuff: Do not call ResetCameraClippingRange in VTK5 and above (fixed) Update to new API for the ZSlicer stuff in vtkImageViewer2 Add a vtkMedicalImageProperties to the writer to pass in medical information from VTK context (pretty neat...) Minor style, avoid including too many header files URL : http://cvs.creatis.insa-lyon.fr/viewcvs/viewcvs.cgi/gdcm/?view=query&branch=&who=malaterre&date=explicit&mindate=2006-04-20%2021:20&maxdate=2006-04-20%2021:22 --- vtk/vtkGdcmWriter.cxx | 67 ++++++++++++++++++++++++++++++++++++++---- vtk/vtkGdcmWriter.h | 22 +++++++++++--- vtk/vtkgdcmViewer2.cxx | 13 ++++++-- 3 files changed, 91 insertions(+), 11 deletions(-) diff --git a/vtk/vtkGdcmWriter.cxx b/vtk/vtkGdcmWriter.cxx index 1ba93f89..9a17fa60 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/03/20 14:32:20 $ - Version: $Revision: 1.28 $ + Date: $Date: 2006/05/02 10:09:43 $ + Version: $Revision: 1.29 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -26,19 +26,26 @@ #include #include #include - +#if (VTK_MAJOR_VERSION >= 5) +#include +#endif #ifndef vtkFloatingPointType #define vtkFloatingPointType float #endif -vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.28 $") +vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.29 $") vtkStandardNewMacro(vtkGdcmWriter) +vtkCxxSetObjectMacro(vtkGdcmWriter,LookupTable,vtkLookupTable); +#if (VTK_MAJOR_VERSION >= 5) +vtkCxxSetObjectMacro(vtkGdcmWriter,MedicalImageProperties,vtkMedicalImageProperties); +#endif //----------------------------------------------------------------------------- // Constructor / Destructor vtkGdcmWriter::vtkGdcmWriter() { this->LookupTable = NULL; + this->MedicalImageProperties = NULL; this->FileDimensionality = 3; this->WriteType = VTK_GDCM_WRITE_TYPE_EXPLICIT_VR; this->GdcmFile = 0; @@ -47,6 +54,8 @@ vtkGdcmWriter::vtkGdcmWriter() vtkGdcmWriter::~vtkGdcmWriter() { + this->SetMedicalImageProperties(NULL); + this->SetLookupTable(NULL); } //----------------------------------------------------------------------------- @@ -124,6 +133,50 @@ 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) +{ + // For now only do: + // PatientName, PatientID, PatientAge, PatientSex, PatientBirthDate, StudyID + 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 *) +{ +} +#endif + /** * Set the data informations in the file */ @@ -340,7 +393,11 @@ void vtkGdcmWriter::WriteDcmFile(char *fileName, vtkImageData *image) dcmFile = gdcm::FileHelper::New(); // From here, the write of the file begins - + + + // Set the medical informations: + SetMedicalImageInformation(dcmFile, this->MedicalImageProperties); + // Set the image informations SetImageInformation(dcmFile, image); diff --git a/vtk/vtkGdcmWriter.h b/vtk/vtkGdcmWriter.h index 548f8195..305aede7 100644 --- a/vtk/vtkGdcmWriter.h +++ b/vtk/vtkGdcmWriter.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: vtkGdcmWriter.h,v $ Language: C++ - Date: $Date: 2006/03/17 14:46:18 $ - Version: $Revision: 1.7 $ + Date: $Date: 2006/05/02 10:09:43 $ + 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 @@ -39,6 +39,9 @@ #define VTK_GDCM_WRITE_TYPE_UNMODIFIED_PIXELS_IMAGE 4 //----------------------------------------------------------------------------- +class vtkLookupTable; +class vtkMedicalImageProperties; + class VTK_EXPORT vtkGdcmWriter : public vtkImageWriter { public: @@ -47,7 +50,8 @@ public: void PrintSelf(ostream &os, vtkIndent indent); - vtkSetObjectMacro(LookupTable, vtkLookupTable); + //vtkSetObjectMacro(LookupTable, vtkLookupTable); + virtual void SetLookupTable(vtkLookupTable*); vtkGetObjectMacro(LookupTable, vtkLookupTable); void SetWriteTypeToDcmImplVR(){SetWriteType(VTK_GDCM_WRITE_TYPE_EXPLICIT_VR);}; @@ -64,6 +68,7 @@ public: vtkGetMacro(WriteType, int); const char *GetWriteTypeAsString(); + //BTX vtkSetMacro(GdcmFile, gdcm::File *); vtkGetMacro(GdcmFile, gdcm::File *); @@ -72,7 +77,15 @@ public: vtkSetMacro(ContentType, int); vtkGetMacro(ContentType, int); - + // Description: + // To pass in some extra information from a VTK context a user can pass a + // vtkMedicalImageProperties object +#if (VTK_MAJOR_VERSION >= 5) + void SetMedicalImageProperties(vtkMedicalImageProperties*); +#else + void SetMedicalImageProperties(vtkMedicalImageProperties*) {} +#endif + protected: vtkGdcmWriter(); ~vtkGdcmWriter(); @@ -85,6 +98,7 @@ protected: private: // Variables vtkLookupTable *LookupTable; + vtkMedicalImageProperties *MedicalImageProperties; int WriteType; //BTX gdcm::File *GdcmFile; diff --git a/vtk/vtkgdcmViewer2.cxx b/vtk/vtkgdcmViewer2.cxx index ccac0d7c..98989111 100644 --- a/vtk/vtkgdcmViewer2.cxx +++ b/vtk/vtkgdcmViewer2.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: vtkgdcmViewer2.cxx,v $ Language: C++ - Date: $Date: 2006/03/17 14:46:18 $ - Version: $Revision: 1.6 $ + Date: $Date: 2006/05/02 10:09:43 $ + Version: $Revision: 1.7 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -68,10 +68,19 @@ public: { if ( event == vtkCommand::CharEvent ) { + #if (VTK_MAJOR_VERSION >= 5) + int max = ImageViewer->GetSliceMax(); + int slice = (ImageViewer->GetSlice() + 1 ) % ++max; + ImageViewer->SetSlice( slice ); +#else int max = ImageViewer->GetWholeZMax(); int slice = (ImageViewer->GetZSlice() + 1 ) % ++max; ImageViewer->SetZSlice( slice ); +#endif +#if !( (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION >= 5 ) ) + // This used to be a bug in version VTK 4.4 and earlier ImageViewer->GetRenderer()->ResetCameraClippingRange(); +#endif ImageViewer->Render(); } } -- 2.45.1