void ViewSphereRender::generatePathArc( const ViewPoint* fromPoint, const ViewPoint* toPoint, ViewPointRecorder* recorder, int step) { ViewPoint* p; Vector3d p1(fromPoint->coord[0], fromPoint->coord[1], fromPoint->coord[2]); Vector3d p0(toPoint->coord[0], toPoint->coord[1], toPoint->coord[2]); Vector3d p2; double cos_alpha = Dot(p0, p1); double alpha = acos(cos_alpha); double sin_alpha = sqrt(1 - cos_alpha * cos_alpha); if (step == -1) step = int(m_nside * alpha / 3.14159265358979323846 + 0.5) * 2; double delta = alpha / step; double beta; double gamma; // alpha - beta double theta; double phi; for (int i = 0; i < step; i++) { beta = delta * i; gamma = alpha - beta; p2 = (p0*sin(beta) + p1*sin(gamma)) / sin_alpha; vec2ang((double*)(&p2), &theta, &phi); p = new ViewPoint(theta, phi, 0.0); p->coord[0] = p2.x; p->coord[1] = p2.y; p->coord[2] = p2.z; m_recorder->push(p); } }
int main(void) { double theta, phi; double vec[3]; long nside; long ipix, npix, dpix, ip2, ip1; printf("Starting C Healpix pixel routines test\n"); nside = 1024; dpix = 23; /* Find the number of pixels in the full map */ npix = nside2npix(nside); printf("Number of pixels in full map: %ld\n", npix); printf("dpix: %ld\n", dpix); printf("Nest -> ang -> vec -> ang -> Ring -> Nest\n"); for (ipix = 0; ipix < npix; ipix +=dpix) { pix2ang_nest(nside, ipix, &theta, &phi); ang2vec(theta, phi, vec); vec2ang(vec, &theta, &phi); ang2pix_ring(nside, theta, phi, &ip2); ring2nest(nside,ip2,&ip1); if (ip1 != ipix) {printf("Error: %ld %ld %ld %ld\n",nside,ipix,ip2,ip1);} } printf("Ring -> ang -> Nest -> Ring\n"); for (ipix = 0; ipix < npix; ipix +=dpix) { pix2ang_ring(nside, ipix, &theta, &phi); ang2pix_nest(nside, theta, phi, &ip2); nest2ring(nside,ip2,&ip1); if (ip1 != ipix) {printf("Error: %ld %ld %ld %ld\n",nside,ipix,ip2,ip1);} } printf("Nest -> vec -> Ring -> Nest\n"); for (ipix = 0; ipix < npix; ipix +=dpix) { pix2vec_nest(nside, ipix, vec); vec2pix_ring(nside, vec, &ip2); ring2nest(nside,ip2,&ip1); if (ip1 != ipix) {printf("Error: %ld %ld %ld %ld\n",nside,ipix,ip2,ip1);} } printf("Ring -> vec -> Nest -> Ring\n"); for (ipix = 0; ipix < npix; ipix +=dpix) { pix2vec_ring(nside, ipix, vec); vec2pix_nest(nside, vec, &ip2); nest2ring(nside,ip2,&ip1); if (ip1 != ipix) {printf("Error: %ld %ld %ld %ld\n",nside,ipix,ip2,ip1);} } printf("%ld\n", nside); printf("test completed\n\n"); /* Later */ return 0; }
int main(void) { double theta, phi, th1, ph1; long nside; long ipix, npix, dpix, ip2, ip1, ns1, pp; double vec[3]; nside = 1024; dpix = 1; /* test nside->npix->nside */ /* for (pp = 0; pp < 14; pp++) { nside = pow(2,pp) ; npix = nside2npix(nside); ns1 = npix2nside(npix); printf("%ld %ld %ld %ld\n",pp,nside,ns1,npix); } */ theta = 0.5; phi = -0.4; ang2vec(theta, phi, vec); vec2ang(vec, &th1, &ph1); printf("%f %f, %f %f\n",theta,th1,phi,ph1); theta = -0.1; /* theta = 5.; */ /* ang2vec(theta, phi, vec); */ /* printf("%f %f %f\n",vec[0],vec[1],vec[2]); */ /* printf("dpix: %ld\n", dpix); */ /* for (ipix = 0; ipix < npix; ipix +=dpix) { */ /* pix2ang_nest(nside, ipix, &theta, &phi); */ /* ang2pix_ring(nside, theta, phi, &ip2); */ /* ring2nest(nside,ip2,&ip1); */ /* if (ip1 != ipix) {printf("%ld %ld %ld %ld\n",nside,ipix,ip2,ip1);} */ /* } */ /* for (ipix = 0; ipix < npix; ipix +=dpix) { */ /* pix2ang_ring(nside, ipix, &theta, &phi); */ /* ang2pix_nest(nside, theta, phi, &ip2); */ /* nest2ring(nside,ip2,&ip1); */ /* if (ip1 != ipix) {printf("%ld %ld %ld %ld\n",nside,ipix,ip2,ip1);} */ /* } */ /* printf("%ld\n", nside); */ /* Later */ return 0; }
/// Creates a Healpix sphere by computing the pixel and coordinate vector /// locations and (phi, theta) values. void CHealpixSpheroid::GenerateHealpixSphere(unsigned int n_pixels, unsigned int n_sides) { // Resize the input vectors to match the image. mFluxTexture.resize(n_pixels); pixel_xyz.resize(n_pixels); pixel_phi.resize(n_pixels); pixel_theta.resize(n_pixels); pixel_radii.resize(n_pixels); // pixel_temperatures.resize(n_pixels); corner_xyz.resize(4 * n_pixels); // four corners per Healpix pixel corner_theta.resize(4 * n_pixels); // four corners per Healpix pixel corner_phi.resize(4 * n_pixels); // four corners per Healpix pixel corner_radii.resize(4 * n_pixels); // four corners per Healpix pixel // Temporary double vectors to interface with Healpix's routines: vector<double> t_pixel_xyz(3); vector<double> t_corner_xyz(12); // Iterate over each pixel in the Healpix image for(unsigned int i = 0; i < n_pixels; i++) { // Init the flux texture to something useful. mFluxTexture[i].r = float(i) / n_pixels; mFluxTexture[i].a = 1.0; // Compute the vertex locations for the center and (four) corners // of the pixels. pix2vec_nest(n_sides, i, &t_pixel_xyz[0], &t_corner_xyz[0]); // Copy the pixel location from the temporary buffer into the storage buffer. pixel_xyz[i] = vec3(t_pixel_xyz[0], t_pixel_xyz[1], t_pixel_xyz[2]); // Compute the (theta, phi) values for the center of each pixel pix2ang_nest(n_sides, i, &pixel_theta[i], &pixel_phi[i]); // Compute the (theta, phi) values for each of the (four) corners for(unsigned int j = 0; j < 4; j++) { vec2ang(&t_corner_xyz[3*j], &corner_theta[4*i + j], &corner_phi[4*i + j]); // Copy the corner location into the storage buffer corner_xyz[4*i + j] = vec3(t_corner_xyz[3*j + 0], t_corner_xyz[3*j + 1], t_corner_xyz[3*j + 2]); } } }