X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFileHelper.cxx;h=f0de399a07f43b301377ea4896c74d8080811576;hb=3a9e9df62b3198c4f93d1768074b6be828ac7308;hp=c1e1c31147701558d0549b335447a63606a52924;hpb=fa5cf7cf67a3ea643dae69394ac8df512a4d4d2e;p=gdcm.git diff --git a/src/gdcmFileHelper.cxx b/src/gdcmFileHelper.cxx index c1e1c311..f0de399a 100644 --- a/src/gdcmFileHelper.cxx +++ b/src/gdcmFileHelper.cxx @@ -4,8 +4,8 @@ Module: $RCSfile: gdcmFileHelper.cxx,v $ Language: C++ - Date: $Date: 2005/03/04 09:45:04 $ - Version: $Revision: 1.25 $ + Date: $Date: 2005/04/04 15:15:24 $ + 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 @@ -611,15 +611,22 @@ bool FileHelper::Write(std::string const &fileName) SetWriteFileTypeToImplicitVR(); CheckMandatoryElements(); break; + case Unknown: // should never happen; ExplicitVR is the default value case ExplicitVR: SetWriteFileTypeToExplicitVR(); CheckMandatoryElements(); break; case ACR: case ACR_LIBIDO: + // Just to avoid further trouble if user create a file ex-nihilo, + // wants to write it as an ACR-NEMA file, + // and forget to create any Entry belonging to group 0008 + // (shame on him !) + // We add Recognition Code (RET) + if ( ! FileInternal->GetValEntry(0x0008, 0x0010) ) + FileInternal->InsertValEntry("", 0x0008, 0x0010); SetWriteFileTypeToACR(); break; - default: SetWriteFileTypeToExplicitVR(); CheckMandatoryElements(); } @@ -632,6 +639,7 @@ bool FileHelper::Write(std::string const &fileName) // just before writting ... /// \todo the best trick would be *change* the recognition code /// but pb expected if user deals with, e.g. COMPLEX images + if( WriteType == ACR_LIBIDO ) { SetWriteToLibido(); @@ -660,6 +668,7 @@ bool FileHelper::Write(std::string const &fileName) RestoreWrite(); RestoreWriteFileType(); + RestoreWriteMandatory(); // -------------------------------------------------------------- // Special Patch to allow gdcm to re-write ACR-LibIDO formated images @@ -943,17 +952,6 @@ void FileHelper::SetWriteFileTypeToImplicitVR() */ void FileHelper::RestoreWriteFileType() { - // group 0002 may be pushed out for ACR-NEMA writting purposes - Archive->Restore(0x0002,0x0000); - Archive->Restore(0x0002,0x0001); - Archive->Restore(0x0002,0x0002); - Archive->Restore(0x0002,0x0003); - Archive->Restore(0x0002,0x0010); - Archive->Restore(0x0002,0x0012); - Archive->Restore(0x0002,0x0013); - Archive->Restore(0x0002,0x0016); - Archive->Restore(0x0002,0x0100); - Archive->Restore(0x0002,0x0102); } /** @@ -1014,6 +1012,12 @@ void FileHelper::RestoreWriteOfLibido() Archive->Restore(0x0028,0x0010); Archive->Restore(0x0028,0x0011); Archive->Restore(0x0008,0x0010); + + // Restore 'LibIDO-special' entries, if any + Archive->Restore(0x0028,0x0015); + Archive->Restore(0x0028,0x0016); + Archive->Restore(0x0028,0x0017); + Archive->Restore(0x0028,0x00199); } /** @@ -1054,7 +1058,7 @@ BinEntry *FileHelper::CopyBinEntry(uint16_t group, uint16_t elem, DocEntry *oldE = FileInternal->GetDocEntry(group, elem); BinEntry *newE; - if( oldE ) + if( oldE ) if( oldE->GetVR()!=vr ) oldE = NULL; @@ -1115,7 +1119,6 @@ void FileHelper::CheckMandatoryElements() // Create them if not found // Always modify the value // Push the entries to the archive. - ValEntry *e_0002_0000 = CopyValEntry(0x0002,0x0000); e_0002_0000->SetValue("0"); // for the moment Archive->Push(e_0002_0000); @@ -1124,6 +1127,7 @@ void FileHelper::CheckMandatoryElements() e_0002_0001->SetBinArea((uint8_t*)Util::GetFileMetaInformationVersion(), false); e_0002_0001->SetLength(2); + Archive->Push(e_0002_0001); ValEntry *e_0002_0002 = CopyValEntry(0x0002,0x0002); // [Secondary Capture Image Storage] @@ -1135,11 +1139,6 @@ void FileHelper::CheckMandatoryElements() e_0002_0003->SetValue(Util::CreateUniqueUID()); Archive->Push(e_0002_0003); - ValEntry *e_0002_0010 = CopyValEntry(0x0002,0x0010); - //[Explicit VR - Little Endian] - e_0002_0010->SetValue("1.2.840.10008.1.2.1"); - Archive->Push(e_0002_0010); - // 'Implementation Class UID' ValEntry *e_0002_0012 = CopyValEntry(0x0002,0x0012); e_0002_0012->SetValue(Util::CreateUniqueUID()); @@ -1308,17 +1307,7 @@ void FileHelper::CheckMandatoryElements() Archive->Push(e_0010_0010); } - // Patient's ID : if missing, we set it to 'GDCM_Patient_ID' - ValEntry *e_0010_0020 = FileInternal->GetValEntry(0x0010, 0x0020); - if ( !e_0010_0020 ) - { - e_0010_0020 = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0010, 0x0020) ); - e_0010_0020->SetValue("GDCM_Patient_ID"); - Archive->Push(e_0010_0020); - } - - // Patient's Birth Date :'type 2' entry -> must exist, value not mandatory + // Patient's Birth Date : 'type 2' entry -> must exist, value not mandatory ValEntry *e_0010_0030 = FileInternal->GetValEntry(0x0010, 0x0030); if ( !e_0010_0030 ) { @@ -1360,6 +1349,23 @@ void FileHelper::CheckMandatoryElements() } } +/** + * \brief Restore in the File the initial group 0002 + */ +void FileHelper::RestoreWriteMandatory() +{ + // group 0002 may be pushed out for ACR-NEMA writting purposes + Archive->Restore(0x0002,0x0000); + Archive->Restore(0x0002,0x0001); + Archive->Restore(0x0002,0x0002); + Archive->Restore(0x0002,0x0003); + Archive->Restore(0x0002,0x0012); + Archive->Restore(0x0002,0x0013); + Archive->Restore(0x0002,0x0016); + Archive->Restore(0x0002,0x0100); + Archive->Restore(0x0002,0x0102); +} + //----------------------------------------------------------------------------- // Private /**