Open3D (C++ API)  0.18.0+fcc396e
LineSet.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <memory>
12 #include <vector>
13 
15 
16 namespace open3d {
17 namespace geometry {
18 
19 class PointCloud;
20 class OrientedBoundingBox;
21 class AxisAlignedBoundingBox;
22 class TriangleMesh;
23 class TetraMesh;
24 
29 class LineSet : public Geometry3D {
30 public:
39  LineSet(const std::vector<Eigen::Vector3d> &points,
40  const std::vector<Eigen::Vector2i> &lines)
42  points_(points),
43  lines_(lines) {}
44  ~LineSet() override {}
45 
46 public:
47  LineSet &Clear() override;
48  bool IsEmpty() const override;
49  Eigen::Vector3d GetMinBound() const override;
50  Eigen::Vector3d GetMaxBound() const override;
51  Eigen::Vector3d GetCenter() const override;
52 
56 
63  bool robust = false) const override;
64 
72  bool robust = false) const override;
73 
74  LineSet &Transform(const Eigen::Matrix4d &transformation) override;
75  LineSet &Translate(const Eigen::Vector3d &translation,
76  bool relative = true) override;
77  LineSet &Scale(const double scale, const Eigen::Vector3d &center) override;
78  LineSet &Rotate(const Eigen::Matrix3d &R,
79  const Eigen::Vector3d &center) override;
80 
81  LineSet &operator+=(const LineSet &lineset);
82  LineSet operator+(const LineSet &lineset) const;
83 
85  bool HasPoints() const { return points_.size() > 0; }
86 
88  bool HasLines() const { return HasPoints() && lines_.size() > 0; }
89 
91  bool HasColors() const {
92  return HasLines() && colors_.size() == lines_.size();
93  }
94 
98  std::pair<Eigen::Vector3d, Eigen::Vector3d> GetLineCoordinate(
99  size_t line_index) const {
100  return std::make_pair(points_[lines_[line_index][0]],
101  points_[lines_[line_index][1]]);
102  }
103 
107  LineSet &PaintUniformColor(const Eigen::Vector3d &color) {
109  return *this;
110  }
111 
118  static std::shared_ptr<LineSet> CreateFromPointCloudCorrespondences(
119  const PointCloud &cloud0,
120  const PointCloud &cloud1,
121  const std::vector<std::pair<int, int>> &correspondences);
122 
126  static std::shared_ptr<LineSet> CreateFromOrientedBoundingBox(
127  const OrientedBoundingBox &box);
128 
133  static std::shared_ptr<LineSet> CreateFromAxisAlignedBoundingBox(
134  const AxisAlignedBoundingBox &box);
135 
139  static std::shared_ptr<LineSet> CreateFromTriangleMesh(
140  const TriangleMesh &mesh);
141 
145  static std::shared_ptr<LineSet> CreateFromTetraMesh(const TetraMesh &mesh);
146 
154  static std::shared_ptr<LineSet> CreateCameraVisualization(
155  int view_width_px,
156  int view_height_px,
157  const Eigen::Matrix3d &intrinsic,
158  const Eigen::Matrix4d &extrinsic,
159  double scale = 1.0);
160 
161 public:
163  std::vector<Eigen::Vector3d> points_;
165  std::vector<Eigen::Vector2i> lines_;
167  std::vector<Eigen::Vector3d> colors_;
168 };
169 
170 } // namespace geometry
171 } // namespace open3d
math::float4 color
Definition: LineSetBuffers.cpp:45
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound.
Definition: BoundingVolume.h:160
The base geometry class for 3D geometries.
Definition: Geometry3D.h:28
void ResizeAndPaintUniformColor(std::vector< Eigen::Vector3d > &colors, const size_t size, const Eigen::Vector3d &color) const
Resizes the colors vector and paints a uniform color.
Definition: Geometry3D.cpp:56
The base geometry class.
Definition: Geometry.h:18
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:23
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Definition: LineSet.h:29
OrientedBoundingBox GetMinimalOrientedBoundingBox(bool robust=false) const override
Definition: LineSet.cpp:44
bool HasPoints() const
Returns true if the object contains points.
Definition: LineSet.h:85
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)
Definition: LineSetFactory.cpp:129
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:98
LineSet & Clear() override
Clear all elements in the geometry.
Definition: LineSet.cpp:17
~LineSet() override
Definition: LineSet.h:44
Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: LineSet.cpp:34
LineSet operator+(const LineSet &lineset) const
Definition: LineSet.cpp:99
LineSet()
Default Constructor.
Definition: LineSet.h:32
std::vector< Eigen::Vector3d > colors_
RGB colors of lines.
Definition: LineSet.h:167
LineSet & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: LineSet.cpp:53
static std::shared_ptr< LineSet > CreateFromAxisAlignedBoundingBox(const AxisAlignedBoundingBox &box)
Factory function to create a LineSet from an AxisAlignedBoundingBox.
Definition: LineSetFactory.cpp:84
Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: LineSet.cpp:30
LineSet & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each line in the LineSet the same color.
Definition: LineSet.h:107
std::vector< Eigen::Vector2i > lines_
Lines denoted by the index of points forming the line.
Definition: LineSet.h:165
static std::shared_ptr< LineSet > CreateFromPointCloudCorrespondences(const PointCloud &cloud0, const PointCloud &cloud1, const std::vector< std::pair< int, int >> &correspondences)
Factory function to create a LineSet from two PointClouds (cloud0, cloud1) and a correspondence set.
Definition: LineSetFactory.cpp:19
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: LineSet.cpp:24
static std::shared_ptr< LineSet > CreateFromOrientedBoundingBox(const OrientedBoundingBox &box)
Factory function to create a LineSet from an OrientedBoundingBox.
Definition: LineSetFactory.cpp:64
Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: LineSet.cpp:26
static std::shared_ptr< LineSet > CreateFromTetraMesh(const TetraMesh &mesh)
Definition: LineSetFactory.cpp:104
std::vector< Eigen::Vector3d > points_
Points coordinates.
Definition: LineSet.h:163
LineSet & operator+=(const LineSet &lineset)
Definition: LineSet.cpp:69
OrientedBoundingBox GetOrientedBoundingBox(bool robust=false) const override
Definition: LineSet.cpp:40
LineSet & Scale(const double scale, const Eigen::Vector3d &center) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
Definition: LineSet.cpp:58
bool HasLines() const
Returns true if the object contains lines.
Definition: LineSet.h:88
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 ,...
Definition: LineSet.cpp:63
static std::shared_ptr< LineSet > CreateFromTriangleMesh(const TriangleMesh &mesh)
Definition: LineSetFactory.cpp:41
LineSet & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: LineSet.cpp:48
LineSet(const std::vector< Eigen::Vector3d > &points, const std::vector< Eigen::Vector2i > &lines)
Parameterized Constructor.
Definition: LineSet.h:39
AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Definition: LineSet.cpp:36
bool HasColors() const
Returns true if the objects lines contains colors.
Definition: LineSet.h:91
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:25
A point cloud consists of point coordinates, and optionally point colors and point normals.
Definition: PointCloud.h:36
Tetra mesh contains vertices and tetrahedra represented by the indices to the vertices.
Definition: TetraMesh.h:29
Triangle mesh contains vertices and triangles represented by the indices to the vertices.
Definition: TriangleMesh.h:35
int points
Definition: FilePCD.cpp:54
OPEN3D_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
Definition: SlabTraits.h:49
Definition: PinholeCameraIntrinsic.cpp:16