00001
00002
00003 #ifndef SIMU_ENVIRONMENT_HPP
00004 #define SIMU_ENVIRONMENT_HPP
00005
00006 #include <vector>
00007
00008 #include "jmath/jblas.hpp"
00009 #include "jmath/random.hpp"
00010 #include "geom/Declarations.hpp"
00011
00012 namespace jafar {
00013 namespace simu {
00014
00015 using namespace jafar;
00016
00017 class Robot;
00018
00023 class Point {
00024
00025 public:
00026
00027 unsigned int id;
00028 jblas::vec x;
00029
00030 Point(unsigned int id_, jblas::vec const& x_);
00031
00032 inline double getX() const { return x(0); }
00033 inline double getY() const { return x(1); }
00034 inline double getZ() const { return x(2); }
00035
00036 };
00037
00038 std::ostream& operator <<(std::ostream& s, const Point& p_);
00039
00040 class PointFactory {
00041 public:
00042
00043 PointFactory(const jblas::vec& xMin_, const jblas::vec& xMax_,
00044 unsigned int randomSeed=1);
00045
00046 Point getRandomPoint(unsigned int idFactory_);
00047
00048 protected:
00049 jafar::jmath::MultiDimUniformDistribution random;
00050 };
00051
00052
00053 class Segment {
00054
00055 public:
00056
00057 unsigned int id;
00058
00059 jblas::vec3 ext1;
00060 jblas::vec3 ext2;
00061
00062 Segment(unsigned int id_, jblas::vec3 const& x1_, jblas::vec3 const& x2_);
00063 inline double getX1() const { return ext1(0); }
00064 inline double getY1() const { return ext1(1); }
00065 inline double getZ1() const { return ext1(2); }
00066 inline double getX2() const { return ext2(0); }
00067 inline double getY2() const { return ext2(1); }
00068 inline double getZ2() const { return ext2(2); }
00069
00070 };
00071
00072 std::ostream& operator <<(std::ostream& s, Segment const& s_);
00073
00074 class SegmentFactory {
00075
00076 public:
00077
00078 SegmentFactory(const jblas::vec& xMin_, const jblas::vec& xMax_,
00079 double lengthMin_, double lengthMax_,
00080 unsigned int randomSeed=1);
00081
00082 Segment getRandomSegment(unsigned int idFactory_);
00083
00084 protected:
00085
00086 jafar::jmath::MultiDimUniformDistribution extremity;
00087 jafar::jmath::UniformDistribution directionTheta;
00088 jafar::jmath::UniformDistribution directionPhi;
00089 jafar::jmath::UniformDistribution length;
00090
00091 };
00092
00098 class Environment {
00099
00100 public:
00101
00102 jblas::vec xMin;
00103 jblas::vec xMax;
00104
00105 typedef std::list<Point> PointsListType;
00106 PointsListType pointsList;
00107
00108 PointsListType persistenPointsList;
00109
00110
00111 typedef std::list<Segment> SegmentsListType;
00112 SegmentsListType segmentsList;
00113
00114 Environment(const jblas::vec& xMin_, const jblas::vec& xMax_,
00115 double segLengthMin_ = 1.0, double segLengthMax_ = 3.0,
00116 unsigned int randomSeedPt = 1, unsigned int randomSeedSeg = 1);
00117
00118 ~Environment();
00119
00120 void addRobot(Robot* robot_);
00121
00122 unsigned int addPoint(jblas::vec const& feature_);
00123 unsigned int addPoint(double x, double y, double z);
00124
00125 unsigned int addPersistentPoint(double x, double y, double z);
00126
00127 unsigned int addSegment(double x1, double y1, double z1, double x2, double y2, double z2);
00128
00129 void addPoints( const std::list<geom::Point3D>& points );
00130 void addSegments( const std::list<geom::Segment3D>& segments );
00131 void addRandomPoints(int nb_=1);
00132 void addRandomSegments(int nb_=1);
00133
00134 void addAlignedPoints(const jblas::vec& x1_, const jblas::vec& x2_, int nbFeatures_, bool bothExt_=true);
00135
00136 const std::list<Point>& getPointsList() const;
00137 const std::list<Segment>& getSegmentsList() const;
00138 std::list<geom::Segment3D> getSegments3DList() const;
00144 std::list<geom::Segment3D> getSegments3DNear(double x, double y, double z, double distance, const jblas::bounded_symmetric_matrix<double, 4 >* cov1 = 0, const jblas::bounded_symmetric_matrix<double, 4 >* cov2 = 0, const jblas::mat44* M = 0, jmath::NormalDistribution* normalDist = 0);
00145 std::string getPointsTclList() const;
00146
00147 std::string getSegmentsTclList() const;
00148
00149 protected:
00150
00151 std::vector<Robot*> robots;
00152
00153 PointFactory pointFactory;
00154
00155 SegmentFactory segmentFactory;
00156
00157 unsigned int idFactory;
00158 unsigned int generateId();
00159
00160 friend std::ostream& operator <<(std::ostream& s, const Environment& e_);
00161 };
00162
00163 std::ostream& operator <<(std::ostream& s, const Environment& e_);
00164
00165 }
00166 }
00167
00168 #endif // SIMU_ENVIRONMENT_HPP