void GraphicWindow::ellipse(double center_x, double center_y, double ra, double rb)
{  
   int cx = user_to_disp_x(center_x);
   int cy = user_to_disp_y(center_y);
   double a = fabs(user_to_disp_dx(ra));
   double b = fabs(user_to_disp_dy(rb));
   
   int x = 0;
   int y = (int)(b + 0.5);
   double d1 = b * b - a * a * b + a * a / 4;
   set4(x, y, cx, cy);
   
   while (a * a * (y - 0.5) > b * b * (x + 1))
   {  
      if (d1 < 0)
      {  
         d1 += b * b * (2 * x + 3);
         x++;
      }
      else
      {  
         d1 += b * b * (2 * x + 3) + a * a * (-2 * y + 2);
         x++;
         y--;
      }
      set4(x, y, cx, cy);
   }
   
   double d2 = b * b * (x + 0.5) * (x + 0.5) + a * a * (y - 1) * (y - 1) - a * a * b * b;
   while (y > 0)
   {  
      if (d2 < 0)
      {  
         d2 += b * b * (2 * x + 2) + a * a * (-2 * y + 3);
         x++;
         y--;
      }
      else
      {  
         d2 += a * a * (-2 * y + 3);
         y--;
      }
      set4(x, y, cx, cy);
   }

   dirty = true;
}
Example #2
0
int main(int argc, char *argv[])
{
  /* sets to be used for testing */
  char s[5] = {'1','2','3','4','\0'};
  char t[4] = {'1','2','3','\0'};
  char u[1] = {'\0'};
  char v[4] = {'x','y','z','\0'};
  
  /* sets to contain results */
  char a[SIZE];
  char b[SIZE];
  char c[SIZE];
  char d[SIZE];
  
  /* SetTypes for testing */
  SetType set1(s);
  SetType set2(t);
  SetType set3(u);
  
  /* test of is_empty. Should output "Set is empty" followed by "Set is not
      empty */
  set3.is_empty() ? cout << "Set is empty\n" : cout << "Set is not empty\n";
  set1.is_empty() ? cout << "Set is empty\n" : cout << "Set is not empty\n";
  
  /* test of is_equal. Should output "s is equal" followed by "t is not equal" 
  */
  set1.is_equal(s) ? cout << "s is equal\n" : cout << "s is not equal\n";
  set1.is_equal(t) ? cout << "t is equal\n" : cout << "t is not equal\n";
  
  /* test of is_member. Should output "4 is a member" followed by "8 is not a
      member */
  set1.is_member('4') ? cout << "4 is a member\n" : cout << "4 is not a member\n";
  set1.is_member('8') ? cout << "8 is a member\n" : cout << "8 is not a member\n";
  
  /* test of is_subset. Should output "t is a subset" followed by "v is not a
      subset */
  set1.is_subset(t) ? cout << "t is a subset\n" : cout << "t is not a subset\n";
  set1.is_subset(v) ? cout << "v is a subset\n" : cout << "v is not a subset\n";
  
  /* test of setunion. Should output all elements from s and v. Implicitly
      tests the write function. */
  set1.setunion(v, a);
  SetType set4(a);
  set4.write();
  
  /* test of intersection. Should output all elements in both t and s. */
  set1.intersection(t, b);
  SetType set5(b);
  set5.write();
  
  /* test of difference. Should output all elements only in t or only in s */
  set1.difference(t, d);
  SetType set7(d);
  set7.write();

  /* return success */
  return 0;
}
Example #3
0
Multitap::Multitap(unsigned long initialSize)
{
	sse = SSEDetect();

	amp = (__m128 *) _aligned_malloc(sizeof(__m128)*32,32);
	delay = (unsigned long *) _aligned_malloc(sizeof(unsigned long)*32,32);
	delayfpu = (unsigned long *) _aligned_malloc(sizeof(unsigned long)*32,32);

	buffer = 0;

	buffersize = 0;
	mask = 0;
	indexfpu = 0;
	maskfpu = 0;

	for(long i=0;i<32;i++)
	{
		delayfpu[i] = 0;
		delay[i] = 0;
		set4(amp[i],0.f);
	}

	setDelay(initialSize >= 1024 ? initialSize : 1024);
}
 void    SetTagSize(DWORD size)	{ set4(data,0,size);	}
 void    SetHeaderOffset(DWORD o){ set4(data,5,o); 	}
