Point Cloud Library (PCL)  1.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
octree_base_state.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  */
00037 
00038 #ifndef OCTREE_TREE_BASE_STATE_H
00039 #define OCTREE_TREE_BASE_STATE_H
00040 
00041 #include "pcl/octree/octree_base.h"
00042 
00043 namespace pcl
00044 {
00045   namespace octree
00046   {
00047     class OctreeBranchWithState : public OctreeBranch
00048     {
00049     public:
00050       OctreeBranchWithState () : OctreeBranch () {}
00052       OctreeBranchWithState (const OctreeBranchWithState& source)
00053         : OctreeBranch (source)
00054         , state_ (source.state_)
00055       { }
00056       inline void setState (const int& state) { state_ = state; }
00057 
00058       inline int getState () const { return (state_); }
00059 
00060     private:
00061       int state_;
00062     };
00063 
00065 
00071 
00072 
00073     template<typename DataT, typename LeafT = OctreeLeafDataT<DataT> >
00074     class OctreeBaseWithState : public OctreeBase <DataT, LeafT, OctreeBranchWithState>
00075     {
00076     public:
00077 
00078       typedef OctreeBase <DataT, LeafT, OctreeBranchWithState> Base;
00079       using Base::OctreeKey;
00080       typedef typename Base::OctreeBranch OctreeBranch;
00081       
00083       OctreeBaseWithState () : Base () {}
00084         
00086       ~OctreeBaseWithState () {}
00087  
00088     protected:
00089 
00091 
00095 
00096       class OctreeLeafBranch : public OctreeNode
00097       {
00098         // OctreeBase is a friend!
00099         friend class OctreeBaseWithState;
00100 
00101       public:
00102 
00104         OctreeLeafBranch () {}
00105 
00107         virtual ~OctreeLeafBranch () {}
00108 
00110         virtual OctreeNode*
00111         deepCopy () const
00112         {
00113           return (OctreeNode*) new OctreeLeafBranch (*this);
00114         }
00115         
00119         virtual node_type_t
00120         getNodeType () const
00121         {
00122           return LEAF_BRANCH;
00123         }
00124         
00125       private:
00126 
00127         // branch state
00128         int state_;
00129       };
00130 
00131     protected:
00132 
00137       inline void
00138       setBranchState (OctreeBranch*& branch_arg, const int state)
00139       {
00140         branch_arg->setState (state);
00141       }
00142 
00147       inline void
00148       setBranchState (OctreeLeafBranch*& branch_arg, const int state)
00149       {
00150         branch_arg->state_ = state;
00151       }
00152     
00157       inline int
00158       getBranchState ( OctreeBranch*& branch_arg)
00159       {
00160         return (branch_arg->getState ());
00161       }
00166       inline int
00167       getBranchState ( OctreeLeafBranch*& branch_arg)
00168       {
00169         return branch_arg->state_;
00170       }
00171 
00172     };
00173   }
00174 }
00175 
00176 #endif