INTRODUCTION
Overview
Download and Install
Quick Start
Documentation
Publications

NONFRAMEWORK CODE
Driver Interfaces
Drivers
Libraries
Utilities

FRAMEWORK CODE
Interfaces
Components
Libraries
Utilities

Full Software Listings

DEVELOPER
Tutorials
Examples
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

mapraytracer.h

00001 #ifndef HYDROOGMAP_MAPRAYTRACER_H
00002 #define HYDROOGMAP_MAPRAYTRACER_H
00003 
00004 #include <hydroogmap/raytracer.h>
00005 
00006 namespace hydroogmap {
00007 
00016 template<typename MapType,
00017          class MapCellTracer>
00018 class SOEXPORT MapRayTracer {
00019 
00020 public:
00021 
00022     MapRayTracer( MapType       &theMap,
00023                   MapCellTracer &mapCellTracer )
00024         : theMap_(theMap),
00025           uncheckedMapCellTracer_(mapCellTracer),
00026           uncheckedRayTracer_(uncheckedMapCellTracer_),
00027           safeMapCellTracer_(theMap,uncheckedMapCellTracer_),
00028           safeRayTracer_(safeMapCellTracer_)
00029         {}
00030 
00036     bool traceCells( const GridIndices &start, const GridIndices &destination )
00037         {
00038             if ( theMap_.cellWithinMap(start) &&
00039                  theMap_.cellWithinMap(destination) )
00040                 return uncheckedRayTracer_.trace( start.x, start.y, destination.x, destination.y );
00041             else
00042                 return safeRayTracer_.trace( start.x, start.y, destination.x, destination.y );
00043         }
00044     bool traceCells( int x0,int y0,  int x1,int y1 )
00045         { return traceCells( GridIndices(x0,y0), GridIndices(x1,y1) ); }
00046 
00048     bool traceCoords( const WorldCoords &start, const WorldCoords &destination )
00049         {
00050             return traceCells( theMap_.gridIndices(start), theMap_.gridIndices(destination) );
00051         }
00052     bool traceCoords( double x0,double y0,  double x1,double y1 )
00053         { return traceCoords( WorldCoords(x0,y0), WorldCoords(x1,y1) ); }
00054 
00055 private:
00056 
00057     class SafeMapCellTracer
00058     {
00059     public:
00060         SafeMapCellTracer( MapType       &theMap, 
00061                            MapCellTracer &uncheckedMapCellTracer )
00062             : theMap_(theMap),
00063               uncheckedMapCellTracer_(uncheckedMapCellTracer)
00064             {}
00065 
00068         inline bool traceCell(int x, int y)
00069             {
00070                 if ( !theMap_.cellWithinMap( x, y ) )
00071                 {
00072                     // Outside the map: stop tracing.
00073                     uncheckedMapCellTracer_.traceLeftMap( x, y );
00074                     return false;
00075                 }
00076                 else
00077                 {
00078                     return uncheckedMapCellTracer_.traceCell( x, y );
00079                 }
00080             }
00081 
00082         inline void traceSucceeded( int x, int y )
00083             { uncheckedMapCellTracer_.traceSucceeded(x,y); }
00084 
00085     private:
00086 
00087         MapType       &theMap_;
00088         MapCellTracer &uncheckedMapCellTracer_;
00089     };
00090 
00091     MapType &theMap_;
00092 
00093     // Use this if we don't care about the exact endpoint, and 
00094     // we know we're gonna stay on the map
00095     MapCellTracer            &uncheckedMapCellTracer_;
00096     RayTracer<MapCellTracer>  uncheckedRayTracer_;
00097 
00098     // Use this if we're gonna go off the map, and we want to know when
00099     SafeMapCellTracer            safeMapCellTracer_;
00100     RayTracer<SafeMapCellTracer> safeRayTracer_;
00101 };
00102 
00103 }
00104 
00105 #endif
 

Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)


Generated for Orca Robotics by  doxygen 1.4.5