00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef PROJECTOR_H
00025 #define PROJECTOR_H
00026
00027 #include "experimentsconfig.h"
00028 #include "wmatrix.h"
00029 #include "mathutils.h"
00030
00031 namespace farsa {
00032
00036 class FARSA_EXPERIMENTS_TEMPLATE ImagePoint {
00037 public:
00043 ImagePoint() :
00044 x(0.0),
00045 y(0.0),
00046 valid(false)
00047 {
00048 }
00049
00057 ImagePoint(double _x, double _y) :
00058 x(_x),
00059 y(_y),
00060 valid(true)
00061 {
00062 }
00063
00069 bool isValid() const
00070 {
00071 return valid;
00072 }
00073
00077 double x;
00078
00082 double y;
00083
00087 bool valid;
00088 };
00089
00097 class FARSA_EXPERIMENTS_TEMPLATE Projector
00098 {
00099 public:
00103 Projector() :
00104 m_horizontalAperture(112.0),
00105 m_verticalAperture(94.0),
00106 m_halfImageWidth(0.0),
00107 m_halfImageHeight(0.0),
00108 m_inverseEyeMatrix(),
00109 m_imagePoint()
00110 {
00111
00112
00113 m_halfImageWidth = 1.0 * tan(deg2rad(m_horizontalAperture / 2.0));
00114 m_halfImageHeight = 1.0 * tan(deg2rad(m_verticalAperture / 2.0));
00115 };
00116
00124 void setEyeMatrix(const wMatrix &eye)
00125 {
00126 m_inverseEyeMatrix = eye.inverse();
00127 }
00128
00135 void set3DPointWorld(const wVector &point)
00136 {
00137 set3DPointEye(m_inverseEyeMatrix.transformVector(point));
00138 }
00139
00146 void set3DPointEye(const wVector &point)
00147 {
00148
00149
00150
00151
00152
00153
00154
00155 m_imagePoint.x = -point.y / point.z;
00156 m_imagePoint.y = -point.x / point.z;
00157
00158 if(point.z >= 0)
00159 m_imagePoint.valid = true;
00160 else
00161 m_imagePoint.valid = false;
00162 }
00163
00171 const ImagePoint& getImagePoint() const
00172 {
00173 return m_imagePoint;
00174 }
00175
00185 ImagePoint getImagePoint01() const
00186 {
00187 ImagePoint p((m_imagePoint.x + m_halfImageWidth) / (2.0 * m_halfImageWidth), (m_imagePoint.y + m_halfImageHeight) / (2.0 * m_halfImageHeight));
00188 return p;
00189 }
00190
00196 bool pointInsideImage() const
00197 {
00198 return (m_imagePoint.x <= m_halfImageWidth) && (m_imagePoint.x >= -m_halfImageWidth) &&
00199 (m_imagePoint.y <= m_halfImageHeight) && (m_imagePoint.y >= -m_halfImageHeight)
00200 && m_imagePoint.valid;
00201 }
00202
00203 private:
00207 double m_horizontalAperture;
00208
00212 double m_verticalAperture;
00213
00221 double m_halfImageWidth;
00222
00230 double m_halfImageHeight;
00231
00239 wMatrix m_inverseEyeMatrix;
00240
00245 ImagePoint m_imagePoint;
00246 };
00247
00248 }
00249
00250 #endif