Home · All Namespaces · All Classes · Functions · Coding Style · Plugins · File Structure

core/StelProjectorClasses.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2008 Stellarium Developers
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 double getMaxFov() const {return 120.;}
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     double fovToViewScalingFactor(double fov) const;
00054     double viewScalingFactorToFov(double vsf) const;
00055     double deltaZoom(double 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 double getMaxFov() const {return 360.;}
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     double fovToViewScalingFactor(double fov) const;
00079     double viewScalingFactorToFov(double vsf) const;
00080     double deltaZoom(double 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 double 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     bool backward(Vec3d &v) const;
00110     double fovToViewScalingFactor(double fov) const;
00111     double viewScalingFactorToFov(double vsf) const;
00112     double deltaZoom(double fov) const;
00113 protected:
00114     virtual bool hasDiscontinuity() const {return false;}
00115     virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return false;}
00116 };
00117 
00118 class StelProjectorFisheye : public StelProjector
00119 {
00120 public:
00121     StelProjectorFisheye(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00122     virtual QString getNameI18() const;
00123     virtual QString getDescriptionI18() const;
00124     virtual double getMaxFov() const {return 180.00001;}
00125     bool forward(Vec3d &v) const
00126     {
00127         const double rq1 = v[0]*v[0] + v[1]*v[1];
00128         if (rq1 > 0.0) {
00129             const double h = std::sqrt(rq1);
00130             const double f = std::atan2(h,-v[2]) / h;
00131             v[0] *= f;
00132             v[1] *= f;
00133             v[2] = std::sqrt(rq1 + v[2]*v[2]);
00134             return true;
00135         }
00136         if (v[2] < 0.0) {
00137             v[0] = 0.0;
00138             v[1] = 0.0;
00139             v[2] = 1.0;
00140             return true;
00141         }
00142         v[0] = 1e99;
00143         v[1] = 1e99;
00144         v[2] = -1e99;
00145         return false;
00146     }
00147     bool backward(Vec3d &v) const;
00148     double fovToViewScalingFactor(double fov) const;
00149     double viewScalingFactorToFov(double vsf) const;
00150     double deltaZoom(double fov) const;
00151 protected:
00152     virtual bool hasDiscontinuity() const {return false;}
00153     virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return false;}
00154 };
00155 
00156 class StelProjectorHammer : public StelProjector
00157 {
00158 public:
00159     StelProjectorHammer(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00160     virtual QString getNameI18() const;
00161     virtual QString getDescriptionI18() const;
00162     virtual double getMaxFov() const {return 360.;}
00163     bool forward(Vec3d &v) const
00164     {
00165         // RealAitoff
00166 //      const double r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00167 //      const double alpha = std::atan2(v[0],-v[2]);
00168 //      const double cosDelta = std::sqrt(1.-v[1]*v[1]/(r*r));
00169 //      double z = std::acos(cosDelta*std::cos(alpha/2.));
00170 //      z = std::sin(z)/z;
00171 //      v[0] = 2.*cosDelta*std::sin(alpha/2.)/z;
00172 //      v[1] = v[1]/r/z;
00173 //      v[2] = r;
00174 //      return true;
00175         
00176         // Hammer Aitoff
00177         const double r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00178         const double alpha = std::atan2(v[0],-v[2]);
00179         const double cosDelta = std::sqrt(1.-v[1]*v[1]/(r*r));
00180         double z = std::sqrt(1.+cosDelta*std::cos(alpha/2.));
00181         v[0] = 2.*M_SQRT2*cosDelta*std::sin(alpha/2.)/z;
00182         v[1] = M_SQRT2*v[1]/r/z;
00183         v[2] = r;
00184         return true;
00185     }
00186     bool backward(Vec3d &v) const;
00187     double fovToViewScalingFactor(double fov) const;
00188     double viewScalingFactorToFov(double vsf) const;
00189     double deltaZoom(double fov) const;
00190 protected:
00191     virtual bool hasDiscontinuity() const {return true;}
00192     virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);}
00193 };
00194 
00195 class StelProjectorCylinder : public StelProjector
00196 {
00197 public:
00198     StelProjectorCylinder(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00199     virtual QString getNameI18() const;
00200     virtual QString getDescriptionI18() const;
00201     virtual double getMaxFov() const {return 175. * 4./3.;} // assume aspect ration of 4/3 for getting a full 360 degree horizon
00202     bool forward(Vec3d &win) const;
00203     bool backward(Vec3d &v) const;
00204     double fovToViewScalingFactor(double fov) const;
00205     double viewScalingFactorToFov(double vsf) const;
00206     double deltaZoom(double fov) const;
00207 protected:
00208     virtual bool hasDiscontinuity() const {return true;}
00209     virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const
00210     {
00211         return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);
00212     }
00213 };
00214 
00215 class StelProjectorMercator : public StelProjector
00216 {
00217 public:
00218     StelProjectorMercator(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00219     virtual QString getNameI18() const;
00220     virtual QString getDescriptionI18() const;
00221     virtual double getMaxFov() const {return 175. * 4./3.;} // assume aspect ration of 4/3 for getting a full 360 degree horizon
00222     bool forward(Vec3d &win) const;
00223     bool backward(Vec3d &v) const;
00224     double fovToViewScalingFactor(double fov) const;
00225     double viewScalingFactorToFov(double vsf) const;
00226     double deltaZoom(double fov) const;
00227 protected:
00228     virtual bool hasDiscontinuity() const {return true;}
00229     virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const
00230     {
00231         return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);
00232     }
00233 };
00234 
00235 class StelProjectorOrthographic : public StelProjector
00236 {
00237 public:
00238     StelProjectorOrthographic(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00239     virtual QString getNameI18() const;
00240     virtual QString getDescriptionI18() const;
00241     virtual double getMaxFov() const {return 179.9999;}
00242     bool forward(Vec3d &win) const;
00243     bool backward(Vec3d &v) const;
00244     double fovToViewScalingFactor(double fov) const;
00245     double viewScalingFactorToFov(double vsf) const;
00246     double deltaZoom(double fov) const;
00247 protected:
00248     virtual bool hasDiscontinuity() const {return false;}
00249     virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return false;}
00250 };
00251 
00252 class StelProjector2d : public StelProjector
00253 {
00254 public:
00255     StelProjector2d() : StelProjector(Mat4d::identity()) {;}
00256     virtual QString getNameI18() const;
00257     virtual QString getDescriptionI18() const;
00258     virtual double getMaxFov() const {return 360.;}
00259     bool forward(Vec3d &win) const;
00260     bool backward(Vec3d &v) const;
00261     double fovToViewScalingFactor(double fov) const;
00262     double viewScalingFactorToFov(double vsf) const;
00263     double deltaZoom(double fov) const;
00264 protected:
00265     virtual bool hasDiscontinuity() const {return false;}
00266     virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {Q_ASSERT(0); return false;}
00267 };
00268 
00269 #endif // _STELPROJECTIONS_HPP_
00270 

Generated on Mon Mar 9 16:16:16 2009 for Stellarium by  doxygen 1.5.5