ImFusion SDK 4.3
PointCloud Class Reference

#include <ImFusion/Base/PointCloud.h>

Data structure for point clouds. More...

+ Inheritance diagram for PointCloud:

Detailed Description

Data structure for point clouds.

Examples
ExamplePointCloudAlgorithm.cpp, and ExamplePointCloudAlgorithm.h.

Classes

struct  PointCloudData
 Struct holding the underlying "heavy" data of a PointCloud object. More...
 

Public Member Functions

 PointCloud (int width=0, int height=0, const std::string &name="")
 Constructs an empty point cloud.
 
 PointCloud (std::vector< vec3 > points, int width=0, int height=0, const std::string &name="")
 Constructs a point cloud with the specified vertices.
 
 PointCloud (std::vector< vec3 > points, std::vector< vec3 > normals, int width=0, int height=0, const std::string &name="")
 Constructs a point cloud with the specified vertices and normals.
 
 PointCloud (std::vector< vec3 > points, std::vector< vec3 > normals, std::vector< vec3 > colors, int width=0, int height=0, const std::string &name="")
 Constructs a point cloud with the specified vertices, normals and colors.
 
 PointCloud (std::vector< vec3 > points, std::vector< vec3 > normals, std::vector< vec3 > colors, const TypedImage< int > *pixelToIndexMap, int width=0, int height=0, const std::string &name="")
 Constructs a point cloud with the specified vertices, normals, colors and mapping from pixel (x, y) to a vertex index.
 
 PointCloud (const PointCloud &other)
 Copy constructor with another point cloud instance.
 
 PointCloud (PointCloud &&other) noexcept
 Move constructor with another point cloud instance.
 
 ~PointCloud () override
 Destructor.
 
PointCloudoperator= (PointCloud) noexcept
 Copy/Move assignment operator.
 
void setMatrix (const mat4 &m) override
 Set the transformation matrix.
 
bool isAnnotationType () const override
 Return whether this data type is visualized through an annotation (e.g. mesh)
 
int size () const
 
void clear ()
 
bool isValid (bool runExtendedCheck=false) const
 Check consistency of point cloud data structure. Set runExtendedCheck to true to also check pixelToIndexMap contents (slow).
 
int width () const
 Return width.
 
void setWidth (int w)
 Set width.
 
int height () const
 Return height.
 
void setHeight (int h)
 Set height.
 
void setCameraIntrinsics (const mat3 &K)
 
mat3 cameraIntrinsics () const
 
bool isDense () const
 Return true when the point cloud is organized as an image.
 
bool isDenseCalibrated (bool reproject=false, unsigned int pixelTol=5) const
 Return true when the point cloud is organized, the intrinsics are set When 'reproject' flag is set to true, we also check that points are given in the camera coordinate system.
 
const std::vector< vec3 > & points () const
 Const access to point coordinates.
 
void setPoints (std::vector< vec3 > &&points)
 Set the points.
 
void setPoints (const std::vector< vec3 > &points)
 
bool setPoint (int idx, const vec3 &point)
 
const std::vector< vec3 > & normals () const
 Const access to normal coordinates.
 
bool setNormals (std::vector< vec3 > &&normals)
 Set the normals.
 
bool setNormals (const std::vector< vec3 > &normals)
 
bool setNormal (int idx, const vec3 &normal)
 
bool hasNormals () const
 Return true if point cloud has normals.
 
const std::vector< vec3 > & colors () const
 Const access to color coordinates.
 
bool setColors (std::vector< vec3 > &&colors)
 Set the colors.
 
bool setColors (const std::vector< vec3 > &colors)
 
bool setColor (int idx, const vec3 &color)
 
bool hasColors () const
 Return true if point cloud has colors.
 
const std::vector< double > & weights () const
 Const access to weights.
 
bool setWeights (std::vector< double > &&colors)
 Set the weights. If the size of the weight vector is not equal to the point cloud size the method does nothing and returns false. Passing in an empty vector clears the weight information.
 
bool setWeights (const std::vector< double > &colors)
 
bool setWeight (int idx, double color)
 
bool hasWeights () const
 Return true if point cloud has weights.
 
const std::vector< int > & labels () const
 Const access to labels.
 
int label (int idx) const
 Get label of the point.
 
bool setLabels (std::vector< int > &&labels)
 Set the labels.
 
bool setLabels (const std::vector< int > &labels)
 
bool setLabel (int idx, int label)
 
