Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | 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 UTILS_INTF_CREATOR(RoadSource, fake, gen, params, globals)
00033 {
00034   UTILS_INTF_REPORT(RoadSource, fake);
00035   FakeRoadSource* intf = new FakeRoadSource();
00036   if (!intf->init(*params)) {
00037     delete intf;
00038     return NULL;
00039   }
00040   return intf;
00041 }
00042 
00043 bool FakeRoadSource::init(utils::ConfigFile& params)
00044 {
00045   // read in the points:  They are required
00046   // Note we use "double points" to force parsing as floating point if the
00047   // points field had no type specifier in the parameter file
00048   int num_pts = params.numValues("double points");
00049   if (!num_pts) {
00050     cerr << "FakeRoadSource::init: No points\n";
00051     return false;
00052   }
00053   // and you need at least 2 (6 numbers)
00054   if (num_pts < 6) {
00055     cerr << "FakeRoadSource::init: Not enough points\n";
00056     return false;
00057   }
00058   double* points = new double[num_pts];
00059   if (params.getDoubles("points", points, num_pts) != num_pts) {
00060     cerr << "FakeRoadSource::init: Error getting points\n";
00061     return false;
00062   }
00063   
00064   // make sure num_pts divisible by 3
00065   num_pts -= (num_pts % 3);
00066 
00067   // and fill the _points vector
00068   for (int i=0;i<num_pts;i+=3) {
00069     _points.push_back(utils::Vec3d(points[i], points[i+1], points[i+2]));
00070   }
00071 
00072   // clean up scratch memory
00073   delete [] points;
00074 
00075   return true;
00076 }
00077 
00078 bool FakeRoadSource::getPoints(utils::Time& time,
00079                                std::vector<utils::Vec3d>& points,
00080                                bool)
00081 {
00082   time = TimeSource::now();
00083   points = _points;
00084 
00085   return true;
00086 }
00087 

Generated on Fri Jun 16 13:21:19 2006 for ModUtils by  doxygen 1.4.4