CropBoxWrapper.cpp
Go to the documentation of this file.
1 
21 #include <rapidxml.hpp>
22 #include <rapidxml_utils.hpp>
23 
24 namespace next_best_view {
25 
26  CropBoxWrapper::CropBoxWrapper(CropBoxPtr cropBoxPtr, boost::shared_ptr<std::vector<SimpleVector3>> cropBoxNormalsListPtr) {
27  this->mCropBoxPtr = cropBoxPtr;
28  this->mCropBoxNormalsListPtr = cropBoxNormalsListPtr;
29  }
30 
32  return mCropBoxPtr;
33  }
34 
37  }
38 
40  this->mCropBoxPtr = cropBoxPtr;
41  }
42 
43  void CropBoxWrapper::setCropBoxNormalsList(boost::shared_ptr<std::vector<SimpleVector3>> cropBoxNormalsListPtr) {
44  this->mCropBoxNormalsListPtr = cropBoxNormalsListPtr;
45  }
46 
48  auto cropBoxPtrList = boost::make_shared<std::vector<CropBoxWrapperPtr>>();
49  DebugHelperPtr debugHelperPtr = DebugHelper::getInstance();
50  debugHelperPtr->write(std::stringstream() << "Path to CropBoxList xml file: " << xml_path,
52  try {
53  rapidxml::file<> xmlFile(xml_path.c_str());
54  rapidxml::xml_document<> doc;
55  doc.parse<0>(xmlFile.data());
56 
57  rapidxml::xml_node<> *root_node = doc.first_node();
58  if (root_node) {
59  rapidxml::xml_node<> *child_node = root_node->first_node();
60 
61  while (child_node)
62  {
63  CropBoxPtr bufferCropBoxPtr = CropBoxPtr(new CropBox);
64  rapidxml::xml_node<> * min_pt = child_node->first_node("min_pt");
65  rapidxml::xml_attribute<> *x = min_pt->first_attribute("x");
66  rapidxml::xml_attribute<> *y = min_pt->first_attribute("y");
67  rapidxml::xml_attribute<> *z = min_pt->first_attribute("z");
68  if (x && y && z)
69  {
70  double x_ = boost::lexical_cast<double>(x->value());
71  double y_ = boost::lexical_cast<double>(y->value());
72  double z_ = boost::lexical_cast<double>(z->value());
73  Eigen::Vector4f pt_min(x_,y_,z_,1);
74  bufferCropBoxPtr->setMin(pt_min);
75  }
76 
77  rapidxml::xml_node<> * max_pt = child_node->first_node("max_pt");
78  x = max_pt->first_attribute("x");
79  y = max_pt->first_attribute("y");
80  z = max_pt->first_attribute("z");
81  if (x && y && z)
82  {
83  double x_ = boost::lexical_cast<double>(x->value());
84  double y_ = boost::lexical_cast<double>(y->value());
85  double z_ = boost::lexical_cast<double>(z->value());
86  Eigen::Vector4f pt_max(x_,y_,z_,1);
87  bufferCropBoxPtr->setMax(pt_max);
88  }
89 
90  rapidxml::xml_node<> * rotation = child_node->first_node("rotation");
91  x = rotation->first_attribute("x");
92  y = rotation->first_attribute("y");
93  z = rotation->first_attribute("z");
94  if (x && y && z)
95  {
96  double x_ = boost::lexical_cast<double>(x->value());
97  double y_ = boost::lexical_cast<double>(y->value());
98  double z_ = boost::lexical_cast<double>(z->value());
99  Eigen::Vector3f rotation(x_,y_,z_);
100  bufferCropBoxPtr->setRotation(rotation);
101  }
102 
103  rapidxml::xml_node<> * translation = child_node->first_node("translation");
104  x = translation->first_attribute("x");
105  y = translation->first_attribute("y");
106  z = translation->first_attribute("z");
107  if (x && y && z)
108  {
109  double x_ = boost::lexical_cast<double>(x->value());
110  double y_ = boost::lexical_cast<double>(y->value());
111  double z_ = boost::lexical_cast<double>(z->value());
112  Eigen::Vector3f translation(x_,y_,z_);
113  bufferCropBoxPtr->setTranslation(translation);
114  }
115 
116  int normalsCount = 0;
117  auto normals = boost::make_shared<std::vector<SimpleVector3>>();
118  char search[100];
119  sprintf(search, "normal_%d", normalsCount);
120  rapidxml::xml_node<> * normalsXML = child_node->first_node(search);
121  while (normalsXML != nullptr) {
122  x = normalsXML->first_attribute("x");
123  y = normalsXML->first_attribute("y");
124  z = normalsXML->first_attribute("z");
125  if (x && y && z)
126  {
127  double x_ = boost::lexical_cast<double>(x->value());
128  double y_ = boost::lexical_cast<double>(y->value());
129  double z_ = boost::lexical_cast<double>(z->value());
130  SimpleVector3 normal(x_, y_, z_);
131  normals->push_back(normal);
132  }
133  ++normalsCount;
134  std::fill(search, search + sizeof(search)/sizeof(search[0]), 0);
135  sprintf(search, "normal_%d", normalsCount);
136  normalsXML = child_node->first_node(search);
137  }
138  CropBoxWrapperPtr cropBoxWrapperPtr = CropBoxWrapperPtr(new CropBoxWrapper(bufferCropBoxPtr, normals));
139 
140  cropBoxPtrList->push_back(cropBoxWrapperPtr);
141  child_node = child_node->next_sibling();
142  }
143  }
144  } catch(std::runtime_error err) {
145  ROS_ERROR_STREAM("Can't parse xml-file. Runtime error: " << err.what());
146  } catch (rapidxml::parse_error err) {
147  ROS_ERROR_STREAM("Can't parse xml-file Parse error: " << err.what());
148  }
149  return cropBoxPtrList;
150  }
151 }
boost::shared_ptr< std::vector< SimpleVector3 > > getCropBoxNormalsList()
static boost::shared_ptr< std::vector< CropBoxWrapperPtr > > readCropBoxDataFromXMLFile(const std::string &xml_path)
readCropBoxDataFromXMLFile reads the given xml file and returns a list of CropBoxWrapper.
boost::shared_ptr< CropBoxWrapper > CropBoxWrapperPtr
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
Definition: typedef.hpp:53
CropBoxWrapper(CropBoxPtr cropBoxPtr, boost::shared_ptr< std::vector< SimpleVector3 >> cropBoxNormalsListPtr)
void setCropBoxNormalsList(boost::shared_ptr< std::vector< SimpleVector3 >> cropBoxNormalsListPtr)
TFSIMD_FORCE_INLINE const tfScalar & y() const
pcl::CropBox< ObjectPoint > CropBox
Definition: typedef.hpp:105
this namespace contains all generally usable classes.
static boost::shared_ptr< DebugHelper > getInstance()
Definition: DebugHelper.cpp:29
CropBox::Ptr CropBoxPtr
Definition: typedef.hpp:106
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & z() const
void setCropBox(CropBoxPtr cropBoxPtr)
#define ROS_ERROR_STREAM(args)
ROSCPP_DECL bool search(const std::string &ns, const std::string &key, std::string &result)
boost::shared_ptr< std::vector< SimpleVector3 > > mCropBoxNormalsListPtr


asr_next_best_view
Author(s): Aumann Florian, Borella Jocelyn, Heller Florian, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
autogenerated on Thu Jan 9 2020 07:20:18