rigging.cpp

Go to the documentation of this file.
00001 /* ============================================================================
00002 'rigging.cpp' defines the rigging of the viewer.
00003 
00004 Written by Nicholas Phillips.
00005 QT4 adaption by Michael R. Greason, ADNET, 27 August 2007
00006 ============================================================================ */
00007 /*
00008                         Fetch header files.
00009 */
00010 #include <qdebug.h>
00011 #include <math.h>
00012 #include "rigging.h"
00013 #include "heal.h"
00014 
00015 using namespace std;
00016 using namespace qglviewer;
00017 /* ============================================================================
00018 'Rigging' manages the faces on the sky.
00019 ============================================================================ */
00020 /* ----------------------------------------------------------------------------
00021 'Rigging' the class constuctor, it creates the faces.
00022 
00023 Arguments:
00024         None.
00025 
00026 Written by Nicholas Phillips.
00027 ---------------------------------------------------------------------------- */
00028 Rigging::Rigging()
00029 {
00030         viewmoll = false;
00031         faces.resize(12);
00032         for(int face = 0; face < 12; face++)
00033                 faces[face].faceNumber(face);
00034         return;
00035 }
00036 /* ----------------------------------------------------------------------------
00037 'Rigging' the class destuctor.
00038 
00039 Arguments:
00040         None.
00041 
00042 Written by Nicholas Phillips.
00043 ---------------------------------------------------------------------------- */
00044 Rigging::~Rigging()
00045 {
00046 }
00047 /* ----------------------------------------------------------------------------
00048 'generate' creates the rigging given the size of the map being supported and
00049 whether or not the map should be displayed as the sphere or as a mollweide
00050 projection.
00051 
00052 Arguments:
00053         ns  - The nside of the map.
00054         mp  - Mollweide projection?
00055         rad - The radius of the 'sphere' the map should be project onto.  Defaults
00056               to 1.
00057 
00058 Returned:
00059         Nothing.
00060 
00061 Written by Nicholas Phillips.
00062 ---------------------------------------------------------------------------- */
00063 void Rigging::generate(int ns, bool mp, double rad)
00064 {
00065         viewmoll = mp;
00066         nside = ns;
00067         setThetas();
00068         for(int i = 0; i < 4; i++)
00069                 faces[i].setRigging(nside,costhetas_np,mp,rad);
00070         for(int i = 4; i < 8; i++)
00071                 faces[i].setRigging(nside,costhetas_eq,mp,rad);
00072         for(int i = 8; i < 12; i++)
00073                 faces[i].setRigging(nside,costhetas_sp,mp,rad);
00074         return;
00075 }
00076 /* ----------------------------------------------------------------------------
00077 'draw' paints all the faces.
00078 
00079 Arguments:
00080         None.
00081 
00082 Returned:
00083         Nothing.
00084 
00085 Written by Nicholas Phillips.
00086 ---------------------------------------------------------------------------- */
00087 void Rigging::draw()
00088 {
00089         for(int i = 0; i < 12; i++)
00090                 faces[i].draw();
00091         return;
00092 }
00093 /* ----------------------------------------------------------------------------
00094 'setThetas' computes the theta values for all the faces.
00095 
00096 Arguments:
00097         None.
00098 
00099 Returned:
00100         Nothing.
00101 
00102 Written by Nicholas Phillips.
00103 ---------------------------------------------------------------------------- */
00104 void Rigging::setThetas()
00105 {
00106         std::vector<double> thetas_np;  
00107         std::vector<double> thetas_eq;  
00108         std::vector<double> thetas_sp;  
00109         double theta,phi,costheta;
00110         int pix = 0;
00111         int dpix = 4;
00112         int npix = nside2npix(nside);
00113         const double eps = 0.128/double(nside);
00114         thetas_np.push_back(0.0);
00115         while( pix < npix ){
00116                 pix2ang_ring(nside, pix,&theta,&phi);
00117                 costheta = cos(theta);
00118                 if( costheta > -eps )
00119                         thetas_np.push_back(theta);
00120                 if( fabs(costheta) <= (2./3.+eps) )
00121                         thetas_eq.push_back(theta);
00122                 if( costheta < eps )
00123                         thetas_sp.push_back(theta);
00124 
00125                 pix += dpix;
00126                 if( costheta > 2./3.) {
00127                         dpix += 4;
00128                 }
00129                 else if( costheta < -2./3. ) {
00130                         dpix -= 4;
00131                 }
00132 
00133         }
00134         thetas_sp.push_back(M_PI);
00135 
00136         unsigned int n = thetas_np.size();
00137         costhetas_np.resize(n);
00138         costhetas_eq.resize(n);
00139         costhetas_sp.resize(n);
00140 
00141         for(unsigned int i = 0; i < n; i++) {
00142                 costhetas_np[i] = cos(thetas_np[n-i-1]);
00143                 costhetas_eq[i] = cos(thetas_eq[n-i-1]);
00144                 costhetas_sp[i] = cos(thetas_sp[n-i-1]);
00145         }
00146         return;
00147 }
00148 /* ----------------------------------------------------------------------------
00149 'projectSelection' converts a selected point, identified by the vectors
00150 returned by the QGLViewer convertClickToLine method, into a vector on the
00151 projected surface.
00152 
00153 Arguments:
00154         o - The location of the observer.
00155         d - A unit vector indicating the direction of the clicked pixel from
00156             the observer's position.
00157         v - The projected vector.
00158 
00159 Returned:
00160         flg - Was a pixel successfully found?
00161 
00162 Written by Nicholas Phillips.
00163 QR4 implementation.  Michael R. Greason, ADNET, 31 August 2007.
00164 Mollweide support.  MRG, ADNET, 21 September 2007.
00165 Discards out-of-bounds selections in the Mollweide projection.  MRG, ADNET,
00166         29 December 2008.
00167 ---------------------------------------------------------------------------- */
00168 bool Rigging::projectSelection (const Vec &o, const Vec &d, Vec &v) const
00169 {
00170         const float srad2 = 1.;                                         // Radius^2 of the 3D sphere.
00171         const float mdist = 0.;                                         // Mollweide distance from origin.
00172         float t;
00173 /*
00174                         3D spherical projection.
00175 */
00176         if (! mollweide())
00177         {
00178                 float sqrtterm, t1, t2, oo, od, dd;
00179                 oo = o * o;
00180                 od = o * d;
00181                 dd = d * d;
00182                 sqrtterm = (od * od) - (dd * (oo - srad2));
00183                 if (sqrtterm < 0) return false;
00184                 t1 = (-od - sqrt(sqrtterm))/(dd);
00185                 t2 = (-od + sqrt(sqrtterm))/(dd);
00186                 t = (t1 < t2) ? t1 : t2;
00187                 v = o + t*d;
00188         }
00189 /*
00190                         Mollweide projection.
00191 */
00192         else
00193         {
00194                 const float w = 2.0;
00195                 const float h = 1.0;
00196                 float l, dy, dz;
00197                 t = (mdist - o.x) / d.x;
00198                 v = o + t*d;
00199                 dy = fabs(v.y);
00200                 dz = fabs(v.z);
00201                 if (dy >= w) return false;
00202                 l = sqrt((1.0 - ((dy * dy) / (w * w))) * (h * h));
00203                 if (dz >= l) return false;
00204         }
00205         return true;
00206 }
00207 /* ----------------------------------------------------------------------------
00208 'projectSelection' converts a selected point, identified by the vectors
00209 returned by the QGLViewer convertClickToLine method, into sky coordinates.
00210 
00211 Arguments:
00212         o      - The location of the observer.
00213         d      - A unit vector indicating the direction of the clicked pixel from
00214                  the observer's position.
00215         phi    - The colatitude of the pixel.
00216         lambda - The longitude of the pixel.
00217 
00218 Returned:
00219         flg - Was a pixel successful found?
00220 
00221 Written by Nicholas Phillips.
00222 QR4 implementation.  Michael R. Greason, ADNET, 31 August 2007.
00223 Mollweide support.  MRG, ADNET, 21 September 2007.
00224 ---------------------------------------------------------------------------- */
00225 bool Rigging::projectSelection (const Vec &o, const Vec &d, 
00226         double &phi, double &lambda) const
00227 {
00228         const double r2 = sqrt(2.);
00229         Vec v;
00230         lambda = phi = 0.;
00231 /*
00232                         Determine where the vector intersects the projection in
00233                         world coordinates.
00234 */
00235         if (! projectSelection(o, d, v)) return false;
00236 /*
00237                         3D spherical projection.
00238 */
00239         if (! mollweide())
00240         {
00241                 phi    = acos(v.z);
00242                 lambda = atan2(v.y, v.x);
00243         }
00244 /*
00245                         Mollweide projection.
00246 */
00247         else
00248         {
00249                 v.y *= r2;
00250                 v.z *= r2;
00251                 try {
00252                         fromMollweide(v.y, v.z, phi, lambda);
00253                 }
00254                 catch (...) { return false; }
00255         }
00256         return true;
00257 }

Generated on Fri Feb 6 15:32:42 2009 for Skyviewer by  doxygen 1.4.7