void requestLabels ()
 If point cloud doesn't have labels, assign zero labels to all points;.
 
void resetLabels ()
 Rest labels of all points to zero, if label information is present.
 
bool hasLabels () const
 Returns true if point cloud contains point labels.
 
PointCloudData takeData ()
 Takes all the underlying data and clears the PointCloud object.
 
MemImagelabelTexture () const
 Returns the texture image used for colors of point labels.
 
const TypedImage< int > * pixelToIndexMap () const
 Access to pixel to index map.
 
void setPixelToIndexMap (const TypedImage< int > *pixelToIndexMap)
 Set pixel to index map. Internally a copy is made.
 
void setLabelTexture (std::unique_ptr< MemImage > tex)
 Set texture for point labels. The image ownership is transferred to the point cloud class.
 
bool densePointCloudIndex (int x, int y, int &indexOut) const
 Retrieves point cloud data associated with a given pixel for dense point clouds.
 
const mat4 & matrixRef () const
 
void setFilename (const std::string &name)
 Sets a filename from where this point cloud can be loaded.
 
const std::stringfilename () const
 Returns the filename from where this point cloud can be loaded or an empty string if it's not on disk.
 
void computeBoundingBox (vec3 &origin, vec3 &extent, bool useMatrix) const
 Computes the bounding box.
 
void computeBoundingBox ()
 Compute bounding box without matrices and store results in object.
 
vec3 center ()
 Return bounding box center computed by a previous call to computeBoundingBox.
 
vec3 origin ()
 Return bounding box origin computed by a previous call to computeBoundingBox.
 
vec3 extent ()
 Return bounding box extent computed by a previous call to computeBoundingBox.
 
virtual int removePoints (const std::vector< int > &indices)
 Remove the points with the specified indices while keeping the point cloud consistent.
 
int duplicatePoints (const std::vector< int > &indices)
 Duplicate the point with the specified indices while keeping the point cloud consistent. Invalidates m_pixelToIndexMap.
 
void beginUpdate ()
 After this call no signals will be emitted if the point cloud data is changed.
 
void endUpdate ()
 End update and send point cloud changed signal.
 
bool signalsBlocked () const
 Returns true if the signals are blocked.
 
void transformPointCloud (const mat4 &transformation)
 Apply given matrix to point cloud.
 
void convertColorsToLabels (const std::vector< std::pair< vec3, int > > *colorToLabelMap=nullptr, double channelTol=0.1)
 Resets point cloud labels.
 
void swapWith (PointCloud &other)
 Swaps the data of with other point cloud and emits a changed signal for both.
 
- Public Member Functions inherited from Data
 Data (const std::string &name="")
 
 Data (const Data &other)
 
Dataoperator= (const Data &other)
 
virtual ~Data ()
 Mandatory virtual destructor.
 
virtual Modality modality () const
 Return the modality of this data.
 
const std::stringname () const
 Return the name of this data.
 
void setName (const std::string &name)
 Sets the name of this data.
 
const DataComponentListcomponents () const
 Returns the list of DataComponents for this data.
 
DataComponentListcomponents ()
 
virtual std::string describe () const
 Human readable description of the data for showing in the info bar.
 
virtual void setMatrixFromWorld (const mat4 &m)
 Set matrix mapping from the world coordinate system to the data coordinate system.
 
virtual void setMatrixToWorld (const mat4 &m)
 Set matrix mapping from the data coordinate system to the world coordinate system.
 
virtual mat4 matrixFromWorld () const
 Get matrix mapping from the world coordinate system to the data coordinate system.
 
virtual mat4 matrixToWorld () const
 Get matrix mapping from the data coordinate system to the world coordinate system.
 
virtual mat4 matrix () const
 Return the transformation matrix.
 

Static Public Member Functions

static bool convertFromPCL (PointCloud *&pcOut, const pcl::PCLPointCloud2 &headerIn, const std::string &nameIn="", bool ignoreNanPoints=true, int versionImFusion=-1)
 Convert PClPointCloud2 to PointCloud.
 
static bool convertToPCL (pcl::PCLPointCloud2 &headerOut, std::string &nameOut, const PointCloud *pcIn, bool applyMatrix)
 Convert PointCloud to PClPointCloud2.
 
- Static Public Member Functions inherited from Data
static std::string modalityString (Data::Modality m)
 Return the name of an image modality.
 
static Data::Modality stringToModality (const std::string &s)
 Returns the modality corresponding to a modality string or NA if nothing matches.
 

