Helios++
Helios software for LiDAR simulations
VoxelFileParser Class Reference

Class for parsing voxel files. More...

#include <VoxelFileParser.h>

Collaboration diagram for VoxelFileParser:

Public Member Functions

 VoxelFileParser ()
 Build a VoxelFileParser.
 
std::vector< std::shared_ptr< DetailedVoxel > > parseDetailed (std::string const &path, size_t numHeaderLines=2, bool const exactFormat=true, bool const discardNullPad=false, std::string const separator=" ")
 Parse detailed voxels specified at file located at given path. More...
 
std::vector< DetailedVoxel * > bruteParseDetailed (std::string const &path, size_t numHeaderLines=2, bool const exactFormat=true, bool const discardNullPad=false, std::string const separator=" ")
 Like parseDetailed but returns a vector a normla pointers instead of shared pointers. More...
 

Protected Member Functions

void loadFile (std::vector< std::string > &lines, std::string const &path)
 Loads the file at given path. More...
 
void cleanLines (std::vector< std::string > &lines, size_t const numHeaderLines, bool &minCornerXFound, double &minCornerX, bool &minCornerYFound, double &minCornerY, bool &minCornerZFound, double &minCornerZ, bool &maxCornerXFound, double &maxCornerX, bool &maxCornerYFound, double &maxCornerY, bool &maxCornerZFound, double &maxCornerZ, bool &splitXFound, size_t &splitX, bool &splitYFound, size_t &splitY, bool &splitZFound, size_t &splitZ, double &voxelSize, double &maxPad)
 Clean unnecessary lines. More...
 
bool isBlankLine (std::string const &line)
 Check if the line is a blank line. More...
 
bool handleSpecLine (std::string const &line, bool &minCornerXFound, double &minCornerX, bool &minCornerYFound, double &minCornerY, bool &minCornerZFound, double &minCornerZ, bool &maxCornerXFound, double &maxCornerX, bool &maxCornerYFound, double &maxCornerY, bool &maxCornerZFound, double &maxCornerZ, bool &splitXFound, size_t &splitX, bool &splitYFound, size_t &splitY, bool &splitZFound, size_t &splitZ, double &voxelSize, double &maxPad)
 Handle line if it is an spec line. Do nothing otherwise. More...
 
void handleSpec (std::string const &line, bool &minCornerXFound, double &minCornerX, bool &minCornerYFound, double &minCornerY, bool &minCornerZFound, double &minCornerZ, bool &maxCornerXFound, double &maxCornerX, bool &maxCornerYFound, double &maxCornerY, bool &maxCornerZFound, double &maxCornerZ, bool &splitXFound, size_t &splitX, bool &splitYFound, size_t &splitY, bool &splitZFound, size_t &splitZ, double &voxelSize, double &maxPad)
 Assuming received line is a spec line, handle it. More...
 
void cleanLine (std::string &line)
 Remove unnecessary stuff from received line. More...
 
void removeHeaderLines (std::vector< std::string > &lines, size_t numHeaderLines)
 Remove header lines. More...
 
void validateDetailed (bool minCornerXFound, bool minCornerYFound, bool minCornerZFound, bool maxCornerXFound, bool maxCornerYFound, bool maxCornerZFound, bool splitXFound, bool splitYFound, bool splitZFound)
 Check if flags are valid. More...
 
DetailedVoxelparseDetailedVoxelLine (std::string &line, std::string const separator, bool const exactFormat, bool const discardNullPad, char const *format1, char const *format2, char const *format3, double minCornerX, double minCornerY, double minCornerZ, double maxCornerX, double maxCornerY, double maxCornerZ, double voxelSize, double voxelHalfSize, double maxPad)
 Parse the DetailedVoxel specified in given line. More...
 

Static Protected Attributes

static constexpr size_t N_BLANK_CHARACTERS = 4
 Nummber of blank characters.
 
static char const BLANK_CHARACTERS [N_BLANK_CHARACTERS] = {' ', '\t', '\r', '\n'}
 Characters considered "blank".
 
static constexpr char SPEC_CHARACTER = '#'
 Character which starts spec lines.
 

Detailed Description

Class for parsing voxel files.

Author
Alberto M. Esmoris Pena
Version
1.0

Current implementation is based on AMAPVox format

