COGS
Computer Graphics Structures library
cogs::PointCloud Class Reference

Management class for a set of data points in a 3D space. More...

Inheritance diagram for cogs::PointCloud:
[legend]

Data Structures

struct  CopyCommand
 A command for copying points. More...
 

Public Types

using PointNormalPredicate = std::function< bool(const glm::vec3 &, const glm::vec3 &)>
 A predicate over points and normals. A function that returns true or false.
 

Public Member Functions

 PointCloud ()
 Creates a cloud with no points.
 
virtual ~PointCloud ()
 Destroys cloud and frees all property data.
 
 PointCloud (const PointCloud &source)
 Make a deep copy of the source PointCloud.
 
PointCloud & operator= (const PointCloud &source)
 Make a deep copy of the source PointCloud.
 
 PointCloud (PointCloud &&) noexcept=default
 Move-construct PointCloud.
 
PointCloud & operator= (PointCloud &&) noexcept=default
 Move-construct PointCloud.
 
virtual bool Import (const std::string &filename)
 Imports point cloud from a file.
 
virtual bool Export (const std::string &filename) const
 Exports point clouds to a file.
 
virtual bool Resize (uint32_t new_size)
 Resizes point count to the new value without initialization of data of newly created points.
 
virtual uint32_t GetSize () const
 Returns number of points currently stored in the cloud.
 
virtual void Reserve (uint32_t new_capacity)
 Changes capacity of cloud. This method is not adding any points.
 
uint32_t GetCapacity () const
 Returns how much points can be added with currently reserved memory.
 
virtual void ShrinkToFit ()
 Frees spare memory so that new capacity exactly matches size.
 
virtual void Clear ()
 Removes all points from cloud.
 
virtual bool Erase (std::vector< uint32_t > indices_to_erase, std::vector< int > *replacement_map=nullptr)
 Removes points with specific indices from cloud. More...
 
virtual bool Erase (const PointNormalPredicate &Predicate, std::vector< int > *replacement_map=nullptr)
 Removes all points from cloud that satisfy a specified condition. More...
 
virtual bool Append (const PointCloud &pc)
 Increments size of this by the size of pc and copies property data available in both. More...
 
glm::vec3 * GetPositions ()
 Returns pointer to position data. More...
 
const glm::vec3 * GetPositions () const
 Returns pointer to position data. More...
 
bool HasNormals () const
 Checks whether normal property exists. More...
 
glm::vec3 * GetNormals ()
 When normal property exists, returns the pointer to data, nullptr otherwise. More...
 
const glm::vec3 * GetNormals () const
 When normal property exists, returns the pointer to data, nullptr otherwise. More...
 
const PointCloudProperty & AddNormals ()
 Creates PointCloud::NORMALS property buffer if it was not added already. More...
 
bool HasColors () const
 Checks whether color property exists. More...
 
struct Color3f * GetColors ()
 When color property exists, returns the pointer to data, nullptr otherwise. More...
 
const struct Color3f * GetColors () const
 When color property exists, returns the pointer to data, nullptr otherwise. More...
 
const PointCloudProperty & AddColors ()
 Creates PointCloud::COLORS property buffer if it was not added already. More...
 
bool HasIntensities () const
 Checks whether intensity property exists. More...
 
float * GetIntensities ()
 When intensity property exists, returns the pointer to data, nullptr otherwise. More...
 
const float * GetIntensities () const
 When intensity property exists, returns the pointer to data, nullptr otherwise. More...
 
const PointCloudProperty & AddIntensities ()
 Creates PointCloud::INTENSITIES property buffer if it was not added already. More...
 
const std::vector< PointCloudProperty > & GetProperties () const
 Returns all available properties.
 
const PointCloudProperty & AddProperty (const PointCloudProperty::Key &key, DataType type)
 Creates new property buffer. More...
 
const PointCloudProperty & AddProperty (const PointCloudProperty::Key &key, size_t bytes_per_point)
 Creates new property buffer. More...
 
void RemoveProperty (const PointCloudProperty::Key &key)
 Remove a single property by key..
 
void ClonePropertiesOf (const PointCloud &pc)
 Adds all properties, which are not already present in this.
 
bool HasProperty (const PointCloudProperty::Key &key) const
 Checks whether a specific property exists.
 
std::optional< PointCloudProperty > GetProperty (const PointCloudProperty::Key &key)
 Returns property with specified key if it exists, std::nullopt otherwise.
 
