Revision: 46873
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46873
Author:   nazgul
Date:     2012-05-22 09:15:01 +0000 (Tue, 22 May 2012)
Log Message:
-----------
Fix for movie distoriton node in tiles

Now it works in the same way as non-tiles node in cases when image's
resolution is not equal to resolution used for calibration.

Also add some additional checks for distortion cache, so now it should
be updating properly when camera intrinsics are changing.

Potentially added support of overscan, but currently all needed computation
is commented out.

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/nodes/COM_MovieDistortionNode.cpp
    
trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
    
trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.h

Modified: 
trunk/blender/source/blender/compositor/nodes/COM_MovieDistortionNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_MovieDistortionNode.cpp   
2012-05-22 09:00:34 UTC (rev 46872)
+++ trunk/blender/source/blender/compositor/nodes/COM_MovieDistortionNode.cpp   
2012-05-22 09:15:01 UTC (rev 46873)
@@ -39,6 +39,7 @@
        
        MovieDistortionOperation * operation = new 
MovieDistortionOperation(bnode->custom1 == 1);
        operation->setMovieClip(clip);
+       operation->setFramenumber(context->getFramenumber());
 
        inputSocket->relinkConnections(operation->getInputSocket(0), true, 0, 
system);
        outputSocket->relinkConnections(operation->getOutputSocket(0));

Modified: 
trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
 2012-05-22 09:00:34 UTC (rev 46872)
+++ 
trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
 2012-05-22 09:15:01 UTC (rev 46873)
@@ -24,8 +24,8 @@
 
 extern "C" {
        #include "BKE_tracking.h"
-
-#include "BLI_linklist.h"
+       #include "BKE_movieclip.h"
+       #include "BLI_linklist.h"
 }
 
 
@@ -46,14 +46,23 @@
 {
        this->inputOperation = this->getInputSocketReader(0);
        if (this->movieClip) {
+               MovieClipUser clipUser = {0};
+               int calibration_width, calibration_height;
+
+               BKE_movieclip_user_set_frame(&clipUser, this->framenumber);
+               BKE_movieclip_get_size(this->movieClip, &clipUser, 
&calibration_width, &calibration_height);
+
                for (int i = 0 ; i < s_cache.size() ; i ++) {
                        DistortionCache *c = (DistortionCache*)s_cache[i];
-                       if (c->isCacheFor(this->movieClip, this->width, 
this->height, this->distortion)) {
+                       if (c->isCacheFor(this->movieClip, this->width, 
this->height,
+                                         calibration_width, 
calibration_height, this->distortion))
+                       {
                                this->cache = c;
                                return;
                        }
                }
-               DistortionCache *newC = new DistortionCache(this->movieClip, 
this->width, this->height, this->distortion);
+               DistortionCache *newC = new DistortionCache(this->movieClip, 
this->width, this->height,
+                                                           calibration_width, 
calibration_height, this->distortion);
                s_cache.push_back(newC);
                this->cache = newC;
        }

Modified: 
trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.h
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.h
   2012-05-22 09:00:34 UTC (rev 46872)
+++ 
trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.h
   2012-05-22 09:15:01 UTC (rev 46873)
@@ -34,18 +34,28 @@
        float k1;
        float k2;
        float k3;
+       float principal_x;
+       float principal_y;
+       float pixel_aspect;
        int width;
        int height;
+       int calibration_width;
+       int calibration_height;
        bool inverted;
        float *buffer;
        int *bufferCalculated;
 public:
-       DistortionCache(MovieClip *movieclip, int width, int height, bool 
inverted) {
+       DistortionCache(MovieClip *movieclip, int width, int height, int 
calibration_width, int calibration_height, bool inverted) {
                this->k1 = movieclip->tracking.camera.k1;
                this->k2 = movieclip->tracking.camera.k2;
                this->k3 = movieclip->tracking.camera.k3;
+               this->principal_x = movieclip->tracking.camera.principal[0];
+               this->principal_y = movieclip->tracking.camera.principal[1];
+               this->pixel_aspect = movieclip->tracking.camera.pixel_aspect;
                this->width = width;
                this->height = height;
+               this->calibration_width = calibration_width;
+               this->calibration_height = calibration_height;
                this->inverted = inverted;
                this->bufferCalculated = new int[this->width*this->height];
                this->buffer = new float[this->width*this->height*2];
@@ -53,13 +63,18 @@
                        this->bufferCalculated[i] = 0;
                }
        }
-       bool isCacheFor(MovieClip *movieclip, int width, int height, bool 
inverted) {
+       bool isCacheFor(MovieClip *movieclip, int width, int height, int 
calibration_width, int claibration_height, bool inverted) {
                return this->k1 == movieclip->tracking.camera.k1 &&
                        this->k2 == movieclip->tracking.camera.k2 &&
                        this->k3 == movieclip->tracking.camera.k3 &&
+                       this->principal_x == 
movieclip->tracking.camera.principal[0] &&
+                       this->principal_y == 
movieclip->tracking.camera.principal[1] &&
+                       this->pixel_aspect == 
movieclip->tracking.camera.pixel_aspect &&
                        this->inverted == inverted &&
-                       this->width == width && 
-                       this->height == height;
+                       this->width == width &&
+                       this->height == height &&
+                       this->calibration_width == calibration_width &&
+                       this->calibration_height == calibration_height;
        }
        
        void getUV(MovieTracking *trackingData, int x, int y, float *u, 
float*v) {
@@ -67,20 +82,30 @@
                        *u = x;
                        *v = y;
                } else {
+
                        int offset = y * this->width + x;
                        int offset2 = offset*2;
                        if (!bufferCalculated[offset]) {
+                               //float overscan = 0.0f;
+                               float w = (float)this->width/* / (1 + overscan) 
*/;
+                               float h = (float)this->height/* / (1 + 
overscan) */;
+                               float aspx = (float)w / this->calibration_width;
+                               float aspy = (float)h / 
this->calibration_height;
                                float in[2];
                                float out[2];
-                               in[0] = x;
-                               in[1] = y;
+
+                               in[0] = (x /* - 0.5 * overscan * w */) / aspx;
+                               in[1] = (y /* - 0.5 * overscan * h */) / aspy / 
this->pixel_aspect;
+
                                if (inverted) {
                                        
BKE_tracking_invert_intrinsics(trackingData, in, out);
                                } else {
                                        
BKE_tracking_apply_intrinsics(trackingData, in, out);
                                }
-                               buffer[offset2] = out[0];
-                               buffer[offset2+1] = out[1];
+
+                               buffer[offset2] = out[0] * aspx /* + 0.5 * 
overscan * w */;
+                               buffer[offset2+1] = (out[1] * aspy /* + 0.5 * 
overscan * h */) * this->pixel_aspect;
+
                                bufferCalculated[offset] = 1;
                        }
                        *u = buffer[offset2];
@@ -97,6 +122,7 @@
 
 protected:
        bool distortion;
+       int framenumber;
 
 public:
        MovieDistortionOperation(bool distortion);
@@ -107,7 +133,7 @@
        void deinitExecution();
        
        void setMovieClip(MovieClip *clip) {this->movieClip = clip;}
-
+       void setFramenumber(int framenumber) {this->framenumber = framenumber;}
 };
 
 #endif

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to