+2004-11-19 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+ * src/gdcmDocEntry.cxx : remove the copy of the DictEntry... there isn't
+ correct to copy it. The DictEntry is specified at the DocEntry creation,
+ then, it musn't change in the time.
+ * src/gdcmDocEntryArchive.[h|cxx] : new class. It's goal is to change the
+ header correctly. At this time, the change is only made for the first
+ level of the Document. In the future, it might consider sequences.
+ The change is made by replacing a DocEntry by an other that is created
+ outside the class. The old value is kept. When we restore the header
+ status, the added DocEntry is deleted and replaced by the old value.
+ * src/gdcmElementSet.h : Set the DocEntryArchive like friend.
+ * src/gdcmFile.[h|cxx] : Use the gdcmDocEntryArchive. Add methods to
+ set the write type to explicit VR, implicit VR or ACR. Add methods to set
+ the write mode to native, decompressed or RGB (but not used at this time)
+
2004-11-15 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
* src/gdcmSeqEntry.cxx : add initialisation of variable SeqTerm
* src/gdcmDocument.cxx : add delete of DocEntry's to remove some memory leaks
gdcmDictSet.cxx
gdcmDirList.cxx
gdcmDocEntry.cxx
+ gdcmDocEntryArchive.cxx
gdcmDocEntrySet.cxx
gdcmDocument.cxx
gdcmElementSet.cxx
Program: gdcm
Module: $RCSfile: gdcmDocEntry.cxx,v $
Language: C++
- Date: $Date: 2004/11/10 18:27:23 $
- Version: $Revision: 1.31 $
+ Date: $Date: 2004/11/19 18:49:39 $
+ 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
*/
void DocEntry::Copy (DocEntry* e)
{
- DicomDict = e->DicomDict;
+// DicomDict = e->DicomDict;
UsableLength = e->UsableLength;
ReadLength = e->ReadLength;
ImplicitVR = e->ImplicitVR;
--- /dev/null
+/*=========================================================================
+
+ Program: gdcm
+ Module: $RCSfile: gdcmDocEntryArchive.cxx,v $
+ Language: C++
+ Date: $Date: 2004/11/19 18:49:39 $
+ Version: $Revision: 1.1 $
+
+ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+ l'Image). All rights reserved. See Doc/License.txt or
+ http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*/
+
+#include "gdcmDocEntryArchive.h"
+#include "gdcmDebug.h"
+
+#include <string>
+
+namespace gdcm
+{
+//-----------------------------------------------------------------------------
+/**
+ * \brief Constructor
+ */
+DocEntryArchive::DocEntryArchive(Header *header):
+ HeaderHT(header->TagHT)
+{
+}
+
+//-----------------------------------------------------------------------------
+/**
+ * \brief Destructor
+ */
+DocEntryArchive::~DocEntryArchive()
+{
+ ClearArchive();
+}
+
+//-----------------------------------------------------------------------------
+// Print
+/**
+ * \brief Print all
+ * @param os The output stream to be written to.
+ */
+void DocEntryArchive::Print(std::ostream &os)
+{
+}
+
+//-----------------------------------------------------------------------------
+// Public
+/**
+ * \brief Replace in the Header a DocEntry by the new DocEntry. The last
+ * DocEntry is kept in archieve
+ * @param newEntry New entry to substitute to an other entry of the Header
+ * @return FALSE when an other DocEntry is already archieved with the same
+ * generalized key, TRUE otherwise
+ */
+bool DocEntryArchive::Push(DocEntry *newEntry)
+{
+ if(!newEntry)
+ return(false);
+
+ uint16_t gr = newEntry->GetDictEntry()->GetGroup();
+ uint16_t elt = newEntry->GetDictEntry()->GetElement();
+ std::string key = DictEntry::TranslateToKey(gr,elt);
+
+ if( Archive.find(key)==Archive.end() )
+ {
+ // Save the old DocEntry if any
+ TagDocEntryHT::iterator it = HeaderHT.find(key);
+ if( it!=HeaderHT.end() )
+ Archive[key] = it->second;
+ else
+ Archive[key] = NULL;
+
+ // Set the new DocEntry
+ HeaderHT[key] = newEntry;
+
+ return(true);
+ }
+ return(false);
+}
+
+/**
+ * \brief Restore in the Header the DocEntry that have the generalized key.
+ * The old entry is destroyed.
+ * @param key Key of the DocEntry to restore
+ * @return FALSE when the generalized key isn't in the archieve,
+ * TRUE otherwise
+ */
+bool DocEntryArchive::Restore(uint16_t group,uint16_t element)
+{
+ std::string key=DictEntry::TranslateToKey(group,element);
+
+ TagDocEntryHT::iterator restoreIt=Archive.find(key);
+ if( restoreIt!=Archive.end() )
+ {
+ TagDocEntryHT::iterator restorePos = HeaderHT.find(key);
+ if( restoreIt!=HeaderHT.end() )
+ delete restorePos->second;
+
+ if( Archive[key] )
+ HeaderHT[key] = Archive[key];
+ else
+ HeaderHT.erase(restorePos);
+
+ Archive.erase(restoreIt);
+
+ return(true);
+ }
+ return(false);
+}
+
+/**
+ * \brief Remove all DocEntry that are in the archive. The entries aren't
+ * restored but only destroyed.
+ */
+void DocEntryArchive::ClearArchive(void)
+{
+ for(TagDocEntryHT::iterator it = Archive.begin();
+ it!=Archive.end();
+ ++it)
+ {
+ delete it->second;
+ }
+ Archive.clear();
+}
+
+//-----------------------------------------------------------------------------
+// Protected
+
+//-----------------------------------------------------------------------------
+// Private
+
+//-----------------------------------------------------------------------------
+
+} // end namespace gdcm
--- /dev/null
+/*=========================================================================
+
+ Program: gdcm
+ Module: $RCSfile: gdcmDocEntryArchive.h,v $
+ Language: C++
+ Date: $Date: 2004/11/19 18:49:39 $
+ Version: $Revision: 1.1 $
+
+ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+ l'Image). All rights reserved. See Doc/License.txt or
+ http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*/
+
+#ifndef GDCMDOCENTRYARCHIVE_H
+#define GDCMDOCENTRYARCHIVE_H
+
+#include "gdcmCommon.h"
+#include "gdcmHeader.h"
+
+namespace gdcm
+{
+
+//-----------------------------------------------------------------------------
+/*
+ * /brief Container
+ *
+ * It's goal is to change the Header correctly. At this time, the change is
+ * only made for the first level of the Document. In the future, it might
+ * consider sequences.
+ * The change is made by replacing a DocEntry by an other that is created
+ * outside the class. The old value is kept. When we restore the header
+ * status, the added DocEntry is deleted and replaced by the old value.
+ */
+class GDCM_EXPORT DocEntryArchive
+{
+public:
+ DocEntryArchive(Header *header);
+ ~DocEntryArchive();
+
+ void Print(std::ostream &os = std::cout);
+
+ bool Push(DocEntry *newEntry);
+ bool Restore(uint16_t group,uint16_t element);
+
+ void ClearArchive(void);
+
+private:
+ TagDocEntryHT &HeaderHT;
+ TagDocEntryHT Archive;
+};
+} // end namespace gdcm
+
+//-----------------------------------------------------------------------------
+#endif
Program: gdcm
Module: $RCSfile: gdcmElementSet.h,v $
Language: C++
- Date: $Date: 2004/10/25 04:47:43 $
- Version: $Revision: 1.21 $
+ Date: $Date: 2004/11/19 18:49:39 $
+ 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
friend class Document;
friend class DicomDir; //For accessing private TagHT
+ friend class DocEntryArchive; //For accessing private TagHT
};
} // end namespace gdcm
//-----------------------------------------------------------------------------
Program: gdcm
Module: $RCSfile: gdcmFile.cxx,v $
Language: C++
- Date: $Date: 2004/11/16 16:20:23 $
- Version: $Revision: 1.157 $
+ Date: $Date: 2004/11/19 18:49:39 $
+ Version: $Revision: 1.158 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
*/
void File::Initialise()
{
+ WriteMode = WMODE_NATIVE;
+ WriteType = WTYPE_IMPL_VR;
PixelConverter = NULL; //just in case
+ Archive = NULL;
+
if ( HeaderInternal->IsReadable() )
{
ImageDataSizeRaw = ComputeDecompressedPixelDataSizeFromHeader();
PixelConverter = new PixelConvert;
PixelConverter->GrabInformationsFromHeader( HeaderInternal );
+
+ Archive = new DocEntryArchive( HeaderInternal );
}
+
SaveInitialValues();
}
*/
File::~File()
{
+ if( PixelConverter )
+ {
+ delete PixelConverter;
+ }
+ if( Archive )
+ {
+ delete Archive;
+ }
+
if( SelfHeader )
{
delete HeaderInternal;
HeaderInternal = 0;
DeleteInitialValues();
- if( PixelConverter )
- {
- delete PixelConverter;
- }
}
/**
*/
void File::SaveInitialValues()
{
-
PixelRead = -1; // no ImageData read yet.
LastAllocatedPixelDataLength = 0;
Pixel_Data = 0;
}
// We say the value *is* loaded.
-/* GetHeader()->SetEntryByNumber( GDCM_BINLOADED,
- GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
-
- // will be 7fe0, 0010 in standard cases
- GetHeader()->SetEntryBinAreaByNumber( decompressed,
- GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());*/
SetPixelData(decompressed);
PixelRead = 1; // PixelRaw
bool File::WriteDcmImplVR (std::string const & fileName)
{
- return WriteBase(fileName, ImplicitVR);
+ SetWriteTypeToDcmImplVR();
+ return Write(fileName);
}
/**
bool File::WriteDcmExplVR (std::string const & fileName)
{
- return WriteBase(fileName, ExplicitVR);
+ SetWriteTypeToDcmExplVR();
+ return Write(fileName);
}
/**
bool File::WriteAcr (std::string const & fileName)
{
- return WriteBase(fileName, ACR);
+ SetWriteTypeToAcr();
+ return Write(fileName);
+}
+
+bool File::Write(std::string const& fileName)
+{
+ switch(WriteType)
+ {
+ case WTYPE_IMPL_VR:
+ return WriteBase(fileName,ImplicitVR);
+ case WTYPE_EXPL_VR:
+ return WriteBase(fileName,ExplicitVR);
+ case WTYPE_ACR:
+ return WriteBase(fileName,ACR);
+ }
+ return(false);
}
//-----------------------------------------------------------------------------
std::string rows, columns;
if ( HeaderInternal->GetFileType() == ACR_LIBIDO)
{
- rows = HeaderInternal->GetEntryByNumber(0x0028, 0x0010);
- columns = HeaderInternal->GetEntryByNumber(0x0028, 0x0011);
+ SetToLibido();
+ //rows = HeaderInternal->GetEntryByNumber(0x0028, 0x0010);
+ //columns = HeaderInternal->GetEntryByNumber(0x0028, 0x0011);
- HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0010);
- HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0011);
+ //HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0010);
+ //HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0011);
}
// ----------------- End of Special Patch ----------------
if ( HeaderInternal->GetFileType() == ACR_LIBIDO )
{
- HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0010);
- HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0011);
+ RestoreFromLibido();
+ //HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0010);
+ //HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0011);
}
// ----------------- End of Special Patch ----------------
fp1->close ();
//-----------------------------------------------------------------------------
// Private
+/**
+ * \brief Set the pixel datas in the good entry of the Header
+ */
void File::SetPixelData(uint8_t* data)
{
GetHeader()->SetEntryByNumber( GDCM_BINLOADED,
}
}
+void File::SetToRAW()
+{
+}
+
+void File::SetToRGB()
+{
+}
+
+void File::Restore()
+{
+}
+
+void File::SetToLibido()
+{
+ ValEntry *oldRow = dynamic_cast<ValEntry *>(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0010));
+ ValEntry *oldCol = dynamic_cast<ValEntry *>(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0011));
+
+
+ if( oldRow && oldCol )
+ {
+ std::string rows, columns;
+
+ ValEntry *newRow=new ValEntry(oldRow->GetDictEntry());
+ ValEntry *newCol=new ValEntry(oldCol->GetDictEntry());
+
+ newRow->Copy(oldCol);
+ newCol->Copy(oldRow);
+
+ newRow->SetValue(oldCol->GetValue());
+ newCol->SetValue(oldRow->GetValue());
+
+ Archive->Push(newRow);
+ Archive->Push(newCol);
+ }
+}
+
+void File::RestoreFromLibido()
+{
+ Archive->Restore(0x0028, 0x0010);
+ Archive->Restore(0x0028, 0x0011);
+}
+
//-----------------------------------------------------------------------------
} // end namespace gdcm
Program: gdcm
Module: $RCSfile: gdcmFile.h,v $
Language: C++
- Date: $Date: 2004/11/16 16:20:23 $
- Version: $Revision: 1.69 $
+ Date: $Date: 2004/11/19 18:49:39 $
+ Version: $Revision: 1.70 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmCommon.h"
#include "gdcmHeader.h"
#include "gdcmPixelConvert.h"
+#include "gdcmDocEntryArchive.h"
namespace gdcm
{
*/
class GDCM_EXPORT File
{
+public:
+ typedef enum
+ {
+ WMODE_NATIVE,
+ WMODE_DECOMPRESSED,
+ WMODE_RGB,
+ } TWriteMode;
+
+ typedef enum
+ {
+ WTYPE_IMPL_VR,
+ WTYPE_EXPL_VR,
+ WTYPE_ACR,
+ } TWriteType;
+
public:
File( Header* header );
File( std::string const& filename );
bool WriteDcmImplVR(std::string const& fileName);
bool WriteDcmExplVR(std::string const& fileName);
bool WriteAcr (std::string const& fileName);
+ bool Write(std::string const& fileName);
virtual bool SetEntryByNumber(std::string const& content,
uint16_t group, uint16_t element)
return true;
}
uint8_t* GetLutRGBA();
-
+
+ // Write mode
+ void SetWriteModeToNative() { SetWriteMode(WMODE_NATIVE); };
+ void SetWriteModeToDecompressed() { SetWriteMode(WMODE_DECOMPRESSED); };
+ void SetWriteModeToRGB() { SetWriteMode(WMODE_RGB); };
+ void SetWriteMode(TWriteMode mode) { WriteMode = mode; };
+ TWriteMode GetWriteMode() { return WriteMode; };
+
+ // Write format
+ void SetWriteTypeToDcmImplVR() { SetWriteType(WTYPE_EXPL_VR); };
+ void SetWriteTypeToDcmExplVR() { SetWriteType(WTYPE_EXPL_VR); };
+ void SetWriteTypeToAcr() { SetWriteType(WTYPE_ACR); };
+ void SetWriteType(TWriteType format) { WriteType = format; };
+ TWriteType GetWriteType() { return WriteType; };
+
protected:
bool WriteBase(std::string const& fileName, FileType type);
+ void SetToRAW();
+ void SetToRGB();
+ void Restore();
+
+ void SetToLibido();
+ void RestoreFromLibido();
+
private:
void Initialise();
/// Utility pixel converter
PixelConvert* PixelConverter;
+ // Utility header archive
+ DocEntryArchive *Archive;
+
+ // Write variables
+ TWriteMode WriteMode;
+ TWriteType WriteType;
+
/// FIXME
// --------------- Will be moved to a PixelData class
//