Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.16.0
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-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 #include "open3d/utility/Logging.h"
39 
40 namespace open3d {
41 namespace t {
42 namespace geometry {
43 
44 class TriangleMesh;
45 
102 
103 class LineSet : public Geometry, public DrawableGeometry {
104 public:
106  LineSet(const core::Device &device = core::Device("CPU:0"));
107 
123  LineSet(const core::Tensor &point_positions,
124  const core::Tensor &line_indices);
125 
126  virtual ~LineSet() override {}
127 
133  LineSet To(const core::Device &device, bool copy = false) const;
134 
136  LineSet Clone() const { return To(GetDevice(), /*copy=*/true); }
137 
139  std::string ToString() const;
140 
142  const TensorMap &GetPointAttr() const { return point_attr_; }
143 
146 
151  core::Tensor &GetPointAttr(const std::string &key) {
152  return point_attr_.at(key);
153  }
154 
157  core::Tensor &GetPointPositions() { return GetPointAttr("positions"); }
158 
160  const TensorMap &GetLineAttr() const { return line_attr_; }
161 
164 
169  core::Tensor &GetLineAttr(const std::string &key) {
170  return line_attr_.at(key);
171  }
172 
175  core::Tensor &GetLineIndices() { return GetLineAttr("indices"); }
176 
179  core::Tensor &GetLineColors() { return GetLineAttr("colors"); }
180 
184  const core::Tensor &GetPointAttr(const std::string &key) const {
185  return point_attr_.at(key);
186  }
187 
192  void RemovePointAttr(const std::string &key) { point_attr_.Erase(key); }
193 
197  return GetPointAttr("positions");
198  }
199 
204  const core::Tensor &GetLineAttr(const std::string &key) const {
205  return line_attr_.at(key);
206  }
207 
212  void RemoveLineAttr(const std::string &key) { line_attr_.Erase(key); }
213 
216  const core::Tensor &GetLineIndices() const {
217  return GetLineAttr("indices");
218  }
219 
222  const core::Tensor &GetLineColors() const { return GetLineAttr("colors"); }
223 
229  void SetPointAttr(const std::string &key, const core::Tensor &value) {
231  point_attr_[key] = value;
232  }
233 
236  void SetPointPositions(const core::Tensor &value) {
238  SetPointAttr("positions", value);
239  }
240 
246  void SetLineAttr(const std::string &key, const core::Tensor &value) {
248  line_attr_[key] = value;
249  }
250 
252  void SetLineIndices(const core::Tensor &value) {
254  SetLineAttr("indices", value);
255  }
256 
259  void SetLineColors(const core::Tensor &value) {
261  SetLineAttr("colors", value);
262  }
263 
268  bool HasPointAttr(const std::string &key) const {
269  return point_attr_.Contains(key) && GetPointAttr(key).GetLength() > 0 &&
270  GetPointAttr(key).GetLength() == GetPointPositions().GetLength();
271  }
272 
275  bool HasPointPositions() const { return HasPointAttr("positions"); }
276 
281  bool HasLineAttr(const std::string &key) const {
282  return line_attr_.Contains(key) && GetLineAttr(key).GetLength() > 0 &&
283  GetLineAttr(key).GetLength() == GetLineIndices().GetLength();
284  }
285 
288  bool HasLineIndices() const { return HasLineAttr("indices"); }
289 
295  bool HasLineColors() const { return HasLineAttr("colors"); }
296 
298  LineSet &Clear() override {
299  point_attr_.clear();
300  line_attr_.clear();
301  return *this;
302  }
303 
305  bool IsEmpty() const override { return !HasPointPositions(); }
306 
308  core::Tensor GetMinBound() const { return GetPointPositions().Min({0}); }
309 
311  core::Tensor GetMaxBound() const { return GetPointPositions().Max({0}); }
312 
314  core::Tensor GetCenter() const { return GetPointPositions().Mean({0}); }
315 
336  LineSet &Transform(const core::Tensor &transformation);
337 
343  LineSet &Translate(const core::Tensor &translation, bool relative = true);
344 
349  LineSet &Scale(double scale, const core::Tensor &center);
350 
357  LineSet &Rotate(const core::Tensor &R, const core::Tensor &center);
358 
360  core::Device GetDevice() const override { return device_; }
361 
370  const open3d::geometry::LineSet &lineset_legacy,
371  core::Dtype float_dtype = core::Float32,
372  core::Dtype int_dtype = core::Int64,
373  const core::Device &device = core::Device("CPU:0"));
374 
377 
380 
389  TriangleMesh ExtrudeRotation(double angle,
390  const core::Tensor &axis,
391  int resolution = 16,
392  double translation = 0.0,
393  bool capping = true) const;
394 
401  double scale = 1.0,
402  bool capping = true) const;
403 
404 protected:
408 };
409 
410 } // namespace geometry
411 } // namespace t
412 } // namespace open3d
const TensorMap & GetPointAttr() const
Getter for point_attr_ TensorMap. Used in Pybind.
Definition: LineSet.h:142
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:144
bool HasLineIndices() const
Definition: LineSet.h:288
constexpr nullopt_t nullopt
Definition: Optional.h:171
LineSet Clone() const
Returns copy of the line set on the same device.
Definition: LineSet.h:136
const Dtype Int64
Definition: Dtype.cpp:66
LineSet & Scale(double scale, const core::Tensor &center)
Scales the points and lines of the LineSet.
Definition: LineSet.cpp:134
TensorMap & GetLineAttr()
Getter for line_attr_ TensorMap.
Definition: LineSet.h:163
core::Tensor GetMaxBound() const
Returns the max bound for point coordinates.
Definition: LineSet.h:311
TriangleMesh ExtrudeRotation(double angle, const core::Tensor &axis, int resolution=16, double translation=0.0, bool capping=true) const
Definition: LineSet.cpp:212
core::Tensor GetCenter() const
Returns the center for point coordinates.
Definition: LineSet.h:314
core::Tensor & GetPointPositions()
Definition: LineSet.h:157
TensorMap line_attr_
Definition: LineSet.h:407
Definition: Dtype.h:39
core::Tensor & GetPointAttr(const std::string &key)
Definition: LineSet.h:151
const core::Tensor & GetLineIndices() const
Definition: LineSet.h:216
A triangle mesh contains vertices and triangles.
Definition: TriangleMesh.h:111
bool HasPointAttr(const std::string &key) const
Definition: LineSet.h:268
void RemovePointAttr(const std::string &key)
Definition: LineSet.h:192
LineSet(const core::Device &device=core::Device("CPU:0"))
Construct an empty LineSet on the provided device.
Definition: LineSet.cpp:44
core::Device GetDevice() const override
Returns the device attribute of this LineSet.
Definition: LineSet.h:360
core::Tensor & GetLineIndices()
Definition: LineSet.h:175
const Dtype Float32
Definition: Dtype.cpp:61
LineSet & Transform(const core::Tensor &transformation)
Transforms the points and lines of the LineSet.
Definition: LineSet.cpp:115
Tensor Min(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1217
void SetLineIndices(const core::Tensor &value)
Set the value of the "indices" attribute in line_attr_.
Definition: LineSet.h:252
Tensor Max(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1224
#define AssertTensorShape(tensor,...)
Definition: TensorCheck.h:77
void SetLineAttr(const std::string &key, const core::Tensor &value)
Definition: LineSet.h:246
void SetPointPositions(const core::Tensor &value)
Definition: LineSet.h:236
LineSet & Translate(const core::Tensor &translation, bool relative=true)
Translates the points and lines of the LineSet.
Definition: LineSet.cpp:121
TensorMap point_attr_
Definition: LineSet.h:406
bool HasLineColors() const
Definition: LineSet.h:295
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:151
bool Contains(const std::string &key) const
Definition: TensorMap.h:206
bool HasPointPositions() const
Definition: LineSet.h:275
Definition: Device.h:37
const core::Tensor & GetLineColors() const
Definition: LineSet.h:222
Tensor Mean(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1196
open3d::geometry::LineSet ToLegacy() const
Convert to a legacy Open3D LineSet.
Definition: LineSet.cpp:188
#define AssertTensorDevice(tensor,...)
Definition: TensorCheck.h:62
AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const
Create an axis-aligned bounding box from point attribute "positions".
Definition: LineSet.cpp:208
The base geometry class.
Definition: Geometry.h:40
A LineSet contains points and lines joining them and optionally attributes on the points and lines...
Definition: LineSet.h:103
Definition: PinholeCameraIntrinsic.cpp:35
core::Tensor & GetLineAttr(const std::string &key)
Definition: LineSet.h:169
core::Tensor & GetLineColors()
Definition: LineSet.h:179
void SetPointAttr(const std::string &key, const core::Tensor &value)
Definition: LineSet.h:229
core::Tensor GetMinBound() const
Returns the max bound for point coordinates.
Definition: LineSet.h:308
Mix-in class for geometry types that can be visualized.
Definition: DrawableGeometry.h:38
const core::Tensor & GetPointPositions() const
Definition: LineSet.h:196
std::string ToString() const
Text description.
Definition: LineSet.cpp:74
TensorMap & GetPointAttr()
Getter for point_attr_ TensorMap.
Definition: LineSet.h:145
bool HasLineAttr(const std::string &key) const
Definition: LineSet.h:281
TriangleMesh ExtrudeLinear(const core::Tensor &vector, double scale=1.0, bool capping=true) const
Definition: LineSet.cpp:222
void SetLineColors(const core::Tensor &value)
Definition: LineSet.h:259
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound...
Definition: BoundingVolume.h:63
LineSet & Clear() override
Clear all data in the line set.
Definition: LineSet.h:298
const core::Tensor & GetLineAttr(const std::string &key) const
Definition: LineSet.h:204
void RemoveLineAttr(const std::string &key)
Definition: LineSet.h:212
LineSet To(const core::Device &device, bool copy=false) const
Definition: LineSet.cpp:60
const TensorMap & GetLineAttr() const
Getter for line_attr_ TensorMap. Used in Pybind.
Definition: LineSet.h:160
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Definition: LineSet.h:48
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:111
const core::Tensor & GetPointAttr(const std::string &key) const
Definition: LineSet.h:184
bool copy
Definition: VtkUtils.cpp:89
int64_t GetLength() const
Definition: Tensor.h:1130
bool IsEmpty() const override
Returns !HasPointPositions(), line indices are ignored.
Definition: LineSet.h:305
virtual ~LineSet() override
Definition: LineSet.h:126
core::Device device_
Definition: LineSet.h:405
Definition: TensorMap.h:50