00001
00002
00003
00004
00005
00006
00007
00008
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
00019
00020
00021
00022
00023
00024
00025
00026
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
00038
00039
00040
00041
00042
00043
00044 Rigging::~Rigging()
00045 {
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
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
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 void Rigging::draw()
00088 {
00089 for(int i = 0; i < 12; i++)
00090 faces[i].draw();
00091 return;
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
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
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 bool Rigging::projectSelection (const Vec &o, const Vec &d, Vec &v) const
00169 {
00170 const float srad2 = 1.;
00171 const float mdist = 0.;
00172 float t;
00173
00174
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
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
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
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
00233
00234
00235 if (! projectSelection(o, d, v)) return false;
00236
00237
00238
00239 if (! mollweide())
00240 {
00241 phi = acos(v.z);
00242 lambda = atan2(v.y, v.x);
00243 }
00244
00245
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 }