Program Listing for File LineReader.hpp
↰ Return to documentation for file (include/lvr2/io/LineReader.hpp)
/*
* LineReader.hpp
*
* Created on: Aug 15, 2017
* Author: Isaak Mitschke
*/
#ifndef LAS_VEGAS_LINEREADER_HPP
#define LAS_VEGAS_LINEREADER_HPP
#include "DataStruct.hpp"
#include <boost/shared_array.hpp>
#include <exception>
#include <string>
namespace lvr2
{
enum fileType
{
XYZ,
XYZRGB,
XYZN,
XYZNRGB
};
struct fileAttribut
{
std::string m_filePath;
size_t m_filePos;
size_t m_elementAmount;
fileType m_fileType;
size_t m_PointBlockSize;
bool m_ply;
bool m_binary;
size_t m_line_element_amount;
};
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#pragma pack(push, 1)
struct xyz
#else
struct __attribute__((packed)) xyz
#endif
{
lvr2::coord<float> point;
};
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#pragma pack(pop)
#endif
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#pragma pack(push, 1)
struct xyzn : xyz
#else
struct __attribute__((packed)) xyzn : xyz
#endif
{
lvr2::coord<float> normal;
};
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#pragma pack(pop)
#endif
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#pragma pack(push, 1)
struct xyznc : xyzn
#else
struct __attribute__((packed)) xyznc : xyzn
#endif
{
lvr2::color<unsigned char> color;
};
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#pragma pack(pop)
#endif
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#pragma pack(push, 1)
struct xyzc : xyz
#else
struct __attribute__((packed)) xyzc : xyz
#endif
{
lvr2::color<unsigned char> color;
};
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#pragma pack(pop)
#endif
template<typename LineType>
struct LineTypeTraits
{
static const bool hasNormal = false;
static const bool hasColor = false;
};
template<>
struct LineTypeTraits<xyzn>
{
static const bool hasNormal = true;
};
template<>
struct LineTypeTraits<xyzc>
{
static const bool hasColor = true;
};
template<>
struct LineTypeTraits<xyznc>
{
static const bool hasNormal = true;
static const bool hasColor = true;
};
class LineReader
{
public:
LineReader();
LineReader(std::string filePath);
LineReader(std::vector<std::string> filePaths);
void open(std::string filePath);
void open(std::vector<std::string> filePaths);
size_t getNumPoints();
bool getNextPoint(xyznc &point);
// boost::shared_array<xyzn> getNextPoints(size_t &return_amount, size_t amount =
// 1000000); boost::shared_array<xyzc> getNextPoints(size_t &return_amount, size_t amount
// = 1000000); boost::shared_array<xyznc> getNextPoints(size_t &return_amount, size_t
// amount = 1000000);
boost::shared_ptr<void> getNextPoints(size_t &return_amount, size_t amount = 1000000);
fileType getFileType(size_t i);
fileType getFileType();
void rewind(size_t i);
void rewind();
bool ok();
bool isPly() { return m_ply; }
class readException : public std::exception
{
public:
readException(std::string what) : error_msg(what) {}
virtual const char *what() const throw() { return error_msg.c_str(); }
private:
std::string error_msg;
};
private:
std::vector<std::string> m_filePaths;
std::vector<size_t> m_filePos;
size_t m_elementAmount;
fileType m_fileType;
size_t m_PointBlockSize;
bool m_ply;
bool m_binary;
size_t m_line_element_amount;
size_t m_numFiles;
size_t m_currentReadFile;
bool m_openNextFile;
std::vector<fileAttribut> m_fileAttributes;
};
} // namespace lvr2
#endif // LAS_VEGAS_LINEREADER_H