00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _STELPROJECTIONS_HPP_
00021 #define _STELPROJECTIONS_HPP_
00022
00023 #include "StelProjector.hpp"
00024
00025 class StelProjectorPerspective : public StelProjector
00026 {
00027 public:
00028 StelProjectorPerspective(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00029 virtual QString getNameI18() const;
00030 virtual QString getDescriptionI18() const;
00031 virtual float getMaxFov() const {return 120.f;}
00032 bool forward(Vec3d &v) const
00033 {
00034 const double r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00035 if (v[2] < 0) {
00036 v[0] /= (-v[2]);
00037 v[1] /= (-v[2]);
00038 v[2] = r;
00039 return true;
00040 }
00041 if (v[2] > 0) {
00042 v[0] /= v[2];
00043 v[1] /= v[2];
00044 v[2] = r;
00045 return false;
00046 }
00047 v[0] *= 1e99;
00048 v[1] *= 1e99;
00049 v[2] = r;
00050 return false;
00051 }
00052 bool backward(Vec3d &v) const;
00053 float fovToViewScalingFactor(float fov) const;
00054 float viewScalingFactorToFov(float vsf) const;
00055 float deltaZoom(float fov) const;
00056 protected:
00057 virtual bool hasDiscontinuity() const {return false;}
00058 virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return false;}
00059 };
00060
00061 class StelProjectorEqualArea : public StelProjector
00062 {
00063 public:
00064 StelProjectorEqualArea(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00065 virtual QString getNameI18() const;
00066 virtual QString getDescriptionI18() const;
00067 virtual float getMaxFov() const {return 360.f;}
00068 bool forward(Vec3d &v) const
00069 {
00070 const double r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00071 const double f = std::sqrt(2.0/(r*(r-v[2])));
00072 v[0] *= f;
00073 v[1] *= f;
00074 v[2] = r;
00075 return true;
00076 }
00077 bool backward(Vec3d &v) const;
00078 float fovToViewScalingFactor(float fov) const;
00079 float viewScalingFactorToFov(float vsf) const;
00080 float deltaZoom(float fov) const;
00081 protected:
00082 virtual bool hasDiscontinuity() const {return false;}
00083 virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return false;}
00084 };
00085
00086 class StelProjectorStereographic : public StelProjector
00087 {
00088 public:
00089 StelProjectorStereographic(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00090 virtual QString getNameI18() const;
00091 virtual QString getDescriptionI18() const;
00092 virtual float getMaxFov() const {return 235.;}
00093 bool forward(Vec3d &v) const
00094 {
00095 const double r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00096 const double h = 0.5*(r-v[2]);
00097 if (h <= 0.0) {
00098 v[0] = 1e99;
00099 v[1] = 1e99;
00100 v[2] = -1e99;
00101 return false;
00102 }
00103 const double f = 1.0 / h;
00104 v[0] *= f;
00105 v[1] *= f;
00106 v[2] = r;
00107 return true;
00108 }
00109
00110 virtual void project(int n, const Vec3d* in, Vec3f* out)
00111 {
00112 Vec3d v;
00113 for (int i = 0; i < n; ++i)
00114 {
00115 v = in[i];
00116 v.transfo4d(modelViewMatrix);
00117 StelProjectorStereographic::forward(v);
00118 out[i][0] = viewportCenter[0] + flipHorz * pixelPerRad * v[0];
00119 out[i][1] = viewportCenter[1] + flipVert * pixelPerRad * v[1];
00120 out[i][2] = (v[2] - zNear) * oneOverZNearMinusZFar;
00121 }
00122 }
00123
00124 bool backward(Vec3d &v) const;
00125 float fovToViewScalingFactor(float fov) const;
00126 float viewScalingFactorToFov(float vsf) const;
00127 float deltaZoom(float fov) const;
00128 protected:
00129 virtual bool hasDiscontinuity() const {return false;}
00130 virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return false;}
00131 };
00132
00133 class StelProjectorFisheye : public StelProjector
00134 {
00135 public:
00136 StelProjectorFisheye(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00137 virtual QString getNameI18() const;
00138 virtual QString getDescriptionI18() const;
00139 virtual float getMaxFov() const {return 180.00001;}
00140 bool forward(Vec3d &v) const
00141 {
00142 const double rq1 = v[0]*v[0] + v[1]*v[1];
00143 if (rq1 > 0.0) {
00144 const double h = std::sqrt(rq1);
00145 const double f = std::atan2(h,-v[2]) / h;
00146 v[0] *= f;
00147 v[1] *= f;
00148 v[2] = std::sqrt(rq1 + v[2]*v[2]);
00149 return true;
00150 }
00151 if (v[2] < 0.0) {
00152 v[0] = 0.0;
00153 v[1] = 0.0;
00154 v[2] = 1.0;
00155 return true;
00156 }
00157 v[0] = 1e99;
00158 v[1] = 1e99;
00159 v[2] = -1e99;
00160 return false;
00161 }
00162 bool backward(Vec3d &v) const;
00163 float fovToViewScalingFactor(float fov) const;
00164 float viewScalingFactorToFov(float vsf) const;
00165 float deltaZoom(float fov) const;
00166 protected:
00167 virtual bool hasDiscontinuity() const {return false;}
00168 virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return false;}
00169 };
00170
00171 class StelProjectorHammer : public StelProjector
00172 {
00173 public:
00174 StelProjectorHammer(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00175 virtual QString getNameI18() const;
00176 virtual QString getDescriptionI18() const;
00177 virtual float getMaxFov() const {return 360.;}
00178 virtual void project(int n, const Vec3d* in, Vec3f* out)
00179 {
00180 Vec3d v;
00181 for (int i = 0; i < n; ++i)
00182 {
00183 v = in[i];
00184 v.transfo4d(modelViewMatrix);
00185 StelProjectorHammer::forward(v);
00186 out[i][0] = viewportCenter[0] + flipHorz * pixelPerRad * v[0];
00187 out[i][1] = viewportCenter[1] + flipVert * pixelPerRad * v[1];
00188 out[i][2] = (v[2] - zNear) * oneOverZNearMinusZFar;
00189 }
00190 }
00191 bool forward(Vec3d &v) const
00192 {
00193
00194 const double r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00195 const double alpha = std::atan2(v[0],-v[2]);
00196 const double cosDelta = std::sqrt(1.-v[1]*v[1]/(r*r));
00197 double z = std::sqrt(1.+cosDelta*std::cos(alpha/2.));
00198 v[0] = 2.*M_SQRT2*cosDelta*std::sin(alpha/2.)/z;
00199 v[1] = M_SQRT2*v[1]/r/z;
00200 v[2] = r;
00201 return true;
00202 }
00203 bool backward(Vec3d &v) const;
00204 float fovToViewScalingFactor(float fov) const;
00205 float viewScalingFactorToFov(float vsf) const;
00206 float deltaZoom(float fov) const;
00207 protected:
00208 virtual bool hasDiscontinuity() const {return true;}
00209 virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);}
00210 };
00211
00212 class StelProjectorCylinder : public StelProjector
00213 {
00214 public:
00215 StelProjectorCylinder(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00216 virtual QString getNameI18() const;
00217 virtual QString getDescriptionI18() const;
00218 virtual float getMaxFov() const {return 175. * 4./3.;}
00219 bool forward(Vec3d &win) const;
00220 bool backward(Vec3d &v) const;
00221 float fovToViewScalingFactor(float fov) const;
00222 float viewScalingFactorToFov(float vsf) const;
00223 float deltaZoom(float fov) const;
00224 protected:
00225 virtual bool hasDiscontinuity() const {return true;}
00226 virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const
00227 {
00228 return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);
00229 }
00230 };
00231
00232 class StelProjectorMercator : public StelProjector
00233 {
00234 public:
00235 StelProjectorMercator(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00236 virtual QString getNameI18() const;
00237 virtual QString getDescriptionI18() const;
00238 virtual float getMaxFov() const {return 175. * 4./3.;}
00239 bool forward(Vec3d &win) const;
00240 bool backward(Vec3d &v) const;
00241 float fovToViewScalingFactor(float fov) const;
00242 float viewScalingFactorToFov(float vsf) const;
00243 float deltaZoom(float fov) const;
00244 protected:
00245 virtual bool hasDiscontinuity() const {return true;}
00246 virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const
00247 {
00248 return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);
00249 }
00250 };
00251
00252 class StelProjectorOrthographic : public StelProjector
00253 {
00254 public:
00255 StelProjectorOrthographic(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00256 virtual QString getNameI18() const;
00257 virtual QString getDescriptionI18() const;
00258 virtual float getMaxFov() const {return 179.9999;}
00259 bool forward(Vec3d &win) const;
00260 bool backward(Vec3d &v) const;
00261 float fovToViewScalingFactor(float fov) const;
00262 float viewScalingFactorToFov(float vsf) const;
00263 float deltaZoom(float fov) const;
00264 protected:
00265 virtual bool hasDiscontinuity() const {return false;}
00266 virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return false;}
00267 };
00268
00269 class StelProjector2d : public StelProjector
00270 {
00271 public:
00272 StelProjector2d() : StelProjector(Mat4d::identity()) {;}
00273 virtual QString getNameI18() const;
00274 virtual QString getDescriptionI18() const;
00275 virtual float getMaxFov() const {return 360.;}
00276 bool forward(Vec3d &win) const;
00277 bool backward(Vec3d &v) const;
00278 float fovToViewScalingFactor(float fov) const;
00279 float viewScalingFactorToFov(float vsf) const;
00280 float deltaZoom(float fov) const;
00281 protected:
00282 virtual bool hasDiscontinuity() const {return false;}
00283 virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {Q_ASSERT(0); return false;}
00284 };
00285
00286 #endif // _STELPROJECTIONS_HPP_
00287