Member Function Documentation

◆ bruteParseDetailed()

std::vector< DetailedVoxel * > VoxelFileParser::bruteParseDetailed ( std::string const &  path,
size_t  numHeaderLines = 2,
bool const  exactFormat = true,
bool const  discardNullPad = false,
std::string const  separator = " " 
)

Like parseDetailed but returns a vector a normla pointers instead of shared pointers.

See also
parseDetailed( std::string const &, size_t, bool const, std::string const)

◆ cleanLine()

void VoxelFileParser::cleanLine ( std::string &  line)
protected

Remove unnecessary stuff from received line.

All starting and ending spaces are removed

Parameters
lineLine to be cleaned

◆ cleanLines()

void VoxelFileParser::cleanLines ( std::vector< std::string > &  lines,
size_t const  numHeaderLines,
bool &  minCornerXFound,
double &  minCornerX,
bool &  minCornerYFound,
double &  minCornerY,
bool &  minCornerZFound,
double &  minCornerZ,
bool &  maxCornerXFound,
double &  maxCornerX,
bool &  maxCornerYFound,
double &  maxCornerY,
bool &  maxCornerZFound,
double &  maxCornerZ,
bool &  splitXFound,
size_t &  splitX,
bool &  splitYFound,
size_t &  splitY,
bool &  splitZFound,
size_t &  splitZ,
double &  voxelSize,
double &  maxPad 
)
protected

Clean unnecessary lines.

  1. All spaces at the beginning and end of each line are removed.
  2. All lines which first character is '#' are considered as comments, hence removed
Parameters
linesLines that shall be cleaned
numHeaderLinesNumber of header lines to be cleaned

◆ handleSpec()

void VoxelFileParser::handleSpec ( std::string const &  line,
bool &  minCornerXFound,
double &  minCornerX,
bool &  minCornerYFound,
double &  minCornerY,
bool &  minCornerZFound,
double &  minCornerZ,
bool &  maxCornerXFound,
double &  maxCornerX,
bool &  maxCornerYFound,
double &  maxCornerY,
bool &  maxCornerZFound,
double &  maxCornerZ,
bool &  splitXFound,
size_t &  splitX,
bool &  splitYFound,
size_t &  splitY,
bool &  splitZFound,
size_t &  splitZ,
double &  voxelSize,
double &  maxPad 
)
protected

Assuming received line is a spec line, handle it.

Handling a spec line means received arguments will be modified accordingly to what have been handled.

Parameters
lineSpec line
minCornerXFoundSpecify if the X coordinate of the minimum corner of the bounding box containing the voxels has been found (true) or not (false)
minCornerXX coordinate of the minimum corner of the bounding box containing the voxels.
minCornerYFoundSpecify if the Y coordinate of the minimum corner of the bounding box containing the voxels has been found (true) or not (false)
minCornerYY coordinate of the minimum corner of the bounding box containing the voxels.
minCornerZFoundSpecify if the Z coordinate of the minimum corner of the bounding box containing the voxels has been found (true) or not (false)
minCornerZZ coordinate of the minimum corner of the bounding box containing the voxels.
maxCornerXFoundSpecify if the X coordinate of the maximum corner of the bounding box containing the voxels has been found (true) or not (false)
maxCornerXX coordinate of the maximum corner of the bounding box containing the voxels.
maxCornerYFoundSpecify if the Y coordinate of the maximum corner of the bounding box containing the voxels has been found (true) or not (false)
maxCornerYY coordinate of the maximum corner of the bounding box containing the voxels.
maxCornerZFoundSpecify if the Z coordinate of the maximum corner of the bounding box containing the voxels has been found (true) or not (false)
maxCornerZZ coordinate of the maximum corner of the bounding box containing the voxels.
splitXFoundSpecify if the number of voxels along the X axis of the bounding box containing the voxels has been found (true) or not (false)
splitXNumber of voxels along the X axis of the bounding box containing the voxels
splitYFoundSpecify if the number of voxels along the Y axis of the bounding box containing the voxels has been found (true) or not (false)
splitYNumber of voxels along the Y axis of the bounding box containing the voxels
splitZFoundSpecify if the number of voxels along the Z axis of the bounding box containing the voxels has been found (true) or not (false)
splitZNumber of voxels along the Z axis of the bounding box containing the voxels
voxelSizeThe size for each voxel

