Point Cloud Library (PCL)  1.7.0
/tmp/buildd/pcl-1.7-1.7.0/outofcore/include/pcl/outofcore/octree_ram_container.h
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2012, Willow Garage, Inc.
00006  *  Copyright (c) 2012, Urban Robotics, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of Willow Garage, Inc. nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  *  $Id$
00038  */
00039 
00040 #ifndef PCL_OUTOFCORE_OCTREE_RAM_CONTAINER_H_
00041 #define PCL_OUTOFCORE_OCTREE_RAM_CONTAINER_H_
00042 
00043 // C++
00044 #include <vector>
00045 
00046 #include <pcl/outofcore/boost.h>
00047 #include <pcl/outofcore/octree_abstract_node_container.h>
00048 
00049 namespace pcl
00050 {
00051   namespace outofcore
00052   {
00053     /** \class OutofcoreOctreeRamContainer
00054      *  \brief Storage container class which the outofcore octree base is templated against
00055      *  \note Code was adapted from the Urban Robotics out of core octree implementation. 
00056      *  Contact Jacob Schloss <jacob.schloss@urbanrobotics.net> with any questions. 
00057      *  http://www.urbanrobotics.net/
00058      * 
00059      *  \ingroup outofcore
00060      *  \author Jacob Schloss (jacob.scloss@urbanrobotics.net)
00061      */
00062     template<typename PointT>
00063     class OutofcoreOctreeRamContainer : public OutofcoreAbstractNodeContainer<PointT>
00064     {
00065       public:
00066         typedef typename OutofcoreAbstractNodeContainer<PointT>::AlignedPointTVector AlignedPointTVector;
00067 
00068         /** \brief empty contructor (with a path parameter?)
00069           */
00070         OutofcoreOctreeRamContainer (const boost::filesystem::path&) : container_ () { }
00071         
00072         /** \brief inserts count number of points into container; uses the container_ type's insert function
00073           * \param[in] start - address of first point in array
00074           * \param[in] count - the maximum offset from start of points inserted 
00075           */
00076         void
00077         insertRange (const PointT* start, const uint64_t count);
00078 
00079         /** \brief inserts count points into container 
00080           * \param[in] start - address of first point in array
00081           * \param[in] count - the maximum offset from start of points inserted 
00082           */
00083         void
00084         insertRange (const PointT* const * start, const uint64_t count);
00085 
00086         void
00087         insertRange (AlignedPointTVector &p)
00088         {
00089           PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeRamContainer] Inserting eigen-aligned point vectors is not implemented using the ram containers\n");
00090           //insertRange (&(p.begin ()), p.size ());
00091         }
00092 
00093         void
00094         insertRange (const AlignedPointTVector &p)
00095         {
00096           PCL_ERROR ("[pcl::outofcore::OutofcoreOctreeRamContainer] Inserting eigen-aligned point vectors is not implemented using the ram containers\n");
00097         }
00098         
00099         /** \brief 
00100           * \param[in] start Index of first point to return from container
00101           * \param[in] count Offset (start + count) of the last point to return from container
00102           * \param[out] v Array of points read from the input range
00103           */
00104         void
00105         readRange (const uint64_t start, const uint64_t count, AlignedPointTVector &v);
00106 
00107         /** \brief grab percent*count random points. points are NOT
00108           *   guaranteed to be unique (could have multiple identical points!)
00109           *
00110           * \param[in] start Index of first point in range to subsample
00111           * \param[in] count Offset (start+count) of last point in range to subsample
00112           * \param[in] percent Percentage of range to return
00113           * \param[out] v Vector with percent*count uniformly random sampled 
00114           * points from given input rangerange
00115           */
00116         void
00117         readRangeSubSample (const uint64_t start, const uint64_t count, const double percent, AlignedPointTVector &v);
00118 
00119         /** \brief returns the size of the vector of points stored in this class */
00120         inline uint64_t
00121         size () const
00122         {
00123           return container_.size ();
00124         }
00125 
00126         inline bool
00127         empty () const
00128         {
00129           return container_.empty ();
00130         }
00131         
00132 
00133         /** \brief clears the vector of points in this class */
00134         inline void
00135         clear ()
00136         {
00137           //clear the elements in the vector of points
00138           container_.clear ();
00139         }
00140 
00141         /** \brief Writes ascii x,y,z point data to path.string().c_str()
00142           *  \param path The path/filename destination of the ascii xyz data
00143           */
00144         void
00145         convertToXYZ (const boost::filesystem::path &path);
00146 
00147         inline PointT
00148         operator[] (uint64_t index) const
00149         {
00150           assert ( index < container_.size () );
00151           return ( container_[index] );
00152         }
00153         
00154 
00155       protected:
00156         //no copy construction
00157         OutofcoreOctreeRamContainer (const OutofcoreOctreeRamContainer &rval) { }
00158 
00159         OutofcoreOctreeRamContainer&
00160         operator= (const OutofcoreOctreeRamContainer& rval) { }
00161 
00162         //the actual container
00163         //std::deque<PointT> container;
00164 
00165         /** \brief linear container to hold the points */
00166         AlignedPointTVector container_;
00167 
00168         static boost::mutex rng_mutex_;
00169         static boost::mt19937 rand_gen_;
00170     };
00171   }
00172 }
00173 
00174 #endif //PCL_OUTOFCORE_OCTREE_RAM_CONTAINER_H_