void ccGraphicalTransformationTool::apply()
{
	assert(m_toTransform);

	//we recompute global GL transformation matrix
	ccGLMatrix finalTrans = m_rotation;
	finalTrans += (m_rotationCenter+m_translation-m_rotation*m_rotationCenter);
	//output resulting transformation matrix
	ccConsole::Print("[GraphicalTransformationTool] Applied transformation:");
	const float* mat = finalTrans.data();
	ccConsole::Print("%6.12f\t%6.12f\t%6.12f\t%6.12f\n%6.12f\t%6.12f\t%6.12f\t%6.12f\n%6.12f\t%6.12f\t%6.12f\t%6.12f\n%6.12f\t%6.12f\t%6.12f\t%6.12f",mat[0],mat[4],mat[8],mat[12],mat[1],mat[5],mat[9],mat[13],mat[2],mat[6],mat[10],mat[14],mat[3],mat[7],mat[11],mat[15]);

	for (unsigned i=0; i<m_toTransform->getChildrenNumber();++i)
	{
		ccHObject* child = m_toTransform->getChild(i);
		child->applyGLTransformation_recursive();
		child->prepareDisplayForRefresh_recursive();
	}

	emit transformationFinished(true);

	clear();

	//MainWindow::RefreshAllGLWindow();

}
Transformation::Transformation(PNM* image, ImageViewer* iv) :
    QThread(0)
{
    parameters = new QHash<QString, QVariant>;
    this->image = image;
    this->supervisor = iv;

    if (iv)
    {
        connect(this, SIGNAL(started()), iv, SLOT(transformationStarted()));
        connect(this, SIGNAL(finished()), iv, SLOT(transformationFinished()));
        connect(this, SIGNAL(message(QString)), iv, SLOT(toolMessage(QString)));
        connect(this, SIGNAL(progress(int)), iv, SLOT(toolProgress(int)));
        connect(this, SIGNAL(resultReady(PNM*)), iv, SLOT(updateImage(PNM*)));
        connect(this, SIGNAL(finished()), iv, SLOT(toolFinished()));
    }
}
void ccGraphicalTransformationTool::cancel()
{
	assert(m_toTransform);

	for (unsigned i=0; i<m_toTransform->getChildrenNumber();++i)
	{
		ccHObject* child = m_toTransform->getChild(i);
		child->razGLTransformation();
		child->prepareDisplayForRefresh_recursive();
	}

	emit transformationFinished(false);

	clear();

	//MainWindow::RefreshAllGLWindow();
}