IVPointParser.hpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <cassert>
27#include <fstream>
28#include <iostream>
29#include <string>
30
31//Eigen
32#include <Eigen/Core>
33
35
37{
38public:
39 static std::vector<Eigen::Vector3f>
40 fromFile(const std::string& fileName)
41 {
42 std::vector<Eigen::Vector3f> ps;
43
44 std::ifstream file(fileName.c_str(), std::ifstream::in);
45
46 if (file.is_open())
47 {
48 std::string word;
49
50 //Find the points
51 while (file >> word)
52 {
53 if (word.find("Coordinate3") != std::string::npos)
54 {
55 break;
56 }
57 }
58
59 //Skip first {
60 file >> word;
61 //Should be "point"
62 file >> word;
63 assert(word.find("point") != std::string::npos);
64
65 //Skip next [
66 file >> word;
67
68 //Start with the points
69 while (true)
70 {
71 double x, y, z;
72 file >> x >> y >> z;
73
74 if (file.fail())
75 {
76 break;
77 }
78
79 file.get(); //Last comma
80
81 Eigen::Vector3f v;
82 v << x, y, z;
83 ps.push_back(v);
84 }
85
86 file.close();
87 }
88 else
89 {
90 ARMARX_WARNING_S << "Could not open IV file to parse points" << armarx::flush;
91 }
92
93 return ps;
94 }
95};
static std::vector< Eigen::Vector3f > fromFile(const std::string &fileName)
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:213
This file offers overloads of toIce() and fromIce() functions for STL container types.
const LogSender::manipulator flush
Definition LogSender.h:251