Open3D (C++ API)
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 TriangleMesh;
40 
41 class LineSet : public Geometry3D {
42 public:
44  ~LineSet() override {}
45 
46 public:
47  void Clear() override;
48  bool IsEmpty() const override;
49  Eigen::Vector3d GetMinBound() const override;
50  Eigen::Vector3d GetMaxBound() const override;
51  LineSet &Transform(const Eigen::Matrix4d &transformation) override;
52  LineSet &Translate(const Eigen::Vector3d &translation) override;
53  LineSet &Scale(const double scale, bool center = true) override;
54  LineSet &Rotate(const Eigen::Vector3d &rotation,
55  bool center = true,
57 
58 public:
59  LineSet &operator+=(const LineSet &lineset);
60  LineSet operator+(const LineSet &lineset) const;
61 
62 public:
63  bool HasPoints() const { return points_.size() > 0; }
64 
65  bool HasLines() const { return HasPoints() && lines_.size() > 0; }
66 
67  bool HasColors() const {
68  return HasLines() && colors_.size() == lines_.size();
69  }
70 
71  std::pair<Eigen::Vector3d, Eigen::Vector3d> GetLineCoordinate(
72  size_t line_index) const {
73  return std::make_pair(points_[lines_[line_index][0]],
74  points_[lines_[line_index][1]]);
75  }
76 
78  void PaintUniformColor(const Eigen::Vector3d &color) {
79  colors_.resize(lines_.size());
80  for (size_t i = 0; i < lines_.size(); i++) {
81  colors_[i] = color;
82  }
83  }
84 
85 public:
86  std::vector<Eigen::Vector3d> points_;
87  std::vector<Eigen::Vector2i> lines_;
88  std::vector<Eigen::Vector3d> colors_;
89 };
90 
94 std::shared_ptr<LineSet> CreateLineSetFromPointCloudCorrespondences(
95  const PointCloud &cloud0,
96  const PointCloud &cloud1,
97  const std::vector<std::pair<int, int>> &correspondences);
98 
101 std::shared_ptr<LineSet> CreateLineSetFromTriangleMesh(
102  const TriangleMesh &mesh);
103 
104 } // namespace geometry
105 } // namespace open3d
std::vector< Eigen::Vector2i > lines_
Definition: LineSet.h:87
Definition: Geometry.h:32
std::shared_ptr< LineSet > CreateLineSetFromTriangleMesh(const TriangleMesh &mesh)
Definition: LineSetFactory.cpp:58
Definition: PointCloud.h:49
std::shared_ptr< LineSet > CreateLineSetFromPointCloudCorrespondences(const PointCloud &cloud0, const PointCloud &cloud1, const std::vector< std::pair< int, int >> &correspondences)
Definition: LineSetFactory.cpp:36
bool HasColors() const
Definition: LineSet.h:67
RotationType
Definition: Geometry3D.h:40
std::vector< Eigen::Vector3d > points_
Definition: LineSet.h:86
~LineSet() override
Definition: LineSet.h:44
std::vector< Eigen::Vector3d > colors_
Definition: LineSet.h:88
std::pair< Eigen::Vector3d, Eigen::Vector3d > GetLineCoordinate(size_t line_index) const
Definition: LineSet.h:71
Definition: Geometry3D.h:38
void Clear() override
Definition: LineSet.cpp:34
void PaintUniformColor(const Eigen::Vector3d &color)
Assigns each line in the LineSet the same color.
Definition: LineSet.h:78
LineSet & operator+=(const LineSet &lineset)
Definition: LineSet.cpp:132
Eigen::Vector3d GetMaxBound() const override
Definition: LineSet.cpp:64
char type
Definition: FilePCD.cpp:56
LineSet & Scale(const double scale, bool center=true) override
Definition: LineSet.cpp:103
Definition: PinholeCameraIntrinsic.cpp:34
GeometryType
Definition: Geometry.h:34
bool HasPoints() const
Definition: LineSet.h:63
bool IsEmpty() const override
Definition: LineSet.cpp:40
LineSet()
Definition: LineSet.h:43
LineSet & Rotate(const Eigen::Vector3d &rotation, bool center=true, RotationType type=RotationType::XYZ) override
Definition: LineSet.cpp:116
bool HasLines() const
Definition: LineSet.h:65
Definition: TriangleMesh.h:43
Definition: LineSet.h:41
Eigen::Vector3d GetMinBound() const override
Definition: LineSet.cpp:42
LineSet operator+(const LineSet &lineset) const
Definition: LineSet.cpp:162
LineSet & Translate(const Eigen::Vector3d &translation) override
Definition: LineSet.cpp:96
long line_index
Definition: FilePLY.cpp:205
LineSet & Transform(const Eigen::Matrix4d &transformation) override
Definition: LineSet.cpp:86