gtsam_points
Loading...
Searching...
No Matches
mesh_utils.hpp
Go to the documentation of this file.
1#ifndef GLK_PRIMITIVES_MESH_UTILS_HPP
2#define GLK_PRIMITIVES_MESH_UTILS_HPP
3
4#include <vector>
5#include <Eigen/Core>
6#include <Eigen/Geometry>
7
8namespace glk {
9
10class Flatize {
11public:
12 Flatize(const std::vector<Eigen::Vector3f>& vertices_, const std::vector<int>& indices_) {
13 vertices.resize(indices_.size());
14 normals.resize(indices_.size());
15 indices.resize(indices_.size());
16 for (int i = 0; i < indices_.size(); i += 3) {
17 Eigen::Vector3f v1 = vertices_[indices_[i]];
18 Eigen::Vector3f v2 = vertices_[indices_[i + 1]];
19 Eigen::Vector3f v3 = vertices_[indices_[i + 2]];
20
21 Eigen::Vector3f n = (v2 - v1).cross(v3 - v2);
22
23 for (int j = 0; j < 3; j++) {
24 vertices[i + j] = vertices_[indices_[i + j]];
25 normals[i + j] = n;
26 indices[i + j] = i + j;
27 }
28 }
29 }
30
31public:
32 std::vector<Eigen::Vector3f> vertices;
33 std::vector<Eigen::Vector3f> normals;
34 std::vector<int> indices;
35};
36
38public:
39 NormalEstimater(const std::vector<Eigen::Vector3f>& vertices, const std::vector<int>& indices) {
40 normals.resize(vertices.size(), Eigen::Vector3f::Zero());
41 for (int i = 0; i < indices.size(); i += 3) {
42 Eigen::Vector3f v1 = vertices[indices[i]];
43 Eigen::Vector3f v2 = vertices[indices[i + 1]];
44 Eigen::Vector3f v3 = vertices[indices[i + 2]];
45
46 Eigen::Vector3f n = (v2 - v1).cross(v3 - v2);
47
48 normals[indices[i]] += n;
49 normals[indices[i + 1]] += n;
50 normals[indices[i + 2]] += n;
51 }
52
53 for (auto& normal : normals) {
54 normal.normalize();
55 }
56 }
57
58public:
59 std::vector<Eigen::Vector3f> normals;
60};
61
62} // namespace glk
63
64#endif
Definition mesh_utils.hpp:10
Flatize(const std::vector< Eigen::Vector3f > &vertices_, const std::vector< int > &indices_)
Definition mesh_utils.hpp:12
std::vector< int > indices
Definition mesh_utils.hpp:34
std::vector< Eigen::Vector3f > vertices
Definition mesh_utils.hpp:32
std::vector< Eigen::Vector3f > normals
Definition mesh_utils.hpp:33
Definition mesh_utils.hpp:37
NormalEstimater(const std::vector< Eigen::Vector3f > &vertices, const std::vector< int > &indices)
Definition mesh_utils.hpp:39
std::vector< Eigen::Vector3f > normals
Definition mesh_utils.hpp:59
Definition async_buffer_copy.hpp:6
std::enable_if_t< needs_aligned_allocator< T >::value, std::shared_ptr< T > > make_shared(Args &&... args)
Definition make_shared.hpp:20