KdTreeXml.hpp
Go to the documentation of this file.
1 // ========================================================================================
2 // ApproxMVBB
3 // Copyright (C) 2014 by Gabriel Nützi <nuetzig (at) imes (d0t) mavt (d0t) ethz (døt) ch>
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 // ========================================================================================
9 
10 #ifndef ApproxMVBB_KdTreeXml_hpp
11 #define ApproxMVBB_KdTreeXml_hpp
12 
13 #ifndef ApproxMVBB_SUPPORT_XML
14  #warning "Your using the KdTreeXml header, which needs to be linked with the Xml library!"
15 #endif
16 
17 #include <pugixml.hpp>
18 
19 #include "KdTree.hpp"
20 
21 
22 namespace ApproxMVBB{
23 
24  namespace KdTree {
25 
26  class XML {
27 
28  public:
29  using XMLNodeType = pugi::xml_node;
30 
32  template<typename TTraits>
33  static void appendToXML(PointData<TTraits> const & obj, XMLNodeType & root){
34  using PointGetter = typename PointData<TTraits>::PointGetter;
35  static const auto nodePCData = pugi::node_pcdata;
36  XMLNodeType node = root.append_child("Points");
37  std::stringstream ss;
38  for(auto & p : obj){
39  ss << PointGetter::get(p).transpose().format(MyMatrixIOFormat::SpaceSep) << std::endl;
40  }
41  node.append_child(nodePCData).set_value( ss.str().c_str() );
42  }
43 
45  template<typename Traits>
46  static void appendToXML(TreeBase<Traits> const & obj, XMLNodeType kdNode){
47  using NodeType = typename TreeBase<Traits>::NodeType;
48  static const auto nodePCData = pugi::node_pcdata;
49  std::stringstream ss;
50  XMLNodeType r = kdNode.append_child("Root");
51  XMLNodeType aabb = r.append_child("AABB");
52  ss.str("");
53  ss << obj.m_root->aabb().m_minPoint.transpose().format(MyMatrixIOFormat::SpaceSep) <<" "
54  << obj.m_root->aabb().m_maxPoint.transpose().format(MyMatrixIOFormat::SpaceSep) << "\n";
55  aabb.append_child(nodePCData).set_value(ss.str().c_str());
56 
57  // Save leafs
58  XMLNodeType leafs = kdNode.append_child("Leafs");
59 
60  for(auto * l: obj.m_leafs) {
61  XMLNodeType node = leafs.append_child("Leaf");
62  node.append_attribute("level").set_value(l->getLevel());
63  node.append_attribute("idx").set_value(std::to_string(l->getIdx()).c_str());
64  aabb = node.append_child("AABB");
65  ss.str("");
66  ss << l->aabb().m_minPoint.transpose().format(MyMatrixIOFormat::SpaceSep) <<" "
67  << l->aabb().m_maxPoint.transpose().format(MyMatrixIOFormat::SpaceSep) << "\n";
68  aabb.append_child(nodePCData).set_value(ss.str().c_str());
69  }
70 
71  // Save AABB tree (breath first)
72  XMLNodeType aabbTree = kdNode.append_child("AABBTree");
73  std::deque<NodeType*> q; // Breath first queue
74 
75  q.push_back(obj.m_root);
76  unsigned int currLevel = obj.m_root->getLevel();
77  ss.str("");
78  while(q.size()>0) {
79  // Write stuff of f if not leaf
80  auto * f = q.front();
81 
82  if(f->getLevel() > currLevel) {
83  // write new string
84  aabb = aabbTree.append_child("AABBSubTree");
85  aabb.append_attribute("level").set_value(currLevel);
86  aabb.append_child(nodePCData).set_value( ss.str().c_str() );
87  // update to next level
88  currLevel = f->getLevel();
89  ss.str("");
90  }
91 
92  if(!f->isLeaf()) {
93  ss << f->aabb().m_minPoint.transpose().format(MyMatrixIOFormat::SpaceSep) <<" "
94  << f->aabb().m_maxPoint.transpose().format(MyMatrixIOFormat::SpaceSep) << "\n";
95  }
96 
97  // push the left/right
98  auto * n = f->leftNode();
99  if(n) {
100  q.push_back(n);
101  }
102  n = f->rightNode();
103  if(n) {
104  q.push_back(n);
105  }
106 
107  q.pop_front();
108  }
109 
110  // write last string
111  auto s = ss.str();
112  if(!s.empty()) {
113  aabb = aabbTree.append_child("AABBSubTree");
114  aabb.append_attribute("level").set_value(currLevel);
115  aabb.append_child(nodePCData).set_value( s.c_str() );
116  }
117  }
119  static void appendToXML(const TreeStatistics & obj, XMLNodeType & kdNode){
120 
121  auto stat = kdNode.append_child("Statistics");
122 
123  stat.append_attribute("m_computedTreeStats").set_value( obj.m_computedTreeStats );
124  stat.append_attribute("m_treeDepth").set_value( obj.m_treeDepth );
125  stat.append_attribute("m_avgSplitPercentage").set_value( obj.m_avgSplitPercentage );
126  stat.append_attribute("m_minLeafExtent").set_value( obj.m_minLeafExtent );
127  stat.append_attribute("m_maxLeafExtent").set_value( obj.m_maxLeafExtent );
128  stat.append_attribute("m_avgLeafSize").set_value( obj.m_avgLeafSize );
129  stat.append_attribute("m_minLeafDataSize").set_value( (long long unsigned int)obj.m_minLeafDataSize );
130  stat.append_attribute("m_maxLeafDataSize").set_value( (long long unsigned int)obj.m_maxLeafDataSize );
131  stat.append_attribute("m_computedNeighbourStats").set_value( (long long unsigned int)obj.m_computedNeighbourStats );
132  stat.append_attribute("m_minNeighbours").set_value( (long long unsigned int)obj.m_minNeighbours );
133  stat.append_attribute("m_maxNeighbours").set_value( (long long unsigned int)obj.m_maxNeighbours );
134  stat.append_attribute("m_avgNeighbours").set_value( obj.m_avgNeighbours );
135  }
136 
138  template<typename TTraits>
139  static void appendToXML(const Tree<TTraits> & obj, XMLNodeType & root, bool aligned = true,
140  const Matrix33 & A_IK = Matrix33::Identity()
141  /*,bool exportPoints = false*/) {
142  using Base = typename Tree<TTraits>::Base;
143 
144  static const auto nodePCData = pugi::node_pcdata;
145 
146  std::stringstream ss;
147  XMLNodeType node;
148  XMLNodeType kdNode = root.append_child("KdTree");
149 
150  kdNode.append_attribute("aligned").set_value( aligned );
151 
152  XMLNodeType a = kdNode.append_child("A_IK");
153  ss << A_IK.format(MyMatrixIOFormat::SpaceSep);
154  a.append_child(nodePCData).set_value(ss.str().c_str());
155 
156  appendToXML(static_cast<const Base &>(obj), kdNode);
157 
158  appendToXML(obj.m_statistics, kdNode);
159 
160  }
161 
163  template<typename TTraits>
164  static void appendToXML(const TreeSimple<TTraits> & obj,
165  XMLNodeType root,
166  bool aligned = true,
167  const Matrix33 & A_IK = Matrix33::Identity()) {
168  using Base = typename TreeSimple<TTraits>::Base;
169  static const auto nodePCData = pugi::node_pcdata;
170 
171  std::stringstream ss;
172  XMLNodeType node;
173  XMLNodeType kdNode = root.append_child("KdTree");
174 
175  kdNode.append_attribute("aligned").set_value( aligned );
176 
177  XMLNodeType a = kdNode.append_child("A_IK");
178  ss << A_IK.format(MyMatrixIOFormat::SpaceSep);
179  a.append_child(nodePCData).set_value(ss.str().c_str());
180 
181  appendToXML(static_cast<const Base &>(obj), kdNode);
182  appendToXML(obj.m_statistics, kdNode);
183 
184  }
185 
186  };
187 
188  }
189 }
190 #endif
NodeContainerType m_leafs
Only leaf nodes , continously index ordered: leafs[idx]->getIdx() < leafs[idx+1]->getIdx();.
Definition: KdTree.hpp:1568
static void appendToXML(const Tree< TTraits > &obj, XMLNodeType &root, bool aligned=true, const Matrix33 &A_IK=Matrix33::Identity())
Definition: KdTreeXml.hpp:139
These are some container definitions.
pugi::xml_node XMLNodeType
Definition: KdTreeXml.hpp:29
static void appendToXML(PointData< TTraits > const &obj, XMLNodeType &root)
Definition: KdTreeXml.hpp:33
typename Traits::PointGetter PointGetter
Definition: KdTree.hpp:177
static const Eigen::IOFormat SpaceSep
Eigen::Matrix< Scalar, 3, 3 > Matrix33
static void appendToXML(const TreeStatistics &obj, XMLNodeType &kdNode)
Definition: KdTreeXml.hpp:119
static void appendToXML(TreeBase< Traits > const &obj, XMLNodeType kdNode)
Definition: KdTreeXml.hpp:46
TreeStatistics m_statistics
Definition: KdTree.hpp:2344
std::string to_string(const T &n)
Definition: CygwinPatch.hpp:20
NodeType * m_root
Root node, has index 0!
Definition: KdTree.hpp:1571
static void appendToXML(const TreeSimple< TTraits > &obj, XMLNodeType root, bool aligned=true, const Matrix33 &A_IK=Matrix33::Identity())
Definition: KdTreeXml.hpp:164


asr_approx_mvbb
Author(s): Gassner Nikolai
autogenerated on Mon Jun 10 2019 12:38:08