Exemple #1
0
KImage * ColorTransfer::applyRecoloring() {
    FILE *fp = fopen("total_time.txt", "w");
    clock_t end, start;
    double time = 0.0f;
    start = clock();
    generateRotationMatrix();
    assert(_pdfTransfer); //the one that was allocated in constructor(see above!)
    if (_pdfTransfer->NDPdfTransfer(_inputImage, _palette, _rotations) != true) {
        printf("Error in applying NDPdfTransfer for image. Exiting...\n");
        exit(1);
    }
    if (this->saveImage() == false) {
        printf("Error in  saving image for color transfer. Exiting...\n");
        exit(1);
    }
    end = clock();
    time = (double) (end - start) / CLOCKS_PER_SEC;
    fprintf(fp, "It took %.2f sec to perform color transfer for: \n"
            "input image ->>> height=%d, width=%d\n"
            "palette image ->>> height=%d, width=%d\n"
            "with %d iterations.\n",
            time, _input->GetHeight(), _input->GetWidth(),
            _paletteImage->GetHeight(), _paletteImage->GetWidth(), _iterations);
    fclose(fp);
    return this->_gradedImage;
}
Exemple #2
0
void glutMotion(int x, int y)
{
    if (gIsRotatingCamera)
    {
        static const double kTrackBallRadius = 0.8;   

        Vec3d lastPos;
        lastPos[0] = gLastMouseX * 2.0 / gWindowWidth - 1.0;
        lastPos[1] = (gWindowHeight - gLastMouseY) * 2.0 / gWindowHeight - 1.0;
        lastPos[2] = projectToTrackball(kTrackBallRadius, lastPos[0], lastPos[1]);

        Vec3d currPos;
        currPos[0] = x * 2.0 / gWindowWidth - 1.0;
        currPos[1] = (gWindowHeight - y) * 2.0 / gWindowHeight - 1.0;
        currPos[2] = projectToTrackball(kTrackBallRadius, currPos[0], currPos[1]);

        currPos.normalize();
        lastPos.normalize();

        Vec3d rotateVec = lastPos.cross(currPos);
				        
        double rotateAngle = asin(rotateVec.norm());
        if (fabs(rotateAngle) > 1e-6)
        {
			double deltaRotation[16];
            
			generateRotationMatrix(deltaRotation, rotateAngle, rotateVec[0], rotateVec[1], rotateVec[2]);
                
            multRight(gCameraRotation, deltaRotation);
        
            updateCamera();
        }
    }
    else if (gIsScalingCamera)
    {
        float y1 = gWindowHeight - gLastMouseY;
        float y2 = gWindowHeight - y;

        gCameraScale *= 1 + (y1 - y2) / gWindowHeight;  

        updateCamera();
    }

    gLastMouseX = x;
    gLastMouseY = y;
}