Point Cloud Library (PCL)  1.9.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/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 = boost::shared_ptr<OctreeDisk>;
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 
167  std::uint64_t
169  {
170  return points_loaded_;
171  }
172 
173  std::uint64_t
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 };
static std::shared_ptr< std::thread > pcd_reader_thread
static CloudDataCache cloud_data_cache
CloudDataCacheItem(std::string pcd_file, float coverage, vtkSmartPointer< vtkPolyData > cloud_data, std::size_t timestamp)
void decreaseLodPixelThreshold()
Eigen::Vector3d getBoundingBoxMax()
Eigen::Vector3d getBoundingBoxMin()
static void pcdReaderThread()
OctreeDiskPtr getOctree()
static std::mutex pcd_queue_mutex
std::uint64_t getDataLoaded() const
std::priority_queue< PcdQueueItem > PcdQueue
Definition: camera.h:19
PcdQueueItem(std::string pcd_file, float coverage)
static std::condition_variable pcd_queue_ready
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: pcl_macros.h:359
std::size_t sizeOf() const override
void setRenderCamera(Camera *render_camera)
int getLodPixelThreshold()
void increaseLodPixelThreshold()
Defines all the PCL implemented PointT point type structures.
void setDisplayVoxels(bool display_voxels)
A point structure representing Euclidean xyz coordinates.
static PcdQueue pcd_queue
vtkSmartPointer< vtkActor > getVoxelActor() const
vtkSmartPointer< vtkActorCollection > getCloudActors() const
OutofcoreCloud(std::string name, boost::filesystem::path &tree_root)
OutofcoreOctreeBaseNode Class internally representing nodes of an outofcore octree, with accessors to its data via the pcl::outofcore::OutofcoreOctreeDiskContainer class or pcl::outofcore::OutofcoreOctreeRamContainer class, whichever it is templated against.
int getDisplayDepth() const
void setLodPixelThreshold(int lod_pixel_threshold)
bool operator<(const PcdQueueItem &rhs) const
Definition: object.h:18
void setDisplayDepth(int displayDepth)
This code defines the octree used for point storage at Urban Robotics.
Definition: octree_base.h:150
void render(vtkRenderer *renderer) override
std::uint64_t getPointsLoaded() const
Defines all the PCL and non-PCL macros used.
void updateVoxelData()
static std::mutex cloud_data_cache_mutex