Public Attributes

Signal signalPointCloudChanged
 Signal emitted when the point cloud data has changed.
 
- Public Attributes inherited from Data
Signal< const Data * > signalDeleted
 Signal emitted when this instance is deleted.
 
Signal< const Data * > signalMatrixChanged
 Signal emitted when the transformation of this Data has changed.
 
Signal< std::stringsignalNameChanged
 Signal emitted when the name changed.
 

Protected Member Functions

void emitPointCloudChangedSignal ()
 
void createDefaultLabelTexture (int numLabels)
 Create a default texture for point labels. Size of the texture is defined by input parameter 'numLabels'.
 
- Protected Member Functions inherited from Data
void swapWith (Data &other)
 Swaps the data and emits a matrix and name changed signal for both.
 

Protected Attributes

std::vector< vec3 > m_points
 point cloud vertices
 
std::vector< vec3 > m_normals
 point cloud vertex normals
 
std::vector< vec3 > m_colors
 point cloud vertex colors
 
std::vector< int > m_labels
 point cloud vertex labels
 
std::vector< double > m_weights
 
std::unique_ptr< TypedImage< int > > m_pixelToIndexMap
 
int m_width
 width of the point cloud. In case of non-dense point clouds it should be equal to the number of vertices
 
int m_height
 height of the point cloud. In case of non-dense point clouds it should be equal to 1
 
mat3 m_K
 
std::string m_filename
 the path from where the point cloud was loaded or empty if not loaded from file
 
bool m_updateBoundingBox
 
vec3 m_origin
 
vec3 m_extent
 
bool m_updateBoundingBoxWithMatrix
 axis-aligned bounding box of this data in world space
 
Geometry::AlignedBox m_boundingBoxWithMatrix
 flag which indicates whether the bounds of this data should be re-computed
 
std::unique_ptr< MemImagem_labelTexture
 
- Protected Attributes inherited from Data
mat4 m_matrix
 Transformation matrix.
 
std::recursive_mutexm_matrixMutex
 Used to internally synchronize access to the matrix of data.
 
DataComponentList m_dataComponentList
 The list of DataComponents for this data.
 

Methods implementing the Data interface

Kind kind () const override
 Return the kind of this data.
 
Geometry::AlignedBox bounds () const override
 Returns the axis-aligned bounding box of this data in world space.
 
Geometry::AlignedBox boundsLocal ()
 Returns the axis-aligned bounding box of this data in local space.
 
Pose::TransformationConvention matrixConvention () const override
 Matrices of point clouds map to world coordinate system.
 

Additional Inherited Members

- Public Types inherited from Data
enum  Kind {
  UNKNOWN = 0 , IMAGE = 1 , VOLUME = 2 , IMAGESET = 3 ,
  VOLUMESET = 4 , IMAGESTREAM = 5 , VOLUMESTREAM = 6 , POINTSET = 7 ,
  SURFACE = 8 , TRACKINGSTREAM = 9 , LIVETRACKINGSTREAM = TRACKINGSTREAM , TRACKINGDATA = 10 ,
  TREE = 11 , TENSOR = 12 , POLYDATASTREAM = 13 , STEREOIMAGESET = 14 ,
  STEREOIMAGESTREAM = 15 , VOLUMETRICMESH = 16
}
 Kind of data. More...
 
enum  Modality {
  NA = 0 , XRAY = 1 , CT = 2 , MRI = 3 ,
  ULTRASOUND = 4 , VIDEO = 5 , NM = 6 , OCT = 7 ,
  LABEL = 8 , DISTANCE = 9
}
 Image modality of the data. More...
 

Constructor & Destructor Documentation

◆ PointCloud()

PointCloud ( std::vector< vec3 > points,
std::vector< vec3 > normals,
std::vector< vec3 > colors,
const TypedImage< int > * pixelToIndexMap,
int width = 0,
int height = 0,
const std::string & name = "" )

Constructs a point cloud with the specified vertices, normals, colors and mapping from pixel (x, y) to a vertex index.

Parameters
[in]pointsVertices of the point cloud
[in]normalsNormals of the point cloud
[in]colorsVertex colors of the point cloud
[in]pixelToIndexMapFor dense point clouds (point clouds which are organized as an image) gives the index of the point for each pixel position. If no point is associated with a pixel the entry must be -1. An internal copy of the map is made.
Returns
PointCloud object

Member Function Documentation

◆ setMatrix()

void setMatrix ( const mat4 & m)
overridevirtual

