void ViewSphereRender::initializeGL()
{
	QGLCanvas::initializeGL();

	//在球面上绘制视点移动轨迹时需要,防止轨迹与球面重合出现z-fighting的情况
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(1, 1);

	// Generate view position
	long npix = nside2npix(m_nside);
	double theta,phi;
	for(int i = 0; i < npix; ++i) {
		pix2ang_ring(m_nside, i, &theta, &phi);
		ViewPoint pos(theta, phi, 0.0);
		ang2vec(theta, phi, pos.coord);
		m_viewSphere.vViewPos.push_back(pos);
	}
	printf("View position count = %d\n", m_viewSphere.vViewPos.size());

	int array[8];
	//生成顶点之间的link
	for(int i = 0; i < npix; i++)
	{
		neighbors(m_nside, i, array, 0);
		for(int j = 0; j < 8; j += 2) {
			if(array[j] > i) 
				m_viewSphere.links.push_back(make_pair(i, array[j]));
		}
	}

	// Generate mesh from vertices
	// 生成球面模型
	vector<ViewPoint>& vp = m_viewSphere.vViewPos;
	m_viewSphere.vTris.push_back(Vector3i(0, 1, 2)); // 北极点的两个三角形
	m_viewSphere.vTris.push_back(Vector3i(0, 2, 3));
	m_viewSphere.vTris.push_back(Vector3i(npix - 1, npix - 2, npix - 3)); // 南极点的两个三角形
	m_viewSphere.vTris.push_back(Vector3i(npix - 1, npix - 3, npix - 4));
	for(int i = 0; i < npix; i++)
	{
		neighbors(m_nside, i, array, 0);

		if (array[4] >= 0 && array[5] >= 0 && array[6] >= 0)
		{
			m_viewSphere.vTris.push_back(Vector3i(i, array[6], array[5]));
			m_viewSphere.vTris.push_back(Vector3i(i, array[5], array[4]));
		} else {
			m_viewSphere.vTris.push_back(Vector3i(i, array[6], array[4]));
		}
 	}

// 	m_currentPos = &(m_viewSphere.vViewPos[0]);
// 
// 	long ipix;
// 	Vector4d p0(1.0, 0.5, 0.0, 1.0);
// 	vec2pix_ring(m_nside, (double*)&p0, &ipix);
// 	moveFromTo(m_currentPos, &(m_viewSphere.vViewPos[ipix]));
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
vfloat ang2projvec(const vec& r1, const vec& r2, const vec& normal) {
  pvecerror(
  "vfloat ang2projvec(const vec& r1, const vec& r2, const vec& normal)");
  vec rt1 = project_to_plane(r1, normal);
  vec rt2 = project_to_plane(r2, normal);
  if (rt1 == dv0 || rt2 == dv0) {
    vecerror = 1; return 0;
  }
  vfloat tang = ang2vec(rt1, rt2);
  if (tang == 0) return tang;  // projections are parallel 
  vec at = rt1 || rt2;
  int i = check_par(at, normal, 0.0001);
  //mcout<<"r1="<<r1<<"r2="<<r2<<"normal="<<normal
  //     <<"rt1="<<rt1<<"rt2="<<rt2<<"\ntang="<<tang
  //     <<"\nat="<<at<<" i="<<i<<'\n';
  if (i == -1) return 2.0 * M_PI - tang;
  return tang; // it works if angle <= PI
} 
Ejemplo n.º 5
0
int main()
{
    std::cout << "****** ang2vec ******" << std::endl;
    double theta = PI / 2;
    double phi = PI / 2;
    double vec[3];
    ang2vec(theta, phi, vec);
    displayVec(vec);

    std::cout << "****** npix2nisde ******" << std::endl;
    long npix = 786432;
    std::cout << npix2nside(npix) << std::endl;

    std::cout << "****** nside2npix ******" << std::endl;
    long nside = 256;
    std::cout << nside2npix(nside) << std::endl;

    std::cout << "****** pix2ang ******" << std::endl;
    long ipring = 10000; // ipring -> Index_Pixel_Ring
    pix2ang_ring(nside, ipring, &theta, &phi);
    std::cout << "theta = " << theta << std::endl;
    std::cout << "phi = " << phi << std::endl;

    std::cout << "****** pix2vec ******" << std::endl;
    pix2vec_ring(nside, ipring, vec);
    displayVec(vec);

    std::cout << "****** ang2pix ******" << std::endl;
    ang2pix_ring(nside, theta, phi, &ipring);
    std::cout << "ipring = " << ipring << std::endl;

    std::cout << "****** vec2pix ******" << std::endl;
    vec2pix_ring(nside, vec, &ipring);
    std::cout << "ipring = " << ipring << std::endl;

    std::cout << "****** ring2nest ******" << std::endl;
    long ipnest;
    ring2nest(nside, ipring, &ipnest);
    std::cout << "ipnest = " << ipnest << std::endl;

    std::cout << "****** nest2ring ******" << std::endl;
    nest2ring(nside, ipnest, &ipring);
    std::cout << "ipring = " << ipring << std::endl;
}
Ejemplo n.º 6
0
/* Find error in time of arrival. */
static void toa_errors(
    double *dt,
    double theta,
    double phi,
    double gmst,
    int nifos,
    const double **locs, /* Input: detector position. */
    const double *toas /* Input: time of arrival. */
) {
    /* Convert to Cartesian coordinates. */
    double n[3];
    ang2vec(theta, phi - gmst, n);

    int i, j;
    for (i = 0; i < nifos; i ++)
    {
        double dot;
        for (dot = 0, j = 0; j < 3; j ++)
        {
            dot += locs[i][j] * n[j];
        }
        dt[i] = toas[i] + dot / LAL_C_SI;
    }
}