void ScColorTransformPool::addTransform(const ScColorTransform& transform, bool force)
{
	ScColorTransform trans;
	if (!force)
		trans = findTransform(transform.transformInfo());
	if (trans.isNull())
		m_pool.append(transform.weakRef());
}
void ScColorTransformPool::addTransform(const ScColorTransform& transform, bool force)
{
	// Check engine ID. If different, transform was created by another engine
	//  and we MUST NOT add it to the transform pool
	if (m_engineID != transform.engine().engineID())
		return;
	ScColorTransform trans;
	if (!force)
		trans = findTransform(transform.transformInfo());
	if (trans.isNull())
		m_pool.append(transform.weakRef());
}
cv::Mat	iteratedTransform(cv::Mat& before, cv::Mat& after, int l = 64) {
    // image dimensions
    int	width = before.cols;
    int	height = before.rows;
    cv::Size	size(width, height);

    // initial transform
    cv::Mat	transform(2, 3, CV_64FC1);
    transform.at<double>(0) =  cos(M_PI * (angle - 1)/ 180);
    transform.at<double>(1) =  sin(M_PI * (angle - 1)/ 180);
    transform.at<double>(3) = -sin(M_PI * (angle - 1)/ 180);;
    transform.at<double>(4) =  cos(M_PI * (angle - 1)/ 180);
    transform.at<double>(2) = 0;
    transform.at<double>(5) = 0;
    std::cout << "start transform: " << transform << std::endl;

    double	s = 0;
    do {
        // apply current transform to a copy of the before image
        cv::Mat	workimg(width, height, CV_32FC1);
        cv::warpAffine(before, workimg, transform, size);

        // determine remaining transform
        cv::Mat	newtransform = findTransform(workimg, after, l);
        std::cout << "newtransform: " << newtransform << std::endl;

        // add remaining transform to current transform
        double	u[6];
        u[0] = newtransform.at<double>(0) * transform.at<double>(0)
               + newtransform.at<double>(1) * transform.at<double>(3);
        u[1] = newtransform.at<double>(0) * transform.at<double>(1)
               + newtransform.at<double>(1) * transform.at<double>(4);
        u[3] = newtransform.at<double>(3) * transform.at<double>(0)
               + newtransform.at<double>(4) * transform.at<double>(3);
        u[4] = newtransform.at<double>(3) * transform.at<double>(1)
               + newtransform.at<double>(4) * transform.at<double>(4);

        u[2] = newtransform.at<double>(0) * transform.at<double>(2)
               + newtransform.at<double>(1) * transform.at<double>(5)
               + newtransform.at<double>(2);
        u[5] = newtransform.at<double>(3) * transform.at<double>(2)
               + newtransform.at<double>(4) * transform.at<double>(5)
               + newtransform.at<double>(5);

        for (int i = 0; i < 6; i++) {
            transform.at<double>(i) = u[i];
        }
        std::cout << "accumulated: " << transform << std::endl;

        // how close is the newtransform to the identity?
        s = 0;
        for (int i = 0; i < 6; i++) {
            double	x = newtransform.at<double>(i);
            if ((i == 0) || (i == 4)) {
                x = 1 - x;
            }
            s += x * x;
        }
        std::cout << "s = " << s << std::endl;
    } while (s > epsilon);

    return transform;
}