void Hud::Draw (Zeni::Time::Second_Type elapsedTime)
{
	HeroComponent & hero = HeroComponent::GetInstance();

	double heroHealth = hero.GetHealth();
	double heroShields = hero.GetShields();
	double healthWidth = 200.0f;
	double healthHeight = 30.0f;

	Zeni::Point2f bgPosition1 (590.0f, 40.0f);
	Zeni::Point2f bgPosition2 (bgPosition1.x, bgPosition1.y + healthHeight);
	Zeni::Point2f bgPosition3 (bgPosition1.x + healthWidth, bgPosition1.y + healthHeight);
	Zeni::Point2f bgPosition4 (bgPosition1.x + healthWidth, bgPosition1.y);

	Zeni::Point2f healthPosition1 = bgPosition1;
	Zeni::Point2f healthPosition2 = bgPosition2;
	Zeni::Point2f healthPosition3 (bgPosition1.x + healthWidth * heroHealth / 1000.0f, bgPosition1.y + healthHeight);
	Zeni::Point2f healthPosition4 (bgPosition1.x + healthWidth * heroHealth / 1000.0f, bgPosition1.y);

	Zeni::Point2f shieldPosition1 = bgPosition1;
	Zeni::Point2f shieldPosition2 = bgPosition2;
	Zeni::Point2f shieldPosition3 (bgPosition1.x + healthWidth * heroShields / 100.0f, bgPosition1.y + healthHeight);
	Zeni::Point2f shieldPosition4 (bgPosition1.x + healthWidth * heroShields / 100.0f, bgPosition1.y);

	int score = hero.GetScore();

	std::stringstream ss4;
	ss4 << score;
	Zeni::get_Fonts()["score"].render_text (ss4.str(), Zeni::Point2f (20.0f, 550.0f), Zeni::get_Colors()["score"]);

	++frameCount;

	std::stringstream ss ("FPS: ");
	ss << fps;

	//Zeni::get_Fonts()["fps"].render_text (ss.str(), Zeni::Point2f(), Zeni::get_Colors()["fps"]);

	const std::vector<ProjectileFactory*>& heroWeapons = hero.GetWeapons();

	size_t numWeapons = heroWeapons.size();
	int selectedWeapon = hero.GetSelectedWeaponIndex();

	double corner = 800.0f - 30.0f * numWeapons;

	Zeni::Color enabled = Zeni::get_Colors()["weapon_enabled"];
	Zeni::Color disabled = Zeni::get_Colors()["weapon_disabled"];

	for (int i = 0; i < numWeapons; ++i)
	{
		Zeni::Vertex2f_Texture vertex1 (Zeni::Point2f(corner + 30.0f * i, 0.0f), Zeni::Point2f(0.0f, 0.0f));
		Zeni::Vertex2f_Texture vertex2 (Zeni::Point2f(corner + 30.0f * i, 30.0f), Zeni::Point2f(0.0f, 1.0f));
		Zeni::Vertex2f_Texture vertex3 (Zeni::Point2f(corner + 30.0f * (i + 1), 30.0f), Zeni::Point2f(1.0f, 1.0f));
		Zeni::Vertex2f_Texture vertex4 (Zeni::Point2f(corner + 30.0f * (i + 1), 0.0f), Zeni::Point2f(1.0f, 0.0f));
		Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q (vertex1, vertex2, vertex3, vertex4);

		Zeni::Material backing(i == selectedWeapon ? "selected_weapon" : "weapon");

		q.lend_Material (&backing);

		Zeni::get_Video().render (q);
		
		double r = selectedWeapon == i ? weaponRotation : 0.0f;
		Zeni::render_image (
			heroWeapons[i]->GetTexture(),
			Zeni::Point2f(corner + 30 * i + 5.0f, 5.0f),
			Zeni::Point2f(corner + 30 * (i + 1.0f) - 5.0f, 25.0),
			r,
			1.0f,
			Zeni::Point2f(corner + 30 * i + 15.0f, 15.0f),
			false,
			heroWeapons[i]->IsReady() ? enabled : disabled);
	}

	int heroAmmo = heroWeapons[selectedWeapon]->GetAmmo();

	std::stringstream ss3;
	ss3 << heroAmmo;
	Zeni::get_Fonts()["ammo"].render_text (ss3.str(), Zeni::Point2f(corner - 5.0f, 0.0f), Zeni::get_Colors()["ammo"], Zeni::ZENI_RIGHT);

	Zeni::Vertex2f_Texture v9 (bgPosition1, Zeni::Point2f (0.0f, 0.0f));
	Zeni::Vertex2f_Texture v10 (bgPosition2, Zeni::Point2f (0.0f, 1.0f));
	Zeni::Vertex2f_Texture v11 (bgPosition3, Zeni::Point2f (1.0f, 1.0f));
	Zeni::Vertex2f_Texture v12 (bgPosition4, Zeni::Point2f (1.0f, 0.0f));

	Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q3 (v9, v10, v11, v12);

	Zeni::Material healthbar1("healthbar1");

	q3.lend_Material (&healthbar1);

	Zeni::get_Video().render (q3);

	Zeni::Vertex2f_Texture v13 (healthPosition1, Zeni::Point2f (0.0f, 0.0f));
	Zeni::Vertex2f_Texture v14 (healthPosition2, Zeni::Point2f (0.0f, 1.0f));
	Zeni::Vertex2f_Texture v15 (healthPosition3, Zeni::Point2f (heroHealth / 1000.0f, 1.0f));
	Zeni::Vertex2f_Texture v16 (healthPosition4, Zeni::Point2f (heroHealth / 1000.0f, 0.0f));

	Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q4 (v13, v14, v15, v16);

	Zeni::Material healthbar2("healthbar2");

	q4.lend_Material (&healthbar2);

	Zeni::get_Video().render (q4);

	Zeni::Vertex2f_Texture v17 (shieldPosition1, Zeni::Point2f (0.0f, 0.0f));
	Zeni::Vertex2f_Texture v18 (shieldPosition2, Zeni::Point2f (0.0f, 1.0f));
	Zeni::Vertex2f_Texture v19 (shieldPosition3, Zeni::Point2f (heroShields / 100.0f, 1.0f));
	Zeni::Vertex2f_Texture v20 (shieldPosition4, Zeni::Point2f (heroShields / 100.0f, 0.0f));

	Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q5 (v17, v18, v19, v20);

	Zeni::Material healthbar3("healthbar3");

	q5.lend_Material (&healthbar3);

	Zeni::get_Video().render (q5);

	double timeRemaining = GameTimer::GetInstance().GetRemainingTime();

	Zeni::Color timerTextColor = timeRemaining < 10.0f ? Zeni::get_Colors()["low_time"] : Zeni::get_Colors()["time"];

	Zeni::render_image (
		"Timer",
		Zeni::Point2f (620.0f, 540.0f),
		Zeni::Point2f (670.0f, 590.0f),
		false,
		timerTextColor);

	std::stringstream ss2;
	int minutes = (int)timeRemaining / 60;
	ss2 << minutes << ":" << std::fixed << std::setprecision(2) << timeRemaining - minutes * 60;
	Zeni::get_Fonts()["time"].render_text (ss2.str(), Zeni::Point2f(680.0f, 550.0f), timerTextColor);
}
Example #2
0
void test_RT()
{
  typedef RT                 Cls;

  //  _test_cls_regular_3( Cls() );
  typedef traits::Bare_point Point;
  typedef traits::Weighted_point Weighted_point;

  typedef typename Cls::Vertex_handle                Vertex_handle;
  typedef typename Cls::Cell_handle                  Cell_handle; 
  typedef typename Cls::Facet                        Facet;
  typedef typename Cls::Edge                         Edge;
  
  typedef std::list<Weighted_point>                  list_point;
  typedef typename Cls::Finite_cells_iterator        Finite_cells_iterator;

  // temporary version

  int n, m;
  int count = 0;

  // For dimension 0, we need to check that the point of highest weight is the
  // one that finally ends up in the vertex.
  std::cout << " test dimension 0 " << std::endl;
  Cls T0;
  T0.insert(Weighted_point( Point (0,0,0), 0) );
  T0.insert(Weighted_point( Point (0,0,0), 1) );
  T0.insert(Weighted_point( Point (0,0,0), -1) );
  assert(T0.dimension() == 0);
  assert(T0.number_of_vertices() == 1);
  assert(T0.finite_vertices_begin()->point().weight() == 1);

  std::cout << " test dimension 1 " << std::endl;
  Cls T1;
  std::cout << " number of inserted points : " ;
  Weighted_point p[5];
  for ( m=0; m<5; m++) {
    if ( (m%2)== 0 ) 
      p[m] = Weighted_point( Point( 2*m,0,0 ), 2 );
    else 
      p[m] = Weighted_point( Point( -2*m+1,0,0 ), 2 );
    T1.insert( p[m] );
    count++;
    if (count <10)
      std::cout << count << '\b' ;
    else
      if (count < 100)
	std::cout << count << '\b' << '\b' ;
      else
	std::cout << count << '\b' << '\b' << '\b' ;
    std::cout.flush();
  }
  assert( T1.is_valid() );
  std::cout << std::endl << " number of vertices : " 
      << T1.number_of_vertices() << std::endl;

  std::cout << " number of inserted points : " ;
  Weighted_point q[5];
  for ( m=0; m<5; m++) {
    if ( (m%2)== 0 )
      q[m] = Weighted_point( Point( 2*m+1,0,0 ), 5 );
    else 
      q[m] = Weighted_point( Point( -2*m+1,0,0 ), 5 );
    T1.insert( q[m] );
    count++;
    if (count <10)
      std::cout << count << '\b' ;
    else
      if (count < 100)
  std::cout << count << '\b' << '\b' ;
      else
  std::cout << count << '\b' << '\b' << '\b' ;
    std::cout.flush();  
  }
  assert( T1.is_valid() );
  std::cout << std::endl << " number of vertices : " 
      << T1.number_of_vertices() << std::endl;

  std::cout << " number of inserted points : " ;
  Weighted_point r[10];
  for ( m=0; m<10; m++) {
    if ( (m%2)== 0 ) 
      r[m] = Weighted_point( Point( m,0,0 ), 1 );
    else 
      r[m] = Weighted_point( Point( -m,0,0 ), 1 );
    T1.insert( r[m] );
    count++;
    if (count <10)
      std::cout << count << '\b' ;
    else
      if (count < 100)
  std::cout << count << '\b' << '\b' ;
      else
  std::cout << count << '\b' << '\b' << '\b' ;
    std::cout.flush();  
  }
  assert( T1.is_valid() );
  std::cout << std::endl << " number of vertices : " 
      << T1.number_of_vertices() << std::endl;
  assert( T1.dimension()==1 );

  // The following is distilled from a bug report by Wulue Zhao
  // ([email protected]), a student of Tamal Dey.
  Point pt0(0,0,0);
  Point pt1( 1,0,0), pt2(2,0,0),  pt3(3,0,0);
  Point pt4(-1,0,0), pt5(-2,0,0), pt6(-3,0,0);

  Weighted_point wp0(pt0,10.0);
  Weighted_point wp1(pt1,0.0),  wp2(pt2,0.0),  wp3(pt3,0.0);
  Weighted_point wp4(pt4,0.0),  wp5(pt5,0.0),  wp6(pt6,0.0);

  Cls T11;

  T11.insert(wp0);
  T11.insert(wp1);
  T11.insert(wp2);
  T11.insert(wp3);
  T11.insert(wp4);
  T11.insert(wp5);
  T11.insert(wp6);

  assert(T11.is_valid());

  // And another distilled bug report from the same guy.
 {
  Point p1(-0.07, 0.04, 0.04);
  Point p2(0.09, 0.04, 0.04);
  Point p3(0.09, -0.05, 0.04);
  Point p4(0.05, -0.05, 0.04);
  Point p5(0.05, 0.0, 0.04);
  Point p6(-0.07, 0.0, 0.04);
  Point p7(-0.07, 0.04, -0.04);
  Point p8(0.09, 0.04, -0.04);
  Point p9(0.09, -0.05, -0.04);
  Point p10(0.05, -0.05, -0.04);
  Point p11(0.05, 0.0, -0.04);
  Point p12(-0.07, 0.0, -0.04);

  Weighted_point wp1(p1,0);
  Weighted_point wp2(p2,0);
  Weighted_point wp3(p3,0);
  Weighted_point wp4(p4,0);
  Weighted_point wp5(p5,0);
  Weighted_point wp6(p6,0);
  Weighted_point wp7(p7,0);
  Weighted_point wp8(p8,0);
  Weighted_point wp9(p9,0);
  Weighted_point wp10(p10,0);
  Weighted_point wp11(p11,0);
  Weighted_point wp12(p12,0);
  Weighted_point wp13(p3,0.3); // wp13 has the same coordinates with wp3

  Cls T111;

  T111.insert(wp1);
  T111.insert(wp2);
  T111.insert(wp3);
  T111.insert(wp13); // it doesnot work inserting wp13 here
  T111.insert(wp4);
  T111.insert(wp5);
  T111.insert(wp6);
  T111.insert(wp7);
  T111.insert(wp8);
  T111.insert(wp9);
  T111.insert(wp10);
  T111.insert(wp11);
  T111.insert(wp12);

  assert(T111.is_valid());
 }

  std::cout << " test dimension 2 " << std::endl;
  std::cout << " number of inserted points : " ;
  Cls T2;

  count = 0 ;
  int px=1, py=1;
  int qx=-1, qy=2;
  Weighted_point s[400];
  for (m=0; m<10; m++)
    for (n=0; n<10; n++) {
      s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), 1 );
      T2.insert( s[m+20*n] );
      count++;
      if (count <10)
  std::cout << count << '\b' ;
      else
  if (count < 100)
    std::cout << count << '\b' << '\b' ;
  else
    std::cout << count << '\b' << '\b' << '\b' ;
      std::cout.flush();
    }
  for (m=10; m<20; m++)
    for (n=0; n<10; n++) {
      s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), -1 );
      T2.insert( s[m+20*n] );
      count++;
      if (count <10)
  std::cout << count << '\b' ;
      else
  if (count < 100)
    std::cout << count << '\b' << '\b' ;
  else
    std::cout << count << '\b' << '\b' << '\b' ;
      std::cout.flush();
    }
  for (m=0; m<10; m++)
    for (n=10; n<20; n++) {
      s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), -2 );
      T2.insert( s[m+20*n] );
      count++;
      if (count <10)
  std::cout << count << '\b' ;
      else
  if (count < 100)
    std::cout << count << '\b' << '\b' ;
  else
    std::cout << count << '\b' << '\b' << '\b' ;
      std::cout.flush();
    }
  for (m=10; m<20; m++)
    for (n=10; n<20; n++) {
      s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), 5 );
      T2.insert( s[m+20*n] );
      count++;
      if (count <10)
  std::cout << count << '\b' ;
      else
  if (count < 100)
    std::cout << count << '\b' << '\b' ;
  else
    std::cout << count << '\b' << '\b' << '\b' ;
      std::cout.flush();
    }
 
  std::cout << std::endl << " number of vertices : " 
      << T2.number_of_vertices() << std::endl;
  assert( T2.dimension()==2 );
  assert( T2.is_valid() );

 // dimension 3
  std::cout << " test dimension 3" << std::endl;
  Cls T;

  list_point lp;
  int a, b, d;
  for (a=0;a!=10;a++)
    //    for (b=0;b!=10;b++)
    for (b=0;b!=5;b++)
      //      for (d=0;d!=10;d++)
      for (d=0;d!=5;d++)
  lp.push_back(Weighted_point( Point(a*b-d*a + (a-b)*10 +a ,
             a-b+d +5*b,
             a*a-d*d+b),
             a*b-a*d) );
  list_point::iterator it;
  count = 0 ;
  std::cout << " number of inserted points : " ;
  for (it=lp.begin(); it!=lp.end(); ++it){
    count++;
    T.insert(*it);
    if (count <10)
      std::cout << count << '\b' ;
    else
      if (count < 100)
        std::cout << count << '\b' << '\b' ;
      else 
        if (count < 1000)
          std::cout << count << '\b' << '\b' << '\b' ;
        else
    std::cout << count << std::endl;
    std::cout.flush();
  }
  std::cout << std::endl;

  std::cout << " number of vertices : " 
      << T.number_of_vertices() << std::endl;
  assert(T.is_valid());
  assert(T.dimension()==3);

  T.clear();
  std::cout << " test iterator range insert" << std::endl;
  T.insert (lp.begin(), lp.end());

  std::cout << " number of vertices : " 
      << T.number_of_vertices() << std::endl;
  assert(T.is_valid());
  assert(T.dimension()==3);


    //test nearest_power_vertex
  std::cout << " test nearest_power_vertex " << std::endl;
  Point pp1(0.0, 0.0, 0.0);
  Point pp2(1.0, 0.0, 0.0);
  Point pp3(0.0, 1.0, 0.0);
  Point pp4(0.0, 0.0, 1.0);
  Point pp5(1.0, 1.0, 0.0);
  Point pp6(0.0, 1.0, 1.0);
  Point pp7(1.0, 0.0, 1.0);
  Point pp8(1.0, 1.0, 1.0);

  Weighted_point wpp1(pp1, 1.0);
  Weighted_point wpp2(pp2, 2.0);
  Weighted_point wpp3(pp3, 1.0);
  Weighted_point wpp4(pp4, 4.0);
  Weighted_point wpp5(pp5, 1.0);
  Weighted_point wpp6(pp6, 1.0);
  Weighted_point wpp7(pp7, 1.0);
  Weighted_point wpp8(pp8, 8.0);

  Cls T3;

  T3.insert(wpp1);
  Vertex_handle v2 = T3.insert(wpp2);
  assert( T3.nearest_power_vertex(Point(0.5,0.5,0.5)) == v2);
  
  T3.insert(wpp3);
  Vertex_handle v4 = T3.insert(wpp4);
  assert( T3.nearest_power_vertex(Point(0.5,0.5,0.5)) == v4);

  T3.insert(wpp5);
  T3.insert(wpp6);
  T3.insert(wpp7);
  // Avoid inserting the same point twice, now that hidden points are handled,
  // insert (existing_point) returns Vertex_handle().
  // T3.insert(wpp8);
  Vertex_handle v8 = T3.insert(wpp8);
  Point query(0.5,0.5,0.5);
  assert(T3.nearest_power_vertex(query) == v8);
  assert(T3.nearest_power_vertex(Weighted_point(query,1.0)) == v8 );
  assert(T3.nearest_power_vertex_in_cell(query ,v8->cell()) == v8); 
  
  // test dual
  std::cout << " test dual member functions" << std::endl;
  Finite_cells_iterator fcit = T3.finite_cells_begin();
  for( ; fcit != T3.finite_cells_end(); ++fcit) {
    Point cc = T3.dual(fcit);
    Vertex_handle ncc = T3.nearest_power_vertex(cc);
    assert(fcit->has_vertex(ncc));
  }

  // test Gabriel
  std::cout << " test is_Gabriel " << std::endl;
  Point q0(0.,0.,0.);
  Point q1(2.,0.,0.);
  Point q2(0.,2.,0.);
  Point q3(0.,0.,2.);

  Weighted_point wq0(q0,0.);
  Weighted_point wq1(q1,0.);
  Weighted_point wq2(q2,0.);
  Weighted_point wq3(q3,0.);
  Weighted_point wq01(q0,2.);
  
  Cls T4;
  Vertex_handle v0 = T4.insert(wq0);
  Vertex_handle v1 = T4.insert(wq1);
  v2 = T4.insert(wq2);
  Vertex_handle v3 = T4.insert(wq3);
  Cell_handle c;
  int i,j,k,l;
  assert(T4.is_facet(v0,v1,v2,c,j,k,l));
  i = 6 - (j+k+l);
  Facet f = std::make_pair(c,i);
  assert(T4.is_Gabriel(c,i));
  assert(T4.is_Gabriel(f));
  assert(T4.is_facet(v1,v2,v3,c,j,k,l));
  i = 6 - (j+k+l);
  assert(!T4.is_Gabriel(c,i));
  assert(T4.is_edge(v0,v1,c,i,j));
  assert(T4.is_Gabriel(c,i,j));
  Edge e = make_triple(c,i,j);
  assert(T4.is_Gabriel(e));
  assert(T4.is_edge(v2,v3,c,i,j));
  assert(T4.is_Gabriel(c,i,j));
  
  Vertex_handle v01 = T4.insert(wq01);
  (void) v01; // kill warning
  assert(T4.is_edge(v2,v3,c,i,j));
  assert(!T4.is_Gabriel(c,i,j));

  Weighted_point wwq0(q0,0.);
  Weighted_point wwq1(q1,0.);
  Weighted_point wwq2(q2,0.);
  Weighted_point wwq3(q3,5.);
  Cls T5;
  v0 = T5.insert(wwq0);
  v1 = T5.insert(wwq1);
  v2 = T5.insert(wwq2);
  v3 = T5.insert(wwq3);
  assert(T5.nearest_power_vertex(v3->point().point()) == v3);
  assert(T5.nearest_power_vertex(v0->point().point()) == v3);
  assert(T5.is_Gabriel(v3));
  assert(!T5.is_Gabriel(v0));
}
Example #3
0
extern void run(OpenCVWindow * window) try{

    const auto images_names=
        CoreUtility::getConfigurationFile().getInputImagesNames("images:000001");
    assert(images_names.size());

    QImage image_input(images_names.first());
    image_input=image_input.convertToFormat(QImage::Format_Grayscale8);

    window->insertImage(image_input)->setWindowTitle(u8"原始图像"_qs);

    cv::Mat mat_input=OpenCVUtility::tryRead(image_input);
    assert( mat_input.channels() == 1 )/*这应当是一个灰度图像*/;

    /*计算获得dft变换所需要的长宽*/
    auto height_ = cv::getOptimalDFTSize(mat_input.rows);
    auto width_ = cv::getOptimalDFTSize(mat_input.cols);

    cv::Mat dft_real;
    /*扩展边界*/
    cv::copyMakeBorder(mat_input,dft_real,
        0/*top*/,height_-mat_input.rows/*bottom*/,
        0/*left*/,width_-mat_input.cols/*right*/,
        cv::BORDER_CONSTANT,cv::Scalar::all(0)
        );

    dft_real.convertTo(dft_real,CV_64FC1);
    cv::Mat dft_imag=cv::Mat::zeros(dft_real.size(),CV_64FC1);

    {
        cv::Mat dft_output;
        cv::merge(
            std::vector<cv::Mat>{ dft_real,dft_imag},
            dft_output);

        /*进行dft变换*/
        cv::dft(dft_output,dft_output);
        cv::split(dft_output,std::vector<cv::Mat>{ dft_real,dft_imag});
    }

    cv::Mat magI ;
    cv::magnitude(dft_real,dft_imag,magI);

    magI+=1;
    cv::log(magI,magI);//取对数
    magI= magI(cv::Rect(0,0,width_,height_));
    cv::normalize(magI,magI,0,255,CV_MINMAX);
    window->insertImage( OpenCVUtility::tryRead(magI ) )
        ->setWindowTitle(u8"变换后图像"_qs);

    {
        const auto w_2=width_/2;
        const auto h_2=height_/2;
        cv::Mat q0(magI,cv::Rect(0,0,w_2,h_2));
        cv::Mat q1(magI,cv::Rect(w_2,0,w_2,h_2));
        cv::Mat q2(magI,cv::Rect(0,h_2,w_2,h_2));
        cv::Mat q3(magI,cv::Rect(w_2,h_2,w_2,h_2));
        cv::flip(q0,q0,-1);
        cv::flip(q1,q1,-1);
        cv::flip(q2,q2,-1);
        cv::flip(q3,q3,-1);
    }
    window->insertImage( OpenCVUtility::tryRead(magI ) )
        ->setWindowTitle(u8"中心化后图像"_qs);

}
catch (const cv::Exception &e) {
    opencv_exception::error(e,"get opencv exception",opencv_line(),opencv_file(),opencv_func());
}
Example #4
0
int test_serial() {
    tbb::flow::graph g;
    tbb::flow::queue_node<T> q(g);
    tbb::flow::queue_node<T> q2(g);
    {   // destroy the graph after manipulating it, and see if all the items in the buffers
        // have been destroyed before the graph
        Check<T> my_check;  // if check_type< U > count constructions and destructions
        T bogus_value(-1);
        T j = bogus_value;

        //
        // Rejects attempts to add / remove predecessor
        // Rejects request from empty Q
        //
        ASSERT( q.register_predecessor( q2 ) == false, NULL );
        ASSERT( q.remove_predecessor( q2 ) == false, NULL );
        ASSERT( q.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );

        //
        // Simple puts and gets
        //

        for (int i = 0; i < N; ++i) {
            bool msg = q.try_put( T(i) );
            ASSERT( msg == true, NULL );
        }


        for (int i = 0; i < N; ++i) {
            j = bogus_value;
            spin_try_get( q, j );
            ASSERT( i == j, NULL );
        }
        j = bogus_value;
        g.wait_for_all();
        ASSERT( q.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );

        tbb::flow::make_edge( q, q2 );

        for (int i = 0; i < N; ++i) {
            bool msg = q.try_put( T(i) );
            ASSERT( msg == true, NULL );
        }


        for (int i = 0; i < N; ++i) {
            j = bogus_value;
            spin_try_get( q2, j );
            ASSERT( i == j, NULL );
        }
        j = bogus_value;
        g.wait_for_all();
        ASSERT( q.try_get( j ) == false, NULL );
        g.wait_for_all();
        ASSERT( q2.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );

        tbb::flow::remove_edge( q, q2 );
        ASSERT( q.try_put( 1 ) == true, NULL );
        g.wait_for_all();
        ASSERT( q2.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );
        g.wait_for_all();
        ASSERT( q.try_get( j ) == true, NULL );
        ASSERT( j == 1, NULL );

        tbb::flow::queue_node<T> q3(g);
        tbb::flow::make_edge( q, q2 );
        tbb::flow::make_edge( q2, q3 );

        for (int i = 0; i < N; ++i) {
            bool msg = q.try_put( T(i) );
            ASSERT( msg == true, NULL );
        }

        for (int i = 0; i < N; ++i) {
            j = bogus_value;
            spin_try_get( q3, j );
            ASSERT( i == j, NULL );
        }
        j = bogus_value;
        g.wait_for_all();
        ASSERT( q.try_get( j ) == false, NULL );
        g.wait_for_all();
        ASSERT( q2.try_get( j ) == false, NULL );
        g.wait_for_all();
        ASSERT( q3.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );

        tbb::flow::remove_edge( q,  q2 );
        ASSERT( q.try_put( 1 ) == true, NULL );
        g.wait_for_all();
        ASSERT( q2.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );
        g.wait_for_all();
        ASSERT( q3.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );
        g.wait_for_all();
        ASSERT( q.try_get( j ) == true, NULL );
        ASSERT( j == 1, NULL );
    }

    return 0;
}
Example #5
0
int test_parallel(int num_threads) {
    tbb::flow::graph g;
    tbb::flow::queue_node<T> q(g);
    tbb::flow::queue_node<T> q2(g);
    tbb::flow::queue_node<T> q3(g);
    {
        Check< T > my_check;
        T bogus_value(-1);
        T j = bogus_value;
        NativeParallelFor( num_threads, parallel_puts<T>(q) );

        T *next_value = new T[num_threads];
        for (int tid = 0; tid < num_threads; ++tid) next_value[tid] = T(0);

        for (int i = 0; i < num_threads * N; ++i ) {
            spin_try_get( q, j );
            check_item( next_value, j );
            j = bogus_value;
        }
        for (int tid = 0; tid < num_threads; ++tid)  {
            ASSERT( next_value[tid] == T(N), NULL );
        }
        delete[] next_value;

        j = bogus_value;
        g.wait_for_all();
        ASSERT( q.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );

        NativeParallelFor( num_threads, parallel_puts<T>(q) );

        {
            touches< T > t( num_threads );
            NativeParallelFor( num_threads, parallel_gets<T>(q, t) );
            g.wait_for_all();
            ASSERT( t.validate_touches(), NULL );
        }
        j = bogus_value;
        ASSERT( q.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );

        g.wait_for_all();
        {
            touches< T > t2( num_threads );
            NativeParallelFor( num_threads, parallel_put_get<T>(q, t2) );
            g.wait_for_all();
            ASSERT( t2.validate_touches(), NULL );
        }
        j = bogus_value;
        ASSERT( q.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );

        tbb::flow::make_edge( q, q2 );
        tbb::flow::make_edge( q2, q3 );

        NativeParallelFor( num_threads, parallel_puts<T>(q) );
        {
            touches< T > t3( num_threads );
            NativeParallelFor( num_threads, parallel_gets<T>(q3, t3) );
            g.wait_for_all();
            ASSERT( t3.validate_touches(), NULL );
        }
        j = bogus_value;
        g.wait_for_all();
        ASSERT( q.try_get( j ) == false, NULL );
        g.wait_for_all();
        ASSERT( q2.try_get( j ) == false, NULL );
        g.wait_for_all();
        ASSERT( q3.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );

        // test copy constructor
        ASSERT( q.remove_successor( q2 ), NULL );
        NativeParallelFor( num_threads, parallel_puts<T>(q) );
        tbb::flow::queue_node<T> q_copy(q);
        j = bogus_value;
        g.wait_for_all();
        ASSERT( q_copy.try_get( j ) == false, NULL );
        ASSERT( q.register_successor( q_copy ) == true, NULL );
        {
            touches< T > t( num_threads );
            NativeParallelFor( num_threads, parallel_gets<T>(q_copy, t) );
            g.wait_for_all();
            ASSERT( t.validate_touches(), NULL );
        }
        j = bogus_value;
        ASSERT( q.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );
        ASSERT( q_copy.try_get( j ) == false, NULL );
        ASSERT( j == bogus_value, NULL );
    }

    return 0;
}
Example #6
0
int main()
{
  {
    Point_2 p1(0,0), p2(2,0), p3(1,3), q1(0,2), q2(2,2), q3(1,-1);
    Triangle_2 t1(p1,p2,p3);
    Triangle_2 t2(q1,q2,q3);
    
    Segment_2 s1(p1,p3), s2(p2, q1);
    CGAL::Object obj = CGAL::intersection(t1,t2);
    const std::vector<Point_2> *V;
    if( !(V = CGAL::object_cast<std::vector<Point_2> > (&obj))  ){
      std::cerr << "ERROR" << std::endl;
      return EXIT_FAILURE;
    }
    else{
      std::cerr << "OK" << std::endl;
      for(std::size_t i = 0; i < V->size(); i++){
        std::cerr << (*V)[i] << std::endl;
        std::cerr << CGAL::exact((*V)[i]) << std::endl;
      } 
    }
    obj = CGAL::intersection(s1,s2);

    // check the variant return type
    CGAL::cpp11::result_of<K::Intersect_2(Triangle_2, Triangle_2) >::type o_variant = CGAL::intersection(t1,t2);
    if(!o_variant) {
      std::cerr << "ERROR, empty" << std::endl;
      return EXIT_FAILURE;
    }
    
    V = NULL; 
    if( !(V = boost::get<std::vector<Point_2> >(&(*o_variant)))  ){
      std::cerr << "ERROR, something other than vector< point_2 >" << std::endl;
      return EXIT_FAILURE;
    }
    else {
      std::cerr << "OK" << std::endl;
      for(std::size_t i = 0; i < V->size(); i++){
        std::cerr << (*V)[i] << std::endl;
        std::cerr << CGAL::exact((*V)[i]) << std::endl;
      } 
    }
  }

  {
    Point_3 p1(0,0,1), p2(2,0,1), p3(1,3,1), q1(0,2,1), q2(2,2,1), q3(1,-1,1);
    Triangle_3 t1(p1,p2,p3);
    Triangle_3 t2(q1,q2,q3);
    
    CGAL::Object obj = CGAL::intersection(t1,t2);
    const std::vector<Point_3> *V;
    if( !(V = CGAL::object_cast<std::vector<Point_3> > (&obj))  ){
      std::cerr << "ERROR" << std::endl;
      return EXIT_FAILURE;
    }
    else{
      std::cerr << "OK" << std::endl;
      for(std::size_t i = 0; i < V->size(); i++){
        std::cerr << (*V)[i] << std::endl;
        std::cerr << CGAL::exact((*V)[i]) << std::endl;
      } 
    }

    // check the variant return type
    CGAL::cpp11::result_of<K::Intersect_3(Triangle_3, Triangle_3)>::type o_variant = CGAL::intersection(t1,t2);
    if(!o_variant) {
      std::cerr << "ERROR, empty" << std::endl;
      return EXIT_FAILURE;
    }

    V = NULL;
    if( !(V = boost::get<std::vector<Point_3> > (&(*o_variant)))  ){
      std::cerr << "ERROR" << std::endl;
      return EXIT_FAILURE;
    }
    else{
      std::cerr << "OK" << std::endl;
      for(std::size_t i = 0; i < V->size(); i++){
        std::cerr << (*V)[i] << std::endl;
        std::cerr << CGAL::exact((*V)[i]) << std::endl;
      } 
    }
  }
  //making the interval construction failing
  {
    double eps = std::numeric_limits<double>::epsilon();
    std::cout << "Epsilon is " << eps << std::endl;
    Point_2 p1(0,0), p2(2,0), p3(1,3), q1(0,eps), q2(2,eps), q3(1,-1);
    Triangle_2 t1(p1,p2,p3);
    Triangle_2 t2(q1,q2,q3);
    
    Segment_2 s1(p1,p3), s2(p2, q1);
    CGAL::Object obj = CGAL::intersection(t2,t1);
    const std::vector<Point_2> *V;
    if( !(V = CGAL::object_cast<std::vector<Point_2> > (&obj))  ){
      std::cerr << "ERROR" << std::endl;
      return EXIT_FAILURE;
    }
    else{
      std::cerr << "OK" << std::endl;
      for(std::size_t i = 0; i < V->size(); i++){
        std::cerr << "A " << (*V)[i] << std::endl;
        std::cerr << "E " << CGAL::exact((*V)[i]) << std::endl;
      } 
      assert(V->size()==6);
    }
    obj = CGAL::intersection(s1,s2);
  }

  
}
Example #7
0
void init_mine_mesh(GLShape& base_mesh, GLShape& wheel_mesh) {
    float d = 0.025f;
    float x0 = 1.5f * d;
    float x1 = 2.0f * d;
    float y0 = 3.0f * d;
    float y1 = 4.0f * d;
    float z0 = d * 0.25f;
    float z1 = d;
    
    Vector3 p0(-x1, 0.0f, z1);
    Vector3 p1(-x0, 0.0f, z1);
    Vector3 p2(-x0, y0, z0);
    Vector3 p3(x0, y0, z0);
    Vector3 p4(x0, 0.0f, z1);
    Vector3 p5(x1, 0.0f, z1);
    Vector3 p6(x1, y1, 0.0f);
    Vector3 p7(-x1, y1, 0.0f);
    
    Vector3 q0(-x1, 0.0f, -z1);
    Vector3 q1(-x0, 0.0f, -z1);
    Vector3 q2(-x0, y0, -z0);
    Vector3 q3(x0, y0, -z0);
    Vector3 q4(x0, 0.0f, -z1);
    Vector3 q5(x1, 0.0f, -z1);
    Vector3 q6(x1, y1, 0.0f);
    Vector3 q7(-x1, y1, 0.0f);
    
    base_mesh = {
        p0, p1, p2, p0, p2, p7, p2, p3, p6, p2, p6, p7, p3, p4, p5, p3, p5, p6,
        q0, q1, q2, q0, q2, q7, q2, q3, q6, q2, q6, q7, q3, q4, q5, q3, q5, q6
    };
    
    std::vector<Vector2> wheel = circle(Vector2(), 3.0f * d, 16);
    wheel = cut(wheel, circle(Vector2(), 2.5f * d, 16));
    
    wheel_mesh = to_xy(triangulate(wheel));
    
    Vector3 w0(-d * 0.25f, -2.75f * d, 0.0f);
    Vector3 w1(d * 0.25f, -2.75f * d, 0.0f);
    Vector3 w2(d * 0.25f, 2.75f * d, 0.0f);
    Vector3 w3(-d * 0.25f, 2.75f * d, 0.0f);
    
    Vector3 w4(-d * 2.75f, -0.25f * d, 0.0f);
    Vector3 w5(d * 2.75f, -0.25f * d, 0.0f);
    Vector3 w6(d * 2.75f, 0.25f * d, 0.0f);
    Vector3 w7(-d * 2.75f, 0.25f * d, 0.0f);
    
    wheel_mesh.push_back(w0);
    wheel_mesh.push_back(w1);
    wheel_mesh.push_back(w2);
    wheel_mesh.push_back(w0);
    wheel_mesh.push_back(w2);
    wheel_mesh.push_back(w3);
    
    wheel_mesh.push_back(w4);
    wheel_mesh.push_back(w5);
    wheel_mesh.push_back(w6);
    wheel_mesh.push_back(w4);
    wheel_mesh.push_back(w6);
    wheel_mesh.push_back(w7);
}