Point Cloud Library (PCL)  1.8.1
octree_disk_container.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, Willow Garage, Inc.
6  * Copyright (c) 2012, Urban Robotics, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of Willow Garage, Inc. nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id: octree_disk_container.hpp 6927M 2012-08-24 17:01:57Z (local) $
38  */
39 
40 #ifndef PCL_OUTOFCORE_OCTREE_DISK_CONTAINER_IMPL_H_
41 #define PCL_OUTOFCORE_OCTREE_DISK_CONTAINER_IMPL_H_
42 
43 // C++
44 #include <sstream>
45 #include <cassert>
46 #include <ctime>
47 
48 // Boost
49 #include <pcl/outofcore/boost.h>
50 
51 // PCL
52 #include <pcl/io/pcd_io.h>
53 #include <pcl/point_types.h>
54 #include <pcl/PCLPointCloud2.h>
55 
56 // PCL (Urban Robotics)
57 #include <pcl/outofcore/octree_disk_container.h>
58 
59 //allows operation on POSIX
60 #if !defined WIN32
61 #define _fseeki64 fseeko
62 #elif defined __MINGW32__
63 #define _fseeki64 fseeko64
64 #endif
65 
66 namespace pcl
67 {
68  namespace outofcore
69  {
70  template<typename PointT>
71  boost::mutex OutofcoreOctreeDiskContainer<PointT>::rng_mutex_;
72 
73  template<typename PointT> boost::mt19937
74  OutofcoreOctreeDiskContainer<PointT>::rand_gen_ (static_cast<unsigned int> (std::time(NULL)));
75 
76  template<typename PointT>
77  boost::uuids::basic_random_generator<boost::mt19937> OutofcoreOctreeDiskContainer<PointT>::uuid_gen_ (&rand_gen_);
78 
79  template<typename PointT>
80  const uint64_t OutofcoreOctreeDiskContainer<PointT>::READ_BLOCK_SIZE_ = static_cast<uint64_t> (2e12);
81  template<typename PointT>
82  const uint64_t OutofcoreOctreeDiskContainer<PointT>::WRITE_BUFF_MAX_ = static_cast<uint64_t> (2e12);
83 
84  template<typename PointT> void
86  {
87  boost::uuids::uuid u;
88  {
89  boost::mutex::scoped_lock lock (rng_mutex_);
90  u = uuid_gen_ ();
91  }
92 
93  std::stringstream ss;
94  ss << u;
95  s = ss.str ();
96  }
97  ////////////////////////////////////////////////////////////////////////////////
98 
99  template<typename PointT>
101  : disk_storage_filename_ ()
102  , filelen_ (0)
103  , writebuff_ (0)
104  {
105  std::string temp;
106  getRandomUUIDString (temp);
107  disk_storage_filename_ = boost::shared_ptr<std::string> (new std::string (temp));
108  filelen_ = 0;
109  }
110  ////////////////////////////////////////////////////////////////////////////////
111 
112  template<typename PointT>
114  : disk_storage_filename_ ()
115  , filelen_ (0)
116  , writebuff_ (0)
117  {
118  if (boost::filesystem::exists (path))
119  {
120  if (boost::filesystem::is_directory (path))
121  {
122  std::string uuid;
123  getRandomUUIDString (uuid);
124  boost::filesystem::path filename (uuid);
125  boost::filesystem::path file = path / filename;
126 
127  disk_storage_filename_ = boost::shared_ptr<std::string> (new std::string (file.string ()));
128  }
129  else
130  {
131  uint64_t len = boost::filesystem::file_size (path);
132 
133  disk_storage_filename_ = boost::shared_ptr<std::string> (new std::string (path.string ()));
134 
135  filelen_ = len / sizeof(PointT);
136 
137  pcl::PCLPointCloud2 cloud_info;
138  Eigen::Vector4f origin;
139  Eigen::Quaternionf orientation;
140  int pcd_version;
141  int data_type;
142  unsigned int data_index;
143 
144  //read the header of the pcd file and get the number of points
145  PCDReader reader;
146  reader.readHeader (*disk_storage_filename_, cloud_info, origin, orientation, pcd_version, data_type, data_index, 0);
147 
148  filelen_ = cloud_info.width * cloud_info.height;
149  }
150  }
151  else //path doesn't exist
152  {
153  disk_storage_filename_ = boost::shared_ptr<std::string> (new std::string (path.string ()));
154  filelen_ = 0;
155  }
156  }
157  ////////////////////////////////////////////////////////////////////////////////
158 
159  template<typename PointT>
161  {
162  flushWritebuff (true);
163  }
164  ////////////////////////////////////////////////////////////////////////////////
165 
166  template<typename PointT> void
167  OutofcoreOctreeDiskContainer<PointT>::flushWritebuff (const bool force_cache_dealloc)
168  {
169  if (writebuff_.size () > 0)
170  {
171  //construct the point cloud for this node
173 
174  cloud->width = static_cast<uint32_t> (writebuff_.size ());
175  cloud->height = 1;
176 
177  cloud->points = writebuff_;
178 
179  //write data to a pcd file
180  pcl::PCDWriter writer;
181 
182 
183  PCL_WARN ("[pcl::outofcore::OutofcoreOctreeDiskContainer::%s] Flushing writebuffer in a dangerous way to file %s. This might overwrite data in destination file\n", __FUNCTION__, disk_storage_filename_->c_str ());
184 
185  // Write ascii for now to debug
186  int res = writer.writeBinaryCompressed (*disk_storage_filename_, *cloud);
187  (void)res;
188  assert (res == 0);
189  if (force_cache_dealloc)
190  {
191  writebuff_.resize (0);
192  }
193  }
194  }
195  ////////////////////////////////////////////////////////////////////////////////
196 
197  template<typename PointT> PointT
199  {
200  PCL_THROW_EXCEPTION (PCLException, "[pcl::outofcore::OutofcoreOctreeDiskContainer] Not implemented for use with PCL library\n");
201 
202  //if the index is on disk
203  if (idx < filelen_)
204  {
205 
206  PointT temp;
207  //open our file
208  FILE* f = fopen (disk_storage_filename_->c_str (), "rb");
209  assert (f != NULL);
210 
211  //seek the right length;
212  int seekret = _fseeki64 (f, idx * sizeof(PointT), SEEK_SET);
213  (void)seekret;
214  assert (seekret == 0);
215 
216  size_t readlen = fread (&temp, 1, sizeof(PointT), f);
217  (void)readlen;
218  assert (readlen == sizeof (PointT));
219 
220  int res = fclose (f);
221  (void)res;
222  assert (res == 0);
223 
224  return (temp);
225  }
226  //otherwise if the index is still in the write buffer
227  if (idx < (filelen_ + writebuff_.size ()))
228  {
229  idx -= filelen_;
230  return (writebuff_[idx]);
231  }
232 
233  //else, throw out of range exception
234  PCL_THROW_EXCEPTION (PCLException, "[pcl::outofcore:OutofcoreOctreeDiskContainer] Index is out of range");
235  }
236 
237  ////////////////////////////////////////////////////////////////////////////////
238  template<typename PointT> void
239  OutofcoreOctreeDiskContainer<PointT>::readRange (const uint64_t start, const uint64_t count, AlignedPointTVector& dst)
240  {
241  if (count == 0)
242  {
243  return;
244  }
245 
246  if ((start + count) > size ())
247  {
248  PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeDiskContainer::%s] Indicies out of range; start + count exceeds the size of the stored points\n", __FUNCTION__);
249  PCL_THROW_EXCEPTION (PCLException, "[pcl::outofcore::OutofcoreOctreeDiskContainer] Outofcore Octree Exception: Read indices exceed range");
250  }
251 
252  pcl::PCDReader reader;
254 
255  int res = reader.read (*disk_storage_filename_, *cloud);
256  (void)res;
257  assert (res == 0);
258 
259  for (size_t i=0; i < cloud->points.size (); i++)
260  dst.push_back (cloud->points[i]);
261 
262  }
263  ////////////////////////////////////////////////////////////////////////////////
264 
265  template<typename PointT> void
266  OutofcoreOctreeDiskContainer<PointT>::readRangeSubSample_bernoulli (const uint64_t start, const uint64_t count, const double percent, AlignedPointTVector& dst)
267  {
268  if (count == 0)
269  {
270  return;
271  }
272 
273  dst.clear ();
274 
275  uint64_t filestart = 0;
276  uint64_t filecount = 0;
277 
278  int64_t buffstart = -1;
279  int64_t buffcount = -1;
280 
281  if (start < filelen_)
282  {
283  filestart = start;
284  }
285 
286  if ((start + count) <= filelen_)
287  {
288  filecount = count;
289  }
290  else
291  {
292  filecount = filelen_ - start;
293 
294  buffstart = 0;
295  buffcount = count - filecount;
296  }
297 
298  if (buffcount > 0)
299  {
300  {
301  boost::mutex::scoped_lock lock (rng_mutex_);
302  boost::bernoulli_distribution<double> buffdist (percent);
303  boost::variate_generator<boost::mt19937&, boost::bernoulli_distribution<double> > buffcoin (rand_gen_, buffdist);
304 
305  for (size_t i = buffstart; i < static_cast<uint64_t> (buffcount); i++)
306  {
307  if (buffcoin ())
308  {
309  dst.push_back (writebuff_[i]);
310  }
311  }
312  }
313  }
314 
315  if (filecount > 0)
316  {
317  //pregen and then sort the offsets to reduce the amount of seek
318  std::vector < uint64_t > offsets;
319  {
320  boost::mutex::scoped_lock lock (rng_mutex_);
321 
322  boost::bernoulli_distribution<double> filedist (percent);
323  boost::variate_generator<boost::mt19937&, boost::bernoulli_distribution<double> > filecoin (rand_gen_, filedist);
324  for (uint64_t i = filestart; i < (filestart + filecount); i++)
325  {
326  if (filecoin ())
327  {
328  offsets.push_back (i);
329  }
330  }
331  }
332  std::sort (offsets.begin (), offsets.end ());
333 
334  FILE* f = fopen (disk_storage_filename_->c_str (), "rb");
335  assert (f != NULL);
336  PointT p;
337  char* loc = reinterpret_cast<char*> (&p);
338 
339  uint64_t filesamp = offsets.size ();
340  for (uint64_t i = 0; i < filesamp; i++)
341  {
342  int seekret = _fseeki64 (f, offsets[i] * static_cast<uint64_t> (sizeof(PointT)), SEEK_SET);
343  (void)seekret;
344  assert (seekret == 0);
345  size_t readlen = fread (loc, sizeof(PointT), 1, f);
346  (void)readlen;
347  assert (readlen == 1);
348 
349  dst.push_back (p);
350  }
351 
352  fclose (f);
353  }
354  }
355  ////////////////////////////////////////////////////////////////////////////////
356 
357 //change this to use a weighted coin flip, to allow sparse sampling of small clouds (eg the bernoulli above)
358  template<typename PointT> void
359  OutofcoreOctreeDiskContainer<PointT>::readRangeSubSample (const uint64_t start, const uint64_t count, const double percent, AlignedPointTVector& dst)
360  {
361  if (count == 0)
362  {
363  return;
364  }
365 
366  dst.clear ();
367 
368  uint64_t filestart = 0;
369  uint64_t filecount = 0;
370 
371  int64_t buffcount = -1;
372 
373  if (start < filelen_)
374  {
375  filestart = start;
376  }
377 
378  if ((start + count) <= filelen_)
379  {
380  filecount = count;
381  }
382  else
383  {
384  filecount = filelen_ - start;
385  buffcount = count - filecount;
386  }
387 
388  uint64_t filesamp = static_cast<uint64_t> (percent * static_cast<double> (filecount));
389 
390  uint64_t buffsamp = (buffcount > 0) ? (static_cast<uint64_t > (percent * static_cast<double> (buffcount))) : 0;
391 
392  if ((filesamp == 0) && (buffsamp == 0) && (size () > 0))
393  {
394  //std::cerr << "would not add points to LOD, falling back to bernoulli";
395  readRangeSubSample_bernoulli (start, count, percent, dst);
396  return;
397  }
398 
399  if (buffcount > 0)
400  {
401  {
402  boost::mutex::scoped_lock lock (rng_mutex_);
403 
404  boost::uniform_int < uint64_t > buffdist (0, buffcount - 1);
405  boost::variate_generator<boost::mt19937&, boost::uniform_int<uint64_t> > buffdie (rand_gen_, buffdist);
406 
407  for (uint64_t i = 0; i < buffsamp; i++)
408  {
409  uint64_t buffstart = buffdie ();
410  dst.push_back (writebuff_[buffstart]);
411  }
412  }
413  }
414 
415  if (filesamp > 0)
416  {
417  //pregen and then sort the offsets to reduce the amount of seek
418  std::vector < uint64_t > offsets;
419  {
420  boost::mutex::scoped_lock lock (rng_mutex_);
421 
422  offsets.resize (filesamp);
423  boost::uniform_int < uint64_t > filedist (filestart, filestart + filecount - 1);
424  boost::variate_generator<boost::mt19937&, boost::uniform_int<uint64_t> > filedie (rand_gen_, filedist);
425  for (uint64_t i = 0; i < filesamp; i++)
426  {
427  uint64_t _filestart = filedie ();
428  offsets[i] = _filestart;
429  }
430  }
431  std::sort (offsets.begin (), offsets.end ());
432 
433  FILE* f = fopen (disk_storage_filename_->c_str (), "rb");
434  assert (f != NULL);
435  PointT p;
436  char* loc = reinterpret_cast<char*> (&p);
437  for (uint64_t i = 0; i < filesamp; i++)
438  {
439  int seekret = _fseeki64 (f, offsets[i] * static_cast<uint64_t> (sizeof(PointT)), SEEK_SET);
440  (void)seekret;
441  assert (seekret == 0);
442  size_t readlen = fread (loc, sizeof(PointT), 1, f);
443  (void)readlen;
444  assert (readlen == 1);
445 
446  dst.push_back (p);
447  }
448  int res = fclose (f);
449  (void)res;
450  assert (res == 0);
451  }
452  }
453  ////////////////////////////////////////////////////////////////////////////////
454 
455  template<typename PointT> void
457  {
458  writebuff_.push_back (p);
459  if (writebuff_.size () > WRITE_BUFF_MAX_)
460  {
461  flushWritebuff (false);
462  }
463  }
464  ////////////////////////////////////////////////////////////////////////////////
465 
466  template<typename PointT> void
468  {
469  const uint64_t count = src.size ();
470 
471  typename pcl::PointCloud<PointT>::Ptr tmp_cloud (new pcl::PointCloud<PointT> ());
472 
473  // If there's a pcd file with data
474  if (boost::filesystem::exists (*disk_storage_filename_))
475  {
476  // Open the existing file
477  pcl::PCDReader reader;
478  int res = reader.read (*disk_storage_filename_, *tmp_cloud);
479  (void)res;
480  assert (res == 0);
481  }
482  // Otherwise create the point cloud which will be saved to the pcd file for the first time
483  else
484  {
485  tmp_cloud->width = static_cast<uint32_t> (count + writebuff_.size ());
486  tmp_cloud->height = 1;
487  }
488 
489  for (size_t i = 0; i < src.size (); i++)
490  tmp_cloud->points.push_back (src[i]);
491 
492  // If there are any points in the write cache writebuff_, a different write cache than this one, concatenate
493  for (size_t i = 0; i < writebuff_.size (); i++)
494  {
495  tmp_cloud->points.push_back (writebuff_[i]);
496  }
497 
498  //assume unorganized point cloud
499  tmp_cloud->width = static_cast<uint32_t> (tmp_cloud->points.size ());
500 
501  //save and close
502  PCDWriter writer;
503 
504  int res = writer.writeBinaryCompressed (*disk_storage_filename_, *tmp_cloud);
505  (void)res;
506  assert (res == 0);
507  }
508 
509  ////////////////////////////////////////////////////////////////////////////////
510 
511  template<typename PointT> void
513  {
515 
516  //if there's a pcd file with data associated with this node, read the data, concatenate, and resave
517  if (boost::filesystem::exists (*disk_storage_filename_))
518  {
519  //open the existing file
520  pcl::PCDReader reader;
521  int res = reader.read (*disk_storage_filename_, *tmp_cloud);
522  (void)res;
523  assert (res == 0);
524  pcl::PCDWriter writer;
525  PCL_DEBUG ("[pcl::outofcore::OutofcoreOctreeDiskContainer::%s] Concatenating point cloud from %s to new cloud\n", __FUNCTION__, disk_storage_filename_->c_str ());
526 
527  size_t previous_num_pts = tmp_cloud->width*tmp_cloud->height + input_cloud->width*input_cloud->height;
528  //Concatenate will fail if the fields in input_cloud do not match the fields in the PCD file.
529  pcl::concatenatePointCloud (*tmp_cloud, *input_cloud, *tmp_cloud);
530  size_t res_pts = tmp_cloud->width*tmp_cloud->height;
531 
532  (void)previous_num_pts;
533  (void)res_pts;
534 
535  assert (previous_num_pts == res_pts);
536 
537  writer.writeBinaryCompressed (*disk_storage_filename_, *tmp_cloud);
538 
539  }
540  else //otherwise create the point cloud which will be saved to the pcd file for the first time
541  {
542  pcl::PCDWriter writer;
543  int res = writer.writeBinaryCompressed (*disk_storage_filename_, *input_cloud);
544  (void)res;
545  assert (res == 0);
546  }
547 
548  }
549 
550  ////////////////////////////////////////////////////////////////////////////////
551 
552  template<typename PointT> void
554  {
555  pcl::PCDReader reader;
556 
557  Eigen::Vector4f origin;
558  Eigen::Quaternionf orientation;
559  int pcd_version;
560 
561  if (boost::filesystem::exists (*disk_storage_filename_))
562  {
563 // PCL_INFO ("[pcl::outofcore::OutofcoreOctreeDiskContainer::%s] Reading points from disk from %s.\n", __FUNCTION__ , disk_storage_filename_->c_str ());
564  int res = reader.read (*disk_storage_filename_, *dst, origin, orientation, pcd_version);
565  (void)res;
566  assert (res != -1);
567  }
568  else
569  {
570  PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeDiskContainer::%s] File %s does not exist in node.\n", __FUNCTION__, disk_storage_filename_->c_str ());
571  }
572  }
573 
574  ////////////////////////////////////////////////////////////////////////////////
575 
576  template<typename PointT> int
578  {
579  pcl::PCLPointCloud2::Ptr temp_output_cloud (new pcl::PCLPointCloud2 ());
580 
581  if (boost::filesystem::exists (*disk_storage_filename_))
582  {
583 // PCL_INFO ("[pcl::outofcore::OutofcoreOctreeDiskContainer::%s] Reading points from disk from %s.\n", __FUNCTION__ , disk_storage_filename_->c_str ());
584  int res = pcl::io::loadPCDFile (*disk_storage_filename_, *temp_output_cloud);
585  (void)res;
586  assert (res != -1);
587  if(res == -1)
588  return (-1);
589  }
590  else
591  {
592  PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeDiskContainer::%s] File %s does not exist in node.\n", __FUNCTION__, disk_storage_filename_->c_str ());
593  return (-1);
594  }
595 
596  if(output_cloud.get () != 0)
597  {
598  pcl::concatenatePointCloud (*output_cloud, *temp_output_cloud, *output_cloud);
599  }
600  else
601  {
602  output_cloud = temp_output_cloud;
603  }
604  return (0);
605  }
606 
607  ////////////////////////////////////////////////////////////////////////////////
608 
609  template<typename PointT> void
610  OutofcoreOctreeDiskContainer<PointT>::insertRange (const PointT* const * start, const uint64_t count)
611  {
612 // PCL_THROW_EXCEPTION (PCLException, "[pcl::outofcore::OutofcoreOctreeDiskContainer] Deprecated\n");
613  //copy the handles to a continuous block
614  PointT* arr = new PointT[count];
615 
616  //copy from start of array, element by element
617  for (size_t i = 0; i < count; i++)
618  {
619  arr[i] = *(start[i]);
620  }
621 
622  insertRange (arr, count);
623  delete[] arr;
624  }
625 
626  ////////////////////////////////////////////////////////////////////////////////
627 
628  template<typename PointT> void
629  OutofcoreOctreeDiskContainer<PointT>::insertRange (const PointT* start, const uint64_t count)
630  {
631  typename pcl::PointCloud<PointT>::Ptr tmp_cloud (new pcl::PointCloud<PointT> ());
632 
633  // If there's a pcd file with data, read it in from disk for appending
634  if (boost::filesystem::exists (*disk_storage_filename_))
635  {
636  pcl::PCDReader reader;
637  // Open it
638  int res = reader.read (disk_storage_filename_->c_str (), *tmp_cloud);
639  (void)res;
640  assert (res == 0);
641  }
642  else //otherwise create the pcd file
643  {
644  tmp_cloud->width = static_cast<uint32_t> (count) + static_cast<uint32_t> (writebuff_.size ());
645  tmp_cloud->height = 1;
646  }
647 
648  // Add any points in the cache
649  for (size_t i = 0; i < writebuff_.size (); i++)
650  {
651  tmp_cloud->points.push_back (writebuff_ [i]);
652  }
653 
654  //add the new points passed with this function
655  for (size_t i = 0; i < count; i++)
656  {
657  tmp_cloud->points.push_back (*(start + i));
658  }
659 
660  tmp_cloud->width = static_cast<uint32_t> (tmp_cloud->points.size ());
661  tmp_cloud->height = 1;
662 
663  //save and close
664  PCDWriter writer;
665 
666  int res = writer.writeBinaryCompressed (*disk_storage_filename_, *tmp_cloud);
667  (void)res;
668  assert (res == 0);
669  }
670  ////////////////////////////////////////////////////////////////////////////////
671 
672  template<typename PointT> boost::uint64_t
674  {
675  pcl::PCLPointCloud2 cloud_info;
676  Eigen::Vector4f origin;
677  Eigen::Quaternionf orientation;
678  int pcd_version;
679  int data_type;
680  unsigned int data_index;
681 
682  //read the header of the pcd file and get the number of points
683  PCDReader reader;
684  reader.readHeader (*disk_storage_filename_, cloud_info, origin, orientation, pcd_version, data_type, data_index, 0);
685 
686  boost::uint64_t total_points = cloud_info.width * cloud_info.height + writebuff_.size ();
687 
688  return (total_points);
689  }
690  ////////////////////////////////////////////////////////////////////////////////
691 
692  }//namespace outofcore
693 }//namespace pcl
694 
695 #endif //PCL_OUTOFCORE_OCTREE_DISK_CONTAINER_IMPL_H_
void readRangeSubSample(const uint64_t start, const uint64_t count, const double percent, AlignedPointTVector &dst)
grab percent*count random points.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:410
A base class for all pcl exceptions which inherits from std::runtime_error.
Definition: exceptions.h:64
int writeBinaryCompressed(const std::string &file_name, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity())
Save point cloud data to a PCD file containing n-D points, in BINARY_COMPRESSED format.
void insertRange(const AlignedPointTVector &src)
Inserts a vector of points into the disk data structure.
static void getRandomUUIDString(std::string &s)
Generate a universally unique identifier (UUID)
std::string & path()
Returns this objects path name.
void readRange(const uint64_t start, const uint64_t count, AlignedPointTVector &dst)
Reads count points into memory from the disk container.
boost::shared_ptr< ::pcl::PCLPointCloud2 > Ptr
uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:415
Class responsible for serialization and deserialization of out of core point data.
PointT operator[](uint64_t idx) const
provides random access to points based on a linear index
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:413
int readHeader(const std::string &file_name, pcl::PCLPointCloud2 &cloud, Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &pcd_version, int &data_type, unsigned int &data_idx, const int offset=0)
Read a point cloud data header from a PCD file.
~OutofcoreOctreeDiskContainer()
flushes write buffer, then frees memory
Defines all the PCL implemented PointT point type structures.
pcl::uint32_t width
void push_back(const PointT &p)
Adds a single point to the buffer to be written to disk when the buffer grows sufficiently large,...
OutofcoreOctreeDiskContainer()
Empty constructor creates disk container and sets filename from random uuid string.
PointCloud represents the base class in PCL for storing collections of 3D points.
boost::uuids::basic_random_generator< boost::mt19937 > OutofcoreOctreeDiskContainer< PointT >::uuid_gen_ & rand_gen_
void readRangeSubSample_bernoulli(const uint64_t start, const uint64_t count, const double percent, AlignedPointTVector &dst)
Use bernoulli trials to select points.
int loadPCDFile(const std::string &file_name, pcl::PCLPointCloud2 &cloud)
Load a PCD v.6 file into a templated PointCloud type.
Definition: pcd_io.h:512
pcl::uint32_t height
int read(pcl::PCLPointCloud2::Ptr &output_cloud)
Reads the entire point contents from disk into output_cloud.
OutofcoreAbstractNodeContainer< PointT >::AlignedPointTVector AlignedPointTVector
PCL_EXPORTS bool concatenatePointCloud(const pcl::PCLPointCloud2 &cloud1, const pcl::PCLPointCloud2 &cloud2, pcl::PCLPointCloud2 &cloud_out)
Concatenate two pcl::PCLPointCloud2.
Point Cloud Data (PCD) file format reader.
Definition: pcd_io.h:52
boost::uint64_t getDataSize() const
Returns the number of points in the PCD file by reading the PCD header.
A point structure representing Euclidean xyz coordinates, and the RGB color.
Point Cloud Data (PCD) file format writer.
Definition: pcd_io.h:224
int read(const std::string &file_name, pcl::PCLPointCloud2 &cloud, Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &pcd_version, const int offset=0)
Read a point cloud data from a PCD file and store it into a pcl/PCLPointCloud2.