Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2004/07/14 14:08:05 $
- Version: $Revision: 1.48 $
+ Date: $Date: 2004/07/16 15:18:05 $
+ Version: $Revision: 1.49 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
bool exception_on_error,
bool enable_sequences,
bool ignore_shadow)
- : gdcmElementSet(-1) {
- IgnoreShadow =ignore_shadow;
+ : gdcmElementSet(-1)
+{
+ IgnoreShadow = ignore_shadow;
//enableSequences=enable_sequences;
(void)enable_sequences;
- enableSequences=true; // JPR // TODO : remove params out of the constructor
+ enableSequences = true; // JPR // TODO : remove params out of the constructor
SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE);
Filename = inFilename;
Initialise();
// Load 'non string' values
std::string PhotometricInterpretation = GetEntryByNumber(0x0028,0x0004);
- if( PhotometricInterpretation == "PALETTE COLOR " ) {
+ if( PhotometricInterpretation == "PALETTE COLOR " )
+ {
LoadEntryVoidArea(0x0028,0x1200); // gray LUT
LoadEntryVoidArea(0x0028,0x1201); // R LUT
LoadEntryVoidArea(0x0028,0x1202); // G LUT
RefShaDict = NULL;
// Recursive clean up of sequences
- for (TagDocEntryHT::iterator it = tagHT.begin(); it != tagHT.end(); ++it )
+ for (TagDocEntryHT::const_iterator it = tagHT.begin();
+ it != tagHT.end(); ++it )
{
- delete it->second;
+ delete it->second;
}
tagHT.clear();
}
*/
bool gdcmDocument::SetShaDict(gdcmDict *dict)
{
- RefShaDict=dict;
+ RefShaDict = dict;
return !RefShaDict;
}
*/
bool gdcmDocument::SetShaDict(DictKey dictName)
{
- RefShaDict=gdcmGlobal::GetDicts()->GetDict(dictName);
+ RefShaDict = gdcmGlobal::GetDicts()->GetDict(dictName);
return !RefShaDict;
}
* @return true when gdcmDocument is the one of a reasonable Dicom/Acr file,
* false otherwise.
*/
-bool gdcmDocument::IsReadable() {
-
- if(Filetype==gdcmUnknown) {
+bool gdcmDocument::IsReadable()
+{
+ if( Filetype == gdcmUnknown)
+ {
std::cout << " gdcmDocument::IsReadable: Filetype " << Filetype
<< " " << "gdcmUnknown " << gdcmUnknown << std::endl; //JPR
dbg.Verbose(0, "gdcmDocument::IsReadable: wrong filetype");
return false;
}
- if(tagHT.empty()) {
+ if(tagHT.empty())
+ {
dbg.Verbose(0, "gdcmDocument::IsReadable: no tags in internal"
" hash table.");
return false;
}
- return(true);
+ return true;
}
* the current document. False either when the document contains
* no Transfer Syntax, or when the Tranfer Syntaxes don't match.
*/
-bool gdcmDocument::IsGivenTransferSyntax(const std::string & SyntaxToCheck)
+bool gdcmDocument::IsGivenTransferSyntax(std::string const & syntaxToCheck)
{
- gdcmDocEntry *Entry = GetDocEntryByNumber(0x0002, 0x0010);
- if ( !Entry )
+ gdcmDocEntry *entry = GetDocEntryByNumber(0x0002, 0x0010);
+ if ( !entry )
+ {
return false;
+ }
// The entry might be present but not loaded (parsing and loading
// happen at differente stages): try loading and proceed with check...
- LoadDocEntrySafe(Entry);
- if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(Entry) )
+ LoadDocEntrySafe(entry);
+ if (gdcmValEntry* valEntry = dynamic_cast< gdcmValEntry* >(entry) )
{
- std::string Transfer = ValEntry->GetValue();
+ std::string transfer = valEntry->GetValue();
+
// The actual transfer (as read from disk) might be padded. We
// first need to remove the potential padding. We can make the
// weak assumption that padding was not executed with digits...
- while ( ! isdigit(Transfer[Transfer.length()-1]) )
+ while ( ! isdigit(transfer[transfer.length()-1]) )
{
- Transfer.erase(Transfer.length()-1, 1);
+ transfer.erase(transfer.length()-1, 1);
}
- if ( Transfer == SyntaxToCheck )
+ if ( transfer == syntaxToCheck )
+ {
return true;
+ }
}
return false;
}
// Anyway, it's to late check if the 'Preamble' was found ...
// And ... would it be a rich idea to check ?
// (some 'no Preamble' DICOM images exist !)
- return (GetDocEntryByNumber(0x0002, 0x0010) != NULL);
+ return GetDocEntryByNumber(0x0002, 0x0010) != NULL;
}
/**
FILE *gdcmDocument::OpenFile(bool exception_on_error)
throw(gdcmFileError)
{
- fp=fopen(Filename.c_str(),"rb");
+ fp = fopen(Filename.c_str(),"rb");
if(!fp)
{
- if(exception_on_error)
+ if(exception_on_error)
+ {
throw gdcmFileError("gdcmDocument::gdcmDocument(const char *, bool)");
+ }
else
{
dbg.Verbose(0, "gdcmDocument::OpenFile cannot open file: ",
//ACR -- or DICOM with no Preamble --
if( zero == 0x0008 || zero == 0x0800 || zero == 0x0002 || zero == 0x0200)
+ {
return fp;
+ }
//DICOM
fseek(fp, 126L, SEEK_CUR);
char dicm[4];
fread(dicm, (size_t)4, (size_t)1, fp);
if( memcmp(dicm, "DICM", 4) == 0 )
+ {
return fp;
+ }
fclose(fp);
dbg.Verbose(0, "gdcmDocument::OpenFile not DICOM/ACR", Filename.c_str());
}
- else {
+ else
+ {
dbg.Verbose(0, "gdcmDocument::OpenFile cannot open file", Filename.c_str());
}
- return NULL;
+
+ return 0;
}
/**
{
int closed = fclose(fp);
fp = (FILE *)0;
- if (! closed)
- return false;
- return true;
+
+ return closed;
}
/**
*/
void gdcmDocument::Write(FILE* fp,FileType filetype)
{
-
/// \todo move the following lines (and a lot of others, to be written)
/// to a future function CheckAndCorrectHeader
*/
gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
- std::string Value,
- uint16_t Group,
- uint16_t Elem )
+ std::string value,
+ uint16_t group,
+ uint16_t elem )
{
- gdcmDocEntry* CurrentEntry;
- gdcmValEntry* ValEntry;
+ gdcmValEntry* valEntry;
- CurrentEntry = GetDocEntryByNumber( Group, Elem);
- if (!CurrentEntry)
+ gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem);
+ if (!currentEntry)
{
// The entry wasn't present and we simply create the required ValEntry:
- CurrentEntry = NewDocEntryByNumber(Group, Elem);
- if (!CurrentEntry)
+ currentEntry = NewDocEntryByNumber(group, elem);
+ if (!currentEntry)
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to"
" NewDocEntryByNumber failed.");
return NULL;
}
- ValEntry = new gdcmValEntry(CurrentEntry);
- if ( !AddEntry(ValEntry))
+ valEntry = new gdcmValEntry(currentEntry);
+ if ( !AddEntry(valEntry))
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry"
" failed allthough this is a creation.");
}
else
{
- ValEntry = dynamic_cast< gdcmValEntry* >(CurrentEntry);
- if ( !ValEntry )
+ valEntry = dynamic_cast< gdcmValEntry* >(currentEntry);
+ if ( !valEntry )
{
// We need to promote the gdcmDocEntry to a gdcmValEntry:
- ValEntry = new gdcmValEntry(CurrentEntry);
- if (!RemoveEntry(CurrentEntry))
+ valEntry = new gdcmValEntry(currentEntry);
+ if (!RemoveEntry(currentEntry))
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal"
" of previous DocEntry failed.");
return NULL;
}
- if ( !AddEntry(ValEntry))
+ if ( !AddEntry(valEntry))
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding"
" promoted ValEntry failed.");
}
}
- SetEntryByNumber(Value, Group, Elem);
+ SetEntryByNumber(value, group, elem);
- return ValEntry;
+ return valEntry;
}
/*
gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber(
void *voidArea,
int lgth,
- uint16_t Group,
- uint16_t Elem)
+ uint16_t group,
+ uint16_t elem)
{
- gdcmDocEntry* a;
gdcmBinEntry* b = 0;
- a = GetDocEntryByNumber( Group, Elem);
- if (a == NULL) {
- a =NewBinEntryByNumber(Group, Elem);
- if (a == NULL)
- return NULL;
+ gdcmDocEntry* a = GetDocEntryByNumber( group, elem);
+ if (!a)
+ {
+ a = NewBinEntryByNumber(group, elem);
+ if (!a)
+ {
+ return 0;
+ }
b = new gdcmBinEntry(a);
AddEntry(b);
+ b->SetVoidArea(voidArea);
}
- SetEntryByNumber(voidArea, lgth, Group, Elem);
- b->SetVoidArea(voidArea);
+ SetEntryByNumber(voidArea, lgth, group, elem);
+ //b->SetVoidArea(voidArea); //what if b == 0 !!
return b;
}
* @param Elem element number of the Entry
* \return boolean
*/
-bool gdcmDocument::ReplaceIfExistByNumber(char* Value, uint16_t Group,
- uint16_t Elem )
+bool gdcmDocument::ReplaceIfExistByNumber(const char* value, uint16_t group,
+ uint16_t elem )
{
- std::string v = Value;
- SetEntryByNumber(v, Group, Elem);
+ std::string v = value;
+ SetEntryByNumber(v, group, elem);
return true;
}
std::string gdcmDocument::GetEntryByName(TagName tagName)
{
gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName);
- if( dictEntry == NULL)
+ if( !dictEntry )
+ {
return GDCM_UNFOUND;
+ }
return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
}
Program: gdcm
Module: $RCSfile: gdcmDocument.h,v $
Language: C++
- Date: $Date: 2004/07/02 13:55:27 $
- Version: $Revision: 1.21 $
+ Date: $Date: 2004/07/16 15:18:05 $
+ 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
FILE* OpenFile(bool exception_on_error = false) throw(gdcmFileError);
bool CloseFile();
- void Write(FILE* fp,FileType type);
+ void Write(FILE* fp, FileType type);
- gdcmValEntry* ReplaceOrCreateByNumber(std::string Value,
- uint16_t Group, uint16_t Elem);
+ gdcmValEntry* ReplaceOrCreateByNumber(std::string value,
+ uint16_t group, uint16_t elem);
gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth,
- uint16_t Group, uint16_t Elem);
- bool ReplaceIfExistByNumber (char* Value, uint16_t Group, uint16_t Elem);
+ uint16_t group, uint16_t elem);
+ bool ReplaceIfExistByNumber (const char* value, uint16_t group, uint16_t elem);
virtual void* LoadEntryVoidArea(uint16_t Group, uint16_t Element);
virtual void* LoadEntryVoidArea(gdcmBinEntry*);
void SetPrintLevel(int level) { printLevel = level; }
/// Accessor to \ref Filename
- std::string &GetFileName() { return Filename; }
+ const std::string &GetFileName() { return Filename; }
/// Accessor to \ref Filename
- void SetFileName(const char* fileName) { Filename = fileName; }
+ void SetFileName(std::string const & fileName) { Filename = fileName; }
/// Accessor to \ref gdcmElementSet::tagHT
TagDocEntryHT &GetEntry() { return tagHT; };
Program: gdcm
Module: $RCSfile: gdcmFile.cxx,v $
Language: C++
- Date: $Date: 2004/07/02 13:55:28 $
- Version: $Revision: 1.115 $
+ Date: $Date: 2004/07/16 15:18:05 $
+ Version: $Revision: 1.116 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
// from Lut R + Lut G + Lut B
uint8_t *newDest = new uint8_t[ImageDataSize];
uint8_t *a = (uint8_t *)destination;
- uint8_t *lutRGBA = Header->GetLUTRGBA();
+ uint8_t *lutRGBA = Header->GetLUTRGBA();
if ( lutRGBA )
{
std::string spp = "3"; // Samples Per Pixel
Header->SetEntryByNumber(spp,0x0028,0x0002);
- std::string rgb= "RGB "; // Photometric Interpretation
+ std::string rgb = "RGB "; // Photometric Interpretation
Header->SetEntryByNumber(rgb,0x0028,0x0004);
std::string planConfig = "0"; // Planar Configuration
Header->SetEntryByNumber(planConfig,0x0028,0x0006);
if ( Header->HasLUT() )
{
/// \todo Let gdcmHeader user a chance to get the right value
- // ImageDataSize /= 3; //dangerous
imgDataSize = ImageDataSizeRaw;
}
bool gdcmFile::WriteRawData(std::string const & fileName)
{
- FILE *fp1;
- fp1 = fopen(fileName.c_str(), "wb");
+ FILE *fp1 = fopen(fileName.c_str(), "wb");
if (fp1 == NULL)
{
printf("Fail to open (write) file [%s] \n", fileName.c_str());
return false;
}
- fwrite (PixelData,ImageDataSize, 1, fp1);
+ fwrite (PixelData, ImageDataSize, 1, fp1);
fclose (fp1);
return true;
*/
bool gdcmFile::WriteBase (std::string const & fileName, FileType type)
{
- FILE *fp1;
-
if ( PixelRead == -1 && type != gdcmExplicitVR)
{
return false;
}
- fp1 = fopen(fileName.c_str(), "wb");
+ FILE *fp1 = fopen(fileName.c_str(), "wb");
if (fp1 == NULL)
{
printf("Failed to open (write) File [%s] \n", fileName.c_str());
uint16_t grPixel = Header->GetGrPixel();
uint16_t numPixel = Header->GetNumPixel();;
- gdcmDocEntry* PixelElement;
-
- PixelElement = GetHeader()->GetDocEntryByNumber(grPixel, numPixel);
+ gdcmDocEntry* PixelElement =
+ GetHeader()->GetDocEntryByNumber(grPixel, numPixel);
if ( PixelRead == 1 )
{
// ---------------------- Run Length Encoding
if ( Header->IsRLELossLessTransferSyntax() )
{
- bool res = (bool)gdcm_read_RLE_file (fp,destination);
+ bool res = gdcm_read_RLE_file (fp,destination);
Header->CloseFile();
return res;
}
Program: gdcm
Module: $RCSfile: gdcmFile.h,v $
Language: C++
- Date: $Date: 2004/07/02 13:55:28 $
- Version: $Revision: 1.37 $
+ Date: $Date: 2004/07/16 15:18:05 $
+ 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
size_t GetImageDataSizeRaw();
void * GetImageData();
- size_t GetImageDataIntoVector(void* destination, size_t MaxSize);
+ size_t GetImageDataIntoVector(void* destination, size_t maxSize);
void * GetImageDataRaw();
- size_t GetImageDataIntoVectorRaw(void* destination, size_t MaxSize);
+ size_t GetImageDataIntoVectorRaw(void* destination, size_t maxSize);
// Allocates ExpectedSize bytes of memory at this->Data and copies the
// pointed data to it. Copying the image might look useless but
// e.g. VTK) before calling the Write
// voir gdcmHeader::SetImageDataSize ?!?
- bool SetImageData (void * Data, size_t ExpectedSize);
+ bool SetImageData (void * data, size_t expectedSize);
/// \todo When the caller is aware we simply point to the data:
/// int SetImageDataNoCopy (void * Data, size_t ExpectedSize);
virtual bool SetEntryByNumber(std::string const & content,
uint16_t group, uint16_t element)
{
- GetHeader()->SetEntryByNumber(content,group,element);
- return true; /// \todo default behavior ?
+ Header->SetEntryByNumber(content,group,element);
+ return true;
}
protected:
- bool WriteBase(std::string const & FileName, FileType type);
+ bool WriteBase(std::string const & fileName, FileType type);
private:
void SwapZone(void* im, int swap, int lgr, int nb);
bool ReadPixelData(void * destination);
// For JPEG 8 Bits, body in file gdcmJpeg.cxx
- bool gdcm_read_JPEG_file (FILE *fp,void * image_buffer);
+ bool gdcm_read_JPEG_file (FILE *fp, void * image_buffer);
static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode,
- long uncompressedSegmentSize,FILE *fp);
+ long uncompressedSegmentSize, FILE *fp);
// For JPEG 12 Bits, body in file gdcmJpeg12.cxx
- bool gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer);
+ bool gdcm_read_JPEG_file12 (FILE *fp, void* image_buffer);
// For JPEG 2000, body in file gdcmJpeg2000.cxx
- bool gdcm_read_JPEG2000_file (FILE *fp,void * image_buffer);
+ bool gdcm_read_JPEG2000_file (FILE *fp, void* image_buffer);
// For Run Length Encoding (TOCHECK)
- bool gdcm_read_RLE_file (FILE *fp,void * image_buffer);
+ bool gdcm_read_RLE_file (FILE *fp, void* image_buffer);
// Variables