Example #1
0
void healpix2ecp(double *hp_r, double *hp_i, int nside,
		 complex *ecp, int Ntheta, int Nphi) {
   // loop over pixels and grab healpix value 
  
  double theta,phi;
  double dtheta = M_PI/Ntheta;
  double dphi = 2*M_PI/Nphi;

  int i,j,p;
  long hp;


  for (j=0;j<Ntheta;j++) {
    theta = j*dtheta;
    
    for (i=0;i<Nphi;i++) {
      p = j * Nphi + i;
      
      phi = i * dphi;
      
      ang2pix_ring(nside, theta, phi, &hp);
      
      ecp[p] = hp_r[hp] + I*hp_i[hp];
    }
    
  }
  
}
ViewPoint* ViewSphereRender::nextPointNearest( const ViewPoint* fromPoint, const ViewPoint* toPoint )
{
	int array[8];
	long fromIdx, toIdx;
	ang2pix_ring(m_nside, fromPoint->theta, fromPoint->phi, &fromIdx);
	neighbors(m_nside, fromIdx, array, 0);

	ViewPoint* result = NULL;
	ViewPoint* ptr = NULL;
	Vector3d p0(fromPoint->coord[0], fromPoint->coord[1], fromPoint->coord[2]);
	Vector3d p1(toPoint->coord[0], toPoint->coord[1], toPoint->coord[2]);
	Vector3d v0 = (p1 - p0).normalize();
	Vector3d v1;
	double maxCosValue = -1.0;
	double dotProduct;
	
	for (int i = 0; i < 8; ++i)
	{
		if (array[i] >= 0)
		{
			ptr = &(m_viewSphere.vViewPos[array[i]]);
			Vector3d p2(ptr->coord[0], ptr->coord[1], ptr->coord[2]);
			v1 = (p2 - p0).normalize();
			dotProduct = Dot(v0, v1);
// 			//用测地线距离来取最近点
// 			dotProduct2 = Dot(p1, p2); 
			if (dotProduct > maxCosValue)
			{
				maxCosValue = dotProduct;
				result = ptr;
			}
		}
	}
	return result;
}
Example #3
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;
}
Example #4
0
void ecp2healpix_avg(complex *ecp, int Ntheta, int Nphi,
		     double *hp_r, double *hp_i, int nside) {
  // assign average of contributing pixels to healpix pixel

  int npix = 12*nside*nside;
  double *w = calloc(npix,sizeof(double));
  
  double theta,phi;
  double dtheta = M_PI/Ntheta;
  double dphi = 2*M_PI/Nphi;
  
  int i,j,p;
  long hp;
  
  // initialize 
  for (hp=0;hp<npix;hp++) {
    hp_r[hp] = 0.0;
    hp_i[hp] = 0.0;
    w[hp] = 0.0;
  }

  // accumulate pixel values & weight map
  for (j=0;j<Ntheta;j++) {
    theta = j*dtheta;
    
    for (i=0;i<Nphi;i++) {
      p = j * Nphi + i;
      
      phi = i * dphi;
      
      ang2pix_ring(nside, theta, phi, &hp);
      
      hp_r[hp] += creal(ecp[p]);
      hp_i[hp] += cimag(ecp[p]);
      w[hp] += 1.0;
    }
    
  }
  
  // normalize by weight map
  for (hp=0;hp<npix;hp++) {
    hp_r[hp] /=  w[hp];
    hp_i[hp] /=  w[hp];
  }



  
  free(w);
}
Example #5
0
Datum pgheal_ang2ipix_ring(PG_FUNCTION_ARGS)
{
	q3c_ipix_t nside = PG_GETARG_INT64(0);
	q3c_coord_t ra = PG_GETARG_FLOAT8(1);
	q3c_coord_t dec = PG_GETARG_FLOAT8(2);
	q3c_ipix_t ipix;
	q3c_coord_t theta, phi;
	if ((!isfinite(ra))||(!isfinite(dec)))
	{
		PG_RETURN_NULL();
	}
	get_theta_phi(ra, dec, &theta, &phi);
	nside_check(nside);
	angle_check(theta);
	ang2pix_ring(nside, theta, phi, &ipix);
	PG_RETURN_INT64(ipix);
}
Example #6
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;
}
void ViewSphereRender::moveTo( ViewPoint* toPoint )
{
	m_recorder->clear();
	m_recorder->push(m_currentPos);
	m_recorderArc->clear();
	m_startPos = m_currentPos;
	m_targetPos = toPoint;

	//生成视点路径
	// 贪婪方法生成路径
	ViewPoint* p  = m_currentPos;
#define PATH_GENERATION_METHOD 3
#if PATH_GENERATION_METHOD == 1
	while(p != m_targetPos)
	{
		p = nextPointNearest(p, m_targetPos);
		m_recorder->push(p);
	}
#elif PATH_GENERATION_METHOD == 2
	// 累加经纬度角度的方法生成路径
	double delta_t = m_targetPos->theta - m_currentPos->theta; 
	double delta_p = m_targetPos->phi - m_currentPos->phi;
	double dt = delta_t / 100;
	double dp = delta_p / 100;
	double it = 0.0;
	double ip = 0.0;
	for (int i = 0; i < 100; i++)
	{
		long idx;
		ang2pix_ring(m_nside, m_currentPos->theta + it, m_currentPos->phi + ip, &idx);
		p = &(m_viewSphere.vViewPos[idx]);
		m_recorder->push(p);
		it += dt;
		ip += dp;
	}
#elif PATH_GENERATION_METHOD == 3
	generatePathArc(m_startPos, m_targetPos, m_recorderArc);
#endif
	//开始自动移动视点
	m_timer->start(50);
}