]> Creatis software - creaImageIO.git/blob - src/creaImageIODicomNode.h
no message
[creaImageIO.git] / src / creaImageIODicomNode.h
1 #ifndef __creaImageIODicomNode_h_INCLUDED__
2 #define __creaImageIODicomNode_h_INCLUDED__
3
4 #include <creaImageIODicomNodeTypeDescription.h>
5 #include <creaImageIODicomNodeComparators.h>
6 #include <vector>
7
8 namespace creaImageIO
9 {
10
11   //=====================================================================
12   /// Forward declaration
13   class DicomDatabase;
14   //=====================================================================  
15
16   //=====================================================================
17   /// 
18   struct DicomNodeData
19   { 
20     DicomNodeData() {}
21     virtual ~DicomNodeData() {}
22   };
23   //=====================================================================
24
25
26   //=====================================================================
27   class DicomNode
28   {
29   public:
30
31     /// The identifier of "Database" node types (root of a tree)
32     static const int Database;
33     /// The identifier of "Patient" node types 
34     static const int Patient;
35     /// The identifier of "Study" node types 
36     static const int Study;
37     /// The identifier of "Series" node types 
38     static const int Series;
39     /// The identifier of "Image" node types 
40     static const int Image;
41
42     typedef int Type;
43     
44     /// Ctor
45     DicomNode(Type type, DicomDatabase* db, DicomNode* parent);
46     virtual ~DicomNode();
47
48  
49     Type GetType() const { return mType; }
50     const std::string& GetTypeName() const;
51
52     static const std::string& GetTypeName(const Type&);
53     static const std::string& GetPluralTypeName(const Type&);
54
55     const DicomNodeTypeDescription& GetTypeDescription() const;
56
57     DicomDatabase* GetDicomDatabase() const { return mDicomDatabase; }
58     //    Tree* GetTree() const;
59     DicomNode* GetParent() const { return mParent; }
60
61     bool ChildrenLoaded() const { return mChildrenLoaded; }
62     void SetChildrenLoaded(bool l) { mChildrenLoaded = l; }
63
64     /// returns the number of children of the node.
65     /// Warning : a non null number of children does not mean that they 
66     /// are loaded !
67     int GetNumberOfChildren();
68
69
70     typedef std::vector<DicomNode*> ChildrenListType;
71     ChildrenListType& GetChildrenList() { return mChildren; }
72     const ChildrenListType& GetChildrenList() const { return mChildren; }
73     void RemoveChildrenFromList(DicomNode*);
74
75     typedef std::map<Field::Key,Field::Value> FieldValueMapType;
76     FieldValueMapType& GetFieldValueMap() { return mFieldValueMap; }
77     const FieldValueMapType& GetFieldValueMap() const { return mFieldValueMap; }
78     const Field::Value& GetFieldValue(const Field::Key& k) const;
79     const Field::Value& GetCleanFieldValue(const Field::Key& k) const;
80     const Field::Value& UnsafeGetFieldValue(const Field::Key& k) const
81     { return mFieldValueMap.find(k)->second; }
82     void SetFieldValue(const Field::Key& k, const Field::Value& v);
83     void UnsafeSetFieldValue(const Field::Key& k, const Field::Value& v)
84     { mFieldValueMap[k] = v; }
85     
86     const Field::Description& GetFieldDescription(const Field::Key& k) const
87     { return GetTypeDescription().GetFieldDescription(k); }
88
89
90     virtual void Print() const;
91     std::string GetLabel() const;
92
93     template<class T> T GetData() const 
94     { if (mData!=0) return dynamic_cast<T>(mData); return 0; }
95
96     void SetData(DicomNodeData* d) { if (mData) delete mData; mData = d; }
97
98     void SortChildren(const LexicographicalDicomNodeComparator&);
99
100
101     int ImageGetRows() const;
102     int ImageGetColumns() const;
103     int ImageGetFrames() const;
104     const std::string& ImageGetFullFileName() const { return UnsafeGetFieldValue("FullFileName"); }
105
106   protected:
107     DicomDatabase* mDicomDatabase;
108
109   private:
110     Type mType;
111     DicomNode* mParent;
112     ChildrenListType mChildren;
113     FieldValueMapType mFieldValueMap;
114     DicomNodeData* mData;
115     bool mChildrenLoaded;
116     int mNumberOfChildren;
117
118   }; // class DicomNode
119   //=====================================================================
120
121
122
123
124 } // namespace creaImageIO
125
126
127
128 #endif // #ifndef __creaImageIODicomNode_h_INCLUDED__