From: regrain Date: Tue, 25 Jan 2005 15:44:21 +0000 (+0000) Subject: * src/ : rename some methods on Entry (SetXxx, InsertXxx) to have a better X-Git-Tag: Version1.0.bp~192 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=ce8913daafe02955368fd2f07e777e86824467cc;p=gdcm.git * src/ : rename some methods on Entry (SetXxx, InsertXxx) to have a better use with python. Some methods ard moved from Document to ElementSet or DocEntrySet. The equivalent methods to ElementSet have been added to SQItem and are virtual in DocEntrySet. Methods that may have the same code in SQItem and ElementSet is directly placed in DocEntrySet -- BeNours --- diff --git a/ChangeLog b/ChangeLog index c094101d..0c86fcfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2005-01-25 Benoit Regrain - * Test/VTKTest*.cxx : remove the show variable in each test method because + * src/ : rename some methods on Entry (SetXxx, InsertXxx) to have a better + use with python. Some methods ard moved from Document to ElementSet or + DocEntrySet. The equivalent methods to ElementSet have been added to + SQItem and are virtual in DocEntrySet. Methods that may have the same code + in SQItem and ElementSet is directly placed in DocEntrySet + +2005-01-25 Benoit Regrain + * Test/VTKTest*.cxx : remove the show variable in each test method because it's useless (the viewer variable replace this variable) 2005-01-25 Benoit Regrain diff --git a/Example/BuildUpDicomDir.cxx b/Example/BuildUpDicomDir.cxx index a56fa9f8..6de2f202 100644 --- a/Example/BuildUpDicomDir.cxx +++ b/Example/BuildUpDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: BuildUpDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:10:49 $ - Version: $Revision: 1.12 $ + Date: $Date: 2005/01/25 15:44:22 $ + Version: $Revision: 1.13 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -50,25 +50,25 @@ int main(int argc, char* argv[]) ((gdcm::Document *)dcmdir)->Print(); gdcm::DicomDirPatient *p1=dcmdir->NewPatient(); - p1->SetEntryValue("patientONE",0x0010, 0x0010); + p1->SetValEntry("patientONE",0x0010, 0x0010); gdcm::DicomDirPatient *p2=dcmdir->NewPatient(); - p2->SetEntryValue("patientTWO",0x0010, 0x0010); + p2->SetValEntry("patientTWO",0x0010, 0x0010); gdcm::DicomDirStudy *s21=p2->NewStudy(); - s21->SetEntryValue("StudyDescrTwo.One",0x0008, 0x1030); + s21->SetValEntry("StudyDescrTwo.One",0x0008, 0x1030); gdcm::DicomDirSerie *s211=s21->NewSerie(); gdcm::DicomDirImage *s2111=s211->NewImage(); (void)s2111; //not used gdcm::DicomDirStudy *s11=p1->NewStudy(); - s11->SetEntryValue("StudyDescrOne.One",0x0008, 0x1030); + s11->SetValEntry("StudyDescrOne.One",0x0008, 0x1030); // Name of the physician reading study // Header Entry to be created - s11->SetEntryValue("Dr Mabuse",0x0008, 0x1060); + s11->SetValEntry("Dr Mabuse",0x0008, 0x1060); gdcm::DicomDirPatient *p3 = dcmdir->NewPatient(); - p3->SetEntryValue("patientTHREE",0x0010, 0x0010); + p3->SetValEntry("patientTHREE",0x0010, 0x0010); std::cout << "\n------- BuildUpDicomDir: Test Print of Patient ONE -----\n"; p1->Print(); diff --git a/Example/FindTags.cxx b/Example/FindTags.cxx index 705a8810..38d4b2e4 100644 --- a/Example/FindTags.cxx +++ b/Example/FindTags.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: FindTags.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:10:49 $ - Version: $Revision: 1.11 $ + Date: $Date: 2005/01/25 15:44:22 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -47,14 +47,14 @@ int main(int argc, char* argv[]) int dataSize = f1->GetImageDataSize(); std::cout << "---> pourFindTaggs : dataSize " << dataSize << std::endl; - f1->SetEntryValue(RecCode ,0x0008,0x0010); - f1->SetEntryValue(ManufacturerName ,0x0008,0x0070); + f1->SetValEntry(RecCode ,0x0008,0x0010); + f1->SetValEntry(ManufacturerName ,0x0008,0x0070); // ImagePositionPatient ImagePositionPatient = f1->GetFile()->GetEntryValue(0x0020,0x0032); // Image Position (RET) - f1->SetEntryValue(ImagePositionPatient, 0x0020,0x0030); + f1->SetValEntry(ImagePositionPatient, 0x0020,0x0030); sscanf(ImagePositionPatient.c_str(), "%f%c%f%c%f", &x,&c,&y,&c,&z); @@ -70,7 +70,7 @@ int main(int argc, char* argv[]) // Location std::string zizi = gdcm::Util::Format("%f",l); Location = gdcm::Util::DicomString(zizi.c_str()); - f1->SetEntryValue(Location, 0x0020,0x0050); + f1->SetValEntry(Location, 0x0020,0x0050); // sinon, la longueur du champ est erronée (?!?) // Probable sac de noeud entre strlen(xxx.c_str()) et xxx.length() @@ -85,7 +85,7 @@ int main(int argc, char* argv[]) zizi = gdcm::Util::Format("%d",0x7FE0); ImageLocation = gdcm::Util::DicomString(zizi.c_str()); -//f1->SetEntryValue(Location, 0x0028,0x0200); +//f1->SetValEntry(Location, 0x0028,0x0200); //f1->GetFile()->SetEntryLength(strlen(ImageLocation.c_str())-1, 0x0020,0x0050); // prudence ! // void* imageData= f1->GetImageData(); diff --git a/Example/TestChangeHeader.cxx b/Example/TestChangeHeader.cxx index 89073f51..b8de5e27 100644 --- a/Example/TestChangeHeader.cxx +++ b/Example/TestChangeHeader.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestChangeHeader.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:53 $ - Version: $Revision: 1.11 $ + Date: $Date: 2005/01/25 15:44:22 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) if(matrix != "gdcm::Unfound") { std::cerr << "Aquisition Matrix:" << matrix << std::endl; - f1->GetFile()->Insert( matrix, 0x0018, 0x1310); + f1->GetFile()->InsertValEntry( matrix, 0x0018, 0x1310); } f1->GetImageData(); diff --git a/Example/TestCopyDicom.cxx b/Example/TestCopyDicom.cxx index 37005844..8e7a43b2 100644 --- a/Example/TestCopyDicom.cxx +++ b/Example/TestCopyDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyDicom.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:53 $ - Version: $Revision: 1.21 $ + Date: $Date: 2005/01/25 15:44:22 $ + Version: $Revision: 1.22 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -104,20 +104,15 @@ int main(int argc, char* argv[]) { if ( gdcm::BinEntry* b = dynamic_cast(d) ) { - copy->GetFile()->Insert( - b->GetBinArea(), - b->GetLength(), - b->GetGroup(), - b->GetElement(), - b->GetVR() ); + copy->GetFile()->InsertBinEntry( b->GetBinArea(),b->GetLength(), + b->GetGroup(),b->GetElement(), + b->GetVR() ); } else if ( gdcm::ValEntry* v = dynamic_cast(d) ) { - copy->GetFile()->Insert( - v->GetValue(), - v->GetGroup(), - v->GetElement(), - v->GetVR() ); + copy->GetFile()->InsertValEntry( v->GetValue(), + v->GetGroup(),v->GetElement(), + v->GetVR() ); } else { diff --git a/Example/TestFromScratch.cxx b/Example/TestFromScratch.cxx index 29099d77..d47f638d 100644 --- a/Example/TestFromScratch.cxx +++ b/Example/TestFromScratch.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestFromScratch.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:53 $ - Version: $Revision: 1.13 $ + Date: $Date: 2005/01/25 15:44:22 $ + Version: $Revision: 1.14 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -62,10 +62,9 @@ int main(int argc, char *argv[]) // Do not bother with field from private dict if( v->GetName() != "gdcm::Unknown" ) { - h2->Insert( v->GetValue(), - v->GetGroup(), - v->GetElement(), - v->GetVR() ); + h2->InsertValEntry( v->GetValue(), + v->GetGroup(),v->GetElement(), + v->GetVR() ); } } //else diff --git a/Example/TestPapyrus.cxx b/Example/TestPapyrus.cxx index e0b5dd13..d82083b0 100644 --- a/Example/TestPapyrus.cxx +++ b/Example/TestPapyrus.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestPapyrus.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:53 $ - Version: $Revision: 1.8 $ + Date: $Date: 2005/01/25 15:44:22 $ + Version: $Revision: 1.9 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -231,23 +231,23 @@ int main(int argc, char* argv[]) gdcm::File *n = new gdcm::File(); n->InitializeDefaultFile(); - n->Insert(MediaStSOPinstUID, 0x0002,0x0002); + n->InsertValEntry(MediaStSOPinstUID, 0x0002,0x0002); // Whe keep default gdcm Transfer Syntax (Explicit VR Little Endian) // since using Papyrus one (Implicit VR Little Endian) is a mess //n->Insert(TransferSyntax, 0x0002,0x0010); - n->Insert(StudyDate, 0x0008,0x0020); - n->Insert(StudyTime, 0x0008,0x0030); - n->Insert(Modality, 0x0008,0x0060); - n->Insert(PatientName, 0x0010,0x0010); - - n->Insert(SamplesPerPixel, 0x0028,0x0002); - n->Insert(NumberOfFrames, 0x0028,0x0008); - n->Insert(Rows, 0x0028,0x0010); - n->Insert(Columns, 0x0028,0x0011); - n->Insert(BitsAllocated, 0x0028,0x0100); - n->Insert(BitsStored, 0x0028,0x0101); - n->Insert(HighBit, 0x0028,0x0102); - n->Insert(PixelRepresentation,0x0028,0x0102); + n->InsertValEntry(StudyDate, 0x0008,0x0020); + n->InsertValEntry(StudyTime, 0x0008,0x0030); + n->InsertValEntry(Modality, 0x0008,0x0060); + n->InsertValEntry(PatientName, 0x0010,0x0010); + + n->InsertValEntry(SamplesPerPixel, 0x0028,0x0002); + n->InsertValEntry(NumberOfFrames, 0x0028,0x0008); + n->InsertValEntry(Rows, 0x0028,0x0010); + n->InsertValEntry(Columns, 0x0028,0x0011); + n->InsertValEntry(BitsAllocated, 0x0028,0x0100); + n->InsertValEntry(BitsStored, 0x0028,0x0101); + n->InsertValEntry(HighBit, 0x0028,0x0102); + n->InsertValEntry(PixelRepresentation,0x0028,0x0102); // create the file gdcm::FileHelper *file = new gdcm::FileHelper(n); diff --git a/Example/WriteDicom.cxx b/Example/WriteDicom.cxx index 50ee7357..e450f33f 100644 --- a/Example/WriteDicom.cxx +++ b/Example/WriteDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: WriteDicom.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:53 $ - Version: $Revision: 1.14 $ + Date: $Date: 2005/01/25 15:44:22 $ + Version: $Revision: 1.15 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -41,12 +41,12 @@ int main(int argc, char* argv[]) std::string nbFrames = f2->GetFile()->GetEntryValue(0x0028, 0x0008); if(nbFrames != "gdcm::Unfound") { - f1->GetFile()->Insert( nbFrames, 0x0028, 0x0008); + f1->GetFile()->InsertValEntry( nbFrames, 0x0028, 0x0008); } - f1->GetFile()->Insert( + f1->GetFile()->InsertValEntry( f2->GetFile()->GetEntryValue(0x0028, 0x0010), 0x0028, 0x0010); // nbLig - f1->GetFile()->Insert( + f1->GetFile()->InsertValEntry( f2->GetFile()->GetEntryValue(0x0028, 0x0011), 0x0028, 0x0011); // nbCol // Some other tags should be updated: diff --git a/Example/WriteDicomSimple.cxx b/Example/WriteDicomSimple.cxx index 78b94565..f5b4e273 100644 --- a/Example/WriteDicomSimple.cxx +++ b/Example/WriteDicomSimple.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: WriteDicomSimple.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:53 $ - Version: $Revision: 1.9 $ + Date: $Date: 2005/01/25 15:44:22 $ + Version: $Revision: 1.10 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -63,39 +63,39 @@ int main(int argc, char* argv[]) // Set the image size str.str(""); str << SIZE_X; - header->Insert(str.str(),0x0028,0x0011); // Columns + header->InsertValEntry(str.str(),0x0028,0x0011); // Columns str.str(""); str << SIZE_Y; - header->Insert(str.str(),0x0028,0x0010); // Rows + header->InsertValEntry(str.str(),0x0028,0x0010); // Rows // Set the pixel type str.str(""); str << COMPONENT_SIZE * 8; - header->Insert(str.str(),0x0028,0x0100); // Bits Allocated - header->Insert(str.str(),0x0028,0x0101); // Bits Stored + header->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated + header->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored str.str(""); str << COMPONENT_SIZE * 8 - 1; - header->Insert(str.str(),0x0028,0x0102); // High Bit + header->InsertValEntry(str.str(),0x0028,0x0102); // High Bit // Set the pixel representation str.str(""); str << "0"; // Unsigned - header->Insert(str.str(),0x0028,0x0103); // Pixel Representation + header->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation // Set the samples per pixel str.str(""); str << COMPONENT; - header->Insert(str.str(),0x0028,0x0002); // Samples per Pixel + header->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel // Set the Window / Level str.str(""); str << COLOR_WINDOW; - header->Insert(str.str(),0x0028,0x1051); // Window Width + header->InsertValEntry(str.str(),0x0028,0x1051); // Window Width str.str(""); str << COLOR_LEVEL; - header->Insert(str.str(),0x0028,0x1050); // Window Center + header->InsertValEntry(str.str(),0x0028,0x1050); // Window Center if( !header->IsReadable() ) { diff --git a/Testing/TestCopyDicom.cxx b/Testing/TestCopyDicom.cxx index 7d0b74b9..1dfd328e 100644 --- a/Testing/TestCopyDicom.cxx +++ b/Testing/TestCopyDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyDicom.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:54 $ - Version: $Revision: 1.35 $ + Date: $Date: 2005/01/25 15:44:22 $ + 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 @@ -83,18 +83,15 @@ int CopyDicom(std::string const & filename, { if ( gdcm::BinEntry* b = dynamic_cast(d) ) { - copyH->Insert( b->GetBinArea(), - b->GetLength(), - b->GetGroup(), - b->GetElement(), - b->GetVR() ); + copyH->InsertBinEntry( b->GetBinArea(),b->GetLength(), + b->GetGroup(),b->GetElement(), + b->GetVR() ); } else if ( gdcm::ValEntry* v = dynamic_cast(d) ) { - copyH->Insert( v->GetValue(), - v->GetGroup(), - v->GetElement(), - v->GetVR() ); + copyH->InsertValEntry( v->GetValue(), + v->GetGroup(),v->GetElement(), + v->GetVR() ); } else { diff --git a/Testing/TestCopyRescaleDicom.cxx b/Testing/TestCopyRescaleDicom.cxx index eaff8b4c..3400ec86 100644 --- a/Testing/TestCopyRescaleDicom.cxx +++ b/Testing/TestCopyRescaleDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyRescaleDicom.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:54 $ - Version: $Revision: 1.10 $ + Date: $Date: 2005/01/25 15:44:22 $ + Version: $Revision: 1.11 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -56,20 +56,15 @@ int CopyRescaleDicom(std::string const & filename, { if ( gdcm::BinEntry* b = dynamic_cast(d) ) { - copyH->Insert( - b->GetBinArea(), - b->GetLength(), - b->GetGroup(), - b->GetElement(), - b->GetVR() ); + copyH->InsertBinEntry( b->GetBinArea(),b->GetLength(), + b->GetGroup(),b->GetElement(), + b->GetVR() ); } else if ( gdcm::ValEntry* v = dynamic_cast(d) ) { - copyH->Insert( - v->GetValue(), - v->GetGroup(), - v->GetElement(), - v->GetVR() ); + copyH->InsertValEntry( v->GetValue(), + v->GetGroup(),v->GetElement(), + v->GetVR() ); } else { @@ -91,10 +86,10 @@ int CopyRescaleDicom(std::string const & filename, if( bitsStored == "16" ) { std::cout << "Rescale..."; - copyH->Insert( "8", 0x0028, 0x0100); // BitsAllocated - copyH->Insert( "8", 0x0028, 0x0101); // BitsStored - copyH->Insert( "7", 0x0028, 0x0102); // HighBit - copyH->Insert( "0", 0x0028, 0x0103); //Pixel Representation + copyH->InsertValEntry( "8", 0x0028, 0x0100); // BitsAllocated + copyH->InsertValEntry( "8", 0x0028, 0x0101); // BitsStored + copyH->InsertValEntry( "7", 0x0028, 0x0102); // HighBit + copyH->InsertValEntry( "0", 0x0028, 0x0103); //Pixel Representation // We assume the value were from 0 to uint16_t max rescaleSize = dataSize / 2; diff --git a/Testing/TestWriteSimple.cxx b/Testing/TestWriteSimple.cxx index 23076f16..af00b7c5 100644 --- a/Testing/TestWriteSimple.cxx +++ b/Testing/TestWriteSimple.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestWriteSimple.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 15:29:33 $ - Version: $Revision: 1.15 $ + Date: $Date: 2005/01/25 15:44:23 $ + 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 @@ -78,41 +78,41 @@ int WriteSimple(Image &img) // Set the image size str.str(""); str << img.sizeX; - header->Insert(str.str(),0x0028,0x0011); // Columns + header->InsertValEntry(str.str(),0x0028,0x0011); // Columns str.str(""); str << img.sizeY; - header->Insert(str.str(),0x0028,0x0010); // Rows + header->InsertValEntry(str.str(),0x0028,0x0010); // Rows if(img.sizeZ>1) { str.str(""); str << img.sizeZ; - header->Insert(str.str(),0x0028,0x0008); // Number of Frames + header->InsertValEntry(str.str(),0x0028,0x0008); // Number of Frames } // Set the pixel type str.str(""); str << img.componentSize; - header->Insert(str.str(),0x0028,0x0100); // Bits Allocated + header->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated str.str(""); str << img.componentUse; - header->Insert(str.str(),0x0028,0x0101); // Bits Stored + header->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored str.str(""); str << img.componentSize - 1; - header->Insert(str.str(),0x0028,0x0102); // High Bit + header->InsertValEntry(str.str(),0x0028,0x0102); // High Bit // Set the pixel representation str.str(""); str << img.sign; - header->Insert(str.str(),0x0028,0x0103); // Pixel Representation + header->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation // Set the samples per pixel str.str(""); str << img.components; - header->Insert(str.str(),0x0028,0x0002); // Samples per Pixel + header->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel if( !header->IsReadable() ) { diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 01fb17ce..97d1f3de 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 11:11:58 $ - Version: $Revision: 1.117 $ + Date: $Date: 2005/01/25 15:44:23 $ + Version: $Revision: 1.118 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -331,11 +331,10 @@ DicomDirPatient *DicomDir::GetFirstPatient() DicomDirPatient *DicomDir::GetNextPatient() { gdcmAssertMacro (ItPatient != Patients.end()); - { - ++ItPatient; - if ( ItPatient != Patients.end() ) - return *ItPatient; - } + + ++ItPatient; + if ( ItPatient != Patients.end() ) + return *ItPatient; return NULL; } diff --git a/src/gdcmDicomDirPatient.cxx b/src/gdcmDicomDirPatient.cxx index 9a339e21..72081cf3 100644 --- a/src/gdcmDicomDirPatient.cxx +++ b/src/gdcmDicomDirPatient.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirPatient.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 11:11:58 $ - Version: $Revision: 1.32 $ + Date: $Date: 2005/01/25 15:44:23 $ + 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 @@ -135,11 +135,10 @@ DicomDirStudy *DicomDirPatient::GetFirstStudy() DicomDirStudy *DicomDirPatient::GetNextStudy() { gdcmAssertMacro (ItStudy != Studies.end()) - { - ++ItStudy; - if (ItStudy != Studies.end()) - return *ItStudy; - } + + ++ItStudy; + if (ItStudy != Studies.end()) + return *ItStudy; return NULL; } diff --git a/src/gdcmDicomDirSerie.cxx b/src/gdcmDicomDirSerie.cxx index a03c6480..3678c9a1 100644 --- a/src/gdcmDicomDirSerie.cxx +++ b/src/gdcmDicomDirSerie.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirSerie.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 11:11:58 $ - Version: $Revision: 1.34 $ + Date: $Date: 2005/01/25 15:44:23 $ + Version: $Revision: 1.35 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -134,11 +134,10 @@ DicomDirImage *DicomDirSerie::GetFirstImage() DicomDirImage *DicomDirSerie::GetNextImage() { gdcmAssertMacro (ItImage != Images.end()); - { - ++ItImage; - if (ItImage != Images.end()) - return *ItImage; - } + + ++ItImage; + if (ItImage != Images.end()) + return *ItImage; return NULL; } diff --git a/src/gdcmDicomDirStudy.cxx b/src/gdcmDicomDirStudy.cxx index 058879ee..8975dabd 100644 --- a/src/gdcmDicomDirStudy.cxx +++ b/src/gdcmDicomDirStudy.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirStudy.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 11:11:58 $ - Version: $Revision: 1.31 $ + Date: $Date: 2005/01/25 15:44:23 $ + Version: $Revision: 1.32 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -135,11 +135,10 @@ DicomDirSerie *DicomDirStudy::GetFirstSerie() DicomDirSerie *DicomDirStudy::GetNextSerie() { gdcmAssertMacro (ItSerie != Series.end()); - { - ++ItSerie; - if (ItSerie != Series.end()) - return *ItSerie; - } + + ++ItSerie; + if (ItSerie != Series.end()) + return *ItSerie; return NULL; } diff --git a/src/gdcmDocEntrySet.cxx b/src/gdcmDocEntrySet.cxx index f9c74ec0..3ff3e607 100644 --- a/src/gdcmDocEntrySet.cxx +++ b/src/gdcmDocEntrySet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 14:14:11 $ - Version: $Revision: 1.44 $ + Date: $Date: 2005/01/25 15:44:23 $ + Version: $Revision: 1.45 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -31,7 +31,394 @@ namespace gdcm //----------------------------------------------------------------------------- // Public +/** + * \brief Get the (std::string representable) value of the Dicom entry + * @param group Group number of the searched tag. + * @param elem Element number of the searched tag. + * @return Corresponding element value when it exists, + * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise. + */ +std::string DocEntrySet::GetEntryValue(uint16_t group, uint16_t elem) +{ + ValEntry *entry = GetValEntry(group,elem); + if( entry ) + return entry->GetValue(); + return GDCM_UNFOUND; +} + +/** + * \brief Gets (from Header) a 'non string' element value + * (LoadElementValues has already be executed) + * @param group group number of the Entry + * @param elem element number of the Entry + * @return Pointer to the 'non string' area + */ +void *DocEntrySet::GetEntryBinArea(uint16_t group, uint16_t elem) +{ + BinEntry *entry = GetBinEntry(group,elem); + if( entry ) + return entry->GetBinArea(); + return 0; +} + +/** + * \brief Searches within Header Entries (Dicom Elements) parsed with + * the public and private dictionaries + * for the value length of a given tag.. + * @param group Group number of the searched tag. + * @param elem Element number of the searched tag. + * @return Corresponding element length; -2 if not found + */ +int DocEntrySet::GetEntryLength(uint16_t group, uint16_t elem) +{ + DocEntry *entry = GetDocEntry(group,elem); + if( entry ) + return entry->GetLength(); + return -1; +} + +/** + * \brief Searches within Header Entries (Dicom Elements) parsed with + * the public and private dictionaries + * for the element value representation of a given tag.. + * Obtaining the VR (Value Representation) might be needed by caller + * to convert the string typed content to caller's native type + * (think of C++ vs Python). The VR is actually of a higher level + * of semantics than just the native C++ type. + * @param group Group number of the searched tag. + * @param elem Element number of the searched tag. + * @return Corresponding element value representation when it exists, + * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise. + */ +std::string DocEntrySet::GetEntryVR(uint16_t group, uint16_t elem) +{ + DocEntry *entry = GetDocEntry(group,elem); + if( entry ) + return entry->GetVR(); + return GDCM_UNFOUND; +} + +/** + * \brief Same as \ref Document::GetDocEntry except it only + * returns a result when the corresponding entry is of type + * ValEntry. + * @param group Group number of the searched Dicom Element + * @param elem Element number of the searched Dicom Element + * @return When present, the corresponding ValEntry. + */ +ValEntry *DocEntrySet::GetValEntry(uint16_t group, uint16_t elem) +{ + DocEntry *currentEntry = GetDocEntry(group, elem); + if ( !currentEntry ) + return NULL; + + return dynamic_cast(currentEntry); +} + +/** + * \brief Same as \ref Document::GetDocEntry except it only + * returns a result when the corresponding entry is of type + * BinEntry. + * @param group Group number of the searched Dicom Element + * @param elem Element number of the searched Dicom Element + * @return When present, the corresponding BinEntry. + */ +BinEntry *DocEntrySet::GetBinEntry(uint16_t group, uint16_t elem) +{ + DocEntry *currentEntry = GetDocEntry(group, elem); + if ( !currentEntry ) + return NULL; + + return dynamic_cast(currentEntry); +} + +/** + * \brief Same as \ref Document::GetDocEntry except it only + * returns a result when the corresponding entry is of type + * SeqEntry. + * @param group Group number of the searched Dicom Element + * @param elem Element number of the searched Dicom Element + * @return When present, the corresponding SeqEntry. + */ +SeqEntry *DocEntrySet::GetSeqEntry(uint16_t group, uint16_t elem) +{ + DocEntry *currentEntry = GetDocEntry(group, elem); + if ( !currentEntry ) + return NULL; + + return dynamic_cast(currentEntry); +} + +/** + * \brief Accesses an existing DocEntry (i.e. a Dicom Element) + * through it's (group, element) and modifies it's content with + * the given value. + * @param content new value (string) to substitute with + * @param group group number of the Dicom Element to modify + * @param elem element number of the Dicom Element to modify + */ +bool DocEntrySet::SetValEntry(std::string const& content, + uint16_t group, uint16_t elem) +{ + ValEntry *entry = GetValEntry(group, elem); + if (!entry ) + { + gdcmVerboseMacro( "No corresponding ValEntry (try promotion first)."); + return false; + } + return SetValEntry(content,entry); +} + +/** + * \brief Accesses an existing DocEntry (i.e. a Dicom Element) + * through it's (group, element) and modifies it's content with + * the given value. + * @param content new value (void* -> uint8_t*) to substitute with + * @param lgth new value length + * @param group group number of the Dicom Element to modify + * @param elem element number of the Dicom Element to modify + */ +bool DocEntrySet::SetBinEntry(uint8_t*content, int lgth, + uint16_t group, uint16_t elem) +{ + BinEntry *entry = GetBinEntry(group, elem); + if (!entry ) + { + gdcmVerboseMacro( "No corresponding ValEntry (try promotion first)."); + return false; + } + + return SetBinEntry(content,lgth,entry); +} + +/** + * \brief Accesses an existing DocEntry (i.e. a Dicom Element) + * and modifies it's content with the given value. + * @param content new value (string) to substitute with + * @param entry Entry to be modified + */ +bool DocEntrySet::SetValEntry(std::string const &content, ValEntry *entry) +{ + if(entry) + { + entry->SetValue(content); + return true; + } + return false; +} + +/** + * \brief Accesses an existing BinEntry (i.e. a Dicom Element) + * and modifies it's content with the given value. + * @param content new value (void* -> uint8_t*) to substitute with + * @param entry Entry to be modified + * @param lgth new value length + */ +bool DocEntrySet::SetBinEntry(uint8_t *content, int lgth, BinEntry *entry) +{ + if(entry) + { + entry->SetBinArea(content); + entry->SetLength(lgth); + entry->SetValue(GDCM_BINLOADED); + return true; + } + return false; +} + +/** + * \brief Modifies the value of a given Doc Entry (Dicom Element) + * when it exists. Create it with the given value when unexistant. + * @param value (string) Value to be set + * @param group Group number of the Entry + * @param elem Element number of the Entry + * @param vr V(alue) R(epresentation) of the Entry -if private Entry- + * \return pointer to the modified/created Header Entry (NULL when creation + * failed). + */ +ValEntry *DocEntrySet::InsertValEntry(std::string const &value, + uint16_t group, uint16_t elem, + TagName const &vr ) +{ + ValEntry *valEntry = 0; + DocEntry *currentEntry = GetDocEntry( group, elem); + + if (currentEntry) + { + valEntry = dynamic_cast(currentEntry); + // Verify the VR + if( valEntry ) + if( valEntry->GetVR()!=vr ) + valEntry = NULL; + + // if currentEntry doesn't correspond to the requested valEntry + if( !valEntry) + { + if( !RemoveEntry(currentEntry) ) + { + gdcmVerboseMacro( "Removal of previous DocEntry failed."); + + return NULL; + } + } + } + + // Create a new valEntry if necessary + if( !valEntry ) + { + valEntry = NewValEntry(group, elem, vr); + + if ( !AddEntry(valEntry) ) + { + gdcmVerboseMacro("AddEntry failed although this is a creation."); + + delete valEntry; + return NULL; + } + } + + // Set the binEntry value + SetValEntry(value, valEntry); // The std::string value + return valEntry; +} + +/* + * \brief Modifies the value of a given Header Entry (Dicom Element) + * when it exists. Create it with the given value when unexistant. + * A copy of the binArea is made to be kept in the Document. + * @param binArea (binary) value to be set + * @param group Group number of the Entry + * @param elem Element number of the Entry + * @param vr V(alue) R(epresentation) of the Entry -if private Entry- + * \return pointer to the modified/created Header Entry (NULL when creation + * failed). + */ +BinEntry *DocEntrySet::InsertBinEntry(uint8_t *binArea,int lgth, + uint16_t group, uint16_t elem, + TagName const &vr ) +{ + BinEntry *binEntry = 0; + DocEntry *currentEntry = GetDocEntry( group, elem); + + // Verify the currentEntry + if (currentEntry) + { + binEntry = dynamic_cast(currentEntry); + + // Verify the VR + if( binEntry ) + if( binEntry->GetVR()!=vr ) + binEntry = NULL; + + // if currentEntry doesn't correspond to the requested valEntry + if( !binEntry) + { + if( !RemoveEntry(currentEntry) ) + { + gdcmVerboseMacro( "Removal of previous DocEntry failed."); + + return NULL; + } + } + } + + // Create a new binEntry if necessary + if( !binEntry) + { + binEntry = NewBinEntry(group, elem, vr); + + if ( !AddEntry(binEntry) ) + { + gdcmVerboseMacro( "AddEntry failed allthough this is a creation."); + + delete binEntry; + return NULL; + } + } + + // Set the binEntry value + uint8_t *tmpArea; + if( lgth>0 && binArea ) + { + tmpArea = new uint8_t[lgth]; + memcpy(tmpArea,binArea,lgth); + } + else + { + tmpArea = 0; + } + if( !SetBinEntry(tmpArea,lgth,binEntry) ) + { + if( tmpArea ) + { + delete[] tmpArea; + } + } + + return binEntry; +} + +/* + * \brief Modifies the value of a given Header Entry (Dicom Element) + * when it exists. Creates it when unexistant. + * @param group Group number of the Entry + * @param elem Element number of the Entry + * \return pointer to the modified/created SeqEntry (NULL when creation + * failed). + */ +SeqEntry *DocEntrySet::InsertSeqEntry(uint16_t group, uint16_t elem) +{ + SeqEntry *seqEntry = 0; + DocEntry *currentEntry = GetDocEntry( group, elem); + + // Verify the currentEntry + if( currentEntry ) + { + seqEntry = dynamic_cast(currentEntry); + + // Verify the VR + if( seqEntry ) + if( seqEntry->GetVR()!="SQ" ) + seqEntry = NULL; + + // if currentEntry doesn't correspond to the requested valEntry + if( !seqEntry ) + { + if (!RemoveEntry(currentEntry)) + { + gdcmVerboseMacro( "Removal of previous DocEntry failed."); + + return NULL; + } + } + } + // Create a new seqEntry if necessary + if( !seqEntry ) + { + seqEntry = NewSeqEntry(group, elem); + + if( !AddEntry(seqEntry) ) + { + gdcmVerboseMacro( "AddEntry failed allthough this is a creation."); + + delete seqEntry; + return NULL; + } + } + return seqEntry; +} + +/** + * \brief Checks if a given Dicom Element exists within the H table + * @param group Group number of the searched Dicom Element + * @param elem Element number of the searched Dicom Element + * @return true is found + */ +bool DocEntrySet::CheckIfEntryExist(uint16_t group, uint16_t elem ) +{ + return GetDocEntry(group,elem)!=NULL; +} /** * \brief Request a new virtual dict entry to the dict set @@ -187,11 +574,8 @@ DictEntry *DocEntrySet::GetDictEntry(uint16_t group, uint16_t elem, return goodEntry; } - - //----------------------------------------------------------------------------- // Private -} // end namespace gdcm - //----------------------------------------------------------------------------- +} // end namespace gdcm diff --git a/src/gdcmDocEntrySet.h b/src/gdcmDocEntrySet.h index e1b94f2a..df5c2fd4 100644 --- a/src/gdcmDocEntrySet.h +++ b/src/gdcmDocEntrySet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.h,v $ Language: C++ - Date: $Date: 2005/01/25 11:11:58 $ - Version: $Revision: 1.43 $ + Date: $Date: 2005/01/25 15:44:23 $ + Version: $Revision: 1.44 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -62,55 +62,60 @@ public: DocEntrySet() {}; virtual ~DocEntrySet() {}; - // ------- '... =0;' stands for 'Pure Virtual' + /// \brief write any type of entry to the entry set + virtual void WriteContent (std::ofstream *fp, FileType filetype) = 0; /// \brief Remove all Entry in the entry set virtual void ClearEntry() = 0; - /// \brief adds any type of entry to the entry set virtual bool AddEntry(DocEntry *Entry) = 0; - /// \brief Removes any type of entry out of the entry set, and destroys it virtual bool RemoveEntry(DocEntry *EntryToRemove)=0; - /// \brief Removes any type of entry out of the entry set, DOESN'T destroy it virtual bool RemoveEntryNoDestroy(DocEntry *EntryToRemove)= 0; - /// \brief write any type of entry to the entry set - virtual void WriteContent (std::ofstream *fp, - FileType filetype) = 0; + virtual DocEntry *GetFirstEntry()=0; + virtual DocEntry *GetNextEntry()=0; - /// \brief Gets any type of DocEntry, identified by its (group,elem) - virtual DocEntry *GetDocEntry(uint16_t group, - uint16_t elem) = 0; + virtual std::string GetEntryValue(uint16_t group, uint16_t elem); + virtual void *GetEntryBinArea(uint16_t group, uint16_t elem); + virtual int GetEntryLength(uint16_t group, uint16_t elem); + virtual std::string GetEntryVR(uint16_t group, uint16_t elem); + /// \brief Gets any type of DocEntry, identified by its (group,elem) + virtual DocEntry *GetDocEntry(uint16_t group,uint16_t elem) = 0; /// \brief Gets a ValEntry, identified by its (group,elem) - virtual ValEntry *GetValEntry(uint16_t group, - uint16_t elem) = 0; + virtual ValEntry *GetValEntry(uint16_t group,uint16_t elem); /// \brief Gets a BinEntry, identified by its (group,elem) - virtual BinEntry *GetBinEntry(uint16_t group, - uint16_t elem) = 0; - + virtual BinEntry *GetBinEntry(uint16_t group,uint16_t elem); /// \brief Gets a SeqEntry, identified by its (group,elem) - virtual SeqEntry *GetSeqEntry(uint16_t group, - uint16_t elem) = 0; - - /// \brief Gets the 'string value' of a ValEntry - /// identified by its (group,elem) - Sorry for the name !...- - virtual std::string GetEntryValue(uint16_t group, uint16_t elem) = 0; - - virtual DocEntry *GetFirstEntry()=0; - virtual DocEntry *GetNextEntry()=0; - - DictEntry *NewVirtualDictEntry(uint16_t group, - uint16_t elem, + virtual SeqEntry *GetSeqEntry(uint16_t group,uint16_t elem); + + virtual bool SetValEntry(std::string const &content, + uint16_t group, uint16_t elem); + virtual bool SetBinEntry(uint8_t *content, int lgth, + uint16_t group, uint16_t elem); + virtual bool SetValEntry(std::string const &content, ValEntry *entry); + virtual bool SetBinEntry(uint8_t *content, int lgth, BinEntry *entry); + + virtual ValEntry *InsertValEntry(std::string const &value, + uint16_t group, uint16_t elem, + TagName const &vr = GDCM_UNKNOWN); + virtual BinEntry *InsertBinEntry(uint8_t *binArea, int lgth, + uint16_t group, uint16_t elem, + TagName const &vr = GDCM_UNKNOWN); + virtual SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem); + + virtual bool IsEmpty() = 0; + virtual bool CheckIfEntryExist(uint16_t group, uint16_t elem); + + DictEntry *NewVirtualDictEntry(uint16_t group,uint16_t elem, TagName const &vr = GDCM_UNKNOWN, TagName const &vm = GDCM_UNKNOWN, TagName const &name = GDCM_UNKNOWN ); protected: // DocEntry related utilities - ValEntry *NewValEntry(uint16_t group,uint16_t elem, TagName const &vr = GDCM_UNKNOWN); BinEntry *NewBinEntry(uint16_t group,uint16_t elem, diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index ca217bb7..fcf5c290 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 11:25:33 $ - Version: $Revision: 1.209 $ + Date: $Date: 2005/01/25 15:44:23 $ + Version: $Revision: 1.210 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -149,8 +149,8 @@ Document::Document( std::string const &filename ) : ElementSet(-1) Filetype = ACR_LIBIDO; std::string rows = GetEntryValue(0x0028, 0x0010); std::string columns = GetEntryValue(0x0028, 0x0011); - SetEntryValue(columns, 0x0028, 0x0010); - SetEntryValue(rows , 0x0028, 0x0011); + SetValEntry(columns, 0x0028, 0x0010); + SetValEntry(rows , 0x0028, 0x0011); } // ----------------- End of ACR-LibIDO kludge ------------------ } @@ -264,7 +264,6 @@ bool Document::IsReadable() return false; } - //if( TagHT.empty() ) if ( IsEmpty() ) { gdcmVerboseMacro( "No tag in internal hash table."); @@ -475,358 +474,8 @@ void Document::WriteContent(std::ofstream *fp, FileType filetype) ElementSet::WriteContent(fp, filetype); // This one is recursive } -/** - * \brief Modifies the value of a given Doc Entry (Dicom Element) - * when it exists. Create it with the given value when unexistant. - * @param value (string) Value to be set - * @param group Group number of the Entry - * @param elem Element number of the Entry - * @param vr V(alue) R(epresentation) of the Entry -if private Entry- - * \return pointer to the modified/created Header Entry (NULL when creation - * failed). - */ -ValEntry *Document::Insert(std::string const &value, - uint16_t group, - uint16_t elem, - TagName const &vr ) -{ - ValEntry *valEntry = 0; - DocEntry *currentEntry = GetDocEntry( group, elem); - - if (currentEntry) - { - valEntry = dynamic_cast< ValEntry* >(currentEntry); - - // Verify the VR - if( valEntry ) - if( valEntry->GetVR()!=vr ) - valEntry=NULL; - - // if currentEntry doesn't correspond to the requested valEntry - if( !valEntry) - { - if (!RemoveEntry(currentEntry)) - { - gdcmVerboseMacro( "Removal of previous DocEntry failed."); - - return NULL; - } - } - } - - // Create a new valEntry if necessary - if (!valEntry) - { - valEntry = NewValEntry(group, elem, vr); - - if ( !AddEntry(valEntry)) - { - gdcmVerboseMacro("AddEntry failed although this is a creation."); - - delete valEntry; - return NULL; - } - } - - // Set the binEntry value - SetEntryValue(value, valEntry); // The std::string value - return valEntry; -} - -/* - * \brief Modifies the value of a given Header Entry (Dicom Element) - * when it exists. Create it with the given value when unexistant. - * A copy of the binArea is made to be kept in the Document. - * @param binArea (binary) value to be set - * @param group Group number of the Entry - * @param elem Element number of the Entry - * @param vr V(alue) R(epresentation) of the Entry -if private Entry- - * \return pointer to the modified/created Header Entry (NULL when creation - * failed). - */ -BinEntry *Document::Insert(uint8_t *binArea, - int lgth, - uint16_t group, - uint16_t elem, - TagName const &vr ) -{ - BinEntry *binEntry = 0; - DocEntry *currentEntry = GetDocEntry( group, elem); - - // Verify the currentEntry - if (currentEntry) - { - binEntry = dynamic_cast< BinEntry* >(currentEntry); - - // Verify the VR - if( binEntry ) - if( binEntry->GetVR()!=vr ) - binEntry=NULL; - - // if currentEntry doesn't correspond to the requested valEntry - if( !binEntry) - { - if (!RemoveEntry(currentEntry)) - { - gdcmVerboseMacro( "Removal of previous DocEntry failed."); - - return NULL; - } - } - } - - // Create a new binEntry if necessary - if (!binEntry) - { - binEntry = NewBinEntry(group, elem, vr); - - if ( !AddEntry(binEntry)) - { - gdcmVerboseMacro( "AddEntry failed allthough this is a creation."); - - delete binEntry; - return NULL; - } - } - - // Set the binEntry value - uint8_t *tmpArea; - if (lgth>0 && binArea) - { - tmpArea = new uint8_t[lgth]; - memcpy(tmpArea,binArea,lgth); - } - else - { - tmpArea = 0; - } - if (!SetEntryBinArea(tmpArea,lgth,binEntry)) - { - if (tmpArea) - { - delete[] tmpArea; - } - } - - return binEntry; -} - -/* - * \brief Modifies the value of a given Header Entry (Dicom Element) - * when it exists. Creates it when unexistant. - * @param group Group number of the Entry - * @param elem Element number of the Entry - * \return pointer to the modified/created SeqEntry (NULL when creation - * failed). - */ -SeqEntry *Document::Insert( uint16_t group, uint16_t elem) -{ - SeqEntry *seqEntry = 0; - DocEntry *currentEntry = GetDocEntry( group, elem); - - // Verify the currentEntry - if (currentEntry) - { - seqEntry = dynamic_cast< SeqEntry* >(currentEntry); - - // Verify the VR - if( seqEntry ) - if( seqEntry->GetVR()!="SQ" ) - seqEntry=NULL; - - // if currentEntry doesn't correspond to the requested valEntry - if( !seqEntry) - { - if (!RemoveEntry(currentEntry)) - { - gdcmVerboseMacro( "Removal of previous DocEntry failed."); - - return NULL; - } - } - } - // Create a new seqEntry if necessary - if (!seqEntry) - { - seqEntry = NewSeqEntry(group, elem); - - if ( !AddEntry(seqEntry)) - { - gdcmVerboseMacro( "AddEntry failed allthough this is a creation."); - - delete seqEntry; - return NULL; - } - } - return seqEntry; -} - -/** - * \brief Set a new value if the invoked element exists - * Seems to be useless !!! - * @param value new element value - * @param group group number of the Entry - * @param elem element number of the Entry - * \return boolean - */ -bool Document::ReplaceIfExist(std::string const &value, - uint16_t group, uint16_t elem ) -{ - SetEntryValue(value, group, elem); - - return true; -} - //----------------------------------------------------------------------------- // Protected - -/** - * \brief Searches within Header Entries (Dicom Elements) parsed with - * the public and private dictionaries - * for the element value representation of a given tag.. - * Obtaining the VR (Value Representation) might be needed by caller - * to convert the string typed content to caller's native type - * (think of C++ vs Python). The VR is actually of a higher level - * of semantics than just the native C++ type. - * @param group Group number of the searched tag. - * @param elem Element number of the searched tag. - * @return Corresponding element value representation when it exists, - * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise. - */ -std::string Document::GetEntryVR(uint16_t group, uint16_t elem) -{ - DocEntry *element = GetDocEntry(group, elem); - if ( !element ) - { - return GDCM_UNFOUND; - } - return element->GetVR(); -} - -/** - * \brief Searches within Header Entries (Dicom Elements) parsed with - * the public and private dictionaries - * for the value length of a given tag.. - * @param group Group number of the searched tag. - * @param elem Element number of the searched tag. - * @return Corresponding element length; -2 if not found - */ -int Document::GetEntryLength(uint16_t group, uint16_t elem) -{ - DocEntry *element = GetDocEntry(group, elem); - if ( !element ) - { - return -2; //magic number - } - return element->GetLength(); -} - -/** - * \brief Accesses an existing DocEntry (i.e. a Dicom Element) - * through it's (group, element) and modifies it's content with - * the given value. - * @param content new value (string) to substitute with - * @param group group number of the Dicom Element to modify - * @param elem element number of the Dicom Element to modify - */ -bool Document::SetEntryValue(std::string const& content, - uint16_t group, uint16_t elem) -{ - ValEntry *entry = GetValEntry(group, elem); - if (!entry ) - { - gdcmVerboseMacro( "No corresponding ValEntry (try promotion first)."); - return false; - } - return SetEntryValue(content,entry); -} -/** - * \brief Accesses an existing DocEntry (i.e. a Dicom Element) - * through it's (group, element) and modifies it's content with - * the given value. - * @param content new value (void* -> uint8_t*) to substitute with - * @param lgth new value length - * @param group group number of the Dicom Element to modify - * @param elem element number of the Dicom Element to modify - */ -bool Document::SetEntryBinArea(uint8_t*content, int lgth, - uint16_t group, uint16_t elem) -{ - BinEntry *entry = GetBinEntry(group, elem); - if (!entry ) - { - gdcmVerboseMacro( "No corresponding ValEntry (try promotion first)."); - return false; - } - - return SetEntryBinArea(content,lgth,entry); -} - -/** - * \brief Accesses an existing DocEntry (i.e. a Dicom Element) - * and modifies it's content with the given value. - * @param content new value (string) to substitute with - * @param entry Entry to be modified - */ -bool Document::SetEntryValue(std::string const &content, ValEntry *entry) -{ - if(entry) - { - entry->SetValue(content); - return true; - } - return false; -} - -/** - * \brief Accesses an existing BinEntry (i.e. a Dicom Element) - * and modifies it's content with the given value. - * @param content new value (void* -> uint8_t*) to substitute with - * @param entry Entry to be modified - * @param lgth new value length - */ -bool Document::SetEntryBinArea(uint8_t *content, int lgth, BinEntry *entry) -{ - if(entry) - { - // Hope Binary field length is *never* wrong - /*if(lgth%2) // Non even length are padded with a space (020H). - { - lgth++; - //content = content + '\0'; // fing a trick to enlarge a binary field? - }*/ - - entry->SetBinArea(content); - entry->SetLength(lgth); - entry->SetValue(GDCM_BINLOADED); - return true; - } - return false; -} - -/** - * \brief Gets (from Header) a 'non string' element value - * (LoadElementValues has already be executed) - * @param group group number of the Entry - * @param elem element number of the Entry - * @return Pointer to the 'non string' area - */ -void *Document::GetEntryBinArea(uint16_t group, uint16_t elem) -{ - DocEntry *entry = GetDocEntry(group, elem); - if (!entry) - { - gdcmVerboseMacro( "No entry"); - return 0; - } - if ( BinEntry *binEntry = dynamic_cast(entry) ) - { - return binEntry->GetBinArea(); - } - - return 0; -} - /** * \brief Loads (from disk) the element content * when a string is not suitable diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index 7082c755..4166b318 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.h,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:54 $ - Version: $Revision: 1.100 $ + Date: $Date: 2005/01/25 15:44:24 $ + Version: $Revision: 1.101 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -88,38 +88,10 @@ public: // Content entries -// Oops ! Python is gonna cry : -// 4 methods with same name and different parameters ... -// Only C++ is aware! - - virtual bool SetEntryValue(std::string const &content, - uint16_t group, uint16_t elem); - virtual bool SetEntryBinArea(uint8_t *content, int lgth, - uint16_t group, uint16_t elem); - virtual bool SetEntryValue(std::string const &content, ValEntry *entry); - virtual bool SetEntryBinArea(uint8_t *content, int lgth, BinEntry *entry); - - virtual void *GetEntryBinArea(uint16_t group, uint16_t elem); - - virtual std::string GetEntryVR(uint16_t group, uint16_t elem); - virtual int GetEntryLength(uint16_t group, uint16_t elem); - - ValEntry *Insert(std::string const &value, - uint16_t group, uint16_t elem, - TagName const &vr = GDCM_UNKNOWN); - BinEntry *Insert(uint8_t *binArea, int lgth, - uint16_t group, uint16_t elem, - TagName const &vr = GDCM_UNKNOWN); - SeqEntry *Insert(uint16_t group, uint16_t elem); - - bool ReplaceIfExist(std::string const &value, - uint16_t group, uint16_t elem ); - virtual void LoadEntryBinArea(uint16_t group, uint16_t elem); virtual void LoadEntryBinArea(BinEntry *entry); void LoadDocEntrySafe(DocEntry *entry); - /*TagDocEntryHT *BuildFlatHashTable();*/ /// Return the Transfer Syntax as a string std::string GetTransferSyntaxName(); diff --git a/src/gdcmElementSet.cxx b/src/gdcmElementSet.cxx index 0b634fa7..dbf05c60 100644 --- a/src/gdcmElementSet.cxx +++ b/src/gdcmElementSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmElementSet.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 11:11:59 $ - Version: $Revision: 1.50 $ + Date: $Date: 2005/01/25 15:44:24 $ + Version: $Revision: 1.51 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -88,124 +88,6 @@ void ElementSet::WriteContent(std::ofstream *fp, FileType filetype) } } -/** - * \brief retrieves a Dicom Element using (group, element) - * @param group Group number of the searched Dicom Element - * @param elem Element number of the searched Dicom Element - * @return - */ -DocEntry *ElementSet::GetDocEntry(uint16_t group, uint16_t elem) -{ - TagKey key = DictEntry::TranslateToKey(group, elem); - if ( !TagHT.count(key)) - { - return NULL; - } - return TagHT.find(key)->second; -} - -/** - * \brief Same as \ref Document::GetDocEntry except it only - * returns a result when the corresponding entry is of type - * ValEntry. - * @param group Group number of the searched Dicom Element - * @param elem Element number of the searched Dicom Element - * @return When present, the corresponding ValEntry. - */ -ValEntry *ElementSet::GetValEntry(uint16_t group, uint16_t elem) -{ - DocEntry *currentEntry = GetDocEntry(group, elem); - if ( !currentEntry ) - { - return 0; - } - if ( ValEntry *entry = dynamic_cast(currentEntry) ) - { - return entry; - } - gdcmVerboseMacro( "Unfound ValEntry."); - - return 0; -} - -/** - * \brief Same as \ref Document::GetDocEntry except it only - * returns a result when the corresponding entry is of type - * BinEntry. - * @param group Group number of the searched Dicom Element - * @param elem Element number of the searched Dicom Element - * @return When present, the corresponding BinEntry. - */ -BinEntry *ElementSet::GetBinEntry(uint16_t group, uint16_t elem) -{ - DocEntry *currentEntry = GetDocEntry(group, elem); - if ( !currentEntry ) - { - return 0; - } - if ( BinEntry *entry = dynamic_cast(currentEntry) ) - { - return entry; - } - gdcmVerboseMacro( "Unfound BinEntry."); - - return 0; -} - -/** - * \brief Same as \ref Document::GetDocEntry except it only - * returns a result when the corresponding entry is of type - * SeqEntry. - * @param group Group number of the searched Dicom Element - * @param elem Element number of the searched Dicom Element - * @return When present, the corresponding SeqEntry. - */ -SeqEntry *ElementSet::GetSeqEntry(uint16_t group, uint16_t elem) -{ - DocEntry *currentEntry = GetDocEntry(group, elem); - if ( !currentEntry ) - { - return 0; - } - if ( SeqEntry *entry = dynamic_cast(currentEntry) ) - { - return entry; - } - gdcmVerboseMacro( "Unfound SeqEntry."); - - return 0; -} - -/** - * \brief Checks if a given Dicom Element exists within the H table - * @param group Group number of the searched Dicom Element - * @param elem Element number of the searched Dicom Element - * @return true is found - */ -bool ElementSet::CheckIfEntryExist(uint16_t group, uint16_t elem ) -{ - const std::string &key = DictEntry::TranslateToKey(group, elem ); - return TagHT.count(key) != 0; -} - -/** - * \brief Get the (std::string representable) value of the Dicom entry - * @param group Group number of the searched tag. - * @param elem Element number of the searched tag. - * @return Corresponding element value when it exists, - * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise. - */ -std::string ElementSet::GetEntryValue(uint16_t group, uint16_t elem) -{ - TagKey key = DictEntry::TranslateToKey(group, elem); - if ( !TagHT.count(key)) - { - return GDCM_UNFOUND; - } - - return ((ValEntry *)TagHT.find(key)->second)->GetValue(); -} - /** * \brief delete all entries in the ElementSet */ @@ -306,29 +188,18 @@ DocEntry *ElementSet::GetNextEntry() } /** - * \brief Get the larst entry while visiting the DocEntrySet - * \return The last DocEntry if found, otherwhise NULL - */ -DocEntry *ElementSet::GetLastEntry() -{ - ItTagHT = TagHT.end(); - if ( ItTagHT != TagHT.begin() ) - return ItTagHT->second; - return NULL; -} - -/** - * \brief Get the previous entry while visiting the Hash table (TagHT) - * \note : meaningfull only if GetFirstEntry already called - * \return The previous DocEntry if found, otherwhise NULL + * \brief retrieves a Dicom Element using (group, element) + * @param group Group number of the searched Dicom Element + * @param elem Element number of the searched Dicom Element + * @return */ -DocEntry *ElementSet::GetPreviousEntry() +DocEntry *ElementSet::GetDocEntry(uint16_t group, uint16_t elem) { - gdcmAssertMacro (ItTagHT != TagHT.begin()); + TagKey key = DictEntry::TranslateToKey(group, elem); + TagDocEntryHT::iterator it = TagHT.find(key); - --ItTagHT; - if (ItTagHT != TagHT.begin()) - return ItTagHT->second; + if ( it!=TagHT.end() ) + return it->second; return NULL; } diff --git a/src/gdcmElementSet.h b/src/gdcmElementSet.h index 0f6e5d50..20b56c53 100644 --- a/src/gdcmElementSet.h +++ b/src/gdcmElementSet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmElementSet.h,v $ Language: C++ - Date: $Date: 2005/01/25 11:11:59 $ - Version: $Revision: 1.37 $ + Date: $Date: 2005/01/25 15:44:24 $ + Version: $Revision: 1.38 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -49,32 +49,19 @@ public: virtual void Print(std::ostream &os = std::cout, std::string const &indent = "" ); + void WriteContent(std::ofstream *fp, FileType filetype); + void ClearEntry(); bool AddEntry(DocEntry *Entry); bool RemoveEntry(DocEntry *EntryToRemove); bool RemoveEntryNoDestroy(DocEntry *EntryToRemove); - void WriteContent(std::ofstream *fp, FileType filetype); - DocEntry *GetFirstEntry(); DocEntry *GetNextEntry(); - DocEntry *GetLastEntry(); - DocEntry *GetPreviousEntry(); DocEntry *GetDocEntry(uint16_t group, uint16_t elem); - ValEntry *GetValEntry(uint16_t group, uint16_t elem); - BinEntry *GetBinEntry(uint16_t group, uint16_t elem); - SeqEntry *GetSeqEntry(uint16_t group, uint16_t elem); bool IsEmpty() { return TagHT.empty(); }; - bool CheckIfEntryExist(uint16_t group, uint16_t elem); - - std::string GetEntryValue(uint16_t group, uint16_t elem); - int GetEntryLength(uint16_t group, uint16_t elem); - std::string GetEntryVR(uint16_t group, uint16_t elem); - - bool SetEntryValue(std::string const& content, - uint16_t group, uint16_t elem); protected: diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 9e6788e6..17e4a80a 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:54 $ - Version: $Revision: 1.199 $ + Date: $Date: 2005/01/25 15:44:24 $ + Version: $Revision: 1.200 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -140,7 +140,7 @@ bool File::Write(std::string fileName, FileType filetype) // Bits Allocated if ( GetEntryValue(0x0028,0x0100) == "12") { - SetEntryValue("16", 0x0028,0x0100); + SetValEntry("16", 0x0028,0x0100); } /// \todo correct 'Pixel group' Length if necessary @@ -151,7 +151,7 @@ bool File::Write(std::string fileName, FileType filetype) // no (GrPixel, NumPixel) element std::string s_lgPix = Util::Format("%d", i_lgPix+12); s_lgPix = Util::DicomString( s_lgPix.c_str() ); - Insert(s_lgPix,GrPixel, 0x0000); + InsertValEntry(s_lgPix,GrPixel, 0x0000); } // FIXME : should be nice if we could move it to File @@ -1209,9 +1209,9 @@ int File::GetLUTNbits() bool File::AnonymizeFile() { // If exist, replace by spaces - SetEntryValue (" ",0x0010, 0x2154); // Telephone - SetEntryValue (" ",0x0010, 0x1040); // Adress - SetEntryValue (" ",0x0010, 0x0020); // Patient ID + SetValEntry (" ",0x0010, 0x2154); // Telephone + SetValEntry (" ",0x0010, 0x1040); // Adress + SetValEntry (" ",0x0010, 0x0020); // Patient ID DocEntry* patientNameHE = GetDocEntry (0x0010, 0x0010); @@ -1220,11 +1220,11 @@ bool File::AnonymizeFile() std::string studyInstanceUID = GetEntryValue (0x0020, 0x000d); if ( studyInstanceUID != GDCM_UNFOUND ) { - Insert(studyInstanceUID, 0x0010, 0x0010); + InsertValEntry(studyInstanceUID, 0x0010, 0x0010); } else { - Insert("anonymised", 0x0010, 0x0010); + InsertValEntry("anonymised", 0x0010, 0x0010); } } @@ -1380,14 +1380,14 @@ void File::InitializeDefaultFile() // Special case this is the image (not a string) GrPixel = 0x7fe0; NumPixel = 0x0010; - Insert(0, 0, GrPixel, NumPixel); + InsertBinEntry(0, 0, GrPixel, NumPixel); // All remaining strings: unsigned int i = 0; DICOM_DEFAULT_VALUE current = defaultvalue[i]; while( current.value ) { - Insert(current.value, current.group, current.elem); + InsertValEntry(current.value, current.group, current.elem); current = defaultvalue[++i]; } } diff --git a/src/gdcmFileHelper.cxx b/src/gdcmFileHelper.cxx index 9d30a55d..9d8e8f44 100644 --- a/src/gdcmFileHelper.cxx +++ b/src/gdcmFileHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFileHelper.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 15:21:20 $ - Version: $Revision: 1.6 $ + Date: $Date: 2005/01/25 15:44:24 $ + 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 @@ -532,10 +532,10 @@ bool FileHelper::Write(std::string const &fileName) * @param group group number of the Dicom Element to modify * @param elem element number of the Dicom Element to modify */ -bool FileHelper::SetEntryValue(std::string const &content, +bool FileHelper::SetValEntry(std::string const &content, uint16_t group, uint16_t elem) { - return FileInternal->SetEntryValue(content,group,elem); + return FileInternal->SetValEntry(content,group,elem); } @@ -548,10 +548,10 @@ bool FileHelper::SetEntryValue(std::string const &content, * @param group group number of the Dicom Element to modify * @param elem element number of the Dicom Element to modify */ -bool FileHelper::SetEntryBinArea(uint8_t *content, int lgth, +bool FileHelper::SetBinEntry(uint8_t *content, int lgth, uint16_t group, uint16_t elem) { - return FileInternal->SetEntryBinArea(content,lgth,group,elem); + return FileInternal->SetBinEntry(content,lgth,group,elem); } /** @@ -563,10 +563,10 @@ bool FileHelper::SetEntryBinArea(uint8_t *content, int lgth, * \return pointer to the modified/created Dicom entry (NULL when creation * failed). */ -bool FileHelper::Insert(std::string const &content, - uint16_t group, uint16_t elem) +ValEntry *FileHelper::InsertValEntry(std::string const &content, + uint16_t group, uint16_t elem) { - return FileInternal->Insert(content,group,elem) != NULL; + return FileInternal->InsertValEntry(content,group,elem); } /* @@ -579,10 +579,24 @@ bool FileHelper::Insert(std::string const &content, * \return pointer to the modified/created Dicom entry (NULL when creation * failed). */ -bool FileHelper::Insert(uint8_t *binArea, int lgth, - uint16_t group, uint16_t elem) +BinEntry *FileHelper::InsertBinEntry(uint8_t *binArea, int lgth, + uint16_t group, uint16_t elem) { - return FileInternal->Insert(binArea,lgth,group,elem) != NULL; + return FileInternal->InsertBinEntry(binArea,lgth,group,elem); +} + +/* + * \brief Modifies the value of a given DocEntry (Dicom entry) + * when it exists. Create it with the given value when unexistant. + * A copy of the binArea is made to be kept in the Document. + * @param group Group number of the Entry + * @param elem Element number of the Entry + * \return pointer to the modified/created Dicom entry (NULL when creation + * failed). + */ +SeqEntry *FileHelper::InsertSeqEntry(uint16_t group, uint16_t elem) +{ + return FileInternal->InsertSeqEntry(group,elem); } /** diff --git a/src/gdcmFileHelper.h b/src/gdcmFileHelper.h index 7752d395..4848a946 100644 --- a/src/gdcmFileHelper.h +++ b/src/gdcmFileHelper.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFileHelper.h,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:54 $ - Version: $Revision: 1.6 $ + Date: $Date: 2005/01/25 15:44:24 $ + 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 @@ -27,6 +27,7 @@ namespace gdcm class File; class ValEntry; class BinEntry; +class SeqEntry; class PixelReadConvert; class PixelWriteConvert; class DocEntryArchive; @@ -54,6 +55,18 @@ public: void Print(std::ostream &os = std::cout, std::string const & indent = ""); + // File methods + bool SetValEntry(std::string const &content, + uint16_t group, uint16_t elem); + bool SetBinEntry(uint8_t *content, int lgth, + uint16_t group, uint16_t elem); + + ValEntry *InsertValEntry(std::string const &content, + uint16_t group, uint16_t elem); + BinEntry *InsertBinEntry(uint8_t *binArea, int lgth, + uint16_t group, uint16_t elem); + SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem); + /// Accessor to \ref File File *GetFile() { return FileInternal; } @@ -86,15 +99,6 @@ public: bool WriteAcr (std::string const &fileName); bool Write (std::string const &fileName); - bool SetEntryValue(std::string const &content, - uint16_t group, uint16_t elem); - bool SetEntryBinArea(uint8_t *content, int lgth, - uint16_t group, uint16_t elem); - bool Insert(std::string const &content, - uint16_t group, uint16_t elem); - bool Insert(uint8_t *binArea, int lgth, - uint16_t group, uint16_t elem); - uint8_t* GetLutRGBA(); // Write mode diff --git a/src/gdcmSQItem.cxx b/src/gdcmSQItem.cxx index 0c1cb641..0431202c 100644 --- a/src/gdcmSQItem.cxx +++ b/src/gdcmSQItem.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSQItem.cxx,v $ Language: C++ - Date: $Date: 2005/01/25 11:11:59 $ - Version: $Revision: 1.59 $ + Date: $Date: 2005/01/25 15:44:24 $ + Version: $Revision: 1.60 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -165,72 +165,6 @@ bool SQItem::AddEntry(DocEntry *entry) return true; } -/** - * \brief Sets Entry (Dicom Element) value of an element, - * specified by it's tag (Group, Number) - * and the length, too ... inside a SQ Item - * If the Element is not found, it's just created ! - * \warning we suppose, right now, the element belongs to a Public Group - * (NOT a shadow one) - * @param val string value to set - * @param group Group number of the searched tag. - * @param elem Element number of the searched tag. - * @return true if element was found or created successfully - */ - -bool SQItem::SetEntryValue(std::string const &val, uint16_t group, - uint16_t elem) -{ - for(ListDocEntry::iterator i = DocEntries.begin(); - i != DocEntries.end(); - ++i) - { - if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0xe000 ) - { - continue; - } - - if ( ( group < (*i)->GetGroup() ) - ||( group == (*i)->GetGroup() && elem < (*i)->GetElement()) ) - { - // instead of Insert, that is a method of Document :-( - ValEntry* entry = 0; - TagKey key = DictEntry::TranslateToKey(group, elem); - - // we assume a Public Dictionary *is* loaded - Dict *pubDict = Global::GetDicts()->GetDefaultPubDict(); - // if the invoked (group,elem) doesn't exist inside the Dictionary - // we create a VirtualDictEntry - DictEntry *dictEntry = pubDict->GetEntry(group, elem); - if (dictEntry == NULL) - { - dictEntry = - Global::GetDicts()->NewVirtualDictEntry(group, elem, - "UN", GDCM_UNKNOWN, - GDCM_UNKNOWN); - } - // we assume the constructor didn't fail - entry = new ValEntry(dictEntry); - if (entry) - { - entry->SetValue(val); - } - DocEntries.insert(i,entry); - - return true; - } - if (group == (*i)->GetGroup() && elem == (*i)->GetElement() ) - { - if ( ValEntry *entry = dynamic_cast(*i) ) - { - entry->SetValue(val); - } - return true; - } - } - return false; -} - /** * \brief Clear the std::list from given entry AND delete the entry. * @param entryToRemove Entry to remove AND delete. @@ -305,8 +239,6 @@ DocEntry *SQItem::GetNextEntry() } } -//----------------------------------------------------------------------------- -// Protected /** * \brief Gets a Dicom Element inside a SQ Item Entry * @param group Group number of the Entry @@ -318,94 +250,15 @@ DocEntry *SQItem::GetDocEntry(uint16_t group, uint16_t elem) for(ListDocEntry::iterator i = DocEntries.begin(); i != DocEntries.end(); ++i) { - if ( (*i)->GetGroup() == group && (*i)->GetElement() == elem ) - { + if ( (*i)->GetGroup()==group && (*i)->GetElement()==elem ) return *i; - } } - return 0; -} - -/** - * \brief Gets a Dicom Element inside a SQ Item Entry - * @param group Group number of the Entry - * @param elem Element number of the Entry - * @return Entry whose (group,elem) was passed. 0 if not found - */ -ValEntry* SQItem::GetValEntry(uint16_t group, uint16_t elem) -{ - DocEntry *d = GetDocEntry(group, elem); - if ( ValEntry *e = dynamic_cast(d) ) - return e; - return 0; -} - -/** - * \brief Gets a Dicom Element inside a SQ Item Entry - * @param group Group number of the Entry - * @param elem Element number of the Entry - * @return Entry whose (group,elem) was passed. 0 if not found - */ -BinEntry* SQItem::GetBinEntry(uint16_t group, uint16_t elem) -{ - DocEntry *d = GetDocEntry(group, elem); - if ( BinEntry *e = dynamic_cast(d) ) - return e; - return 0; -} - -/** - * \brief Gets a Dicom Element inside a SQ Item Entry - * @param group Group number of the Entry - * @param elem Element number of the Entry - * @return Entry whose (group,elem) was passed. 0 if not found - */ -SeqEntry* SQItem::GetSeqEntry(uint16_t group, uint16_t elem) -{ - DocEntry *d = GetDocEntry(group, elem); - if ( SeqEntry *e = dynamic_cast(d) ) - return e; - return 0; + return NULL; } +//----------------------------------------------------------------------------- +// Protected -/** - * \brief Get the value of a Dicom Element inside a SQ Item Entry - * \note : meaningfull only if the required entry is NEITHER a SeqEntry - * NOR a BinEntry - * @param group Group number of the Entry - * @param elem Element number of the Entry - * @return 'string value' of the entry whose (group,elem) was passed. - * GDCM_UNFOUND if not found - */ - -std::string SQItem::GetEntryValue(uint16_t group, uint16_t elem) -{ - -/* - DocEntry *e = GetFirstEntry(); - while (e) - { - if ( e->GetGroup() == group && e->GetElement() == elem) - { - - if (ValEntry *ve = dynamic_cast(e)) - return ve->GetValue(); - } - e = GetNextEntry(); - } -*/ - for(ListDocEntry::iterator i = DocEntries.begin(); - i != DocEntries.end(); ++i) - { - if ( (*i)->GetGroup() == group && (*i)->GetElement() == elem) - { - if (ValEntry *ve = dynamic_cast(*i)) - return ve->GetValue(); - } - } - return GDCM_UNFOUND; -} //----------------------------------------------------------------------------- // Private diff --git a/src/gdcmSQItem.h b/src/gdcmSQItem.h index de9fa1f0..23c5586f 100644 --- a/src/gdcmSQItem.h +++ b/src/gdcmSQItem.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSQItem.h,v $ Language: C++ - Date: $Date: 2005/01/25 11:11:59 $ - Version: $Revision: 1.36 $ + Date: $Date: 2005/01/25 15:44:24 $ + Version: $Revision: 1.37 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -46,33 +46,25 @@ public: virtual void Print(std::ostream &os = std::cout, std::string const & indent = "" ); void WriteContent(std::ofstream *fp, FileType filetype); - /// \brief returns the DocEntry chained List for this SQ Item. - ListDocEntry const &GetDocEntries() const { return DocEntries; }; - void ClearEntry(); bool AddEntry(DocEntry *Entry); // add to the List bool RemoveEntry(DocEntry *EntryToRemove); bool RemoveEntryNoDestroy(DocEntry *EntryToRemove); + DocEntry *GetFirstEntry(); + DocEntry *GetNextEntry(); + DocEntry *GetDocEntry(uint16_t group, uint16_t elem); - ValEntry *GetValEntry(uint16_t group, uint16_t elem); - BinEntry *GetBinEntry(uint16_t group, uint16_t elem); - SeqEntry *GetSeqEntry(uint16_t group, uint16_t elem); - - bool SetEntryValue(std::string const &val, uint16_t group, - uint16_t elem); - - std::string GetEntryValue(uint16_t group, uint16_t elem); + + bool IsEmpty() { return DocEntries.empty(); }; /// \brief returns the ordinal position of a given SQItem int GetSQItemNumber() { return SQItemNumber; }; - /// \brief Sets the ordinal position of a given SQItem void SetSQItemNumber(int itemNumber) { SQItemNumber = itemNumber; }; /// \brief Accessor on \ref SQDepthLevel. - int GetDepthLevel() { return SQDepthLevel; } - + int GetDepthLevel() { return SQDepthLevel; } /// \brief Accessor on \ref SQDepthLevel. void SetDepthLevel(int depth) { SQDepthLevel = depth; } @@ -82,23 +74,14 @@ public: /// \brief Accessor on \ref BaseTagKey. BaseTagKey const &GetBaseTagKey() const { return BaseTagKeyNested; } - DocEntry *GetFirstEntry(); - DocEntry *GetNextEntry(); - protected: // Variables that need to be access in subclasses - /// \brief Chained list of (Elementary) Doc Entries ListDocEntry DocEntries; /// Chained list iterator, used to visit the TagHT variable ListDocEntry::iterator ItDocEntries; - /// \brief pointer to the HTable of the Document, - /// (because we don't know it within any DicomDirObject nor any SQItem) - // TagDocEntryHT *PtagHT; - private: - /// \brief Sequences can be nested. This \ref SQDepthLevel represents /// the level of the nesting of instances of this class. /// \ref SQDepthLevel and its \ref SeqEntry::SQDepthLevel diff --git a/vtk/vtkGdcmWriter.cxx b/vtk/vtkGdcmWriter.cxx index 822a7132..1652c3c6 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/24 16:51:01 $ - Version: $Revision: 1.14 $ + Date: $Date: 2005/01/25 15:44:25 $ + Version: $Revision: 1.15 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -26,7 +26,7 @@ #include #include -vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.14 $"); +vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.15 $"); vtkStandardNewMacro(vtkGdcmWriter); //----------------------------------------------------------------------------- @@ -132,29 +132,29 @@ void SetImageInformation(gdcm::FileHelper *file,vtkImageData *image) str.str(""); str << dim[0]; - file->Insert(str.str(),0x0028,0x0011); // Columns + file->InsertValEntry(str.str(),0x0028,0x0011); // Columns str.str(""); str << dim[1]; - file->Insert(str.str(),0x0028,0x0010); // Rows + file->InsertValEntry(str.str(),0x0028,0x0010); // Rows if(dim[2]>1) { str.str(""); str << dim[2]; //file->Insert(str.str(),0x0028,0x0012); // Planes - file->Insert(str.str(),0x0028,0x0008); // Number of Frames + file->InsertValEntry(str.str(),0x0028,0x0008); // Number of Frames } // Pixel type str.str(""); str << image->GetScalarSize()*8; - file->Insert(str.str(),0x0028,0x0100); // Bits Allocated - file->Insert(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->Insert(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 +171,39 @@ void SetImageInformation(gdcm::FileHelper *file,vtkImageData *image) { str << "1"; // Signed } - file->Insert(str.str(),0x0028,0x0103); // Pixel Representation + file->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation // Samples per pixel str.str(""); str << image->GetNumberOfScalarComponents(); - file->Insert(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->Insert(str.str(),0x0028,0x0030); // Pixel Spacing + file->InsertValEntry(str.str(),0x0028,0x0030); // Pixel Spacing str.str(""); str << sp[2]; - file->Insert(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->Insert(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->Insert(str.str(),0x0028,0x1051); // Window Width + file->InsertValEntry(str.str(),0x0028,0x1051); // Window Width str.str(""); str << (rng[1]+rng[0])/2.0; - file->Insert(str.str(),0x0028,0x1050); // Window Center + file->InsertValEntry(str.str(),0x0028,0x1050); // Window Center // Pixels unsigned char *data;