Set the transformation matrix.

Note
The matrix convention expected for m depends on the concrete derived class implementation, with either a matrix mapping to or from the world coordinate system being expected. Only use if convention is explicitly known. Use methods setMatrixFromWorld or setMatrixToWorld to avoid inconsistencies. The default implementation sets m_matrix.

Reimplemented from Data.

◆ isAnnotationType()

bool isAnnotationType ( ) const
inlineoverridevirtual

Return whether this data type is visualized through an annotation (e.g. mesh)

Reimplemented from Data.

◆ isDenseCalibrated()

bool isDenseCalibrated ( bool reproject = false,
unsigned int pixelTol = 5 ) const

Return true when the point cloud is organized, the intrinsics are set When 'reproject' flag is set to true, we also check that points are given in the camera coordinate system.

The points are reprojected to the image and the error is checked with respect to the given pixel tolerance 'pixelTol'

◆ kind()

Kind kind ( ) const
overridevirtual

Return the kind of this data.

Implements Data.

◆ bounds()

Geometry::AlignedBox bounds ( ) const
overridevirtual

Returns the axis-aligned bounding box of this data in world space.

Implements Data.

◆ matrixConvention()

Pose::TransformationConvention matrixConvention ( ) const
overridevirtual

Matrices of point clouds map to world coordinate system.

Implements Data.

◆ setPoints()

void setPoints ( std::vector< vec3 > && points)

Set the points.

If normals and/or colors are available they will be cleared unless the size of the passed in vector is the same as the size of the existing points.

◆ setNormals()

bool setNormals ( std::vector< vec3 > && normals)

Set the normals.

If the size of the normal vector is not equal to the point cloud size the method does nothing and returns false. Passing in an empty vector clears the normal information.

◆ setColors()

bool setColors ( std::vector< vec3 > && colors)

Set the colors.

If the size of the color vector is not equal to the point cloud size the method does nothing and returns false. Passing in an empty vector clears the color information.

◆ label()

int label ( int idx) const

Get label of the point.

Returns 0 if index is invalid or if point cloud does not contain label information. Query presence of labels by using hasLabels() method

◆ setLabels()

bool setLabels ( std::vector< int > && labels)

Set the labels.

If the size of the label vector is not equal to the point cloud size the method does nothing and returns false. Passing in an empty vector clears the label information. If there is no texture for point label colors, a default one will be created. If the existing texture for point label colors does not have an entry for at least one of the new labels, the texture will be reset with a default one of appropriate size

◆ densePointCloudIndex()

bool densePointCloudIndex ( int x,
int y,
int & indexOut ) const

Retrieves point cloud data associated with a given pixel for dense point clouds.

Parameters
[in]pixelInCoordinate (x, y) of the image pixel
[out]indexOutIndex of the vertex associated with the pixelIn
Returns
True when successful, false otherwise (i.e. if the cloud is not dense or if the vertex doesn't exist at pixelIn)

◆ removePoints()

virtual int removePoints ( const std::vector< int > & indices)
virtual

Remove the points with the specified indices while keeping the point cloud consistent.

Reimplemented in FrameBasedPointCloud.

◆ beginUpdate()

void beginUpdate ( )

After this call no signals will be emitted if the point cloud data is changed.

This is useful if many update operations must be performed but it is not desired that the signal is emitted for every update. When done with the update operations call endUpdate to emit a single update signal

◆ signalsBlocked()

bool signalsBlocked ( ) const

Returns true if the signals are blocked.

Useful to know whether the signals were blocked before calling beginUpdate - endUpdate. User might want not to call endUpdate, so that the signals remain blocked

◆ convertColorsToLabels()

void convertColorsToLabels ( const std::vector< std::pair< vec3, int > > * colorToLabelMap = nullptr,
double channelTol = 0.1 )

Resets point cloud labels.

Converts point cloud colors to labels using the predefined colorToLabelMap if provided, otherwise random labels are assigned to colors. In case colorToLabelMap if provided, tolerance of channelTol is applied when comparing each channel of the point cloud colors to the channels in the map. Example: color of 1st point is {0.52, 0.2, 0.7}, one of the map entry contains {0.5, 0.2, 0.7} with corresponding label 2. In case of default channelTol parameter, the label of the 1st point will be assigned to 2. If channelTol was 0.01, the color of the point wouldn't correspond to the entry in the map, and therefore, its label would stay unchanged unless the other fitting map entry could be found


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close