21 py::class_<LineSet, PyGeometry<LineSet>, std::shared_ptr<LineSet>,
Geometry,
23 line_set(m,
"LineSet", R
"(
24 A LineSet contains points and lines joining them and optionally attributes on
25 the points and lines. The ``LineSet`` class stores the attribute data in
26 key-value maps, where the key is the attribute name and value is a Tensor
27 containing the attribute data. There are two maps: one each for ``point``
30 The attributes of the line set have different levels::
32 import cloudViewer as cv3d
34 dtype_f = cv3d.core.float32
35 dtype_i = cv3d.core.int32
37 # Create an empty line set
38 # Use lineset.point to access the point attributes
39 # Use lineset.line to access the line attributes
40 lineset = cv3d.t.geometry.LineSet()
42 # Default attribute: point.positions, line.indices
43 # These attributes is created by default and are required by all line
44 # sets. The shape must be (N, 3) and (N, 2) respectively. The device of
45 # "positions" determines the device of the line set.
46 lineset.point.positions = cv3d.core.Tensor([[0, 0, 0],
49 [0, 1, 1]], dtype_f, device)
50 lineset.line.indices = cv3d.core.Tensor([[0, 1],
53 [3, 0]], dtype_i, device)
55 # Common attributes: line.colors
56 # Common attributes are used in built-in line set operations. The
57 # spellings must be correct. For example, if "color" is used instead of
58 # "color", some internal operations that expects "colors" will not work.
59 # "colors" must have shape (N, 3) and must be on the same device as the
61 lineset.line.colors = cv3d.core.Tensor([[0.0, 0.0, 0.0],
64 [0.3, 0.3, 0.3]], dtype_f, device)
66 # User-defined attributes
67 # You can also attach custom attributes. The value tensor must be on the
68 # same device as the line set. The are no restrictions on the shape or
70 lineset.point.labels = cv3d.core.Tensor(...)
71 lineset.line.features = cv3d.core.Tensor(...)
75 line_set.def(py::init<const core::Device&>(),
77 "Construct an empty LineSet on the provided device.")
78 .def(py::init<const core::Tensor&, const core::Tensor&>(),
79 "point_positions"_a,
"line_indices"_a, R
"(
80 Construct a LineSet from point_positions and line_indices.
82 The input tensors will be directly used as the underlying storage of the line
83 set (no memory copy). The resulting ``LineSet`` will have the same ``dtype``
84 and ``device`` as the tensor. The device for ``point_positions`` must be consistent with
87 m, "LineSet",
"__init__",
88 {{
"point_positions",
"A tensor with element shape (3,)"},
90 "A tensor with element shape (2,) and Int dtype."}});
92 py::detail::bind_copy_functions<LineSet>(line_set);
94 line_set.def(py::pickle(
97 return py::make_tuple(line_set.GetDevice(),
98 line_set.GetPointAttr(),
99 line_set.GetLineAttr());
105 "Cannot unpickle LineSet! Expecting a tuple of "
113 "Device ({}) is not available. LineSet will be "
121 for (
auto& kv : point_attr) {
122 line_set.SetPointAttr(kv.first, kv.second);
124 for (
auto& kv : line_attr) {
125 line_set.SetLineAttr(kv.first, kv.second);
135 line_set.def_property_readonly(
137 "Dictionary containing point attributes. The primary key "
138 "``positions`` contains point positions.");
139 line_set.def_property_readonly(
141 "Dictionary containing line attributes. The primary key "
142 "``indices`` contains indices of points defining the lines.");
148 "Transfer the line set to a specified device.",
"device"_a,
151 "Returns copy of the line set on the same device.");
157 "Transfer the line set to CPU. If the line set "
158 "is already on CPU, no copy will be performed.");
161 [](
const LineSet& line_set,
int device_id) {
164 "Transfer the line set to a CUDA device. If the line set "
165 "is already on the specified CUDA device, no copy will be "
171 "Returns the min bound for point coordinates.");
173 "Returns the max bound for point coordinates.");
175 "Returns the center for point coordinates.");
177 Transforms the points and lines. Custom attributes (e.g. point normals) are not
178 transformed. Extracts R, t from the transformation as:
181 T_{(4,4)} = \begin{bmatrix} R_{(3,3)} & t_{(3,1)} \\
182 O_{(1,3)} & s_{(1,1)} \end{bmatrix}
184 It assumes :math:`s = 1` (no scaling) and :math:`O = [0,0,0]` and applies the
185 transformation as :math:`P = R(P) + t`)");
187 m, "LineSet",
"transform",
189 "Transformation [Tensor of shape (4,4)]. Should be on the same "
190 "device as the LineSet"}});
193 "Translates points and lines of the LineSet.");
195 m,
"LineSet",
"translate",
197 "Translation tensor of dimension (3,). Should be on the same "
198 "device as the LineSet"},
200 "If true (default) translates relative to center of LineSet."}});
202 "Scale points and lines. Custom attributes are not scaled.");
204 m,
"LineSet",
"scale",
205 {{
"scale",
"Scale magnitude."},
207 "Center [Tensor of shape (3,)] about which the LineSet is to be "
208 "scaled. Should be on the same device as the LineSet."}});
210 "Rotate points and lines. Custom attributes (e.g. point "
211 "normals) are not rotated.");
213 m,
"LineSet",
"rotate",
214 {{
"R",
"Rotation [Tensor of shape (3,3)]."},
216 "Center [Tensor of shape (3,)] about which the LineSet is to be "
217 "rotated. Should be on the same device as the LineSet."}});
222 "Create a LineSet from a legacy Open3D LineSet.");
224 m,
"LineSet",
"from_legacy",
226 {
"lineset_legacy",
"Legacy Open3D LineSet."},
228 "Float32 or Float64, used to store floating point values, "
229 "e.g. points, normals, colors."},
231 "Int32 or Int64, used to store index values, e.g. line "
234 "The device where the resulting LineSet resides."},
237 "Convert to a legacy Open3D LineSet.");
239 line_set.def(
"get_axis_aligned_bounding_box",
241 "Create an axis-aligned bounding box from point attribute "
244 "Create an oriented bounding box from point attribute "
247 "axis"_a,
"resolution"_a = 16,
"translation"_a = 0.0,
249 R
"(Sweeps the line set rotationally about an axis.
252 angle (float): The rotation angle in degree.
253 axis (cloudViewer.core.Tensor): The rotation axis.
254 resolution (int): The resolution defines the number of intermediate sweeps
255 about the rotation axis.
256 translation (float): The translation along the rotation axis.
259 A triangle mesh with the result of the sweep operation.
263 This code generates a spring from a single line::
265 import cloudViewer as cv3d
267 line = cv3d.t.geometry.LineSet([[0.7,0,0],[1,0,0]], [[0,1]])
268 spring = line.extrude_rotation(3*360, [0,1,0], resolution=3*16, translation=2)
269 cv3d.visualization.draw([{'name': 'spring', 'geometry': spring}])
274 "scale"_a = 1.0,
"capping"_a =
true,
275 R
"(Sweeps the line set along a direction vector.
278 vector (cloudViewer.core.Tensor): The direction vector.
279 scale (float): Scalar factor which essentially scales the direction vector.
282 A triangle mesh with the result of the sweep operation.
286 This code generates an L-shaped mesh::
288 import cloudViewer as cv3d
290 lines = cv3d.t.geometry.LineSet([[1.0,0.0,0.0],[0,0,0],[0,0,1]], [[0,1],[1,2]])
291 mesh = lines.extrude_linear([0,1,0])
292 cv3d.visualization.draw([{'name': 'L', 'geometry': mesh}])
296 "Assigns unifom color to all the lines of the LineSet. "
297 "Floating color values are clipped between 00 and 1.0. Input "
298 "`color` should be a (3,) shape tensor.");
301 "view_width_px"_a,
"view_height_px"_a,
"intrinsic"_a,
"extrinsic"_a,
304 "cloudViewer.core.Tensor([], "
305 "dtype=cloudViewer.core.Dtype.Float32)"),
306 R
"(Factory function to create a LineSet from intrinsic and extrinsic
307 matrices. Camera reference frame is shown with XYZ axes in RGB.
310 view_width_px (int): The width of the view, in pixels.
311 view_height_px (int): The height of the view, in pixels.
312 intrinsic (cloudViewer.core.Tensor): The intrinsic matrix {3,3} shape.
313 extrinsic (cloudViewer.core.Tensor): The extrinsic matrix {4,4} shape.
314 scale (float): camera scale
315 color (cloudViewer.core.Tensor): color with float32 and shape {3}. Default is blue.
319 Draw a purple camera frame with XYZ axes in RGB::
321 import cloudViewer.core as o3c
322 from cloudViewer.t.geometry import LineSet
323 from cloudViewer.visualization import draw
324 K = o3c.Tensor([[512, 0, 512], [0, 512, 512], [0, 0, 1]], dtype=o3c.float32)
325 T = o3c.Tensor.eye(4, dtype=o3c.float32)
326 ls = LineSet.create_camera_visualization(1024, 1024, K, T, 1, [0.8, 0.2, 0.8])
std::string ToString() const
Returns string representation of device, e.g. "CPU:0", "CUDA:0".
bool IsAvailable() const
Returns true if the device is available.
Mix-in class for geometry types that can be visualized.
A LineSet contains points and lines joining them and optionally attributes on the points and lines.
core::Tensor GetCenter() const
Returns the center for point coordinates.
core::Tensor GetMaxBound() const
Returns the max bound for point coordinates.
std::string ToString() const
Text description.
LineSet & Translate(const core::Tensor &translation, bool relative=true)
Translates the points and lines of the LineSet.
LineSet & PaintUniformColor(const core::Tensor &color)
Assigns uniform color to all lines of the LineSet.
OrientedBoundingBox GetOrientedBoundingBox() const
Create an oriented bounding box from point attribute "positions".
const TensorMap & GetLineAttr() const
Getter for line_attr_ TensorMap. Used in Pybind.
LineSet Clone() const
Returns copy of the line set on the same device.
LineSet To(const core::Device &device, bool copy=false) const
TriangleMesh ExtrudeLinear(const core::Tensor &vector, double scale=1.0, bool capping=true) const
TriangleMesh ExtrudeRotation(double angle, const core::Tensor &axis, int resolution=16, double translation=0.0, bool capping=true) const
static LineSet CreateCameraVisualization(int view_width_px, int view_height_px, const core::Tensor &intrinsic, const core::Tensor &extrinsic, double scale, const core::Tensor &color={})
cloudViewer::geometry::LineSet ToLegacy() const
Convert to a legacy CloudViewer LineSet.
LineSet & Transform(const core::Tensor &transformation)
Transforms the points and lines of the LineSet.
static geometry::LineSet FromLegacy(const cloudViewer::geometry::LineSet &lineset_legacy, core::Dtype float_dtype=core::Float32, core::Dtype int_dtype=core::Int64, const core::Device &device=core::Device("CPU:0"))
const TensorMap & GetPointAttr() const
Getter for point_attr_ TensorMap. Used in Pybind.
AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const
Create an axis-aligned bounding box from point attribute "positions".
LineSet & Rotate(const core::Tensor &R, const core::Tensor ¢er)
Rotates the points and lines of the line set. Custom attributes (e.g.: point or line normals) are not...
core::Tensor GetMinBound() const
Returns the max bound for point coordinates.
LineSet & Scale(double scale, const core::Tensor ¢er)
Scales the points and lines of the LineSet.
void ClassMethodDocInject(py::module &pybind_module, const std::string &class_name, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
void pybind_lineset(py::module &m)
Generic file read and write utility for python interface.