Point Cloud Library (PCL)  1.3.1
octree_nodes.h
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-2011, Willow Garage, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Willow Garage, Inc. nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id: octree_nodes.h 3017 2011-11-01 03:24:04Z rusu $
00037  */
00038 
00039 #ifndef OCTREE_NODE_H
00040 #define OCTREE_NODE_H
00041 
00042 // maximum depth of octree as we are using "unsigned int" octree keys / bit masks
00043 #define OCT_MAXTREEDEPTH ( sizeof(unsigned int) * 8  )
00044 
00045 #include <pcl/pcl_macros.h>
00046 
00047 namespace pcl
00048 {
00049   namespace octree
00050   {
00051 
00052     // enum of node types within the octree
00053     enum node_type_t
00054     {
00055       BRANCH_NODE, LEAF_NODE
00056     };
00057 
00059 
00063     class PCL_EXPORTS OctreeNode
00064     {
00065     public:
00066 
00068       virtual node_type_t
00069       getNodeType () const = 0;
00070     };
00071 
00073 
00077     template<typename DataT>
00078       class OctreeLeafAbstract : public OctreeNode
00079       {
00080       public:
00081 
00082         typedef DataT leaf_data_t;
00083 
00085         OctreeLeafAbstract ()
00086         {
00087         }
00089         ~OctreeLeafAbstract ()
00090         {
00091         }
00092 
00094         virtual node_type_t
00095         getNodeType () const
00096         {
00097           return LEAF_NODE;
00098         }
00099 
00103         virtual void
00104         setData (const leaf_data_t& data_arg) = 0;
00105 
00109         virtual void
00110         getData (const DataT*& data_arg) const = 0;
00111 
00115         virtual void
00116         getData (std::vector<leaf_data_t>& dataVector_arg) const = 0;
00117 
00119         virtual void
00120         reset () = 0;
00121 
00122       };
00123 
00125 
00129     template<typename DataT>
00130       class OctreeLeafEmpty : public OctreeLeafAbstract<DataT>
00131       {
00132       public:
00134         OctreeLeafEmpty ()
00135         {
00136         }
00137 
00139         ~OctreeLeafEmpty ()
00140         {
00141         }
00142 
00147         virtual void
00148         setData (const DataT& data_arg)
00149         {
00150         }
00151 
00155         virtual void
00156         getData (const DataT*& data_arg) const
00157         {
00158           data_arg = 0;
00159         }
00160 
00164         virtual void
00165         getData (std::vector<DataT>& dataVector_arg) const
00166         {
00167         }
00168 
00170         virtual void
00171         reset ()
00172         {
00173         }
00174       };
00175 
00177 
00181     template<typename DataT>
00182       class OctreeLeafDataT : public OctreeLeafAbstract<DataT>
00183       {
00184       public:
00185 
00187         OctreeLeafDataT ()
00188         {
00189         }
00190 
00192         ~OctreeLeafDataT ()
00193         {
00194         }
00195 
00199         virtual void
00200         setData (const DataT& data_arg)
00201         {
00202           this->data_ = data_arg;
00203         }
00204 
00208         virtual void
00209         getData (const DataT*& data_arg) const
00210         {
00211           data_arg = &data_;
00212         }
00213 
00217         virtual void
00218         getData (std::vector<DataT>& dataVector_arg) const
00219         {
00220           dataVector_arg.push_back (this->data_);
00221         }
00222 
00224         virtual void
00225         reset ()
00226         {
00227           memset (&data_, 0, sizeof(data_));
00228         }
00229 
00230       protected:
00232         DataT data_;
00233 
00234       };
00235 
00237 
00241     template<typename DataT>
00242       class OctreeLeafDataTVector : public OctreeLeafAbstract<DataT>
00243       {
00244 
00245       public:
00247         OctreeLeafDataTVector ()
00248         {
00249         }
00251         ~OctreeLeafDataTVector ()
00252         {
00253         }
00254 
00258         virtual void
00259         setData (const DataT& data_arg)
00260         {
00261           leafDataTVector_.push_back (data_arg);
00262         }
00263 
00267         virtual void
00268         getData (const DataT*& data_arg) const
00269         {
00270           DataT* result = 0;
00271 
00272           if (leafDataTVector_.size () > 0)
00273             result = (DataT*)&leafDataTVector_.back ();
00274 
00275           data_arg = result;
00276 
00277         }
00278 
00282         virtual void
00283         getData (std::vector<DataT>& dataVector_arg) const
00284         {
00285 
00286           dataVector_arg.insert (dataVector_arg.end (), leafDataTVector_.begin (), leafDataTVector_.end ());
00287         }
00288 
00292         virtual const std::vector<DataT>&
00293         getIdxVector ()
00294         {
00295           return leafDataTVector_;
00296         }
00297 
00299         virtual void
00300         reset ()
00301         {
00302           leafDataTVector_.clear ();
00303         }
00304 
00305       protected:
00307         std::vector<DataT> leafDataTVector_;
00308 
00309       };
00310   }
00311 }
00312 
00313 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines