10 #include <Eigen/Dense>
11 #include <unordered_set>
26 const std::vector<std::pair<int, int>> &correspondences) {
28 unsigned int point0_size = cloud0.
size();
29 unsigned int point1_size = cloud1.
size();
30 lineset_ptr->points_.resize(point0_size + point1_size);
31 for (
unsigned int i = 0; i < point0_size; i++)
33 for (
unsigned int i = 0; i < point1_size; i++)
36 size_t corr_size = correspondences.size();
38 for (
size_t i = 0; i < corr_size; i++)
41 point0_size + correspondences[i].second);
46 auto line_set = std::make_shared<LineSet>();
52 auto InsertEdge = [&](
int vidx0,
int vidx1) {
54 if (inserted_edges.count(edge) == 0) {
55 inserted_edges.insert(edge);
60 for (
unsigned int i = 0; i < mesh.
size(); ++i) {
63 InsertEdge(tri->
i1, tri->
i2);
64 InsertEdge(tri->
i2, tri->
i3);
65 InsertEdge(tri->
i3, tri->
i1);
73 auto line_set = std::make_shared<LineSet>();
87 line_set->PaintUniformColor(box.
GetColor());
93 auto line_set = std::make_shared<LineSet>();
107 line_set->PaintUniformColor(box.
GetColor());
112 auto line_set = std::make_shared<LineSet>();
118 auto InsertEdge = [&](
int vidx0,
int vidx1) {
120 if (inserted_edges.count(edge) == 0) {
121 inserted_edges.insert(edge);
125 for (
const auto &tetra : mesh.
tetras_) {
126 InsertEdge(tetra(0), tetra(1));
127 InsertEdge(tetra(1), tetra(2));
128 InsertEdge(tetra(2), tetra(0));
129 InsertEdge(tetra(3), tetra(0));
130 InsertEdge(tetra(3), tetra(1));
131 InsertEdge(tetra(3), tetra(2));
140 const Eigen::Matrix3d &intrinsic,
141 const Eigen::Matrix4d &extrinsic,
143 Eigen::Matrix4d intrinsic4;
144 intrinsic4 << intrinsic(0, 0), intrinsic(0, 1), intrinsic(0, 2), 0.0,
145 intrinsic(1, 0), intrinsic(1, 1), intrinsic(1, 2), 0.0,
146 intrinsic(2, 0), intrinsic(2, 1), intrinsic(2, 2), 0.0, 0.0, 0.0,
148 Eigen::Matrix4d m = (intrinsic4 * extrinsic).inverse();
149 auto lines = std::make_shared<geometry::LineSet>();
151 auto mult = [](
const Eigen::Matrix4d &m,
152 const Eigen::Vector3d &v) -> Eigen::Vector3d {
153 Eigen::Vector4d v4(v.x(), v.y(), v.z(), 1.0);
158 double w = double(view_width_px);
159 double h = double(view_height_px);
164 lines->points_.push_back(mult(m, Eigen::Vector3d{0.0, 0.0, 0.0}));
165 lines->points_.push_back(mult(m, Eigen::Vector3d{0.0, 0.0, scale}));
166 lines->points_.push_back(mult(m, Eigen::Vector3d{w * scale, 0.0, scale}));
167 lines->points_.push_back(
168 mult(m, Eigen::Vector3d{w * scale, h * scale, scale}));
169 lines->points_.push_back(mult(m, Eigen::Vector3d{0.0, h * scale, scale}));
171 lines->lines_.push_back({0, 1});
172 lines->lines_.push_back({0, 2});
173 lines->lines_.push_back({0, 3});
174 lines->lines_.push_back({0, 4});
175 lines->lines_.push_back({1, 2});
176 lines->lines_.push_back({2, 3});
177 lines->lines_.push_back({3, 4});
178 lines->lines_.push_back({4, 1});
179 lines->PaintUniformColor({0.0f, 0.0f, 1.0f});
182 lines->points_.push_back(
183 mult(m, Eigen::Vector3d{intrinsic(0, 0) * scale, 0.0, 0.0}));
184 lines->points_.push_back(
185 mult(m, Eigen::Vector3d{0.0, intrinsic(1, 1) * scale, 0.0}));
186 lines->points_.push_back(
187 mult(m, Eigen::Vector3d{intrinsic(0, 2) * scale,
188 intrinsic(1, 2) * scale, scale}));
191 lines->lines_.push_back({0, 5});
192 lines->lines_.push_back({0, 6});
193 lines->lines_.push_back({0, 7});
196 lines->colors_.push_back({1.0f, 0.0f, 0.0f});
197 lines->colors_.push_back({0.0f, 1.0f, 0.0f});
198 lines->colors_.push_back({0.0f, 0.0f, 1.0f});
geometry::LineSet * lineset_ptr
std::vector< Eigen::Vector3d > GetBoxPoints() const
Returns the eight points that define the bounding box.
virtual unsigned size() const override
Returns the number of triangles.
std::vector< Eigen::Vector3d > getEigenVertices() const
cloudViewer::VerticesIndexes * getTriangleVertIndexes(unsigned triangleIndex) override
Returns the indexes of the vertices of a given triangle.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Eigen::Vector3d GetColor() const
Gets the bounding box color.
std::vector< Eigen::Vector3d > GetBoxPoints() const
const Eigen::Vector3d & GetColor() const
Gets the bounding box color.
unsigned size() const override
Eigen::Vector3d getEigenPoint(size_t index) const
static std::shared_ptr< LineSet > CreateFromTetraMesh(const TetraMesh &mesh)
static std::shared_ptr< LineSet > CreateFromOrientedBoundingBox(const ecvOrientedBBox &box)
Factory function to create a LineSet from an OrientedBoundingBox.
static std::shared_ptr< LineSet > CreateFromPointCloudCorrespondences(const ccPointCloud &cloud0, const ccPointCloud &cloud1, const std::vector< std::pair< int, int >> &correspondences)
Factory function to create a LineSet from two PointClouds (cloud0, cloud1) and a correspondence set.
static std::shared_ptr< LineSet > CreateFromTriangleMesh(const ccMesh &mesh)
static std::shared_ptr< LineSet > CreateCameraVisualization(int view_width_px, int view_height_px, const Eigen::Matrix3d &intrinsic, const Eigen::Matrix4d &extrinsic, double scale=1.0)
static std::shared_ptr< LineSet > CreateFromAxisAlignedBoundingBox(const ccBBox &box)
Factory function to create a LineSet from an ccBBox.
Tetra mesh contains vertices and tetrahedra represented by the indices to the vertices.
std::vector< Eigen::Vector4i, cloudViewer::utility::Vector4i_allocator > tetras_
List of tetras denoted by the index of points forming the tetra.
std::vector< Eigen::Vector3d > vertices_
Vertex coordinates.
Generic file read and write utility for python interface.
Eigen::Matrix< Index, 2, 1 > Vector2i
Triangle described by the indexes of its 3 vertices.