Implements a point cloud (with contiguous storage), whose main goal is to offer a convenient, synchronized interface to commonly used fields and data types applicable for basic 3D perception.
This is a mix between the philosophy of PCL (templated interface to provide a compile-time open set, run-time closed set) and VTK (non-templated interface to provide a very free form run-time open set).
Definitions:
This point cloud class provides the following fields:
xyz(i)
, mutable_descriptor(i)
) to avoid overhead when accessing a single element (either copying or creating a reference).#include <drake/perception/point_cloud.h>
Public Types | |
using | T = float |
Geometric scalar type. More... | |
using | C = uint8_t |
Color channel scalar type. More... | |
using | D = T |
Descriptor scalar type. More... | |
Public Member Functions | |
PointCloud (int new_size=0, pc_flags::Fields fields=pc_flags::kXYZs, bool skip_initialize=false) | |
Constructs a point cloud of a given new_size , with the prescribed fields . More... | |
PointCloud (const PointCloud &other) | |
Copies another point cloud's fields and data. More... | |
PointCloud (PointCloud &&other) | |
Takes ownership of another point cloud's data. More... | |
PointCloud (const PointCloud &other, pc_flags::Fields copy_fields) | |
Copies another point cloud's fields and data. More... | |
PointCloud & | operator= (const PointCloud &other) |
PointCloud & | operator= (PointCloud &&other) |
~PointCloud () | |
pc_flags::Fields | fields () const |
Returns the fields provided by this point cloud. More... | |
int | size () const |
Returns the number of points in this point cloud. More... | |
void | resize (int new_size, bool skip_initialize=false) |
Conservative resize; will maintain existing data, and initialize new data to their invalid values. More... | |
PointCloud | VoxelizedDownSample (double voxel_size, Parallelism parallelize=false) const |
Returns a down-sampled point cloud by grouping all xyzs in this cloud into a 3D grid with cells of dimension voxel_size. More... | |
bool | EstimateNormals (double radius, int num_closest, Parallelism parallelize=false) |
Estimates the normal vectors in this by fitting a plane at each point in the cloud using up to num_closest points within Euclidean distance radius from the point. More... | |
Geometric Descriptors - XYZs | |
bool | has_xyzs () const |
Returns if this cloud provides XYZ values. More... | |
Eigen::Ref< const Matrix3X< T > > | xyzs () const |
Returns access to XYZ values. More... | |
Eigen::Ref< Matrix3X< T > > | mutable_xyzs () |
Returns mutable access to XYZ values. More... | |
Vector3< T > | xyz (int i) const |
Returns access to an XYZ value. More... | |
Eigen::Ref< Vector3< T > > | mutable_xyz (int i) |
Returns mutable access to an XYZ value. More... | |
Geometric Descriptors - Normals | |
bool | has_normals () const |
Returns if this cloud provides normals. More... | |
Eigen::Ref< const Matrix3X< T > > | normals () const |
Returns access to normals. More... | |
Eigen::Ref< Matrix3X< T > > | mutable_normals () |
Returns mutable access to normals. More... | |
Vector3< T > | normal (int i) const |
Returns access to a normal. More... | |
Eigen::Ref< Vector3< T > > | mutable_normal (int i) |
Returns mutable access to a normal. More... | |
Geometric Descriptors - RGBs | |
bool | has_rgbs () const |
Returns if this cloud provides RGB colors. More... | |
Eigen::Ref< const Matrix3X< C > > | rgbs () const |
Returns access to RGB colors. More... | |
Eigen::Ref< Matrix3X< C > > | mutable_rgbs () |
Returns mutable access to RGB colors. More... | |
Vector3< C > | rgb (int i) const |
Returns access to an RGB color. More... | |
Eigen::Ref< Vector3< C > > | mutable_rgb (int i) |
Returns mutable access to an RGB color. More... | |
Run-Time Descriptors | |
bool | has_descriptors () const |
Returns if this point cloud provides descriptor values. More... | |
bool | has_descriptors (const pc_flags::DescriptorType &descriptor_type) const |
Returns if the point cloud provides a specific descriptor. More... | |
const pc_flags::DescriptorType & | descriptor_type () const |
Returns the descriptor type. More... | |
Eigen::Ref< const MatrixX< D > > | descriptors () const |
Returns access to descriptor values. More... | |
Eigen::Ref< MatrixX< D > > | mutable_descriptors () |
Returns mutable access to descriptor values. More... | |
VectorX< D > | descriptor (int i) const |
Returns access to a descriptor value. More... | |
Eigen::Ref< VectorX< D > > | mutable_descriptor (int i) |
Returns mutable access to a descriptor value. More... | |
Container Manipulation | |
void | SetFrom (const PointCloud &other, pc_flags::Fields fields_in=pc_flags::kInherit, bool allow_resize=true) |
Copies all points from another point cloud. More... | |
void | Expand (int add_size, bool skip_initialization=false) |
Adds add_size default-initialized points. More... | |
Fields | |
void | SetFields (pc_flags::Fields new_fields, bool skip_initialize=false) |
Updates the point cloud to a given set of fields. More... | |
bool | HasFields (pc_flags::Fields fields_in) const |
Returns if a point cloud has a given set of fields. More... | |
void | RequireFields (pc_flags::Fields fields_in) const |
Requires a given set of fields. More... | |
bool | HasExactFields (pc_flags::Fields fields_in) const |
Returns if a point cloud has exactly a given set of fields. More... | |
void | RequireExactFields (pc_flags::Fields field_set) const |
Requires the exact given set of fields. More... | |
Point Cloud Processing | |
PointCloud | Crop (const Eigen::Ref< const Vector3< T >> &lower_xyz, const Eigen::Ref< const Vector3< T >> &upper_xyz) |
Returns a new point cloud containing only the points in this with xyz values within the axis-aligned bounding box defined by lower_xyz and upper_xyz . More... | |
void | FlipNormalsTowardPoint (const Eigen::Ref< const Vector3< T >> &p_CP) |
Changes the sign of the normals in this , if necessary, so that each normal points toward the point P in the frame C in which the xyzs of this cloud are represented. More... | |
Static Public Member Functions | |
static bool | IsDefaultValue (T value) |
static bool | IsInvalidValue (T value) |
Static Public Attributes | |
static constexpr T | kDefaultValue = std::numeric_limits<T>::quiet_NaN() |
Represents an invalid or uninitialized value. More... | |
static constexpr C | kDefaultColor {} |
using C = uint8_t |
Color channel scalar type.
using T = float |
Geometric scalar type.
|
explicit |
Constructs a point cloud of a given new_size
, with the prescribed fields
.
If kDescriptors
is one of the fields, then descriptor
should be included and should not be kNone
.
new_size | Size of the point cloud after construction. |
fields | Fields that the point cloud contains. |
skip_initialize | Do not default-initialize new values. |
PointCloud | ( | const PointCloud & | other | ) |
Copies another point cloud's fields and data.
PointCloud | ( | PointCloud && | other | ) |
Takes ownership of another point cloud's data.
PointCloud | ( | const PointCloud & | other, |
pc_flags::Fields | copy_fields | ||
) |
Copies another point cloud's fields and data.
copy_fields | Fields to copy. If this is kInherit , then other s fields will be copied. Otherwise, only the specified fields will be copied; the remaining fields in this cloud are left default initialized. |
~PointCloud | ( | ) |
PointCloud Crop | ( | const Eigen::Ref< const Vector3< T >> & | lower_xyz, |
const Eigen::Ref< const Vector3< T >> & | upper_xyz | ||
) |
Returns a new point cloud containing only the points in this
with xyz values within the axis-aligned bounding box defined by lower_xyz
and upper_xyz
.
Requires that xyz values are defined.
std::exception | if has_xyzs() != true. |
Returns access to a descriptor value.
has_descriptors()
must be true. const pc_flags::DescriptorType& descriptor_type | ( | ) | const |
Returns the descriptor type.
Returns access to descriptor values.
has_descriptors()
must be true. bool EstimateNormals | ( | double | radius, |
int | num_closest, | ||
Parallelism | parallelize = false |
||
) |
Estimates the normal vectors in this
by fitting a plane at each point in the cloud using up to num_closest
points within Euclidean distance radius
from the point.
If has_normals() is false, then new normals will be allocated (and has_normals() will become true). Points for which the normals cannot be estimated (because the this
has less than two closest points within the radius
), will receive normal [NaN, NaN, NaN]. Normals estimated from two closest points will be orthogonal to the vector between those points, but can be arbitrary in the last dimension. parallelize
enables OpenMP parallelization.
radius
.radius
> 0 and num_closest
>= 3. std::exception | if has_xyzs() is false. |
void Expand | ( | int | add_size, |
bool | skip_initialization = false |
||
) |
Adds add_size
default-initialized points.
add_size | Number of points to add. |
skip_initialization | Do not require that the new values be initialized. |
pc_flags::Fields fields | ( | ) | const |
Returns the fields provided by this point cloud.
Changes the sign of the normals in this
, if necessary, so that each normal points toward the point P
in the frame C
in which the xyzs of this
cloud are represented.
This can be useful, for instance, when P
is the position of the camera used to generate the cloud.
std::exception | if has_xyzs() != true or has_normals() != true. |
bool has_descriptors | ( | ) | const |
Returns if this point cloud provides descriptor values.
bool has_descriptors | ( | const pc_flags::DescriptorType & | descriptor_type | ) | const |
Returns if the point cloud provides a specific descriptor.
bool has_normals | ( | ) | const |
Returns if this cloud provides normals.
bool has_rgbs | ( | ) | const |
Returns if this cloud provides RGB colors.
bool has_xyzs | ( | ) | const |
Returns if this cloud provides XYZ values.
bool HasExactFields | ( | pc_flags::Fields | fields_in | ) | const |
Returns if a point cloud has exactly a given set of fields.
bool HasFields | ( | pc_flags::Fields | fields_in | ) | const |
Returns if a point cloud has a given set of fields.
|
static |
|
static |
Returns mutable access to a descriptor value.
has_descriptors()
must be true. Returns mutable access to descriptor values.
has_descriptors()
must be true. Returns mutable access to a normal.
has_normals()
must be true. Returns mutable access to normals.
has_normals()
must be true. Returns mutable access to an RGB color.
has_rgbs()
must be true. Returns mutable access to RGB colors.
has_rgbs()
must be true. Returns mutable access to an XYZ value.
has_xyzs()
must be true. Returns mutable access to XYZ values.
has_xyzs()
must be true. Returns access to a normal.
has_normals()
must be true. Returns access to normals.
has_normals()
must be true. PointCloud& operator= | ( | const PointCloud & | other | ) |
PointCloud& operator= | ( | PointCloud && | other | ) |
void RequireExactFields | ( | pc_flags::Fields | field_set | ) | const |
Requires the exact given set of fields.
std::exception | if this point cloud does not have exactly these fields. |
void RequireFields | ( | pc_flags::Fields | fields_in | ) | const |
Requires a given set of fields.
std::exception | if this point cloud does not have these fields. |
void resize | ( | int | new_size, |
bool | skip_initialize = false |
||
) |
Conservative resize; will maintain existing data, and initialize new data to their invalid values.
Returns access to an RGB color.
has_rgbs()
must be true. Returns access to RGB colors.
has_rgbs()
must be true. void SetFields | ( | pc_flags::Fields | new_fields, |
bool | skip_initialize = false |
||
) |
Updates the point cloud to a given set of fields.
In the case of introducing a new field, its container will be allocated with the current size and default initialized. The data for all retained fields will remain unchanged.
new_fields | New fields to set to. |
skip_initialize | Do not default-initialize new values. |
void SetFrom | ( | const PointCloud & | other, |
pc_flags::Fields | fields_in = pc_flags::kInherit , |
||
bool | allow_resize = true |
||
) |
Copies all points from another point cloud.
other | Other point cloud. |
fields_in | Fields to copy. If this is kInherit , then other s fields will be copied. Otherwise, both clouds must support the fields indicated this parameter. |
allow_resize | Permit resizing to the other cloud's size. |
int size | ( | ) | const |
Returns the number of points in this point cloud.
PointCloud VoxelizedDownSample | ( | double | voxel_size, |
Parallelism | parallelize = false |
||
) | const |
Returns a down-sampled point cloud by grouping all xyzs in this cloud into a 3D grid with cells of dimension voxel_size.
Each occupied voxel will result in one point in the downsampled cloud, with a location corresponding to the centroid of the points in that voxel. Points with non-finite xyz values are ignored. All other fields (e.g. rgbs, normals, and descriptors) with finite values will also be averaged across the points in a voxel. parallelize
enables OpenMP parallelization. Equivalent to Open3d's voxel_down_sample or PCL's VoxelGrid filter.
std::exception | if has_xyzs() is false. |
std::exception | if voxel_size <= 0. |
Returns access to an XYZ value.
has_xyzs()
must be true. Returns access to XYZ values.
has_xyzs()
must be true.
|
static |
Represents an invalid or uninitialized value.