<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8"/> <title>OMPL: src/ompl/geometric/planners/kpiece/Discretization.h Source File</title> <meta name="author" content="Ioan A. Șucan, Mark Moll, Lydia E. Kavraki"> <link rel="stylesheet" href="../css/screen.css" type="text/css" media="screen, projection"> <link rel="stylesheet" href="../css/print.css" type="text/css" media="print"> <!--[if lt IE 7]> <script type="text/javascript" src="../js/jquery/jquery.js"></script> <script type="text/javascript" src="../js/jquery/jquery.dropdown.js"></script> <![endif]--> <script type="text/javaScript" src="search/search.js"></script> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-9156598-2']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </head> <body onload='searchBox.OnSelectItem(0);'> <script type="text/javascript"><!-- var searchBox = new SearchBox("searchBox", "search",false,'Search API'); --></script> <div class="navigation" id="top"> <div class="tabs" id="ompltitle"> <ul class="tablist"> <li>The Open Motion Planning Library</li> <li id="searchli"> <div id="MSearchBox" class="MSearchBoxInactive"> <span class="left"> <img id="MSearchSelect" src="search/mag_sel.png" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" alt=""/> <input type="text" id="MSearchField" value="Search API" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)" onkeyup="searchBox.OnSearchFieldChange(event)"/> </span><span class="right"> <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> </span> </div> </li> </ul> </div> <ul id="nav" class="dropdown"> <li class="first"><a href="index.html">Home</a></li> <li><a href="download.html">Download</a></li> <li><a href="documentation.html">Documentation</a></li> <li><span class="dir">Code API</span> <ul> <li><a href="api_overview.html">API Overview</a></li> <li><a href="namespaces.html">Namespaces</a></li> <li><a href="annotated.html">Classes</a></li> <li><a href="files.html">Files</a></li> <li><a href="dirs.html">Directories</a></li> </ul> </li> <li><span class="dir">Community</span> <ul> <li><a href="developers.html">Developers</a></li> <li><a href="thirdparty.html">Contributions</a></li> <li><a href="education.html">Education</a></li> <li><a href="gallery.html">Gallery</a></li> </ul> </li> <li><span class="dir">About</span> <ul> <li><a href="license.html">License</a></li> <li><a href="citations.html">Citations</a></li> <li><a href="acknowledgements.html">Acknowledgments</a></li> <li><a href="contact.html">Contact Us</a></li> </ul> </li> </ul> </div> <!--- window showing the filter options --> <div id="MSearchSelectWindow" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" onkeydown="return searchBox.OnSearchSelectKey(event)"> <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a></div> <!-- iframe showing the search results (closed by default) --> <div id="MSearchResultsWindow"> <iframe src="" frameborder="0"name="MSearchResults" id="MSearchResults"></iframe> </div> <div class="container"> <div class="span-22 push-2 first last"> <div> <!-- Generated by Doxygen 1.7.4 --> <script type="text/javascript"><!-- var searchBox = new SearchBox("searchBox", "search",false,'Search'); --></script> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="dir_f5421e52a658cd938113ed6044324834.html">src</a> </li> <li class="navelem"><a class="el" href="dir_ae92c2ff78847f0cb49b545f9089bbbc.html">ompl</a> </li> <li class="navelem"><a class="el" href="dir_09c87af92e12dad9ad42621ff12ca21c.html">geometric</a> </li> <li class="navelem"><a class="el" href="dir_ea5fd944e8f903b1c975832ff4982cc4.html">planners</a> </li> <li class="navelem"><a class="el" href="dir_49b7897943bf914faee6ea202af1bfa1.html">kpiece</a> </li> </ul> </div> </div> <div class="header"> <div class="headertitle"> <div class="title">Discretization.h</div> </div> </div> <div class="contents"> <div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*********************************************************************</span> <a name="l00002"></a>00002 <span class="comment">* Software License Agreement (BSD License)</span> <a name="l00003"></a>00003 <span class="comment">*</span> <a name="l00004"></a>00004 <span class="comment">* Copyright (c) 2008, Rice University</span> <a name="l00005"></a>00005 <span class="comment">* All rights reserved.</span> <a name="l00006"></a>00006 <span class="comment">*</span> <a name="l00007"></a>00007 <span class="comment">* Redistribution and use in source and binary forms, with or without</span> <a name="l00008"></a>00008 <span class="comment">* modification, are permitted provided that the following conditions</span> <a name="l00009"></a>00009 <span class="comment">* are met:</span> <a name="l00010"></a>00010 <span class="comment">*</span> <a name="l00011"></a>00011 <span class="comment">* * Redistributions of source code must retain the above copyright</span> <a name="l00012"></a>00012 <span class="comment">* notice, this list of conditions and the following disclaimer.</span> <a name="l00013"></a>00013 <span class="comment">* * Redistributions in binary form must reproduce the above</span> <a name="l00014"></a>00014 <span class="comment">* copyright notice, this list of conditions and the following</span> <a name="l00015"></a>00015 <span class="comment">* disclaimer in the documentation and/or other materials provided</span> <a name="l00016"></a>00016 <span class="comment">* with the distribution.</span> <a name="l00017"></a>00017 <span class="comment">* * Neither the name of the Rice University nor the names of its</span> <a name="l00018"></a>00018 <span class="comment">* contributors may be used to endorse or promote products derived</span> <a name="l00019"></a>00019 <span class="comment">* from this software without specific prior written permission.</span> <a name="l00020"></a>00020 <span class="comment">*</span> <a name="l00021"></a>00021 <span class="comment">* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span> <a name="l00022"></a>00022 <span class="comment">* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span> <a name="l00023"></a>00023 <span class="comment">* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS</span> <a name="l00024"></a>00024 <span class="comment">* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE</span> <a name="l00025"></a>00025 <span class="comment">* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,</span> <a name="l00026"></a>00026 <span class="comment">* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,</span> <a name="l00027"></a>00027 <span class="comment">* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span> <a name="l00028"></a>00028 <span class="comment">* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER</span> <a name="l00029"></a>00029 <span class="comment">* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</span> <a name="l00030"></a>00030 <span class="comment">* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN</span> <a name="l00031"></a>00031 <span class="comment">* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</span> <a name="l00032"></a>00032 <span class="comment">* POSSIBILITY OF SUCH DAMAGE.</span> <a name="l00033"></a>00033 <span class="comment">*********************************************************************/</span> <a name="l00034"></a>00034 <a name="l00035"></a>00035 <span class="comment">/* Author: Ioan Sucan */</span> <a name="l00036"></a>00036 <a name="l00037"></a>00037 <span class="preprocessor">#ifndef OMPL_GEOMETRIC_PLANNERS_KPIECE_DISCRETIZATION_</span> <a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#define OMPL_GEOMETRIC_PLANNERS_KPIECE_DISCRETIZATION_</span> <a name="l00039"></a>00039 <span class="preprocessor"></span> <a name="l00040"></a>00040 <span class="preprocessor">#include "ompl/base/Planner.h"</span> <a name="l00041"></a>00041 <span class="preprocessor">#include "ompl/datastructures/GridB.h"</span> <a name="l00042"></a>00042 <span class="preprocessor">#include "ompl/util/Exception.h"</span> <a name="l00043"></a>00043 <span class="preprocessor">#include <boost/function.hpp></span> <a name="l00044"></a>00044 <span class="preprocessor">#include <vector></span> <a name="l00045"></a>00045 <span class="preprocessor">#include <limits></span> <a name="l00046"></a>00046 <span class="preprocessor">#include <cassert></span> <a name="l00047"></a>00047 <span class="preprocessor">#include <utility></span> <a name="l00048"></a>00048 <span class="preprocessor">#include <cstdlib></span> <a name="l00049"></a>00049 <a name="l00050"></a>00050 <span class="keyword">namespace </span>ompl <a name="l00051"></a>00051 { <a name="l00052"></a>00052 <a name="l00053"></a>00053 <span class="keyword">namespace </span>geometric <a name="l00054"></a>00054 { <a name="l00055"></a>00055 <a name="l00057"></a>00057 <span class="keyword">template</span><<span class="keyword">typename</span> Motion> <a name="l00058"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html">00058</a> <span class="keyword">class </span><a class="code" href="classompl_1_1geometric_1_1Discretization.html" title="One-level discretization used for KPIECE.">Discretization</a> <a name="l00059"></a>00059 { <a name="l00060"></a>00060 <span class="keyword">public</span>: <a name="l00061"></a>00061 <a name="l00063"></a><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html">00063</a> <span class="keyword">struct </span><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html" title="The data held by a cell in the grid of motions.">CellData</a> <a name="l00064"></a>00064 { <a name="l00065"></a>00065 <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html" title="The data held by a cell in the grid of motions.">CellData</a>(<span class="keywordtype">void</span>) : <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#ac7a58b36b1ec1834200c1704b63bfa3a" title="A measure of coverage for this cell. For this implementation, this is the sum of motion lengths...">coverage</a>(0.0), <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#a45ea371833bde9daba518b76d54ff794" title="The number of times this cell has been selected for expansion.">selections</a>(1), <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#a42338a1046b5d86cd309d79d30d34321" title="A heuristic score computed based on distance to goal (if available), successes and failures at expand...">score</a>(1.0), <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#ae2164d5b2e2d2805a61aabd3e326ea62" title="The iteration at which this cell was created.">iteration</a>(0), <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#ab6eecc2c36a2cda7a473f7fa2f556c3d" title="The computed importance (based on other class members)">importance</a>(0.0) <a name="l00066"></a>00066 { <a name="l00067"></a>00067 } <a name="l00068"></a>00068 <a name="l00069"></a>00069 ~<a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html" title="The data held by a cell in the grid of motions.">CellData</a>(<span class="keywordtype">void</span>) <a name="l00070"></a>00070 { <a name="l00071"></a>00071 } <a name="l00072"></a>00072 <a name="l00074"></a><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#aee2a1799a55bdc3ed15e7920b1d36757">00074</a> std::vector<Motion*> <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#aee2a1799a55bdc3ed15e7920b1d36757" title="The set of motions contained in this grid cell.">motions</a>; <a name="l00075"></a>00075 <a name="l00079"></a><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#ac7a58b36b1ec1834200c1704b63bfa3a">00079</a> <span class="keywordtype">double</span> <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#ac7a58b36b1ec1834200c1704b63bfa3a" title="A measure of coverage for this cell. For this implementation, this is the sum of motion lengths...">coverage</a>; <a name="l00080"></a>00080 <a name="l00083"></a><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#a45ea371833bde9daba518b76d54ff794">00083</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#a45ea371833bde9daba518b76d54ff794" title="The number of times this cell has been selected for expansion.">selections</a>; <a name="l00084"></a>00084 <a name="l00088"></a><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#a42338a1046b5d86cd309d79d30d34321">00088</a> <span class="keywordtype">double</span> <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#a42338a1046b5d86cd309d79d30d34321" title="A heuristic score computed based on distance to goal (if available), successes and failures at expand...">score</a>; <a name="l00089"></a>00089 <a name="l00091"></a><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#ae2164d5b2e2d2805a61aabd3e326ea62">00091</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#ae2164d5b2e2d2805a61aabd3e326ea62" title="The iteration at which this cell was created.">iteration</a>; <a name="l00092"></a>00092 <a name="l00094"></a><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#ab6eecc2c36a2cda7a473f7fa2f556c3d">00094</a> <span class="keywordtype">double</span> <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#ab6eecc2c36a2cda7a473f7fa2f556c3d" title="The computed importance (based on other class members)">importance</a>; <a name="l00095"></a>00095 }; <a name="l00096"></a>00096 <a name="l00099"></a><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1OrderCellsByImportance.html">00099</a> <span class="keyword">struct </span><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1OrderCellsByImportance.html" title="Definintion of an operator passed to the Grid structure, to order cells by importance.">OrderCellsByImportance</a> <a name="l00100"></a>00100 { <a name="l00101"></a>00101 <a name="l00103"></a><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1OrderCellsByImportance.html#ad7bebc77a8c63baac356336e706a66b2">00103</a> <span class="keywordtype">bool</span> <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1OrderCellsByImportance.html#ad7bebc77a8c63baac356336e706a66b2" title="Order function.">operator()</a>(<span class="keyword">const</span> <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html" title="The data held by a cell in the grid of motions.">CellData</a> * <span class="keyword">const</span> a, <span class="keyword">const</span> <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html" title="The data held by a cell in the grid of motions.">CellData</a> * <span class="keyword">const</span> b)<span class="keyword"> const</span> <a name="l00104"></a>00104 <span class="keyword"> </span>{ <a name="l00105"></a>00105 <span class="keywordflow">return</span> a-><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#ab6eecc2c36a2cda7a473f7fa2f556c3d" title="The computed importance (based on other class members)">importance</a> > b-><a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html#ab6eecc2c36a2cda7a473f7fa2f556c3d" title="The computed importance (based on other class members)">importance</a>; <a name="l00106"></a>00106 } <a name="l00107"></a>00107 }; <a name="l00108"></a>00108 <a name="l00110"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html#ac21186181755603cb91938f280e9dbc3">00110</a> <span class="keyword">typedef</span> <a class="code" href="classompl_1_1GridB.html">GridB<CellData*, OrderCellsByImportance></a> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#ac21186181755603cb91938f280e9dbc3" title="The datatype for the maintained grid datastructure.">Grid</a>; <a name="l00111"></a>00111 <a name="l00113"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html#a810ca49dd7278f5699560d2af1a4bc26">00113</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="structompl_1_1Grid_1_1Cell.html" title="Definition of a cell in this grid.">Grid::Cell</a> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a810ca49dd7278f5699560d2af1a4bc26" title="The datatype for the maintained grid cells.">Cell</a>; <a name="l00114"></a>00114 <a name="l00116"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html#a685f1b61176111a7a248f20350f421e7">00116</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="classompl_1_1GridB.html#ae1ffa2705f26a8916307afa7b020ba49" title="Datatype for cell coordinates.">Grid::Coord</a> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a685f1b61176111a7a248f20350f421e7" title="The datatype for the maintained grid coordinates.">Coord</a>; <a name="l00117"></a>00117 <a name="l00119"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html#a68ecdad46dcce89216b417b81d1fa57a">00119</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> boost::function1<void, Motion*> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a68ecdad46dcce89216b417b81d1fa57a" title="The signature of a function that frees the memory for a motion.">FreeMotionFn</a>; <a name="l00120"></a>00120 <a name="l00121"></a>00121 <a class="code" href="classompl_1_1geometric_1_1Discretization.html" title="One-level discretization used for KPIECE.">Discretization</a>(<span class="keyword">const</span> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a68ecdad46dcce89216b417b81d1fa57a" title="The signature of a function that frees the memory for a motion.">FreeMotionFn</a> &freeMotion) : grid_(0), size_(0), iteration_(1), recentCell_(NULL), <a name="l00122"></a>00122 freeMotion_(freeMotion) <a name="l00123"></a>00123 { <a name="l00124"></a>00124 grid_.<a class="code" href="classompl_1_1GridB.html#a89bffe3573ef977f63b4ab4ff7759705">onCellUpdate</a>(computeImportance, NULL); <a name="l00125"></a>00125 selectBorderFraction_ = 0.9; <a name="l00126"></a>00126 } <a name="l00127"></a>00127 <a name="l00128"></a>00128 ~<a class="code" href="classompl_1_1geometric_1_1Discretization.html" title="One-level discretization used for KPIECE.">Discretization</a>(<span class="keywordtype">void</span>) <a name="l00129"></a>00129 { <a name="l00130"></a>00130 <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a47602ef0c42c4afa40f8655f899e94f6" title="Free the memory for the motions contained in a grid.">freeMemory</a>(); <a name="l00131"></a>00131 } <a name="l00132"></a>00132 <a name="l00139"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html#aac6dfc7acc8db082a84b7bbdadb78e87">00139</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#aac6dfc7acc8db082a84b7bbdadb78e87" title="Set the fraction of time for focusing on the border (between 0 and 1). This is the minimum fraction u...">setBorderFraction</a>(<span class="keywordtype">double</span> bp) <a name="l00140"></a>00140 { <a name="l00141"></a>00141 <span class="keywordflow">if</span> (bp < std::numeric_limits<double>::epsilon() || bp > 1.0) <a name="l00142"></a>00142 <span class="keywordflow">throw</span> <a class="code" href="classompl_1_1Exception.html" title="The exception type for ompl.">Exception</a>(<span class="stringliteral">"The fraction of time spent selecting border cells must be in the range (0,1]"</span>); <a name="l00143"></a>00143 selectBorderFraction_ = bp; <a name="l00144"></a>00144 } <a name="l00145"></a>00145 <a name="l00148"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html#aa8bad537b028cf076e379cc11b81aec4">00148</a> <span class="keywordtype">double</span> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#aa8bad537b028cf076e379cc11b81aec4" title="Set the fraction of time for focusing on the border (between 0 and 1).">getBorderFraction</a>(<span class="keywordtype">void</span>)<span class="keyword"> const</span> <a name="l00149"></a>00149 <span class="keyword"> </span>{ <a name="l00150"></a>00150 <span class="keywordflow">return</span> selectBorderFraction_; <a name="l00151"></a>00151 } <a name="l00152"></a>00152 <a name="l00154"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html#acfdbc5b059330490b55185dda00f0eb1">00154</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#acfdbc5b059330490b55185dda00f0eb1" title="Set the dimension of the grid to be maintained.">setDimension</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> dim) <a name="l00155"></a>00155 { <a name="l00156"></a>00156 grid_.<a class="code" href="classompl_1_1GridN.html#a8f301e691e48294e1e216d1c7971aa9d">setDimension</a>(dim); <a name="l00157"></a>00157 } <a name="l00158"></a>00158 <a name="l00160"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html#a70dc618627b2b7921d9294d2a43da994">00160</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a70dc618627b2b7921d9294d2a43da994" title="Restore the discretization to its original form.">clear</a>(<span class="keywordtype">void</span>) <a name="l00161"></a>00161 { <a name="l00162"></a>00162 <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a47602ef0c42c4afa40f8655f899e94f6" title="Free the memory for the motions contained in a grid.">freeMemory</a>(); <a name="l00163"></a>00163 size_ = 0; <a name="l00164"></a>00164 iteration_ = 1; <a name="l00165"></a>00165 recentCell_ = NULL; <a name="l00166"></a>00166 } <a name="l00167"></a>00167 <a name="l00168"></a>00168 <span class="keywordtype">void</span> countIteration(<span class="keywordtype">void</span>) <a name="l00169"></a>00169 { <a name="l00170"></a>00170 ++iteration_; <a name="l00171"></a>00171 } <a name="l00172"></a>00172 <a name="l00173"></a>00173 std::size_t getMotionCount(<span class="keywordtype">void</span>) <a name="l00174"></a>00174 { <a name="l00175"></a>00175 <span class="keywordflow">return</span> size_; <a name="l00176"></a>00176 } <a name="l00177"></a>00177 <a name="l00178"></a>00178 std::size_t getCellCount(<span class="keywordtype">void</span>) <a name="l00179"></a>00179 { <a name="l00180"></a>00180 <span class="keywordflow">return</span> grid_.<a class="code" href="classompl_1_1Grid.html#a94c2dd5667093608a10aa91a46f42dfa" title="Check the size of the grid.">size</a>(); <a name="l00181"></a>00181 } <a name="l00182"></a>00182 <a name="l00184"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html#a47602ef0c42c4afa40f8655f899e94f6">00184</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a47602ef0c42c4afa40f8655f899e94f6" title="Free the memory for the motions contained in a grid.">freeMemory</a>(<span class="keywordtype">void</span>) <a name="l00185"></a>00185 { <a name="l00186"></a>00186 <span class="keywordflow">for</span> (<span class="keyword">typename</span> <a class="code" href="classompl_1_1Grid.html#ac85bc047c9574aea0fb08c1c53701eb9" title="We only allow const iterators.">Grid::iterator</a> it = grid_.<a class="code" href="classompl_1_1Grid.html#ad74c5df97cf3d54a1a15eff55596973c" title="Return the begin() iterator for the grid.">begin</a>(); it != grid_.<a class="code" href="classompl_1_1Grid.html#ac5d360c8fa02bd6ec58aa8cbbc450dd7" title="Return the end() iterator for the grid.">end</a>() ; ++it) <a name="l00187"></a>00187 freeCellData(it->second->data); <a name="l00188"></a>00188 grid_.<a class="code" href="classompl_1_1GridB.html#a99febb9d816320dc306778a4e0f5d0b0" title="Clear all cells in the grid.">clear</a>(); <a name="l00189"></a>00189 } <a name="l00190"></a>00190 <a name="l00199"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html#a6ac71e099d8a69dc6c2ee5ff1736a277">00199</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a6ac71e099d8a69dc6c2ee5ff1736a277" title="Add a motion to the grid containing motions. As a hint, dist specifies the distance to the goal from ...">addMotion</a>(Motion* motion, <span class="keyword">const</span> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a685f1b61176111a7a248f20350f421e7" title="The datatype for the maintained grid coordinates.">Coord</a> &coord, <span class="keywordtype">double</span> dist = 0.0) <a name="l00200"></a>00200 { <a name="l00201"></a>00201 <a class="code" href="structompl_1_1Grid_1_1Cell.html" title="Definition of a cell in this grid.">Cell</a> *cell = grid_.<a class="code" href="classompl_1_1GridN.html#a55b24fea201c89c9dab91c8624cec4e5" title="Get the cell at a specified coordinate.">getCell</a>(coord); <a name="l00202"></a>00202 <a name="l00203"></a>00203 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> created = 0; <a name="l00204"></a>00204 <span class="keywordflow">if</span> (cell) <a name="l00205"></a>00205 { <a name="l00206"></a>00206 cell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->motions.push_back(motion); <a name="l00207"></a>00207 cell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->coverage += 1.0; <a name="l00208"></a>00208 grid_.<a class="code" href="classompl_1_1GridB.html#aceb50d07f1b2bdb195df8ef2c06999e7" title="Update the position in the heaps for a particular cell.">update</a>(cell); <a name="l00209"></a>00209 } <a name="l00210"></a>00210 <span class="keywordflow">else</span> <a name="l00211"></a>00211 { <a name="l00212"></a>00212 cell = grid_.<a class="code" href="classompl_1_1GridB.html#a13473103dede044e44d731b094ea6515" title="Create a cell but do not add it to the grid; update neighboring cells however.">createCell</a>(coord); <a name="l00213"></a>00213 cell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a> = <span class="keyword">new</span> <a class="code" href="structompl_1_1geometric_1_1Discretization_1_1CellData.html" title="The data held by a cell in the grid of motions.">CellData</a>(); <a name="l00214"></a>00214 cell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->motions.push_back(motion); <a name="l00215"></a>00215 cell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->coverage = 1.0; <a name="l00216"></a>00216 cell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->iteration = iteration_; <a name="l00217"></a>00217 cell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->selections = 1; <a name="l00218"></a>00218 cell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->score = (1.0 + log((<span class="keywordtype">double</span>)(iteration_))) / (1.0 + dist); <a name="l00219"></a>00219 grid_.<a class="code" href="classompl_1_1GridB.html#a2d028cfdf6233f097ff43fd70591896b" title="Add the cell to the grid.">add</a>(cell); <a name="l00220"></a>00220 recentCell_ = cell; <a name="l00221"></a>00221 created = 1; <a name="l00222"></a>00222 } <a name="l00223"></a>00223 ++size_; <a name="l00224"></a>00224 <span class="keywordflow">return</span> created; <a name="l00225"></a>00225 } <a name="l00226"></a>00226 <a name="l00230"></a><a class="code" href="classompl_1_1geometric_1_1Discretization.html#a8db183fa4a3231509336ffb7057805df">00230</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a8db183fa4a3231509336ffb7057805df" title="Select a motion and the cell it is part of from the grid of motions. This is where preference is give...">selectMotion</a>(Motion* &smotion, <a class="code" href="structompl_1_1Grid_1_1Cell.html" title="Definition of a cell in this grid.">Cell</a>* &scell) <a name="l00231"></a>00231 { <a name="l00232"></a>00232 scell = rng_.<a class="code" href="classompl_1_1RNG.html#ac49dc7cc9fe4a8d6f73faf7e62df1621" title="Generate a random real between 0 and 1.">uniform01</a>() < std::max(selectBorderFraction_, grid_.<a class="code" href="classompl_1_1GridB.html#a63f2125ed08e7f46a199fe1782482a06" title="Return the fraction of external cells.">fracExternal</a>()) ? <a name="l00233"></a>00233 grid_.<a class="code" href="classompl_1_1GridB.html#af42768c3fa822baeddc138924ac26d50" title="Return the cell that is at the top of the heap maintaining external cells.">topExternal</a>() : grid_.<a class="code" href="classompl_1_1GridB.html#a904761417572e6715c13028ba5c3ee13" title="Return the cell that is at the top of the heap maintaining internal cells.">topInternal</a>(); <a name="l00234"></a>00234 <a name="l00235"></a>00235 <span class="comment">// We are running on finite precision, so our update scheme will end up</span> <a name="l00236"></a>00236 <span class="comment">// with 0 values for the score. This is where we fix the problem</span> <a name="l00237"></a>00237 <span class="keywordflow">if</span> (scell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->score < std::numeric_limits<double>::epsilon()) <a name="l00238"></a>00238 { <a name="l00239"></a>00239 std::vector<CellData*> content; <a name="l00240"></a>00240 content.reserve(grid_.<a class="code" href="classompl_1_1Grid.html#a94c2dd5667093608a10aa91a46f42dfa" title="Check the size of the grid.">size</a>()); <a name="l00241"></a>00241 grid_.<a class="code" href="classompl_1_1Grid.html#afe4fa2e9e3b6db8d57c69daaeb1be0b7" title="Get the data stored in the cells we are aware of.">getContent</a>(content); <a name="l00242"></a>00242 <span class="keywordflow">for</span> (<span class="keyword">typename</span> std::vector<CellData*>::iterator it = content.begin() ; it != content.end() ; ++it) <a name="l00243"></a>00243 (*it)->score += 1.0 + log((<span class="keywordtype">double</span>)((*it)->iteration)); <a name="l00244"></a>00244 grid_.<a class="code" href="classompl_1_1GridB.html#ab7ffc08ce1a2547b5adbfad0672d4935" title="Update all cells and reconstruct the heaps.">updateAll</a>(); <a name="l00245"></a>00245 } <a name="l00246"></a>00246 <a name="l00247"></a>00247 assert(scell && !scell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->motions.empty()); <a name="l00248"></a>00248 <a name="l00249"></a>00249 ++scell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->selections; <a name="l00250"></a>00250 smotion = scell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->motions[rng_.<a class="code" href="classompl_1_1RNG.html#a26c0a9c26d9a34e2f6004536dc92bf1d" title="Generate a random integer using a half-normal distribution. The value is within specified bounds ([r_...">halfNormalInt</a>(0, scell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->motions.size() - 1)]; <a name="l00251"></a>00251 } <a name="l00252"></a>00252 <a name="l00253"></a>00253 <span class="keywordtype">bool</span> removeMotion(Motion *motion, <span class="keyword">const</span> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a685f1b61176111a7a248f20350f421e7" title="The datatype for the maintained grid coordinates.">Coord</a> &coord) <a name="l00254"></a>00254 { <a name="l00255"></a>00255 <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a810ca49dd7278f5699560d2af1a4bc26" title="The datatype for the maintained grid cells.">Cell</a>* cell = grid_.<a class="code" href="classompl_1_1GridN.html#a55b24fea201c89c9dab91c8624cec4e5" title="Get the cell at a specified coordinate.">getCell</a>(coord); <a name="l00256"></a>00256 <span class="keywordflow">if</span> (cell) <a name="l00257"></a>00257 { <a name="l00258"></a>00258 <span class="keywordtype">bool</span> found = <span class="keyword">false</span>; <a name="l00259"></a>00259 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0 ; i < cell->data->motions.size(); ++i) <a name="l00260"></a>00260 <span class="keywordflow">if</span> (cell->data->motions[i] == motion) <a name="l00261"></a>00261 { <a name="l00262"></a>00262 cell-><a class="code" href="structompl_1_1Grid_1_1Cell.html#a9a32dbce70bab52e6d45b0a4d0106366" title="The data we store in the cell.">data</a>->motions.erase(cell->data->motions.begin() + i); <a name="l00263"></a>00263 found = <span class="keyword">true</span>; <a name="l00264"></a>00264 --size_; <a name="l00265"></a>00265 <span class="keywordflow">break</span>; <a name="l00266"></a>00266 } <a name="l00267"></a>00267 <span class="keywordflow">if</span> (cell->data->motions.empty()) <a name="l00268"></a>00268 { <a name="l00269"></a>00269 grid_.<a class="code" href="classompl_1_1GridB.html#a35d8377f870c0e03fca9f2839d863165" title="Remove a cell from the grid.">remove</a>(cell); <a name="l00270"></a>00270 freeCellData(cell->data); <a name="l00271"></a>00271 grid_.<a class="code" href="classompl_1_1Grid.html#a5876a2ff7b1092fd00fc58fee9ad1829" title="Clear the memory occupied by a cell; do not call this function unless remove() was called first...">destroyCell</a>(cell); <a name="l00272"></a>00272 } <a name="l00273"></a>00273 <span class="keywordflow">return</span> found; <a name="l00274"></a>00274 } <a name="l00275"></a>00275 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00276"></a>00276 } <a name="l00277"></a>00277 <a name="l00278"></a>00278 <span class="keywordtype">void</span> updateCell(<a class="code" href="classompl_1_1geometric_1_1Discretization.html#a810ca49dd7278f5699560d2af1a4bc26" title="The datatype for the maintained grid cells.">Cell</a> *cell) <a name="l00279"></a>00279 { <a name="l00280"></a>00280 grid_.<a class="code" href="classompl_1_1GridB.html#aceb50d07f1b2bdb195df8ef2c06999e7" title="Update the position in the heaps for a particular cell.">update</a>(cell); <a name="l00281"></a>00281 } <a name="l00282"></a>00282 <a name="l00283"></a>00283 <span class="keyword">const</span> <a class="code" href="classompl_1_1geometric_1_1Discretization.html#ac21186181755603cb91938f280e9dbc3" title="The datatype for the maintained grid datastructure.">Grid</a>& getGrid(<span class="keywordtype">void</span>)<span class="keyword"> const</span> <a name="l00284"></a>00284 <span class="keyword"> </span>{ <a name="l00285"></a>00285 <span class="keywordflow">return</span> grid_; <a name="l00286"></a>00286 } <a name="l00287"></a>00287 <a name="l00288"></a>00288 <span class="keywordtype">void</span> getPlannerData(base::PlannerData &data, <span class="keywordtype">int</span> tag)<span class="keyword"> const</span> <a name="l00289"></a>00289 <span class="keyword"> </span>{ <a name="l00290"></a>00290 std::vector<CellData*> cdata; <a name="l00291"></a>00291 grid_.<a class="code" href="classompl_1_1Grid.html#afe4fa2e9e3b6db8d57c69daaeb1be0b7" title="Get the data stored in the cells we are aware of.">getContent</a>(cdata); <a name="l00292"></a>00292 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0 ; i < cdata.size() ; ++i) <a name="l00293"></a>00293 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> j = 0 ; j < cdata[i]->motions.size() ; ++j) <a name="l00294"></a>00294 { <a name="l00295"></a>00295 data.recordEdge(cdata[i]->motions[j]->parent ? cdata[i]->motions[j]->parent->state : NULL, cdata[i]->motions[j]->state); <a name="l00296"></a>00296 data.tagState(cdata[i]->motions[j]->state, tag); <a name="l00297"></a>00297 } <a name="l00298"></a>00298 } <a name="l00299"></a>00299 <a name="l00300"></a>00300 <span class="keyword">private</span>: <a name="l00301"></a>00301 <a name="l00303"></a>00303 <span class="keywordtype">void</span> freeCellData(CellData *cdata) <a name="l00304"></a>00304 { <a name="l00305"></a>00305 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0 ; i < cdata->motions.size() ; ++i) <a name="l00306"></a>00306 freeMotion_(cdata->motions[i]); <a name="l00307"></a>00307 <span class="keyword">delete</span> cdata; <a name="l00308"></a>00308 } <a name="l00309"></a>00309 <a name="l00313"></a>00313 <span class="keyword">static</span> <span class="keywordtype">void</span> computeImportance(<a class="code" href="classompl_1_1geometric_1_1Discretization.html#a810ca49dd7278f5699560d2af1a4bc26" title="The datatype for the maintained grid cells.">Cell</a> *cell, <span class="keywordtype">void</span>*) <a name="l00314"></a>00314 { <a name="l00315"></a>00315 CellData &cd = *(cell->data); <a name="l00316"></a>00316 cd.importance = cd.score / ((cell->neighbors + 1) * cd.coverage * cd.selections); <a name="l00317"></a>00317 } <a name="l00318"></a>00318 <a name="l00321"></a>00321 <a class="code" href="classompl_1_1geometric_1_1Discretization.html#ac21186181755603cb91938f280e9dbc3" title="The datatype for the maintained grid datastructure.">Grid</a> grid_; <a name="l00322"></a>00322 <a name="l00325"></a>00325 std::size_t size_; <a name="l00326"></a>00326 <a name="l00328"></a>00328 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> iteration_; <a name="l00329"></a>00329 <a name="l00331"></a>00331 <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a810ca49dd7278f5699560d2af1a4bc26" title="The datatype for the maintained grid cells.">Cell</a> *recentCell_; <a name="l00332"></a>00332 <a name="l00334"></a>00334 <a class="code" href="classompl_1_1geometric_1_1Discretization.html#a68ecdad46dcce89216b417b81d1fa57a" title="The signature of a function that frees the memory for a motion.">FreeMotionFn</a> freeMotion_; <a name="l00335"></a>00335 <a name="l00338"></a>00338 <span class="keywordtype">double</span> selectBorderFraction_; <a name="l00339"></a>00339 <a name="l00341"></a>00341 RNG rng_; <a name="l00342"></a>00342 <a name="l00343"></a>00343 }; <a name="l00344"></a>00344 } <a name="l00345"></a>00345 } <a name="l00346"></a>00346 <a name="l00347"></a>00347 <span class="preprocessor">#endif</span> </pre></div></div> </div> <!-- window showing the filter options --> <div id="MSearchSelectWindow" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" onkeydown="return searchBox.OnSearchSelectKey(event)"> <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a></div> <!-- iframe showing the search results (closed by default) --> <div id="MSearchResultsWindow"> <iframe src="javascript:void(0)" frameborder="0" name="MSearchResults" id="MSearchResults"> </iframe> </div> </div> <div class="footer span-22 push-2 last"> <a href="http://www.kavrakilab.org">Physical and Biological Computing Group</a> • <a href="http://www.cs.rice.edu">Department of Computer Science</a> • <a href="http://www.rice.edu">Rice University</a><br> <div class="gray">Generated on Sun Oct 9 2011 23:04:30 by <a href="http://www.doxygen.org/index.html">doxygen</a> 1.7.4</div> </div> </div> </body> </html>