cloudViewer.t.geometry.LineSet#
- class cloudViewer.t.geometry.LineSet#
A LineSet contains points and lines joining them and optionally attributes on the points and lines. The
LineSetclass stores the attribute data in key-value maps, where the key is the attribute name and value is a Tensor containing the attribute data. There are two maps: one each forpointandline.The attributes of the line set have different levels:
import cloudViewer as cv3d dtype_f = cv3d.core.float32 dtype_i = cv3d.core.int32 # Create an empty line set # Use lineset.point to access the point attributes # Use lineset.line to access the line attributes lineset = cv3d.t.geometry.LineSet() # Default attribute: point.positions, line.indices # These attributes is created by default and are required by all line # sets. The shape must be (N, 3) and (N, 2) respectively. The device of # "positions" determines the device of the line set. lineset.point.positions = cv3d.core.Tensor([[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1]], dtype_f, device) lineset.line.indices = cv3d.core.Tensor([[0, 1], [1, 2], [2, 3], [3, 0]], dtype_i, device) # Common attributes: line.colors # Common attributes are used in built-in line set operations. The # spellings must be correct. For example, if "color" is used instead of # "color", some internal operations that expects "colors" will not work. # "colors" must have shape (N, 3) and must be on the same device as the # line set. lineset.line.colors = cv3d.core.Tensor([[0.0, 0.0, 0.0], [0.1, 0.1, 0.1], [0.2, 0.2, 0.2], [0.3, 0.3, 0.3]], dtype_f, device) # User-defined attributes # You can also attach custom attributes. The value tensor must be on the # same device as the line set. The are no restrictions on the shape or # dtype, e.g., lineset.point.labels = cv3d.core.Tensor(...) lineset.line.features = cv3d.core.Tensor(...)
- __init__(*args, **kwargs)#
Overloaded function.
__init__(self: cloudViewer.t.geometry.LineSet, device: cloudViewer.core.Device = Device(“CPU”, 0)) -> None
Construct an empty LineSet on the provided device.
__init__(self: cloudViewer.t.geometry.LineSet, point_positions: cloudViewer.core.Tensor, line_indices: cloudViewer.core.Tensor) -> None
Construct a LineSet from point_positions and line_indices.
The input tensors will be directly used as the underlying storage of the line set (no memory copy). The resulting
LineSetwill have the samedtypeanddeviceas the tensor. The device forpoint_positionsmust be consistent withline_indices.__init__(self: cloudViewer.t.geometry.LineSet, arg0: cloudViewer.t.geometry.LineSet) -> None
Copy constructor
- clear(self)#
Clear all elements in the geometry.
- Returns:
cloudViewer.t.geometry.Geometry
- clone(self: cloudViewer.t.geometry.LineSet) cloudViewer.t.geometry.LineSet#
Returns copy of the line set on the same device.
- cpu(self: cloudViewer.t.geometry.LineSet) cloudViewer.t.geometry.LineSet#
Transfer the line set to CPU. If the line set is already on CPU, no copy will be performed.
- static create_camera_visualization(view_width_px: SupportsInt, view_height_px: SupportsInt, intrinsic: cloudViewer.core.Tensor, extrinsic: cloudViewer.core.Tensor, scale: SupportsFloat = 1.0, color: cloudViewer.core.Tensor = cloudViewer.core.Tensor([], dtype=cloudViewer.core.Dtype.Float32)) cloudViewer.t.geometry.LineSet#
Factory function to create a LineSet from intrinsic and extrinsic matrices. Camera reference frame is shown with XYZ axes in RGB.
- Parameters:
view_width_px (int) – The width of the view, in pixels.
view_height_px (int) – The height of the view, in pixels.
intrinsic (cloudViewer.core.Tensor) – The intrinsic matrix {3,3} shape.
extrinsic (cloudViewer.core.Tensor) – The extrinsic matrix {4,4} shape.
scale (float) – camera scale
color (cloudViewer.core.Tensor) – color with float32 and shape {3}. Default is blue.
Example
Draw a purple camera frame with XYZ axes in RGB:
import cloudViewer.core as o3c from cloudViewer.t.geometry import LineSet from cloudViewer.visualization import draw K = o3c.Tensor([[512, 0, 512], [0, 512, 512], [0, 0, 1]], dtype=o3c.float32) T = o3c.Tensor.eye(4, dtype=o3c.float32) ls = LineSet.create_camera_visualization(1024, 1024, K, T, 1, [0.8, 0.2, 0.8]) draw([ls])
- cuda(self: cloudViewer.t.geometry.LineSet, device_id: SupportsInt = 0) cloudViewer.t.geometry.LineSet#
Transfer the line set to a CUDA device. If the line set is already on the specified CUDA device, no copy will be performed.
- extrude_linear(self: cloudViewer.t.geometry.LineSet, vector: cloudViewer.core.Tensor, scale: SupportsFloat = 1.0, capping: bool = True) cloudViewer::t::geometry::TriangleMesh#
Sweeps the line set along a direction vector.
- Parameters:
vector (cloudViewer.core.Tensor) – The direction vector.
scale (float) – Scalar factor which essentially scales the direction vector.
- Returns:
A triangle mesh with the result of the sweep operation.
Example
This code generates an L-shaped mesh:
import cloudViewer as cv3d lines = cv3d.t.geometry.LineSet([[1.0,0.0,0.0],[0,0,0],[0,0,1]], [[0,1],[1,2]]) mesh = lines.extrude_linear([0,1,0]) cv3d.visualization.draw([{'name': 'L', 'geometry': mesh}])
- extrude_rotation(self: cloudViewer.t.geometry.LineSet, angle: SupportsFloat, axis: cloudViewer.core.Tensor, resolution: SupportsInt = 16, translation: SupportsFloat = 0.0, capping: bool = True) cloudViewer::t::geometry::TriangleMesh#
Sweeps the line set rotationally about an axis.
- Parameters:
angle (float) – The rotation angle in degree.
axis (cloudViewer.core.Tensor) – The rotation axis.
resolution (int) – The resolution defines the number of intermediate sweeps about the rotation axis.
translation (float) – The translation along the rotation axis.
- Returns:
A triangle mesh with the result of the sweep operation.
Example
This code generates a spring from a single line:
import cloudViewer as cv3d line = cv3d.t.geometry.LineSet([[0.7,0,0],[1,0,0]], [[0,1]]) spring = line.extrude_rotation(3*360, [0,1,0], resolution=3*16, translation=2) cv3d.visualization.draw([{'name': 'spring', 'geometry': spring}])
- static from_legacy(lineset_legacy, float_dtype=Float32, int_dtype=Int64, device=Device('CPU', 0))#
Create a LineSet from a legacy Open3D LineSet.
- Parameters:
lineset_legacy (cloudViewer.geometry.LineSet) – Legacy Open3D LineSet.
float_dtype (cloudViewer.core.Dtype, optional, default=Float32) – Float32 or Float64, used to store floating point values, e.g. points, normals, colors.
int_dtype (cloudViewer.core.Dtype, optional, default=Int64) – Int32 or Int64, used to store index values, e.g. line indices.
device (cloudViewer.core.Device, optional, default=Device("CPU", 0)) – The device where the resulting LineSet resides.
- Returns:
cloudViewer.t.geometry.LineSet
- get_axis_aligned_bounding_box(self: cloudViewer.t.geometry.LineSet) cloudViewer::t::geometry::AxisAlignedBoundingBox#
Create an axis-aligned bounding box from point attribute ‘positions’.
- get_center(self: cloudViewer.t.geometry.LineSet) cloudViewer.core.Tensor#
Returns the center for point coordinates.
- get_max_bound(self: cloudViewer.t.geometry.LineSet) cloudViewer.core.Tensor#
Returns the max bound for point coordinates.
- get_min_bound(self: cloudViewer.t.geometry.LineSet) cloudViewer.core.Tensor#
Returns the min bound for point coordinates.
- get_oriented_bounding_box(self: cloudViewer.t.geometry.LineSet) cloudViewer::t::geometry::OrientedBoundingBox#
Create an oriented bounding box from point attribute ‘positions’.
- has_valid_material(self: cloudViewer.t.geometry.DrawableGeometry) bool#
Returns true if the geometry’s material is valid.
- is_empty(self)#
Returns
Trueiff the geometry is empty.- Returns:
bool
- paint_uniform_color(self: cloudViewer.t.geometry.LineSet, color: cloudViewer.core.Tensor) cloudViewer.t.geometry.LineSet#
Assigns unifom color to all the lines of the LineSet. Floating color values are clipped between 00 and 1.0. Input color should be a (3,) shape tensor.
- rotate(self, R, center)#
Rotate points and lines. Custom attributes (e.g. point normals) are not rotated.
- Parameters:
R (cloudViewer.core.Tensor) – Rotation [Tensor of shape (3,3)].
center (cloudViewer.core.Tensor) – Center [Tensor of shape (3,)] about which the LineSet is to be rotated. Should be on the same device as the LineSet.
- Returns:
cloudViewer.t.geometry.LineSet
- scale(self, scale, center)#
Scale points and lines. Custom attributes are not scaled.
- Parameters:
scale (SupportsFloat) – Scale magnitude.
center (cloudViewer.core.Tensor) – Center [Tensor of shape (3,)] about which the LineSet is to be scaled. Should be on the same device as the LineSet.
- Returns:
cloudViewer.t.geometry.LineSet
- to(self: cloudViewer.t.geometry.LineSet, device: cloudViewer.core.Device, copy: bool = False) cloudViewer.t.geometry.LineSet#
Transfer the line set to a specified device.
- to_legacy(self: cloudViewer.t.geometry.LineSet) cloudViewer.geometry.LineSet#
Convert to a legacy Open3D LineSet.
- transform(self, transformation)#
Transforms the points and lines. Custom attributes (e.g. point normals) are not transformed. Extracts R, t from the transformation as:
\[\begin{split}T_{(4,4)} = \begin{bmatrix} R_{(3,3)} & t_{(3,1)} \\ O_{(1,3)} & s_{(1,1)} \end{bmatrix}\end{split}\]It assumes \(s = 1\) (no scaling) and \(O = [0,0,0]\) and applies the transformation as \(P = R(P) + t\)
- Parameters:
transformation (cloudViewer.core.Tensor) – Transformation [Tensor of shape (4,4)]. Should be on the same device as the LineSet
- Returns:
cloudViewer.t.geometry.LineSet
- translate(self, translation, relative=True)#
Translates points and lines of the LineSet.
- Parameters:
translation (cloudViewer.core.Tensor) – Translation tensor of dimension (3,). Should be on the same device as the LineSet
relative (bool, optional, default=True) – If true (default) translates relative to center of LineSet.
- Returns:
cloudViewer.t.geometry.LineSet
- property device#
Returns the device of the geometry.
- property is_cpu#
Returns true if the geometry is on CPU.
- property is_cuda#
Returns true if the geometry is on CUDA.
- property line#
Dictionary containing line attributes. The primary key
indicescontains indices of points defining the lines.
- property material#
- property point#
Dictionary containing point attributes. The primary key
positionscontains point positions.