Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Tönne <lukas.toenne@gmail.com>2014-03-11 17:07:49 +0400
committerLukas Tönne <lukas.toenne@gmail.com>2014-03-11 17:12:08 +0400
commit658b4c0d56dffbcf1476c2a2a019fa0ecfb79376 (patch)
tree28fb8dd6b9a3bedf6d95e9e7737e3753b7308e90 /source/blender/compositor/operations
parent558fa43ffd5bb1c4950855bd07450841664e89aa (diff)
New Corner Pin node: uses explicit corner values for a plane warp transformation.
This was suggested by Christopher Barrett (terrachild). Corner pin is a common feature in compositing. The corners for the plane warping can be defined by using vector node inputs to allow using perspective plane transformations without having to go via the MovieClip editor tracking data. Uses the same math as the PlaneTrack node, but without the link to MovieClip and Object. {F78199} The code for PlaneTrack operations has been restructured a bit to share it with the CornerPin node. * PlaneDistortCommonOperation.h/.cpp: Shared generic code for warping images based on 4 plane corners and a perspective matrix generated from these. Contains operation base classes for both the WarpImage and Mask operations. * PlaneTrackOperation.h/.cpp: Current plane track node operations, based on the common code above. These add pointers to MovieClip and Object which define the track data from wich to read the corners. * PlaneCornerPinOperation.h/.cpp: New corner pin variant, using explicit input sockets for the plane corners. One downside of the current compositor design is that there is no concept of invariables (constants) that don't vary over the image space. This has already been an issue for Blur nodes (size input is usually constant except when "variable size" is enabled) and a few others. For the corner pin node it is necessary that the corner input sockets are also invariant. They have to be evaluated for each tile now, otherwise the data is not available. This in turn makes it necessary to make the operation "complex" and request full input buffers, which adds unnecessary overhead.
Diffstat (limited to 'source/blender/compositor/operations')
-rw-r--r--source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp223
-rw-r--r--source/blender/compositor/operations/COM_PlaneCornerPinOperation.h (renamed from source/blender/compositor/operations/COM_PlaneTrackMaskOperation.h)43
-rw-r--r--source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp (renamed from source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.cpp)105
-rw-r--r--source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h (renamed from source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.h)32
-rw-r--r--source/blender/compositor/operations/COM_PlaneTrackMaskOperation.cpp70
-rw-r--r--source/blender/compositor/operations/COM_PlaneTrackOperation.cpp (renamed from source/blender/compositor/operations/COM_PlaneTrackCommonOperation.cpp)68
-rw-r--r--source/blender/compositor/operations/COM_PlaneTrackOperation.h (renamed from source/blender/compositor/operations/COM_PlaneTrackCommonOperation.h)48
7 files changed, 452 insertions, 137 deletions
diff --git a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp
new file mode 100644
index 00000000000..fe272000b6e
--- /dev/null
+++ b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2014, 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:
+ * Lukas Toenne
+ */
+
+#include "COM_PlaneCornerPinOperation.h"
+#include "COM_ReadBufferOperation.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_math_color.h"
+
+extern "C" {
+# include "BLI_jitter.h"
+
+# include "BKE_node.h"
+}
+
+static bool check_corners(float corners[4][2])
+{
+ int i, next, prev;
+ float cross = 0.0f;
+
+ for (i = 0; i < 4; i++) {
+ float v1[2], v2[2], cur_cross;
+
+ next = (i + 1) % 4;
+ prev = (4 + i - 1) % 4;
+
+ sub_v2_v2v2(v1, corners[i], corners[prev]);
+ sub_v2_v2v2(v2, corners[next], corners[i]);
+
+ cur_cross = cross_v2v2(v1, v2);
+ if (fabsf(cur_cross) <= FLT_EPSILON)
+ return false;
+
+ if (cross == 0.0f)
+ cross = cur_cross;
+ else if (cross * cur_cross < 0.0f)
+ return false;
+ }
+
+ return true;
+}
+
+static void readCornersFromSockets(rcti *rect, SocketReader *readers[4], float corners[4][2])
+{
+ for (int i = 0; i < 4; ++i) {
+ float result[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ readers[i]->readSampled(result, rect->xmin, rect->ymin, COM_PS_NEAREST);
+ corners[i][0] = result[0];
+ corners[i][1] = result[1];
+ }
+
+ /* convexity check:
+ * concave corners need to be prevented, otherwise
+ * BKE_tracking_homography_between_two_quads will freeze
+ */
+ if (!check_corners(corners)) {
+ /* simply revert to default corners
+ * there could be a more elegant solution,
+ * this prevents freezing at least.
+ */
+ corners[0][0] = 0.0f; corners[0][1] = 0.0f;
+ corners[1][0] = 1.0f; corners[1][1] = 0.0f;
+ corners[2][0] = 1.0f; corners[2][1] = 1.0f;
+ corners[3][0] = 0.0f; corners[3][1] = 1.0f;
+ }
+}
+
+
+/* ******** PlaneCornerPinMaskOperation ******** */
+
+PlaneCornerPinMaskOperation::PlaneCornerPinMaskOperation() :
+ PlaneDistortMaskOperation(),
+ m_corners_ready(false)
+{
+ addInputSocket(COM_DT_VECTOR);
+ addInputSocket(COM_DT_VECTOR);
+ addInputSocket(COM_DT_VECTOR);
+ addInputSocket(COM_DT_VECTOR);
+
+ /* XXX this is stupid: we need to make this "complex",
+ * so we can use the initializeTileData function
+ * to read corners from input sockets ...
+ */
+ setComplex(true);
+}
+
+void PlaneCornerPinMaskOperation::initExecution()
+{
+ PlaneDistortMaskOperation::initExecution();
+
+ initMutex();
+}
+
+void PlaneCornerPinMaskOperation::deinitExecution()
+{
+ PlaneDistortMaskOperation::deinitExecution();
+
+ deinitMutex();
+}
+
+void *PlaneCornerPinMaskOperation::initializeTileData(rcti *rect)
+{
+ void *data = PlaneDistortMaskOperation::initializeTileData(rect);
+
+ /* get corner values once, by reading inputs at (0,0)
+ * XXX this assumes invariable values (no image inputs),
+ * we don't have a nice generic system for that yet
+ */
+ lockMutex();
+ if (!m_corners_ready) {
+ SocketReader *readers[4] = { getInputSocketReader(0),
+ getInputSocketReader(1),
+ getInputSocketReader(2),
+ getInputSocketReader(3) };
+ float corners[4][2];
+ readCornersFromSockets(rect, readers, corners);
+ calculateCorners(corners, true);
+
+ m_corners_ready = true;
+ }
+ unlockMutex();
+
+ return data;
+}
+
+void PlaneCornerPinMaskOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
+{
+ resolution[0] = preferredResolution[0];
+ resolution[1] = preferredResolution[1];
+}
+
+
+/* ******** PlaneCornerPinWarpImageOperation ******** */
+
+PlaneCornerPinWarpImageOperation::PlaneCornerPinWarpImageOperation() :
+ PlaneDistortWarpImageOperation(),
+ m_corners_ready(false)
+{
+ addInputSocket(COM_DT_VECTOR);
+ addInputSocket(COM_DT_VECTOR);
+ addInputSocket(COM_DT_VECTOR);
+ addInputSocket(COM_DT_VECTOR);
+}
+
+void PlaneCornerPinWarpImageOperation::initExecution()
+{
+ PlaneDistortWarpImageOperation::initExecution();
+
+ initMutex();
+}
+
+void PlaneCornerPinWarpImageOperation::deinitExecution()
+{
+ PlaneDistortWarpImageOperation::deinitExecution();
+
+ deinitMutex();
+}
+
+void *PlaneCornerPinWarpImageOperation::initializeTileData(rcti *rect)
+{
+ void *data = PlaneDistortWarpImageOperation::initializeTileData(rect);
+
+ /* get corner values once, by reading inputs at (0,0)
+ * XXX this assumes invariable values (no image inputs),
+ * we don't have a nice generic system for that yet
+ */
+ lockMutex();
+ if (!m_corners_ready) {
+ /* corner sockets start at index 1 */
+ SocketReader *readers[4] = { getInputSocketReader(1),
+ getInputSocketReader(2),
+ getInputSocketReader(3),
+ getInputSocketReader(4) };
+ float corners[4][2];
+ readCornersFromSockets(rect, readers, corners);
+ calculateCorners(corners, true);
+ calculatePerspectiveMatrix();
+
+ m_corners_ready = true;
+ }
+ unlockMutex();
+
+ return data;
+}
+
+bool PlaneCornerPinWarpImageOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
+{
+ for (int i = 0; i < 4; ++i)
+ if (getInputOperation(i + 1)->determineDependingAreaOfInterest(input, readOperation, output))
+ return true;
+
+ /* XXX this is bad, but unavoidable with the current design:
+ * we don't know the actual corners and matrix at this point,
+ * so all we can do is get the full input image
+ */
+ output->xmin = 0;
+ output->ymin = 0;
+ output->xmax = getInputOperation(0)->getWidth();
+ output->ymax = getInputOperation(0)->getHeight();
+ return true;
+// return PlaneDistortWarpImageOperation::determineDependingAreaOfInterest(input, readOperation, output);
+}
diff --git a/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.h b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.h
index 7f763954079..ed70d9c80a3 100644
--- a/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.h
+++ b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.h
@@ -1,6 +1,6 @@
/*
- * Copyright 2013, Blender Foundation.
+ * Copyright 2014, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -17,15 +17,15 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
- * Sergey Sharybin
+ * Lukas Toenne
*/
-#ifndef _COM_PlaneTrackMaskOperation_h
-#define _COM_PlaneTrackMaskOperation_h
+#ifndef _COM_CornerPinWarpImageOperation_h
+#define _COM_CornerPinWarpImageOperation_h
#include <string.h>
-#include "COM_PlaneTrackCommonOperation.h"
+#include "COM_PlaneDistortCommonOperation.h"
#include "DNA_movieclip_types.h"
#include "DNA_tracking_types.h"
@@ -33,17 +33,36 @@
#include "BLI_listbase.h"
#include "BLI_string.h"
-class PlaneTrackMaskOperation : public PlaneTrackCommonOperation {
-protected:
- int m_osa;
- float m_jitter[32][2];
+class PlaneCornerPinMaskOperation : public PlaneDistortMaskOperation {
+private:
+ bool m_corners_ready;
+
public:
- PlaneTrackMaskOperation();
-
+ PlaneCornerPinMaskOperation();
+
void initExecution();
+ void deinitExecution();
+
+ void *initializeTileData(rcti *rect);
+
+ void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
+};
+
- void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
+class PlaneCornerPinWarpImageOperation : public PlaneDistortWarpImageOperation {
+private:
+ bool m_corners_ready;
+
+public:
+ PlaneCornerPinWarpImageOperation();
+
+ void initExecution();
+ void deinitExecution();
+
+ void *initializeTileData(rcti *rect);
+
+ bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
};
#endif
diff --git a/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.cpp b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
index 6579276fa9f..362d7f6d2d7 100644
--- a/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.cpp
+++ b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
@@ -17,25 +17,26 @@
*
* Contributor:
* Sergey Sharybin
+ * Lukas Toenne
*/
-#include "COM_PlaneTrackWarpImageOperation.h"
-#include "COM_ReadBufferOperation.h"
+#include "COM_PlaneDistortCommonOperation.h"
#include "MEM_guardedalloc.h"
+extern "C" {
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_math_color.h"
+#include "BLI_jitter.h"
-extern "C" {
-# include "BLI_jitter.h"
-
-# include "BKE_movieclip.h"
-# include "BKE_node.h"
-# include "BKE_tracking.h"
+#include "BKE_movieclip.h"
+#include "BKE_node.h"
+#include "BKE_tracking.h"
}
+/* ******** PlaneDistort WarpImage ******** */
+
BLI_INLINE void warpCoord(float x, float y, float matrix[3][3], float uv[2], float deriv[2][2])
{
float vec[3] = {x, y, 1.0f};
@@ -49,7 +50,8 @@ BLI_INLINE void warpCoord(float x, float y, float matrix[3][3], float uv[2], flo
deriv[1][1] = (matrix[1][1] - matrix[1][2] * uv[1]) / vec[2];
}
-PlaneTrackWarpImageOperation::PlaneTrackWarpImageOperation() : PlaneTrackCommonOperation()
+PlaneDistortWarpImageOperation::PlaneDistortWarpImageOperation() :
+ NodeOperation()
{
this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE);
this->addOutputSocket(COM_DT_COLOR);
@@ -57,12 +59,24 @@ PlaneTrackWarpImageOperation::PlaneTrackWarpImageOperation() : PlaneTrackCommonO
this->setComplex(true);
}
-void PlaneTrackWarpImageOperation::initExecution()
+void PlaneDistortWarpImageOperation::calculateCorners(const float corners[4][2], bool normalized)
{
- PlaneTrackCommonOperation::initExecution();
-
- this->m_pixelReader = this->getInputSocketReader(0);
+ if (normalized) {
+ for (int i = 0; i < 4; i++) {
+ this->m_frameSpaceCorners[i][0] = corners[i][0] * this->getWidth();
+ this->m_frameSpaceCorners[i][1] = corners[i][1] * this->getHeight();
+ }
+ }
+ else {
+ for (int i = 0; i < 4; i++) {
+ this->m_frameSpaceCorners[i][0] = corners[i][0];
+ this->m_frameSpaceCorners[i][1] = corners[i][1];
+ }
+ }
+}
+void PlaneDistortWarpImageOperation::calculatePerspectiveMatrix()
+{
const int width = this->m_pixelReader->getWidth();
const int height = this->m_pixelReader->getHeight();
float frame_corners[4][2] = {{0.0f, 0.0f},
@@ -74,12 +88,17 @@ void PlaneTrackWarpImageOperation::initExecution()
this->m_perspectiveMatrix);
}
-void PlaneTrackWarpImageOperation::deinitExecution()
+void PlaneDistortWarpImageOperation::initExecution()
+{
+ this->m_pixelReader = this->getInputSocketReader(0);
+}
+
+void PlaneDistortWarpImageOperation::deinitExecution()
{
this->m_pixelReader = NULL;
}
-void PlaneTrackWarpImageOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
+void PlaneDistortWarpImageOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
float xy[2] = {x, y};
float uv[2];
@@ -90,12 +109,12 @@ void PlaneTrackWarpImageOperation::executePixelSampled(float output[4], float x,
m_pixelReader->readFiltered(output, uv[0], uv[1], deriv[0], deriv[1], COM_PS_BILINEAR);
}
-void PlaneTrackWarpImageOperation::pixelTransform(const float xy[2], float r_uv[2], float r_deriv[2][2])
+void PlaneDistortWarpImageOperation::pixelTransform(const float xy[2], float r_uv[2], float r_deriv[2][2])
{
warpCoord(xy[0], xy[1], m_perspectiveMatrix, r_uv, r_deriv);
}
-bool PlaneTrackWarpImageOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
+bool PlaneDistortWarpImageOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
{
float UVs[4][2];
float deriv[2][2];
@@ -121,3 +140,55 @@ bool PlaneTrackWarpImageOperation::determineDependingAreaOfInterest(rcti *input,
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+
+
+/* ******** PlaneDistort Mask ******** */
+
+PlaneDistortMaskOperation::PlaneDistortMaskOperation() :
+ NodeOperation()
+{
+ addOutputSocket(COM_DT_VALUE);
+
+ /* Currently hardcoded to 8 samples. */
+ m_osa = 8;
+}
+
+void PlaneDistortMaskOperation::calculateCorners(const float corners[4][2], bool normalized)
+{
+ if (normalized) {
+ for (int i = 0; i < 4; i++) {
+ this->m_frameSpaceCorners[i][0] = corners[i][0] * this->getWidth();
+ this->m_frameSpaceCorners[i][1] = corners[i][1] * this->getHeight();
+ }
+ }
+ else {
+ for (int i = 0; i < 4; i++) {
+ this->m_frameSpaceCorners[i][0] = corners[i][0];
+ this->m_frameSpaceCorners[i][1] = corners[i][1];
+ }
+ }
+}
+
+void PlaneDistortMaskOperation::initExecution()
+{
+ BLI_jitter_init(m_jitter[0], m_osa);
+}
+
+void PlaneDistortMaskOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
+{
+ float point[2];
+
+ int inside_counter = 0;
+ for (int sample = 0; sample < this->m_osa; sample++) {
+ point[0] = x + this->m_jitter[sample][0];
+ point[1] = y + this->m_jitter[sample][1];
+
+ if (isect_point_tri_v2(point, this->m_frameSpaceCorners[0], this->m_frameSpaceCorners[1], this->m_frameSpaceCorners[2]) ||
+ isect_point_tri_v2(point, this->m_frameSpaceCorners[0], this->m_frameSpaceCorners[2], this->m_frameSpaceCorners[3]))
+ {
+ inside_counter++;
+ }
+ }
+
+ output[0] = (float) inside_counter / this->m_osa;
+}
diff --git a/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.h b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h
index ceb002c8039..ee2874c6b46 100644
--- a/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.h
+++ b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h
@@ -20,12 +20,12 @@
* Sergey Sharybin
*/
-#ifndef _COM_PlaneTrackWarpImageOperation_h
-#define _COM_PlaneTrackWarpImageOperation_h
+#ifndef _COM_PlaneTrackCommonOperation_h
+#define _COM_PlaneTrackCommonOperation_h
#include <string.h>
-#include "COM_PlaneTrackCommonOperation.h"
+#include "COM_NodeOperation.h"
#include "DNA_movieclip_types.h"
#include "DNA_tracking_types.h"
@@ -33,13 +33,18 @@
#include "BLI_listbase.h"
#include "BLI_string.h"
-class PlaneTrackWarpImageOperation : public PlaneTrackCommonOperation {
+
+class PlaneDistortWarpImageOperation : public NodeOperation {
protected:
SocketReader *m_pixelReader;
+ float m_frameSpaceCorners[4][2]; /* Corners coordinates in pixel space. */
float m_perspectiveMatrix[3][3];
public:
- PlaneTrackWarpImageOperation();
+ PlaneDistortWarpImageOperation();
+
+ void calculateCorners(const float corners[4][2], bool normalized);
+ void calculatePerspectiveMatrix();
void initExecution();
void deinitExecution();
@@ -50,4 +55,21 @@ public:
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
};
+
+class PlaneDistortMaskOperation : public NodeOperation {
+protected:
+ int m_osa;
+ float m_jitter[32][2];
+ float m_frameSpaceCorners[4][2]; /* Corners coordinates in pixel space. */
+
+public:
+ PlaneDistortMaskOperation();
+
+ void calculateCorners(const float corners[4][2], bool normalized);
+
+ void initExecution();
+
+ void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
+};
+
#endif
diff --git a/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.cpp b/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.cpp
deleted file mode 100644
index e43f6ab05b3..00000000000
--- a/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2013, 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:
- * Sergey Sharybin
- */
-
-#include "COM_PlaneTrackMaskOperation.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_listbase.h"
-#include "BLI_math.h"
-#include "BLI_math_color.h"
-
-extern "C" {
-# include "BLI_jitter.h"
-
-# include "BKE_movieclip.h"
-# include "BKE_node.h"
-# include "BKE_tracking.h"
-}
-
-PlaneTrackMaskOperation::PlaneTrackMaskOperation() : PlaneTrackCommonOperation()
-{
- this->addOutputSocket(COM_DT_VALUE);
-
- /* Currently hardcoded to 8 samples. */
- this->m_osa = 8;
-}
-
-void PlaneTrackMaskOperation::initExecution()
-{
- PlaneTrackCommonOperation::initExecution();
-
- BLI_jitter_init(this->m_jitter[0], this->m_osa);
-}
-
-void PlaneTrackMaskOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
-{
- float point[2];
-
- int inside_counter = 0;
- for (int sample = 0; sample < this->m_osa; sample++) {
- point[0] = x + this->m_jitter[sample][0];
- point[1] = y + this->m_jitter[sample][1];
-
- if (isect_point_tri_v2(point, this->m_frameSpaceCorners[0], this->m_frameSpaceCorners[1], this->m_frameSpaceCorners[2]) ||
- isect_point_tri_v2(point, this->m_frameSpaceCorners[0], this->m_frameSpaceCorners[2], this->m_frameSpaceCorners[3]))
- {
- inside_counter++;
- }
- }
-
- output[0] = (float) inside_counter / this->m_osa;
-}
diff --git a/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.cpp b/source/blender/compositor/operations/COM_PlaneTrackOperation.cpp
index 5deb7b99bce..fec39cbfde0 100644
--- a/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.cpp
+++ b/source/blender/compositor/operations/COM_PlaneTrackOperation.cpp
@@ -19,7 +19,8 @@
* Sergey Sharybin
*/
-#include "COM_PlaneTrackMaskOperation.h"
+#include "COM_PlaneTrackOperation.h"
+#include "COM_ReadBufferOperation.h"
#include "MEM_guardedalloc.h"
@@ -28,12 +29,16 @@
#include "BLI_math_color.h"
extern "C" {
+# include "BLI_jitter.h"
+
# include "BKE_movieclip.h"
# include "BKE_node.h"
# include "BKE_tracking.h"
}
-PlaneTrackCommonOperation::PlaneTrackCommonOperation() : NodeOperation()
+/* ******** PlaneTrackCommon ******** */
+
+PlaneTrackCommon::PlaneTrackCommon()
{
this->m_movieClip = NULL;
this->m_framenumber = 0;
@@ -41,55 +46,72 @@ PlaneTrackCommonOperation::PlaneTrackCommonOperation() : NodeOperation()
this->m_planeTrackName[0] = '\0';
}
-void PlaneTrackCommonOperation::initExecution()
+void PlaneTrackCommon::readCornersFromTrack(float corners[4][2])
{
MovieTracking *tracking;
MovieTrackingObject *object;
- memset(this->m_corners, 0, sizeof(this->m_corners));
- memset(this->m_frameSpaceCorners, 0, sizeof(this->m_frameSpaceCorners));
-
if (!this->m_movieClip)
return;
-
+
tracking = &this->m_movieClip->tracking;
-
+
object = BKE_tracking_object_get_named(tracking, this->m_trackingObjectName);
if (object) {
MovieTrackingPlaneTrack *plane_track;
-
+
plane_track = BKE_tracking_plane_track_get_named(tracking, object, this->m_planeTrackName);
-
+
if (plane_track) {
MovieTrackingPlaneMarker *plane_marker;
int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip, this->m_framenumber);
-
+
plane_marker = BKE_tracking_plane_marker_get(plane_track, clip_framenr);
- memcpy(this->m_corners, plane_marker->corners, sizeof(this->m_corners));
+ copy_v2_v2(corners[0], plane_marker->corners[0]);
+ copy_v2_v2(corners[1], plane_marker->corners[1]);
+ copy_v2_v2(corners[2], plane_marker->corners[2]);
+ copy_v2_v2(corners[3], plane_marker->corners[3]);
}
}
-
- for (int i = 0; i < 4; i++) {
- this->m_frameSpaceCorners[i][0] = this->m_corners[i][0] * this->getWidth();
- this->m_frameSpaceCorners[i][1] = this->m_corners[i][1] * this->getHeight();
- }
}
-void PlaneTrackCommonOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
+void PlaneTrackCommon::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
{
- NodeOperation::determineResolution(resolution, preferredResolution);
-
resolution[0] = 0;
resolution[1] = 0;
-
+
if (this->m_movieClip) {
int width, height;
MovieClipUser user = {0};
-
+
BKE_movieclip_user_set_frame(&user, this->m_framenumber);
BKE_movieclip_get_size(this->m_movieClip, &user, &width, &height);
-
+
resolution[0] = width;
resolution[1] = height;
}
}
+
+
+/* ******** PlaneTrackMaskOperation ******** */
+
+void PlaneTrackMaskOperation::initExecution()
+{
+ PlaneDistortMaskOperation::initExecution();
+
+ float corners[4][2];
+ readCornersFromTrack(corners);
+ calculateCorners(corners, true);
+}
+
+/* ******** PlaneTrackWarpImageOperation ******** */
+
+void PlaneTrackWarpImageOperation::initExecution()
+{
+ PlaneDistortWarpImageOperation::initExecution();
+
+ float corners[4][2];
+ readCornersFromTrack(corners);
+ calculateCorners(corners, true);
+ calculatePerspectiveMatrix();
+}
diff --git a/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.h b/source/blender/compositor/operations/COM_PlaneTrackOperation.h
index 705bdf4bd81..fdca760650a 100644
--- a/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.h
+++ b/source/blender/compositor/operations/COM_PlaneTrackOperation.h
@@ -20,12 +20,12 @@
* Sergey Sharybin
*/
-#ifndef _COM_PlaneTrackCommonOperation_h
-#define _COM_PlaneTrackCommonOperation_h
+#ifndef _COM_PlaneTrackWarpImageOperation_h
+#define _COM_PlaneTrackWarpImageOperation_h
#include <string.h>
-#include "COM_NodeOperation.h"
+#include "COM_PlaneDistortCommonOperation.h"
#include "DNA_movieclip_types.h"
#include "DNA_tracking_types.h"
@@ -33,30 +33,58 @@
#include "BLI_listbase.h"
#include "BLI_string.h"
-class PlaneTrackCommonOperation : public NodeOperation {
+class PlaneTrackCommon {
protected:
MovieClip *m_movieClip;
int m_framenumber;
char m_trackingObjectName[64];
char m_planeTrackName[64];
- float m_corners[4][2]; /* Corners coordinates in normalized space. */
- float m_frameSpaceCorners[4][2]; /* Corners coordinates in pixel space. */
-
- /**
- * Determine the output resolution. The resolution is retrieved from the Renderer
+ /* note: this class is not an operation itself (to prevent virtual inheritance issues)
+ * implementation classes must make wrappers to use these methods, see below.
*/
+ void readCornersFromTrack(float corners[4][2]);
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
public:
- PlaneTrackCommonOperation();
+ PlaneTrackCommon();
void setMovieClip(MovieClip *clip) {this->m_movieClip = clip;}
void setTrackingObject(char *object) { BLI_strncpy(this->m_trackingObjectName, object, sizeof(this->m_trackingObjectName)); }
void setPlaneTrackName(char *plane_track) { BLI_strncpy(this->m_planeTrackName, plane_track, sizeof(this->m_planeTrackName)); }
void setFramenumber(int framenumber) {this->m_framenumber = framenumber;}
+};
+
+class PlaneTrackMaskOperation : public PlaneDistortMaskOperation, public PlaneTrackCommon {
+public:
+ PlaneTrackMaskOperation() :
+ PlaneDistortMaskOperation(),
+ PlaneTrackCommon()
+ {}
+
+ void initExecution();
+
+ void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
+ {
+ PlaneTrackCommon::determineResolution(resolution, preferredResolution);
+ }
+};
+
+
+class PlaneTrackWarpImageOperation : public PlaneDistortWarpImageOperation, public PlaneTrackCommon {
+public:
+ PlaneTrackWarpImageOperation() :
+ PlaneDistortWarpImageOperation(),
+ PlaneTrackCommon()
+ {}
+
void initExecution();
+
+ void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
+ {
+ PlaneTrackCommon::determineResolution(resolution, preferredResolution);
+ }
};
#endif