module documentation

3D utilities.

Copyright 2017-2022, Voxel51, Inc.

Class OrthographicProjectionMetadata Class for storing metadata about orthographic projections.
Function compute_cuboid_iou Computes the IoU between the given ground truth and predicted cuboids.
Function compute_orthographic_projection_image Generates an orthographic projection image for the given PCD file onto the specified plane (default xy plane).
Function compute_orthographic_projection_images Computes orthographic projection images for the point clouds in the given collection.
Function get_scene_asset_paths Extracts all asset paths for the specified 3D scenes.
Function pcd_to_3d Converts the point cloud samples in the given dataset to 3D samples.
Constant DEFAULT_SHADING_GRADIENT_MAP Undocumented
Variable logger Undocumented
Variable o3d Undocumented
Class _Box No class docstring; 0/6 instance variable, 2/5 methods documented
Function _clamp_to_discrete Discretize by mapping each continuous value in arr to the closest value in discrete.
Function _classify_point_to_plane Classify position of a point w.r.t the given plane.
Function _clip_poly Clips the polygon with the plane using the Sutherland-Hodgman algorithm.
Function _compute_intersection_points Computes the intersection of two boxes.
Function _contains_none Undocumented
Function _fill_none Undocumented
Function _get_3d_slice Undocumented
Function _get_pcd_filepath_from_scene Undocumented
Function _get_scene_asset_paths_single Undocumented
Function _get_scene_paths Return Tuple of scene paths to use and whether all are local This function is a no-op here but could be different in a repo fork.
Function _inside Checks whether a given point is on a 2D plane.
Function _intersect Computes the intersection of a line with an axis-aligned plane.
Function _intersect_box_poly Clips the polygon against the faces of the axis-aligned box.
Function _make_scene Undocumented
Function _parse_point_cloud Undocumented
Function _parse_size Undocumented
Function _pcd_slices_to_3d_slices Undocumented
Function _pcd_to_3d Undocumented
Constant _EDGES Undocumented
Constant _FACES Undocumented
Constant _FRONT_FACE_ID Undocumented
Constant _NUM_KEYPOINTS Undocumented
Constant _PLANE_THICKNESS_EPSILON Undocumented
Constant _POINT_BEHIND_PLANE Undocumented
Constant _POINT_IN_FRONT_OF_PLANE Undocumented
Constant _POINT_ON_PLANE Undocumented
Constant _TOP_FACE_ID Undocumented
Constant _UNIT_BOX Undocumented
def compute_cuboid_iou(gt, pred, gt_crowd=False): (source)

Computes the IoU between the given ground truth and predicted cuboids.

Parameters
gta fiftyone.core.labels.Detection
preda fiftyone.core.labels.Detection
gt_crowd:Falsewhether the ground truth cuboid is a crowd
Returns
the IoU, in [0, 1]
def compute_orthographic_projection_image(filepath, size, shading_mode=None, colormap=None, subsampling_rate=None, projection_normal=None, bounds=None, padding=None): (source)

Generates an orthographic projection image for the given PCD file onto the specified plane (default xy plane).

The returned image is a three-channel array encoding the intensity, height, and density of the point cloud.

Parameters
filepaththe path to the .pcd file
sizethe desired (width, height) for the generated maps. Either dimension can be None or negative, in which case the appropriate aspect-preserving value is used
shading_mode:Nonean optional shading algorithm for the points. Supported values are ("intensity", "rgb", or "height"). The "intensity" and "rgb" options are only valid if the PCD's header contains the "rgb" flag. By default, all points are shaded white
colormap:None

an optional colormap to use when shading gradients, formatted as either:

  • a dict mapping values in [0, 1] to (R, G, B) tuples in [0, 255]
  • a list of of (R, G, B) tuples in [0, 255] that cover [0, 1] linearly spaced
subsampling_rate:Nonean unsigned int that, if defined, defines a uniform subsampling rate. The selected point indices are [0, k, 2k, ...], where k = subsampling_rate
projection_normal:Nonethe normal vector of the plane onto which to perform the projection. By default, (0, 0, 1) is used
bounds:Nonean optional ((xmin, ymin, zmin), (xmax, ymax, zmax)) tuple defining the field of view for which to generate each map in the projected plane. Either element of the tuple or any/all of its values can be None, in which case a tight crop of the point cloud along the missing dimension(s) are used
padding:Nonea relative padding(s) in [0, 1]] to apply to the field of view bounds prior to projection. Can either be a single value to apply in all directions or a [padx, pady, padz]. For example, pass padding=0.25 with no bounds to project onto a tight crop of the point cloud with 25% padding around it
Returns

a tuple of

