Helios++
Helios software for LiDAR simulations
XYZPointCloudFileLoader Class Reference

Import point cloud files abstracting them to a set of voxels. More...

#include <XYZPointCloudFileLoader.h>

Inheritance diagram for XYZPointCloudFileLoader:
Collaboration diagram for XYZPointCloudFileLoader:

Public Member Functions

 XYZPointCloudFileLoader ()
 Constructor for point cloud loader. More...
 
ScenePartrun ()
 
- Public Member Functions inherited from AbstractGeometryFilter
 AbstractGeometryFilter (ScenePart *parts_)
 Base constructor for asset loading filters. More...
 
std::shared_ptr< MaterialgetMaterial (std::string materialName)
 Retrieve requested material by name. More...
 
std::vector< std::shared_ptr< Material > > parseMaterials ()
 Parse materials specified through "matfile", which can be concreted through "matname" parameter. It can also handle random materials when parameter "randomMaterials" is set. More...
 

Static Public Attributes

static int const minPointsForSafeNormalEstimation = 3
 How many points are necessary for the normal estimation to be reliable.
 
static size_t const batchSize = 10000000
 How many points consider per batch when estimating normals.
 
static int const voxelPopulationThreshold = 40000
 How many points can be contained inside a voxel without triggering a warning due to excessive population.
 

Private Member Functions

void parse (std::string const &filePath)
 Parse XYZ file. More...
 
void firstPass (string const &filePathString, ifstream &ifs)
 First pass of input file used to find essential information needed to successfully abstract the point cloud to voxels. More...
 
void secondPass (string const &filePathString, string const &matName, ifstream &ifs)
 Second pass where the input file is read as many times as needed to build necessary voxels. More...
 
void loadMaterial ()
 
void prepareVoxelsGrid (int &estimateNormals, double &halfVoxelSize)
 Prepare voxels grid computation. More...
 
void fillVoxelsGrid (ifstream &ifs, int estimateNormals, double halfVoxelSize, string const &filePathString)
 Fill voxels grid. More...
 
bool correctNormal (double &x, double &y, double &z)
 Correct normal if necessary. Only non valid normals will be corrected. More...
 
void digestVoxel (int estimateNormals, double halfVoxelSize, double x, double y, double z, double r, double g, double b, double xnorm, double ynorm, double znorm)
 Digest a voxel when filling voxels grid. This implies the voxel will be created in the grid if it does not exist. If the voxel already existed, then it will be populated with given new data.
 
void postProcess (string const &matName, int estimateNormals)
 Post process already filled voxels grid. More...
 
void estimateNormals (ifstream &ifs)
 Estimate voxels normal as the orthonormal of best fitting plane for points inside voxel.
 
void estimateNormalsBatch (ifstream &ifs)
 Estimate voxels normals in batch mode, which implies reading input file as many times as specified by numBatches variable. The output generated by this function is the same than the one that should be generated by estimateNormals function. More...
 
void _estimateNormals (size_t start, size_t end)
 Assists estimateNormals function. Normals for filled matrices are computed at this function. More...
 
void voxelsGridToScenePart ()
 Compose the scene part considering voxels at voxels grid.
 
size_t indexFromCoordinates (double x, double y, double z, size_t &I, size_t &J, size_t &K)
 Obtain voxel-grid index for given coordinates. More...
 

Static Private Member Functions

static bool isLineComment (string const &line)
 Check if given line is a comment or not. More...
 
static void restartInputFileStream (ifstream &ifs)
 Reset given input file stream so it points to file start. More...
 

Private Attributes

std::string separator = " "
 Field separator specification used by the point cloud file.
 
double voxelSize = 1
 Size for each voxel.
 
double maxColorValue = 0
 Max value with respect to used color codification.
 
bool snapNeighborNormal = false
 Snap neighbor normal instead of average when enabled (true).
 
