00001
00013 #ifndef LGL_VISIBILITYMAP_HPP
00014 #define LGL_VISIBILITYMAP_HPP
00015
00016 #include <lgl/GeoData.hpp>
00017 #include <lgl/VisibleArea.hpp>
00018
00019 #include <vector>
00020 #include <set>
00021 #include <map>
00022
00023 #ifndef DEFAULT_VIEW_LENGTH
00024 #define DEFAULT_VIEW_LENGTH 10.0 // in term of "pixel" (in GEODATA_VISIBILITY_(HEIGHT_)BAND resolution)
00025 #endif
00026
00027
00028
00029
00030
00031 #ifndef DEFAULT_SENSORS_HEIGHT
00032 #define DEFAULT_SENSORS_HEIGHT 1.0 // meter(s)
00033 #endif
00034
00035 #ifndef DEFAULT_MAX_HEIGHT
00036 #define DEFAULT_MAX_HEIGHT 5.0 // meters
00037 #endif
00038
00039
00040
00041 #ifndef MIN_VISIBILITY_VALUE
00042 #define MIN_VISIBILITY_VALUE 0.3
00043 #endif
00044
00045 #ifndef PI
00046 #define PI 3.14159265
00047 #endif
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 namespace jafar {
00066 namespace lgl {
00067
00071 class CellRay {
00073 public :
00074 unsigned int id;
00075 double dist;
00076
00077 CellRay(){}
00078
00079 CellRay(int _id, double _dist ) :
00080 id(_id),
00081 dist(_dist)
00082 {}
00083
00084 ~CellRay(){}
00085 } ;
00086
00089 class PatternPoint {
00091 public :
00092 int x;
00093 int y;
00094 std::vector< CellRay > rays ;
00095
00096 PatternPoint(){}
00097
00098 PatternPoint(int _x, int _y, std::vector<CellRay > _rays ) :
00099 x(_x),
00100 y(_y),
00101 rays(_rays)
00102 {}
00103
00104 ~PatternPoint(){}
00105 } ;
00106
00107
00113 class VisibilityMap {
00115 private :
00116
00117
00118 GeoData * pt_Geodata;
00119
00120 int viewLength ;
00121
00122 double sensorsHeight ;
00123
00124 int maxHeight ;
00125
00126
00127
00128 unsigned long int xsize ;
00129 unsigned long int ysize ;
00130
00131
00132 std::vector<VisibleArea> visibilityMap;
00133
00134
00135 std::vector<PatternPoint> currentPattern ;
00136
00137
00138 std::vector< std::pair<bool, VisibleArea> > od_visibilityMap;
00139
00140
00141 int n ;
00142
00143
00144 double alpha ;
00145
00151 void computePattern();
00152
00155 void findVisibleCells(const int i, const int j, std::vector<RasterCellIndex> &cellList, std::vector<double> &raysRatio );
00156
00159 PatternPoint computeCurrentPoint(const int i, const int j);
00160
00163 double computeAngle( const int i, const int j);
00164
00168 double computeDistance( const int i1, const int j1,
00169 const int i2, const int j2,
00170 const int i3, const int j3,
00171 const double a3,
00172 const int r
00173 );
00174
00177 bool findIntersection( double &x, double &y, const int i1, const int j1, const int i2, const int j2, const double angle);
00178
00179
00180 public:
00181
00184 VisibilityMap() : pt_Geodata (NULL),
00185 viewLength (DEFAULT_VIEW_LENGTH),
00186 sensorsHeight ( (DEFAULT_SENSORS_HEIGHT * 255 ) / DEFAULT_MAX_HEIGHT),
00187 maxHeight(DEFAULT_MAX_HEIGHT),
00188 xsize(0),
00189 ysize(0)
00190 {
00191 visibilityMap.clear() ;
00192
00193 od_visibilityMap.clear();
00194 }
00195
00196
00199 VisibilityMap( GeoData * _pt_Geodata = NULL,
00200 int _viewLength = DEFAULT_VIEW_LENGTH,
00201 double _sensorsHeight = DEFAULT_SENSORS_HEIGHT,
00202 int _maxHeight = DEFAULT_MAX_HEIGHT
00203 );
00204
00207 ~VisibilityMap();
00208
00212 bool computeWholeVisibility() ;
00213
00216 bool clearVisibility() ;
00217
00225 bool computePartialVisibility(std::map<Cell_ID,VisibleArea> &partialVisibilityMap, const std::set<Cell_ID> &cellSet) ;
00226
00230 bool computeVisibilityOnDemand(std::map<Cell_ID,VisibleArea> &partialVisibilityMap, const std::set<Cell_ID> &cellSet) ;
00231
00232
00233 bool computeVisibilityOnDemand(std::map<Cell_ID,const VisibleArea*> &partialVisibilityMap, const std::set<Cell_ID> &cellSet) ;
00234
00238
00239
00240 VisibleArea getVisibility(int i, int j) const ;
00241
00242
00243 const VisibleArea* getPtVisibility(int i, int j) const ;
00244
00245
00246
00247
00248
00249 const VisibleArea* getPtVisibilityOnDemand(Cell_ID cell) ;
00250
00251
00252
00253
00254 bool getPrecomputedVisibility(std::map<Cell_ID,VisibleArea> &partialVisibilityMap, const std::set<Cell_ID> &cellSet) ;
00255
00256
00257 bool getPrecomputedVisibility(std::map<Cell_ID, const VisibleArea*> &partialVisibilityMap, const std::set<Cell_ID> &cellSet) ;
00258
00259
00260 bool isVisible(const Cell_ID cell) const;
00261
00262 int getxsize() const;
00263 int getysize() const;
00264
00265 int getviewLength() const;
00266
00267 int getn() const;
00268 double getalpha() const;
00269
00270 };
00271
00272
00273
00274 }
00275 }
00276
00277 #endif