Point Cloud Library (PCL)  1.14.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
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_{1};
269  std::uint64_t points_loaded_{0};
270  std::uint64_t data_loaded_{0};
271 
272  Eigen::Vector3d bbox_min_, bbox_max_;
273 
274  Camera *render_camera_{nullptr};
275 
276  int lod_pixel_threshold_{10000};
277 
278  vtkSmartPointer<vtkActor> voxel_actor_;
279 
280  std::map<std::string, vtkSmartPointer<vtkActor> > cloud_actors_map_;
282 
283  public:
285 };
Definition: camera.h:21
vtkSmartPointer< vtkPolyData > item
Definition: lru_cache.hpp:25
Definition: object.h:19
CloudDataCacheItem(std::string pcd_file, float coverage, vtkSmartPointer< vtkPolyData > cloud_data, std::size_t timestamp)
std::size_t sizeOf() const override
static std::condition_variable pcd_queue_ready
static std::mutex pcd_queue_mutex
void decreaseLodPixelThreshold()
void setLodPixelThreshold(int lod_pixel_threshold)
Eigen::Vector3d getBoundingBoxMax()
static std::mutex cloud_data_cache_mutex
int getLodPixelThreshold() const
void setDisplayVoxels(bool display_voxels)
void render(vtkRenderer *renderer) override
void increaseLodPixelThreshold()
static void pcdReaderThread()
std::uint64_t getPointsLoaded() const
std::uint64_t getDataLoaded() const
static std::shared_ptr< std::thread > pcd_reader_thread
void setRenderCamera(Camera *render_camera)
static CloudDataCache cloud_data_cache
OctreeDiskPtr getOctree()
int getDisplayDepth() const
std::priority_queue< PcdQueueItem > PcdQueue
vtkSmartPointer< vtkActorCollection > getCloudActors() const
static PcdQueue pcd_queue
Eigen::Vector3d getBoundingBoxMin()
OutofcoreCloud(std::string name, boost::filesystem::path &tree_root)
vtkSmartPointer< vtkActor > getVoxelActor() const
void setDisplayDepth(int displayDepth)
void updateVoxelData()
This code defines the octree used for point storage at Urban Robotics.
Definition: octree_base.h:151
shared_ptr< OutofcoreOctreeBase< ContainerT, PointT > > Ptr
Definition: octree_base.h:178
OutofcoreOctreeBaseNode Class internally representing nodes of an outofcore octree,...
Defines all the PCL implemented PointT point type structures.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Defines functions, macros and traits for allocating and using memory.
Defines all the PCL and non-PCL macros used.
bool operator<(const PcdQueueItem &rhs) const
PcdQueueItem(std::string pcd_file, float coverage)
A point structure representing Euclidean xyz coordinates.