COGS
Computer Graphics Structures library
cogs::Scan Class Reference

Set of 3D data points which are additionally organized over 2D grid. More...

Inheritance diagram for cogs::Scan:
[legend]

Public Types

using Coords = glm::uvec2
 Type of point Coordinates.
 
- Public Types inherited from cogs::PointCloud
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

 Scan ()
 Creates a new scan with zero resolution and no points.
 
 ~Scan () override=default
 Destroys cloud, frees all property data and destroys grid.
 
 Scan (const Scan &source)
 Make a deep copy of the source Scan.
 
Scan & operator= (const Scan &source)
 Make a deep copy of the source Scan.
 
 Scan (Scan &&)=default
 Move-construct Scan.
 
Scan & operator= (Scan &&)=default
 Move-construct Scan.
 
virtual bool Import (const std::string &filename) override
 Imports scan from a file.
 
virtual bool Export (const std::string &filename) const override
 Exports scan to a file.
 
virtual void Reserve (uint32_t new_capacity) override
 Changes capacity of cloud. This method is not adding any points.
 
virtual void ShrinkToFit () override
 Frees spare memory so that new capacity exactly matches size.
 
virtual void Clear () override
 Removes all points from cloud.
 
virtual void ClonePropertiesOf (const cogs::Scan &scan)
 Calls PointCloud::ClonePropertiesOf and additionally copies resolution and camera parameters.
 
void SetResolution (const glm::uvec2 &new_resolution)
 Changes grid resolution new grid points are empty and old points may be erased. More...
 
glm::uvec2 GetResolution () const
 Returns current grid resolution.
 
uint32_t GetWidth () const
 Returns current grid width.
 
uint32_t GetHeight () const
 Returns current grid height.
 
void SetCameraParams (const ScanCameraParams &new_params)
 Sets camera parameters to the new value.
 
const ScanCameraParams & GetCameraParams () const
 Returns currently set camera parameters.
 
void SetCameraPosition (const glm::vec3 &new_position)
 Sets camera position to the new value.
 
const glm::vec3 & GetCameraPosition () const
 Returns currently set camera position.
 
void SetCameraBasis (const glm::mat3 &new_basis, const utils::BasisDefinition &basis_def)
 Sets camera basis to the new value.
 
glm::mat3 GetCameraBasis (const utils::BasisDefinition &basis_def) const
 Returns currently set camera basis in the specified basis definition.
 
glm::vec3 GetCameraForward () const
 Returns camera forward direction.
 
glm::vec3 GetCameraUp () const
 Returns camera up direction.
 
utils::BasisDefinition GetCameraBasisDefinition () const
 Returns current camera basis definition.
 
void ChangeCameraBasisDefinition (const utils::BasisDefinition &new_def)
 Changes camera basis definition and transforms internal camera basis to the new one.
 
std::string GetCameraBasisDefinitionId () const
 Returns string representation of current camera basis definition.
 
const std::vector< Coords > & GetCoords () const
 Returns points coordinates.
 
bool IsPointAt (const glm::uvec2 &coord) const
 Checks whether the coordinates are valid and occupied by a point.
 
bool IsPointAt (const uint32_t x_coord, const uint32_t y_coord) const
 Checks whether the coordinates are valid and occupied by a point.
 
uint32_t AddPointAt (const glm::uvec2 &coord)
 Adds new point at grid coordinate. Returns point index.
 
uint32_t AddPointAt (const uint32_t x_coord, const uint32_t y_coord)
 Adds new point at grid coordinate. Returns point index.
 
uint32_t AddPointsAt (const std::vector< glm::uvec2 > &new_coords)
 Adds a vector of new points at grid coordinates. Returns starting point index.
 
uint32_t GetPointAt (const glm::uvec2 &coord) const
 Returns point index at grid coordinate. May return Scan::INVALID_INDEX if there is no point.
 
uint32_t GetPointAt (const uint32_t x_coord, const uint32_t y_coord) const
 Returns point index at grid coordinate. May return Scan::INVALID_INDEX if there is no point.
 
virtual void Transform (const glm::mat4 &transformation, const std::optional< utils::SpaceDefinition > &resulting_space=std::nullopt) override
 Transforms point positions and normals and camera parameters. More...
 
std::optional< double > GetTimestamp () const
 Returns optional timestamp (milliseconds between device connection and scan capture).
 
void SetTimestamp (std::optional< double > timestamp)
 Set custom synthetic timestamp in milliseconds.
 
- Public Member Functions inherited from cogs::PointCloud
 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 uint32_t GetSize () const
 Returns number of points currently stored in the cloud.
 
uint32_t GetCapacity () const
 Returns how much points can be added with currently reserved memory.
 
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...
 
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.
 
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 Member Functions

static bool GetCameraUV (const glm::vec3 &point, const ScanCameraParams &cam_params, glm::vec2 &result)
 Returns coordinate for given point.
 
static std::vector< std::vector< float > > ComputeDepthMap (const cogs::Scan &scan)
 Computes depth map from scan.
 
static std::vector< std::vector< float > > ComputeDepthMap (const cogs::Scan &scan, const glm::vec3 &camera_position)
 Computes depth map from scan and custom camera position.
 
static std::vector< std::vector< uint32_t > > ComputeIndexMap (const cogs::Scan &scan)
 Computes map of point indices from scan.
 

Static Public Attributes

static const glm::vec3 CAMERA_SPACE_FORWARD
 
static const glm::vec3 CAMERA_SPACE_UP
 
static const glm::vec3 CAMERA_SPACE_RIGHT
 
static const uint32_t INVALID_INDEX
 Index which is never assigned to any point. Indicates invalid points.
 
- Static Public Attributes inherited from cogs::PointCloud
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 Scan &source)
 Deep-clone source Scan.
 
virtual void TruncateSize (size_t delta_size) override
 Decreases cloud size by the specified number of points.
 
- Protected Member Functions inherited from cogs::PointCloud
void MakeCloneOf (const PointCloud &source)
 Make a deep copy of the source PointCloud.
 

Detailed Description

Set of 3D data points which are additionally organized over 2D grid.

Class extends PointCloud by holding point indices in 2D grid. Adding of new points must be done strictly through grid so that each point has a valid grid coordinate.

Member Function Documentation

◆ SetResolution()

void cogs::Scan::SetResolution ( const glm::uvec2 &  new_resolution)

Changes grid resolution new grid points are empty and old points may be erased.

Warning
Camera parameters remain unchanged.

◆ Transform()

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

Transforms point positions and normals and camera parameters.

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

Reimplemented from cogs::PointCloud.

Reimplemented in cogs::DynamicScan.