def compute_orthographic_projection_images(samples, size, output_dir, rel_dir=None, in_group_slice=None, out_group_slice=None, metadata_field='orthographic_projection_metadata', shading_mode=None, colormap=None, subsampling_rate=None, projection_normal=None, bounds=None, padding=None, overwrite=False, skip_failures=False, progress=None): (source)

Computes orthographic projection images for the point clouds in the given collection.

This operation will populate OrthographicProjectionMetadata instances for each projection in the metadata_field of each sample.

Examples:

import fiftyone as fo
import fiftyone.utils.utils3d as fou3d
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset("quickstart-groups")
view = dataset.select_group_slices("pcd")

fou3d.compute_orthographic_projection_images(view, (-1, 512), "/tmp/proj")

session = fo.launch_app(view)
Parameters
samplesa fiftyone.core.collections.SampleCollection
sizethe desired (width, height) for the generated maps. Either dimension can be None or negative, in which case the appropriate aspect-preserving value is used
output_diran output directory in which to store the images/maps
rel_dir:Nonean optional relative directory to strip from each input filepath to generate a unique identifier that is joined with output_dir to generate an output path for each image. This argument allows for populating nested subdirectories in output_dir that match the shape of the input paths
in_group_slice:Nonethe name of the group slice containing the point cloud data. Only applicable if samples is a grouped collection. If samples is a grouped collection and this parameter is not provided, the first point cloud slice will be used
out_group_slice:Nonethe name of a group slice to which to add new samples containing the feature images/maps. Only applicable if samples is a grouped collection
metadata_field:"orthographic_projection_metadata"the name of the field in which to store OrthographicProjectionMetadata instances for each projection
shading_mode:Nonean optional shading algorithm for the points. Supported values are ("intensity", "rgb", or "height"). The "intensity" and "rgb" options are only valid if the PCD's header contains the "rgb" flag. By default, all points are shaded white
colormap:None

an optional colormap to use when shading gradients, formatted as either:

  • a dict mapping values in [0, 1] to (R, G, B) tuples in [0, 255]
  • a list of of (R, G, B) tuples in [0, 255] that cover [0, 1] linearly spaced
subsampling_rate:Nonean optional unsigned int that, if provided, defines a uniform subsampling rate. The selected point indices are [0, k, 2k, ...], where k = subsampling_rate
projection_normal:Nonethe normal vector of the plane onto which to perform the projection. By default, (0, 0, 1) is used
bounds:Nonean optional ((xmin, ymin, zmin), (xmax, ymax, zmax)) tuple defining the field of view in the projected plane for which to generate each map. Either element of the tuple or any/all of its values can be None, in which case a tight crop of the point cloud along the missing dimension(s) are used
padding:Nonea relative padding(s) in [0, 1]] to apply to the field of view bounds prior to projection. Can either be a single value to apply in all directions or a [padx, pady, padz]. For example, pass padding=0.25 with no bounds to project onto a tight crop of each point cloud with 25% padding around it
overwrite:Falsewhether to overwrite existing images
skip_failures:Falsewhether to gracefully continue without raising an error if a projection fails
progress:Nonewhether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead
def get_scene_asset_paths(scene_paths, abs_paths=False, skip_failures=True, progress=None): (source)

Extracts all asset paths for the specified 3D scenes.

Parameters
scene_pathsan iterable of .fo3d paths
abs_paths:Falsewhether to return absolute paths
skip_failures:Truewhether to gracefully continue without raising an error if metadata cannot be computed for a file
progress:Nonewhether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead
Returns
a dict mapping scene paths to lists of asset paths
def pcd_to_3d(dataset, slices=None, output_dir=None, assets_dir=None, rel_dir=None, abs_paths=False, progress=None): (source)

Converts the point cloud samples in the given dataset to 3D samples.

Parameters
dataseta fiftyone.core.dataset.Dataset containing point clouds
slices:None

point cloud slice(s) to convert. Only applicable when the dataset is grouped, in which case you can provide:

  • a slice or iterable of point cloud slices to convert in-place
  • a dict mapping point cloud slices to desired 3D slice names
  • None (default): all point cloud slices are converted in-place
output_dir:Nonean optional output directory for the .fo3d files
assets_dir:Nonean optional directory to copy the .pcd files into. Can be either an absolute directory, a subdirectory of output_dir, or None if you do not wish to copy point clouds
rel_dir:Nonean optional relative directory to strip from each point cloud path to generate a unique identifier for each scene, which is joined with output_dir to generate an output path for each .fo3d file. This argument allows for populating nested subdirectories that match the shape of the input paths. The path is converted to an absolute path (if necessary) via fiftyone.core.storage.normalize_path
abs_paths:Falsewhether to store absolute paths to the point cloud files in the exported .fo3d files
progress:Nonewhether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead
DEFAULT_SHADING_GRADIENT_MAP: dict = (source)

