File: read_xml.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (38 lines) | stat: -rw-r--r-- 1,163 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>

#include <vector>
#include <fstream>

typedef CGAL::Exact_predicates_inexact_constructions_kernel  K;
typedef K::Point_3                                Point_3;

int main(int argc, char* argv[])
{
  std::ifstream in( (argc>1)? argv[1] : "data/cloud.pol");
  boost::property_tree::ptree tree;
  boost::property_tree::read_xml(in, tree);

  std::vector<Point_3> points;

  for(boost::property_tree::ptree::value_type& node : tree.get_child("PolySet.Polygon")){
    boost::property_tree::ptree subtree = node.second;
    if( node.first == "Point" ){
      for( boost::property_tree::ptree::value_type const& v : subtree.get_child( "" ) ) {
        std::string label = v.first;

        if ( label == "<xmlattr>" ) {
          Point_3 p(subtree.get<double>( label+".X"),
                    subtree.get<double>( label+".Y"),
                    subtree.get<double>( label+".Z"));
          points.push_back(p);
        }
      }
    }
  }

  std::cout << points.size() << " points read"<< std::endl;
  return 0;
}