Helios++
Helios software for LiDAR simulations
XYZPointCloudFileLoader.h
1 #pragma once
2 
3 #include "AbstractGeometryFilter.h"
4 #include "Voxel.h"
5 #include <string>
6 #include <fstream>
7 #include <armadillo>
8 
9 using std::string;
10 using std::ifstream;
11 using arma::Mat;
12 
18  Voxel *voxel = nullptr;
19  Mat<double> *matrix = nullptr;
20  size_t cursor = 0;
21  double closestPointDistance = std::numeric_limits<double>::max();
22 };
23 
28 public:
29  // *** CONSTANTS *** //
30  // ******************* //
35  static int const minPointsForSafeNormalEstimation = 3;
39  static size_t const batchSize = 10000000;
44  static int const voxelPopulationThreshold = 40000;
45 private:
46  // *** ATTRIBUTES *** //
47  // ******************** //
51  std::string separator = " ";
55  double voxelSize = 1;
59  double maxColorValue = 0;
60 
64  bool snapNeighborNormal = false;
69  bool assignDefaultNormal = false;
73  glm::dvec3 defaultNormal = glm::dvec3(0,0,0);
85 
89  size_t n;
93  double minX;
97  double minY;
101  double minZ;
105  double maxX;
109  double maxY;
113  double maxZ;
114 
118  size_t nx;
122  size_t ny;
126  size_t nz;
131  size_t nynz;
132 
141  double xCoeff;
150  double yCoeff;
159  double zCoeff;
160 
164  VoxelGridCell *voxels = nullptr;
169  size_t maxNVoxels;
173  size_t numBatches;
174 
180 
181  // *** MAIN PARSING METHODS *** //
182  // ****************************** //
187  void parse(std::string const & filePath);
188 
195  void firstPass(string const & filePathString, ifstream &ifs);
203  void secondPass(
204  string const &filePathString,
205  string const &matName,
206  ifstream &ifs
207  );
213  void loadMaterial();
214 
215  // *** AUXILIAR PARSING METHODS *** //
216  // ********************************** //
223  void prepareVoxelsGrid(
224  int &estimateNormals,
225  double &halfVoxelSize
226  );
235  void fillVoxelsGrid(
236  ifstream &ifs,
237  int estimateNormals,
238  double halfVoxelSize,
239  string const &filePathString
240  );
249  bool correctNormal(
250  double &x,
251  double &y,
252  double &z
253  );
259  void digestVoxel(
260  int estimateNormals,
261  double halfVoxelSize,
262  double x,
263  double y,
264  double z,
265  double r,
266  double g,
267  double b,
268  double xnorm,
269  double ynorm,
270  double znorm
271  );
272 
282  void warnAboutPotentialErrors(string const &filePathString);
283 
289  void postProcess(string const &matName, int estimateNormals);
294  void estimateNormals(ifstream &ifs);
303  void estimateNormalsBatch(ifstream &ifs);
311  void _estimateNormals(size_t start, size_t end);
315  void voxelsGridToScenePart();
316 
324  size_t indexFromCoordinates(
325  double x, double y, double z,
326  size_t &I, size_t &J, size_t &K
327  );
328 
329  // *** STATIC METHODS *** //
330  // ************************ //
336  static bool isLineComment(string const & line);
341  static void restartInputFileStream(ifstream &ifs);
342 
343 public:
344  // *** CONSTRUCTION / DESTRUCTION *** //
345  // ************************************ //
352  {}
353 
357  ScenePart* run();
358 
359 };
Abstract class defining asset loading filters common behavior.
Definition: AbstractGeometryFilter.h:18
Class representing a scene part.
Definition: ScenePart.h:20
Class representing a voxel primitive.
Definition: Voxel.h:11
Import point cloud files abstracting them to a set of voxels.
Definition: XYZPointCloudFileLoader.h:27
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.
Definition: XYZPointCloudFileLoader.cpp:702
ScenePart * run()
Definition: XYZPointCloudFileLoader.cpp:24
void postProcess(string const &matName, int estimateNormals)
Post process already filled voxels grid.
Definition: XYZPointCloudFileLoader.cpp:489
static size_t const batchSize
How many points consider per batch when estimating normals.
Definition: XYZPointCloudFileLoader.h:39
size_t n
The number of points in the point cloud.
Definition: XYZPointCloudFileLoader.h:89
bool correctNormal(double &x, double &y, double &z)
Correct normal if necessary. Only non valid normals will be corrected.
Definition: XYZPointCloudFileLoader.cpp:383
static void restartInputFileStream(ifstream &ifs)
Reset given input file stream so it points to file start.
Definition: XYZPointCloudFileLoader.cpp:719
void voxelsGridToScenePart()
Compose the scene part considering voxels at voxels grid.
Definition: XYZPointCloudFileLoader.cpp:692
double voxelSize
Size for each voxel.
Definition: XYZPointCloudFileLoader.h:55
double maxY
Maximum Y coordinate considering all points.
Definition: XYZPointCloudFileLoader.h:109
void fillVoxelsGrid(ifstream &ifs, int estimateNormals, double halfVoxelSize, string const &filePathString)
Fill voxels grid.
Definition: XYZPointCloudFileLoader.cpp:284
size_t numBatches
How many batches are necessary to estimate normals.
Definition: XYZPointCloudFileLoader.h:173
size_t lastNumVoxels
Used to correctly report number of voxels for each part when reading multiple files at once (i....
Definition: XYZPointCloudFileLoader.h:179
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 doe...
Definition: XYZPointCloudFileLoader.cpp:404
double yCoeff
Coefficient ( ) to compute voxel index for a given coordinate.
Definition: XYZPointCloudFileLoader.h:150
double maxColorValue
Max value with respect to used color codification.
Definition: XYZPointCloudFileLoader.h:59
VoxelGridCell * voxels
Full voxels grid.
Definition: XYZPointCloudFileLoader.h:164
void parse(std::string const &filePath)
Parse XYZ file.
Definition: XYZPointCloudFileLoader.cpp:72
bool snapNeighborNormal
Snap neighbor normal instead of average when enabled (true).
Definition: XYZPointCloudFileLoader.h:64
size_t nynz
Product . Stored in a variable because of its recurrent usage.
Definition: XYZPointCloudFileLoader.h:131
static int const voxelPopulationThreshold
How many points can be contained inside a voxel without triggering a warning due to excessive populat...
Definition: XYZPointCloudFileLoader.h:44
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.
Definition: XYZPointCloudFileLoader.cpp:197
double xCoeff
Coefficient ( ) to compute voxel index for a given coordinate.
Definition: XYZPointCloudFileLoader.h:141
size_t ny
Number of partitions along y-axis.
Definition: XYZPointCloudFileLoader.h:122
static int const minPointsForSafeNormalEstimation
How many points are necessary for the normal estimation to be reliable.
Definition: XYZPointCloudFileLoader.h:35
size_t nx
Number of partitions along x-axis.
Definition: XYZPointCloudFileLoader.h:118
std::string separator
Field separator specification used by the point cloud file.
Definition: XYZPointCloudFileLoader.h:51
void _estimateNormals(size_t start, size_t end)
Assists estimateNormals function. Normals for filled matrices are computed at this function.
Definition: XYZPointCloudFileLoader.cpp:658
glm::dvec3 defaultNormal
The default normal to be used when needed to fill missing ones.
Definition: XYZPointCloudFileLoader.h:73
double maxZ
Maximum Z coordinate considering all points.
Definition: XYZPointCloudFileLoader.h:113
double minZ
Minimum Z coordinate considering all points.
Definition: XYZPointCloudFileLoader.h:101
double zCoeff
Coefficient ( ) to compute voxel index for a given coordinate.
Definition: XYZPointCloudFileLoader.h:159
double minY
Minimum Y coordinate considering all points.
Definition: XYZPointCloudFileLoader.h:97
double minX
Minimum X coordinate considering all points.
Definition: XYZPointCloudFileLoader.h:93
void warnAboutPotentialErrors(string const &filePathString)
Some issues with normals might be solved during post processing. This function is called before XYZPo...
Definition: XYZPointCloudFileLoader.cpp:463
size_t discardedPointsByNormal
How many points were discarded because they were expected to have a correct normal but they did not.
Definition: XYZPointCloudFileLoader.h:84
bool assignDefaultNormal
Specify whether default normal must be assigned to voxels which normal cannot be safely determined (T...
Definition: XYZPointCloudFileLoader.h:69
double maxX
Maximum X coordinate considering all points.
Definition: XYZPointCloudFileLoader.h:105
void estimateNormalsBatch(ifstream &ifs)
Estimate voxels normals in batch mode, which implies reading input file as many times as specified by...
Definition: XYZPointCloudFileLoader.cpp:580
size_t nz
Number of partitions along z-axis.
Definition: XYZPointCloudFileLoader.h:126
size_t maxNVoxels
Total size of full voxels grid.
Definition: XYZPointCloudFileLoader.h:169
void prepareVoxelsGrid(int &estimateNormals, double &halfVoxelSize)
Prepare voxels grid computation.
Definition: XYZPointCloudFileLoader.cpp:241
void firstPass(string const &filePathString, ifstream &ifs)
First pass of input file used to find essential information needed to successfully abstract the point...
Definition: XYZPointCloudFileLoader.cpp:134
static bool isLineComment(string const &line)
Check if given line is a comment or not.
Definition: XYZPointCloudFileLoader.cpp:715
void loadMaterial()
Load the material for each primitive in a cyclic fashion. It is, if materials are given then the -th...
Definition: XYZPointCloudFileLoader.cpp:224
size_t unsafeNormalEstimations
How many voxels normals could not be safely estimated because there was not enough data inside the vo...
Definition: XYZPointCloudFileLoader.h:78
void estimateNormals(ifstream &ifs)
Estimate voxels normal as the orthonormal of best fitting plane for points inside voxel.
Definition: XYZPointCloudFileLoader.cpp:526
XYZPointCloudFileLoader()
Constructor for point cloud loader.
Definition: XYZPointCloudFileLoader.h:350
VoxelGridCell is used to build and fill all necessary voxels to represent input point cloud.
Definition: XYZPointCloudFileLoader.h:17