-
Notifications
You must be signed in to change notification settings - Fork 0
/
off_helpers.h
48 lines (38 loc) · 1.08 KB
/
off_helpers.h
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
39
40
41
42
43
44
45
46
47
48
#ifndef OFF_HELPERS_H_
#define OFF_HELPERS_H_
#include <fstream>
#include <pcl/common/io.h>
#include <pcl/PolygonMesh.h>
#include <pcl/PCLPointCloud2.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
void loadOFFFile(const std::string& path, pcl::PolygonMesh &mesh) {
std::ifstream ifs(path, std::ifstream::in);
// Ignore the first line
ifs.ignore(4);
// Read the mesh size
size_t n_vertices, n_faces, _;
ifs >> n_vertices >> n_faces >> _;
// Read vertices
pcl::PointCloud<pcl::PointXYZ> vertices;
for (size_t i = 0; i < n_vertices; ++i) {
float x, y, z;
ifs >> x >> y >> z;
vertices.push_back(pcl::PointXYZ(x, y, z));
}
pcl::toPCLPointCloud2(vertices, mesh.cloud);
// Read faces
for (size_t i = 0; i < n_faces; ++i) {
pcl::Vertices face;
size_t size;
ifs >> size;
for (size_t j = 0; j < size; ++j) {
uint32_t vid;
ifs >> vid;
face.vertices.push_back(vid);
}
mesh.polygons.push_back(face);
}
ifs.close();
}
#endif