00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __2DGRIDSEARCH_H_
00030 #define __2DGRIDSEARCH_H_
00031
00032 #define SBPL_2DGRIDSEARCH_NUMOF2DDIRS 16
00033
00034 #define SBPL_2DSEARCH_OPEN_LIST_ID 0
00035
00036 enum SBPL_2DGRIDSEARCH_TERM_CONDITION {SBPL_2DGRIDSEARCH_TERM_CONDITION_OPTPATHFOUND, SBPL_2DGRIDSEARCH_TERM_CONDITION_20PERCENTOVEROPTPATH, SBPL_2DGRIDSEARCH_TERM_CONDITION_TWOTIMESOPTPATH,
00037 SBPL_2DGRIDSEARCH_TERM_CONDITION_THREETIMESOPTPATH, SBPL_2DGRIDSEARCH_TERM_CONDITION_ALLCELLS};
00038
00039 enum SBPL_2DGRIDSEARCH_OPENTYPE {SBPL_2DGRIDSEARCH_OPENTYPE_HEAP, SBPL_2DGRIDSEARCH_OPENTYPE_SLIDINGBUCKETS};
00040
00041
00042 #define SBPL_2DGRIDSEARCH_HEUR2D(x,y) ((int)(1000*cellSize_m_*__max(abs(x-goalX_),abs(y-goalY_))))
00043
00046 class SBPL_2DGridSearchState : public AbstractSearchState
00047 {
00048 public:
00049
00052 int x,y;
00053
00056 int g;
00059 int iterationaccessed;
00060
00061 public:
00062 SBPL_2DGridSearchState() {iterationaccessed = 0;};
00063 ~SBPL_2DGridSearchState() {};
00064
00065 };
00066
00067
00068
00069 class CIntHeap;
00070 class CSlidingBucket;
00071
00074 class SBPL2DGridSearch
00075 {
00076 public:
00077
00078 SBPL2DGridSearch(int width_x, int height_y, float cellsize_m);
00079 ~SBPL2DGridSearch(){destroy();}
00080
00083 bool setOPENdatastructure(SBPL_2DGRIDSEARCH_OPENTYPE OPENtype);
00084
00087 void destroy();
00088
00095 bool search(unsigned char** Grid2D, unsigned char obsthresh, int startx_c, int starty_c, int goalx_c, int goaly_c, SBPL_2DGRIDSEARCH_TERM_CONDITION termination_condition);
00096
00099 void printvalues();
00100
00103 inline int getlowerboundoncostfromstart_inmm(int x, int y)
00104 {
00105 if(term_condition_usedlast == SBPL_2DGRIDSEARCH_TERM_CONDITION_OPTPATHFOUND)
00106 {
00107
00108 int h = SBPL_2DGRIDSEARCH_HEUR2D(x,y);
00109
00110 return ( (searchStates2D_[x][y].iterationaccessed == iteration_ && searchStates2D_[x][y].g+h <= largestcomputedoptf_) ?
00111 searchStates2D_[x][y].g:(largestcomputedoptf_ < INFINITECOST?largestcomputedoptf_-h:INFINITECOST));
00112 }
00113 else
00114 {
00115
00116
00117 return ( (searchStates2D_[x][y].iterationaccessed == iteration_ && searchStates2D_[x][y].g <= largestcomputedoptf_) ?
00118 searchStates2D_[x][y].g:largestcomputedoptf_);
00119
00120 }
00121 };
00122
00125 int getlargestcomputedoptimalf_inmm() {return largestcomputedoptf_;};
00126
00127
00128 private:
00129
00130 inline bool withinMap(int x, int y) {return (x >= 0 && y >= 0 && x < width_ && y < height_);};
00131 void computedxy();
00132 inline void initializeSearchState2D(SBPL_2DGridSearchState* state2D);
00133 bool createSearchStates2D(void);
00134
00135 bool search_withheap(unsigned char** Grid2D, unsigned char obsthresh, int startx_c, int starty_c, int goalx_c, int goaly_c,
00136 SBPL_2DGRIDSEARCH_TERM_CONDITION termination_condition);
00137 bool search_exp(unsigned char** Grid2D, unsigned char obsthresh, int startx_c, int starty_c, int goalx_c, int goaly_c);
00138 bool search_withbuckets(unsigned char** Grid2D, unsigned char obsthresh, int startx_c, int starty_c, int goalx_c, int goaly_c);
00139 bool search_withslidingbuckets(unsigned char** Grid2D, unsigned char obsthresh, int startx_c, int starty_c, int goalx_c, int goaly_c,
00140 SBPL_2DGRIDSEARCH_TERM_CONDITION termination_condition);
00141
00142
00143
00144 CSlidingBucket* OPEN2DBLIST_;
00145 CIntHeap* OPEN2D_;
00146 SBPL_2DGridSearchState** searchStates2D_;
00147 int dx_[SBPL_2DGRIDSEARCH_NUMOF2DDIRS];
00148 int dy_[SBPL_2DGRIDSEARCH_NUMOF2DDIRS];
00149
00150
00151 int dx0intersects_[SBPL_2DGRIDSEARCH_NUMOF2DDIRS];
00152 int dx1intersects_[SBPL_2DGRIDSEARCH_NUMOF2DDIRS];
00153 int dy0intersects_[SBPL_2DGRIDSEARCH_NUMOF2DDIRS];
00154 int dy1intersects_[SBPL_2DGRIDSEARCH_NUMOF2DDIRS];
00155
00156 int dxy_distance_mm_[SBPL_2DGRIDSEARCH_NUMOF2DDIRS];
00157
00158
00159 SBPL_2DGRIDSEARCH_OPENTYPE OPENtype_;
00160
00161
00162 int startX_, startY_;
00163 int goalX_, goalY_;
00164
00165
00166 int width_, height_;
00167 float cellSize_m_;
00168
00169
00170 int iteration_;
00171
00172
00173 int largestcomputedoptf_;
00174
00175
00176 SBPL_2DGRIDSEARCH_TERM_CONDITION term_condition_usedlast;
00177 };
00178 #endif
00179