expander.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2008, 2013, Willow Garage, Inc.
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of Willow Garage, Inc. nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  * Author: Eitan Marder-Eppstein
00036  *         David V. Lu!!
00037  *********************************************************************/
00038 #ifndef _EXPANDER_H
00039 #define _EXPANDER_H
00040 #include <global_planner/potential_calculator.h>
00041 #include <global_planner/planner_core.h>
00042 
00043 namespace global_planner {
00044 
00045 class Expander {
00046     public:
00047         Expander(PotentialCalculator* p_calc, int nx, int ny) :
00048                 unknown_(true), lethal_cost_(253), neutral_cost_(50), factor_(3.0), p_calc_(p_calc) {
00049             setSize(nx, ny);
00050         }
00051         virtual bool calculatePotentials(unsigned char* costs, double start_x, double start_y, double end_x, double end_y,
00052                                         int cycles, float* potential) = 0;
00053 
00059         virtual void setSize(int nx, int ny) {
00060             nx_ = nx;
00061             ny_ = ny;
00062             ns_ = nx * ny;
00063         } 
00064         void setLethalCost(unsigned char lethal_cost) {
00065             lethal_cost_ = lethal_cost;
00066         }
00067         void setNeutralCost(unsigned char neutral_cost) {
00068             neutral_cost_ = neutral_cost;
00069         }
00070         void setFactor(float factor) {
00071             factor_ = factor;
00072         }
00073         void setHasUnknown(bool unknown) {
00074             unknown_ = unknown;
00075         }
00076 
00077         void clearEndpoint(unsigned char* costs, float* potential, int gx, int gy, int s){
00078             int startCell = toIndex(gx, gy);
00079             for(int i=-s;i<=s;i++){
00080             for(int j=-s;j<=s;j++){
00081                 int n = startCell+i+nx_*j;
00082                 if(potential[n]<POT_HIGH)
00083                     continue;
00084                 float c = costs[n]+neutral_cost_;
00085                 float pot = p_calc_->calculatePotential(potential, c, n);
00086                 potential[n] = pot;
00087             }
00088             }
00089         }
00090 
00091     protected:
00092         inline int toIndex(int x, int y) {
00093             return x + nx_ * y;
00094         }
00095 
00096         int nx_, ny_, ns_; 
00097         bool unknown_;
00098         unsigned char lethal_cost_, neutral_cost_;
00099         int cells_visited_;
00100         float factor_;
00101         PotentialCalculator* p_calc_;
00102 
00103 };
00104 
00105 } //end namespace global_planner
00106 #endif


global_planner
Author(s): David Lu!!
autogenerated on Wed Aug 2 2017 03:13:12