Point Cloud Library (PCL)  1.10.0
outofcore_cloud.h
1 #pragma once
2 
3 #include <condition_variable>
4 #include <cstdint>
5 #include <memory>
6 #include <mutex>
7 #include <thread>
8 
9 // PCL
10 #include <pcl/pcl_macros.h>
11 #include <pcl/point_types.h>
12 
13 // PCL - outofcore
14 #include <pcl/outofcore/outofcore.h>
15 #include <pcl/outofcore/outofcore_impl.h>
16 #include <pcl/outofcore/impl/lru_cache.hpp>
17 
18 // PCL
19 #include "camera.h"
20 
21 // VTK
22 #include <vtkActor.h>
23 #include <vtkActorCollection.h>
24 #include <vtkAppendPolyData.h>
25 #include <vtkDataSetMapper.h>
26 #include <vtkPolyData.h>
27 #include <vtkSmartPointer.h>
28 
29 //class Camera;
30 
31 class OutofcoreCloud : public Object
32 {
33  // Typedefs
34  // -----------------------------------------------------------------------------
35  using PointT = pcl::PointXYZ;
36 // using octree_disk = pcl::outofcore::OutofcoreOctreeBase<pcl::outofcore::OutofcoreOctreeDiskContainer<PointT>, PointT>;
37 // using octree_disk_node = pcl::outofcore::OutofcoreOctreeBaseNode<pcl::outofcore::OutofcoreOctreeDiskContainer<PointT>, PointT>;
38 
41 // using OctreeBreadthFirstIterator = pcl::outofcore::OutofcoreBreadthFirstIterator<>;
42 
43  using OctreeDiskPtr = OctreeDisk::Ptr;
44  using AlignedPointT = Eigen::aligned_allocator<PointT>;
45 
46 
47 
48  using CloudActorMap = std::map<std::string, vtkSmartPointer<vtkActor> >;
49 
50  public:
51 
52 // using CloudDataCache = std::map<std::string, vtkSmartPointer<vtkPolyData> >;
53 // using CloudDataCacheIterator = std::map<std::string, vtkSmartPointer<vtkPolyData> >::iterator;
54 
55 
56  static std::shared_ptr<std::thread> pcd_reader_thread;
57  //static MonitorQueue<std::string> pcd_queue;
58 
59  struct PcdQueueItem
60  {
61  PcdQueueItem (std::string pcd_file, float coverage)
62  {
63  this->pcd_file = pcd_file;
64  this->coverage = coverage;
65  }
66 
67  bool operator< (const PcdQueueItem& rhs) const
68  {
69  return coverage < rhs.coverage;
70  }
71 
72  std::string pcd_file;
73  float coverage;
74  };
75 
76  using PcdQueue = std::priority_queue<PcdQueueItem>;
78  static std::mutex pcd_queue_mutex;
79  static std::condition_variable pcd_queue_ready;
80 
81  class CloudDataCacheItem : public LRUCacheItem< vtkSmartPointer<vtkPolyData> >
82  {
83  public:
84 
85  CloudDataCacheItem (std::string pcd_file, float coverage, vtkSmartPointer<vtkPolyData> cloud_data, std::size_t timestamp)
86  {
87  this->pcd_file = pcd_file;
88  this->coverage = coverage;
89  this->item = cloud_data;
90  this->timestamp = timestamp;
91  }
92 
93  std::size_t
94  sizeOf() const override
95  {
96  return item->GetActualMemorySize();
97  }
98 
99  std::string pcd_file;
100  float coverage;
101  };
102 
103 
104 // static CloudDataCache cloud_data_map;
105 // static std::mutex cloud_data_map_mutex;
108  static std::mutex cloud_data_cache_mutex;
109 
110  static void pcdReaderThread();
111 
112  // Operators
113  // -----------------------------------------------------------------------------
114  OutofcoreCloud (std::string name, boost::filesystem::path& tree_root);
115 
116  // Methods
117  // -----------------------------------------------------------------------------
118  void
119  updateVoxelData ();
120 
121  // Accessors
122  // -----------------------------------------------------------------------------
123  OctreeDiskPtr
125  {
126  return octree_;
127  }
128 
130  getVoxelActor () const
131  {
132  return voxel_actor_;
133  }
134 
136  getCloudActors () const
137  {
138  return cloud_actors_;
139  }
140 
141  void
142  setDisplayDepth (int displayDepth)
143  {
144  if (displayDepth < 0)
145  {
146  displayDepth = 0;
147  }
148  else if (static_cast<unsigned int> (displayDepth) > octree_->getDepth ())
149  {
150  displayDepth = octree_->getDepth ();
151  }
152 
153  if (display_depth_ != static_cast<std::uint64_t> (displayDepth))
154  {
155  display_depth_ = displayDepth;
156  updateVoxelData ();
157  //updateCloudData();
158  }
159  }
160 
161  int
163  {
164  return display_depth_;
165  }
166 
169  {
170  return points_loaded_;
171  }
172 
174  getDataLoaded () const
175  {
176  return data_loaded_;
177  }
178 
179  Eigen::Vector3d
181  {
182  return bbox_min_;
183  }
184 
185  Eigen::Vector3d
187  {
188  return bbox_max_;
189  }
190 
191  void
192  setDisplayVoxels (bool display_voxels)
193  {
194  voxel_actor_->SetVisibility (display_voxels);
195  }
196 
197  bool
199  {
200  return voxel_actor_->GetVisibility ();
201  }
202 
203  void
204  setRenderCamera(Camera *render_camera)
205  {
206  render_camera_ = render_camera;
207  }
208 
209  int
211  {
212  return lod_pixel_threshold_;
213  }
214 
215  void
216  setLodPixelThreshold (int lod_pixel_threshold)
217  {
218  if (lod_pixel_threshold <= 1000)
219  lod_pixel_threshold = 1000;
220 
221  lod_pixel_threshold_ = lod_pixel_threshold;
222  }
223 
224  void
226  {
227  int value = 1000;
228 
229  if (lod_pixel_threshold_ >= 50000)
230  value = 10000;
231  if (lod_pixel_threshold_ >= 10000)
232  value = 5000;
233  else if (lod_pixel_threshold_ >= 1000)
234  value = 100;
235 
236  lod_pixel_threshold_ += value;
237  std::cout << "Increasing lod pixel threshold: " << lod_pixel_threshold_ << std::endl;
238  }
239 
240  void
242  {
243  int value = 1000;
244  if (lod_pixel_threshold_ > 50000)
245  value = 10000;
246  else if (lod_pixel_threshold_ > 10000)
247  value = 5000;
248  else if (lod_pixel_threshold_ > 1000)
249  value = 100;
250 
251  lod_pixel_threshold_ -= value;
252 
253  if (lod_pixel_threshold_ < 100)
254  lod_pixel_threshold_ = 100;
255  std::cout << "Decreasing lod pixel threshold: " << lod_pixel_threshold_ << std::endl;
256  }
257 
258  void
259  render (vtkRenderer* renderer) override;
260 
261  private:
262 
263  // Members
264  // -----------------------------------------------------------------------------
265  OctreeDiskPtr octree_;
266 
267  std::uint64_t display_depth_;
268  std::uint64_t points_loaded_;
269  std::uint64_t data_loaded_;
270 
271  Eigen::Vector3d bbox_min_, bbox_max_;
272 
273  Camera *render_camera_;
274 
275  int lod_pixel_threshold_;
276 
277  vtkSmartPointer<vtkActor> voxel_actor_;
278 
279  std::map<std::string, vtkSmartPointer<vtkActor> > cloud_actors_map_;
281 
282  public:
284 };
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