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 bool calculatePotentials(unsigned char* costs, double start_x, double start_y, double end_x, double end_y,
52  int cycles, float* potential) = 0;
53 
59  virtual void setSize(int nx, int ny) {
60  nx_ = nx;
61  ny_ = ny;
62  ns_ = nx * ny;
63  }
64  void setLethalCost(unsigned char lethal_cost) {
65  lethal_cost_ = lethal_cost;
66  }
67  void setNeutralCost(unsigned char neutral_cost) {
68  neutral_cost_ = neutral_cost;
69  }
70  void setFactor(float factor) {
71  factor_ = factor;
72  }
73  void setHasUnknown(bool unknown) {
74  unknown_ = unknown;
75  }
76 
77  void clearEndpoint(unsigned char* costs, float* potential, int gx, int gy, int s){
78  int startCell = toIndex(gx, gy);
79  for(int i=-s;i<=s;i++){
80  for(int j=-s;j<=s;j++){
81  int n = startCell+i+nx_*j;
82  if(potential[n]<POT_HIGH)
83  continue;
84  float c = costs[n]+neutral_cost_;
85  float pot = p_calc_->calculatePotential(potential, c, n);
86  potential[n] = pot;
87  }
88  }
89  }
90 
91  protected:
92  inline int toIndex(int x, int y) {
93  return x + nx_ * y;
94  }
95 
96  int nx_, ny_, ns_;
97  bool unknown_;
98  unsigned char lethal_cost_, neutral_cost_;
100  float factor_;
102 
103 };
104 
105 } //end namespace global_planner
106 #endif
virtual float calculatePotential(float *potential, unsigned char cost, int n, float prev_potential=-1)
void setLethalCost(unsigned char lethal_cost)
Definition: expander.h:64
virtual void setSize(int nx, int ny)
Sets or resets the size of the map.
Definition: expander.h:59
unsigned char lethal_cost_
Definition: expander.h:98
#define POT_HIGH
Definition: planner_core.h:40
void clearEndpoint(unsigned char *costs, float *potential, int gx, int gy, int s)
Definition: expander.h:77
int toIndex(int x, int y)
Definition: expander.h:92
unsigned char neutral_cost_
Definition: expander.h:98
Expander(PotentialCalculator *p_calc, int nx, int ny)
Definition: expander.h:47
PotentialCalculator * p_calc_
Definition: expander.h:101
void setHasUnknown(bool unknown)
Definition: expander.h:73
virtual bool calculatePotentials(unsigned char *costs, double start_x, double start_y, double end_x, double end_y, int cycles, float *potential)=0
void setNeutralCost(unsigned char neutral_cost)
Definition: expander.h:67
void setFactor(float factor)
Definition: expander.h:70


global_planner
Author(s): David Lu!!
autogenerated on Thu Mar 12 2020 04:10:23