23 namespace visualization {
27 static const Eigen::Vector3d kDefaultVoxelColor(0.5, 0.5, 0.5);
30 const static std::vector<Eigen::Vector3i> kCuboidVertexOffsets{
38 const static std::vector<Eigen::Vector3i> kCuboidTrianglesVertexIndices{
48 const static std::vector<Eigen::Vector2i> kCuboidLinesVertexIndices{
55 static void AddVoxelFaces(
ccMesh& mesh,
56 const std::vector<Eigen::Vector3d>& vertices,
57 const Eigen::Vector3d&
color) {
59 kCuboidTrianglesVertexIndices) {
62 mesh.
addVertice(vertices[triangle_vertex_indices(0)]);
63 mesh.
addVertice(vertices[triangle_vertex_indices(1)]);
64 mesh.
addVertice(vertices[triangle_vertex_indices(2)]);
71 static void AddLineFace(
ccMesh& mesh,
72 const Eigen::Vector3d& start,
73 const Eigen::Vector3d& end,
74 const Eigen::Vector3d& half_width,
75 const Eigen::Vector3d&
color) {
89 static std::shared_ptr<ccMesh> CreateTriangleMeshFromVoxelGrid(
90 const geometry::VoxelGrid& voxel_grid) {
93 auto mesh = std::make_shared<ccMesh>(baseVertices);
94 auto num_voxels = voxel_grid.voxels_.size();
95 if (!baseVertices->
reserve(
static_cast<unsigned>(36 * num_voxels))) {
102 std::vector<Eigen::Vector3d>
104 for (
auto& it : voxel_grid.voxels_) {
106 const geometry::Voxel& voxel = it.second;
108 const Eigen::Matrix3d scaled_rot =
109 voxel_grid.rotation_ * voxel_grid.voxel_size_;
110 Eigen::Vector3d base_vertex =
112 scaled_rot * voxel.grid_index_.cast<
double>();
114 vertices.push_back(base_vertex +
115 scaled_rot * vertex_offset.cast<
double>());
119 Eigen::Vector3d voxel_color;
120 if (voxel_grid.HasColors()) {
121 voxel_color = voxel.color_;
123 voxel_color = kDefaultVoxelColor;
126 AddVoxelFaces(*mesh, vertices, voxel_color);
147 static std::shared_ptr<ccMesh> CreateTriangleMeshFromOctree(
148 const geometry::Octree&
octree) {
149 auto mesh = std::make_shared<ccMesh>();
150 if (!mesh->CreateInternalCloud()) {
158 double line_half_width = 0.0015 *
octree.size_;
160 auto f = [&mesh = *mesh, line_half_width](
161 const std::shared_ptr<geometry::OctreeNode>& node,
162 const std::shared_ptr<geometry::OctreeNodeInfo>& node_info)
164 Eigen::Vector3d base_vertex = node_info->origin_.cast<
double>();
165 std::vector<Eigen::Vector3d> vertices;
167 vertices.push_back(base_vertex + vertex_offset.cast<
double>() *
168 double(node_info->size_));
172 std::dynamic_pointer_cast<geometry::OctreeColorLeafNode>(node);
174 AddVoxelFaces(mesh, vertices, leaf_node->color_);
179 kCuboidLinesVertexIndices) {
180 auto& start = vertices[line_vertex_indices(0)];
181 auto& end = vertices[line_vertex_indices(1)];
182 Eigen::Vector3d w(line_half_width, 0.0, 0.0);
184 if (
std::abs(end.y() - start.y()) < 0.1 &&
185 std::abs(end.z() - start.z()) < 0.1) {
186 w = {0.0, 0.0, line_half_width};
188 AddLineFace(mesh, start, end, w, {0.0, 0.0, 0.0});
190 w = {0.0, line_half_width, 0.0};
192 if (
std::abs(end.x() - start.x()) < 0.1 &&
193 std::abs(end.z() - start.z()) < 0.1) {
194 w = {0.0, 0.0, line_half_width};
196 AddLineFace(mesh, start, end, w, {0.0, 0.0, 0.0});
216 std::shared_ptr<geometry::LineSet> lines_;
225 std::shared_ptr<ccMesh> mesh_;
234 return std::make_unique<TriangleMeshBuffersBuilder>(
235 static_cast<const ccMesh&
>(geometry));
238 return std::make_unique<PointCloudBuffersBuilder>(
242 return std::make_unique<LineSetBuffersBuilder>(
247 lines->PaintUniformColor(obb.color_);
248 return std::make_unique<TemporaryLineSetBuilder>(lines);
251 auto aabb =
static_cast<const ccBBox&
>(geometry);
254 lines->PaintUniformColor(aabb.GetColor());
255 return std::make_unique<TemporaryLineSetBuilder>(lines);
259 auto mesh = CreateTriangleMeshFromVoxelGrid(voxel_grid);
260 return std::make_unique<TemporaryMeshBuilder>(mesh);
264 auto mesh = CreateTriangleMeshFromOctree(
octree);
268 return std::make_unique<TemporaryMeshBuilder>(mesh);
286 return std::make_unique<TGaussianSplatBuffersBuilder>(
289 return std::make_unique<TPointCloudBuffersBuilder>(pointcloud);
293 return std::make_unique<TMeshBuffersBuilder>(
296 return std::make_unique<TLineSetBuffersBuilder>(
Array of compressed 3D normals (single index)
Hierarchical CLOUDVIEWER Object.
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
CV_CLASS_ENUM getClassID() const override
Returns class ID.
NormsIndexesTableType * getTriNormsTable() const override
Returns per-triangle normals shared array.
void addVertice(const Eigen::Vector3d &vertice)
void addTriangle(unsigned i1, unsigned i2, unsigned i3)
Adds a triangle to the mesh.
unsigned int getVerticeSize() const
void shrinkToFit()
Removes unused capacity.
void addVertexColor(const Eigen::Vector3d &color)
virtual void setLocked(bool state)
Sets the "enabled" property.
virtual void setEnabled(bool state)
Sets the "enabled" property.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool reserve(unsigned numberOfPoints) override
Reserves memory for all the active features.
bool reserveTheRGBTable()
Reserves memory to store the RGB colors.
void shrinkToFit()
Removes unused capacity.
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
static std::shared_ptr< LineSet > CreateFromOrientedBoundingBox(const ecvOrientedBBox &box)
Factory function to create a LineSet from an OrientedBoundingBox.
static std::shared_ptr< LineSet > CreateFromAxisAlignedBoundingBox(const ccBBox &box)
Factory function to create a LineSet from an ccBBox.
VoxelGrid is a collection of voxels which are aligned in grid.
GeometryType
Specifies possible geometry types.
GeometryType GetGeometryType() const
Returns one of registered geometry types.
A LineSet contains points and lines joining them and optionally attributes on the points and lines.
A point cloud contains a list of 3D points.
bool IsGaussianSplat() const
A triangle mesh contains vertices and triangles.
static void DeallocateBuffer(void *buffer, size_t size, void *user_ptr)
static std::unique_ptr< GeometryBuffersBuilder > GetBuilder(const ccHObject &geometry)
TemporaryLineSetBuilder(std::shared_ptr< geometry::LineSet > lines)
TemporaryMeshBuilder(std::shared_ptr< ccMesh > mesh)
__host__ __device__ int2 abs(int2 v)
::ccPointCloud PointCloud
Generic file read and write utility for python interface.
Eigen::Matrix< Index, 3, 1 > Vector3i
Eigen::Matrix< Index, 2, 1 > Vector2i