grid-functors.h
Go to the documentation of this file.
00001 #ifndef __GRID_FUNCTORS_H
00002 #define __GRID_FUNCTORS_H
00003 
00004 #include "gridmap/grid-map.h"
00005 
00006 struct MapCorrelation
00007 {
00008         GridMap& map;
00009         long long int correlation;
00010         int pointCount;
00011         
00012         MapCorrelation(GridMap& map) : map(map), correlation(0), pointCount(0) {}
00013         
00014         bool operator()(const int x, const int y, const int texVal, const bool reverseScan)
00015         {
00016                 const long long int iMapVal(map.atInternalCoord(x, y) / 4);
00017                 correlation += texVal * iMapVal;
00018                 ++pointCount;
00019                 return true;
00020         }
00021 };
00022 
00023 struct MapUpdater
00024 {
00025         GridMap& map;
00026         
00027         MapUpdater(GridMap& map) : map(map) {}
00028         
00029         bool operator()(const int x, const int y, const int texVal, const bool reverseScan)
00030         {
00031                 GridMap::Value& mapVal(map.atInternalCoord(x, y));
00032                 int iMapVal(mapVal);
00033                 iMapVal += texVal;
00034                 mapVal = GridMap::saturatedValueFromInt(iMapVal);
00035                 return true;
00036         }
00037 };
00038 
00039 struct MapConstUpdater
00040 {
00041         GridMap& map;
00042         const int value;
00043         
00044         MapConstUpdater(GridMap& map, const int value) : map(map), value(value) {}
00045         
00046         bool operator()(const int x, const int y, const int texVal, const bool reverseScan)
00047         {
00048                 GridMap::Value& mapVal(map.atInternalCoord(x, y));
00049                 int iMapVal(mapVal);
00050                 iMapVal += value;
00051                 mapVal = GridMap::saturatedValueFromInt(iMapVal);
00052                 return true;
00053         }
00054 };
00055 
00056 struct MapWallFinder
00057 {
00058         GridMap& map;
00059         const GridMap::Value wallSeen;
00060         int wallX, wallY;
00061         
00062         MapWallFinder(GridMap& map, const GridMap::Value wallSeen = 0) : map(map), wallSeen(wallSeen), wallX(-1), wallY(-1) {}
00063         
00064         bool operator()(const int x, const int y, const int texVal, const bool reverseScan)
00065         {
00066                 // if we have seen a wall twice, with > 90 % probability each time, we are confident it is a wall
00067                 // as update function set prob value at 0 on wall, consider that as well there
00068                 const GridMap::Value& mapValue(map.atInternalCoord(x, y));
00069                 if (mapValue > wallSeen)
00070                 {
00071                         wallX = x;
00072                         wallY = y;
00073                         if (!reverseScan)
00074                                 return false;
00075                 }
00076                 return true;
00077         }
00078         
00079         void clearWall()
00080         {
00081                 wallX = -1;
00082                 wallY = -1;
00083         }
00084 };
00085 
00086 struct MapEndOfAreaFinder
00087 {
00088         const GridMap& map;
00089         int eoaX, eoaY;
00090         const GridMap::Value areaLabel;
00091         
00092         MapEndOfAreaFinder(const GridMap& map, const GridMap::Value areaLabel) : map(map), eoaX(-1), eoaY(-1), areaLabel(areaLabel) {}
00093         
00094         bool operator()(const int x, const int y, const int texVal, const bool reverseScan)
00095         {
00096                 // if we see another label, that means the end of this one
00097                 const GridMap::Value& mapValue(map.atInternalCoord(x, y));
00098                 if (mapValue != areaLabel)
00099                 {
00100                         eoaX = x;
00101                         eoaY = y;
00102                         if (!reverseScan)
00103                                 return false;
00104                 }
00105                 return true;
00106         }
00107         
00108         void clearEndOfArea()
00109         {
00110                 eoaX = -1;
00111                 eoaY = -1;
00112         }
00113 };
00114 
00115 struct Drawer
00116 {
00117         GridMap& map;
00118         
00119         Drawer(GridMap& map) : map(map) {}
00120         
00121         bool operator()(const int x, const int y, const int texVal, const bool reverseScan)
00122         {
00123                 map.atInternalCoord(x,y) = texVal ;
00124                 return true;
00125         }
00126 };
00127 
00128 #endif // __GRID_FUNCTORS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


gridmap
Author(s): Stéphane Magnenat
autogenerated on Tue Nov 20 2012 16:28:24