Open3D (C++ API)  0.18.0+252c867
LineSet.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <string>
11 
12 #include "open3d/core/Tensor.h"
19 #include "open3d/utility/Logging.h"
20 
21 namespace open3d {
22 namespace t {
23 namespace geometry {
24 
25 class TriangleMesh;
26 
83 
84 class LineSet : public Geometry, public DrawableGeometry {
85 public:
87  LineSet(const core::Device &device = core::Device("CPU:0"));
88 
104  LineSet(const core::Tensor &point_positions,
105  const core::Tensor &line_indices);
106 
107  virtual ~LineSet() override {}
108 
114  LineSet To(const core::Device &device, bool copy = false) const;
115 
117  LineSet Clone() const { return To(GetDevice(), /*copy=*/true); }
118 
120  std::string ToString() const;
121 
123  const TensorMap &GetPointAttr() const { return point_attr_; }
124 
127 
132  core::Tensor &GetPointAttr(const std::string &key) {
133  return point_attr_.at(key);
134  }
135 
138  core::Tensor &GetPointPositions() { return GetPointAttr("positions"); }
139 
141  const TensorMap &GetLineAttr() const { return line_attr_; }
142 
145 
150  core::Tensor &GetLineAttr(const std::string &key) {
151  return line_attr_.at(key);
152  }
153 
156  core::Tensor &GetLineIndices() { return GetLineAttr("indices"); }
157 
160  core::Tensor &GetLineColors() { return GetLineAttr("colors"); }
161 
165  const core::Tensor &GetPointAttr(const std::string &key) const {
166  return point_attr_.at(key);
167  }
168 
173  void RemovePointAttr(const std::string &key) { point_attr_.Erase(key); }
174 
178  return GetPointAttr("positions");
179  }
180 
185  const core::Tensor &GetLineAttr(const std::string &key) const {
186  return line_attr_.at(key);
187  }
188 
193  void RemoveLineAttr(const std::string &key) { line_attr_.Erase(key); }
194 
197  const core::Tensor &GetLineIndices() const {
198  return GetLineAttr("indices");
199  }
200 
203  const core::Tensor &GetLineColors() const { return GetLineAttr("colors"); }
204 
210  void SetPointAttr(const std::string &key, const core::Tensor &value) {
212  point_attr_[key] = value;
213  }
214 
217  void SetPointPositions(const core::Tensor &value) {
219  SetPointAttr("positions", value);
220  }
221 
227  void SetLineAttr(const std::string &key, const core::Tensor &value) {
229  line_attr_[key] = value;
230  }
231 
233  void SetLineIndices(const core::Tensor &value) {
235  SetLineAttr("indices", value);
236  }
237 
240  void SetLineColors(const core::Tensor &value) {
242  SetLineAttr("colors", value);
243  }
244 
249  bool HasPointAttr(const std::string &key) const {
250  return point_attr_.Contains(key) && GetPointAttr(key).GetLength() > 0 &&
251  GetPointAttr(key).GetLength() == GetPointPositions().GetLength();
252  }
253 
256  bool HasPointPositions() const { return HasPointAttr("positions"); }
257 
262  bool HasLineAttr(const std::string &key) const {
263  return line_attr_.Contains(key) && GetLineAttr(key).GetLength() > 0 &&
264  GetLineAttr(key).GetLength() == GetLineIndices().GetLength();
265  }
266 
269  bool HasLineIndices() const { return HasLineAttr("indices"); }
270 
276  bool HasLineColors() const { return HasLineAttr("colors"); }
277 
279  LineSet &Clear() override {
280  point_attr_.clear();
281  line_attr_.clear();
282  return *this;
283  }
284 
286  bool IsEmpty() const override { return !HasPointPositions(); }
287 
289  core::Tensor GetMinBound() const { return GetPointPositions().Min({0}); }
290 
292  core::Tensor GetMaxBound() const { return GetPointPositions().Max({0}); }
293 
295  core::Tensor GetCenter() const { return GetPointPositions().Mean({0}); }
296 
317  LineSet &Transform(const core::Tensor &transformation);
318 
324  LineSet &Translate(const core::Tensor &translation, bool relative = true);
325 
330  LineSet &Scale(double scale, const core::Tensor &center);
331 
338  LineSet &Rotate(const core::Tensor &R, const core::Tensor &center);
339 
341  core::Device GetDevice() const override { return device_; }
342 
351  const open3d::geometry::LineSet &lineset_legacy,
352  core::Dtype float_dtype = core::Float32,
353  core::Dtype int_dtype = core::Int64,
354  const core::Device &device = core::Device("CPU:0"));
355 
358 
361 
364 
373  TriangleMesh ExtrudeRotation(double angle,
374  const core::Tensor &axis,
375  int resolution = 16,
376  double translation = 0.0,
377  bool capping = true) const;
378 
385  double scale = 1.0,
386  bool capping = true) const;
387 
388 protected:
392 };
393 
394 } // namespace geometry
395 } // namespace t
396 } // namespace open3d
#define AssertTensorDevice(tensor,...)
Definition: TensorCheck.h:43
#define AssertTensorShape(tensor,...)
Definition: TensorCheck.h:58
bool copy
Definition: VtkUtils.cpp:73
Definition: Device.h:18
Definition: Dtype.h:20
Definition: Tensor.h:32
int64_t GetLength() const
Definition: Tensor.h:1124
Tensor Min(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1236
Tensor Mean(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1215
Tensor Max(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1243
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Definition: LineSet.h:29
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound.
Definition: BoundingVolume.h:46
Mix-in class for geometry types that can be visualized.
Definition: DrawableGeometry.h:19
The base geometry class.
Definition: Geometry.h:21
A LineSet contains points and lines joining them and optionally attributes on the points and lines.
Definition: LineSet.h:84
std::string ToString() const
Text description.
Definition: LineSet.cpp:55
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:125
const core::Tensor & GetLineIndices() const
Definition: LineSet.h:197
core::Device device_
Definition: LineSet.h:389
bool HasLineColors() const
Definition: LineSet.h:276
bool HasPointAttr(const std::string &key) const
Definition: LineSet.h:249
core::Tensor GetMaxBound() const
Returns the max bound for point coordinates.
Definition: LineSet.h:292
void SetLineColors(const core::Tensor &value)
Definition: LineSet.h:240
void RemoveLineAttr(const std::string &key)
Definition: LineSet.h:193
core::Tensor & GetPointAttr(const std::string &key)
Definition: LineSet.h:132
virtual ~LineSet() override
Definition: LineSet.h:107
void SetLineAttr(const std::string &key, const core::Tensor &value)
Definition: LineSet.h:227
core::Tensor & GetLineAttr(const std::string &key)
Definition: LineSet.h:150
LineSet(const core::Device &device=core::Device("CPU:0"))
Construct an empty LineSet on the provided device.
Definition: LineSet.cpp:25
const TensorMap & GetLineAttr() const
Getter for line_attr_ TensorMap. Used in Pybind.
Definition: LineSet.h:141
AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const
Create an axis-aligned bounding box from point attribute "positions".
Definition: LineSet.cpp:189
open3d::geometry::LineSet ToLegacy() const
Convert to a legacy Open3D LineSet.
Definition: LineSet.cpp:169
TriangleMesh ExtrudeLinear(const core::Tensor &vector, double scale=1.0, bool capping=true) const
Definition: LineSet.cpp:203
core::Tensor GetCenter() const
Returns the center for point coordinates.
Definition: LineSet.h:295
bool HasPointPositions() const
Definition: LineSet.h:256
void SetPointAttr(const std::string &key, const core::Tensor &value)
Definition: LineSet.h:210
const core::Tensor & GetPointAttr(const std::string &key) const
Definition: LineSet.h:165
bool HasLineAttr(const std::string &key) const
Definition: LineSet.h:262
LineSet Clone() const
Returns copy of the line set on the same device.
Definition: LineSet.h:117
TensorMap & GetLineAttr()
Getter for line_attr_ TensorMap.
Definition: LineSet.h:144
core::Tensor & GetLineIndices()
Definition: LineSet.h:156
core::Device GetDevice() const override
Returns the device attribute of this LineSet.
Definition: LineSet.h:341
const core::Tensor & GetLineAttr(const std::string &key) const
Definition: LineSet.h:185
LineSet & Scale(double scale, const core::Tensor &center)
Scales the points and lines of the LineSet.
Definition: LineSet.cpp:115
bool HasLineIndices() const
Definition: LineSet.h:269
LineSet & Transform(const core::Tensor &transformation)
Transforms the points and lines of the LineSet.
Definition: LineSet.cpp:96
LineSet To(const core::Device &device, bool copy=false) const
Definition: LineSet.cpp:41
core::Tensor & GetLineColors()
Definition: LineSet.h:160
LineSet & Clear() override
Clear all data in the line set.
Definition: LineSet.h:279
core::Tensor & GetPointPositions()
Definition: LineSet.h:138
void RemovePointAttr(const std::string &key)
Definition: LineSet.h:173
void SetLineIndices(const core::Tensor &value)
Set the value of the "indices" attribute in line_attr_.
Definition: LineSet.h:233
core::Tensor GetMinBound() const
Returns the max bound for point coordinates.
Definition: LineSet.h:289
TensorMap line_attr_
Definition: LineSet.h:391
void SetPointPositions(const core::Tensor &value)
Definition: LineSet.h:217
TensorMap point_attr_
Definition: LineSet.h:390
TensorMap & GetPointAttr()
Getter for point_attr_ TensorMap.
Definition: LineSet.h:126
LineSet & Translate(const core::Tensor &translation, bool relative=true)
Translates the points and lines of the LineSet.
Definition: LineSet.cpp:102
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:132
OrientedBoundingBox GetOrientedBoundingBox() const
Create an oriented bounding box from point attribute "positions".
Definition: LineSet.cpp:210
const core::Tensor & GetPointPositions() const
Definition: LineSet.h:177
const core::Tensor & GetLineColors() const
Definition: LineSet.h:203
TriangleMesh ExtrudeRotation(double angle, const core::Tensor &axis, int resolution=16, double translation=0.0, bool capping=true) const
Definition: LineSet.cpp:193
const TensorMap & GetPointAttr() const
Getter for point_attr_ TensorMap. Used in Pybind.
Definition: LineSet.h:123
bool IsEmpty() const override
Returns !HasPointPositions(), line indices are ignored.
Definition: LineSet.h:286
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:257
Definition: TensorMap.h:31
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:92
bool Contains(const std::string &key) const
Definition: TensorMap.h:187
A triangle mesh contains vertices and triangles.
Definition: TriangleMesh.h:94
const Dtype Int64
Definition: Dtype.cpp:47
const Dtype Float32
Definition: Dtype.cpp:42
constexpr nullopt_t nullopt
Definition: Optional.h:152
Definition: PinholeCameraIntrinsic.cpp:16