Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

FakeRoadSource.cc

Go to the documentation of this file.
00001 00005 #include <iostream> 00006 00007 #include <utils/ConfigFile.h> 00008 #include <TimeSource/TimeSource.h> 00009 00010 #include "RoadSource.h" 00011 00017 class FakeRoadSource : public RoadSource { 00018 public: 00020 virtual bool getPoints(utils::Time& time, 00021 std::vector<utils::Vec3d>& points, 00022 bool blocking = true); 00023 00025 bool init(utils::ConfigFile& params); 00026 00027 private: 00028 std::vector<utils::Vec3d> _points; // stored points to return 00029 }; 00030 00032 RoadSource* create_RoadSource_fake(RoadSourceGenerator*, 00033 utils::ConfigFile* params, 00034 utils::SymbolTable* globals) 00035 { 00036 FakeRoadSource* intf = new FakeRoadSource(); 00037 if (!intf->init(*params)) { 00038 delete intf; 00039 return NULL; 00040 } 00041 return intf; 00042 } 00043 00044 bool FakeRoadSource::init(utils::ConfigFile& params) 00045 { 00046 // read in the points: They are required 00047 // Note we use "double points" to force parsing as floating point if the 00048 // points field had no type specifier in the parameter file 00049 int num_pts = params.numValues("double points"); 00050 if (!num_pts) { 00051 cerr << "FakeRoadSource::init: No points\n"; 00052 return false; 00053 } 00054 // and you need at least 2 (6 numbers) 00055 if (num_pts < 6) { 00056 cerr << "FakeRoadSource::init: Not enough points\n"; 00057 return false; 00058 } 00059 double* points = new double[num_pts]; 00060 if (params.getDoubles("points", points, num_pts) != num_pts) { 00061 cerr << "FakeRoadSource::init: Error getting points\n"; 00062 return false; 00063 } 00064 00065 // make sure num_pts divisible by 3 00066 num_pts -= (num_pts % 3); 00067 00068 // and fill the _points vector 00069 for (int i=0;i<num_pts;i+=3) { 00070 _points.push_back(utils::Vec3d(points[i], points[i+1], points[i+2])); 00071 } 00072 00073 // clean up scratch memory 00074 delete [] points; 00075 00076 return true; 00077 } 00078 00079 bool FakeRoadSource::getPoints(utils::Time& time, 00080 std::vector<utils::Vec3d>& points, 00081 bool) 00082 { 00083 time = TimeSource::now(); 00084 points = _points; 00085 00086 return true; 00087 } 00088

Generated on Tue Sep 7 20:37:49 2004 for ModUtils by doxygen 1.3.8