expander.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2008, 2013, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * Author: Eitan Marder-Eppstein
36  * David V. Lu!!
37  *********************************************************************/
38 #ifndef _EXPANDER_H
39 #define _EXPANDER_H
42 
43 namespace global_planner {
44 
45 class Expander {
46  public:
47  Expander(PotentialCalculator* p_calc, int nx, int ny) :
48  unknown_(true), lethal_cost_(253), neutral_cost_(50), factor_(3.0), p_calc_(p_calc) {
49  setSize(nx, ny);
50  }
51  virtual ~Expander() {}
52  virtual bool calculatePotentials(unsigned char* costs, double start_x, double start_y, double end_x, double end_y,
53  int cycles, float* potential) = 0;
54 
60  virtual void setSize(int nx, int ny) {
61  nx_ = nx;
62  ny_ = ny;
63  ns_ = nx * ny;
64  }
65  void setLethalCost(unsigned char lethal_cost) {
66  lethal_cost_ = lethal_cost;
67  }
68  void setNeutralCost(unsigned char neutral_cost) {
69  neutral_cost_ = neutral_cost;
70  }
71  void setFactor(float factor) {
72  factor_ = factor;
73  }
74  void setHasUnknown(bool unknown) {
75  unknown_ = unknown;
76  }
77 
78  void clearEndpoint(unsigned char* costs, float* potential, int gx, int gy, int s){
79  int startCell = toIndex(gx, gy);
80  for(int i=-s;i<=s;i++){
81  for(int j=-s;j<=s;j++){
82  int n = startCell+i+nx_*j;
83  if(potential[n]<POT_HIGH)
84  continue;
85  float c = costs[n]+neutral_cost_;
86  float pot = p_calc_->calculatePotential(potential, c, n);
87  potential[n] = pot;
88  }
89  }
90  }
91 
92  protected:
93  inline int toIndex(int x, int y) {
94  return x + nx_ * y;
95  }
96 
97  int nx_, ny_, ns_;
98  bool unknown_;
99  unsigned char lethal_cost_, neutral_cost_;
100  int cells_visited_;
101  float factor_;
102  PotentialCalculator* p_calc_;
103 
104 };
105 
106 } //end namespace global_planner
107 #endif
global_planner::Expander::~Expander
virtual ~Expander()
Definition: expander.h:123
global_planner
Definition: astar.h:46
global_planner::Expander::cells_visited_
int cells_visited_
Definition: expander.h:172
global_planner::Expander::nx_
int nx_
Definition: expander.h:169
s
XmlRpcServer s
global_planner::Expander::setFactor
void setFactor(float factor)
Definition: expander.h:143
global_planner::Expander::ns_
int ns_
Definition: expander.h:169
POT_HIGH
#define POT_HIGH
Definition: planner_core.h:40
global_planner::Expander::calculatePotentials
virtual bool calculatePotentials(unsigned char *costs, double start_x, double start_y, double end_x, double end_y, int cycles, float *potential)=0
global_planner::Expander::p_calc_
PotentialCalculator * p_calc_
Definition: expander.h:174
global_planner::Expander::factor_
float factor_
Definition: expander.h:173
planner_core.h
global_planner::Expander::setNeutralCost
void setNeutralCost(unsigned char neutral_cost)
Definition: expander.h:140
global_planner::Expander::lethal_cost_
unsigned char lethal_cost_
Definition: expander.h:171
global_planner::Expander::clearEndpoint
void clearEndpoint(unsigned char *costs, float *potential, int gx, int gy, int s)
Definition: expander.h:150
global_planner::PotentialCalculator::calculatePotential
virtual float calculatePotential(float *potential, unsigned char cost, int n, float prev_potential=-1)
Definition: potential_calculator.h:123
global_planner::Expander::ny_
int ny_
Definition: expander.h:169
global_planner::Expander::Expander
Expander(PotentialCalculator *p_calc, int nx, int ny)
Definition: expander.h:119
global_planner::Expander::unknown_
bool unknown_
Definition: expander.h:170
global_planner::Expander::neutral_cost_
unsigned char neutral_cost_
Definition: expander.h:171
global_planner::Expander::setLethalCost
void setLethalCost(unsigned char lethal_cost)
Definition: expander.h:137
global_planner::Expander::toIndex
int toIndex(int x, int y)
Definition: expander.h:165
potential_calculator.h
global_planner::Expander::setHasUnknown
void setHasUnknown(bool unknown)
Definition: expander.h:146


global_planner
Author(s): David Lu!!
autogenerated on Mon Mar 6 2023 03:50:40