outofcore_cloud.h
#pragma once
#include <condition_variable>
#include <cstdint>
#include <memory>
#include <mutex>
#include <thread>
// PCL
#include <pcl/pcl_macros.h>
#include <pcl/point_types.h>
// PCL - outofcore
#include <pcl/outofcore/outofcore.h>
#include <pcl/outofcore/outofcore_impl.h>
#include <pcl/outofcore/impl/lru_cache.hpp>
// PCL
#include "camera.h"
// VTK
#include <vtkActor.h>
#include <vtkActorCollection.h>
#include <vtkAppendPolyData.h>
#include <vtkDataSetMapper.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
//class Camera;
class OutofcoreCloud : public Object
{
// Typedefs
// -----------------------------------------------------------------------------
using PointT = pcl::PointXYZ;
// using octree_disk = pcl::outofcore::OutofcoreOctreeBase<pcl::outofcore::OutofcoreOctreeDiskContainer<PointT>, PointT>;
// using octree_disk_node = pcl::outofcore::OutofcoreOctreeBaseNode<pcl::outofcore::OutofcoreOctreeDiskContainer<PointT>, PointT>;
using OctreeDisk = pcl::outofcore::OutofcoreOctreeBase<>;
using OctreeDiskNode = pcl::outofcore::OutofcoreOctreeBaseNode<>;
// using OctreeBreadthFirstIterator = pcl::outofcore::OutofcoreBreadthFirstIterator<>;
using OctreeDiskPtr = OctreeDisk::Ptr;
using AlignedPointT = Eigen::aligned_allocator<PointT>;
using CloudActorMap = std::map<std::string, vtkSmartPointer<vtkActor> >;
public:
// using CloudDataCache = std::map<std::string, vtkSmartPointer<vtkPolyData> >;
// using CloudDataCacheIterator = std::map<std::string, vtkSmartPointer<vtkPolyData> >::iterator;
static std::shared_ptr<std::thread> pcd_reader_thread;
//static MonitorQueue<std::string> pcd_queue;
struct PcdQueueItem
{
PcdQueueItem (std::string pcd_file, float coverage)
{
this->pcd_file = pcd_file;
this->coverage = coverage;
}
bool operator< (const PcdQueueItem& rhs) const
{
return coverage < rhs.coverage;
}
std::string pcd_file;
float coverage;
};
using PcdQueue = std::priority_queue<PcdQueueItem>;
static PcdQueue pcd_queue;
static std::mutex pcd_queue_mutex;
static std::condition_variable pcd_queue_ready;
class CloudDataCacheItem : public LRUCacheItem< vtkSmartPointer<vtkPolyData> >
{
public:
CloudDataCacheItem (std::string pcd_file, float coverage, vtkSmartPointer<vtkPolyData> cloud_data, std::size_t timestamp)
{
this->pcd_file = pcd_file;
this->coverage = coverage;
this->item = cloud_data;
this->timestamp = timestamp;
}
std::size_t
sizeOf() const override
{
return item->GetActualMemorySize();
}
std::string pcd_file;
float coverage;
};
// static CloudDataCache cloud_data_map;
// static std::mutex cloud_data_map_mutex;
using CloudDataCache = LRUCache<std::string, CloudDataCacheItem>;
static CloudDataCache cloud_data_cache;
static std::mutex cloud_data_cache_mutex;
static void pcdReaderThread();
// Operators
// -----------------------------------------------------------------------------
OutofcoreCloud (std::string name, boost::filesystem::path& tree_root);
// Methods
// -----------------------------------------------------------------------------
void
updateVoxelData ();
// Accessors
// -----------------------------------------------------------------------------
OctreeDiskPtr
getOctree ()
{
return octree_;
}
inline vtkSmartPointer<vtkActor>
getVoxelActor () const
{
return voxel_actor_;
}
inline vtkSmartPointer<vtkActorCollection>
getCloudActors () const
{
return cloud_actors_;
}
void
setDisplayDepth (int displayDepth)
{
if (displayDepth < 0)
{
displayDepth = 0;
}
else if (static_cast<unsigned int> (displayDepth) > octree_->getDepth ())
{
displayDepth = octree_->getDepth ();
}
if (display_depth_ != static_cast<std::uint64_t> (displayDepth))
{
display_depth_ = displayDepth;
updateVoxelData ();
//updateCloudData();
}
}
int
getDisplayDepth () const
{
return display_depth_;
}
std::uint64_t
getPointsLoaded () const
{
return points_loaded_;
}
std::uint64_t
getDataLoaded () const
{
return data_loaded_;
}
Eigen::Vector3d
getBoundingBoxMin ()
{
return bbox_min_;
}
Eigen::Vector3d
getBoundingBoxMax ()
{
return bbox_max_;
}
void
setDisplayVoxels (bool display_voxels)
{
voxel_actor_->SetVisibility (display_voxels);
}
bool
getDisplayVoxels()
{
return voxel_actor_->GetVisibility ();
}
void
setRenderCamera(Camera *render_camera)
{
render_camera_ = render_camera;
}
int
getLodPixelThreshold ()
{
return lod_pixel_threshold_;
}
void
setLodPixelThreshold (int lod_pixel_threshold)
{
if (lod_pixel_threshold <= 1000)
lod_pixel_threshold = 1000;
lod_pixel_threshold_ = lod_pixel_threshold;
}
void
increaseLodPixelThreshold ()
{
int value = 1000;
if (lod_pixel_threshold_ >= 50000)
value = 10000;
if (lod_pixel_threshold_ >= 10000)
value = 5000;
else if (lod_pixel_threshold_ >= 1000)
value = 100;
lod_pixel_threshold_ += value;
std::cout << "Increasing lod pixel threshold: " << lod_pixel_threshold_ << std::endl;
}
void
decreaseLodPixelThreshold ()
{
int value = 1000;
if (lod_pixel_threshold_ > 50000)
value = 10000;
else if (lod_pixel_threshold_ > 10000)
value = 5000;
else if (lod_pixel_threshold_ > 1000)
value = 100;
lod_pixel_threshold_ -= value;
if (lod_pixel_threshold_ < 100)
lod_pixel_threshold_ = 100;
std::cout << "Decreasing lod pixel threshold: " << lod_pixel_threshold_ << std::endl;
}
void
render (vtkRenderer* renderer) override;
private:
// Members
// -----------------------------------------------------------------------------
OctreeDiskPtr octree_;
std::uint64_t display_depth_;
std::uint64_t points_loaded_;
std::uint64_t data_loaded_;
Eigen::Vector3d bbox_min_, bbox_max_;
Camera *render_camera_;
int lod_pixel_threshold_;
vtkSmartPointer<vtkActor> voxel_actor_;
std::map<std::string, vtkSmartPointer<vtkActor> > cloud_actors_map_;
vtkSmartPointer<vtkActorCollection> cloud_actors_;
public:
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
OutofcoreCloud::PcdQueue
std::priority_queue< PcdQueueItem > PcdQueue
Definition: outofcore_cloud.h:76
OutofcoreCloud::cloud_data_cache_mutex
static std::mutex cloud_data_cache_mutex
Definition: outofcore_cloud.h:108
pcl_macros.h
Defines all the PCL and non-PCL macros used.
OutofcoreCloud::setDisplayDepth
void setDisplayDepth(int displayDepth)
Definition: outofcore_cloud.h:142
point_types.h
OutofcoreCloud::PcdQueueItem::PcdQueueItem
PcdQueueItem(std::string pcd_file, float coverage)
Definition: outofcore_cloud.h:61
OutofcoreCloud::pcd_reader_thread
static std::shared_ptr< std::thread > pcd_reader_thread
Definition: outofcore_cloud.h:56
OutofcoreCloud::setRenderCamera
void setRenderCamera(Camera *render_camera)
Definition: outofcore_cloud.h:204
OutofcoreCloud::updateVoxelData
void updateVoxelData()
LRUCacheItem< vtkSmartPointer< vtkPolyData > >::item
vtkSmartPointer< vtkPolyData > item
Definition: lru_cache.hpp:22
pcl::outofcore::OutofcoreOctreeBase::Ptr
shared_ptr< OutofcoreOctreeBase< ContainerT, PointT > > Ptr
Definition: octree_base.h:178
OutofcoreCloud::pcd_queue_ready
static std::condition_variable pcd_queue_ready
Definition: outofcore_cloud.h:79
OutofcoreCloud::CloudDataCacheItem::coverage
float coverage
Definition: outofcore_cloud.h:100
OutofcoreCloud::CloudDataCacheItem
Definition: outofcore_cloud.h:81
pcl::outofcore::OutofcoreOctreeBaseNode
OutofcoreOctreeBaseNode Class internally representing nodes of an outofcore octree,...
Definition: octree_base_node.h:62
OutofcoreCloud
Definition: outofcore_cloud.h:31
OutofcoreCloud::getBoundingBoxMax
Eigen::Vector3d getBoundingBoxMax()
Definition: outofcore_cloud.h:186
OutofcoreCloud::decreaseLodPixelThreshold
void decreaseLodPixelThreshold()
Definition: outofcore_cloud.h:241
OutofcoreCloud::CloudDataCacheItem::CloudDataCacheItem
CloudDataCacheItem(std::string pcd_file, float coverage, vtkSmartPointer< vtkPolyData > cloud_data, std::size_t timestamp)
Definition: outofcore_cloud.h:85
OutofcoreCloud::PcdQueueItem
Definition: outofcore_cloud.h:59
OutofcoreCloud::increaseLodPixelThreshold
void increaseLodPixelThreshold()
Definition: outofcore_cloud.h:225
OutofcoreCloud::pcd_queue_mutex
static std::mutex pcd_queue_mutex
Definition: outofcore_cloud.h:78
LRUCache
Definition: lru_cache.hpp:27
OutofcoreCloud::getOctree
OctreeDiskPtr getOctree()
Definition: outofcore_cloud.h:124
OutofcoreCloud::getLodPixelThreshold
int getLodPixelThreshold()
Definition: outofcore_cloud.h:210
OutofcoreCloud::getDataLoaded
std::uint64_t getDataLoaded() const
Definition: outofcore_cloud.h:174
OutofcoreCloud::CloudDataCacheItem::sizeOf
std::size_t sizeOf() const override
Definition: outofcore_cloud.h:94
OutofcoreCloud::getBoundingBoxMin
Eigen::Vector3d getBoundingBoxMin()
Definition: outofcore_cloud.h:180
OutofcoreCloud::pcdReaderThread
static void pcdReaderThread()
OutofcoreCloud::getVoxelActor
vtkSmartPointer< vtkActor > getVoxelActor() const
Definition: outofcore_cloud.h:130
OutofcoreCloud::setDisplayVoxels
void setDisplayVoxels(bool display_voxels)
Definition: outofcore_cloud.h:192
pcl::PointXYZ
A point structure representing Euclidean xyz coordinates.
Definition: point_types.hpp:291
OutofcoreCloud::setLodPixelThreshold
void setLodPixelThreshold(int lod_pixel_threshold)
Definition: outofcore_cloud.h:216
OutofcoreCloud::pcd_queue
static PcdQueue pcd_queue
Definition: outofcore_cloud.h:77
OutofcoreCloud::CloudDataCacheItem::pcd_file
std::string pcd_file
Definition: outofcore_cloud.h:99
OutofcoreCloud::getCloudActors
vtkSmartPointer< vtkActorCollection > getCloudActors() const
Definition: outofcore_cloud.h:136
Object
Definition: object.h:18
PCL_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: pcl_macros.h:371
OutofcoreCloud::OutofcoreCloud
OutofcoreCloud(std::string name, boost::filesystem::path &tree_root)
OutofcoreCloud::PcdQueueItem::pcd_file
std::string pcd_file
Definition: outofcore_cloud.h:72
OutofcoreCloud::PcdQueueItem::coverage
float coverage
Definition: outofcore_cloud.h:73
OutofcoreCloud::getDisplayVoxels
bool getDisplayVoxels()
Definition: outofcore_cloud.h:198
LRUCacheItem< vtkSmartPointer< vtkPolyData > >::timestamp
std::size_t timestamp
Definition: lru_cache.hpp:23
OutofcoreCloud::PcdQueueItem::operator<
bool operator<(const PcdQueueItem &rhs) const
Definition: outofcore_cloud.h:67
LRUCacheItem
Definition: lru_cache.hpp:9
OutofcoreCloud::cloud_data_cache
static CloudDataCache cloud_data_cache
Definition: outofcore_cloud.h:107
OutofcoreCloud::render
void render(vtkRenderer *renderer) override
Camera
Definition: camera.h:19
pcl::outofcore::OutofcoreOctreeBase
This code defines the octree used for point storage at Urban Robotics.
Definition: octree_base.h:150
OutofcoreCloud::getDisplayDepth
int getDisplayDepth() const
Definition: outofcore_cloud.h:162
OutofcoreCloud::getPointsLoaded
std::uint64_t getPointsLoaded() const
Definition: outofcore_cloud.h:168
vtkSmartPointer< vtkPolyData >
pcl::uint64_t
std::uint64_t uint64_t
Definition: pcl_macros.h:98