ocnn.octree
Decodes the shuffled key to |
|
Encodes |
|
Represents a point cloud and contains some elementary transformations. |
|
Builds an octree from an input point cloud. |
|
A wrapper of |
|
A wrapper of |
|
A wrapper of |
- key2xyz(key: Tensor, depth: int = 16)[source]
Decodes the shuffled key to
x,y,zcoordinates and the batch index based on pre-computed look up tables.- Parameters:
key (torch.Tensor) – The shuffled key.
depth (int) – The depth of the shuffled key, and must be smaller than 17 (< 17).
- xyz2key(x: Tensor, y: Tensor, z: Tensor, b: Tensor | int | None = None, depth: int = 16)[source]
Encodes
x,y,zcoordinates to the shuffled keys based on pre-computed look up tables. The speed of this function is much faster than the method based on for-loop.- Parameters:
x (torch.Tensor) – The x coordinate.
y (torch.Tensor) – The y coordinate.
z (torch.Tensor) – The z coordinate.
b (torch.Tensor or int) – The batch index of the coordinates, and should be smaller than 32768. If
bistorch.Tensor, the size ofbmust be the same asx,y, andz.depth (int) – The depth of the shuffled key, and must be smaller than 17 (< 17).
- class Points(points: Tensor, normals: Tensor | None = None, features: Tensor | None = None, labels: Tensor | None = None, batch_id: Tensor | None = None, batch_size: int = 1)[source]
Represents a point cloud and contains some elementary transformations.
- Parameters:
points (torch.Tensor) – The coordinates of the points with a shape of
(N, 3), whereNis the number of points.normals (torch.Tensor or None) – The point normals with a shape of
(N, 3).features (torch.Tensor or None) – The point features with a shape of
(N, C), whereCis the channel of features.labels (torch.Tensor or None) – The point labels with a shape of
(N, K), whereKis the channel of labels.batch_id (torch.Tensor or None) – The batch indices for each point with a shape of
(N, 1).batch_size (int) – The batch size.
- property npt
- orient_normal(axis: str = 'x')[source]
Orients the point normals along a given axis.
- Parameters:
axis (int) – The coordinate axes, choose from
x,yandz. (default:x)
- scale(factor: Tensor)[source]
Rescales the point cloud.
- Parameters:
factor (torch.Tensor) – The scale factor with shape
(3,).
- rotate(angle: Tensor)[source]
Rotates the point cloud.
- Parameters:
angle (torch.Tensor) – The rotation angles in radian with shape
(3,).
- translate(dis: Tensor)[source]
Translates the point cloud.
- Parameters:
dis (torch.Tensor) – The displacement with shape
(3,).
- flip(axis: str)[source]
Flips the point cloud along the given
axis.- Parameters:
axis (str) – The flipping axis, choosen from
x,y, and :obj`z`.
- clip(min: float = -1.0, max: float = 1.0, esp: float = 0.01)[source]
Clips the point cloud to
[min+esp, max-esp]and returns the mask.
- inbox_mask(bbmin: float | Tensor = -1.0, bbmax: float | Tensor = 1.0)[source]
Returns a mask indicating whether the points are within the specified bounding box or not.
- centralize_scale(bbmin: Tensor, bbmax: Tensor, scale: float = 1.0)[source]
Centralizes the point cloud to
[-scale, scale].- Parameters:
bbmin (torch.Tensor) – The minimum coordinates of the bounding box.
bbmax (torch.Tensor) – The maximum coordinates of the bounding box.
scale (float) – The scale factor
- normalize(bbmin: Tensor, bbmax: Tensor, scale: float, inplace: bool = False)[source]
Normalizes the point cloud to
[0, scale].- Parameters:
bbmin (torch.Tensor) – The minimum coordinates of the bounding box.
bbmax (torch.Tensor) – The maximum coordinates of the bounding box.
scale (float) – The scale factor.
inplace (bool) – If True, the normalization is performed in-place; otherwise, directly returns the normalized points without modifying the original points.
- to(device: device | str, non_blocking: bool = False)[source]
Moves the Points to a specified device.
- Parameters:
device (torch.device or str) – The destination device.
non_blocking (bool) – If True and the source is in pinned memory, the copy will be asynchronous with respect to the host. Otherwise, the argument has no effect. Default: False.
- merge_points(points: List[Points], update_batch_info: bool = True)[source]
Merges a list of points into one batch.
- Parameters:
points (List[Octree]) – A list of points to merge. The batch size of each points in the list is assumed to be 1, and the
batch_size,batch_id, andbatch_nptin the points are ignored.
- classmethod init_points(device: device | str | None = None, batch_size: int = 1)[source]
Initialzes a Points object with dummy data on a specified device.
- Parameters:
device (torch.device or str or None) – The device of the Points. If
None, the device is set tocpu.batch_size (int) – The batch size.
- class Octree(depth: int, full_depth: int = 2, batch_size: int = 1, device: device | str = 'cpu', **kwargs)[source]
Builds an octree from an input point cloud.
- Parameters:
Note
The octree data structure requires that if an octree node has children nodes, the number of children nodes is exactly 8, in which some of the nodes are empty and some nodes are non-empty. The properties of an octree, including
keys,childrenandneighs, contain both non-empty and empty nodes, and other properties, includingfeatures,normalsandpoints, contain only non-empty nodes.Note
The point cloud must be strictly in range
[-1, 1]. A good practice is to normalize it into[-0.99, 0.99]or[0.9, 0.9]to retain some margin.- xyzb(depth: int, nempty: bool = False)[source]
Returns the xyz coordinates and the batch indices of each octree node.
- nempty_mask(depth: int, reset: bool = False)[source]
Returns a binary mask which indicates whether the cooreponding octree node is empty or not.
- nempty_index(depth: int, reset: bool = False)[source]
Returns the indices of non-empty octree nodes.
- nempty_neigh(depth: int, reset: bool = False)[source]
Returns the neighborhoods of non-empty octree nodes. :param depth: The depth of the octree. :type depth: int :param reset: If True, recomputes the neighborhoods. :type reset: bool
- remap_nempty_neigh(neigh: Tensor, depth: int)[source]
Remaps the neighborhood indices to the non-empty octree nodes.
- Parameters:
neigh (torch.Tensor) – The input neighborhoods with shape
(N, 27).depth (int) – The depth of the octree.
- build_octree(point_cloud: Points, bbmin: float | Tensor = -1.0, bbmax: float | Tensor = 1.0)[source]
Builds an octree from a point cloud.
- Parameters:
point_cloud (Points) – The input point cloud.
bbmin (float or torch.Tensor) – The minimum coordinates of the bounding box.
bbmax (float or torch.Tensor) – The maximum coordinates of the bounding box.
Note
For a point cloud in range
[-1, 1], a good practice is to normalize it into[0.9, 0.9]to retain some margin.
- octree_grow_full(depth: int, update_neigh: bool = True)[source]
Builds the full octree, which is essentially a dense volumetric grid.
- octree_split(split: Tensor, depth: int)[source]
Sets whether the octree nodes in
depthare splitted or not.- Parameters:
split (torch.Tensor) – The input tensor with its element indicating status of each octree node: 0 - empty, 1 - non-empty or splitted.
depth (int) – The depth of current octree.
- octree_grow(depth: int, update_neigh: bool = True)[source]
Grows the octree and updates the relevant properties. And in most cases, call
Octree.octree_split()to update the splitting status of the octree before this function.
- construct_neigh(depth: int)[source]
Constructs the
3x3x3neighbors for each octree node.- Parameters:
depth (int) – The octree depth with a value larger than 0 (
>0).
- search_xyzb(query: Tensor, depth: int, nempty: bool = False)[source]
Searches the octree nodes given the query points.
- Parameters:
query (torch.Tensor) – The coordinates of query points with shape
(N, 4). The first 3 channels of the coordinates arex,y, andz, and the last channel is the batch index. Note that the coordinates must be in range[0, 2^depth).depth (int) – The depth of the octree layer. nemtpy (bool): If true, only searches the non-empty octree nodes.
- search_key(query: Tensor, depth: int, nempty: bool = False)[source]
Searches the octree nodes given the query points.
- Parameters:
query (torch.Tensor) – The keys of query points with shape
(N,), which are computed from the coordinates of query points.depth (int) – The depth of the octree layer. nemtpy (bool): If true, only searches the non-empty octree nodes.
- get_neigh(depth: int, kernel: str = '333', stride: int = 1, nempty: bool = False)[source]
Returns the neighborhoods given the depth and a kernel shape.
- Parameters:
depth (int) – The octree depth with a value larger than 0 (
>0).kernel (str) – The kernel shape from
333,311,131,113,222,331,133, and313.stride (int) – The stride of neighborhoods (
1or2). If the stride is2, always returns the neighborhood of the first siblings.nempty (bool) – If True, only returns the neighborhoods of the non-empty octree nodes.
- get_input_feature(feature: str, nempty: bool = False)[source]
Returns the initial input feature stored in octree.
- Parameters:
feature (str) – A string used to indicate which features to extract from the input octree. If the character
Nis infeature, the normal signal is extracted (3 channels). Similarly, ifDis infeature, the local displacement is extracted (1 channels). IfLis infeature, the local coordinates of the averaged points in each octree node is extracted (3 channels). IfPis infeature, the global coordinates are extracted (3 channels). IfFis infeature, other features (like colors) are extracted (k channels).nempty (bool) – If false, gets the features of all octree nodes.
- to_points(rescale: bool = True)[source]
Converts averaged points in the octree to a point cloud.
- Parameters:
rescale (bool) – rescale the xyz coordinates to [-1, 1] if True.
- to(device: device | str, non_blocking: bool = False)[source]
Moves the octree to a specified device.
- Parameters:
device (torch.device or str) – The destination device.
non_blocking (bool) – If True and the source is in pinned memory, the copy will be asynchronous with respect to the host. Otherwise, the argument has no effect. Default: False.
- classmethod init_like(octree: Octree, device: device | str | None = None)[source]
Initializes the octree like another octree.
- Parameters:
octree (Octree) – The reference octree.
device (torch.device or str) – The device to use for computation.
- classmethod init_octree(depth: int, full_depth: int = 2, batch_size: int = 1, device: device | str = 'cpu')[source]
Initializes an octree to
full_depth.- Parameters:
depth (int) – The depth of the octree.
full_depth (int) – The octree layers with a depth small than
full_depthare forced to be full.batch_size (int, optional) – The batch size.
device (torch.device or str) – The device to use for computation.
- Returns:
The initialized Octree object.
- Return type:
- merge_points(points: List[Points], update_batch_info: bool = True)[source]
A wrapper of
Points.merge_points().Deprecated since version 2.2.7: Use
Points.merge_points()instead.
- merge_octrees(octrees: List[Octree])[source]
A wrapper of
Octree.merge_octrees().Deprecated since version 2.2.7: Use
Octree.merge_octrees()instead.
- init_octree(depth: int, full_depth: int = 2, batch_size: int = 1, device: device | str = 'cpu')[source]
A wrapper of
Octree.init_octree().Deprecated since version 2.2.7: Use
Octree.init_octree()instead.