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