Measures.h
Go to the documentation of this file.00001 #ifndef INCLUDED_Measures_h_
00002 #define INCLUDED_Measures_h_
00003
00004 #include "Shared/fmatCore.h"
00005
00006 #include <cmath>
00007
00008
00009 class PlaneEquation {
00010 private:
00011 fmat::Column<3> direction;
00012 float displacement;
00013 public:
00014 PlaneEquation(const fmat::Column<3> &dir, float disp);
00015 PlaneEquation(float a, float b, float c, float d);
00016 PlaneEquation() : direction(fmat::pack(0.f, 0.f, 1.f)), displacement(0) {}
00017 const fmat::Column<3>& getDirection() const { return direction; }
00018 void setDirection(const fmat::Column<3>& dir) { direction = dir / dir.norm(); }
00019
00020 float getDisplacement() const { return displacement; }
00021 void setDisplacement(float disp) { displacement = disp; }
00022
00023 float getZsign() const { return direction[2] < 0 ? -1.f : 1.f; }
00024 float getDsign() const { return displacement < 0 ? -1.f : 1.f; }
00025
00026
00027 template<class T> void exportTo(T& x) const { x[0]=direction[0]; x[1]=direction[1]; x[2]=direction[2]; x[3]=displacement; }
00028
00029 template<class T> void importFrom(const T& x) { direction[0]=x[0]; direction[1]=x[1]; direction[2]=x[2]; displacement=x[3]; }
00030 };
00031
00032 std::ostream& operator<<(std::ostream &os, const PlaneEquation& p);
00033
00034 typedef float coordinate_t;
00035 typedef float orientation_t;
00036 typedef float direction_t;
00037
00038 const direction_t Pi=static_cast<direction_t>(M_PI);
00039 const direction_t TwoPi=static_cast<direction_t>(2*M_PI);
00040
00041 typedef coordinate_t Slope;
00042 const Slope BIG_SLOPE=static_cast<Slope>(5000);
00043
00044
00045 class AngPi {
00046 friend AngPi angdist(AngPi const &arg1, AngPi const &arg2);
00047 public:
00048 AngPi(void) : value(0) {};
00049 AngPi(orientation_t const &v) : value(v) { normalize(); }
00050
00051 AngPi operator+(AngPi const &arg) const { return AngPi(value+arg.value); };
00052 AngPi operator-(AngPi const &arg) const { return AngPi(value-arg.value); };
00053 AngPi operator*(orientation_t const &arg) const { return AngPi(value*arg); };
00054 AngPi operator/(orientation_t const &arg) const { return AngPi(value/arg); };
00055
00056 AngPi& operator=(AngPi const &arg) { value = arg.value; return(*this); };
00057 AngPi& operator=(orientation_t const &arg) { value = arg; normalize(); return(*this); };
00058 AngPi& operator+=(orientation_t const &arg) { value += arg; normalize(); return(*this); };
00059 AngPi& operator-=(orientation_t const &arg) { value -= arg; normalize(); return(*this); };
00060 AngPi& operator*=(orientation_t const &arg) { value *= arg; normalize(); return(*this); };
00061 AngPi& operator/=(orientation_t const &arg) { value /= arg; normalize(); return(*this); };
00062
00063 operator orientation_t() const { return value; };
00064
00065 protected:
00066 void normalize();
00067 orientation_t value;
00068 };
00069
00070
00071 AngPi angdist(AngPi const &arg1, AngPi const &arg2);
00072
00073
00074 class AngTwoPi {
00075 friend AngPi angdist(AngTwoPi const &arg1, AngTwoPi const &arg2);
00076 public:
00077 AngTwoPi(void) : value(0) {};
00078 AngTwoPi(direction_t const &v) : value(v) { normalize(); }
00079
00080 AngTwoPi operator+(AngTwoPi const &arg) const { return AngTwoPi(value+arg.value); };
00081 AngTwoPi operator-(AngTwoPi const &arg) const { return AngTwoPi(value-arg.value); };
00082 AngTwoPi operator*(direction_t const &arg) const { return AngTwoPi(value*arg); };
00083 AngTwoPi operator/(direction_t const &arg) const { return AngTwoPi(value/arg); };
00084
00085 AngTwoPi& operator=(AngTwoPi const &arg) { value = arg.value; return(*this); };
00086 AngTwoPi& operator=(direction_t const &arg) { value = arg; normalize(); return(*this); };
00087 AngTwoPi& operator+=(direction_t const &arg) { value += arg; normalize(); return(*this); };
00088 AngTwoPi& operator-=(direction_t const &arg) { value -= arg; normalize(); return(*this); };
00089 AngTwoPi& operator*=(direction_t const &arg) { value *= arg; normalize(); return(*this); };
00090 AngTwoPi& operator/=(direction_t const &arg) { value /= arg; normalize(); return(*this); };
00091
00092 operator direction_t() const { return value; };
00093
00094 protected:
00095 void normalize();
00096 direction_t value;
00097 };
00098
00099
00100 AngPi angdist(AngTwoPi const &arg1, AngTwoPi const &arg2);
00101
00102
00103 class AngSignPi {
00104 friend AngPi angdist(AngSignPi const &arg1, AngSignPi const &arg2);
00105 public:
00106 AngSignPi(void) : value(0) {};
00107 AngSignPi(direction_t const &v) : value(v) { normalize(); }
00108
00109 AngSignPi operator+(AngSignPi const &arg) const { return AngSignPi(value+arg.value); };
00110 AngSignPi operator-(AngSignPi const &arg) const { return AngSignPi(value-arg.value); };
00111 AngSignPi operator*(direction_t const &arg) const { return AngSignPi(value*arg); };
00112 AngSignPi operator/(direction_t const &arg) const { return AngSignPi(value/arg); };
00113
00114 AngSignPi& operator=(AngSignPi const &arg) { value = arg.value; return(*this); };
00115 AngSignPi& operator=(direction_t const &arg) { value = arg; normalize(); return(*this); };
00116 AngSignPi& operator+=(direction_t const &arg) { value += arg; normalize(); return(*this); };
00117 AngSignPi& operator-=(direction_t const &arg) { value -= arg; normalize(); return(*this); };
00118 AngSignPi& operator*=(direction_t const &arg) { value *= arg; normalize(); return(*this); };
00119 AngSignPi& operator/=(direction_t const &arg) { value /= arg; normalize(); return(*this); };
00120
00121 operator direction_t() const { return value; };
00122
00123 protected:
00124 void normalize();
00125 direction_t value;
00126 };
00127
00128
00129 AngPi angdist(AngSignPi const &arg1, AngSignPi const &arg2);
00130
00131
00132 class AngSignTwoPi {
00133 public:
00134 AngSignTwoPi(void) : value(0) {};
00135 AngSignTwoPi(direction_t const &v) : value(v) { normalize(); }
00136
00137 AngSignTwoPi operator+(AngSignTwoPi const &arg) const { return AngSignTwoPi(value+arg.value); };
00138 AngSignTwoPi operator-(AngSignTwoPi const &arg) const { return AngSignTwoPi(value-arg.value); };
00139 AngSignTwoPi operator*(direction_t const &arg) const { return AngSignTwoPi(value*arg); };
00140 AngSignTwoPi operator/(direction_t const &arg) const { return AngSignTwoPi(value/arg); };
00141
00142 AngSignTwoPi& operator=(AngSignTwoPi const &arg) { value = arg.value; return(*this); };
00143 AngSignTwoPi& operator=(direction_t const &arg) { value = arg; normalize(); return(*this); };
00144 AngSignTwoPi& operator+=(direction_t const &arg) { value += arg; normalize(); return(*this); };
00145 AngSignTwoPi& operator-=(direction_t const &arg) { value -= arg; normalize(); return(*this); };
00146 AngSignTwoPi& operator*=(direction_t const &arg) { value *= arg; normalize(); return(*this); };
00147 AngSignTwoPi& operator/=(direction_t const &arg) { value /= arg; normalize(); return(*this); };
00148
00149 operator direction_t() const { return value; };
00150
00151 protected:
00152 void normalize();
00153 direction_t value;
00154 };
00155
00156 #endif