Point Cloud Library (PCL)  1.11.1
octree_ram_container.h
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$
38  */
39 
40 #pragma once
41 
42 // C++
43 #include <mutex>
44 #include <random>
45 #include <vector>
46 
47 #include <pcl/outofcore/boost.h>
48 #include <pcl/outofcore/octree_abstract_node_container.h>
49 
50 namespace pcl
51 {
52  namespace outofcore
53  {
54  /** \class OutofcoreOctreeRamContainer
55  * \brief Storage container class which the outofcore octree base is templated against
56  * \note Code was adapted from the Urban Robotics out of core octree implementation.
57  * Contact Jacob Schloss <jacob.schloss@urbanrobotics.net> with any questions.
58  * http://www.urbanrobotics.net/
59  *
60  * \ingroup outofcore
61  * \author Jacob Schloss (jacob.scloss@urbanrobotics.net)
62  */
63  template<typename PointT>
65  {
66  public:
68 
69  /** \brief empty constructor (with a path parameter?)
70  */
71  OutofcoreOctreeRamContainer (const boost::filesystem::path&) : container_ () { }
72 
73  /** \brief inserts count number of points into container; uses the container_ type's insert function
74  * \param[in] start - address of first point in array
75  * \param[in] count - the maximum offset from start of points inserted
76  */
77  void
78  insertRange (const PointT* start, const std::uint64_t count);
79 
80  /** \brief inserts count points into container
81  * \param[in] start - address of first point in array
82  * \param[in] count - the maximum offset from start of points inserted
83  */
84  void
85  insertRange (const PointT* const * start, const std::uint64_t count);
86 
87  void
89  {
90  PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeRamContainer] Inserting eigen-aligned point vectors is not implemented using the ram containers\n");
91  //insertRange (&(p.begin ()), p.size ());
92  }
93 
94  void
96  {
97  PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeRamContainer] Inserting eigen-aligned point vectors is not implemented using the ram containers\n");
98  }
99 
100  /** \brief
101  * \param[in] start Index of first point to return from container
102  * \param[in] count Offset (start + count) of the last point to return from container
103  * \param[out] v Array of points read from the input range
104  */
105  void
106  readRange (const std::uint64_t start, const std::uint64_t count, AlignedPointTVector &v);
107 
108  /** \brief grab percent*count random points. points are NOT
109  * guaranteed to be unique (could have multiple identical points!)
110  *
111  * \param[in] start Index of first point in range to subsample
112  * \param[in] count Offset (start+count) of last point in range to subsample
113  * \param[in] percent Percentage of range to return
114  * \param[out] v Vector with percent*count uniformly random sampled
115  * points from given input rangerange
116  */
117  void
118  readRangeSubSample (const std::uint64_t start, const std::uint64_t count, const double percent, AlignedPointTVector &v);
119 
120  /** \brief returns the size of the vector of points stored in this class */
121  inline std::uint64_t
122  size () const
123  {
124  return container_.size ();
125  }
126 
127  inline bool
128  empty () const
129  {
130  return container_.empty ();
131  }
132 
133 
134  /** \brief clears the vector of points in this class */
135  inline void
136  clear ()
137  {
138  //clear the elements in the vector of points
139  container_.clear ();
140  }
141 
142  /** \brief Writes ascii x,y,z point data to path.string().c_str()
143  * \param path The path/filename destination of the ascii xyz data
144  */
145  void
146  convertToXYZ (const boost::filesystem::path &path);
147 
148  inline PointT
150  {
151  assert ( index < container_.size () );
152  return ( container_[index] );
153  }
154 
155 
156  protected:
157  //no copy construction
159 
162 
163  //the actual container
164  //std::deque<PointT> container;
165 
166  /** \brief linear container to hold the points */
168 
169  static std::mutex rng_mutex_;
170  static std::mt19937 rng_;
171  };
172  }
173 }
pcl
Definition: convolution.h:46
pcl::outofcore::OutofcoreOctreeRamContainer::OutofcoreOctreeRamContainer
OutofcoreOctreeRamContainer(const OutofcoreOctreeRamContainer &)
Definition: octree_ram_container.h:158
pcl::outofcore::OutofcoreOctreeRamContainer::rng_mutex_
static std::mutex rng_mutex_
Definition: octree_ram_container.h:169
pcl::outofcore::OutofcoreOctreeRamContainer::readRangeSubSample
void readRangeSubSample(const std::uint64_t start, const std::uint64_t count, const double percent, AlignedPointTVector &v)
grab percent*count random points.
Definition: octree_ram_container.hpp:118
pcl::outofcore::OutofcoreOctreeRamContainer::size
std::uint64_t size() const
returns the size of the vector of points stored in this class
Definition: octree_ram_container.h:122
pcl::outofcore::OutofcoreOctreeRamContainer::container_
AlignedPointTVector container_
linear container to hold the points
Definition: octree_ram_container.h:167
pcl::outofcore::OutofcoreAbstractNodeContainer::AlignedPointTVector
std::vector< PointT, Eigen::aligned_allocator< PointT > > AlignedPointTVector
Definition: octree_abstract_node_container.h:56
pcl::outofcore::OutofcoreOctreeRamContainer
Storage container class which the outofcore octree base is templated against.
Definition: octree_ram_container.h:65
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:629
pcl::outofcore::OutofcoreOctreeRamContainer::empty
bool empty() const
Definition: octree_ram_container.h:128
pcl::outofcore::OutofcoreOctreeRamContainer::OutofcoreOctreeRamContainer
OutofcoreOctreeRamContainer(const boost::filesystem::path &)
empty constructor (with a path parameter?)
Definition: octree_ram_container.h:71
pcl::outofcore::OutofcoreOctreeRamContainer::clear
void clear()
clears the vector of points in this class
Definition: octree_ram_container.h:136
pcl::outofcore::OutofcoreOctreeRamContainer::insertRange
void insertRange(const PointT *start, const std::uint64_t count)
inserts count number of points into container; uses the container_ type's insert function
Definition: octree_ram_container.hpp:86
pcl::outofcore::OutofcoreOctreeRamContainer::rng_
static std::mt19937 rng_
Definition: octree_ram_container.h:170
pcl::outofcore::OutofcoreOctreeRamContainer::AlignedPointTVector
typename OutofcoreAbstractNodeContainer< PointT >::AlignedPointTVector AlignedPointTVector
Definition: octree_ram_container.h:67
pcl::outofcore::OutofcoreOctreeRamContainer::operator[]
PointT operator[](std::uint64_t index) const
Definition: octree_ram_container.h:149
pcl::outofcore::OutofcoreAbstractNodeContainer
Definition: octree_abstract_node_container.h:53
pcl::outofcore::OutofcoreOctreeRamContainer::convertToXYZ
void convertToXYZ(const boost::filesystem::path &path)
Writes ascii x,y,z point data to path.string().c_str()
Definition: octree_ram_container.hpp:60
pcl::outofcore::OutofcoreOctreeRamContainer::insertRange
void insertRange(const AlignedPointTVector &)
Definition: octree_ram_container.h:95
pcl::outofcore::OutofcoreOctreeRamContainer::readRange
void readRange(const std::uint64_t start, const std::uint64_t count, AlignedPointTVector &v)
Definition: octree_ram_container.hpp:108
pcl::outofcore::OutofcoreOctreeRamContainer::insertRange
void insertRange(AlignedPointTVector &)
Definition: octree_ram_container.h:88
pcl::outofcore::OutofcoreOctreeRamContainer::operator=
OutofcoreOctreeRamContainer & operator=(const OutofcoreOctreeRamContainer &)
Definition: octree_ram_container.h:161
pcl::uint64_t
std::uint64_t uint64_t
Definition: types.h:60