File: read_polylines.h

package info (click to toggle)
cgal 5.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 121,084 kB
  • sloc: cpp: 742,056; ansic: 182,102; sh: 647; python: 411; makefile: 280; javascript: 110
file content (29 lines) | stat: -rw-r--r-- 650 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
#ifndef READ_POLYLINES_H
#define READ_POLYLINES_H

#include <cstddef>
#include <vector>
#include <fstream>

template <typename Point_3>
bool read_polylines(const char* fname,
                    std::vector<std::vector<Point_3> >& polylines)
{
  std::ifstream ifs(fname);
  if(ifs.bad()) return false;
  std::size_t n;
  while(ifs >> n) {
    polylines.resize(polylines.size()+1);
    std::vector<Point_3>& polyline = polylines.back();
    while(n-- != 0) {
      Point_3 p;
      ifs >> p;
      if(ifs.fail()) return false;
      polyline.push_back(p);
    }
  }
  if(ifs.bad()) return false;
  else return ifs.eof();
}

#endif // READ_POLYLINES_H