Example #6
0
int main(int argc, char *argv[]) 
{
  int file;

  unsigned long i    = argc; /* dummy use of argc to fix compiler warning */
  unsigned long len  = 0;

  struct stat sbuf;
  struct stat fbuf;

  /* For compression.
   */
  lzo_byte *    inbuf;
  lzo_byte *    outbuf;
  int           r;
  lzo_uint      in_len;
  lzo_uint      out_len;


  char *        p;

  char          fname[128];
#if defined (__linux__)
  char          pname[128];
#endif

  UINT32        pid;

  /* no SUID
   */
  if (getuid() != geteuid())
    {
      setuid(getuid());
    }

  /* reset umask 
   */
  umask(0);


  astate[0] = programkey_0[0];
  astate[1] = programkey_0[1];
  astate[2] = programkey_0[2];

  taus_set_from_state (cstate, astate);

  out_len = (unsigned long) programlen_compressed_0;
  len     = (unsigned long) programlen_0;

  outbuf  = program_0;

  /* Decode.
   */
  for (i = 0; i < out_len; ++i)
    {
      outbuf[i] ^= (taus_get_long (cstate) & 0xff);
    }


  inbuf  = (lzo_byte *) malloc (sizeof(lzo_byte) * len);


  /*
   * Step 1: initialize the LZO library
   */
  if (lzo_init() != LZO_E_OK)
    {
      return 1;
    }

  /*
   * Step 2: decompress again, now going from `out' to `in'
   */
  r = lzo1x_decompress_safe (outbuf, out_len, inbuf, &in_len, NULL);

  if (r == LZO_E_OK && in_len == len)
    {
      /*
      printf("decompressed %lu bytes back into %lu bytes\n",
	     (long) out_len, (long) in_len);
      */
      ;
    }
  else
    {
      /*
      printf("internal error - decompression failed: %d\n", 
	     r);
      */
      return 2;
    }

  /*
   * Step 3: choose a filename
   */

 nameIt:

  p  = fname;

  /* --- use /tmp if the sticky bit is set ---
   */
#if defined(S_ISVTX)

  set4 (p, '/', 't', 'm', 'p');
  p += 4;
  *p = '\0';

  if ( 0 != stat(fname, &sbuf))
    {
      if ( (sbuf.st_mode & S_ISVTX) != S_ISVTX)
	{
	  p  = fname;
	  set4 (p, '/', 'u', 's', 'r');
	  p += 4;
	  set4 (p, '/', 'b', 'i', 'n');
	  p += 4;
	}
    }

#else

  set4 (p, '/', 'u', 's', 'r');
  p += 4;
  set4 (p, '/', 'b', 'i', 'n');
  p += 4;

#endif

  set4 (p, '/', 't', 'm', 'p');

  p += 4;

  cstate[0] ^= (UINT32) getpid ();
  cstate[1] ^= (UINT32) time (NULL);
  cstate[0] |= (UINT32) 0x03;
  cstate[1] |= (UINT32) 0x09;

  pid = (UINT32) (taus_get_long (cstate) ^ taus_get_long (cstate));

  for (i = 0; i < 4; ++i)
    {
      *p = 'a' + (pid % 26);
      pid /= 26;
      ++p;
    }

  pid = (UINT32) (taus_get_long (cstate) ^ taus_get_long (cstate));

  for (i = 0; i < 4; ++i)
    {
      *p = 'a' + (pid % 26);
      pid /= 26;
      ++p;
    }

  pid = (UINT32) (taus_get_long (cstate) ^ taus_get_long (cstate));

  for (i = 0; i < 3; ++i)
    {
      *p = 'a' + (pid % 26);
      pid /= 26;
      ++p;
    }
  *p = '\0';

  if ( (-1) != stat(fname, &sbuf) || errno != ENOENT)
    {
      /* because cstate[2] is not initialized, the next name will
       * be different
       */
      goto nameIt;
    } 
      
  if ((file = open (fname, O_CREAT|O_EXCL|O_WRONLY, 0700)) < 0)
    {
      return (4);
    } 

  write(file, inbuf, in_len);

#if defined(__linux__)

  if ( 0 != fstat(file, &sbuf))
    {
      return (5);
    } 
  
  /* Must reopen for read only.
   */
  close(file);
  file = open (fname, O_RDONLY, 0);

  if ( 0 != fstat(file, &fbuf))
    {
      return (6);
    } 

  /* check mode, inode, owner, and device, to make sure it is the same file
   */
  if (sbuf.st_mode != fbuf.st_mode || 
      sbuf.st_ino  != fbuf.st_ino  || 
      sbuf.st_uid  != fbuf.st_uid  ||
      sbuf.st_gid  != fbuf.st_gid  ||
      sbuf.st_dev  != fbuf.st_dev )
    {
      close  ( file );
      return ( 6 );
    }
  
  p = pname;
  set4(p, '/', 'p', 'r', 'o');
  p += 4;

  set2(p, 'c', '/');
  p += 2;

  set4(p, 's', 'e', 'l', 'f');
  p += 4;

  set4(p, '/', 'f', 'd', '/');
  p += 4;

  sprintf(p, "%d", file);


  if (0 == access(pname, R_OK|X_OK))
    {
      unlink (fname);
      fcntl  (file, F_SETFD, FD_CLOEXEC);
      execve (pname, argv, environ); 
      return (8);
    }
#endif

  /* /proc not working, or not linux
   */
  close (file);

  if ( (i = fork()) != 0) 
    {
      wait   (NULL);
      execve (fname, argv, environ);
      unlink (fname);
      return (9);
    } 
  else if (i == 0)
    {
      if (0 == fork())
	{
	  sleep  (3);
	  unlink (fname);
	}
      return (0);
    }

  /* only reached in case of error 
   */
  unlink (fname);
  return (-1);
}
Example #7
0
// constructor
MyWindow::MyWindow(int w, int h) : 
  red_active(false),
  red_set(*(new Polygon_set)),
  blue_set(*(new Polygon_set)),
  res_set(*(new Polygon_set))										  
{
  widget = new CGAL::Qt_widget(this); //Constructs a widget which is a child of this window


  /* Sets the central widget for this main window to w.
   * The central widget is surrounded by the left, top, right and bottom dock areas.
   * The menu bar is above the top dock area
   */
  setCentralWidget(widget);

  file_name= QString::null;

  //create a timer for checking if somthing changed
  QTimer *timer = new QTimer( this ); // constructs a timer whose parent is this window

  connect( timer, SIGNAL(timeout()),
           this, SLOT(timer_done()) );  // connects the timer to the window
  timer->start( 200, FALSE ); // Starts the timer with a msec milliseconds timeout

  // file menu
  QPopupMenu * file = new QPopupMenu( this );
  menuBar()->insertItem( "&File", file );
  file->insertItem("&New", this, SLOT(new_instance()), CTRL+Key_N);
  file->insertItem("New &Window", this, SLOT(new_window()), CTRL+Key_W);
  file->insertSeparator();
  file->insertItem("&Open Linear Polygon file", this, SLOT(open_linear_polygon_file()),CTRL+Key_O);
  file->insertItem("&Open DXF file", this, SLOT(open_dxf_file()),CTRL+Key_D);
  file->insertSeparator();
  //file->insertItem("&Save",this ,SLOT(save_file()),CTRL+Key_S);
  //file->insertItem("&Save as",this ,SLOT(save_file_as()));
  file->insertSeparator();
  file->insertItem("Print", widget, SLOT(print_to_ps()), CTRL+Key_P);
  file->insertSeparator();
  file->insertItem( "&Close", this, SLOT(close()), CTRL+Key_X );
  file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q );

  // help menu
  QPopupMenu * help = new QPopupMenu( this );
  menuBar()->insertItem( "&Help", help );
  help->insertItem("How To", this, SLOT(howto()), Key_F1);
  help->insertSeparator();
  help->insertItem("&About", this, SLOT(about()), CTRL+Key_A );
  help->insertItem("About &Qt", this, SLOT(aboutQt()) );

  //the standard toolbar
  stoolbar = new CGAL::Qt_widget_standard_toolbar (widget, this, "ST");

  radiotoolbar = new QToolBar(this, "polygon type");
  blue_pgn = new QRadioButton ("Blue", radiotoolbar);
  blue_pgn->toggle();
  red_pgn = new QRadioButton("Red", radiotoolbar);
  radio_group = new QVButtonGroup(this,"Radios");
  radio_group->insert(blue_pgn);
  radio_group->insert(red_pgn);
  radio_group->setRadioButtonExclusive(true);


  connect(blue_pgn, SIGNAL(toggled (bool)),
	  this, SLOT(radio_selected()));
  connect(red_pgn, SIGNAL(toggled (bool)),
	  this, SLOT(radio_selected()));


  //layers
  //widget->attach(&testlayer);

  //the new tools toolbar
  newtoolbar = new Tools_toolbar(widget, this);

  // voronoi toolbar
  bops_toolbar = new QToolBar(this, "Boolean operations");

  QIconSet set0(QPixmap( (const char**)intersection_xpm ),
		QPixmap( (const char**)intersection_xpm ));

  intersection_but = new QToolButton(bops_toolbar, "Boolean operations");
  intersection_but->setAutoRaise(TRUE);

  intersection_but->setIconSet(set0);
  intersection_but->setTextLabel("Intersection ");
  connect(intersection_but,SIGNAL(pressed()),
	  this, SLOT(perform_intersection()));

  QIconSet set1(QPixmap( (const char**)union_xpm ),
		QPixmap( (const char**)union_xpm ));

  bops_toolbar->addSeparator();
  union_but = new QToolButton(bops_toolbar, "Boolean operations");
  union_but->setAutoRaise(TRUE);

  union_but->setIconSet(set1);
  union_but->setTextLabel("Union ");
  connect(union_but,SIGNAL(pressed()),
	  this, SLOT(perform_union()));

  QIconSet set2(QPixmap( (const char**)diff_PQ_xpm ),
		QPixmap( (const char**)diff_PQ_xpm ));

  bops_toolbar->addSeparator();
  diff_but2 = new QToolButton(bops_toolbar, "Boolean operations");
  diff_but2->setAutoRaise(TRUE);

  diff_but2->setIconSet(set2);
  diff_but2->setTextLabel("Difference between Blue and Red");
  connect(diff_but2, SIGNAL(pressed()),
	  this, SLOT(perform_diff2()));

  QIconSet set3(QPixmap( (const char**)diff_QP_xpm ),
		QPixmap( (const char**)diff_QP_xpm ));

  bops_toolbar->addSeparator();
  diff_but = new QToolButton(bops_toolbar, "Boolean operations");
  diff_but->setAutoRaise(TRUE);

  diff_but->setIconSet(set3);
  diff_but->setTextLabel("Difference between Red and Blue");
  connect(diff_but, SIGNAL(pressed()),
	  this, SLOT(perform_diff()));

  QIconSet set4(QPixmap( (const char**)symm_diff_xpm ),
		QPixmap( (const char**)symm_diff_xpm ));
  bops_toolbar->addSeparator();

  symm_diff_but = new QToolButton(bops_toolbar, "Boolean operations");
  symm_diff_but->setAutoRaise(TRUE);

  symm_diff_but->setIconSet(set4);
  symm_diff_but->setTextLabel("Symmetric Difference ");
  connect(symm_diff_but, SIGNAL(pressed()),
	  this, SLOT(perform_symm_diff()));

  QIconSet set12(QPixmap( (const char**)mink_sum_xpm ),
		 QPixmap( (const char**)mink_sum_xpm ));
  bops_toolbar->addSeparator();
  mink_sum_but = new QToolButton(bops_toolbar, "Boolean operations");
  mink_sum_but->setAutoRaise(TRUE);
  mink_sum_but->setIconSet(set12);
  mink_sum_but->setTextLabel("Minkowski Sum ");
  connect(mink_sum_but, SIGNAL(pressed()),
	  this, SLOT(perform_mink_sum()));

  QIconSet set5(QPixmap( (const char**)comp_P_xpm ),
		QPixmap( (const char**)comp_P_xpm ));
  bops_toolbar->addSeparator();

  blue_complement_but = new QToolButton(bops_toolbar, "Boolean operations");
  blue_complement_but->setAutoRaise(TRUE);

  blue_complement_but->setIconSet(set5);
  blue_complement_but->setTextLabel("Blue Complement ");
  connect(blue_complement_but, SIGNAL(pressed()),
	  this, SLOT(perform_blue_complement()));

  QIconSet set6(QPixmap( (const char**)comp_Q_xpm ),
		QPixmap( (const char**)comp_Q_xpm ));
  bops_toolbar->addSeparator();

  red_complement_but = new QToolButton(bops_toolbar, "Boolean operations");
  red_complement_but->setAutoRaise(TRUE);

  red_complement_but->setIconSet(set6);
  red_complement_but->setTextLabel("Red Complement ");
  connect(red_complement_but, SIGNAL(pressed()),
	  this, SLOT(perform_red_complement()));


  QIconSet set7(QPixmap( (const char**)make_P_xpm ),
		QPixmap( (const char**)make_P_xpm ));
  bops_toolbar->addSeparator();
  make_res_blue_but = new QToolButton(bops_toolbar, "Boolean operations");
  make_res_blue_but->setAutoRaise(TRUE);


  make_res_blue_but->setIconSet(set7);
  make_res_blue_but->setTextLabel("Make Result Blue");
  connect(make_res_blue_but,SIGNAL(pressed()),
	  this, SLOT(make_res_blue()));

  QIconSet set8(QPixmap( (const char**)make_Q_xpm ),
		QPixmap( (const char**)make_Q_xpm ));
  bops_toolbar->addSeparator();
  make_res_red_but = new QToolButton(bops_toolbar, "Boolean operations");
  make_res_red_but->setAutoRaise(TRUE);


  make_res_red_but->setIconSet(set8);
  make_res_red_but->setTextLabel("Make Result Red");
  connect(make_res_red_but,SIGNAL(pressed()),
	  this, SLOT(make_res_red()));

  QIconSet set9(QPixmap( (const char**)refresh_xpm ),
		QPixmap( (const char**)refresh_xpm ));
  bops_toolbar->addSeparator();

  refresh_but = new QToolButton(bops_toolbar, "Boolean operations");
  refresh_but->setAutoRaise(TRUE);

  refresh_but->setIconSet(set9);
  refresh_but->setTextLabel("Refresh ");
  connect(refresh_but,SIGNAL(pressed()),
	  this, SLOT(refresh()));

  QIconSet set10(QPixmap( (const char**)del_P_xpm ),
		 QPixmap( (const char**)del_P_xpm ));
  bops_toolbar->addSeparator();

  delete_blue_but = new QToolButton(bops_toolbar, "Boolean operations");
  delete_blue_but->setAutoRaise(TRUE);

  delete_blue_but->setIconSet(set10);
  delete_blue_but->setTextLabel("Delete Blue Polygons");
  connect(delete_blue_but,SIGNAL(pressed()),
	  this, SLOT(delete_blue_polygons()));


  QIconSet set11(QPixmap( (const char**)del_Q_xpm ),
		 QPixmap( (const char**)del_Q_xpm ));
  bops_toolbar->addSeparator();

  delete_red_but = new QToolButton(bops_toolbar, "Boolean operations");
  delete_red_but->setAutoRaise(TRUE);

  delete_red_but->setIconSet(set11);
  delete_red_but->setTextLabel("Delete Red Polygons");
  connect(delete_red_but,SIGNAL(pressed()),
	  this, SLOT(delete_red_polygons()));




  *widget << CGAL::LineWidth(2) << CGAL::BackgroundColor (CGAL::BLACK);

  resize(w,h);
  widget->set_window(-1, 1, -1, 1);
  widget->setMouseTracking(TRUE);

  //connect the widget to the main function that receives the objects
  connect(widget, SIGNAL(new_cgal_object(CGAL::Object)),
	  this, SLOT(get_new_object(CGAL::Object)));

  //application flag stuff
  old_state = 0;
  current_state = 1;
  red_active = false;
  red_set.clear();
  blue_set.clear();
  res_set.clear();
}
Example #8
0
static void drawTriangle(double x1,double y1,double z1,double u1,double v1,  double x2,double y2,double z2,double u2,double v2,  double x3,double y3,double z3,double u3,double v3, int tries) {
	set4(tempVert1, x1,y1,z1,1);
	set4(tempVert2, x2,y2,z2,1);
	set4(tempVert3, x3,y3,z3,1);

	multMatVec(completeMat, tempVert1, tempVert1);
	multMatVec(completeMat, tempVert2, tempVert2);
	multMatVec(completeMat, tempVert3, tempVert3);

	
	double oz1 = z1, oz2 = z2, oz3 = z3;
	
	double w1, w2, w3,
		miX, miY, maX, maY,
	        //x01, y01, z01,
	        x21, y21, z21,
	        x31, y31, z31,
	        //x32, y32, z32,
		az, bz, c,
	        //au, bu,
		//av, bv,
		area,
		s, t,
		depth;
		
	int x,y, u,v, miXi,miYi,maXi,maYi;
	//double ow1, ow2, ow3;
	
	
	
	/*ow1 = */w1 = tempVert1[3];	
	z1 = tempVert1[2]; ///w1;

	/*ow2 = */w2 = tempVert2[3];				
	z2 = tempVert2[2]; ///w2;
	
	/*ow3 = */w3 = tempVert3[3];
	z3 = tempVert3[2]; ///w3;

	// Completely outside of the frustem
	if(tries == 0) {
		if((z1 < near && z2 < near && z3 < near) || (z1 > far && z2 > far && z3 > far)) {
			////printf("offscreen...\n");
			return;
		}

		//Partially outside, need to clip
		if(z1 < pseudoNear || z2 < pseudoNear || z3 < pseudoNear) {		
			//printf("CLIP!\n");
			clip(x1,y1,oz1,u1,v1,	z1,
				x2,y2,oz2,u2,v2,	z2,
				x3,y3,oz3,u3,v3,	z3);
			return;
		}
	}
	
	//printf("ws <%lf, %lf, %lf>\n", w1, w2, w3);	

	w1 = fabs(w1);
	x1 = tempVert1[0]/-w1;
	y1 = tempVert1[1]/-w1;

	w2 = fabs(w2);
	x2 = tempVert2[0]/-w2;
	y2 = tempVert2[1]/-w2;
	
	w3 = fabs(w3);
	x3 = tempVert3[0]/-w3;
	y3 = tempVert3[1]/-w3;

	/*printf("--------------------------\n");	
	printf("ws <%lf, %lf, %lf>\n", w1, w2, w3);	
	printf("pt1 <%lf, %lf, %lf>\n", x1, y1, z1);
	printf("pt2 <%lf, %lf, %lf>\n", x2, y2, z2);
	printf("pt3 <%lf, %lf, %lf>\n", x3, y3, z3);
	printf("--------------------------\n");	
	printf("\n");*/
	
	
	miX = (x1 < x2) ? ((x1 < x3) ? x1 : x3) : ((x2 < x3) ? x2 : x3);
	miY = (y1 < y2) ? ((y1 < y3) ? y1 : y3) : ((y2 < y3) ? y2 : y3);
	maX = (x1 > x2) ? ((x1 > x3) ? x1 : x3) : ((x2 > x3) ? x2 : x3);
	maY = (y1 > y2) ? ((y1 > y3) ? y1 : y3) : ((y2 > y3) ? y2 : y3);

	miXi = (int) ((miX < 0) ? 0 : miX);
	miYi = (int) ((miY < 0) ? 0 : miY);
	maXi = (int) ((maX < RESOLUTION_WIDTH) ? maX : RESOLUTION_WIDTH);
	maYi = (int) ((maY < RESOLUTION_HEIGHT) ? maY : RESOLUTION_HEIGHT);

	x21 = x2-x1;
	y21 = y2-y1;
	z21 = z2-z1;

	x31 = x3-x1;
	y31 = y3-y1;
	z31 = z3-z1;
	
	/*
	x32 = x3-x2;
	y32 = y3-y2;
	z32 = z3-z2;
	*/

	az = y21*z31 - y31*z21;
	bz = -x21*z31 + x31*z21;
	c = x21*y31 - x31*y21;

	area = .5*(-y2*x3 + y1*(-x2+x3) + x1*(y2-y3) + x2*y3);
	
	if(area == 0)
		return;

	
	double b1, b2, b3, 
		bDenom = -1./((y2-y3)*x31 + (x3-x2)*y31);

	int index, dRGBA=0, 
		dR=0, dG=0, dB=0, dA=0,
		pR=0, pG=0, pB=0, pA=0;
	double val = 1, wp, up, vp, fr;						
	for(x = miXi; x < maXi; x++) {
		for(y = miYi; y < maYi; y++) {
			s = 1/(2*area)*(y1*x3 - x1*y3 + y31*x - x31*y);
			t = 1/(2*area)*(x1*y2 - y1*x2 - y21*x + x21*y);
			
			if(0 <= s && s <= 1 && 0 <= t && t <= 1 && s+t <= 1) {
				depth = (z1 + (az*(x-x1) + bz*(y-y1))/-c);
			
				b1 = ((y2-y3)*(x-x3) + (x3-x2)*(y-y3)) * bDenom;
				b2 = ((y3-y1)*(x-x3) + (x1-x3)*(y-y3)) * bDenom;
				b3 = 1. - b1 - b2;
								
				if(!doDepthTest || (depth >= near && depth <= far)) {
					index = y*RESOLUTION_WIDTH + x;

					if(!doDepthTest || (depth < depths[index])) {
						depths[index] = depth;
						
						if(texture == NULL || !doTexture) {
							if(!doFog)
								pixels[index] = RGBA;
							else {
								val = contain(0, (far-depth)/(far-near), 1);
								pixels[index] = convertRGB2Int((int)(R*val),(int)(G*val),(int)(B*val));
							}
						}
						else {
							wp = ( 1 / w1 ) * b1 + ( 1 / w2 ) * b2 + ( 1 / w3 ) * b3;
							up = ( ( u1 / w1 ) * b1 + ( u2 / w2 ) * b2 + ( u3 / w3 ) * b3 ) / wp;
							vp = ( ( v1 / w1 ) * b1 + ( v2 / w2 ) * b2 + ( v3 / w3 ) * b3 ) / wp;
						
							if(up < 0 || up > 1)
								up = fabs(fmod(up,1));
							if(vp < 0 || vp > 1)
								vp = fabs(fmod(vp,1));
						
							u = (int)(textureWidth * up);
							v = (int)(textureHeight * vp);

							
							dRGBA = texture[textureWidth*v + u];
							convertInt2RGBA(dRGBA, &dR,&dG,&dB,&dA);
							
							dR = (int) (dR/255. * R);
							dG = (int) (dG/255. * G);
							dB = (int) (dB/255. * B);
							dA = (int) (dA/255. * A);
							
							if(dA == 0)
								continue;
							
							dRGBA = convertRGBA2Int(dR,dG,dB,dA);
						
							
							if(!doFog) {
								if(dA == 255)
									pixels[index] = dRGBA;
								else if (dA > 0) {
									convertInt2RGBA(pixels[index], &pR,&pG,&pB,&pA);
									
									fr = dA/255.;

									// Colors have to be squared!
									pR = sqrt((1-fr)*pR*pR + fr*dR*dR);
									pG = sqrt((1-fr)*pG*pG + fr*dG*dG);
									pB = sqrt((1-fr)*pB*pB + fr*dB*dB);
									
									pixels[index] = convertRGB2Int((int)(pR),(int)(pG),(int)(pB));	
								}
							}
							else {
								val = contain(0, (far-depth)/(far-near), 1);
								
								if(dA == 1)
									pixels[index] = convertRGB2Int((int)(dR*val),(int)(dG*val),(int)(dB*val));
								else {
									convertInt2RGBA(pixels[index], &pR,&pG,&pB,&pA);
									pixels[index] = convertRGB2Int((int)(dR*val),(int)(dG*val),(int)(dB*val));									
								}									
							}
						}
					}
				}
			}
		}
	}
}
Example #9
0
int main() {
	srand(static_cast<unsigned int>(time(NULL)));
	std::vector<int> set1(10,0);
	set1[9] = 31;
	set1[8] = 30;
	set1[7] = 24;
	set1[6] = 15;
	set1[5] = 13;
	set1[4] = 10;
	set1[3] = 9;
	set1[2] = 5;
	set1[1] = 4;
	set1[0] = 2;
	MySet obj1(set1);

	std::cout << "Set 1: " << obj1 << std::endl << std::endl;

	//Insert
	for (int i = 0; i < 20; i++) {
		int randNum = rand() % 1000;
		std::cout << "Lets insert " << randNum << " into the set";
		obj1.insert(randNum);
		std::cout << obj1 << std::endl << std::endl;
	}

	//Remove
	for (int i = 0; i < 20; i++) {
		int randNum = rand() % 20;
		std::cout << "Lets remove " << randNum << " into the set";
		obj1.remove(randNum);
		std::cout << obj1 << std::endl << std::endl;
	}

	std::cout << std::endl << std::endl;
	

	//New Set
	std::vector<int> set2(30,0);
	for (int i = 0; i < set2.size(); i++) {
		set2[i] = rand() % 1000;
	}
	MySet obj2(set2);
	std::cout << "Set 2: " << obj2 << std::endl;

	std::vector<int> set3(30, 0);
	for (int i = 0; i < set3.size(); i++) {
		set3[i] = rand() % 1000;
	}
	MySet obj3(set3);
	std::cout << "Set 3: " << obj3 << std::endl;

	//Add
	std::cout << "Set 3 + Set 2: ";
	std::cout << (obj3 + obj2) << std::endl << std::endl;

	//Sub
	std::cout << "Set 3 - Set 2: ";
	std::cout << (obj3 - obj2) << std::endl << std::endl;

	//Intersect
	std::cout << "Set 3 & Set 2: ";
	std::cout << (obj3 & obj2) << std::endl << std::endl;

	//Equals
	std::cout << "Set 3 == Set 2: ";
	std::cout << (obj3 == obj2 ? "Yes" : "No") << std::endl << std::endl << std::endl;

	//New Set
	std::vector<int> set4(30, 0);
	for (int i = 0; i < set4.size(); i++) {
		set4[i] = rand() % 1000;
	}
	MySet obj4(set4);
	std::cout << "Set 4: " << obj4 << std::endl;

	MySet obj5(set4);
	std::cout << "Set 5: " << obj5 << std::endl;

	//Equals
	std::cout << "Set 4 == Set 5: ";
	std::cout << (obj4 == obj5 ? "Yes" : "No") << std::endl;

	return 0;
}
static void TestBitSet(skiatest::Reporter* reporter) {
    SkBitSet set0(65536);
    REPORTER_ASSERT(reporter, set0.isBitSet(0) == false);
    REPORTER_ASSERT(reporter, set0.isBitSet(32767) == false);
    REPORTER_ASSERT(reporter, set0.isBitSet(65535) == false);

    SkBitSet set1(65536);
    REPORTER_ASSERT(reporter, set0 == set1);

    set0.setBit(22, true);
    REPORTER_ASSERT(reporter, set0.isBitSet(22) == true);
    set0.setBit(24, true);
    REPORTER_ASSERT(reporter, set0.isBitSet(24) == true);
    set0.setBit(35, true);  // on a different DWORD
    REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
    set0.setBit(22, false);
    REPORTER_ASSERT(reporter, set0.isBitSet(22) == false);
    REPORTER_ASSERT(reporter, set0.isBitSet(24) == true);
    REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);

    SkTDArray<unsigned int> data;
    set0.exportTo(&data);
    REPORTER_ASSERT(reporter, data.count() == 2);
    REPORTER_ASSERT(reporter, data[0] == 24);
    REPORTER_ASSERT(reporter, data[1] == 35);

    set1.setBit(12345, true);
    set1.orBits(set0);
    REPORTER_ASSERT(reporter, set0.isBitSet(12345) == false);
    REPORTER_ASSERT(reporter, set1.isBitSet(12345) == true);
    REPORTER_ASSERT(reporter, set1.isBitSet(22) == false);
    REPORTER_ASSERT(reporter, set1.isBitSet(24) == true);
    REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
    REPORTER_ASSERT(reporter, set1 != set0);

    set1.clearAll();
    REPORTER_ASSERT(reporter, set0.isBitSet(12345) == false);
    REPORTER_ASSERT(reporter, set1.isBitSet(12345) == false);
    REPORTER_ASSERT(reporter, set1.isBitSet(22) == false);
    REPORTER_ASSERT(reporter, set1.isBitSet(24) == false);
    REPORTER_ASSERT(reporter, set1.isBitSet(35) == false);

    set1.orBits(set0);
    REPORTER_ASSERT(reporter, set1 == set0);

    SkBitSet set2(1);
    SkBitSet set3(1);
    SkBitSet set4(4);
    SkBitSet set5(33);

    REPORTER_ASSERT(reporter, set2 == set3);
    REPORTER_ASSERT(reporter, set2 != set4);
    REPORTER_ASSERT(reporter, set2 != set5);

    set2.setBit(0, true);
    REPORTER_ASSERT(reporter, set2 != set5);
    set5.setBit(0, true);
    REPORTER_ASSERT(reporter, set2 != set5);
    REPORTER_ASSERT(reporter, set2 != set3);
    set3.setBit(0, true);
    REPORTER_ASSERT(reporter, set2 == set3);
    set3.clearAll();
    set3 = set2;
    set2 = set2;
    REPORTER_ASSERT(reporter, set2 == set3);
}
Tools_toolbar::Tools_toolbar(CGAL::Qt_widget *w,
			     QMainWindow *mw, std::vector<Point_2> *l1) :
  QToolBar(mw, "NT")
  {
    w->attach(&edit_layer);
    w->attach(&point_layer);
    w->attach(&iso_r_layer);
    w->attach(&circle_layer);
    edit_layer.deactivate();
    point_layer.deactivate();
    iso_r_layer.deactivate();
    circle_layer.deactivate();
    edit_layer.pass_the_structure(l1);

    //set the widget
    widget = w;

    QIconSet set0(QPixmap( (const char**)arrow_small_xpm ),
                  QPixmap( (const char**)arrow_xpm ));
    QIconSet set1(QPixmap( (const char**)point_small_xpm ),
                  QPixmap( (const char**)point_xpm ));
    QIconSet set2(QPixmap( (const char**)iso_rectangle_small_xpm ),
                  QPixmap( (const char**)iso_rectangle_xpm ));
    QIconSet set3(QPixmap( (const char**)circle_small_xpm ),
                  QPixmap( (const char**)circle_xpm ));
    QIconSet set4(QPixmap( (const char**)movepoint_small_xpm ),
                  QPixmap( (const char**)movepoint_xpm ));


  but[0] = new QToolButton(this, "deactivate layer");
  but[0]->setIconSet(set0);
  but[0]->setTextLabel("Deactivate Layer");
  but[1] = new QToolButton(this, "pointtool");
  but[1]->setIconSet(set1);
  but[1]->setTextLabel("Input Point");
  but[2] = new QToolButton(this, "iso_rectangle");
  but[2]->setIconSet(set2);
  but[2]->setTextLabel("Input Iso_rectangle");
  but[3] = new QToolButton(this, "iso_rectangle");
  but[3]->setIconSet(set3);
  but[3]->setTextLabel("Input Circle");
  but[4] = new QToolButton(this, "move/delete tool");
  but[4]->setIconSet(set4);
  but[4]->setTextLabel("Move/Delete Point");

  nr_of_buttons = 5;
  button_group = new QButtonGroup(0, "My_group");
  for(int i = 0; i<nr_of_buttons; i++) {
    button_group->insert(but[i]);
    but[i]->setToggleButton(true);
  }
  button_group->setExclusive(true);

  connect(but[1], SIGNAL(stateChanged(int)),
        &point_layer, SLOT(stateChanged(int)));
  connect(but[2], SIGNAL(stateChanged(int)),
        &iso_r_layer, SLOT(stateChanged(int)));
  connect(but[3], SIGNAL(stateChanged(int)),
        &circle_layer, SLOT(stateChanged(int)));
  connect(but[4], SIGNAL(stateChanged(int)),
        &edit_layer, SLOT(stateChanged(int)));
  but[1]->toggle();
}
Example #12
0
MediaFrame* H264Depacketizer::AddPayload(BYTE* payload, DWORD payload_len)
{
	BYTE nalHeader[4];
	BYTE nal_unit_type;
	BYTE nal_ref_idc;
	BYTE S, E;
	DWORD nalu_size;
	DWORD pos;
	//Check lenght
	if (!payload_len)
		//Exit
		return NULL;

	/* +---------------+
	 * |0|1|2|3|4|5|6|7|
	 * +-+-+-+-+-+-+-+-+
	 * |F|NRI|  Type   |
	 * +---------------+
	 *
	 * F must be 0.
	 */
	nal_ref_idc = (payload[0] & 0x60) >> 5;
	nal_unit_type = payload[0] & 0x1f;

	//printf("[NAL:%x,type:%x]\n", payload[0], nal_unit_type);

	//Check type
	switch (nal_unit_type)
	{
		case 0:
		case 30:
		case 31:
			/* undefined */
			return NULL;
		case 25:
			/* STAP-B		Single-time aggregation packet		 5.7.1 */
			/* 2 byte extra header for DON */
			/** Not supported */
			return NULL;
		case 24:
			/**
			   Figure 7 presents an example of an RTP packet that contains an STAP-
			   A.  The STAP contains two single-time aggregation units, labeled as 1
			   and 2 in the figure.

			       0                   1                   2                   3
			       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
			      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
			      |                          RTP Header                           |
			      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
			      |STAP-A NAL HDR |         NALU 1 Size           | NALU 1 HDR    |
			      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
			      |                         NALU 1 Data                           |
			      :                                                               :
			      +               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
			      |               | NALU 2 Size                   | NALU 2 HDR    |
			      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
			      |                         NALU 2 Data                           |
			      :                                                               :
			      |                               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
			      |                               :...OPTIONAL RTP padding        |
			      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

			      Figure 7.  An example of an RTP packet including an STAP-A and two
					 single-time aggregation units
			*/
			//Everything goes to the payload
			frame.AddRtpPacket(0,0,payload,payload_len);

			/* Skip STAP-A NAL HDR */
			payload++;
			payload_len--;

			/* STAP-A Single-time aggregation packet 5.7.1 */
			while (payload_len > 2)
			{
				/* Get NALU size */
				nalu_size = (payload[0] << 8) | payload[1];

				/* strip NALU size */
				payload += 2;
				payload_len -= 2;

				//Get nal type
				BYTE nalType = payload[0] & 0x1f;
				//Check it
				if (nalType==0x05)
					//It is intra
					frame.SetIntra(true);

				//Set size
				set4(nalHeader,0,nalu_size);
				//Append data
				//frame.AppendMedia(sync_bytes, sizeof (sync_bytes));
				frame.AppendMedia(nalHeader, sizeof (nalHeader));
				
				//Append NAL
				frame.AppendMedia(payload,nalu_size);
				
				payload += nalu_size;
				payload_len -= nalu_size;
			}
			break;
		case 26:
			/* MTAP16 Multi-time aggregation packet	5.7.2 */
			return NULL;
		case 27:
			/* MTAP24 Multi-time aggregation packet	5.7.2 */
			return NULL;
		case 28:
		case 29:
			/* FU-A	Fragmentation unit	 5.8 */
			/* FU-B	Fragmentation unit	 5.8 */


			/* +---------------+
			 * |0|1|2|3|4|5|6|7|
			 * +-+-+-+-+-+-+-+-+
			 * |S|E|R| Type	   |
			 * +---------------+
			 *
			 * R is reserved and always 0
			 */
			S = (payload[1] & 0x80) == 0x80;
			E = (payload[1] & 0x40) == 0x40;

			/* strip off FU indicator and FU header bytes */
			nalu_size = payload_len-2;

			if (S)
			{
				/* NAL unit starts here */
				BYTE nal_header;

				/* reconstruct NAL header */
				nal_header = (payload[0] & 0xe0) | (payload[1] & 0x1f);

				//Get nal type
				BYTE nalType = nal_header & 0x1f;
				//Check it
				if (nalType==0x05)
					//It is intra
					frame.SetIntra(true);

				//Get init of the nal
				iniFragNALU = frame.GetLength();
				//Set size with start code
				set4(nalHeader,0,1);
				//Append data
				frame.AppendMedia(nalHeader, sizeof (nalHeader));
				//Append NAL header
				frame.AppendMedia(&nal_header,1);
			}

			//Get position
			pos = frame.GetLength();
			//Append data
			frame.AppendMedia(payload+2,nalu_size);
			//Add rtp payload
			frame.AddRtpPacket(pos,nalu_size,payload,2);

			if (E)
			{
				//Get NAL size
				DWORD nalSize = frame.GetLength()-iniFragNALU-4;
				//Set it
				set4(frame.GetData(),iniFragNALU,nalSize);
			}
			//Done
			break;
		default:
			/* 1-23	 NAL unit	Single NAL unit packet per H.264	 5.6 */
			//Check it
			if (nal_unit_type==0x05)
				//It is intra
				frame.SetIntra(true);
			/* the entire payload is the output buffer */
			nalu_size = payload_len;
			//Set size
			set4(nalHeader,0,nalu_size);
			//Append data
			frame.AppendMedia(nalHeader, sizeof (nalHeader));
			//Get current position in frame
			DWORD pos = frame.GetLength();
			//And data
			frame.AppendMedia(payload, nalu_size);
			//Add RTP packet
			frame.AddRtpPacket(pos,nalu_size,NULL,0);
			//Done
			break;
	}

	return &frame;
}