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