QPixmap RectificationController::assistedFromProjectionToSimilarity(ClickableLabel* projectedImageLabel, const QSize& POISize,
											 bool pointOfInterestFlag)
	{	
		// First, create pairs of point correlations between projection and world space.
		CircularList<SelectedPixel*>* selectedPixelsProj = projectedImageLabel->getSelectedPixels();
		int numSelectedPixels = selectedPixelsProj->size();
		
		vector<QPoint> selectedPixelsWorld(numSelectedPixels);
		selectedPixelsWorld[0] = QPoint(0, 0);
		selectedPixelsWorld[1] = selectedPixelsWorld[0] + QPoint(0, POISize.height());
		selectedPixelsWorld[2] = selectedPixelsWorld[0] + QPoint(POISize.width(), POISize.height());
		selectedPixelsWorld[3] = selectedPixelsWorld[0] + QPoint(POISize.width(), 0);
		
		vector<pair<VectorXd, VectorXd>> correlationPoints(numSelectedPixels);
		
		for (int i = 0; i < numSelectedPixels; ++i)
		{
			QPoint qProjectedPoint = (*selectedPixelsProj)[i]->getPos();
			QPoint qWorldPoint = selectedPixelsWorld[i];
			
			VectorXd projectedPoint(3);
			projectedPoint << qProjectedPoint.x(), qProjectedPoint.y(), 1.;
			VectorXd worldPoint(3);
			worldPoint << qWorldPoint.x(), qWorldPoint.y(), 1.;
			
			pair<VectorXd, VectorXd> correlationPair(projectedPoint, worldPoint);
			correlationPoints[i] = correlationPair;
		}
		
		// Second, define the projection to world transformation.
		AssistedSimilarityFromProjRectificator rectificator(correlationPoints);
		MatrixXd projToWorld = *rectificator.getTransformation();
		
		// Qt uses the transpose of the usual transformation representation.
		QTransform qProjToWorld(
			projToWorld(0, 0), projToWorld(1, 0), projToWorld(2, 0),
			projToWorld(0, 1), projToWorld(1, 1), projToWorld(2, 1),
			projToWorld(0, 2), projToWorld(1, 2), projToWorld(2, 2)
		);
		
		QPixmap rectifiedPixmap = projectedImageLabel->pixmap()->transformed(qProjToWorld, Qt::SmoothTransformation);
		
		if (pointOfInterestFlag)
		{
			return selectPointOfInterest(rectifiedPixmap, qProjToWorld, projectedImageLabel->pixmap()->size(), (*selectedPixelsProj)[0]->getPos(), POISize);
		}
		else
		{
			return rectifiedPixmap;
		}
	}
Esempio n. 2
0
//--------------------------------------------------------------------------------------------------
/// Compute projection of point p3 on the line p1 - p2
//  If projection is out side the line segment, the end of line is returned
//--------------------------------------------------------------------------------------------------
cvf::Vec3d GeometryTools::projectPointOnLine(const cvf::Vec3d& p1, const cvf::Vec3d& p2, const cvf::Vec3d& p3, double* normalizedIntersection)
{
    cvf::Vec3d v31 = p3 - p1;
    cvf::Vec3d v21 = p2 - p1;

    double u = (v31*v21) / (v21*v21);
    cvf::Vec3d projectedPoint(0, 0, 0);
    if (0 < u && u < 1) projectedPoint = p1 + u*v21;
    else if (u <= 0) projectedPoint = p1;
    else projectedPoint = p2;

    if (normalizedIntersection)
    {
        *normalizedIntersection = u;
    }

    return projectedPoint;
}
Esempio n. 3
0
//===========================================================================
void cShapeBox::computeLocalInteraction(const cVector3d& a_toolPos,
                                        const cVector3d& a_toolVel,
                                        const unsigned int a_IDN)
{
    // temp variables
    bool inside;
    cVector3d projectedPoint;

    // sign
    double signX = cSign(a_toolPos(0) );
    double signY = cSign(a_toolPos(1) );
    double signZ = cSign(a_toolPos(2) );

    // check if tool is located inside box
    double tx = (signX * a_toolPos(0) );
    double ty = (signY * a_toolPos(1) );
    double tz = (signZ * a_toolPos(2) );

    inside = false;
    if (cContains(tx, 0.0, m_hSizeX))
    {
        if (cContains(ty, 0.0, m_hSizeY))
        {
            if (cContains(tz, 0.0, m_hSizeZ))
            {
                inside = true;
            }
        }
    }

    if (inside)
    {
        // tool is located inside box, compute distance from tool to surface
        double m_distanceX = m_hSizeX - (signX * a_toolPos(0) );
        double m_distanceY = m_hSizeY - (signY * a_toolPos(1) );
        double m_distanceZ = m_hSizeZ - (signZ * a_toolPos(2) );

        // search nearest surface
        if (m_distanceX < m_distanceY)
        {
            if (m_distanceX < m_distanceZ)
            {
                projectedPoint(0)  = signX * m_hSizeX;
                projectedPoint(1)  = a_toolPos(1) ;
                projectedPoint(2)  = a_toolPos(2) ;
            }
            else
            {
                projectedPoint(0)  = a_toolPos(0) ;
                projectedPoint(1)  = a_toolPos(1) ;
                projectedPoint(2)  = signZ * m_hSizeZ;
            }
        }
        else
        {
            if (m_distanceY < m_distanceZ)
            {
                projectedPoint(0)  = a_toolPos(0) ;
                projectedPoint(1)  = signY * m_hSizeY;
                projectedPoint(2)  = a_toolPos(2) ;
            }
            else
            {
                projectedPoint(0)  = a_toolPos(0) ;
                projectedPoint(1)  = a_toolPos(1) ;
                projectedPoint(2)  = signZ * m_hSizeZ;
            }
        }
    }
    else
    {
        projectedPoint(0)  = cClamp(a_toolPos(0) , -m_hSizeX, m_hSizeX);
        projectedPoint(1)  = cClamp(a_toolPos(1) , -m_hSizeY, m_hSizeY);
        projectedPoint(2)  = cClamp(a_toolPos(2) , -m_hSizeZ, m_hSizeZ);
    }

    // return results
    projectedPoint.copyto(m_interactionProjectedPoint);
    m_interactionInside = inside;
}