[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45547] branches/tile/source/blender/ compositor: TileBranch
Jeroen Bakker
j.bakker at atmind.nl
Wed Apr 11 21:36:35 CEST 2012
Revision: 45547
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45547
Author: jbakker
Date: 2012-04-11 19:36:33 +0000 (Wed, 11 Apr 2012)
Log Message:
-----------
TileBranch
* added caching operations to Distortion node.
With thanks to Sergey!
- At Mind -
Modified Paths:
--------------
branches/tile/source/blender/compositor/CMakeLists.txt
branches/tile/source/blender/compositor/nodes/COM_MovieDistortionNode.cpp
branches/tile/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
branches/tile/source/blender/compositor/operations/COM_MovieDistortionOperation.h
Removed Paths:
-------------
branches/tile/source/blender/compositor/operations/COM_MovieUndistortionOperation.cpp
branches/tile/source/blender/compositor/operations/COM_MovieUndistortionOperation.h
Modified: branches/tile/source/blender/compositor/CMakeLists.txt
===================================================================
--- branches/tile/source/blender/compositor/CMakeLists.txt 2012-04-11 18:37:46 UTC (rev 45546)
+++ branches/tile/source/blender/compositor/CMakeLists.txt 2012-04-11 19:36:33 UTC (rev 45547)
@@ -306,8 +306,6 @@
operations/COM_MovieClipAttributeOperation.h
operations/COM_MovieDistortionOperation.cpp
operations/COM_MovieDistortionOperation.h
- operations/COM_MovieUndistortionOperation.cpp
- operations/COM_MovieUndistortionOperation.h
# Matte nodes
nodes/COM_BoxMaskNode.cpp
Modified: branches/tile/source/blender/compositor/nodes/COM_MovieDistortionNode.cpp
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_MovieDistortionNode.cpp 2012-04-11 18:37:46 UTC (rev 45546)
+++ branches/tile/source/blender/compositor/nodes/COM_MovieDistortionNode.cpp 2012-04-11 19:36:33 UTC (rev 45547)
@@ -23,7 +23,6 @@
#include "COM_MovieDistortionNode.h"
#include "COM_MovieDistortionOperation.h"
-#include "COM_MovieUndistortionOperation.h"
#include "COM_ExecutionSystem.h"
#include "DNA_movieclip_types.h"
@@ -36,13 +35,7 @@
bNode* bnode = this->getbNode();
MovieClip * clip = (MovieClip*)bnode->id;
- MovieDistortionOperation * operation;
- if (bnode->custom1 == 0) {
- operation = new MovieUndistortionOperation();
-
- } else {
- operation = new MovieDistortionOperation();
- }
+ MovieDistortionOperation * operation = new MovieDistortionOperation(bnode->custom1 == 1);
operation->setMovieClip(clip);
inputSocket->relinkConnections(operation->getInputSocket(0), true, 0, system);
Modified: branches/tile/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp 2012-04-11 18:37:46 UTC (rev 45546)
+++ branches/tile/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp 2012-04-11 19:36:33 UTC (rev 45547)
@@ -24,17 +24,39 @@
extern "C" {
#include "BKE_tracking.h"
+
+#include "BLI_linklist.h"
}
-MovieDistortionOperation::MovieDistortionOperation() : NodeOperation() {
+
+vector<DistortionCache*> s_cache;
+
+
+MovieDistortionOperation::MovieDistortionOperation(bool distortion) : NodeOperation() {
this->addInputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_COLOR);
this->setResolutionInputSocketIndex(0);
this->inputOperation = NULL;
this->movieClip = NULL;
+ this->cache = NULL;
+ this->distortion = distortion;
}
void MovieDistortionOperation::initExecution() {
this->inputOperation = this->getInputSocketReader(0);
+ if (this->movieClip) {
+ 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)) {
+ this->cache = c;
+ return;
+ }
+ }
+ DistortionCache* newC = new DistortionCache(this->movieClip, this->width, this->height, this->distortion);
+ s_cache.push_back(newC);
+ this->cache = newC;
+ } else {
+ this->cache = NULL;
+ }
}
void MovieDistortionOperation::deinitExecution() {
@@ -45,19 +67,13 @@
void MovieDistortionOperation::executePixel(float *color,float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) {
- if (this->movieClip != NULL) {
- float in[2];
- float out[2];
-
- in[0] = x;
- in[1] = y;
-
- BKE_tracking_invert_intrinsics(&this->movieClip->tracking, in, out);
- this->inputOperation->read(color, out[0], out[1], sampler, inputBuffers);
+ if (this->cache != NULL) {
+ float u, v;
+ this->cache->getUV(&this->movieClip->tracking, x, y, &u, &v);
+ this->inputOperation->read(color, u, v, sampler, inputBuffers);
}
else {
this->inputOperation->read(color, x, y, sampler, inputBuffers);
-
}
}
Modified: branches/tile/source/blender/compositor/operations/COM_MovieDistortionOperation.h
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_MovieDistortionOperation.h 2012-04-11 18:37:46 UTC (rev 45546)
+++ branches/tile/source/blender/compositor/operations/COM_MovieDistortionOperation.h 2012-04-11 19:36:33 UTC (rev 45547)
@@ -25,13 +25,76 @@
#include "COM_NodeOperation.h"
#include "DNA_movieclip_types.h"
+extern "C" {
+ #include "BKE_tracking.h"
+}
+class DistortionCache {
+private:
+ float k1;
+ float k2;
+ float k3;
+ int width;
+ int height;
+ bool inverted;
+ float *buffer;
+ int *bufferCalculated;
+public:
+ DistortionCache(MovieClip* movieclip, int width, int height, bool inverted) {
+ this->k1 = movieclip->tracking.camera.k1;
+ this->k2 = movieclip->tracking.camera.k2;
+ this->k3 = movieclip->tracking.camera.k3;
+ this->width = width;
+ this->height = height;
+ this->inverted = inverted;
+ this->bufferCalculated = new int[this->width*this->height];
+ this->buffer = new float[this->width*this->height*2];
+ for (int i = 0 ; i < this->width*this->height ; i ++) {
+ this->bufferCalculated[i] = 0;
+ }
+ }
+ bool isCacheFor(MovieClip* movieclip, int width, int height, bool inverted) {
+ return this->k1 == movieclip->tracking.camera.k1 &&
+ this->k2 == movieclip->tracking.camera.k2 &&
+ this->k3 == movieclip->tracking.camera.k3 &&
+ this->inverted == inverted &&
+ this->width == width &&
+ this->height == height;
+ }
+
+ void getUV(MovieTracking* trackingData, int x, int y, float *u, float*v) {
+ int offset = y * this->width + x;
+ int offset2 = offset*2;
+ if (!bufferCalculated[offset]) {
+ float in[2];
+ float out[2];
+ in[0] = x;
+ in[1] = y;
+ 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];
+ bufferCalculated[offset] = 1;
+ }
+ *u = buffer[offset2];
+ *v = buffer[offset2+1];
+ }
+};
+
class MovieDistortionOperation: public NodeOperation {
-protected:
+private:
+ DistortionCache *cache;
SocketReader *inputOperation;
MovieClip * movieClip;
+
+protected:
+ bool distortion;
+
public:
- MovieDistortionOperation();
+ MovieDistortionOperation(bool distortion);
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]);
Deleted: branches/tile/source/blender/compositor/operations/COM_MovieUndistortionOperation.cpp
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_MovieUndistortionOperation.cpp 2012-04-11 18:37:46 UTC (rev 45546)
+++ branches/tile/source/blender/compositor/operations/COM_MovieUndistortionOperation.cpp 2012-04-11 19:36:33 UTC (rev 45547)
@@ -1,45 +0,0 @@
-/*
- * Copyright 2011, Blender Foundation.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor:
- * Jeroen Bakker
- * Monique Dewanchand
- */
-
-#include "COM_MovieUndistortionOperation.h"
-extern "C" {
-#include "BKE_tracking.h"
-}
-MovieUndistortionOperation::MovieUndistortionOperation() : MovieDistortionOperation() {
-}
-void MovieUndistortionOperation::executePixel(float *color,float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) {
- if (this->movieClip != NULL) {
- float in[2];
- float out[2];
-
- in[0] = x;
- in[1] = y;
-
- BKE_tracking_apply_intrinsics(&this->movieClip->tracking, in, out);
- this->inputOperation->read(color, out[0], out[1], sampler, inputBuffers);
- }
- else {
- this->inputOperation->read(color, x, y, sampler, inputBuffers);
-
- }
-}
-
Deleted: branches/tile/source/blender/compositor/operations/COM_MovieUndistortionOperation.h
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_MovieUndistortionOperation.h 2012-04-11 18:37:46 UTC (rev 45546)
+++ branches/tile/source/blender/compositor/operations/COM_MovieUndistortionOperation.h 2012-04-11 19:36:33 UTC (rev 45547)
@@ -1,34 +0,0 @@
-/*
- * Copyright 2011, Blender Foundation.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor:
- * Jeroen Bakker
- * Monique Dewanchand
- */
-
-#ifndef _COM_MovieUndistortionOperation_h_
-#define _COM_MovieUndistortionOperation_h_
-
-#include "COM_MovieDistortionOperation.h"
-
-class MovieUndistortionOperation: public MovieDistortionOperation {
-public:
- MovieUndistortionOperation();
- void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]);
-};
-
-#endif
More information about the Bf-blender-cvs
mailing list