Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VisibilityMap.hpp
Go to the documentation of this file.
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 // NB : Note on the scale
00028 //    in the bitmap, a value is between 0 and 255
00029 //    in geodata, a value is between 0 and 1
00030 //    In both case, maximal value (255 and 1) is = MAX_HEIGHT (here, DEFAULT_MAX_HEIGHT) 
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 // a cell must have a minimal visibility value
00040 // (remind you that 0 < visibility_value < 1 in geodata VISIBILITY_Band
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 // NOTA BENE :
00050 // this class compute visibility over a bitmap map
00051 // BUT this uses discrete cells (of course) and discrete rays (line of view ; not a disk)
00052 // so there may be some special case with few odd results
00053 // (as a non visible cell surrounded by visible cells, 
00054 // or a ligne a visible cells surronded by non-visible cells)
00055 //
00056 // This cannot be avoid by now, though it could be limited by increasing
00057 // the resolution (size of cells and number of rays).
00058 // But beware of computation and memory ressources needed...
00059 //
00060 // The problem of continuity could probably be handled through Morphology.
00061 // But it has not been implemented yet... (TODO)
00062 //
00063 // Cyril Robin - may 2011
00064 
00065 namespace jafar { //namespace jafar
00066   namespace lgl { //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 ; // rays number (first) and related distance (second)
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         // Input Data
00118         GeoData * pt_Geodata;           // Pointer for the currently used geodata.
00119 
00120         int viewLength ;            // Max length for the field of view (pixels)
00121 
00122         double sensorsHeight ;          // Height of the sensors ; impact the visibility
00123         
00124         int maxHeight ;             // Maximal Height in the map
00125                             // such that 255 in the bitmap (=1 in Geodata) = maxHeight in reality
00126             
00127         // size of environment
00128         unsigned long int xsize ; // 2N+1 : vertices
00129         unsigned long int ysize ; // 2N+1 : vertices
00130 
00131         // visibleArea matrix
00132         std::vector<VisibleArea> visibilityMap; 
00133         
00134         // Pattern for visibility computing
00135         std::vector<PatternPoint> currentPattern ;
00136 
00137         // visibleArea matrix for computation "on demand"
00138         std::vector< std::pair<bool, VisibleArea> > od_visibilityMap; 
00139         
00140         // number of rays use for visibility computing
00141         int n ;
00142 
00143         // angular step between rays
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         /* idem as above, with pointers */
00233         bool computeVisibilityOnDemand(std::map<Cell_ID,const VisibleArea*> &partialVisibilityMap, const std::set<Cell_ID> &cellSet) ;  
00234 
00238         /* Return a copy of the visible Area of the node (i,j)
00239          */
00240         VisibleArea getVisibility(int i, int j) const ;
00241 
00242         /* idem as above, with pointers */
00243         const VisibleArea* getPtVisibility(int i, int j) const ;
00244 
00245         /* idem as above, with pointers, but use the "On Demand" features 
00246          * (ie compute the visibility if it has not been pre-computed already) 
00247          * BEWARE : this is NOT a const function !
00248          */
00249         const VisibleArea* getPtVisibilityOnDemand(Cell_ID cell) ;
00250 
00251         /* get the visibility for a set of position, using visibilityMap
00252          * NB: if visibilityMap has not been computed yet, compute visibilityMap.
00253          */
00254         bool getPrecomputedVisibility(std::map<Cell_ID,VisibleArea> &partialVisibilityMap, const std::set<Cell_ID> &cellSet) ;  
00255 
00256         /* idem as above, with pointers */
00257         bool getPrecomputedVisibility(std::map<Cell_ID, const VisibleArea*> &partialVisibilityMap, const std::set<Cell_ID> &cellSet) ;  
00258 
00259         /* tell is a cell is visible or not  (ie if its VISIBILITY_BAND value is above the MIN_VALUE*/
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 //    std::ostream& operator<<(std::ostream& out, const VisibilityMap &_visibilityMap);
00273   
00274   } // end of namespace lgl
00275 } // end of namespace jafar
00276 
00277 #endif /* LGL_VISIBILITYMAP_HPP */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:24 for Jafar by doxygen 1.7.6.1
LAAS-CNRS