bool assignDefaultNormal = false
 Specify whether default normal must be assigned to voxels which normal cannot be safely determined (True) or not (False).
 
glm::dvec3 defaultNormal = glm::dvec3(0,0,0)
 The default normal to be used when needed to fill missing ones.
 
size_t unsafeNormalEstimations = 0
 How many voxels normals could not be safely estimated because there was not enough data inside the voxel.
 
size_t discardedPointsByNormal = 0
 How many points were discarded because they were expected to have a correct normal but they did not. More...
 
size_t n
 The number of points in the point cloud.
 
double minX
 Minimum X coordinate considering all points.
 
double minY
 Minimum Y coordinate considering all points.
 
double minZ
 Minimum Z coordinate considering all points.
 
double maxX
 Maximum X coordinate considering all points.
 
double maxY
 Maximum Y coordinate considering all points.
 
double maxZ
 Maximum Z coordinate considering all points.
 
size_t nx
 Number of partitions along x-axis.
 
size_t ny
 Number of partitions along y-axis.
 
size_t nz
 Number of partitions along z-axis.
 
size_t nynz
 Product \(ny \cdot nz\). Stored in a variable because of its recurrent usage.
 
double xCoeff
 Coefficient ( \(K_{x}\)) to compute \(I\) voxel index for a given \(x\) coordinate. More...
 
double yCoeff
 Coefficient ( \(K_{y}\)) to compute \(J\) voxel index for a given \(y\) coordinate. More...
 
double zCoeff
 Coefficient ( \(K_{z}\)) to compute \(K\) voxel index for a given \(z\) coordinate. More...
 
VoxelGridCellvoxels = nullptr
 Full voxels grid.
 
size_t maxNVoxels
 Total size of full voxels grid. More...
 
size_t numBatches
 How many batches are necessary to estimate normals.
 
size_t lastNumVoxels
 Used to correctly report number of voxels for each part when reading multiple files at once (i.e. efilepath is given)
 

Additional Inherited Members

- Public Attributes inherited from AbstractGeometryFilter
OGRSpatialReference * sourceCRS
 
std::map< std::string, ObjectT > params
 Available parameters.
 
std::map< std::string, Materialmaterials
 Available materials.
 
ScenePartprimsOut = nullptr
 ScenePart used to build the output. Not strictly necessary for any filter.
 

Detailed Description

Import point cloud files abstracting them to a set of voxels.

Constructor & Destructor Documentation

◆ XYZPointCloudFileLoader()

XYZPointCloudFileLoader::XYZPointCloudFileLoader ( )
inlineexplicit

Constructor for point cloud loader.

See also
AbstractGeometryFilter::AbstractGeometryFilter(ScenePart*)

Member Function Documentation

◆ _estimateNormals()

void XYZPointCloudFileLoader::_estimateNormals ( size_t  start,
size_t  end 
)
private

Assists estimateNormals function. Normals for filled matrices are computed at this function.

Parameters
startSpecifies the start index in the voxel grid
endSpecified the end index in the voxel grid

◆ correctNormal()

bool XYZPointCloudFileLoader::correctNormal ( double &  x,
double &  y,
double &  z 
)
private

Correct normal if necessary. Only non valid normals will be corrected.

Parameters
xNormal x component
yNormal y component
zNormal z component
Returns
True if the voxel normal is valid, False otherwise.

◆ estimateNormalsBatch()

void XYZPointCloudFileLoader::estimateNormalsBatch ( ifstream &  ifs)
private

Estimate voxels normals in batch mode, which implies reading input file as many times as specified by numBatches variable. The output generated by this function is the same than the one that should be generated by estimateNormals function.

See also
XYZPointCloudFileLoader::estimateNormals
XYZPointCloudFileLoader::numBatches

◆ fillVoxelsGrid()

void XYZPointCloudFileLoader::fillVoxelsGrid ( ifstream &  ifs,
int  estimateNormals,
double  halfVoxelSize,
string const &  filePathString 
)
private

