ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
LineSet.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <memory>
12 #include <vector>
13 
14 #include "ecvHObject.h"
15 
16 class ccMesh;
17 class ccBBox;
18 class ecvOrientedBBox;
19 class ccPointCloud;
20 namespace cloudViewer {
21 namespace geometry {
22 
23 class TetraMesh;
24 
30 public:
32  LineSet(const char *name = "LineSet") : ccHObject(name) {}
39  LineSet(const std::vector<Eigen::Vector3d> &points,
40  const std::vector<Eigen::Vector2i> &lines,
41  const char *name = "LineSet")
42  : ccHObject(name), points_(points), lines_(lines) {}
43  ~LineSet() override {}
44 
45  // inherited methods (ccHObject)
46  virtual bool isSerializable() const override { return true; }
47 
49  virtual CV_CLASS_ENUM getClassID() const override {
50  return CV_TYPES::LINESET;
51  }
52 
53  virtual ccBBox getOwnBB(bool withGLFeatures = false) override;
54 
55 protected:
56  // inherited methods (ccHObject)
57  virtual void drawMeOnly(CC_DRAW_CONTEXT &context) override;
58 
59 public:
61  inline virtual bool IsEmpty() const override { return !HasPoints(); }
62  virtual Eigen::Vector3d GetMinBound() const override;
63  virtual Eigen::Vector3d GetMaxBound() const override;
64  virtual Eigen::Vector3d GetCenter() const override;
65  virtual ccBBox GetAxisAlignedBoundingBox() const override;
66  virtual ecvOrientedBBox GetOrientedBoundingBox() const override;
67  virtual LineSet &Transform(const Eigen::Matrix4d &transformation) override;
68  virtual LineSet &Translate(const Eigen::Vector3d &translation,
69  bool relative = true) override;
70  virtual LineSet &Scale(const double s,
71  const Eigen::Vector3d &center) override;
72  virtual LineSet &Rotate(const Eigen::Matrix3d &R,
73  const Eigen::Vector3d &center) override;
74 
75  LineSet &operator+=(const LineSet &lineset);
76  LineSet operator+(const LineSet &lineset) const;
77 
79  bool HasPoints() const { return points_.size() > 0; }
80 
82  bool HasLines() const { return HasPoints() && lines_.size() > 0; }
83 
85  bool HasColors() const {
86  return HasLines() && colors_.size() == lines_.size();
87  }
88 
92  std::pair<Eigen::Vector3d, Eigen::Vector3d> GetLineCoordinate(
93  size_t line_index) const {
94  return std::make_pair(points_[lines_[line_index][0]],
95  points_[lines_[line_index][1]]);
96  }
97 
101  LineSet &PaintUniformColor(const Eigen::Vector3d &color) {
102  ResizeAndPaintUniformColor(colors_, lines_.size(), color);
103  return *this;
104  }
105 
112  static std::shared_ptr<LineSet> CreateFromPointCloudCorrespondences(
113  const ccPointCloud &cloud0,
114  const ccPointCloud &cloud1,
115  const std::vector<std::pair<int, int>> &correspondences);
116 
120  static std::shared_ptr<LineSet> CreateFromOrientedBoundingBox(
121  const ecvOrientedBBox &box);
122 
127  static std::shared_ptr<LineSet> CreateFromAxisAlignedBoundingBox(
128  const ccBBox &box);
129 
133  static std::shared_ptr<LineSet> CreateFromTriangleMesh(const ccMesh &mesh);
134 
138  static std::shared_ptr<LineSet> CreateFromTetraMesh(const TetraMesh &mesh);
139 
147  static std::shared_ptr<LineSet> CreateCameraVisualization(
148  int view_width_px,
149  int view_height_px,
150  const Eigen::Matrix3d &intrinsic,
151  const Eigen::Matrix4d &extrinsic,
152  double scale = 1.0);
153 
154 public:
156  std::vector<Eigen::Vector3d> points_;
158  std::vector<Eigen::Vector2i> lines_;
160  std::vector<Eigen::Vector3d> colors_;
161 };
162 
163 } // namespace geometry
164 } // namespace cloudViewer
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
Definition: CVTypes.h:97
#define CV_DB_LIB_API
Definition: CV_db.h:15
std::string name
int points
math::float4 color
Bounding box structure.
Definition: ecvBBox.h:25
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Triangular mesh.
Definition: ecvMesh.h:35
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Definition: LineSet.h:29
bool HasColors() const
Returns true if the objects lines contains colors.
Definition: LineSet.h:85
virtual LineSet & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
LineSet & operator+=(const LineSet &lineset)
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
std::pair< Eigen::Vector3d, Eigen::Vector3d > GetLineCoordinate(size_t line_index) const
Returns the coordinates of the line at the given index.
Definition: LineSet.h:92
virtual bool IsEmpty() const override
Definition: LineSet.h:61
virtual ccBBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
static std::shared_ptr< LineSet > CreateFromTetraMesh(const TetraMesh &mesh)
virtual bool isSerializable() const override
Returns whether object is serializable of not.
Definition: LineSet.h:46
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
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)
std::vector< Eigen::Vector3d > points_
Points coordinates.
Definition: LineSet.h:156
std::vector< Eigen::Vector3d > colors_
RGB colors of lines.
Definition: LineSet.h:160
virtual LineSet & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
LineSet(const char *name="LineSet")
Default Constructor.
Definition: LineSet.h:32
virtual ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
bool HasLines() const
Returns true if the object contains lines.
Definition: LineSet.h:82
virtual LineSet & Scale(const double s, const Eigen::Vector3d &center) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
virtual CV_CLASS_ENUM getClassID() const override
Returns unique class ID.
Definition: LineSet.h:49
LineSet operator+(const LineSet &lineset) const
std::vector< Eigen::Vector2i > lines_
Lines denoted by the index of points forming the line.
Definition: LineSet.h:158
virtual ecvOrientedBBox GetOrientedBoundingBox() const override
LineSet(const std::vector< Eigen::Vector3d > &points, const std::vector< Eigen::Vector2i > &lines, const char *name="LineSet")
Parameterized Constructor.
Definition: LineSet.h:39
virtual LineSet & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
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 > CreateFromAxisAlignedBoundingBox(const ccBBox &box)
Factory function to create a LineSet from an ccBBox.
LineSet & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each line in the LineSet the same color.
Definition: LineSet.h:101
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
virtual void drawMeOnly(CC_DRAW_CONTEXT &context) override
Draws the entity only (not its children)
bool HasPoints() const
Returns true if the object contains points.
Definition: LineSet.h:79
Tetra mesh contains vertices and tetrahedra represented by the indices to the vertices.
Definition: ecvTetraMesh.h:29
ImGuiContext * context
Definition: Window.cpp:76
@ LINESET
Definition: CVTypes.h:152
CLOUDVIEWER_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
Definition: SlabTraits.h:49
Generic file read and write utility for python interface.
Display context.