Undocumented

Value
{0.0: (165, 0, 38),
 0.111: (215, 48, 39),
 0.222: (244, 109, 67),
 0.333: (253, 174, 97),
 0.444: (254, 224, 144),
 0.555: (224, 243, 248),
 0.666: (171, 217, 233),
...

Undocumented

Undocumented

def _clamp_to_discrete(arr, discrete): (source)

Discretize by mapping each continuous value in arr to the closest value in discrete.

def _classify_point_to_plane(point, plane, normal, axis): (source)

Classify position of a point w.r.t the given plane.

See Real-Time Collision Detection, by Christer Ericson, page 364.

Parameters
point3x1 vector indicating the point
plane3x1 vector indicating a point on the plane
normalscalar (+1, or -1) indicating the normal to the vector
axisscalar (0, 1, or 2) indicating the xyz axis
Returns
which side of the plane the point is located
def _clip_poly(poly, plane, normal, axis): (source)

Clips the polygon with the plane using the Sutherland-Hodgman algorithm.

See https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm for an overview of the Sutherland-Hodgman algorithm. Here we adopted a robust implementation from "Real-Time Collision Detection", by Christer Ericson, page 370.

Parameters
polylist of 3D vertices defining the polygon
planethe 3D vertices of the (2D) axis-aligned plane
normalnormal
axisa tuple defining a 2D axis
Returns
the list of 3D vertices of the clipped polygon
def _compute_intersection_points(box1, box2): (source)

Computes the intersection of two boxes.

def _contains_none(values): (source)

Undocumented

def _fill_none(values, ref_values): (source)

Undocumented

def _get_3d_slice(samples): (source)

Undocumented

def _get_pcd_filepath_from_scene(scene_path: str): (source)

Undocumented

def _get_scene_asset_paths_single(task, abs_paths=False, skip_failures=True): (source)

Undocumented

def _get_scene_paths(scene_paths): (source)

Return Tuple of scene paths to use and whether all are local This function is a no-op here but could be different in a repo fork.

def _inside(plane, point, axis): (source)

Checks whether a given point is on a 2D plane.

def _intersect(plane, prev_point, current_point, axis): (source)

Computes the intersection of a line with an axis-aligned plane.

Parameters
planeformulated as two 3D points on the plane
prev_pointthe point on the edge of the line
current_pointthe other end of the line
axisa tuple defining a 2D axis
Returns
A 3D point intersection of the poly edge with the plane
def _intersect_box_poly(box, poly): (source)

Clips the polygon against the faces of the axis-aligned box.

def _make_scene(pcd_path, filename_maker=None, media_exporter=None, abs_paths=False): (source)

Undocumented

def _parse_point_cloud(filepath, size=None, bounds=None, padding=None, projection_normal=None, subsampling_rate=None): (source)

Undocumented

def _parse_size(size, bounds): (source)

Undocumented

def _pcd_slices_to_3d_slices(dataset, slices=None, output_dir=None, assets_dir=None, rel_dir=None, abs_paths=False, progress=None): (source)

Undocumented

def _pcd_to_3d(dataset, output_dir=None, assets_dir=None, rel_dir=None, abs_paths=False, progress=None): (source)

Undocumented

Undocumented

Value
([1, 5],
 [2, 6],
 [3, 7],
 [4, 8],
 [1, 3],
 [5, 7],
 [2, 4],
...

Undocumented

Value
np.array([[5, 6, 8, 7],
          [1, 3, 4, 2],
          [3, 7, 8, 4],
          [1, 2, 6, 5],
          [2, 4, 8, 6],
          [1, 5, 7, 3]])
_FRONT_FACE_ID: int = (source)

Undocumented

Value
4
_NUM_KEYPOINTS: int = (source)

Undocumented

Value
9
_PLANE_THICKNESS_EPSILON: float = (source)

Undocumented

Value
1e-06
_POINT_BEHIND_PLANE: int = (source)

Undocumented

Value
-1
_POINT_IN_FRONT_OF_PLANE: int = (source)

Undocumented

Value
1
_POINT_ON_PLANE: int = (source)

Undocumented

Value
0
_TOP_FACE_ID: int = (source)

Undocumented

Value
2
_UNIT_BOX = (source)

Undocumented

Value
np.asarray([[0.0, 0.0, 0.0],
            [(-0.5), (-0.5), (-0.5)],
            [(-0.5), (-0.5), 0.5],
            [(-0.5), 0.5, (-0.5)],
            [(-0.5), 0.5, 0.5],
            [0.5, (-0.5), (-0.5)],
            [0.5, (-0.5), 0.5],
...