Open3D (C++ API)  0.16.1
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-2021 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
35namespace open3d {
36namespace geometry {
37
38class PointCloud;
39class OrientedBoundingBox;
40class AxisAlignedBoundingBox;
41class TriangleMesh;
42class TetraMesh;
43
48class LineSet : public Geometry3D {
49public:
58 LineSet(const std::vector<Eigen::Vector3d> &points,
59 const std::vector<Eigen::Vector2i> &lines)
62 lines_(lines) {}
63 ~LineSet() override {}
64
65public:
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 bool robust = false) const override;
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
161public:
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:64
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:155
The base geometry class for 3D geometries.
Definition: Geometry3D.h:47
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
The base geometry class.
Definition: Geometry.h:37
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:42
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Definition: LineSet.h:48
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:148
LineSet & Clear() override
Clear all elements in the geometry.
Definition: LineSet.cpp:36
~LineSet() override
Definition: LineSet.h:63
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
Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: LineSet.cpp:53
LineSet operator+(const LineSet &lineset) const
Definition: LineSet.cpp:114
LineSet()
Default Constructor.
Definition: LineSet.h:51
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:68
static std::shared_ptr< LineSet > CreateFromAxisAlignedBoundingBox(const AxisAlignedBoundingBox &box)
Factory function to create a LineSet from an AxisAlignedBoundingBox.
Definition: LineSetFactory.cpp:103
Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: LineSet.cpp:49
std::vector< Eigen::Vector2i > lines_
Lines denoted by the index of points forming the line.
Definition: LineSet.h:165
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: LineSet.cpp:43
static std::shared_ptr< LineSet > CreateFromOrientedBoundingBox(const OrientedBoundingBox &box)
Factory function to create a LineSet from an OrientedBoundingBox.
Definition: LineSetFactory.cpp:83
Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: LineSet.cpp:45
static std::shared_ptr< LineSet > CreateFromTetraMesh(const TetraMesh &mesh)
Definition: LineSetFactory.cpp:123
LineSet & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each line in the LineSet the same color.
Definition: LineSet.h:107
std::vector< Eigen::Vector3d > points_
Points coordinates.
Definition: LineSet.h:163
LineSet & operator+=(const LineSet &lineset)
Definition: LineSet.cpp:84
OrientedBoundingBox GetOrientedBoundingBox(bool robust=false) const override
Definition: LineSet.cpp:59
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
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
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:78
static std::shared_ptr< LineSet > CreateFromTriangleMesh(const TriangleMesh &mesh)
Definition: LineSetFactory.cpp:60
LineSet & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: LineSet.cpp:63
LineSet(const std::vector< Eigen::Vector3d > &points, const std::vector< Eigen::Vector2i > &lines)
Parameterized Constructor.
Definition: LineSet.h:58
AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: LineSet.cpp:55
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:44
A point cloud consists of point coordinates, and optionally point colors and point normals.
Definition: PointCloud.h:55
Tetra mesh contains vertices and tetrahedra represented by the indices to the vertices.
Definition: TetraMesh.h:48
Triangle mesh contains vertices and triangles represented by the indices to the vertices.
Definition: TriangleMesh.h:54
int points
Definition: FilePCD.cpp:73
OPEN3D_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
Definition: SlabTraits.h:68
Definition: PinholeCameraIntrinsic.cpp:35