std::optional< const PointCloudProperty > GetProperty (const PointCloudProperty::Key &key) const
 Returns property with specified key if it exists, std::nullopt otherwise.
 
virtual void * GetVoidData (const PointCloudProperty::Key &key)
 When property exists, returns the pointer to data, nullptr otherwise.
 
const void * GetVoidData (const PointCloudProperty::Key &key) const
 When property exists, returns the pointer to data, nullptr otherwise.
 
template<typename T >
T * GetData (const PointCloudProperty::Key &key)
 When property exists, returns the pointer to data of a template type, nullptr otherwise.
 
template<typename T >
const T * GetData (const PointCloudProperty::Key &key) const
 When property exists, returns the pointer to data of a template type, nullptr otherwise.
 
virtual void Transform (const glm::mat4 &transformation, const std::optional< utils::SpaceDefinition > &resulting_space=std::nullopt)
 Transforms point positions and normals. More...
 
bool HasSpace () const
 Returns true, if there is a space defined for this structure.
 
const std::optional< utils::SpaceDefinition > & GetSpace () const
 Returns current space definition, if there is one.
 
std::string GetSpaceId () const
 Returns string representation of current space definition. Returns "N/A" otherwise.
 
void SetSpace (const std::optional< utils::SpaceDefinition > &new_space)
 Assigns a new space definition to the structure, overwriting the previous one.
 
bool TransformToSpace (const utils::SpaceDefinition &new_space)
 Transforms the structure to the new space. Fails, if the current space is not defined.
 

Static Public Attributes

static const cogs::PointCloudProperty::Key POSITIONS
 Common identifier for point positions.
 
static const cogs::PointCloudProperty::Key NORMALS
 Common identifier for point normals.
 
static const cogs::PointCloudProperty::Key COLORS
 Common identifier for point colors.
 
static const cogs::PointCloudProperty::Key UVS
 Common identifier for point texture coordinates.
 
static const cogs::PointCloudProperty::Key INTENSITIES
 Common identifier for point intensities.
 

Protected Member Functions

void MakeCloneOf (const PointCloud &source)
 Make a deep copy of the source PointCloud.
 
virtual void ExecuteCopyCommands (const std::vector< CopyCommand > &copy_info)
 Copies chunks of points according to copy commands.
 
virtual void TruncateSize (size_t delta_size)
 Decreases cloud size by the specified number of points.
 

Detailed Description

Management class for a set of data points in a 3D space.

Class stores point data separated in data buffers. Every data record is called a property, and by default, only a single property exists - PointCloud::POSITIONS. User can specify custom properties which will be assigned to all points in the cloud.

Member Function Documentation

◆ AddColors()

const PointCloudProperty& cogs::PointCloud::AddColors ( )

Creates PointCloud::COLORS property buffer if it was not added already.

Note
Do not add this property using PointCloud:AddProperty method.

◆ AddIntensities()

const PointCloudProperty& cogs::PointCloud::AddIntensities ( )

Creates PointCloud::INTENSITIES property buffer if it was not added already.

Note
Do not add this property using PointCloud:AddProperty method.

◆ AddNormals()

const PointCloudProperty& cogs::PointCloud::AddNormals ( )

Creates PointCloud::NORMALS property buffer if it was not added already.

Note
Do not add this property using PointCloud:AddProperty method.

◆ AddProperty() [1/2]

const PointCloudProperty& cogs::PointCloud::AddProperty ( const PointCloudProperty::Key &  key,
DataType  type 
)

Creates new property buffer.

Parameters
keyProperty identifier. If it already exists, does nothing and returns existing property.
typeSpecific type of data in buffer.
Returns
Newly created property.

◆ AddProperty() [2/2]

const PointCloudProperty& cogs::PointCloud::AddProperty ( const PointCloudProperty::Key &  key,
size_t  bytes_per_point 
)

Creates new property buffer.

Parameters
keyProperty identifier. If it already exists, does nothing and returns existing property.
bytes_per_pointNumber of bytes reserved for each point.
Returns
Newly created property.

◆ Append()

virtual bool cogs::PointCloud::Append ( const PointCloud &  pc)
virtual

Increments size of this by the size of pc and copies property data available in both.

Note
Properties not available in this will not be copied. To add also properties not currently available in this, use PointCloud::ClonePropertiesOf before calling this function.

