Exemple #1
0
 void affixPos(sf::Vertex sprite[4], sf::Vector2f pos, sf::Vector2f size, int reference)
 {
     sf::Vector2f hSize(size.x / 2.f, size.y / 2.f);
     sf::Vector2f realPos = referenceToCenter(pos, size, reference);
     sprite[0].position = sf::Vector2f(realPos.x - hSize.x, realPos.y - hSize.y);
     sprite[1].position = sf::Vector2f(realPos.x + hSize.x, realPos.y - hSize.y);
     sprite[2].position = sf::Vector2f(realPos.x + hSize.x, realPos.y + hSize.y);
     sprite[3].position = sf::Vector2f(realPos.x - hSize.x, realPos.y + hSize.y);
 }
Exemple #2
0
rpmRC rpmwfInit(rpmwf wf, const char * fn, const char * fmode)
{
if (_rpmwf_debug)
fprintf(stderr, "==> rpmwfInit(%p, %s, %s)\n", wf, fn, fmode);
    if (fn == NULL)
	fn = wf->fn;
assert(fn != NULL);

/*@-globs@*/
    wf->fd = Fopen(fn, fmode);
/*@=globs@*/
    if (wf->fd == NULL || Ferror(wf->fd)) {
	(void) rpmwfFini(wf);
	return RPMRC_NOTFOUND;
    }

    if (fmode && *fmode == 'r') {
	wf->b = mmap(NULL, wf->nb, PROT_READ, MAP_SHARED, Fileno(wf->fd), 0L);

	if (wf->b == (void *)-1) {
	    wf->b = NULL;
	    (void) rpmwfFini(wf);
	    return RPMRC_NOTFOUND;
	}

	wf->l = (char *) wf->b;
assert(wf->l != NULL);
	wf->nl = 96;

	wf->s = wf->l + wf->nl;
	wf->ns = hSize((rpmuint32_t *)wf->s);
	wf->ns += ((8 - (wf->ns % 8)) % 8);	/* padding */

	wf->h = wf->s + wf->ns;
	wf->nh = hSize((rpmuint32_t *)wf->h);

	wf->p = wf->h + wf->nh;
	wf->np = wf->nb;
	wf->np -= wf->nl + wf->ns + wf->nh;
    }

    return RPMRC_OK;
}
Exemple #3
0
vec3f Plane::ClampPointInRect( const Rectangle &rect, const vec3f &point ) const
{
	const vec3f dir = P - point;

	vec2f dist2D( Dot( dir, rect.ex ), Dot( dir, rect.ey ) );
	vec2f hSize( rect.hx, rect.hy );
	dist2D.x = std::min( hSize.x, std::max( -hSize.x, dist2D.x ) );
	dist2D.y = std::min( hSize.y, std::max( -hSize.y, dist2D.y ) );

	return point + rect.ex * dist2D.x + rect.ey * dist2D.y;
}
Exemple #4
0
void Cell::integrateAndUpdate(Real dt){
	//incremental displacement gradient
	_trsfInc=dt*gradV;
	// total transformation; M = (Id+G).M = F.M
	trsf+=_trsfInc*trsf;
	_invTrsf=trsf.inverse();

	if(trsfUpperTriangular) checkTrsfUpperTriangular();

	// hSize contains colums with updated base vectors
	Matrix3r prevHsize=hSize; // remember old value
	if(homoDeform==HOMO_GRADV2) hSize=(Matrix3r::Identity()-gradV*dt/2.).inverse()*(Matrix3r::Identity()+gradV*dt/2.)*hSize;
	else hSize+=_trsfInc*hSize;
	pprevHsize=.5*(prevHsize+hSize); // average of previous and current value

	if(hSize.determinant()==0){ throw std::runtime_error("Cell is degenerate (zero volume)."); }
	// lengths of transformed cell vectors, skew cosines
	Matrix3r Hnorm; // normalized transformed base vectors
	for(int i=0; i<3; i++){
		Vector3r base(hSize.col(i));
		_size[i]=base.norm(); base/=_size[i]; //base is normalized now
		Hnorm(0,i)=base[0]; Hnorm(1,i)=base[1]; Hnorm(2,i)=base[2];
	};
	// skew cosines
	for(int i=0; i<3; i++){
		int i1=(i+1)%3, i2=(i+2)%3;
		// sin between axes is cos of skew
		_cos[i]=(Hnorm.col(i1).cross(Hnorm.col(i2))).squaredNorm();
	}
	// pure shear trsf: ones on diagonal
	_shearTrsf=Hnorm;
	// pure unshear transformation
	_unshearTrsf=_shearTrsf.inverse();
	// some parts can branch depending on presence/absence of shear
	_hasShear=(hSize(0,1)!=0 || hSize(0,2)!=0 || hSize(1,0)!=0 || hSize(1,2)!=0 || hSize(2,0)!=0 || hSize(2,1)!=0);
	// OpenGL shear matrix (used frequently)
	fillGlShearTrsfMatrix(_glShearTrsfMatrix);

	if(!(homoDeform==HOMO_NONE || homoDeform==HOMO_POS || homoDeform==HOMO_VEL || homoDeform==HOMO_VEL_2ND || homoDeform==HOMO_GRADV2)) throw std::invalid_argument("Cell.homoDeform must be in {0,1,2,3,4}.");
}
Exemple #5
0
const WordInfo*
Pst::
useHeadC(const ECString& head)
{
  int top = hSize();
  int bot = -1;
  for( ; ; )
    {
      if( top <= bot+1 )return NULL;
      int mid = (top+bot)/2;
      const WordInfo* midH = &(h_[mid]);
      ECString midString = midH->lexeme();
      if( head == midString )
	return midH;
      else if( head < midString )
	top = mid;
      else bot = mid;
    }
}
Exemple #6
0
 sf::Vector2f referenceToCenter(sf::Vector2f pos, sf::Vector2f size, int reference)
 {
     sf::Vector2f hSize(size.x / 2.f, size.y / 2.f);
     sf::Vector2f realPos = pos;
     if (reference == 1) {
         realPos.x += hSize.x;
         realPos.y += hSize.y;
     }
     else if (reference == 2) {
         realPos.x -= hSize.x;
         realPos.y += hSize.y;
     }
     else if (reference == 3) {
         realPos.x -= hSize.x;
         realPos.y -= hSize.y;
     }
     else if (reference == 4) {
         realPos.x += hSize.x;
         realPos.y -= hSize.y;
     }
     return realPos;
 }
