]> Creatis software - gdcm.git/blob - src/gdcmDataEntry.h
upgrades for 4DSplitter
[gdcm.git] / src / gdcmDataEntry.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDataEntry.h,v $
5   Language:  C++
6   Date:      $Date: 2011/03/29 07:36:00 $
7   Version:   $Revision: 1.23 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18  
19 #ifndef _GDCMDATAENTRY_H_
20 #define _GDCMDATAENTRY_H_
21
22 #include "gdcmDocEntry.h"
23
24 #include <vector> // for GetDSValue
25 #include <iostream>
26
27 namespace GDCM_NAME_SPACE 
28 {
29 //-----------------------------------------------------------------------------
30 /**
31  * \brief   Any Dicom Document (File or DicomDir, or ...) contains 
32  *           a set of DocEntry  - Dicom entries -
33  *           (when successfuly parsed against a given Dicom dictionary)
34  *          DataEntry is an elementary DocEntry (as opposed to SeqEntry).
35  *          Depending on the type of its content,
36  */
37 class GDCM_EXPORT DataEntry  : public DocEntry
38 {
39    gdcmTypeMacro(DataEntry);
40
41 public:
42 /// \brief Contructs a DataEntry with a RefCounter from DictEntry
43 //   static DataEntry *New(DictEntry *e) {return new DataEntry(e);}
44 /// \brief Contructs a DataEntry with a RefCounter from DocEntry
45    static DataEntry *New(DocEntry *d)  {return new DataEntry(d);}
46 /// \brief Contructs a DataEntry with a RefCounter from elementary items
47    static DataEntry *New(uint16_t group,uint16_t elem, VRKey const &vr)  
48            {return new DataEntry(group,elem,vr);}
49    
50 // Print
51    void Print(std::ostream &os = std::cout, std::string const &indent = "");
52
53 // Write
54    virtual void WriteContent(std::ofstream *fp, FileType filetype,
55                                bool insideMetaElements, bool insideSequence);
56    uint32_t ComputeFullLength();
57    
58 // Set/Get data
59    // Sets the value (string) of the current Dicom entry
60    //virtual void SetValue(std::string const &val);
61
62    /// \brief Returns the area value of the current Dicom Entry
63    ///  when it's not string-translatable (e.g : LUT table, overlay, icon)   
64    uint8_t *GetBinArea()  { return BinArea; }
65    void SetBinArea( uint8_t *area, bool self = true );
66    void CopyBinArea( uint8_t *area, uint32_t length );
67
68    void SetValue(const uint32_t &id,const double &val);
69    double GetValue(const uint32_t &id) const;
70    uint32_t GetValueCount() const;
71    bool IsValueCountValid() /*const*/; // GetVM may update the pointer DicomDict
72
73    void SetString(std::string const &value);
74    std::string const &GetString() const;
75
76    std::string const &GetHexaRepresentation() const;
77
78    bool IsNumerical();
79    bool GetNumerical(std::vector <double> &valueVector);
80     
81    /// \brief Sets SelfArea
82    void SetSelfArea(bool area) { SelfArea = area; }
83    /// \brief True if Entry owns its BinArea
84    bool IsSelfArea() { return SelfArea; }
85
86    ///\brief values for current state of a DataEntry (internal use only)
87    enum TValueState
88    {
89       STATE_LOADED    = 0x00,
90       STATE_NOTLOADED = 0x01,
91       STATE_UNFOUND   = 0x02,
92       STATE_UNREAD    = 0x03
93    };
94    
95    ///\brief values for current pixel status of a DataEntry (internal use only)
96    enum TValueFlag
97    {
98       FLAG_NONE       = 0x00,
99       FLAG_PIXELDATA  = 0x01
100    };
101
102    // State
103    /// \brief Sets the state (Loaded, NotLoaded, UnFound, ...) of the DataEntry
104    void SetState(const TValueState &state) { State = state; }
105    /// \brief Returns the state (Loaded, NotLoaded, ...) of the DataEntry
106    const TValueState &GetState() const { return State; }
107    /// \brief true when value Entry not loaded  
108    bool IsNotLoaded() { return State == STATE_NOTLOADED; }
109    /// \brief true if Entry not found  
110    bool IsUnfound()   { return State == STATE_UNFOUND; }
111    /// \brief true if Entry not read    
112    bool IsUnread()    { return State == STATE_UNREAD; }
113    /// \brief true if Entry value properly loaded
114    bool IsGoodValue() { return State == STATE_LOADED; }
115
116    // Flags
117    /// \brief sets the 'pixel data flag'   
118    void SetFlag(const TValueFlag &flag) { Flag = flag; }
119    /// \brief returns the 'pixel data flag'
120    const TValueFlag &GetFlag() const { return Flag; }
121    /// \brief true id Entry is a Pixel Data entry
122    bool IsPixelData() { return (Flag &FLAG_PIXELDATA) != 0; }
123
124    virtual void Copy(DocEntry *doc);
125
126    /// \brief returns the size threshold above which an element value 
127    ///        will NOT be *printed* in order no to polute the screen output
128    static const uint32_t &GetMaxSizePrintEntry() { return MaxSizePrintEntry; }
129    /// \brief Header Elements too long will not be printed
130    static void SetMaxSizePrintEntry(const uint32_t &size) 
131                                                  { MaxSizePrintEntry = size; }
132
133    bool GetDSValue(std::vector <double> &valueVector);
134
135 protected:
136   // DataEntry(DictEntry *e);
137    DataEntry(DocEntry *d);
138    DataEntry(uint16_t group,uint16_t elem,VRKey const &vr); 
139    ~DataEntry();
140
141 // Methods :
142    void NewBinArea( );
143    void DeleteBinArea( );
144
145 // Members :
146    /// \brief memory area to hold 'non std::string' representable values 
147    ///       (ie : Lookup Tables, overlays, icons)   
148    uint8_t *BinArea;
149    /// \brief Whether DataEntry has its own BinArea or not
150    bool SelfArea;
151    /// \brief  std::string representable value of the Entry. 
152    ///        Parts of a multivaluated data are separated by back-slash
153    mutable std::string *StrArea; // to avoid allocating useless std::string
154
155    /// \brief  std::string Hexadecimal represention of the value Entry. 
156    ///        Parts of a multivaluated data are separated by back-slash
157    mutable std::string *StrHexaArea; // to avoid allocating useless std::string
158 private:
159    /// \brief 0 for straight entries, FLAG_PIXELDATA for Pixel Data entries
160    TValueFlag Flag;
161    /// \brief Entry status:STATE_NOTLOADED,STATE_UNFOUND,STATE_UNREAD,STATE_LOADED
162    TValueState State;
163
164    /// \brief Size threshold above which an element is printed
165    static uint32_t MaxSizePrintEntry;   
166 };
167
168 } // end namespace gdcm
169
170 //-----------------------------------------------------------------------------
171 #endif
172