octomap 1.5.0
|
00001 #ifndef OCTOMAP_COUNTING_OCTREE_HH 00002 #define OCTOMAP_COUNTING_OCTREE_HH 00003 00004 // $Id: CountingOcTree.h 391 2012-06-21 10:07:53Z ahornung $ 00005 00014 /* 00015 * Copyright (c) 2009-2011, K. M. Wurm, A. Hornung, University of Freiburg 00016 * All rights reserved. 00017 * 00018 * Redistribution and use in source and binary forms, with or without 00019 * modification, are permitted provided that the following conditions are met: 00020 * 00021 * * Redistributions of source code must retain the above copyright 00022 * notice, this list of conditions and the following disclaimer. 00023 * * Redistributions in binary form must reproduce the above copyright 00024 * notice, this list of conditions and the following disclaimer in the 00025 * documentation and/or other materials provided with the distribution. 00026 * * Neither the name of the University of Freiburg nor the names of its 00027 * contributors may be used to endorse or promote products derived from 00028 * this software without specific prior written permission. 00029 * 00030 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00031 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00032 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00033 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00034 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00035 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00036 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00037 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00038 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00039 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00040 * POSSIBILITY OF SUCH DAMAGE. 00041 */ 00042 00043 00044 #include <stdio.h> 00045 #include "OcTreeBase.h" 00046 #include "OcTreeDataNode.h" 00047 00048 namespace octomap { 00049 00059 class CountingOcTreeNode : public OcTreeDataNode<unsigned int> { 00060 00061 public: 00062 00063 CountingOcTreeNode(); 00064 ~CountingOcTreeNode(); 00065 bool createChild(unsigned int i); 00066 00067 inline CountingOcTreeNode* getChild(unsigned int i) { 00068 return static_cast<CountingOcTreeNode*> (OcTreeDataNode<unsigned int>::getChild(i)); 00069 } 00070 00071 inline const CountingOcTreeNode* getChild(unsigned int i) const { 00072 return static_cast<const CountingOcTreeNode*> (OcTreeDataNode<unsigned int>::getChild(i)); 00073 } 00074 00075 inline unsigned int getCount() const { return getValue(); } 00076 inline void increaseCount() { value++; } 00077 inline void setCount(unsigned c) {this->setValue(c); } 00078 00079 // overloaded: 00080 void expandNode(); 00081 }; 00082 00083 00084 00094 class CountingOcTree : public OcTreeBase <CountingOcTreeNode> { 00095 00096 public: 00098 CountingOcTree(double resolution) : OcTreeBase<CountingOcTreeNode>(resolution) {}; 00099 virtual CountingOcTreeNode* updateNode(const point3d& value); 00100 CountingOcTreeNode* updateNode(const OcTreeKey& k); 00101 void getCentersMinHits(point3d_list& node_centers, unsigned int min_hits) const; 00102 00103 protected: 00104 00105 void getCentersMinHitsRecurs( point3d_list& node_centers, 00106 unsigned int& min_hits, 00107 unsigned int max_depth, 00108 CountingOcTreeNode* node, unsigned int depth, 00109 const OcTreeKey& parent_key) const; 00110 00115 class StaticMemberInitializer{ 00116 public: 00117 StaticMemberInitializer() { 00118 CountingOcTree* tree = new CountingOcTree(0.1); 00119 AbstractOcTree::registerTreeType(tree); 00120 } 00121 }; 00123 static StaticMemberInitializer countingOcTreeMemberInit; 00124 }; 00125 00126 00127 } 00128 00129 00130 #endif