INTRODUCTION Overview Download and Install Quick Start Documentation Publications NONFRAMEWORK CODE Driver Interfaces Drivers Libraries Utilities FRAMEWORK CODE Interfaces Components Libraries Utilities Full Software Listings DEVELOPER Tutorials Examples Dev Guide Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
sparseskel.h00001 /* 00002 * Orca-Robotics Project: Components for robotics 00003 * http://orca-robotics.sf.net/ 00004 * Copyright (c) 2004-2009 Alex Brooks, Alexei Makarenko, Tobias Kaupp 00005 * 00006 * This copy of Orca is licensed to you under the terms described in 00007 * the LICENSE file included in this distribution. 00008 * 00009 */ 00010 #ifndef HYDROPATHPLAN_SPARSE_SKEL_H 00011 #define HYDROPATHPLAN_SPARSE_SKEL_H 00012 00013 #include <hydropathplan/util.h> 00014 #include <hydroogmap/hydroogmap.h> 00015 00016 namespace hydropathplan { 00017 00018 namespace sparseskel { 00019 00020 class SparseSkelArc; 00021 class ContiguousSparseSkel; 00022 class SparseSkelNode; 00023 00026 00035 class SparseSkel { 00036 00037 public: 00038 00049 SparseSkel( const hydroogmap::OgMap &ogMap, 00050 double traversabilityThreshhold, 00051 const Cell2DVector &skel, 00052 const FloatMap &costMap, 00053 bool addExtraNodes, 00054 double extraNodeResolution ); 00055 00056 ~SparseSkel(); 00057 00058 // access 00059 const std::vector<ContiguousSparseSkel*> &contiguousSkels() const 00060 { return contiguousSkels_; } 00061 const hydroogmap::OgMap &ogMap() const { return ogMap_; } 00062 const hydroogmap::OgMap &extraNodesOgMap() const { return extraNodesOgMap_; } 00063 00064 int numNodes() const; 00065 double traversabilityThreshhold() const { return traversabilityThreshhold_; } 00066 00067 private: 00068 00069 // 00070 // 'wps' is the set of waypoints: end-points or junctions of the skel. 00071 // 00072 void build( Cell2DList &skel, 00073 Cell2DList &wps, 00074 const FloatMap &costMap, 00075 bool addExtraNodes, 00076 double extraNodeResolution ); 00077 00078 // If the map has disjoint sections, we may require more than one 00079 // separate ContiguousSparseSkel. 00080 std::vector<ContiguousSparseSkel*> contiguousSkels_; 00081 00082 // Use this OG map generally. It should have been pre-grown 00083 const hydroogmap::OgMap &ogMap_; 00084 00085 // Use this OG map for adding extra nodes: only add if LOS is very clear. 00086 hydroogmap::OgMap extraNodesOgMap_; 00087 00088 const double traversabilityThreshhold_; 00089 }; 00090 00093 00094 // 00095 // If the map has disjoint sections, we may require more than one 00096 // separate ContiguousSparseSkel. 00097 // 00098 // Not intended to be instantiated by anything other than SparseSkel. 00099 // 00100 class ContiguousSparseSkel 00101 { 00102 public: 00103 00104 // 00105 // This constructor removes the stuff it uses from the parameters wps and skel. 00106 // 00107 ContiguousSparseSkel( SparseSkel &parent, 00108 Cell2DList &wps, 00109 Cell2DList &skel, 00110 const FloatMap &costMap, 00111 bool addExtraNodes, 00112 double extraNodeResolution ); 00113 ~ContiguousSparseSkel(); 00114 00115 // access 00116 const std::vector<SparseSkelNode*> &nodes() const 00117 { return nodes_; } 00118 00119 const hydroogmap::OgMap &ogMap() const { return parent_.ogMap(); } 00120 double traversabilityThreshhold() const { return parent_.traversabilityThreshhold(); } 00121 00122 bool isSane() const; 00123 00124 private: 00125 00126 // This function grows outwards along the skel from 'fromNode', 00127 // finding and adding all directly-connected neighbours. It will 00128 // modify its arguments, adding to 'ungrownCells', 00129 // and removing from and 'skel' 00130 void growNode( SparseSkelNode *fromNode, 00131 Cell2DList &ungrownCells, 00132 Cell2DList &wps, 00133 Cell2DList &skel ); 00134 00135 // Search through the skel to find the next node in this 00136 // direction. findNeighbourNode deletes all visited 00137 // members of skel. Visited members of skel get put in 00138 // cellsEnRoute. 00139 bool findNeighbourNode( const SparseSkelNode *fromNode, 00140 const Cell2D &startCell, 00141 Cell2D &neighbourPos, 00142 Cell2DVector &cellsEnRoute, 00143 Cell2DList &wps, 00144 Cell2DList &skel ); 00145 00146 SparseSkelNode* findNode( const Cell2D &pos ); 00147 00148 void mergeAdjacentNodes(); 00149 00150 // prior to this, all costs are initialised to -1 00151 void setArcCosts( const FloatMap &costMap ); 00152 00153 // return true if it's ok to merge. 00154 bool canMerge( SparseSkelNode *slave, SparseSkelNode *master ); 00155 // replace all references to slave with refs to master. 00156 void merge( SparseSkelNode *slave, SparseSkelNode *master ); 00157 00158 // Add extra nodes to cover the space a bit better 00159 // (if this isn't done, the skeleton has trouble accurately estimating the cost 00160 // in large open areas where the skeleton just goes through the middle) 00161 void addExtraNodes( const hydroogmap::OgMap &ogMap, int cellStep ); 00162 void tryAddExtraNode( const Cell2D &cell, 00163 double minDistForLinkSq, 00164 double maxDistForLinkSq, 00165 const hydroogmap::OgMap &ogMap ); 00166 00167 // Returns the node that it arced to (possibly after creating it) 00168 // Note that cellsEnRoute doesn't include either end-point. 00169 SparseSkelNode *createArc( SparseSkelNode *fromNode, 00170 Cell2D &neighbourNodePos, 00171 Cell2DVector &cellsEnRoute ); 00172 00173 std::vector<SparseSkelNode*> nodes_; 00174 SparseSkel &parent_; 00175 }; 00176 00179 00180 // 00181 // Not intended to be instantiated by anything other than SparseSkel. 00182 // 00183 class SparseSkelNode { 00184 00185 public: 00186 00187 SparseSkelNode( const Cell2D &nodePos ) 00188 : pos(nodePos) {} 00189 ~SparseSkelNode(); 00190 00191 Cell2D pos; 00192 std::vector<SparseSkelArc*> arcs; 00193 00194 // Temporary used for searching 00195 mutable float nodeCost; 00196 }; 00197 00200 00201 // 00202 // Not intended to be instantiated by anything other than SparseSkel. 00203 // 00204 class SparseSkelArc { 00205 00206 public: 00207 00208 SparseSkelArc( SparseSkelNode *initToNode, float initCost ) 00209 : toNode(initToNode), cost(initCost) {} 00210 00211 SparseSkelNode *toNode; 00212 float cost; 00213 00214 }; 00215 00217 inline float distance( const Cell2D &a, const Cell2D &b ) 00218 { 00219 #ifdef __QNX__ 00220 return std::hypot( a.x()-b.x(), a.y()-b.y() ); 00221 #else 00222 return hypot( a.x()-b.x(), a.y()-b.y() ); 00223 #endif 00224 } 00225 00227 inline float distanceSq( const Cell2D &a, const Cell2D &b ) 00228 { 00229 return (a.x()-b.x())*(a.x()-b.x()) + (a.y()-b.y())*(a.y()-b.y()); 00230 } 00231 00234 00235 // // helper function for debugging. 00236 // void printCellList( const Cell2DList &cellList ); 00237 00238 } 00239 00240 } 00241 00242 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)