Fill voxels grid.

Parameters
estimateNormalsUsed to specified normal estimation method. A value of 0 means no normal estimation, a value of 1 means normal estimation will be performed entirely in memory and a value of 2 means normal estimation will be performed through multiple runs over the input file

◆ firstPass()

void XYZPointCloudFileLoader::firstPass ( string const &  filePathString,
ifstream &  ifs 
)
private

First pass of input file used to find essential information needed to successfully abstract the point cloud to voxels.

Parameters
filePathStringPath to the input file
ifsStream used to read from input file

◆ indexFromCoordinates()

size_t XYZPointCloudFileLoader::indexFromCoordinates ( double  x,
double  y,
double  z,
size_t &  I,
size_t &  J,
size_t &  K 
)
private

Obtain voxel-grid index for given coordinates.

Parameters
[out]IUsed to output I index (x axis)
[out]JUsed to output J index (y axis)
[out]KUsed to output K index (z axis)
Returns
Voxel-grid index

◆ isLineComment()

bool XYZPointCloudFileLoader::isLineComment ( string const &  line)
staticprivate

Check if given line is a comment or not.

Parameters
lineLine to be checked
Returns
True if line is a comment, false otherwise

◆ parse()

void XYZPointCloudFileLoader::parse ( std::string const &  filePath)
private

Parse XYZ file.

Parameters
filePathPath to XYZ file to be parsed

◆ postProcess()

void XYZPointCloudFileLoader::postProcess ( string const &  matName,
int  estimateNormals 
)
private

Post process already filled voxels grid.

Parameters
estimateNormalsUsed to specify if normals must be estimated (>0) or not (0)

◆ prepareVoxelsGrid()

void XYZPointCloudFileLoader::prepareVoxelsGrid ( int &  estimateNormals,
double &  halfVoxelSize 
)
private

Prepare voxels grid computation.

Parameters
[out]estimateNormalsUsed to return normals estimation specification
[out]halfVoxelSizeUsed to return half of the voxel size

◆ restartInputFileStream()

void XYZPointCloudFileLoader::restartInputFileStream ( ifstream &  ifs)
staticprivate

Reset given input file stream so it points to file start.

Parameters
ifsInput file stream to be resetted.

◆ run()

ScenePart * XYZPointCloudFileLoader::run ( )
virtual

◆ secondPass()

void XYZPointCloudFileLoader::secondPass ( string const &  filePathString,
string const &  matName,
ifstream &  ifs 
)
private

Second pass where the input file is read as many times as needed to build necessary voxels.

Parameters
filePathStringPath to the input file
matNameName of the material to be used for voxels
ifsStream used to read from input file

Member Data Documentation

◆ discardedPointsByNormal

size_t XYZPointCloudFileLoader::discardedPointsByNormal = 0
private

How many points were discarded because they were expected to have a correct normal but they did not.

See also
XYZPointCloudFileLoader::correctNormal

◆ maxNVoxels

size_t XYZPointCloudFileLoader::maxNVoxels
private

Total size of full voxels grid.

See also
XYZPointCloudFileLoader::voxels

◆ xCoeff

double XYZPointCloudFileLoader::xCoeff
private

Coefficient ( \(K_{x}\)) to compute \(I\) voxel index for a given \(x\) coordinate.

\[ I = (x - x_{min}) \cdot K_{x} \]

◆ yCoeff

double XYZPointCloudFileLoader::yCoeff
private

Coefficient ( \(K_{y}\)) to compute \(J\) voxel index for a given \(y\) coordinate.

\[ J = (y - y_{min}) \cdot K_{y} \]

◆ zCoeff

double XYZPointCloudFileLoader::zCoeff
private

Coefficient ( \(K_{z}\)) to compute \(K\) voxel index for a given \(z\) coordinate.

\[ K = (z - z_{min}) \cdot K_{z} \]


The documentation for this class was generated from the following files: