[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58871] branches/soc-2011-tomato: Initial code layout for plane track deform node

Sergey Sharybin sergey.vfx at gmail.com
Sat Aug 3 21:53:16 CEST 2013


Revision: 58871
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58871
Author:   nazgul
Date:     2013-08-03 19:53:16 +0000 (Sat, 03 Aug 2013)
Log Message:
-----------
Initial code layout for plane track deform node

Idea of this is:
- User selects which plane track to use (for this he
  need to select movie clip datablock, object and track
  names).
- Node gets an image and mask inputs (both are optional).
- Node outputs:
  * Input image warped into the plane.
  * Input mask warped by the plane.
  * Plane, rasterized to a mask.

Warping image is done by computing reverse bilinear
coordinates, and getting pixel from corresponding
position.

This requires some tricks with downsampling to make warped
image looks smooth.

Currently compositor doesn't support downsampling, so we
needed to implement our own operation for this.

Currently idea is dead simple: value of output pixel equals
to an average of neighborhood of corresponding pixel in input
image. Size of neighborhood is defined by ratio between input
and output resolutions.

This operation doesn't give perfect results and works only
for downsampling. But it's totally internal operation not
exposed to the interface, so it's easy to replace it with
smarter bi-directional sampler with nicer filtering.

Limitations:
- Node currently only warps image and outputs mask created
  out of plane, warping input mask is not implemented yet.
- Image warping doesn't report proper depending area of
  interest yet, meaning interactivity might be not so much
  great,
- There's no anti-aliasing applied on the edges of warped
  image and plane mask, so they look really sharp at this
  moment.

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/nodeitems_builtins.py
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_node.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/node.c
    branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt
    branches/soc-2011-tomato/source/blender/compositor/intern/COM_Converter.cpp
    branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
    branches/soc-2011-tomato/source/blender/editors/space_node/drawnode.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_node_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_nodetree.c
    branches/soc-2011-tomato/source/blender/nodes/CMakeLists.txt
    branches/soc-2011-tomato/source/blender/nodes/NOD_composite.h
    branches/soc-2011-tomato/source/blender/nodes/NOD_static_types.h

Added Paths:
-----------
    branches/soc-2011-tomato/source/blender/compositor/nodes/COM_PlaneTrackDeformNode.cpp
    branches/soc-2011-tomato/source/blender/compositor/nodes/COM_PlaneTrackDeformNode.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_DownsampleOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_DownsampleOperation.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpMaskOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpMaskOperation.h
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_planetrackdeform.c

Modified: branches/soc-2011-tomato/release/scripts/startup/nodeitems_builtins.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/nodeitems_builtins.py	2013-08-03 19:46:21 UTC (rev 58870)
+++ branches/soc-2011-tomato/release/scripts/startup/nodeitems_builtins.py	2013-08-03 19:53:16 UTC (rev 58871)
@@ -342,6 +342,7 @@
         NodeItem("CompositorNodeMapUV"),
         NodeItem("CompositorNodeTransform"),
         NodeItem("CompositorNodeStabilize"),
+        NodeItem("CompositorNodePlaneTrackDeform"),
         ]),
     CompositorNodeCategory("CMP_GROUP", "Group", items=node_group_items),
     CompositorNodeCategory("CMP_LAYOUT", "Layout", items=[

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_node.h	2013-08-03 19:46:21 UTC (rev 58870)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_node.h	2013-08-03 19:53:16 UTC (rev 58871)
@@ -898,6 +898,7 @@
 #define CMP_NODE_PIXELATE       318
 
 #define CMP_NODE_MAP_RANGE	319
+#define CMP_NODE_PLANETRACKDEFORM	320
 
 /* channel toggles */
 #define CMP_CHAN_RGB		1

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/node.c	2013-08-03 19:46:21 UTC (rev 58870)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/node.c	2013-08-03 19:53:16 UTC (rev 58871)
@@ -3391,6 +3391,7 @@
 
 	register_node_type_cmp_mask();
 	register_node_type_cmp_trackpos();
+	register_node_type_cmp_planetrackdeform();
 }
 
 static void registerShaderNodes(void) 

Modified: branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt	2013-08-03 19:46:21 UTC (rev 58870)
+++ branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt	2013-08-03 19:53:16 UTC (rev 58871)
@@ -184,6 +184,9 @@
 	nodes/COM_GlareNode.cpp
 	nodes/COM_GlareNode.h
 
+	nodes/COM_PlaneTrackDeformNode.cpp
+	nodes/COM_PlaneTrackDeformNode.h
+
 	nodes/COM_CropNode.cpp
 	nodes/COM_CropNode.h
 	operations/COM_CropOperation.cpp
@@ -597,6 +600,16 @@
 	operations/COM_ProjectorLensDistortionOperation.h
 	operations/COM_ScreenLensDistortionOperation.cpp
 	operations/COM_ScreenLensDistortionOperation.h
+	operations/COM_PlaneTrackCommonOperation.cpp
+	operations/COM_PlaneTrackCommonOperation.h
+	operations/COM_PlaneTrackMaskOperation.cpp
+	operations/COM_PlaneTrackMaskOperation.h
+	operations/COM_PlaneTrackWarpImageOperation.cpp
+	operations/COM_PlaneTrackWarpImageOperation.h
+	operations/COM_PlaneTrackWarpMaskOperation.cpp
+	operations/COM_PlaneTrackWarpMaskOperation.h
+	operations/COM_DownsampleOperation.cpp
+	operations/COM_DownsampleOperation.h
 
 	#Filter operations
 	operations/COM_ConvolutionFilterOperation.h

Modified: branches/soc-2011-tomato/source/blender/compositor/intern/COM_Converter.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/intern/COM_Converter.cpp	2013-08-03 19:46:21 UTC (rev 58870)
+++ branches/soc-2011-tomato/source/blender/compositor/intern/COM_Converter.cpp	2013-08-03 19:53:16 UTC (rev 58871)
@@ -121,6 +121,7 @@
 #include "COM_ViewerNode.h"
 #include "COM_ZCombineNode.h"
 #include "COM_PixelateNode.h"
+#include "COM_PlaneTrackDeformNode.h"
 
 Node *Converter::convert(bNode *b_node, bool fast)
 {
@@ -402,6 +403,9 @@
 		case CMP_NODE_PIXELATE:
 			node = new PixelateNode(b_node);
 			break;
+		case CMP_NODE_PLANETRACKDEFORM:
+			node = new PlaneTrackDeformNode(b_node);
+			break;
 		default:
 			node = new MuteNode(b_node);
 			break;

Added: branches/soc-2011-tomato/source/blender/compositor/nodes/COM_PlaneTrackDeformNode.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/nodes/COM_PlaneTrackDeformNode.cpp	                        (rev 0)
+++ branches/soc-2011-tomato/source/blender/compositor/nodes/COM_PlaneTrackDeformNode.cpp	2013-08-03 19:53:16 UTC (rev 58871)
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2012, 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
+ *		Sergey Sharybin
+ */
+
+#include "COM_PlaneTrackDeformNode.h"
+#include "COM_ExecutionSystem.h"
+
+#include "COM_PlaneTrackMaskOperation.h"
+#include "COM_PlaneTrackWarpImageOperation.h"
+#include "COM_PlaneTrackWarpMaskOperation.h"
+
+#include "COM_DownsampleOperation.h"
+
+extern "C" {
+	#include "BKE_node.h"
+	#include "BKE_movieclip.h"
+	#include "BKE_tracking.h"
+}
+
+static int getLengthInPixels(float v1[2], float v2[2], int width, int height)
+{
+	float dx = fabsf(v2[0] - v1[0]) * width;
+	float dy = fabsf(v2[1] - v1[1]) * height;
+
+	return sqrtf(dx * dx + dy * dy);
+}
+
+PlaneTrackDeformNode::PlaneTrackDeformNode(bNode *editorNode) : Node(editorNode)
+{
+	/* pass */
+}
+
+bool PlaneTrackDeformNode::getDownsampleDimensions(MovieClip *movieClip, NodePlaneTrackDeformData *data, int frame_number,
+                                                   float *downsample_width_r, float *downsample_height_r)
+{
+	bool do_downsample = false;
+
+	*downsample_width_r = 0.0f;
+	*downsample_height_r = 0.0f;
+
+	if (movieClip) {
+		MovieTracking *tracking = &movieClip->tracking;
+		MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, data->tracking_object);
+		if (object) {
+			MovieTrackingPlaneTrack *plane_track =
+				BKE_tracking_plane_track_get_named(tracking, object, data->plane_track_name);
+
+			if (plane_track) {
+				MovieClipUser user = {0};
+				int width, height;
+				int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(movieClip, frame_number);
+				MovieTrackingPlaneMarker *plane_marker =
+					BKE_tracking_plane_marker_get(plane_track, clip_framenr);
+
+				BKE_movieclip_user_set_frame(&user, frame_number);
+				BKE_movieclip_get_size(movieClip, &user, &width, &height);
+
+				*downsample_width_r = max_ff(getLengthInPixels(plane_marker->corners[0], plane_marker->corners[1], width, height),
+				                             getLengthInPixels(plane_marker->corners[2], plane_marker->corners[3], width, height));
+				*downsample_height_r = max_ff(getLengthInPixels(plane_marker->corners[1], plane_marker->corners[2], width, height),
+				                              getLengthInPixels(plane_marker->corners[0], plane_marker->corners[3], width, height));
+
+				/* Only do downsample if both dimensions are smaller */
+				do_downsample = *downsample_width_r < width && *downsample_height_r < height;
+			}
+		}
+	}
+
+	return do_downsample;
+}
+
+void PlaneTrackDeformNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
+{
+	InputSocket *input_image = this->getInputSocket(0);
+	InputSocket *input_mask = this->getInputSocket(1);
+
+	OutputSocket *output_warped_image = this->getOutputSocket(0);
+	OutputSocket *output_warped_mask = this->getOutputSocket(1);
+	OutputSocket *output_plane = this->getOutputSocket(2);
+
+	bNode *editorNode = this->getbNode();
+	MovieClip *clip = (MovieClip *) editorNode->id;
+
+	NodePlaneTrackDeformData *data = (NodePlaneTrackDeformData *) editorNode->storage;
+
+	int frame_number = context->getFramenumber();
+
+	if (output_warped_image->isConnected()) {
+		PlaneTrackWarpImageOperation *warp_image_operation = new PlaneTrackWarpImageOperation();
+
+		warp_image_operation->setMovieClip(clip);
+		warp_image_operation->setTrackingObject(data->tracking_object);
+		warp_image_operation->setPlaneTrackName(data->plane_track_name);
+		warp_image_operation->setFramenumber(frame_number);
+
+		float downsample_width, downsample_height;
+		if (getDownsampleDimensions(clip, data, frame_number, &downsample_width, &downsample_height)) {
+			DownsampleOperation *downsample_operation = new DownsampleOperation();
+			downsample_operation->setNewWidth(downsample_width);
+			downsample_operation->setNewHeight(downsample_height);
+			downsample_operation->setKeepAspect(true);
+
+			input_image->relinkConnections(downsample_operation->getInputSocket(0), 0, graph);
+			addLink(graph, downsample_operation->getOutputSocket(), warp_image_operation->getInputSocket(0));
+			graph->addOperation(downsample_operation);
+		}
+		else {
+			input_image->relinkConnections(warp_image_operation->getInputSocket(0), 0, graph);
+		}
+
+		output_warped_image->relinkConnections(warp_image_operation->getOutputSocket());
+
+		graph->addOperation(warp_image_operation);
+	}
+
+	if (output_warped_mask->isConnected()) {
+		PlaneTrackWarpMaskOperation *warp_mask_operation = new PlaneTrackWarpMaskOperation();
+
+		warp_mask_operation->setMovieClip(clip);
+		warp_mask_operation->setTrackingObject(data->tracking_object);
+		warp_mask_operation->setPlaneTrackName(data->plane_track_name);
+		warp_mask_operation->setFramenumber(frame_number);
+
+		input_mask->relinkConnections(warp_mask_operation->getInputSocket(0), 1, graph);
+		output_warped_mask->relinkConnections(warp_mask_operation->getOutputSocket());
+		graph->addOperation(warp_mask_operation);
+	}
+
+	if (output_plane->isConnected()) {
+		PlaneTrackMaskOperation *plane_mask_operation = new PlaneTrackMaskOperation();
+
+		plane_mask_operation->setMovieClip(clip);
+		plane_mask_operation->setTrackingObject(data->tracking_object);
+		plane_mask_operation->setPlaneTrackName(data->plane_track_name);
+		plane_mask_operation->setFramenumber(frame_number);
+
+		output_plane->relinkConnections(plane_mask_operation->getOutputSocket());
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list