Open3D (C++ API)
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
44 class LineSet : public Geometry3D {
45 public:
47  LineSet(const std::vector<Eigen::Vector3d> &points,
48  const std::vector<Eigen::Vector2i> &lines)
50  points_(points),
51  lines_(lines) {}
52  ~LineSet() override {}
53 
54 public:
55  LineSet &Clear() override;
56  bool IsEmpty() const override;
57  Eigen::Vector3d GetMinBound() const override;
58  Eigen::Vector3d GetMaxBound() const override;
59  Eigen::Vector3d GetCenter() const override;
62  LineSet &Transform(const Eigen::Matrix4d &transformation) override;
63  LineSet &Translate(const Eigen::Vector3d &translation,
64  bool relative = true) override;
65  LineSet &Scale(const double scale, bool center = true) override;
66  LineSet &Rotate(const Eigen::Matrix3d &R, bool center = true) override;
67 
68  LineSet &operator+=(const LineSet &lineset);
69  LineSet operator+(const LineSet &lineset) const;
70 
71  bool HasPoints() const { return points_.size() > 0; }
72 
73  bool HasLines() const { return HasPoints() && lines_.size() > 0; }
74 
75  bool HasColors() const {
76  return HasLines() && colors_.size() == lines_.size();
77  }
78 
79  std::pair<Eigen::Vector3d, Eigen::Vector3d> GetLineCoordinate(
80  size_t line_index) const {
81  return std::make_pair(points_[lines_[line_index][0]],
82  points_[lines_[line_index][1]]);
83  }
84 
86  LineSet &PaintUniformColor(const Eigen::Vector3d &color) {
88  return *this;
89  }
90 
94  static std::shared_ptr<LineSet> CreateFromPointCloudCorrespondences(
95  const PointCloud &cloud0,
96  const PointCloud &cloud1,
97  const std::vector<std::pair<int, int>> &correspondences);
98 
99  static std::shared_ptr<LineSet> CreateFromOrientedBoundingBox(
100  const OrientedBoundingBox &box);
101  static std::shared_ptr<LineSet> CreateFromAxisAlignedBoundingBox(
102  const AxisAlignedBoundingBox &box);
103 
106  static std::shared_ptr<LineSet> CreateFromTriangleMesh(
107  const TriangleMesh &mesh);
108 
111  static std::shared_ptr<LineSet> CreateFromTetraMesh(const TetraMesh &mesh);
112 
113 public:
114  std::vector<Eigen::Vector3d> points_;
115  std::vector<Eigen::Vector2i> lines_;
116  std::vector<Eigen::Vector3d> colors_;
117 };
118 
119 } // namespace geometry
120 } // namespace open3d
std::vector< Eigen::Vector2i > lines_
Definition: LineSet.h:115
The base geometry class.
Definition: Geometry.h:35
LineSet & Rotate(const Eigen::Matrix3d &R, bool center=true) override
Apply rotation to the geometry coordinates and normals.
Definition: LineSet.cpp:77
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:130
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:44
Definition: PointCloud.h:50
static std::shared_ptr< LineSet > CreateFromAxisAlignedBoundingBox(const AxisAlignedBoundingBox &box)
Definition: LineSetFactory.cpp:104
LineSet & Clear() override
Clear all elements in the geometry.
Definition: LineSet.cpp:35
bool HasColors() const
Definition: LineSet.h:75
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:67
std::vector< Eigen::Vector3d > points_
Definition: LineSet.h:114
~LineSet() override
Definition: LineSet.h:52
std::vector< Eigen::Vector3d > colors_
Definition: LineSet.h:116
std::pair< Eigen::Vector3d, Eigen::Vector3d > GetLineCoordinate(size_t line_index) const
Definition: LineSet.h:79
The base geometry class for 3D geometries.
Definition: Geometry3D.h:46
LineSet & operator+=(const LineSet &lineset)
Definition: LineSet.cpp:82
Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: LineSet.cpp:48
OrientedBoundingBox GetOrientedBoundingBox() const override
Returns an oriented bounding box of the geometry.
Definition: LineSet.cpp:58
Definition: TetraMesh.h:44
static std::shared_ptr< LineSet > CreateFromPointCloudCorrespondences(const PointCloud &cloud0, const PointCloud &cloud1, const std::vector< std::pair< int, int >> &correspondences)
Definition: LineSetFactory.cpp:38
LineSet(const std::vector< Eigen::Vector3d > &points, const std::vector< Eigen::Vector2i > &lines)
Definition: LineSet.h:47
Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: LineSet.cpp:52
LineSet & Scale(const double scale, bool center=true) override
Apply scaling to the geometry coordinates.
Definition: LineSet.cpp:72
int points
Definition: FilePCD.cpp:70
Definition: PinholeCameraIntrinsic.cpp:34
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:40
static std::shared_ptr< LineSet > CreateFromOrientedBoundingBox(const OrientedBoundingBox &box)
Definition: LineSetFactory.cpp:84
LineSet & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each line in the LineSet the same color.
Definition: LineSet.h:86
bool HasPoints() const
Definition: LineSet.h:71
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: LineSet.cpp:42
LineSet()
Definition: LineSet.h:46
AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: LineSet.cpp:54
bool HasLines() const
Definition: LineSet.h:73
Definition: TriangleMesh.h:46
Definition: LineSet.h:44
Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: LineSet.cpp:44
LineSet operator+(const LineSet &lineset) const
Definition: LineSet.cpp:112
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:71
static std::shared_ptr< LineSet > CreateFromTetraMesh(const TetraMesh &mesh)
Definition: LineSetFactory.cpp:124
long line_index
Definition: FilePLY.cpp:216
LineSet & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: LineSet.cpp:62