示例#1
0
bool 
GLTextureManager::preparePaper (const char *name, GLuint itexname)
{
  QImage qim(name);
  QFileInfo fi(name);
  QString filename = fi.fileName();
  if (qim.isNull()) 
    {
      cerr << "  Error: unable to read \"" << name << "\"" << endl;
      return false;
    }
  if (qim.depth()!=32)
    {
      cerr<<"  Error: \""<<name<<"\" has "<<qim.depth()<<" bits/pixel"<<endl;
      return false;
    }
  QImage qim2=QGLWidget::convertToGLFormat( qim );

  glBindTexture(GL_TEXTURE_2D, itexname);
	
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
		  GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
		  GL_LINEAR);     

  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, qim.width(), qim.height(), 0, 
	       GL_RGBA, GL_UNSIGNED_BYTE, qim2.bits());	

  cout << "  \"" << filename.toStdString() << "\" loaded with "<< qim.depth() << " bits per pixel" << endl;

  return true;
}
示例#2
0
	gh::Quaternion qMult( const Quaternion& p, const Quaternion& q )
	{
		Vector4 result;
		Vector3 qim( q.x, q.y, q.z );
		Vector3 pim( p.x, p.y, p.z );

		Vector3 resultIm = pim.getCrossProduct( qim );

		resultIm += p.w * qim + q.w * pim;

		result.w = p.w * q.w - pim.dotProduct( qim );
		
		result.setXYZW( resultIm.x, resultIm.y, resultIm.z, result.w );

		return result;
	}