◆ Erase() [1/2]

virtual bool cogs::PointCloud::Erase ( std::vector< uint32_t >  indices_to_erase,
std::vector< int > *  replacement_map = nullptr 
)
virtual

Removes points with specific indices from cloud.

Every chunk of points that should be erased, is replaced with the points from the back of cloud. This ensures minimal copy operations.

Note
Method changes point ordering. Memory for erased points is not released, you should call ShrinkToFit afterwards, to free excess memory.
Parameters
indices_to_eraseIndices of points to erase.
replacement_mapOptional output parameter - vector representing the mapping old_index->new_index.

◆ Erase() [2/2]

virtual bool cogs::PointCloud::Erase ( const PointNormalPredicate &  Predicate,
std::vector< int > *  replacement_map = nullptr 
)
virtual

Removes all points from cloud that satisfy a specified condition.

Every chunk of points that should be erased, is replaced with the points from the back of cloud. This ensures minimal copy operations.

Note
Method changes point ordering. Memory for erased points is not released, you should call ShrinkToFit afterwards, to free excess memory.
Parameters
PredicateThe erase condition. A point is removed from the point cloud if it returns true.
replacement_mapOptional output parameter - vector representing the mapping old_index->new_index.

◆ GetColors() [1/2]

struct Color3f* cogs::PointCloud::GetColors ( )

When color property exists, returns the pointer to data, nullptr otherwise.

Note
Equivalent to PointCloud::GetData<COGS::Color3f>(PointCloud::COLORS);

◆ GetColors() [2/2]

const struct Color3f* cogs::PointCloud::GetColors ( ) const

When color property exists, returns the pointer to data, nullptr otherwise.

Note
Equivalent to PointCloud::GetData<COGS::Color3f>(PointCloud::COLORS);

◆ GetIntensities() [1/2]

float* cogs::PointCloud::GetIntensities ( )

When intensity property exists, returns the pointer to data, nullptr otherwise.

Note
Equivalent to PointCloud::GetData<float>(PointCloud::INTENSITIES);

◆ GetIntensities() [2/2]

const float* cogs::PointCloud::GetIntensities ( ) const

When intensity property exists, returns the pointer to data, nullptr otherwise.

Note
Equivalent to PointCloud::GetData<float>(PointCloud::INTENSITIES);

◆ GetNormals() [1/2]

glm::vec3* cogs::PointCloud::GetNormals ( )

When normal property exists, returns the pointer to data, nullptr otherwise.

Note
Equivalent to PointCloud::GetData<glm::vec3>(PointCloud::NORMALS);

◆ GetNormals() [2/2]

const glm::vec3* cogs::PointCloud::GetNormals ( ) const

When normal property exists, returns the pointer to data, nullptr otherwise.

Note
Equivalent to PointCloud::GetData<glm::vec3>(PointCloud::NORMALS);

◆ GetPositions() [1/2]

glm::vec3* cogs::PointCloud::GetPositions ( )

Returns pointer to position data.

Note
Equivalent to PointCloud::GetData<glm::vec3>(PointCloud::POSITIONS);

◆ GetPositions() [2/2]

const glm::vec3* cogs::PointCloud::GetPositions ( ) const

Returns pointer to position data.

Note
Equivalent to PointCloud::GetData<glm::vec3>(PointCloud::POSITIONS);

◆ HasColors()

bool cogs::PointCloud::HasColors ( ) const

Checks whether color property exists.

Note
Equivalent to PointCloud::HasProperty(PointCloud::COLORS);

◆ HasIntensities()

bool cogs::PointCloud::HasIntensities ( ) const

Checks whether intensity property exists.

Note
Equivalent to PointCloud::HasProperty(PointCloud::INTENSITIES);

◆ HasNormals()

bool cogs::PointCloud::HasNormals ( ) const

Checks whether normal property exists.

Note
Equivalent to PointCloud::HasProperty(PointCloud::NORMALS);

◆ Transform()

virtual void cogs::PointCloud::Transform ( const glm::mat4 &  transformation,
const std::optional< utils::SpaceDefinition > &  resulting_space = std::nullopt 
)
virtual

Transforms point positions and normals.

Parameters
transformationTransformation matrix applied on every point and camera parameter.
resulting_spaceResulting point cloud space after the transformation is applied.

Reimplemented in cogs::Scan, and cogs::DynamicScan.