Exemple #1
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;
}
Exemple #2
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::paintGL()
{
	m_camera.setupModelMatrix();
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	float ps;
	glGetFloatv(GL_POINT_SIZE, &ps);
	vector<ViewPoint>& vp = m_viewSphere.vViewPos;
	glPointSize(5);
/*
	// 绘制顶点
	glColor3ub(255, 0, 0);
	glPointSize(5);
	glBegin(GL_POINTS);
	glVertex3dv(vp[0].coord);
	vector<ViewPoint>::iterator iter = vp.begin();
	for (; iter != vp.end(); ++iter)
	{
		glVertex3dv(iter->coord);
	}
	glEnd();
*/
	Vector4d p0(vp[0].coord[0], vp[0].coord[1], vp[0].coord[2], 1.0);

	double matrix[16];
	glGetDoublev(GL_MODELVIEW_MATRIX, matrix);
// 	GLint viewport[4];
// 	GLdouble projection[16];
// 	double win_coord[3]; 
// 	win_coord[0] = width() / 2;
// 	win_coord[1] = height() / 2;
// 	glReadPixels( int(win_coord[0]), int(win_coord[1]), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &win_coord[2] );
// 	glGetDoublev( GL_PROJECTION_MATRIX, projection );
// 	glGetIntegerv( GL_VIEWPORT, viewport );
// 	double pos[3];
// 	gluUnProject( win_coord[0], win_coord[1], win_coord[2], matrix, projection, viewport, &pos[0], &pos[1], &pos[2]);

// 	glPushMatrix();
// 	glMatrixMode(GL_MODELVIEW);
// 	glLoadIdentity();
// 	glPopMatrix();

	p0.set(0, 0, 1.0, 1.0);
	invMatrix(matrix, matrix);
	p0 = multiply(p0, matrix);

	long ipix;
	vec2pix_ring(m_nside, (double*)&p0, &ipix);
	glColor3ub(255, 128, 0);
	glBegin(GL_POINTS);
		glVertex3dv(vp[ipix].coord);
	glEnd();
	m_currentPos = &(vp[ipix]);
/*
	glColor3ub(255, 255, 255);
	// 绘制顶点连线
	glBegin(GL_LINES);
	vector< pair<int, int> >::iterator itLink = m_viewSphere.links.begin();
	for(; itLink != m_viewSphere.links.end(); ++ itLink)
	{
		glVertex3dv(vp[itLink->first].coord);
		glVertex3dv(vp[itLink->second].coord);
	}
	glEnd();

	*/
	// 绘制球面
	vector<Vector3i>& vTris = m_viewSphere.vTris;
	vector<Vector3i>::iterator itTris = vTris.begin();
	glBegin(GL_TRIANGLES);
	for (; itTris != vTris.end(); ++itTris)
	{
		glColor3ub(128, 0, 0);
		glVertex3dv(vp[itTris->x].coord); 
		glColor3ub(0, 128, 0);
		glVertex3dv(vp[itTris->y].coord);
		glColor3ub(0, 0, 128);
		glVertex3dv(vp[itTris->z].coord);
	}
	glEnd();

	// 绘制视点变化曲线
	vector<const ViewPoint*> vPoint = m_recorder->all();
	if (vPoint.size() > 0)
	{
		glColor3ub(255, 255, 0);
		glBegin(GL_POINTS);
		glVertex3dv(vPoint.front()->coord);
		glEnd();
		if (vPoint.size() > 1)
		{
			glColor3ub(255, 102, 0);
			glBegin(GL_LINES);
			glVertex3dv(vPoint.front()->coord);
			for(int i = 0; i < m_recorder->current(); ++i)
			{
				glVertex3dv(vPoint[i]->coord);
				glVertex3dv(vPoint[i]->coord);
			}
			glVertex3dv(vPoint[m_recorder->current()]->coord);
			glEnd();

			glColor3ub(0, 255, 0);
			glBegin(GL_POINTS);
				glVertex3dv(vPoint.back()->coord);
			glEnd();
		}
	}
	//glDisable(GL_POLYGON_OFFSET_FILL);
	//////////////////////////////////////////////////////////////////////////

	glDisable(GL_DEPTH_TEST);
	//drawCoord();
	m_camera.setOrthoProjection();
	m_camera.drawArc();
	glEnable(GL_DEPTH_TEST);

 	glPointSize(ps);

}