示例#3
0
bool 
GLTextureManager::prepareTextureLuminanceAndAlpha (string sname, GLuint itexname)
{
  const char * name = sname.c_str();
  QImage qim(name);
  QFileInfo fi(name);
  QString filename = fi.fileName();
  if (qim.isNull()) 
    {
      cerr << "  Error: unable to read \"" << name << "\"" << endl;
      return false;
    }
  if (qim.depth() > 8)
    {
      cerr<<"  Error: \""<<name<<"\" has "<<qim.depth()<<" bits/pixel"<<endl;
      return false;
    }
					   
  glBindTexture(GL_TEXTURE_2D, itexname);
  //glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
					     
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
		  GL_LINEAR);
  //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
  //	      GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
		  GL_LINEAR);     
						     
  glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, qim.width(), qim.height(), 0, 
	       GL_LUMINANCE, GL_UNSIGNED_BYTE, qim.bits());	
  glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, qim.width(), qim.height(), 0, 
	       GL_ALPHA, GL_UNSIGNED_BYTE, qim.bits());	
							 
  cout << "  \"" << filename.toStdString() << "\" loaded with "<< qim.depth() << " bits per pixel" << endl;						   

  return true;
							     
}
示例#4
0
void MocapPlugin::videoCB(const sensor_msgs::ImageConstPtr &msg) {
    lockWhileWriting = true;
    try {
        cv_ptr = cv_bridge::toCvCopy(msg, "mono8");
        cv_ptr->image.copyTo(img);
        flip(img,img,1);
    } catch (cv_bridge::Exception &e) {
        ROS_ERROR("cv_bridge exception: %s", e.what());
    }
    lockWhileWriting = false;

    char str[1];
    for (uint col = 0; col < MARKER; col++) {
        cv::Point2f center(camera[currentID.second].projectedPosition2D(0, col),
                           camera[currentID.second].projectedPosition2D(1, col));
        circle(img, center, 5, cv::Scalar(255, 255, 0), 4);
        line(img, cv::Point2f(camera[currentID.second].origin2D(0), camera[currentID.second].origin2D(1)), center,
             cv::Scalar::all(255), 4);
        sprintf(str, "%d", camera[currentID.second].markerIDs[col]);
        putText(img, str, center, cv::FONT_HERSHEY_SCRIPT_SIMPLEX, 1, cv::Scalar::all(255));
    }

    QLabel *camimage = this->findChild<QLabel *>("camimage");
    int w = img.cols;
    int h = img.rows;
    QImage qim(w, h, QImage::Format_RGB32);
    QRgb pixel;
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
            int gray = (int) img.at < unsigned char > (j, i);
            pixel = qRgb(gray, gray, gray);
            qim.setPixel(i, j, pixel);
        }
    }
    QPixmap pixmap = QPixmap::fromImage(qim);
    camimage->setPixmap(pixmap);
    camimage->repaint();
}
示例#5
0
文件: main.cpp 项目: GCZhang/SNAP
void run( const int N, const int M, const int L, const int hyper_threads, const int vector_lanes,
                  const int nx, const int ny, const int nz, const int ichunk,
                  const int nang, const int noct, const int ng, const int nmom, const int cmom,
                  const vector<diag_c>& diag )
{
  
	typedef typename Kokkos::DefaultExecutionSpace device_t;
	typedef TeamPolicy<device_t> team_policy_t;
	typedef View<double*, device_t> view_1d_t;
	typedef View<double**, Kokkos::LayoutLeft, device_t> view_2d_t;
	typedef View<double***, Kokkos::LayoutLeft, device_t> view_3d_t;
	typedef View<double****, Kokkos::LayoutLeft, device_t> view_4d_t;
	typedef View<double*****, Kokkos::LayoutLeft, device_t> view_5d_t;
	typedef View<double******, Kokkos::LayoutLeft, device_t> view_6d_t;
	typedef View<double*******, Kokkos::LayoutLeft, device_t> view_7d_t;


	int id = 1;
	int ich = 1;
	int jlo = 0;
	int jhi = ny-1;
	int jst = 1;
	int jd = 2;
	int klo = 0;
	int khi = nz-1;
	int kst = 1;
	int kd = 2;
	double hi = c1;
	
	Kokkos::initialize();
	Kokkos::DefaultExecutionSpace::print_configuration(cout);
	
	view_4d_t psii( "psii", nang, ny, nz, ng );
	view_4d_t psij( "psij", nang, ichunk, nz, ng );
	view_4d_t psik( "psik", nang, ichunk, ny, ng );
	view_4d_t jb_in( "jb_in", nang, ichunk, ny, ng ); // jb_in(nang,ichunk,nz,ng)
	view_4d_t kb_in( "kb_in", nang, ichunk, ny, ng ); // kb_in(nang,ichunk,nz,ng)
	view_6d_t qim( "qim", nang, nx, ny, nz, noct, ng ); // qim(nang,nx,ny,nz,noct,ng)
  view_5d_t qtot( "qtot", cmom, nx, ny, nx, ng ); // qtot(cmom,nx,ny,nz,ng)
	view_2d_t ec( "ec", nang, cmom ); // ec(nang,cmom)
	view_1d_t mu( "mu", nang ); // mu(nang)
	view_1d_t w( "w", nang ); // w(nang)
	view_1d_t wmu( "wmu", nang ); // wmu(nang)
	view_1d_t weta( "weta", nang ); // weta(nang)
	view_1d_t wxi( "wxi", nang ); // wxi(nang)
	view_1d_t hj( "hj", nang ); // hj(nang)
	view_1d_t hk( "hk", nang ); // hk(nang)
	view_1d_t vdelt( "vdelt", ng ); // vdelt(ng)
	view_6d_t ptr_in( "ptr_in", nang, nx, ny, nz, noct, ng ); // ptr_in(nang,nx,ny,nz,noct,ng)
	view_6d_t ptr_out( "ptr_out", nang, nx, ny, nz, noct, ng ); // ptr_out(nang,nx,ny,nz,noct,ng)
	view_4d_t flux( "flux", nx, ny, nz, ng ); // flux(nx,ny,nz,ng)
	view_5d_t fluxm( "fluxm", cmom-1, nx, ny, nz, ng ); //fluxm(cmom-1,nx,ny,nz,ng)
	view_2d_t psi( "psi", nang, M );
	view_2d_t pc( "pc", nang, M );
	view_4d_t jb_out( "jb_out", nang, ichunk, nz, ng );
	view_4d_t kb_out( "kb_out", nang, ichunk, ny, ng );
	view_4d_t flkx( "flkx", nx+1, ny, nz, ng );
	view_4d_t flky( "flky", nx, ny+1, nz, ng );
	view_4d_t flkz( "flkz", nx, ny, nz+1, ng );
  view_3d_t hv( "hv", nang, 4, M ); // hv(nang,4,M)
  view_3d_t fxhv( "fxhv", nang, 4, M ); // fxhv(nang,4,M)
  view_5d_t dinv( "dinv", nang, nx, ny, nz, ng ); // dinv(nang,nx,ny,nz,ng)
  view_2d_t den( "den", nang, M ); // den(nang,M)
  view_4d_t t_xs( "t_xs", nx, ny, nz, ng ); // t_xs(nx,ny,nz,ng)
   	  
  const team_policy_t policy( N, hyper_threads, vector_lanes );
  
  for (int ii = 0; ii < n_test_iter; ii++) {
    Kokkos::Impl::Timer timer;
    
    for (int oct = 0; oct < noct; oct++) {
      parallel_for( policy, dim3_sweep2<  team_policy_t,
                                          view_1d_t, view_2d_t, view_3d_t, view_4d_t,
                                          view_5d_t, view_6d_t, view_7d_t >
                                        ( M, L,
                                          ng, cmom, noct,
                                          nx, ny, nz, ichunk,
                                          diag,
                                          id, ich, oct,
                                          jlo, jhi, jst, jd,
                                          klo, khi, kst, kd,
                                          psii, psij, psik,
                                          jb_in, kb_in,
                                          qim, qtot, ec,
                                          mu, w,
                                          wmu, weta, wxi,
                                          hi, hj, hk,
                                          vdelt, ptr_in, ptr_out,
                                          flux, fluxm, psi, pc,
                                          jb_out, kb_out,
                                          flkx, flky, flkz,
                                          hv, fxhv, dinv,
                                          den, t_xs ) );
    }// end noct
    
    std::cout << " ii " << ii << " elapsed time " << timer.seconds() << std::endl;
  } // end n_test_iter	
	
	Kokkos::finalize();
}
示例#6
0
文件: main.cpp 项目: GCZhang/SNAP
void run_serial(  int nx, int ny, int nz, int ndiag, const vector<diag_c>& diag,
                  int ndimen, int id, int jd, int kd,
                  int nang, int nmom, int noct, int ng,
                  int ich, int ichunk,
                  int jlo, int klo, int jhi, int khi, int jst, int kst,
                  bool firsty, bool lasty, bool firstz, bool lastz,
                  int nnested, int src_opt, int fixup,
                  double hi, double vdelt )
{

	typedef Kokkos::Serial device_type;
	typedef Kokkos::View<double*, Kokkos::LayoutLeft, device_type> serial_view_t_1d;
	typedef Kokkos::View<double**, Kokkos::LayoutLeft, device_type> serial_view_t_2d;
	typedef Kokkos::View<double***, Kokkos::LayoutLeft, device_type> serial_view_t_3d;
	typedef Kokkos::View<double****, Kokkos::LayoutLeft, device_type> serial_view_t_4d;
	typedef Kokkos::View<double*****, Kokkos::LayoutLeft, device_type> serial_view_t_5d;
	typedef Kokkos::View<double******, Kokkos::LayoutLeft, device_type> serial_view_t_6d;
	typedef Kokkos::View<double*, Kokkos::LayoutStride> serial_view_t_1d_s;

//   cout << " a " << endl;
  
	int cmom = nmom * nmom;
	int d1 = nang; // TEST, (timedep == 1 => 		d1 = nang; d2 = nx; d3 = ny; d4 = nz )
	int d2 = nx; // TEST
	int d3 = ny; // TEST
	int d4 = nz; // TEST

//   cout << " b " << endl;
  
  serial_view_t_1d hj( "hj", nang );
  serial_view_t_1d hk( "hk", nang );
  serial_view_t_1d mu( "mu", nang );
	serial_view_t_1d w( "w", nang );
  serial_view_t_6d qim( "qim", nang, nx, ny, nz, noct, ng );
	serial_view_t_3d psii( "psii", nang, ny, nz );
	serial_view_t_3d psij( "psij", nang, ichunk, nz );
	serial_view_t_3d psik( "psik", nang, ichunk, ny );
  serial_view_t_4d qtot( "qtot", cmom, nx, ny, nz );
	serial_view_t_2d ec( "ec", nang, cmom );
  serial_view_t_4d ptr_in( "ptr_in", d1, d2, d3, d4 );
  serial_view_t_4d ptr_out( "ptr_out", d1, d2, d3, d4 );
  serial_view_t_4d dinv( "dinv", nang, nx, ny, nz );
	serial_view_t_3d flux( "flux", nx, ny, nz );
  serial_view_t_4d fluxm( "fluxm", cmom-1, nx, ny, nz );
 	serial_view_t_3d jb_in( "jb_in", nang, ichunk, nz );
  serial_view_t_3d jb_out( "jb_out", nang, ichunk, nz );
	serial_view_t_3d kb_in( "kb_in", nang, ichunk, ny );
	serial_view_t_3d kb_out( "kb_out", nang, ichunk, ny );
	serial_view_t_1d wmu( "wmu", nang );
	serial_view_t_1d weta( "weta", nang );
	serial_view_t_1d wxi( "wxi", nang );
  serial_view_t_3d flkx( "flkx", nx+1, ny, nz );
  serial_view_t_3d flky( "flky", nx, ny+1, nz );
  serial_view_t_3d flkz( "flkz", nx, ny, nz+1 );
  serial_view_t_3d t_xs( "t_xs", nx, ny, nz );

//   cout << " c " << endl;
  
  for (int ii = 0; ii < n_test_iter; ii++) {
    time(&timer_start);
    
    for (int oct = 0; oct < noct; oct++) {
      for (int g = 0; g < ng; g++) {	
        dim3_sweep< device_type, serial_view_t_1d, serial_view_t_2d,
                  serial_view_t_3d, serial_view_t_4d, serial_view_t_5d,
                  serial_view_t_6d, serial_view_t_1d_s >
                ( ichunk, firsty, lasty, firstz, lastz, nnested,
                  nx, hi, hj, hk, ndimen, ny, nz, ndiag, diag,
                  cmom, nang, mu, w, noct,
                  src_opt, ng, qim,
                  fixup,
                  ich, id, d1, d2, d3, d4, jd, kd, jlo, klo, oct, g,
                  jhi, khi, jst, kst, psii, psij, psik, qtot, ec, vdelt,
                  ptr_in, ptr_out, dinv, flux, fluxm, jb_in, jb_out,
                  kb_in, kb_out, wmu, weta, wxi, flkx, flky, flkz, t_xs );
      }
    }
    
    time(&timer_end);
    std::cout << " ii " << ii << " elapsed time " << difftime(timer_end, timer_start) << std::endl;
  }
}