//! Convertion des valeurs de lecture d'un point théorique en valeur réelle
void CalibrationUtils::cameraToScreenSpace(float &x, float &y)
{
	vector2df pt = vector2df(x, y);
	triangle* t;
    float alpha, beta;

    //Si le point est dans la zone de calibration
	if (inCalibrationSector(x, y))
	{
        //Recherche du triangle contenant le point (ou les trois points les plus proche selon les cas)
	    t = findTriangleWithin(pt);
        //
        if ((t->s1->coord != pt) && (t->s2->coord != pt) && (t->s3->coord != pt))
        {
            //beta  = .....
            beta = ( ( t->s3->_y() - pt.Y ) * ( t->s1->_x() - pt.X ) + ( pt.X - t->s3->_x() ) * ( t->s1->_y() - pt.Y ) )
                   / ( ( t->s2->_x() - pt.X ) * ( t->s1->_y() - pt.Y) + ( pt.Y - t->s2->_y() ) * ( t->s1->_x() - pt.X ) );

            //alpha = .....
            alpha = ( beta * ( pt.X - t->s2->_x() ) + ( pt.X - t->s3->_x()) )
                    / ( t->s1->_x() - pt.X );

            //pt    = (alpha*A + beta*B + C)/(alpha+beta+1)
            x = ( alpha * t->s1->_x() + beta * t->s2->_x() + t->s3->_x() ) / ( alpha + beta + 1 );
            y = ( alpha * t->s1->_y() + beta * t->s2->_y() + t->s3->_y() ) / ( alpha + beta + 1 );
        }
	}
}
Example #2
0
void ofxMultiplexer::cameraToScreenSpace(unsigned int &x, unsigned int &y,vector2df* screenPoints,vector2df* cameraPoints,int* triangles)
{
	vector2df pt((float)x, (float)y);
	int t = findTriangleWithin(pt,screenPoints,triangles);
	if(t != -1)
	{
		vector2df A = screenPoints[triangles[t+0]];
		vector2df B = screenPoints[triangles[t+1]];
		vector2df C = screenPoints[triangles[t+2]];

		float total_area = (A.X - B.X) * (A.Y - C.Y) - (A.Y - B.Y) * (A.X - C.X);
		float area_A = (pt.X - B.X) * (pt.Y - C.Y) - (pt.Y - B.Y) * (pt.X - C.X);
		float area_B = (A.X - pt.X) * (A.Y - C.Y) - (A.Y - pt.Y) * (A.X - C.X);
		float bary_A = area_A / total_area;
		float bary_B = area_B / total_area;
		float bary_C = 1.0f - bary_A - bary_B;
		
		vector2df sA = cameraPoints[triangles[t+0]];
		vector2df sB = cameraPoints[triangles[t+1]];
		vector2df sC = cameraPoints[triangles[t+2]];

		vector2df transformedPos;

		transformedPos = (sA*bary_A) + (sB*bary_B) + (sC*bary_C);

		x = (unsigned int)transformedPos.X;
		y = (unsigned int)transformedPos.Y;
		return;
	}
	x = 0;
	y = 0;
}
Example #3
0
// Transforms a camera space coordinate into a screen space coord
void calibrationB::cameraToScreenSpace(float &x, float &y)
{

	vector2df pt(x, y);
	
	int t = findTriangleWithin(pt);

	if(t != -1)
	{

		vector2df A = cameraPoints[triangles[t+0]];
		vector2df B = cameraPoints[triangles[t+1]];
		vector2df C = cameraPoints[triangles[t+2]];
		float total_area = (A.X - B.X) * (A.Y - C.Y) - (A.Y - B.Y) * (A.X - C.X);

		// pt,B,C
		float area_A = (pt.X - B.X) * (pt.Y - C.Y) - (pt.Y - B.Y) * (pt.X - C.X);

		// A,pt,C
		float area_B = (A.X - pt.X) * (A.Y - C.Y) - (A.Y - pt.Y) * (A.X - C.X);

		float bary_A = area_A / total_area;
		float bary_B = area_B / total_area;
		float bary_C = 1.0f - bary_A - bary_B;	// bary_A + bary_B + bary_C = 1

		vector2df sA = screenPoints[triangles[t+0]];
		vector2df sB = screenPoints[triangles[t+1]];
		vector2df sC = screenPoints[triangles[t+2]];

		vector2df transformedPos;

		transformedPos = (sA*bary_A) + (sB*bary_B) + (sC*bary_C);

		x = transformedPos.X;
		y = transformedPos.Y;
		return;
	}

	x = 0;
	y = 0;
	// FIXME: what to do in the case that it's outside the mesh?
}
Example #4
0
// Transforms a camera space coordinate into a screen space coord
void CalibrationUtils::cameraToScreenSpace(float &x, float &y)
{
	vector2df pt(x, y);

	int t = findTriangleWithin(pt);

	if(t != -1)
	{
		vector2df A = cameraPoints[triangles[t+0]];
		vector2df B = cameraPoints[triangles[t+1]];
		vector2df C = cameraPoints[triangles[t+2]];
		float total_area = (A.X - B.X) * (A.Y - C.Y) - (A.Y - B.Y) * (A.X - C.X);

		// pt,B,C
		float area_A = (pt.X - B.X) * (pt.Y - C.Y) - (pt.Y - B.Y) * (pt.X - C.X);

		// A,pt,C
		float area_B = (A.X - pt.X) * (A.Y - C.Y) - (A.Y - pt.Y) * (A.X - C.X);

		float bary_A = area_A / total_area;
		float bary_B = area_B / total_area;
		float bary_C = 1.0f - bary_A - bary_B;	// bary_A + bary_B + bary_C = 1

		vector2df sA = screenPoints[triangles[t+0]];
		vector2df sB = screenPoints[triangles[t+1]];
		vector2df sC = screenPoints[triangles[t+2]];

		vector2df transformedPos;

		transformedPos = (sA*bary_A) + (sB*bary_B) + (sC*bary_C);

		x = transformedPos.X;
		y = transformedPos.Y;
		return;
	}

	// If not in the mesh then set the position to something identifiable so we can remove it later
	x = -1;
        y = -1;
}