2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
28 #include <creaImageIOTreeNode.h>
29 #include <creaImageIOTree.h>
30 #include <creaImageIOSystem.h>
32 #include <creaImageIOGimmick.h>
39 //=============================================================
41 Node::Node(Node* parent)
42 : mParent(parent),//mData(0),
43 mChildrenLoaded(false)
48 GimmickDebugMessage(6,"Default Node constructor (level "<<GetLevel()<<")"
50 // Insert into parent's children list
51 InitializeAttributeMap();
52 parent->GetChildrenList().push_back(this);
56 GimmickDebugMessage(6,"Default Node constructor without parent"
60 //=============================================================
62 //=============================================================
63 /// Ctor with parent and attributes map
64 Node::Node(Node* parent, const AttributeMapType& attr)
65 : mParent(parent),//mData(0),
66 mChildrenLoaded(false)
69 GimmickDebugMessage(6,"Node constructor (level "<<GetLevel()<<")"
74 // Insert into parent's children list
75 parent->GetChildrenList().push_back(this);
76 // Initialize attributes
77 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
78 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
79 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
83 AttributeMapType::const_iterator i = attr.find(a->GetKey());
84 if ( i != attr.end() )
88 GimmickDebugMessage(6,"Setting attribute '"<<a->GetName()<<"' = '"
90 UnsafeSetAttribute( a->GetKey(), v );
95 //=============================================================
98 //=============================================================
101 GimmickDebugMessage(6,"Node destructor"
103 ChildrenListType::iterator i;
104 for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
110 //=============================================================
113 //=============================================================
114 /// Initializes the attribute map i.e. creates the entries
115 void Node::InitializeAttributeMap()
117 // Initialize attributes
118 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
119 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
120 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
123 UnsafeSetAttribute( a->GetKey(), "" );
126 //=============================================================
128 //=============================================================
129 /// Returns the level descriptor of the node
130 const LevelDescriptor& Node::GetLevelDescriptor() const
132 return GetTree()->GetLevelDescriptor(GetLevel());
135 //=============================================================
137 //=============================================================
138 /// Returns the attribute descriptor of the passed parameter
139 const AttributeDescriptor& Node::GetAttributeDescriptor(const std::string& k)const
141 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
142 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
143 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
155 //=============================================================
157 //=============================================================
158 int Node::RemoveChildrenFromList(Node* node)
160 ChildrenListType::iterator i = find(GetChildrenList().begin(),
161 GetChildrenList().end(),
163 if (i != GetChildrenList().end())
165 GetChildrenList().erase(i);
167 return (int)GetChildrenList().size();
169 //=============================================================
171 //=============================================================
172 const std::string& Node::GetAttribute(const std::string& k) const
174 // std::cout << "this = "<<(void*)this<<std::endl;
175 // std::cout << "mFieldValueMap="<<(void*)(&mFieldValueMap)<<std::endl;
176 AttributeMapType::const_iterator i = mAttributeMap.find(k);
177 if (i == mAttributeMap.end())
179 static std::string def("");
181 // CREAIMAGEIO_ERROR("DicomNode::GetFieldValue : no field with key '"<<k<<"'");
185 //=============================================================
187 //=============================================================
188 void Node::SetAttribute(const std::string& k,
189 const std::string& v)
191 AttributeMapType::iterator i = mAttributeMap.find(k);
192 if (i==mAttributeMap.end())
194 std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with key '"
196 creaError( "[Gimmick!] Node::SetAttribute : no attribute with key '"
201 //=============================================================
203 //=============================================================
204 bool Node::Matches( const AttributeMapType& m ) const
206 GimmickDebugMessage(2,"'"<<GetLabel()<<"' matching..."<<std::endl);
207 const std::vector<std::string>& id
208 = GetLevelDescriptor().GetIdentifierList();
209 std::vector<std::string>::const_iterator i;
210 for (i = id.begin(); i != id.end(); ++i)
212 if (mAttributeMap.find(*i)->second != m.find(*i)->second )
214 GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values do not match"<<std::endl);
217 GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values match"<<std::endl);
221 //=============================================================
223 //=============================================================
224 void Node::Print() const
227 for (int i = 0; i<GetLevel(); ++i) mess += " ";
228 mess += "|_ " + GetLabel();
229 GimmickMessage(1,mess<<std::endl);
230 ChildrenListType::const_iterator j;
231 for (j=GetChildrenList().begin(); j!=GetChildrenList().end(); j++)
236 //=============================================================
238 //=============================================================
239 std::string Node::GetLabel() const
242 const std::vector<std::string>& label
243 = GetLevelDescriptor().GetLabelList();
245 std::vector<std::string>::const_iterator i;
246 for (i = label.begin(); i != label.end(); )
248 GimmickDebugMessage(9,"LABEL '"<<*i<<"'"<<std::endl);
249 AttributeMapType::const_iterator j = mAttributeMap.find(*i);
250 if (j != mAttributeMap.end())
254 if (i != label.end()) l += "|";
258 GimmickError("Node::GetLabel() : LABEL attribute '"
260 <<"' is not in node attribute map (should be!)" );
263 if (l.size()==0) l="?";
266 //=============================================================