ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
pc_io.cpp
Go to the documentation of this file.
1 /* License Information
2  *
3  * Copyright (C) ONERA, The French Aerospace Lab
4  * Author: Alexandre BOULCH
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  *
25  * Note that this library relies on external libraries subject to their own
26  * license. To use this software, you are subject to the dependencies license,
27  * these licenses applies to the dependency ONLY and NOT this code. Please
28  * refer below to the web sites for license informations: PCL, BOOST,NANOFLANN,
29  * EIGEN, LUA TORCH
30  *
31  * When using the software please aknowledge the corresponding publication:
32  * "Deep Learning for Robust Normal Estimation in Unstructured Point Clouds "
33  * by Alexandre Boulch and Renaud Marlet
34  * Symposium of Geometry Processing 2016, Computer Graphics Forum
35  */
36 
37 #include "pc_io.h"
38 
39 #include <fstream>
40 #include <iostream>
41 #include <sstream>
42 #include <vector>
43 
44 using namespace std;
45 
46 void pc_load(const std::string& filename, Eigen::MatrixX3d& pc) {
47  ifstream istr(filename.c_str());
48  vector<Eigen::Vector3d> points;
49  string line;
50  double x, y, z;
51  while (getline(istr, line)) {
52  stringstream sstr("");
53  sstr << line;
54  sstr >> x >> y >> z;
55  points.push_back(Eigen::Vector3d(x, y, z));
56  }
57  istr.close();
58  pc.resize(points.size(), 3);
59  for (int i = 0; i < points.size(); i++) {
60  pc.row(i) = points[i];
61  }
62 }
63 
64 void pc_save(const std::string& filename,
65  const Eigen::MatrixX3d& pc,
66  const Eigen::MatrixX3d& normals) {
67  ofstream ofs(filename.c_str());
68  for (int i = 0; i < pc.rows(); i++) {
69  ofs << pc(i, 0) << " ";
70  ofs << pc(i, 1) << " ";
71  ofs << pc(i, 2) << " ";
72  ofs << normals(i, 0) << " ";
73  ofs << normals(i, 1) << " ";
74  ofs << normals(i, 2) << endl;
75  }
76  ofs.close();
77 }
std::string filename
int points
double normals[3]
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
Definition: Eigen.h:85
void pc_load(const std::string &filename, Eigen::MatrixX3d &pc)
Definition: pc_io.cpp:46
void pc_save(const std::string &filename, const Eigen::MatrixX3d &pc, const Eigen::MatrixX3d &normals)
Definition: pc_io.cpp:64