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