Open3D (C++ API)  0.11.0
LineSet.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <Eigen/Core>
30 #include <memory>
31 #include <vector>
32 
34 
35 namespace open3d {
36 namespace geometry {
37 
38 class PointCloud;
39 class OrientedBoundingBox;
40 class AxisAlignedBoundingBox;
41 class TriangleMesh;
42 class TetraMesh;
43 
48 class LineSet : public Geometry3D {
49 public:
58  LineSet(const std::vector<Eigen::Vector3d> &points,
59  const std::vector<Eigen::Vector2i> &lines)
61  points_(points),
62  lines_(lines) {}
63  ~LineSet() override {}
64 
65 public:
66  LineSet &Clear() override;
67  bool IsEmpty() const override;
68  Eigen::Vector3d GetMinBound() const override;
69  Eigen::Vector3d GetMaxBound() const override;
70  Eigen::Vector3d GetCenter() const override;
73  LineSet &Transform(const Eigen::Matrix4d &transformation) override;
74  LineSet &Translate(const Eigen::Vector3d &translation,
75  bool relative = true) override;
76  LineSet &Scale(const double scale, const Eigen::Vector3d &center) override;
77  LineSet &Rotate(const Eigen::Matrix3d &R,
78  const Eigen::Vector3d &center) override;
79 
80  LineSet &operator+=(const LineSet &lineset);
81  LineSet operator+(const LineSet &lineset) const;
82 
84  bool HasPoints() const { return points_.size() > 0; }
85 
87  bool HasLines() const { return HasPoints() && lines_.size() > 0; }
88 
90  bool HasColors() const {
91  return HasLines() && colors_.size() == lines_.size();
92  }
93 
97  std::pair<Eigen::Vector3d, Eigen::Vector3d> GetLineCoordinate(
98  size_t line_index) const {
99  return std::make_pair(points_[lines_[line_index][0]],
100  points_[lines_[line_index][1]]);
101  }
102 
106  LineSet &PaintUniformColor(const Eigen::Vector3d &color) {
108  return *this;
109  }
110 
117  static std::shared_ptr<LineSet> CreateFromPointCloudCorrespondences(
118  const PointCloud &cloud0,
119  const PointCloud &cloud1,
120  const std::vector<std::pair<int, int>> &correspondences);
121 
125  static std::shared_ptr<LineSet> CreateFromOrientedBoundingBox(
126  const OrientedBoundingBox &box);
127 
132  static std::shared_ptr<LineSet> CreateFromAxisAlignedBoundingBox(
133  const AxisAlignedBoundingBox &box);
134 
138  static std::shared_ptr<LineSet> CreateFromTriangleMesh(
139  const TriangleMesh &mesh);
140 
144  static std::shared_ptr<LineSet> CreateFromTetraMesh(const TetraMesh &mesh);
145 
146 public:
148  std::vector<Eigen::Vector3d> points_;
150  std::vector<Eigen::Vector2i> lines_;
152  std::vector<Eigen::Vector3d> colors_;
153 };
154 
155 } // namespace geometry
156 } // namespace open3d
std::vector< Eigen::Vector2i > lines_
Lines denoted by the index of points forming the line.
Definition: LineSet.h:150
The base geometry class.
Definition: Geometry.h:37
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:149
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:44
A point cloud consists of point coordinates, and optionally point colors and point normals...
Definition: PointCloud.h:54
static std::shared_ptr< LineSet > CreateFromAxisAlignedBoundingBox(const AxisAlignedBoundingBox &box)
Factory function to create a LineSet from an AxisAlignedBoundingBox.
Definition: LineSetFactory.cpp:103
LineSet & Clear() override
Clear all elements in the geometry.
Definition: LineSet.cpp:36
bool HasColors() const
Returns true if the objects lines contains colors.
Definition: LineSet.h:90
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:73
static std::shared_ptr< LineSet > CreateFromTriangleMesh(const TriangleMesh &mesh)
Definition: LineSetFactory.cpp:60
LineSet & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: LineSet.cpp:68
std::vector< Eigen::Vector3d > points_
Points coordinates.
Definition: LineSet.h:148
~LineSet() override
Definition: LineSet.h:63
std::vector< Eigen::Vector3d > colors_
RGB colors of lines.
Definition: LineSet.h:152
math::float4 color
Definition: LineSetBuffers.cpp:63
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:97
The base geometry class for 3D geometries.
Definition: Geometry3D.h:46
LineSet & operator+=(const LineSet &lineset)
Definition: LineSet.cpp:84
Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: LineSet.cpp:49
OrientedBoundingBox GetOrientedBoundingBox() const override
Returns an oriented bounding box of the geometry.
Definition: LineSet.cpp:59
Tetra mesh contains vertices and tetrahedra represented by the indices to the vertices.
Definition: TetraMesh.h:48
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:38
LineSet(const std::vector< Eigen::Vector3d > &points, const std::vector< Eigen::Vector2i > &lines)
Parameterized Constructor.
Definition: LineSet.h:58
Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: LineSet.cpp:53
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:78
int points
Definition: FilePCD.cpp:73
Definition: PinholeCameraIntrinsic.cpp:35
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:42
static std::shared_ptr< LineSet > CreateFromOrientedBoundingBox(const OrientedBoundingBox &box)
Factory function to create a LineSet from an OrientedBoundingBox.
Definition: LineSetFactory.cpp:83
LineSet & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each line in the LineSet the same color.
Definition: LineSet.h:106
bool HasPoints() const
Returns true if the object contains points.
Definition: LineSet.h:84
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: LineSet.cpp:43
LineSet()
Default Constructor.
Definition: LineSet.h:51
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:75
AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: LineSet.cpp:55
bool HasLines() const
Returns true if the object contains lines.
Definition: LineSet.h:87
Triangle mesh contains vertices and triangles represented by the indices to the vertices.
Definition: TriangleMesh.h:54
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Definition: LineSet.h:48
Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: LineSet.cpp:45
LineSet operator+(const LineSet &lineset) const
Definition: LineSet.cpp:114
static std::shared_ptr< LineSet > CreateFromTetraMesh(const TetraMesh &mesh)
Definition: LineSetFactory.cpp:123
OPEN3D_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
Definition: Traits.h:70
LineSet & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: LineSet.cpp:63