+2004-11-25 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+ * src/gdcmDocument.[h|cxx] : set the Transfert Syntax values to the header
+ file, to be accessed by other files (like gdcmFile). Remove commented
+ code. Move the change of the header to the gdcmFile, using the
+ DocEntryArchive
+ * src/gdcmHeader.[h|cxx] : the write is completely made in the Header.
+ To be sure of that (and simplify calls), the Write of the header now
+ gets a file name and not a file pointer (std::ifstream).
+ * src/gdcmFile.[h|cxx] : apply the write file type to the header, using the
+ DocEntryArchive. Remove all open of the written file
+
2004-11-25 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
* vtk/vtkGdcmReader.cxx : compilation bug fix for the vtk part
Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2004/11/25 10:24:34 $
- Version: $Revision: 1.138 $
+ Date: $Date: 2004/11/25 13:12:02 $
+ Version: $Revision: 1.139 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
namespace gdcm
{
-static const char *TransferSyntaxStrings[] = {
- // Implicit VR Little Endian
- "1.2.840.10008.1.2",
- // Implicit VR Little Endian DLX G.E?
- "1.2.840.113619.5.2",
- // Explicit VR Little Endian
- "1.2.840.10008.1.2.1",
- // Deflated Explicit VR Little Endian
- "1.2.840.10008.1.2.1.99",
- // Explicit VR Big Endian
- "1.2.840.10008.1.2.2",
- // JPEG Baseline (Process 1)
- "1.2.840.10008.1.2.4.50",
- // JPEG Extended (Process 2 & 4)
- "1.2.840.10008.1.2.4.51",
- // JPEG Extended (Process 3 & 5)
- "1.2.840.10008.1.2.4.52",
- // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
- "1.2.840.10008.1.2.4.53",
- // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
- "1.2.840.10008.1.2.4.55",
- // JPEG Lossless, Non-Hierarchical (Process 14)
- "1.2.840.10008.1.2.4.57",
- // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14, [Selection Value 1])
- "1.2.840.10008.1.2.4.70",
- // JPEG 2000 Lossless
- "1.2.840.10008.1.2.4.90",
- // JPEG 2000
- "1.2.840.10008.1.2.4.91",
- // RLE Lossless
- "1.2.840.10008.1.2.5",
- // Unknown
- "Unknown Transfer Syntax"
-};
-
//-----------------------------------------------------------------------------
// Refer to Document::CheckSwap()
const unsigned int Document::HEADER_LENGTH_TO_READ = 256;
fp->write("DICM", 4);
}
- if (filetype == ImplicitVR)
- {
- std::string ts =
- Util::DicomString( TransferSyntaxStrings[ImplicitVRLittleEndian] );
- ReplaceOrCreateByNumber(ts, 0x0002, 0x0010);
-
- /// \todo Refer to standards on page 21, chapter 6.2
- /// "Value representation": values with a VR of UI shall be
- /// padded with a single trailing null
- /// in the following case we have to padd manually with a 0
-
- SetEntryLengthByNumber(18, 0x0002, 0x0010);
- }
-
- if (filetype == ExplicitVR)
- {
- std::string ts =
- Util::DicomString( TransferSyntaxStrings[ExplicitVRLittleEndian] );
- ReplaceOrCreateByNumber(ts, 0x0002, 0x0010); //LEAK
-
- /// \todo Refer to standards on page 21, chapter 6.2
- /// "Value representation": values with a VR of UI shall be
- /// padded with a single trailing null
- /// Dans le cas suivant on doit pader manuellement avec un 0
-
- SetEntryLengthByNumber(20, 0x0002, 0x0010);
- }
-
/**
* \todo rewrite later, if really usefull
* - 'Group Length' element is optional in DICOM
*/
ElementSet::Write(fp, filetype); // This one is recursive
-
}
/**
}
//////////////////// BinEntry or UNKOWN VR:
-/* BinEntry* newBinEntry =
- new BinEntry( newDocEntry->GetDictEntry() ); //LEAK
- newBinEntry->Copy( newDocEntry );*/
BinEntry* newBinEntry = new BinEntry( newDocEntry ); //LEAK
// When "this" is a Document the Key is simply of the
// representation of a 32 bits integer. Hence the following dirty
// trick :
s32 = *((uint32_t *)(entCur));
-
+
switch( s32 )
{
case 0x00040000 :
Program: gdcm
Module: $RCSfile: gdcmDocument.h,v $
Language: C++
- Date: $Date: 2004/11/24 11:17:47 $
- Version: $Revision: 1.62 $
+ Date: $Date: 2004/11/25 13:12:02 $
+ Version: $Revision: 1.63 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
UnknownTS
};
+static const char *TransferSyntaxStrings[] = {
+ // Implicit VR Little Endian
+ "1.2.840.10008.1.2",
+ // Implicit VR Little Endian DLX G.E?
+ "1.2.840.113619.5.2",
+ // Explicit VR Little Endian
+ "1.2.840.10008.1.2.1",
+ // Deflated Explicit VR Little Endian
+ "1.2.840.10008.1.2.1.99",
+ // Explicit VR Big Endian
+ "1.2.840.10008.1.2.2",
+ // JPEG Baseline (Process 1)
+ "1.2.840.10008.1.2.4.50",
+ // JPEG Extended (Process 2 & 4)
+ "1.2.840.10008.1.2.4.51",
+ // JPEG Extended (Process 3 & 5)
+ "1.2.840.10008.1.2.4.52",
+ // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
+ "1.2.840.10008.1.2.4.53",
+ // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
+ "1.2.840.10008.1.2.4.55",
+ // JPEG Lossless, Non-Hierarchical (Process 14)
+ "1.2.840.10008.1.2.4.57",
+ // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14, [Selection Value 1])
+ "1.2.840.10008.1.2.4.70",
+ // JPEG 2000 Lossless
+ "1.2.840.10008.1.2.4.90",
+ // JPEG 2000
+ "1.2.840.10008.1.2.4.91",
+ // RLE Lossless
+ "1.2.840.10008.1.2.5",
+ // Unknown
+ "Unknown Transfer Syntax"
+};
+
//-----------------------------------------------------------------------------
/**
* \brief Derived by both Header and DicomDir
Program: gdcm
Module: $RCSfile: gdcmFile.cxx,v $
Language: C++
- Date: $Date: 2004/11/25 10:24:34 $
- Version: $Revision: 1.163 $
+ Date: $Date: 2004/11/25 13:12:02 $
+ Version: $Revision: 1.164 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
=========================================================================*/
#include "gdcmFile.h"
+#include "gdcmDocument.h"
#include "gdcmDebug.h"
#include "gdcmUtil.h"
#include "gdcmBinEntry.h"
*/
bool File::WriteBase (std::string const & fileName, FileType type)
{
- std::ofstream* fp1 = new std::ofstream(fileName.c_str(),
- std::ios::out | std::ios::binary);
- if (fp1 == NULL)
+ switch(type)
{
- dbg.Verbose(2, "Failed to open (write) File: " , fileName.c_str());
- return false;
+ case ImplicitVR:
+ SetWriteFileTypeToImplicitVR();
+ break;
+ case ExplicitVR:
+ SetWriteFileTypeToExplicitVR();
+ break;
+ case ACR:
+ SetWriteFileTypeToACR();
+ break;
+ case ACR_LIBIDO:
+ SetWriteFileTypeToACRLibido();
+ break;
}
-
+
switch(WriteMode)
{
case WMODE_NATIVE :
}*/
// ----------------- End of Special Patch ----------------
- bool check=CheckWriteIntegrity();
+ bool check = CheckWriteIntegrity();
if(check)
{
- HeaderInternal->Write(fp1,type);
+ check = HeaderInternal->Write(fileName,type);
}
// --------------------------------------------------------------
// ----------------- End of Special Patch ----------------
RestoreWrite();
-
- fp1->close();
- delete fp1;
+ RestoreWriteFileType();
return check;
}
{
if(Pixel_Data)
{
+ int numberBitsAllocated = HeaderInternal->GetBitsAllocated();
+ if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
+ {
+ numberBitsAllocated = 16;
+ }
+
+ int decSize = HeaderInternal->GetXSize()
+ * HeaderInternal->GetYSize()
+ * HeaderInternal->GetZSize()
+ * ( numberBitsAllocated / 8 )
+ * HeaderInternal->GetSamplesPerPixel();
+ int rgbSize = decSize;
+ if( HeaderInternal->HasLUT() )
+ rgbSize = decSize * 3;
+
switch(WriteMode)
{
case WMODE_NATIVE :
break;
case WMODE_DECOMPRESSED :
- if(GetImageDataRawSize()!=ImageDataSize)
+ if( decSize!=ImageDataSize )
{
- std::cerr<<"RAW : "<<GetImageDataRawSize()<<" / "<<ImageDataSize<<std::endl;
+ dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect");
+ //std::cerr<<"Dec : "<<decSize<<" | "<<ImageDataSize<<std::endl;
return false;
}
break;
case WMODE_RGB :
- if(GetImageDataSize()!=ImageDataSize)
+ if( rgbSize!=ImageDataSize )
{
- std::cerr<<"RGB : "<<GetImageDataSize()<<" / "<<ImageDataSize<<std::endl;
+ dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect");
+ //std::cerr<<"RGB : "<<decSize<<" | "<<ImageDataSize<<std::endl;
return false;
}
break;
Archive->Restore(0x0028,0x1203);
}
+void File::SetWriteFileTypeToACR()
+{
+ Archive->Push(0x0002,0x0010);
+}
+
+void File::SetWriteFileTypeToACRLibido()
+{
+ SetWriteFileTypeToACR();
+}
+
+void File::SetWriteFileTypeToExplicitVR()
+{
+ std::string ts =
+ Util::DicomString( TransferSyntaxStrings[ExplicitVRLittleEndian] );
+
+ ValEntry* tss = CopyValEntry(0x0002,0x0010);
+ tss->SetValue(ts);
+ tss->SetLength(ts.length());
+
+ Archive->Push(tss);
+}
+
+void File::SetWriteFileTypeToImplicitVR()
+{
+ std::string ts =
+ Util::DicomString( TransferSyntaxStrings[ImplicitVRLittleEndian] );
+
+ ValEntry* tss = CopyValEntry(0x0002,0x0010);
+ tss->SetValue(ts);
+ tss->SetLength(ts.length());
+}
+
+void File::RestoreWriteFileType()
+{
+ Archive->Restore(0x0002,0x0010);
+}
+
void File::SetWriteToLibido()
{
ValEntry *oldRow = dynamic_cast<ValEntry *>(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0010));
Program: gdcm
Module: $RCSfile: gdcmFile.h,v $
Language: C++
- Date: $Date: 2004/11/25 10:24:34 $
- Version: $Revision: 1.76 $
+ Date: $Date: 2004/11/25 13:12:02 $
+ Version: $Revision: 1.77 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
void SetWriteToRGB();
void RestoreWrite();
+ void SetWriteFileTypeToACR();
+ void SetWriteFileTypeToACRLibido();
+ void SetWriteFileTypeToExplicitVR();
+ void SetWriteFileTypeToImplicitVR();
+ void RestoreWriteFileType();
+
void SetWriteToLibido();
void RestoreWriteFromLibido();
void SetPixelData(uint8_t* data);
private:
-
// members variables:
/// Header to use to load the file
Program: gdcm
Module: $RCSfile: gdcmHeader.cxx,v $
Language: C++
- Date: $Date: 2004/11/23 17:12:25 $
- Version: $Revision: 1.205 $
+ Date: $Date: 2004/11/25 13:12:02 $
+ Version: $Revision: 1.206 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* @param filetype Type of the File to be written
* (ACR-NEMA, ExplicitVR, ImplicitVR)
*/
-void Header::Write(std::ofstream* fp,FileType filetype)
+bool Header::Write(std::string fileName,FileType filetype)
{
+ std::ofstream* fp = new std::ofstream(fileName.c_str(),
+ std::ios::out | std::ios::binary);
+ if (fp == NULL)
+ {
+ dbg.Verbose(2, "Failed to open (write) File: " , fileName.c_str());
+ return false;
+ }
+
// Bits Allocated
if ( GetEntryByNumber(0x0028,0x0100) == "12")
{
}
}
Document::Write(fp,filetype);
+
+ fp->close();
+ delete fp;
+
+ return true;
}
//-----------------------------------------------------------------------------
Program: gdcm
Module: $RCSfile: gdcmHeader.h,v $
Language: C++
- Date: $Date: 2004/11/16 05:03:35 $
- Version: $Revision: 1.93 $
+ Date: $Date: 2004/11/25 13:12:02 $
+ Version: $Revision: 1.94 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
/// Read (used in File)
void SetImageDataSize(size_t expectedSize);
- void Write(std::ofstream* fp, FileType filetype);
+ bool Write(std::string fileName, FileType filetype);
/// Initialize DICOM header when none
void InitializeDefaultHeader();