Open3D (C++ API)  0.15.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 <string>
30
31#include "open3d/core/Tensor.h"
38
39namespace open3d {
40namespace t {
41namespace geometry {
42
99
100class LineSet : public Geometry, public DrawableGeometry {
101public:
103 LineSet(const core::Device &device = core::Device("CPU:0"));
104
120 LineSet(const core::Tensor &point_positions,
121 const core::Tensor &line_indices);
122
123 virtual ~LineSet() override {}
124
130 LineSet To(const core::Device &device, bool copy = false) const;
131
133 LineSet Clone() const { return To(GetDevice(), /*copy=*/true); }
134
136 std::string ToString() const;
137
139 const TensorMap &GetPointAttr() const { return point_attr_; }
140
145 core::Tensor &GetPointAttr(const std::string &key) {
146 return point_attr_.at(key);
147 }
148
151 core::Tensor &GetPointPositions() { return GetPointAttr("positions"); }
152
154 const TensorMap &GetLineAttr() const { return line_attr_; }
155
160 core::Tensor &GetLineAttr(const std::string &key) {
161 return line_attr_.at(key);
162 }
163
166 core::Tensor &GetLineIndices() { return GetLineAttr("indices"); }
167
170 core::Tensor &GetLineColors() { return GetLineAttr("colors"); }
171
175 const core::Tensor &GetPointAttr(const std::string &key) const {
176 return point_attr_.at(key);
177 }
178
183 void RemovePointAttr(const std::string &key) { point_attr_.Erase(key); }
184
188 return GetPointAttr("positions");
189 }
190
195 const core::Tensor &GetLineAttr(const std::string &key) const {
196 return line_attr_.at(key);
197 }
198
203 void RemoveLineAttr(const std::string &key) { line_attr_.Erase(key); }
204
208 return GetLineAttr("indices");
209 }
210
213 const core::Tensor &GetLineColors() const { return GetLineAttr("colors"); }
214
220 void SetPointAttr(const std::string &key, const core::Tensor &value) {
222 point_attr_[key] = value;
223 }
224
227 void SetPointPositions(const core::Tensor &value) {
229 SetPointAttr("positions", value);
230 }
231
237 void SetLineAttr(const std::string &key, const core::Tensor &value) {
239 line_attr_[key] = value;
240 }
241
243 void SetLineIndices(const core::Tensor &value) {
245 SetLineAttr("indices", value);
246 }
247
250 void SetLineColors(const core::Tensor &value) {
252 SetLineAttr("colors", value);
253 }
254
259 bool HasPointAttr(const std::string &key) const {
260 return point_attr_.Contains(key) && GetPointAttr(key).GetLength() > 0 &&
261 GetPointAttr(key).GetLength() == GetPointPositions().GetLength();
262 }
263
266 bool HasPointPositions() const { return HasPointAttr("positions"); }
267
272 bool HasLineAttr(const std::string &key) const {
273 return line_attr_.Contains(key) && GetLineAttr(key).GetLength() > 0 &&
274 GetLineAttr(key).GetLength() == GetLineIndices().GetLength();
275 }
276
279 bool HasLineIndices() const { return HasLineAttr("indices"); }
280
286 bool HasLineColors() const { return HasLineAttr("colors"); }
287
289 LineSet &Clear() override {
290 point_attr_.clear();
291 line_attr_.clear();
292 return *this;
293 }
294
296 bool IsEmpty() const override { return !HasPointPositions(); }
297
300
303
305 core::Tensor GetCenter() const { return GetPointPositions().Mean({0}); }
306
327 LineSet &Transform(const core::Tensor &transformation);
328
334 LineSet &Translate(const core::Tensor &translation, bool relative = true);
335
340 LineSet &Scale(double scale, const core::Tensor &center);
341
348 LineSet &Rotate(const core::Tensor &R, const core::Tensor &center);
349
351 core::Device GetDevice() const { return device_; }
352
361 const open3d::geometry::LineSet &lineset_legacy,
362 core::Dtype float_dtype = core::Float32,
363 core::Dtype int_dtype = core::Int64,
364 const core::Device &device = core::Device("CPU:0"));
365
368
369protected:
373};
374
375} // namespace geometry
376} // namespace t
377} // namespace open3d
#define AssertTensorDevice(tensor,...)
Definition: TensorCheck.h:62
#define AssertTensorShape(tensor,...)
Definition: TensorCheck.h:77
Definition: Device.h:39
Definition: Dtype.h:39
Definition: Tensor.h:51
int64_t GetLength() const
Definition: Tensor.h:1089
Tensor Min(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1198
Tensor Mean(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1177
Tensor Max(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1205
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Definition: LineSet.h:48
Mix-in class for geometry types that can be visualized.
Definition: DrawableGeometry.h:38
The base geometry class.
Definition: Geometry.h:38
A LineSet contains points and lines joining them and optionally attributes on the points and lines.
Definition: LineSet.h:100
std::string ToString() const
Text description.
Definition: LineSet.cpp:73
LineSet & Rotate(const core::Tensor &R, const core::Tensor &center)
Rotates the points and lines of the line set. Custom attributes (e.g.: point or line normals) are not...
Definition: LineSet.cpp:143
LineSet & Clear() override
Clear all data in the line set.
Definition: LineSet.h:289
core::Device device_
Definition: LineSet.h:370
const TensorMap & GetLineAttr() const
Getter for line_attr_ TensorMap. Used in Pybind.
Definition: LineSet.h:154
const core::Tensor & GetPointAttr(const std::string &key) const
Definition: LineSet.h:175
const core::Tensor & GetLineColors() const
Definition: LineSet.h:213
bool HasLineColors() const
Definition: LineSet.h:286
bool HasPointAttr(const std::string &key) const
Definition: LineSet.h:259
core::Tensor GetMaxBound() const
Returns the max bound for point coordinates.
Definition: LineSet.h:302
void SetLineColors(const core::Tensor &value)
Definition: LineSet.h:250
void RemoveLineAttr(const std::string &key)
Definition: LineSet.h:203
virtual ~LineSet() override
Definition: LineSet.h:123
void SetLineAttr(const std::string &key, const core::Tensor &value)
Definition: LineSet.h:237
LineSet(const core::Device &device=core::Device("CPU:0"))
Construct an empty LineSet on the provided device.
Definition: LineSet.cpp:43
core::Tensor & GetPointPositions()
Definition: LineSet.h:151
open3d::geometry::LineSet ToLegacy() const
Convert to a legacy Open3D LineSet.
Definition: LineSet.cpp:187
core::Tensor GetCenter() const
Returns the center for point coordinates.
Definition: LineSet.h:305
core::Tensor & GetLineIndices()
Definition: LineSet.h:166
bool HasPointPositions() const
Definition: LineSet.h:266
void SetPointAttr(const std::string &key, const core::Tensor &value)
Definition: LineSet.h:220
bool HasLineAttr(const std::string &key) const
Definition: LineSet.h:272
LineSet Clone() const
Returns copy of the line set on the same device.
Definition: LineSet.h:133
core::Tensor & GetLineColors()
Definition: LineSet.h:170
LineSet & Scale(double scale, const core::Tensor &center)
Scales the points and lines of the LineSet.
Definition: LineSet.cpp:133
const core::Tensor & GetLineIndices() const
Definition: LineSet.h:207
const TensorMap & GetPointAttr() const
Getter for point_attr_ TensorMap. Used in Pybind.
Definition: LineSet.h:139
bool HasLineIndices() const
Definition: LineSet.h:279
const core::Tensor & GetLineAttr(const std::string &key) const
Definition: LineSet.h:195
LineSet & Transform(const core::Tensor &transformation)
Transforms the points and lines of the LineSet.
Definition: LineSet.cpp:114
LineSet To(const core::Device &device, bool copy=false) const
Definition: LineSet.cpp:59
void RemovePointAttr(const std::string &key)
Definition: LineSet.h:183
void SetLineIndices(const core::Tensor &value)
Set the value of the "indices" attribute in line_attr_.
Definition: LineSet.h:243
core::Tensor GetMinBound() const
Returns the max bound for point coordinates.
Definition: LineSet.h:299
TensorMap line_attr_
Definition: LineSet.h:372
void SetPointPositions(const core::Tensor &value)
Definition: LineSet.h:227
TensorMap point_attr_
Definition: LineSet.h:371
LineSet & Translate(const core::Tensor &translation, bool relative=true)
Translates the points and lines of the LineSet.
Definition: LineSet.cpp:120
static geometry::LineSet FromLegacy(const open3d::geometry::LineSet &lineset_legacy, core::Dtype float_dtype=core::Float32, core::Dtype int_dtype=core::Int64, const core::Device &device=core::Device("CPU:0"))
Definition: LineSet.cpp:150
core::Tensor & GetLineAttr(const std::string &key)
Definition: LineSet.h:160
core::Tensor & GetPointAttr(const std::string &key)
Definition: LineSet.h:145
core::Device GetDevice() const
Returns the device attribute of this LineSet.
Definition: LineSet.h:351
bool IsEmpty() const override
Returns !HasPointPositions(), line indices are ignored.
Definition: LineSet.h:296
const core::Tensor & GetPointPositions() const
Definition: LineSet.h:187
Definition: TensorMap.h:49
std::size_t Erase(const std::string key)
Erase elements for the TensorMap by key value, if the key exists. If the key does not exists,...
Definition: TensorMap.h:100
bool Contains(const std::string &key) const
Definition: TensorMap.h:134
const Dtype Int64
Definition: Dtype.cpp:66
const Dtype Float32
Definition: Dtype.cpp:61
constexpr nullopt_t nullopt
Definition: Optional.h:171
Definition: PinholeCameraIntrinsic.cpp:35