◆ handleSpecLine()

bool VoxelFileParser::handleSpecLine ( std::string const &  line,
bool &  minCornerXFound,
double &  minCornerX,
bool &  minCornerYFound,
double &  minCornerY,
bool &  minCornerZFound,
double &  minCornerZ,
bool &  maxCornerXFound,
double &  maxCornerX,
bool &  maxCornerYFound,
double &  maxCornerY,
bool &  maxCornerZFound,
double &  maxCornerZ,
bool &  splitXFound,
size_t &  splitX,
bool &  splitYFound,
size_t &  splitY,
bool &  splitZFound,
size_t &  splitZ,
double &  voxelSize,
double &  maxPad 
)
protected

Handle line if it is an spec line. Do nothing otherwise.

Spec lines are so because its first non blank character is #

Parameters
lineLine to be handled
Returns
True if line is a spec line, False otherwise
See also
BLANK_CHARACTERS
SPEC_CHARACTER

◆ isBlankLine()

bool VoxelFileParser::isBlankLine ( std::string const &  line)
protected

Check if the line is a blank line.

Blank lines are those lines which only contain spaces, tabulations, carriage return or new line characters.

Parameters
lineLine to be checked
Returns
True if line is a blank line, False otherwise
See also
BLANK_CHARACTERS

◆ loadFile()

void VoxelFileParser::loadFile ( std::vector< std::string > &  lines,
std::string const &  path 
)
protected

Loads the file at given path.

Parameters
linesWhere lines shall be placed
pathPath to the file to be loaded

◆ parseDetailed()

std::vector< std::shared_ptr< DetailedVoxel > > VoxelFileParser::parseDetailed ( std::string const &  path,
size_t  numHeaderLines = 2,
bool const  exactFormat = true,
bool const  discardNullPad = false,
std::string const  separator = " " 
)

Parse detailed voxels specified at file located at given path.

Parameters
pathWhere the detailed voxels specification file is located
numHeaderLinesSpecify how many header lines are used at given file. Comments and blank lines must not be considered for this count.
exactFormatWhen true it is assumed that only standard parameters should be considering for each voxel. Using this knowledge parsing process can be accelerated.
discardNullPadWhen true, those voxels with a PadBvTotal of 0 will be discarded (by default they are preserved)
separatorThe separator between different fields

For instance, if 1st line is a header line, 2nd line is a comment line, 3rd line is a header line and from 4th line all lines are content; number of header lines should be specified as 2

Returns
Parsed detailed voxels

◆ parseDetailedVoxelLine()

DetailedVoxel * VoxelFileParser::parseDetailedVoxelLine ( std::string &  line,
std::string const  separator,
bool const  exactFormat,
bool const  discardNullPad,
char const *  format1,
char const *  format2,
char const *  format3,
double  minCornerX,
double  minCornerY,
double  minCornerZ,
double  maxCornerX,
double  maxCornerY,
double  maxCornerZ,
double  voxelSize,
double  voxelHalfSize,
double  maxPad 
)
protected

Parse the DetailedVoxel specified in given line.

Parameters
lineLine where the DetailedVoxel is specified
separatorThe separator between different fields
format1Format string to parse indices at X,Y,Z (i,j,k), so voxel coordinates can be computed
format2Format string to parse expected doubles
format3Format string to parse extra values (doubles)
Returns
Parsed DetailedVoxel (nullptr if it was discarded, for instance to ignore transmittive voxels with PadBVTotal==0)

◆ removeHeaderLines()

void VoxelFileParser::removeHeaderLines ( std::vector< std::string > &  lines,
size_t  numHeaderLines 
)
protected

Remove header lines.

Parameters
linesFrom where header lines shall be removed
numHeaderLinesHow many header lines shall be removed

◆ validateDetailed()

void VoxelFileParser::validateDetailed ( bool  minCornerXFound,
bool  minCornerYFound,
bool  minCornerZFound,
bool  maxCornerXFound,
bool  maxCornerYFound,
bool  maxCornerZFound,
bool  splitXFound,
bool  splitYFound,
bool  splitZFound 
)
protected

Check if flags are valid.

Exceptions
HeliosExceptionif there is a not valid flag

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