From fd5c14391627c6e42283ced90561271af2a161a2 Mon Sep 17 00:00:00 2001 From: jpr Date: Tue, 29 Mar 2011 07:35:55 +0000 Subject: [PATCH] upgrades for 4DSplitter --- CMakeLists.txt | 9 +++ Example/CMakeLists.txt | 2 +- Example/MergeDICOMRaw.cxx | 6 +- Example/PcpdenseToDicom.cxx | 15 ++--- Example/SplitIntoXCoherentDirectories.cxx | 11 ++-- ...IntoXCoherentDirectoriesIgnoreSerieUID.cxx | 6 +- Example/ToMRIregister.cxx | 6 +- src/gdcmDataEntry.cxx | 10 +-- src/gdcmDataEntry.h | 6 +- src/gdcmDocument.cxx | 5 +- src/gdcmSerieHelper.cxx | 64 +++++++++++++++++-- src/gdcmSerieHelper.h | 16 ++++- vtk/CMakeLists.txt | 8 +-- vtk/vtkGdcmReader.cxx | 8 +-- vtk/vtkGdcmReader.h | 11 ++-- vtk/vtkgdcmViewer.cxx | 5 +- vtk/vtkgdcmViewer2.cxx | 15 ++--- 17 files changed, 136 insertions(+), 67 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d385c98..13007304 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,12 @@ +# --------------------------------- +# +# Unless you are an experimented cmake user, +# have a look at : +# http://www.creatis.insa-lyon.fr/site/fr/CreatoolsGettingStarted-v2.0.X +# before starting. +# +# --------------------------------- + PROJECT(GDCM) CMAKE_MINIMUM_REQUIRED(VERSION 2.0) # okay in fact you need at least cmake 2.0.4 to get swig working properly diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt index 3b7c5ca8..3962d224 100644 --- a/Example/CMakeLists.txt +++ b/Example/CMakeLists.txt @@ -5,7 +5,7 @@ INCLUDE_DIRECTORIES( ${GDCM_BINARY_DIR}/src) SET(EXAMPLE_SOURCES #names starting with 'ex' are examples - #------------------------------------- + #------------------------------------- #SingleFrames2Multiframe #Txt2Mat #exDicomRTStructSetFile diff --git a/Example/MergeDICOMRaw.cxx b/Example/MergeDICOMRaw.cxx index b44e490e..4fb43c71 100644 --- a/Example/MergeDICOMRaw.cxx +++ b/Example/MergeDICOMRaw.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: MergeDICOMRaw.cxx,v $ Language: C++ - Date: $Date: 2010/09/01 14:41:48 $ - Version: $Revision: 1.3 $ + Date: $Date: 2011/03/29 07:35:57 $ + Version: $Revision: 1.4 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) // TODO // for UltrasoundMultiframeImageStorage we may need also: - // (0028,0009) AT (0018,1063) # 4, 1 FrameIncrementPointer + // (0028,0009) AT (0018,1063) # 4, 1 FrameIncrementPointer // and // Pixel Aspect Ratio diff --git a/Example/PcpdenseToDicom.cxx b/Example/PcpdenseToDicom.cxx index 161d9452..a31c050b 100644 --- a/Example/PcpdenseToDicom.cxx +++ b/Example/PcpdenseToDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: PcpdenseToDicom.cxx,v $ Language: C++ - Date: $Date: 2010/09/01 14:41:48 $ - Version: $Revision: 1.6 $ + Date: $Date: 2011/03/29 07:35:57 $ + 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 @@ -154,9 +154,9 @@ int main(int argc, char *argv[]) // === Ecc === strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); - + serieDescr = "Ecc"; - + if (!multiframe) { for (int i=0; iSetLoadMode(GDCM_NAME_SPACE::LD_ALL); // Load everything for each File s->SetDirectory(dirName, true); // true : recursive exploration - - GDCM_NAME_SPACE::File *f; GDCM_NAME_SPACE::DirList dirlist(dirName, true); // recursive exploration GDCM_NAME_SPACE::DirListType fileNames = dirlist.GetFilenames(); - GDCM_NAME_SPACE::FileList *l = new GDCM_NAME_SPACE::FileList; + + GDCM_NAME_SPACE::File *f; // Loop on all the gdcm-readable files for (GDCM_NAME_SPACE::DirListType::iterator it = fileNames.begin(); it != fileNames.end(); diff --git a/Example/SplitIntoXCoherentDirectoriesIgnoreSerieUID.cxx b/Example/SplitIntoXCoherentDirectoriesIgnoreSerieUID.cxx index bec07d82..992b53c0 100755 --- a/Example/SplitIntoXCoherentDirectoriesIgnoreSerieUID.cxx +++ b/Example/SplitIntoXCoherentDirectoriesIgnoreSerieUID.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: SplitIntoXCoherentDirectoriesIgnoreSerieUID.cxx,v $ Language: C++ - Date: $Date: 2009/05/28 15:44:34 $ - Version: $Revision: 1.2 $ + Date: $Date: 2011/03/29 07:35:58 $ + Version: $Revision: 1.3 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) " tag : group-elem (in hexa, no space) ", " the user wants to split on ", " sort : user wants FileHelper to sort the images ", - " Warning : will probabely crah if sort has no meaning ", + " Warning : will probabely crash if sort has no meaning ", " (not only look at image names) ", " studyUID : *aware* user wants to add the serie ", " to an already existing study ", diff --git a/Example/ToMRIregister.cxx b/Example/ToMRIregister.cxx index ae426b59..7ebc8f00 100755 --- a/Example/ToMRIregister.cxx +++ b/Example/ToMRIregister.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: ToMRIregister.cxx,v $ Language: C++ - Date: $Date: 2007/10/24 08:03:44 $ - Version: $Revision: 1.5 $ + Date: $Date: 2011/03/29 07:35:58 $ + Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) "\n ToMriregister :\n ", " - Converts the Siemens Sonata MRI '*tfl2d1' ", " to be processable by MriRegister software ", - " - May be used as a template for GDCM_NAME_SPACE::SerieHelper use. ", + " - May be used as a template for GDCM_NAME_SPACE::SerieHelper use. ", " ", "usage: ToMriRegister dirin=inputDirectoryName ", " dirout=outputDirectoryName ", diff --git a/src/gdcmDataEntry.cxx b/src/gdcmDataEntry.cxx index 07603e1b..78f186c5 100644 --- a/src/gdcmDataEntry.cxx +++ b/src/gdcmDataEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDataEntry.cxx,v $ Language: C++ - Date: $Date: 2010/07/09 09:20:20 $ - Version: $Revision: 1.56 $ + Date: $Date: 2011/03/29 07:36:00 $ + Version: $Revision: 1.57 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -168,7 +168,7 @@ bool DataEntry::IsNumerical() { /// \todo rewrite the whole method, in order *not to use* std::string ! std::vector tokens; - + Util::Tokenize ( GetString().c_str(), tokens, "\\" ); int nbValues= tokens.size(); @@ -181,14 +181,14 @@ bool DataEntry::IsNumerical() else for (loop=0; looptellg()) " << (long)(Fp->tellg()) // in Debug mode << std::hex << " 0x(" <<(long)(Fp->tellg()) << ")" << std::endl; - // if ( !delim_mode && ((long)(Fp->tellg())-offset) >= l_max) // Once per DocEntry if ( !delim_mode ) // 'and then' doesn't exist in C++ :-( if ( ((long)(Fp->tellg())-offset) >= l_max) // Once per DocEntry, when no delim mode diff --git a/src/gdcmSerieHelper.cxx b/src/gdcmSerieHelper.cxx index 4e215e7f..56aaaabc 100644 --- a/src/gdcmSerieHelper.cxx +++ b/src/gdcmSerieHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSerieHelper.cxx,v $ Language: C++ - Date: $Date: 2010/04/09 15:38:18 $ - Version: $Revision: 1.70 $ + Date: $Date: 2011/03/29 07:36:00 $ + Version: $Revision: 1.71 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -13,7 +13,7 @@ This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. - + =========================================================================*/ #include "gdcmSerieHelper.h" @@ -581,14 +581,14 @@ XCoherentFileSetmap SerieHelper::SplitOnPosition(FileList *fileSet) * \return std::map of 'Xcoherent' File sets */ -XCoherentFileSetmap SerieHelper::SplitOnTagValue(FileList *fileSet, +XCoherentFileSetmap SerieHelper::SplitOnTagValue(FileList *fileSet, uint16_t group, uint16_t element) { XCoherentFileSetmap CoherentFileSet; int nb = fileSet->size(); if (nb == 0 ) { - gdcmWarningMacro("Empty FileList passed to SplitOnPosition"); + gdcmWarningMacro("Empty FileList passed to SplitOnTagValue"); return CoherentFileSet; } @@ -605,6 +605,60 @@ XCoherentFileSetmap SerieHelper::SplitOnTagValue(FileList *fileSet, // 0020,0030 : Image Position (RET) strTagValue = (*it)->GetEntryString(group,element); + + if ( CoherentFileSet.count(strTagValue) == 0 ) + { + gdcmDebugMacro(" :[" << strTagValue << "]"); + // create a File set in 'position' position + CoherentFileSet[strTagValue] = new FileList; + } + // Current Tag value and DICOM header match; add the file: + CoherentFileSet[strTagValue]->push_back( (*it) ); + } + return CoherentFileSet; +} + + +/** + * \brief Splits a 'Single SerieUID' File set Coherent according to the + * value of a given Tag + * @param fileSet File Set to be splitted + * @param group group number of the target Element + * @param element element number of the target Element + * \return std::map of 'Xcoherent' File sets + */ + +XCoherentFileSetmap SerieHelper::SplitOnTagValueConvertToFloat(FileList *fileSet, + uint16_t group, uint16_t element) +{ + XCoherentFileSetmap CoherentFileSet; + + int nb = fileSet->size(); + if (nb == 0 ) { + gdcmWarningMacro("Empty FileList passed to SplitOnTagValue"); + return CoherentFileSet; + } + + std::string strTagValue; // read on disc + + double dTagValue; + int iTagValue; + char cTagValue[11]; + std::string sTagValue; + + FileList::const_iterator it = fileSet->begin(); + //it ++; + for ( ; + it != fileSet->end(); + ++it) + { + /// \TODO : find a trick to create a string whose value follows lexicographical order + + strTagValue = (*it)->GetEntryString(group,element); + dTagValue = atof( strTagValue.c_str()); + iTagValue = dTagValue; + sprintf(cTagValue, "%010d", iTagValue); + strTagValue = cTagValue; if ( CoherentFileSet.count(strTagValue) == 0 ) { diff --git a/src/gdcmSerieHelper.h b/src/gdcmSerieHelper.h index c7405f4e..2f20fe4f 100644 --- a/src/gdcmSerieHelper.h +++ b/src/gdcmSerieHelper.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSerieHelper.h,v $ Language: C++ - Date: $Date: 2010/04/09 15:38:18 $ - Version: $Revision: 1.46 $ + Date: $Date: 2011/03/29 07:36:00 $ + Version: $Revision: 1.47 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -91,6 +91,11 @@ public: void OrderFileList(FileList *fileSet); void Clear() { ClearAll(); } + bool UserOrdering(FileList *fileSet); + bool ImagePositionPatientOrdering(FileList *fileSet); + bool ImageNumberOrdering(FileList *fileSet); + bool FileNameOrdering(FileList *fileSet); + /// \brief Gets the FIRST Single SerieUID Fileset. /// Deprecated; kept not to break the API /// \note Caller must call OrderFileList first @@ -187,16 +192,21 @@ public: XCoherentFileSetmap SplitOnPosition(FileList *fileSet); XCoherentFileSetmap SplitOnTagValue(FileList *fileSet, uint16_t group, uint16_t element); + XCoherentFileSetmap SplitOnTagValueConvertToFloat(FileList *fileSet, + uint16_t group, uint16_t element); protected : SerieHelper(); private: void ClearAll(); + + /* + //move them to public (usefull for aware user!) bool UserOrdering(FileList *fileSet); bool ImagePositionPatientOrdering(FileList *fileSet); bool ImageNumberOrdering(FileList *fileSet); bool FileNameOrdering(FileList *fileSet); - + */ static bool ImageNumberLessThan(File *file1, File *file2); static bool ImageNumberGreaterThan(File *file1, File *file2); static bool FileNameLessThan(File *file1, File *file2); diff --git a/vtk/CMakeLists.txt b/vtk/CMakeLists.txt index fd422a85..9d6b4732 100644 --- a/vtk/CMakeLists.txt +++ b/vtk/CMakeLists.txt @@ -29,6 +29,7 @@ IF("${VTK_MAJOR_VERSION}" GREATER 4) vtkGdcmWriter.cxx vtkImageColorViewer.cxx vtkImageMapToWindowLevelColors2.cxx + # vtkGdcm4DSplitter.cxx ) ELSE("${VTK_MAJOR_VERSION}" GREATER 4) SET(VTKGDCM_LIB_SRCS @@ -67,11 +68,11 @@ TARGET_LINK_LIBRARIES(vtkgdcmdemo SET(Bmp2Dcm_SOURCES Bmp2Dcm.cxx ) + ADD_EXECUTABLE(Bmp2Dcm ${Bmp2Dcm_SOURCES}) TARGET_LINK_LIBRARIES(Bmp2Dcm vtkgdcm vtkImaging - ) #----------------------------------------------------------------------------- @@ -136,7 +137,6 @@ TARGET_LINK_LIBRARIES(vtkgdcmSerieViewer2 vtkRendering ) - #----------------------------------------------------------------------------- SET(vtkWriteDicom_SOURCES vtkWriteDicom.cxx @@ -170,10 +170,10 @@ IF(NOT GDCM_INSTALL_NO_LIBRARIES) INSTALL_TARGETS(${GDCM_INSTALL_LIB_DIR} vtkgdcm) INSTALL_TARGETS(${GDCM_INSTALL_BIN_DIR} vtkgdcmViewer) INSTALL_TARGETS(${GDCM_INSTALL_BIN_DIR} vtkgdcmViewer) - + # INSTALL_TARGETS(${GDCM_INSTALL_BIN_DIR} vtkJPEGViewer) # INSTALL_TARGETS(${GDCM_INSTALL_BIN_DIR} vtkJPEGViewer2) - + INSTALL_TARGETS(${GDCM_INSTALL_BIN_DIR} vtkgdcmSerieViewer) ENDIF(NOT GDCM_INSTALL_NO_LIBRARIES) diff --git a/vtk/vtkGdcmReader.cxx b/vtk/vtkGdcmReader.cxx index 913f9a74..449eb536 100644 --- a/vtk/vtkGdcmReader.cxx +++ b/vtk/vtkGdcmReader.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: vtkGdcmReader.cxx,v $ Language: C++ - Date: $Date: 2010/09/01 13:33:36 $ - Version: $Revision: 1.98 $ + Date: $Date: 2011/03/29 07:36:02 $ + Version: $Revision: 1.99 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -92,7 +92,7 @@ #include #include -vtkCxxRevisionMacro(vtkGdcmReader, "$Revision: 1.98 $") +vtkCxxRevisionMacro(vtkGdcmReader, "$Revision: 1.99 $") vtkStandardNewMacro(vtkGdcmReader) //----------------------------------------------------------------------------- @@ -861,7 +861,7 @@ void vtkGdcmReader::LoadImageInMemory( src = (unsigned char*)fileH->GetImageData(); //else // very strange, but it doesn't work (I have to memcpy the pixels ?!?) - // dest = (unsigned char*)fileH->GetImageData(); + // dest = (unsigned char*)fileH->GetImageData(); } if (this->GetFlipY()) { diff --git a/vtk/vtkGdcmReader.h b/vtk/vtkGdcmReader.h index 183fbf01..dc29361f 100644 --- a/vtk/vtkGdcmReader.h +++ b/vtk/vtkGdcmReader.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: vtkGdcmReader.h,v $ Language: C++ - Date: $Date: 2010/09/01 13:33:36 $ - Version: $Revision: 1.38 $ + Date: $Date: 2011/03/29 07:36:02 $ + Version: $Revision: 1.39 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -73,17 +73,17 @@ public: vtkSetMacro(KeepOverlays, bool); vtkGetMacro(KeepOverlays, bool); vtkBooleanMacro(KeepOverlays, bool); - + // Implementation note: when FileLowerLeft (gdcm2) is set to on the image is not flipped // upside down as VTK would expect, use this option only if you know what you are doing. // vtkSetMacro(FileLowerLeft, bool); // vtkGetMacro(FileLowerLeft, bool); // vtkBooleanMacro(FileLowerLeft, bool); - + vtkSetMacro(FlipY, bool); vtkGetMacro(FlipY, bool); vtkBooleanMacro(FlipY, bool); - + vtkGetObjectMacro(LookupTable, vtkLookupTable); // FIXME : HOW to doxygen a VTK macro? @@ -199,6 +199,7 @@ private: // bool FileLowerLeft; bool FlipY; + /// Pointer to a user suplied function to allow modification of pixel order VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction; diff --git a/vtk/vtkgdcmViewer.cxx b/vtk/vtkgdcmViewer.cxx index 95da0fa0..6d2751a6 100644 --- a/vtk/vtkgdcmViewer.cxx +++ b/vtk/vtkgdcmViewer.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: vtkgdcmViewer.cxx,v $ Language: C++ - Date: $Date: 2009/11/03 14:05:23 $ - Version: $Revision: 1.32 $ + Date: $Date: 2011/03/29 07:36:02 $ + Version: $Revision: 1.33 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -156,7 +156,6 @@ reader->GetOutput()->GetScalarComponentAsFloat(0,127,0,0) << iren->Start(); //if you wish you can export dicom to a vtk file - vtkStructuredPointsWriter *writer = vtkStructuredPointsWriter::New(); writer->SetInput( reader->GetOutput()); writer->SetFileName( "foo.vtk" ); diff --git a/vtk/vtkgdcmViewer2.cxx b/vtk/vtkgdcmViewer2.cxx index caf0b836..f991efde 100644 --- a/vtk/vtkgdcmViewer2.cxx +++ b/vtk/vtkgdcmViewer2.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: vtkgdcmViewer2.cxx,v $ Language: C++ - Date: $Date: 2010/09/01 13:33:36 $ - Version: $Revision: 1.18 $ + Date: $Date: 2011/03/29 07:36:02 $ + Version: $Revision: 1.19 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -120,7 +120,7 @@ int main(int argc, char *argv[]) { if( argc < 2 ) return 0; - + bool metaWrite = false; vtkGdcmReader *reader = vtkGdcmReader::New(); @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) argc--; // Is it allowed?!? reader->SetKeepOverlays(true); } - + // not a very clever way to pass several params // but it's just for checking if (strcmp (argv[argc-1], "n") == 0) @@ -146,7 +146,7 @@ int main(int argc, char *argv[]) argc--; // Is it allowed?!? metaWrite = true; } - + if( argc == 2 ) reader->SetFileName( argv[1] ); else @@ -174,8 +174,7 @@ int main(int argc, char *argv[]) //w->Delete(); std::cout << "end write .mhd" << std::endl; //} - - + vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); #if VTK_MAJOR_VERSION >= 5 vtkImageColorViewer *viewer = vtkImageColorViewer::New(); @@ -229,7 +228,7 @@ int main(int argc, char *argv[]) writer->SetFileName( "foo.vtk" ); writer->SetFileTypeToBinary(); //writer->Write(); - + //if you wish you can export dicom to a .mhd file /* if (metaWrite) { -- 2.45.0