123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680 |
- /****************************************************************
- * DICOMVRSet.hpp
- ****************************************************************/
- #ifndef _INCLUDE_DICOM_VRSET_
- #define _INCLUDE_DICOM_VRSET_
- class DICOMVRSet;
- class VRGroup;
- class DMarkup;
- class DICOMDataSet;
- class LinkedVR : public VR
- {
- public:
- inline LinkedVR (UINT16 g, UINT16 e, void * d, UINT32 l)
- {
- Group = g;
- Element = e;
- LongData = d;
- Length = l;
- SQVRSetArray= NULL;
- TypeCode = 0;
- }
- inline virtual ~LinkedVR ()
- {
- LongData = NULL;
- }
- };
- class VRItem
- {
- public:
- VR * vr;
- VRItem * PrevItem;
- VRItem * NextItem;
- inline VRItem (VRItem *p, VRItem *n)
- {
- PrevItem = p;
- NextItem = n;
- };
-
- inline VRItem ()
- {
- PrevItem = NULL;
- NextItem = NULL;
- };
- };
- class DICOM_API DICOMVRSet
- {
- public:
- UINT32 lParam;
- public:
- DICOMVRSet ();
- DICOMVRSet (const DICOMVRSet &);
- virtual ~DICOMVRSet () { Reset (); };
- BOOL Push (VR * vr);
- BOOL Push (UINT16 Group, UINT16 Element, DICOMVRSet *); // Sequence Embedding
- inline void Add (UINT32 tag)
- {
- if (! IsExist (tag))
- Push (new VR (tag));
- }
- inline void Add (UINT16 g, UINT16 e)
- {
- if (! IsExist (g, e))
- Push (new VR (g, e));
- }
- inline void Add (UINT16 g, UINT16 e, const UID & v)
- {
- VR * vr = GetVR (g, e);
- if (vr)
- (*vr) = v;
- else
- Push (new VR (g, e, v));
- }
- inline void Add (UINT16 g, UINT16 e, const char * v)
- {
- VR * vr = GetVR (g, e);
- if (vr)
- (*vr) = v;
- else
- Push (new VR (g, e, v));
- }
- inline void Add (UINT16 g, UINT16 e, const DString & v)
- {
- VR * vr = GetVR (g, e);
- if (vr)
- (*vr) = v;
- else
- Push (new VR (g, e, v));
- }
- inline void Add (UINT16 g, UINT16 e, UINT16 v)
- {
- VR * vr = GetVR (g, e);
- if (vr)
- (*vr) = v;
- else
- Push (new VR (g, e, v));
- }
- inline void Add (UINT16 g, UINT16 e, UINT32 v)
- {
- VR * vr = GetVR (g, e);
- if (vr)
- (*vr) = v;
- else
- Push (new VR (g, e, v));
- }
- inline void Add (UINT16 g, UINT16 e, INT16 v)
- {
- VR * vr = GetVR (g, e);
- if (vr)
- (*vr) = v;
- else
- Push (new VR (g, e, v));
- }
- inline void Add (UINT16 g, UINT16 e, INT32 v)
- {
- VR * vr = GetVR (g, e);
- if (vr)
- (*vr) = v;
- else
- Push (new VR (g, e, v));
- }
- inline void Add (UINT16 g, UINT16 e, float v)
- {
- VR * vr = GetVR (g, e);
- if (vr)
- (*vr) = v;
- else
- Push (new VR (g, e, v));
- }
- inline void Add (UINT16 g, UINT16 e, double v)
- {
- VR * vr = GetVR (g, e);
- if (vr)
- (*vr) = v;
- else
- Push (new VR (g, e, v));
- }
- inline void Add (UINT16 g, UINT16 e, DICOMVRSet & v)
- {
- VR * vr = GetVR (g, e);
- if (vr)
- (*vr) = v;
- else
- {
- vr = new VR (g, e);
- (*vr) = v;
- Push (vr);
- }
- }
- void Add (UINT16 g, UINT16 e, UINT16 * pus, int Count);
- void Add (UINT16 g, UINT16 e, UINT32 * pul, int Count);
- void Add (UINT16 g, UINT16 e, INT16 * pss, int Count);
- void Add (UINT16 g, UINT16 e, INT32 * psl, int Count);
- VR * Pop (void);
- VR * TakeOut (UINT16 g, UINT16 e);
- BOOL CopyTo (DICOMVRSet &) const;
- BOOL CopyTo (DICOMVRSet &, UINT32 FromTag, UINT32 ToTag = 0xFFFFFFFF) const;
- BOOL Delete (UINT16 g, UINT16 e);
- BOOL Delete (const DICOMVRSet & DVRS);
- BOOL Filter (const DICOMVRSet & DVRS);
- BOOL DeleteGroup (UINT16 g);
- VR * GetVR (UINT16 g, UINT16 e) const;
- VR * GetFirstVR () const;
- VR * GetLastVR () const;
- DICOMVRSet * GetSequence (UINT16 g, UINT16 e, int nItem = 0) const
- {
- VR * vr = this->GetVR (g, e);
- if (! vr) return NULL;
- Array <DICOMVRSet *> * pSQArray = vr->GetSQArray ();
- if (! pSQArray) return NULL;
- if (pSQArray->GetSize () <= nItem) return NULL;
- DICOMVRSet * VRS;
- if (nItem == 0)
- VRS = pSQArray->GetFirst ();
- else
- VRS = pSQArray->GetAt (nItem);
- return VRS;
- }
- inline LE_UINT16 GetUINT16 (UINT16 g, UINT16 e) const
- {
- VR * vr = this->GetVR (g, e);
- if (! vr) return (0);
- return (LE_UINT16) (*vr);
- }
- inline LE_UINT32 GetUINT32 (UINT16 g, UINT16 e) const
- {
- VR * vr = this->GetVR (g, e);
- if (! vr) return (0);
- return (LE_UINT32) (*vr);
- }
- inline DString GetDString (UINT16 g, UINT16 e) const
- {
- DString str;
- VR * vr = this->GetVR (g, e);
- if (vr) vr->Extract (str);
- return str;
- }
- inline float GetFloat (UINT16 g, UINT16 e) const
- {
- VR * vr = this->GetVR (g, e);
- if (! vr) return (0);
- return (float) (*vr);
- }
- inline double GetDouble (UINT16 g, UINT16 e) const
- {
- VR * vr = this->GetVR (g, e);
- if (! vr) return (0);
- return (double) (*vr);
- }
- inline int GetSize (void) const { return GroupCount; }
- inline int GetLength (void) const { return Length; }
- inline int GetVRCount (void) const;
- BOOL Package (void);
- BOOL Package (UINT16 g);
- inline BOOL IsEmpty (void) const { return (GroupCount == 0); }
- inline BOOL IsExist (UINT16 g, UINT16 e = 0) const
- {
- if (e)
- return (UINT32) GetVR (g,e);
- else
- return (UINT32) SeekFor (g);
- }
- inline BOOL IsExist (UINT32 tag) const
- {
- UINT16 g = GroupOfTag32 (tag);
- UINT16 e = ElementOfTag32 (tag);
- if (e)
- return (UINT32) GetVR (g,e);
- else
- return (UINT32) SeekFor (g);
- }
- virtual void Reset (void);
- DICOMVRSet & operator = (DICOMVRSet & DVRS);
- DICOMVRSet & TransferTo (DICOMVRSet & ToVRS);
- // Append all VR from FromVRS to me
- DICOMVRSet & AppendFrom (DICOMVRSet & FromVRS);
- virtual int Serialize (BYTE * pBuffer, int BufferSize) const;
- virtual int Deserialize (const BYTE * pBuffer, int BufferSize);
- // VRSetToXML
- virtual DString XmlSerialize (void) const;
- // XMLToVRSet
- virtual int XmlDeserialize (const char * XML);
- virtual int XmlDeserialize (const DString & XML);
- virtual DString ToString (void) const;
- virtual DString ToString (int nMinLength) const;
- protected:
- void Init (void)
- {
- lParam = 0;
- GroupCount = 0;
- FirstGroup = NULL;
- LastGroup = NULL;
- Length = 0;
- LastVR = NULL;
- LastVRG = NULL;
- CurrentGroup= NULL;
- }
- VRGroup * SeekFor (UINT16 g) const;
- BOOL PushGroup (VRGroup * VRGroupPtr);
- VRGroup * PopGroup (void);
- BOOL Push (DICOMVRSet *); // Sequence Embedding
- DString ToStringOfTabStop (int nbTab, int nMinLength = 0) const;
- int XmlSerialize (DMarkup * xml) const;
- int XmlDeserialize (DMarkup * xml);
- static BOOL XMLToVRSetArray (DMarkup * xml, Array <DICOMVRSet *> * arVRS);
- static BOOL XMLToADDS (DMarkup * xml, Array <DICOMDataSet*> * ADDS);
- private:
- VRGroup * FirstGroup;
- VRGroup * LastGroup;
- int GroupCount;
- VRGroup * CurrentGroup;
- mutable VRGroup * LastVRG;
- VR * LastVR;
- UINT32 Length;
- static VR ReservedVR;
- friend class VRSetIterator;
- friend class FixDecoder;
- friend class BigEndianDecoder;
- friend class Iterator;
- public:
- static BOOL VRSetArrayToXML (const Array <const DICOMVRSet *> * arVRS, DString * str);
- static BOOL VRSetArrayToXML (const Array <DICOMVRSet *> * arVRS, DString * str);
- static BOOL XMLToVRSetArray (const DString * str, Array <DICOMVRSet *> * arVRS);
- static BOOL ADDSToXML (const Array <const DICOMDataSet *> * ADDS, DString * str);
- static BOOL ADDSToXML (const Array <DICOMDataSet *> * ADDS, DString * str);
- static BOOL XMLToADDS (const DString * str, Array <DICOMDataSet *> * ADDS);
- public:
- class DICOM_API Iterator
- {
- private:
- const DICOMVRSet & DVS;
- int TotalVRCount;
- VRGroup * CurrentGroup;
- VRItem * CurrentItem;
- VR * CurrentVR;
- int m_Index;
- bool m_Continue;
- public:
- inline Iterator (const DICOMVRSet & theDVS) : DVS (theDVS)
- {
- Restart ();
- }
- inline void Restart ()
- {
- TotalVRCount = DVS.GetVRCount ();
- CurrentGroup = DVS.FirstGroup;
- CurrentItem = NULL;
- CurrentVR = NULL;
- m_Index = -1;
- m_Continue = true;
- Next ();
- }
- inline operator bool () const { return m_Continue; }
- inline VR * Current (void) const { return CurrentVR; }
- inline int Index (void) const { return m_Index; }
- inline int GetNbOfVR (void) const { return TotalVRCount; }
- inline void operator ++ () // ++ Iter;
- {
- Next ();
- }
- inline void operator ++ (int) // Iter ++;
- {
- Next ();
- }
- inline VR * operator () (void) { return Current (); }
- inline VR * operator * (void) { return Current (); }
- inline operator INT16 () const { return (INT16) (*Current ()); }
- inline operator INT32 () const { return (INT32) (*Current ()); }
- inline operator UINT16 () const { return (UINT16) (*Current ()); }
- inline operator UINT32 () const { return (UINT32) (*Current ()); }
- inline operator DString () const { return (DString) (*Current ()); }
- void Next ();
- };
- public:
- class DICOM_API Proxy
- {
- public:
- inline Proxy (DICOMVRSet & VRS, UINT16 g, UINT16 e) :
- m_VRSet (VRS),
- m_Group (g), m_Element (e)
- {
- }
- inline Proxy & operator = (const Proxy & vrp)
- {
- VR * vr = vrp.m_VRSet.GetVR (vrp.m_Group, vrp.m_Element);
- if (vr)
- {
- VR * nvr = new VR (*vr);
- nvr->SetTag (m_Group, m_Element);
- m_VRSet.Push (nvr);
- }
- return (*this);
- }
- inline Proxy & operator = (UINT16 v)
- {
- m_VRSet.Add (m_Group, m_Element, v);
- return (*this);
- }
- inline Proxy & operator = (UINT32 v)
- {
- m_VRSet.Add (m_Group, m_Element, v);
- return (*this);
- }
- inline Proxy & operator = (INT16 v)
- {
- m_VRSet.Add (m_Group, m_Element, v);
- return (*this);
- }
- inline Proxy & operator = (INT32 v)
- {
- m_VRSet.Add (m_Group, m_Element, v);
- return (*this);
- }
- inline Proxy & operator = (float v)
- {
- m_VRSet.Add (m_Group, m_Element, v);
- return (*this);
- }
- inline Proxy & operator = (double v)
- {
- m_VRSet.Add (m_Group, m_Element, v);
- return (*this);
- }
- inline Proxy & operator = (const char * v)
- {
- m_VRSet.Add (m_Group, m_Element, v);
- return (*this);
- }
- inline Proxy & operator = (const UID & v)
- {
- m_VRSet.Add (m_Group, m_Element, v);
- return (*this);
- }
- inline Proxy & operator = (const DString & v)
- {
- m_VRSet.Add (m_Group, m_Element, v);
- return (*this);
- }
- inline Proxy & operator = (DICOMVRSet & v)
- {
- m_VRSet.Add (m_Group, m_Element, v);
- return (*this);
- }
- inline operator DString () const
- {
- DString str = m_VRSet.GetDString (m_Group, m_Element);
- return str;
- }
- inline operator UINT32 () const
- {
- return m_VRSet.GetUINT32 (m_Group, m_Element);
- }
- inline operator UINT16 () const
- {
- return m_VRSet.GetUINT16 (m_Group, m_Element);
- }
- inline operator INT32 () const
- {
- return (INT32) (m_VRSet.GetUINT32 (m_Group, m_Element));
- }
- inline operator INT16 () const
- {
- return (INT16) (m_VRSet.GetUINT16 (m_Group, m_Element));
- }
- inline operator float () const
- {
- return m_VRSet.GetFloat (m_Group, m_Element);
- }
- inline operator double () const
- {
- return m_VRSet.GetDouble (m_Group, m_Element);
- }
- private:
- DICOMVRSet & m_VRSet;
- UINT16 m_Group;
- UINT16 m_Element;
- };
- inline Proxy operator [] (UINT32 tag)
- {
- return Proxy (*this, GroupOfTag32 (tag), ElementOfTag32 (tag));
- }
- inline Proxy operator () (UINT32 tag)
- {
- return Proxy (*this, GroupOfTag32 (tag), ElementOfTag32 (tag));
- }
- inline Proxy operator () (UINT16 g, UINT16 e)
- {
- return Proxy (*this, g, e);
- }
- inline const Proxy operator [] (UINT32 tag) const
- {
- return Proxy (const_cast <DICOMVRSet &> (*this), GroupOfTag32 (tag), ElementOfTag32 (tag));
- }
- inline const Proxy operator () (UINT32 tag) const
- {
- return Proxy (const_cast <DICOMVRSet &> (*this), GroupOfTag32 (tag), ElementOfTag32 (tag));
- }
- inline const Proxy operator () (UINT16 g, UINT16 e) const
- {
- return Proxy (const_cast <DICOMVRSet &> (*this), g, e);
- }
- friend class Proxy;
- };
- class VRGroup
- {
- private:
- VRGroup * PrevGroup;
- VRGroup * NextGroup;
- VRItem * FirstItem;
- VRItem * LastItem;
- int ItemCount;
- private:
- UINT16 Group;
- UINT32 Length;
- LinkedVR *Element0;
- //public:
- protected:
- VRGroup (UINT16 G);
- ~VRGroup ()
- {
- Reset () ;
- delete Element0;
- Element0 = NULL;
- }
- void Reset (void);
- BOOL Push (VR * vr);
- VR * Pop (void);
- VR * TakeOut (UINT16 e);
- VR * SeekFor (UINT16 e) const ;
- int GetVRCount (void) const { return (ItemCount+1) ; } // All VR plus the Element0
- protected:
- BOOL Package (void);
- friend class DICOMVRSet;
- friend class DICOMVRSet::Iterator;
- friend class VRSetIterator;
- };
- inline void DICOMVRSet::Iterator::Next ()
- {
- if (! CurrentItem)
- {
- if (! CurrentGroup)
- {
- CurrentVR = NULL;
- m_Continue = false;
- m_Index = -1;
- return;
- }
- m_Index ++;
- CurrentItem = CurrentGroup->FirstItem;
- CurrentVR = CurrentGroup -> Element0;
- return;
- }
- m_Index ++;
- CurrentVR = CurrentItem -> vr;
- CurrentItem = CurrentItem->NextItem;
- if (! CurrentItem)
- CurrentGroup = CurrentGroup->NextGroup;
- }
- DICOM_API BOOL operator == (const DICOMVRSet & SetA, const DICOMVRSet & SetB) ;
- inline DICOM_API BOOL operator != (const DICOMVRSet & SetA, const DICOMVRSet & SetB)
- {
- return ! (SetA == SetB);
- }
- //////////////////////////////////////////////////////////////////////
- // class VRSetIterator
- class DICOM_API VRSetIterator
- {
- private:
- const DICOMVRSet & DVS;
- int TotalVRCount;
- VRGroup * CurrentGroup;
- VRItem * CurrentItem;
- VR * LastVR;
- int VRCount;
- public:
- VRSetIterator (const DICOMVRSet & theDVS) : DVS (theDVS)
- {
- TotalVRCount = theDVS.GetVRCount ();
- CurrentGroup = theDVS.FirstGroup;
- CurrentItem = NULL;
- LastVR = NULL;
- VRCount = 0;
- }
- VR * operator () (void);
- };
- #endif
|