Program Listing for File BigGrid.hpp

Return to documentation for file (include/lvr2/reconstruction/BigGrid.hpp)

#pragma once

#include "lvr2/geometry/BoundingBox.hpp"
#include "lvr2/io/DataStruct.hpp"
#include "lvr2/types/MatrixTypes.hpp"

#include <boost/iostreams/device/mapped_file.hpp>
#include <string>
#include <unordered_map>
#include <utility>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;


namespace lvr2
{

struct CellInfo
{
    CellInfo() : size(0), offset(0), inserted(0) {}
    size_t size;
    size_t offset;
    size_t inserted;
};

template <typename BaseVecT>
class BigGrid
{
  public:
    BigGrid(std::vector<std::string> cloudPath, float voxelsize, float scale = 0, bool extrude = false, size_t bufferSize = 1024);

    BigGrid(float voxelsize, ScanProjectEditMarkPtr project, const fs::path& pathPrefix = "./", float scale = 0, bool extrude = false);

    BigGrid(std::string path);

    virtual ~BigGrid();

    size_t size();

    size_t pointSize();

    size_t pointSize(const Vector3i& index);

    lvr2::floatArr points(const Vector3i& index, size_t& numPoints) const;

    lvr2::floatArr points(const BoundingBox<BaseVecT>& bb, size_t& numPoints, size_t minNumPoints = 0) const;

    lvr2::floatArr normals(const BoundingBox<BaseVecT>& bb, size_t& numNormals, size_t minNumNormals = 0) const;

    lvr2::ucharArr colors(const BoundingBox<BaseVecT>& bb, size_t& numColors, size_t minNumColors = 0) const;

    size_t getSizeofBox(const BoundingBox<BaseVecT>& bb) const
    {
        std::vector<std::pair<const CellInfo*, size_t>> _unused;
        return getSizeofBox(bb, _unused);
    }
    size_t getSizeofBox(const BoundingBox<BaseVecT>& bb, std::vector<std::pair<const CellInfo*, size_t>>& cellCounts) const;

    size_t estimateSizeofBox(const BoundingBox<BaseVecT>& bb) const;

    void serialize(std::string path = "serinfo.ls");

    lvr2::floatArr getPointCloud(size_t& numPoints);

    BoundingBox<BaseVecT>& getBB() { return m_bb; }

    BoundingBox<BaseVecT>& getpartialBB() { return m_partialbb; }

    void calcIndex(const BaseVecT& vec, Vector3i& index) const
    {
        index.x() = std::floor(vec.x / m_voxelSize);
        index.y() = std::floor(vec.y / m_voxelSize);
        index.z() = std::floor(vec.z / m_voxelSize);
    }
    Vector3i calcIndex(const BaseVecT& vec) const
    {
        Vector3i ret;
        calcIndex(vec, ret);
        return ret;
    }

    inline bool exists(const Vector3i& index)
    {
        return m_cells.find(index) != m_cells.end();
    }

    const std::unordered_map<Vector3i, CellInfo>& getCells() const
    {
        return m_cells;
    }

    inline bool hasColors() const { return m_hasColor; }
    inline bool hasNormals() const { return m_hasNormal; }

private:
    template<typename LineType>
    void initFromLineReader(LineReader& lineReader);

    void calcExtrusion();

    size_t m_numPoints;

    size_t m_pointBufferSize;

    float m_voxelSize;
    bool m_extrude;
    bool m_hasNormal;
    bool m_hasColor;

    fs::path m_pathPrefix = "./";

    boost::iostreams::mapped_file m_PointFile;
    boost::iostreams::mapped_file m_NormalFile;
    boost::iostreams::mapped_file m_ColorFile;
    BoundingBox<BaseVecT> m_bb;

    //BoundingBox, of unreconstructed scans
    BoundingBox<BaseVecT> m_partialbb;

    CellInfo& getCellInfo(const BaseVecT& vec)
    {
        return getCellInfo(calcIndex(vec));
    }
    CellInfo& getCellInfo(const Vector3i& index)
    {
        return m_cells[index];
    }

    std::unordered_map<Vector3i, CellInfo> m_cells;
    float m_scale;
};

} // namespace lvr2

#include "BigGrid.tcc"