1 #include <creaMessageManager.h>
2 #include <creaImageIODicomNode.h>
4 #include <creaImageIODicomDatabase.h>
5 //#include <creaImageIOException.h>
11 //=============================================================
12 const int DicomNode::Database = 0;
13 const int DicomNode::Patient = 1;
14 const int DicomNode::Study = 2;
15 const int DicomNode::Series = 3;
16 const int DicomNode::Image = 4;
17 //=============================================================
19 const std::string DicomNodeTypeName[5] =
26 const std::string DicomNodePluralTypeName[5] =
34 //=============================================================
35 DicomNode::DicomNode(Type type, DicomDatabase* root, DicomNode* parent)
40 mChildrenLoaded(false),
45 parent->GetChildrenList().push_back(this);
49 DicomNodeTypeDescription::FieldDescriptionMapType::const_iterator i;
50 for (i = GetTypeDescription().GetFieldDescriptionMap().begin();
51 i != GetTypeDescription().GetFieldDescriptionMap().end();
54 mFieldValueMap[i->first] = "----";
58 //=============================================================
60 //=============================================================
61 DicomNode::~DicomNode()
63 ChildrenListType::iterator i;
64 for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
74 //=============================================================
76 //=============================================================
77 const std::string& DicomNode::GetTypeName(const Type& t)
79 return DicomNodeTypeName[t];
81 //=============================================================
82 //=============================================================
83 const std::string& DicomNode::GetPluralTypeName(const Type& t)
85 return DicomNodePluralTypeName[t];
87 //=============================================================
89 //=============================================================
90 const std::string& DicomNode::GetTypeName() const
92 return DicomNodeTypeName[GetType()];
94 //=============================================================
96 //=============================================================
97 void DicomNode::RemoveChildrenFromList(DicomNode* node)
99 ChildrenListType::iterator i = find(GetChildrenList().begin(),
100 GetChildrenList().end(),
102 if (i != GetChildrenList().end())
104 GetChildrenList().erase(i);
107 //=============================================================
109 //=============================================================
110 const DicomNodeTypeDescription& DicomNode::GetTypeDescription() const
112 return mDicomDatabase->GetDicomNodeTypeDescription(mType);
114 //=============================================================
117 // Tree* DicomNode::GetTree() const { return mDicomDatabase->GetTree(); }
120 //=============================================================
121 const Field::Value& DicomNode::GetFieldValue(const Field::Key& k) const
123 // std::cout << "this = "<<(void*)this<<std::endl;
124 // std::cout << "mFieldValueMap="<<(void*)(&mFieldValueMap)<<std::endl;
125 FieldValueMapType::const_iterator i = mFieldValueMap.find(k);
126 if (i==mFieldValueMap.end())
128 static Field::Value def("");
130 // CREAIMAGEIO_ERROR("DicomNode::GetFieldValue : no field with key '"<<k<<"'");
134 //=============================================================
136 //=============================================================
137 const Field::Value& DicomNode::GetCleanFieldValue(const Field::Key& k) const
139 static std::string Clean("-");
140 FieldValueMapType::const_iterator i = mFieldValueMap.find(k);
141 if (i==mFieldValueMap.end())
143 creaError("DicomNode::GetFieldValue : no field with key '"<<k<<"'");
145 if (i->second == "GDCM::Unfound")
151 //=============================================================
154 //=============================================================
155 void DicomNode::SetFieldValue(const Field::Key& k, const Field::Value& v)
157 FieldValueMapType::iterator i = mFieldValueMap.find(k);
158 if (i==mFieldValueMap.end())
160 std::cout << "DicomNode::SetFieldValue : no field with key '"<<k
162 creaError("DicomNode::SetFieldValue : no field with key '"<<k<<"'");
166 //=============================================================
168 //=============================================================
169 int DicomNode::ImageGetRows() const
171 return atoi(UnsafeGetFieldValue("A0028_0010").c_str());
173 //=============================================================
175 //=============================================================
176 int DicomNode::ImageGetColumns() const
178 return atoi(UnsafeGetFieldValue("A0028_0011").c_str());
180 //=============================================================
182 //=============================================================
183 int DicomNode::ImageGetFrames() const
185 return atoi(UnsafeGetFieldValue("A0028_0008").c_str());
187 //=============================================================
189 //=============================================================
190 void DicomNode::Print() const
192 for (int ii=0;ii<GetType()+1;++ii) std::cout << " ";
193 std::cout << "-> "<<GetLabel() << std::endl;
194 ChildrenListType::const_iterator i;
195 for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
201 //=============================================================
203 //=============================================================
204 std::string DicomNode::GetLabel() const
210 l += GetFieldValue("Name");
212 // + " (" + GetFieldValue("Location") + ")";
214 l += GetCleanFieldValue("A0010_0010") // Name
215 + " | " + GetCleanFieldValue("A0010_0040") + " | " // Sex
216 + GetCleanFieldValue("A0010_0030"); // Birthday
219 l += GetCleanFieldValue("A0008_0020") // Study Date
220 + " | " + GetCleanFieldValue("A0008_1030"); // Study Description
223 l += GetCleanFieldValue("A0008_0060") // Modality
224 + " | " + GetCleanFieldValue("A0008_103E"); // Description
227 l += GetCleanFieldValue("A0004_1500"); // File Name
232 //=============================================================
234 //=============================================================
235 int DicomNode::GetNumberOfChildren()
237 // std::cout << "$$$ DicomNode::GetNumberOfChildren"<<std::endl;
238 if ( GetType() == DicomNode::Image ) return 0;
239 if ( GetChildrenList().size() > 0 ) return GetChildrenList().size();
240 if ( mNumberOfChildren == -1 )
242 mNumberOfChildren = 0;
243 if (GetDicomDatabase()!=0)
246 GetDicomDatabase()->DBQueryNumberOfChildren(this);
249 return mNumberOfChildren;
251 //=============================================================
254 const Field::Description& DicomNode::GetFieldDescription(const Field::Key& k)
258 return GetTypeDescription().GetFieldDescription(k);
265 //=====================================================================
266 void DicomNode::SortChildren(const LexicographicalDicomNodeComparator& c)
270 ChildrenListType::const_iterator i;
271 for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
273 std::cout << (*i)->GetLabel()<<std::endl;
276 std::cout << "!!! SortChildren : child = "<<*i<<std::endl;
280 std::cout<<"=========================="<<std::endl;
282 std::sort(GetChildrenList().begin(),
283 GetChildrenList().end(),
286 //=====================================================================
292 } // namespace creaImageIO