Exemple #7
0
void GUITable::draw( sf::RenderWindow* window )
{
	// Primero dibujar el rectangulo de fila seleccionada
	if (selectedRow != DEFAULT_ROW_SELECTED)
	{
		highlight.setPosition(this->position.x, this->position.y + (selectedRow * ROW_HEIGHT));
		// Largo de la tabla y alto de altura de filas
		sf::Vector2f hSize(this->size.x, ROW_HEIGHT);
		highlight.setSize(hSize); // SFML pide este tipo de vector para el size pero no para el position O_o
		window->draw(highlight);
	}

	// Titulo de cada columna
	for (size_t i = 0; i < columns.size(); i++)
	{
		columns[i].caption->draw(window);
	}

	// Recorremos las celdas para dibujar su elemento GUIText
	for ( size_t i = 0; i < cells.size(); i++ )
	{
		cells[i].text->draw(window);
	}
}
bool TransportSimple::retargetImage(cv::Mat const &input,
                                    int     const &colReduc, 
                                    int     const &rowReduc,
                                    cv::Mat       &output)
{
   // Create the grayscale
   cv::cvtColor(input, m_gray, CV_RGB2GRAY);
   cv::Mat workImg;
   cv::Mat workRGB;
   input.copyTo(workRGB);
   m_gray.copyTo(workImg);

   // Start at zero and evaluate every option
   // until we get to the required number of cuts
   int colCount = 0;
   int rowCount = 0;

   // Keep track of the size
   cv::Size size(input.cols,input.rows);
   cv::Size inSize(0,0);
   cv::Size hSize(0,0);

   // Create some extra helpers
   cv::Mat hCutImg, vCutImg;
   cv::Mat hPath,   vPath;
   float   hCost = 0;
   float   vCost = 0;
   
   // Create a window
   cv::namedWindow("Carved",1);
   cv::Mat tmpRGB, hTmp;
   // Iterate until one of the counters is zero
   while( colCount < colReduc && rowCount < rowReduc )
   {
      // Calculate a vertical cut
      inSize.width  = input.cols-colCount;
      inSize.height = input.rows-rowCount;
      calculateSeamCost( workImg, vCutImg, vPath, vCost ,true,inSize);

      // Calculate a horizontal cut
      inSize.width  = input.rows-rowCount;
      inSize.height = input.cols-colCount;
      calculateSeamCost( workImg, hCutImg, hPath, hCost ,false,inSize);

      if( hCost < vCost ) // take the horizontal cut
      {
         hCutImg.copyTo(workImg);
         --size.height;

         // Transpose
         cv::transpose(workRGB,tmpRGB);
         hSize.width  = size.height;
         hSize.height = size.width;
         Filters::removeSeamRGB(tmpRGB,hPath,workRGB,hSize); 
         cv::transpose(workRGB,tmpRGB);
         ++rowCount;
      }
      else
      {
         vCutImg.copyTo(workImg);
         --size.width;
         Filters::removeSeamRGB(workRGB,vPath,tmpRGB,size); 
         ++colCount;
      }
      tmpRGB.copyTo(workRGB);
      cv::imshow("Carved",workRGB);
      cv::waitKey(5);
   }

   // One of them hit zero, which was it?
   while( colCount < colReduc )
   {
      // Calculate a vertical cut
      inSize.width  = input.cols-colCount;
      inSize.height = input.rows-rowCount;
      calculateSeamCost( workImg, vCutImg, vPath, vCost ,true,inSize);
      vCutImg.copyTo(workImg);
  
      // Update the size
      ++colCount;
      --size.width;
  
      Filters::removeSeamRGB(workRGB,vPath,tmpRGB,size);
      tmpRGB.copyTo(workRGB);
 
      // Display the result
      cv::imshow("Carved",workRGB);
      cv::waitKey(5);
   }
   while( rowCount < rowReduc )
   {
      // Calculate a vertical cut
      inSize.height = input.cols-colCount;
      inSize.width = input.rows-rowCount;
      calculateSeamCost( workImg, hCutImg, hPath, hCost ,false,inSize);
      hCutImg.copyTo(workImg);

      // Update the size
      ++rowCount;
      --size.height;

      // Transpose
      cv::transpose(workRGB,tmpRGB);
      hSize.width  = size.height;
      hSize.height = size.width;
      Filters::removeSeamRGB(tmpRGB,hPath,workRGB,hSize); 
      cv::transpose(workRGB,tmpRGB);
      tmpRGB.copyTo(workRGB);

      // Display
      cv::imshow("Carved",workRGB);
      cv::waitKey(5);

   }

   cv::Rect roi(0,0,size.width,size.height);
   cv::Mat  tmpOut = workRGB(roi);
   tmpOut.copyTo(output);
   return true;
}