octree_ram_container.hpp
Go to the documentation of this file.
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: octree_ram_container.hpp 6927 2012-08-23 02:34:54Z stfox88 $
00038  */
00039 
00040 #ifndef PCL_OUTOFCORE_RAM_CONTAINER_IMPL_H_
00041 #define PCL_OUTOFCORE_RAM_CONTAINER_IMPL_H_
00042 
00043 // C++
00044 #include <sstream>
00045 
00046 // PCL (Urban Robotics)
00047 #include <pcl/outofcore/octree_ram_container.h>
00048 
00049 namespace pcl
00050 {
00051   namespace outofcore
00052   {
00053 
00054     template<typename PointT>
00055     boost::mutex OutofcoreOctreeRamContainer<PointT>::rng_mutex_;
00056 
00057     template<typename PointT> 
00058     boost::mt19937 OutofcoreOctreeRamContainer<PointT>::rand_gen_ (static_cast<unsigned int>(std::time( NULL)));
00059 
00060     template<typename PointT> void
00061     OutofcoreOctreeRamContainer<PointT>::convertToXYZ (const boost::filesystem::path& path)
00062     {
00063       if (!container_.empty ())
00064       {
00065         FILE* fxyz = fopen (path.string ().c_str (), "w");
00066 
00067         boost::uint64_t num = size ();
00068         for (boost::uint64_t i = 0; i < num; i++)
00069         {
00070           const PointT& p = container_[i];
00071 
00072           std::stringstream ss;
00073           ss << std::fixed;
00074           ss.precision (16);
00075           ss << p.x << "\t" << p.y << "\t" << p.z << "\n";
00076 
00077           fwrite (ss.str ().c_str (), 1, ss.str ().size (), fxyz);
00078         }
00079 
00080         assert ( fclose (fxyz) == 0 );
00081       }
00082     }
00083 
00085 
00086     template<typename PointT> void
00087     OutofcoreOctreeRamContainer<PointT>::insertRange (const PointT* start, const boost::uint64_t count)
00088     {
00089       container_.insert (container_.end (), start, start + count);
00090     }
00091 
00093 
00094     template<typename PointT> void
00095     OutofcoreOctreeRamContainer<PointT>::insertRange (const PointT* const * start, const boost::uint64_t count)
00096     {
00097       AlignedPointTVector temp;
00098       temp.resize (count);
00099       for (boost::uint64_t i = 0; i < count; i++)
00100       {
00101         temp[i] = *start[i];
00102       }
00103       container_.insert (container_.end (), temp.begin (), temp.end ());
00104     }
00105 
00107 
00108     template<typename PointT> void
00109     OutofcoreOctreeRamContainer<PointT>::readRange (const boost::uint64_t start, const boost::uint64_t count,
00110                                              AlignedPointTVector& v)
00111     {
00112       v.resize (count);
00113       memcpy (v.data (), container_.data () + start, count * sizeof(PointT));
00114     }
00115 
00117 
00118     template<typename PointT> void
00119     OutofcoreOctreeRamContainer<PointT>::readRangeSubSample (const boost::uint64_t start, 
00120                                                       const boost::uint64_t count,
00121                                                       const double percent, 
00122                                                       AlignedPointTVector& v)
00123     {
00124       boost::uint64_t samplesize = static_cast<boost::uint64_t> (percent * static_cast<double> (count));
00125 
00126       boost::mutex::scoped_lock lock (rng_mutex_);
00127 
00128       boost::uniform_int < boost::uint64_t > buffdist (start, start + count);
00129       boost::variate_generator<boost::mt19937&, boost::uniform_int<boost::uint64_t> > buffdie (rand_gen_, buffdist);
00130 
00131       for (boost::uint64_t i = 0; i < samplesize; i++)
00132       {
00133         boost::uint64_t buffstart = buffdie ();
00134         v.push_back (container_[buffstart]);
00135       }
00136     }
00137 
00139 
00140   }//namespace outofcore
00141 }//namespace pcl
00142 
00143 #endif //PCL_OUTOFCORE_RAM_CONTAINER_IMPL_H_


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:26:19