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