Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
NodeInfo.hh
1 #ifndef __NodeInfo_hh__
2 #define __NodeInfo_hh__
3 
4 #include <bias_config.h>
5 #include <Base/Debug/Error.hh>
6 #include <Base/Debug/Exception.hh>
7 #include <osg/Node>
8 #include <Base/Common/XMLBase.hh>
9 #include <sstream>
10 #include <GLviewer/OpenSceneGraphHelper.hh>
11 #include <GLviewer/Scenes/SceneOpenSceneGraphDefines.hh>
12 
13 namespace BIAS
14 {
15 
16  enum eNodeType { eNT_Default = 0,
24  //add strings for xml output here -
25  //( the enum is index in array - keep an eye on the right order)
26  static std::string NodeTypeXMLStrings[] = { "NT_Default",
27  "NT_FromDisk",
28  "NT_FromImageFile",
29  "NT_Marker",
30  "NT_Light",
31  "NT_PointCloud",
32  "NT_BBox",
33  "NT_VNTriMesh"};
34 
35  inline enum eNodeType String2NodeType(const std::string &val)
36  {
37  for(unsigned int s=0; s<sizeof(NodeTypeXMLStrings); s++){
38  if(NodeTypeXMLStrings[s]==val){
39  return (eNodeType) s;
40  }
41  }
42  BEXCEPTION("String2NodeType(): Invalid string \""+val+"\"");
43  }
44 
45  inline std::string NodeType2String(const enum eNodeType &t)
46  { return NodeTypeXMLStrings[t]; }
47 
49  {
50  std::string stype;
51  const bool found =
52  OpenSceneGraphHelper::HasInfo(node, SOSG_KEY_NODE_TYPE, stype);
53  if (!found) return eNT_Default;
54  return String2NodeType(stype);
55  }
56 
57 
58  /** @struct NodeInfo
59  struct containing details of a OSG::Node when used in a
60  wxTreeCtrlOpenSGWx */
61  struct NodeInfo: public BIAS::XMLBase
62  {
64  {
65  Name = "(Unnamed)";
66  FileName = "";
68  IsVisible = true;
69  IsEditable = false;
70  IsExpanded = false;
71  IsOccluder = false;
72  IsClippingOutSide = true;
73  SizeMM = 0.;
74  };
75 
76  std::string Name;
77  std::string FileName;
78 
79  // bool IsFromDisk;
81  bool IsVisible; //is this node visible in treectrl?
82  bool IsEditable;
83  bool IsExpanded; //is tree item collapsed or expanded?
84  bool IsOccluder;
85  bool IsClippingOutSide; //is clips bounding volume inside or outside
86  double SizeMM; // necessary for models generated from image files
87  unsigned long long MarkerID;
88 
89  std::string Id; //only used for file io - move along. nothing to see here.
90 
91  virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
92  {
93  TopLevelTag = "NodeInfo";
94  Version = 1.0;
95  return 0;
96  };
97 
98  virtual int XMLIn(const xmlNodePtr Node, BIAS::XMLIO &XMLObject)
99  {
100  Id = XMLObject.getAttributeValueString(Node, "Id");
101  Name = XMLObject.getAttributeValueString(Node, "Name");
102  FileName = XMLObject.getAttributeValueString(Node, "FileName");
103 
104  std::string NodeInfoStr
105  = XMLObject.getAttributeValueString(Node, "NodeType");
107  for(unsigned int s=0; s<sizeof(NodeTypeXMLStrings); s++)
108  {
109  if(NodeTypeXMLStrings[s]==NodeInfoStr)
110  {
111  NodeType =(eNodeType) s;
112  break;
113  }
114  }
115  if(NodeType==eNT_Marker)
116  {
117  std::stringstream ss;
118  ss << XMLObject.getAttributeValueString(Node, "MarkerID");
119  ss>>MarkerID;
120  }
121  IsVisible = XMLObject.getAttributeValueBool(Node, "IsVisible");
122  IsEditable = XMLObject.getAttributeValueBool(Node, "IsEditable");
123  IsExpanded = XMLObject.getAttributeValueBool(Node, "IsExpanded");
124  IsOccluder = XMLObject.getAttributeValueBool(Node, "IsOccluder");
125  if(NodeType==eNT_BBox)
126  {
128  XMLObject.getAttributeValueBool(Node,"IsClippingOutSide");
129  }
130  return 0;
131  }
132 
133  virtual int XMLOut(const xmlNodePtr Node, BIAS::XMLIO &XMLObject) const
134  {
135  XMLObject.addAttribute(Node, "Id", Id);
136  XMLObject.addAttribute(Node, "Name", Name);
137  XMLObject.addAttribute(Node, "FileName", FileName);
138  // XMLObject.addAttribute(Node, "IsFromDisk", IsFromDisk);
139  XMLObject.addAttribute(Node, "NodeType", NodeTypeXMLStrings[NodeType]);
140  if(NodeType==eNT_Marker)
141  {
142  std::stringstream ss;
143  ss<<MarkerID;
144  XMLObject.addAttribute(Node, "MarkerID", ss.str());
145  }
146  XMLObject.addAttribute(Node, "IsVisible", IsVisible);
147  XMLObject.addAttribute(Node, "IsEditable", IsEditable);
148  XMLObject.addAttribute(Node, "IsExpanded", IsExpanded);
149  XMLObject.addAttribute(Node, "IsOccluder", IsOccluder);
150  if(NodeType==eNT_BBox)
151  {
152  XMLObject.addAttribute(Node, "IsClippingOutSide",
154  }
155  return 0;
156  };
157  };
158 
159 
160  class NodeInfoMap:public std::map< osg::Node*, NodeInfo >,
161  public BIAS::XMLBase
162  {
163  public:
165  {
166  areKeyPointersValid_ = true;
167  }
168  virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
169  {
170  TopLevelTag = "NodeInfoMap";
171  Version = 1.0;
172  return 0;
173  };
174 
175  virtual int XMLIn(const xmlNodePtr Node, BIAS::XMLIO &XMLObject)
176  {
177  clear();
178  xmlNodePtr Cur = XMLObject.getFirstChild(Node);
179  areKeyPointersValid_ = false; //after loading the pointers can't be valid
180  unsigned int dummycouter = 1;
181  //read node infos
182  while(Cur!=NULL)
183  {
184  osg::Node* invalidcrap =
185  (osg::Node* ) (long)dummycouter;//for this coding crime god kills a kitten
186  NodeInfo temp;
187  temp.XMLIn(Cur,XMLObject);
188  (*this)[invalidcrap] = temp;
189  Cur = XMLObject.getNextChild(Cur);
190  dummycouter++;
191  }
192  return 0;
193  }
194 
195  virtual int XMLOut(const xmlNodePtr Node, BIAS::XMLIO &XMLObject) const
196  {
197  //add children tag
198  std::map< osg::Node*, NodeInfo >::const_iterator it;
199  for(it=begin(); it!=end(); it++)
200  {
201  (*it).second.XMLAdd(Node,XMLObject);
202  }
203  return 0;
204  };
205 
206  bool NodeHasNodeInfo(osg::Node* node) const
207  {
208  return(find(node)!=end());
209  }
210 
212  {
213  return areKeyPointersValid_;
214  };
215 
216  protected:
218  };
219 
220 
221  /** @struct TreeDescr
222  @brief container for scene root and ptr to nodeinfomap
223  */
224  struct TreeDescr
225  {
228  };
229 
230 }//end of namespace
231 
232 #endif
233 
void addAttribute(const xmlNodePtr Node, const std::string &AttributeName, bool AttributeValue)
Add an attribute to a node.
Definition: XMLIO.cpp:156
virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
derived classes must implement this, so that it returns the name of the class for the top level tag i...
Definition: NodeInfo.hh:168
bool IsClippingOutSide
Definition: NodeInfo.hh:85
NodeInfoMap * pNodeInfoMap
Definition: NodeInfo.hh:227
xmlNodePtr getNextChild()
Get the next child of the parent specified in the last getFirstChild() call, the class remembers the ...
Definition: XMLIO.cpp:466
enum eNodeType GetNodeType(const osg::ref_ptr< osg::Node > node)
Definition: NodeInfo.hh:48
bool NodeHasNodeInfo(osg::Node *node) const
Definition: NodeInfo.hh:206
eNodeType NodeType
Definition: NodeInfo.hh:80
container for scene root and ptr to nodeinfomap
Definition: NodeInfo.hh:224
struct containing details of a OSG::Node when used in a wxTreeCtrlOpenSGWx
Definition: NodeInfo.hh:61
bool getAttributeValueBool(const xmlAttrPtr Attribute) const
Get the value of a given Attribute, with type-cast overloads for different attribute types...
Definition: XMLIO.cpp:700
bool IsExpanded
Definition: NodeInfo.hh:83
static std::string NodeTypeXMLStrings[]
Definition: NodeInfo.hh:26
double SizeMM
Definition: NodeInfo.hh:86
virtual int XMLOut(const xmlNodePtr Node, BIAS::XMLIO &XMLObject) const
derived classes must implement this to write the code of (*this) into the XML tree.
Definition: NodeInfo.hh:133
bool IsEditable
Definition: NodeInfo.hh:82
std::string getAttributeValueString(const xmlAttrPtr Attribute) const
Definition: XMLIO.cpp:716
enum eNodeType String2NodeType(const std::string &val)
Definition: NodeInfo.hh:35
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
xmlNodePtr getFirstChild(const xmlNodePtr ParentNode)
Get the first child of a given parent, or NULL for no childs.
Definition: XMLIO.cpp:452
bool AreKeyPointersValid()
Definition: NodeInfo.hh:211
bool areKeyPointersValid_
Definition: NodeInfo.hh:214
osg::ref_ptr< osg::Node > RootNode
Definition: NodeInfo.hh:226
virtual int XMLIn(const xmlNodePtr Node, BIAS::XMLIO &XMLObject)
derived classes must implement this to read everything in Node into (*this).
Definition: NodeInfo.hh:175
virtual int XMLOut(const xmlNodePtr Node, BIAS::XMLIO &XMLObject) const
derived classes must implement this to write the code of (*this) into the XML tree.
Definition: NodeInfo.hh:195
Base class with interface for xml output.
Definition: XMLBase.hh:56
std::string Id
Definition: NodeInfo.hh:89
unsigned long long MarkerID
Definition: NodeInfo.hh:87
virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
derived classes must implement this, so that it returns the name of the class for the top level tag i...
Definition: NodeInfo.hh:91
std::string FileName
Definition: NodeInfo.hh:77
std::string Name
Definition: NodeInfo.hh:74
virtual int XMLIn(const xmlNodePtr Node, BIAS::XMLIO &XMLObject)
derived classes must implement this to read everything in Node into (*this).
Definition: NodeInfo.hh:98
bool IsOccluder
Definition: NodeInfo.hh:84
std::string NodeType2String(const enum eNodeType &t)
Definition: NodeInfo.hh:45
bool IsVisible
Definition: NodeInfo.hh:81
static bool HasInfo(const osg::ref_ptr< osg::Node > node, const std::string &key, std::string &value)
Checks if the node contains additional information in form of a key value pair.
eNodeType
Definition: NodeInfo.hh:16