Implementation of node for track position input
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 19 Jun 2012 17:29:58 +0000 (17:29 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 19 Jun 2012 17:29:58 +0000 (17:29 +0000)
15 files changed:
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/compositor/CMakeLists.txt
source/blender/compositor/intern/COM_Converter.cpp
source/blender/compositor/nodes/COM_TrackPositionNode.cpp [new file with mode: 0644]
source/blender/compositor/nodes/COM_TrackPositionNode.h [new file with mode: 0644]
source/blender/compositor/operations/COM_TrackPositionOperation.cpp [new file with mode: 0644]
source/blender/compositor/operations/COM_TrackPositionOperation.h [new file with mode: 0644]
source/blender/editors/space_node/drawnode.c
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/intern/rna_nodetree.c
source/blender/makesrna/intern/rna_nodetree_types.h
source/blender/nodes/CMakeLists.txt
source/blender/nodes/NOD_composite.h
source/blender/nodes/composite/nodes/node_composite_trackpos.c [new file with mode: 0644]

index b3f17c06d5c691f6ae8cafda6b696b88d0c681a3..7bd9f75b2dd3314c6b4ab9edea68b71bf40e30e9 100644 (file)
@@ -660,6 +660,7 @@ void                        ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat);
 #define CMP_NODE_MASK          268
 #define CMP_NODE_KEYINGSCREEN          269
 #define CMP_NODE_KEYING                        270
+#define CMP_NODE_TRACKPOS              271
 
 #define CMP_NODE_GLARE         301
 #define CMP_NODE_TONEMAP       302
index a5e081d122df3ad52b404f52bbacf47d70cc7774..47f574d6832bd003faf06cc06fe38af42647699f 100644 (file)
@@ -1925,6 +1925,7 @@ static void registerCompositNodes(bNodeTreeType *ttype)
        register_node_type_cmp_switch(ttype);
 
        register_node_type_cmp_mask(ttype);
+       register_node_type_cmp_trackpos(ttype);
 }
 
 static void registerShaderNodes(bNodeTreeType *ttype) 
index d0093c58d23235c6b8d1819796f2fda5550a949c..2b1e8b6f9c43f7319c2eef55ce1e721e29932275 100644 (file)
@@ -334,6 +334,11 @@ set(SRC
        operations/COM_KeyingScreenOperation.cpp
        operations/COM_KeyingScreenOperation.h
 
+       nodes/COM_TrackPositionNode.cpp
+       nodes/COM_TrackPositionNode.h
+       operations/COM_TrackPositionOperation.cpp
+       operations/COM_TrackPositionOperation.h
+
        nodes/COM_KeyingNode.cpp
        nodes/COM_KeyingNode.h
        operations/COM_KeyingOperation.cpp
index 0a8862e4017fa90ff7911ad92892eb3dda9fba8e..926276c09a7683e15ad9923f3af457bdfb3e9b9e 100644 (file)
 #include "COM_TransformNode.h"
 #include "COM_TranslateNode.h"
 #include "COM_TranslateOperation.h"
+#include "COM_TrackPositionNode.h"
 #include "COM_ValueNode.h"
 #include "COM_VectorBlurNode.h"
 #include "COM_VectorCurveNode.h"
@@ -361,6 +362,9 @@ Node *Converter::convert(bNode *bNode)
                case CMP_NODE_KEYING:
                        node = new KeyingNode(bNode);
                        break;
+               case CMP_NODE_TRACKPOS:
+                       node = new TrackPositionNode(bNode);
+                       break;
                /* not inplemented yet */
                default:
                        node = new MuteNode(bNode);
diff --git a/source/blender/compositor/nodes/COM_TrackPositionNode.cpp b/source/blender/compositor/nodes/COM_TrackPositionNode.cpp
new file mode 100644 (file)
index 0000000..c692bb4
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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_TrackPositionNode.h"
+#include "COM_ExecutionSystem.h"
+#include "COM_TrackPositionOperation.h"
+
+extern "C" {
+       #include "DNA_movieclip_types.h"
+}
+
+TrackPositionNode::TrackPositionNode(bNode *editorNode) : Node(editorNode)
+{
+       /* pass */
+}
+
+void TrackPositionNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
+{
+       OutputSocket *outputX = this->getOutputSocket(0);
+       OutputSocket *outputY = this->getOutputSocket(1);
+
+       bNode *editorNode = this->getbNode();
+       MovieClip *clip = (MovieClip *) editorNode->id;
+
+       NodeTrackPosData *trackpos_data = (NodeTrackPosData *) editorNode->storage;
+
+       TrackPositionOperation *operationX = new TrackPositionOperation();
+       TrackPositionOperation *operationY = new TrackPositionOperation();
+
+       operationX->setMovieClip(clip);
+       operationX->setTrackingObject(trackpos_data->tracking_object);
+       operationX->setTrackName(trackpos_data->track_name);
+       operationX->setFramenumber(context->getFramenumber());
+       operationX->setAxis(0);
+
+       operationY->setMovieClip(clip);
+       operationY->setTrackingObject(trackpos_data->tracking_object);
+       operationY->setTrackName(trackpos_data->track_name);
+       operationY->setFramenumber(context->getFramenumber());
+       operationY->setAxis(1);
+
+       outputX->relinkConnections(operationX->getOutputSocket());
+       outputY->relinkConnections(operationY->getOutputSocket());
+
+       graph->addOperation(operationX);
+}
diff --git a/source/blender/compositor/nodes/COM_TrackPositionNode.h b/source/blender/compositor/nodes/COM_TrackPositionNode.h
new file mode 100644 (file)
index 0000000..55fd162
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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_Node.h"
+#include "DNA_node_types.h"
+
+/**
+  * @brief TrackPositionNode
+  * @ingroup Node
+  */
+class TrackPositionNode : public Node {
+public:
+       TrackPositionNode(bNode *editorNode);
+       void convertToOperations(ExecutionSystem *graph, CompositorContext *context);
+
+};
diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.cpp b/source/blender/compositor/operations/COM_TrackPositionOperation.cpp
new file mode 100644 (file)
index 0000000..359e973
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * 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_TrackPositionOperation.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_math_color.h"
+
+#include "DNA_scene_types.h"
+
+extern "C" {
+       #include "BKE_movieclip.h"
+       #include "BKE_tracking.h"
+}
+
+TrackPositionOperation::TrackPositionOperation() : NodeOperation()
+{
+       this->addOutputSocket(COM_DT_VALUE);
+       this->movieClip = NULL;
+       this->framenumber = 0;
+       this->trackingObject[0] = 0;
+       this->trackName[0] = 0;
+       this->axis = 0;
+}
+
+void TrackPositionOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
+{
+       MovieClipUser user = {0};
+       MovieTracking *tracking = &movieClip->tracking;
+       MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, this->trackingObject);
+       MovieTrackingTrack *track;
+       MovieTrackingMarker *marker;
+       int width, height;
+
+       outputValue[0] = 0.0f;
+
+       if (!object)
+               return;
+
+       track = BKE_tracking_track_get_named(tracking, object, this->trackName);
+
+       if (!track)
+               return;
+
+       BKE_movieclip_user_set_frame(&user, this->framenumber);
+       BKE_movieclip_get_size(this->movieClip, &user, &width, &height);
+
+       marker = BKE_tracking_marker_get(track, this->framenumber);
+
+       outputValue[0] = marker->pos[this->axis];
+
+       if (this->axis == 0)
+               outputValue[0] *= width;
+       else
+               outputValue[0] *= height;
+}
+
+void TrackPositionOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[])
+{
+       resolution[0] = preferredResolution[0];
+       resolution[1] = preferredResolution[1];
+}
diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.h b/source/blender/compositor/operations/COM_TrackPositionOperation.h
new file mode 100644 (file)
index 0000000..5ef745c
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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
+ */
+
+
+#ifndef _COM_TrackPositionOperation_h
+#define _COM_TrackPositionOperation_h
+
+#include <string.h>
+
+#include "COM_NodeOperation.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_movieclip_types.h"
+
+#include "BLI_listbase.h"
+
+/**
+  * Class with implementation of green screen gradient rasterization
+  */
+class TrackPositionOperation : public NodeOperation {
+protected:
+       MovieClip *movieClip;
+       int framenumber;
+       char trackingObject[64];
+       char trackName[64];
+       int axis;
+
+       /**
+         * Determine the output resolution. The resolution is retrieved from the Renderer
+         */
+       void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]);
+
+public:
+       TrackPositionOperation();
+
+       void setMovieClip(MovieClip *clip) {this->movieClip = clip;}
+       void setTrackingObject(char *object) {strncpy(this->trackingObject, object, sizeof(this->trackingObject));}
+       void setTrackName(char *track) {strncpy(this->trackName, track, sizeof(this->trackName));}
+       void setFramenumber(int framenumber) {this->framenumber = framenumber;}
+       void setAxis(int value) {this->axis = value;}
+
+       void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer * inputBuffers[]);
+
+       const bool isSetOperation() const { return true; }
+};
+
+#endif
index 4ed9acf14818bf6c10a1a8ec8b9148bc9a4327eb..54f852f11222666bb85bfdd9309521a06bcd9019 100644 (file)
@@ -52,6 +52,7 @@
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
+#include "BKE_tracking.h"
 
 #include "BLF_api.h"
 #include "BLF_translation.h"
@@ -2466,6 +2467,39 @@ static void node_composit_buts_keying(uiLayout *layout, bContext *UNUSED(C), Poi
        uiItemR(layout, ptr, "blur_post", 0, NULL, ICON_NONE);
 }
 
+static void node_composit_buts_trackpos(uiLayout *layout, bContext *C, PointerRNA *ptr)
+{
+       bNode *node= ptr->data;
+
+       uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
+
+       if (node->id) {
+               MovieClip *clip = (MovieClip *) node->id;
+               MovieTracking *tracking = &clip->tracking;
+               MovieTrackingObject *object;
+               uiLayout *col;
+               PointerRNA tracking_ptr;
+               NodeTrackPosData *data = node->storage;
+
+               RNA_pointer_create(&clip->id, &RNA_MovieTracking, tracking, &tracking_ptr);
+
+               col = uiLayoutColumn(layout, 0);
+               uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA);
+
+               object = BKE_tracking_object_get_named(tracking, data->tracking_object);
+               if (object) {
+                       PointerRNA object_ptr;
+
+                       RNA_pointer_create(&clip->id, &RNA_MovieTrackingObject, object, &object_ptr);
+
+                       uiItemPointerR(col, ptr, "track_name", &object_ptr, "tracks", "", ICON_ANIM_DATA);
+               }
+               else {
+                       uiItemR(layout, ptr, "track_name", 0, "", ICON_ANIM_DATA);
+               }
+       }
+}
+
 /* only once called */
 static void node_composit_set_butfunc(bNodeType *ntype)
 {
@@ -2664,6 +2698,9 @@ static void node_composit_set_butfunc(bNodeType *ntype)
                case CMP_NODE_KEYING:
                        ntype->uifunc = node_composit_buts_keying;
                        break;
+               case CMP_NODE_TRACKPOS:
+                       ntype->uifunc = node_composit_buts_trackpos;
+                       break;
                default:
                        ntype->uifunc = NULL;
        }
index 9bc002b7bbee4b24cb3537640917eb1b917de45e..460038f60046c7b42fbdd13cc570d060d30fd744 100644 (file)
@@ -643,6 +643,11 @@ typedef struct NodeKeyingData {
        int blur_pre, blur_post;
 } NodeKeyingData;
 
+typedef struct NodeTrackPosData {
+       char tracking_object[64];
+       char track_name[64];
+} NodeTrackPosData;
+
 /* frame node flags */
 #define NODE_FRAME_SHRINK              1       /* keep the bounding box minimal */
 #define NODE_FRAME_RESIZEABLE  2       /* test flag, if frame can be resized by user */
index 906f9cf5b1c6999a9f77a08b390921198a18af60..b72d2e22d6889e09c88c8be7acac91a8fa2b63bc 100644 (file)
@@ -3613,6 +3613,30 @@ static void def_cmp_keying(StructRNA *srna)
        RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 }
 
+static void def_cmp_trackpos(StructRNA *srna)
+{
+       PropertyRNA *prop;
+
+       prop = RNA_def_property(srna, "clip", PROP_POINTER, PROP_NONE);
+       RNA_def_property_pointer_sdna(prop, NULL, "id");
+       RNA_def_property_struct_type(prop, "MovieClip");
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Movie Clip", "");
+       RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+       RNA_def_struct_sdna_from(srna, "NodeTrackPosData", "storage");
+
+       prop = RNA_def_property(srna, "tracking_object", PROP_STRING, PROP_NONE);
+       RNA_def_property_string_sdna(prop, NULL, "tracking_object");
+       RNA_def_property_ui_text(prop, "Tracking Object", "");
+       RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
+
+       prop = RNA_def_property(srna, "track_name", PROP_STRING, PROP_NONE);
+       RNA_def_property_string_sdna(prop, NULL, "track_name");
+       RNA_def_property_ui_text(prop, "Track", "");
+       RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
+}
+
 /* -- Texture Nodes --------------------------------------------------------- */
 
 static void def_tex_output(StructRNA *srna)
index 20f58f4d16e9f8432757a1e74c4c97e7e202bb81..dd604e8735776af3c3500aced73987c32eb87691 100644 (file)
@@ -170,6 +170,7 @@ DefNode( CompositorNode, CMP_NODE_COLORCORRECTION,def_cmp_colorcorrection,"COLOR
 DefNode( CompositorNode, CMP_NODE_MASK,           def_cmp_mask,           "MASK",           Mask,             "Mask",              ""              )
 DefNode( CompositorNode, CMP_NODE_KEYINGSCREEN,   def_cmp_keyingscreen,   "KEYINGSCREEN",   KeyingScreen,     "KeyingScreen",      ""              )
 DefNode( CompositorNode, CMP_NODE_KEYING,         def_cmp_keying,         "KEYING",         Keying,           "Keying",            ""              )
+DefNode( CompositorNode, CMP_NODE_TRACKPOS,       def_cmp_trackpos,       "TRACKPOS",       TrackPos,         "Track Position",    ""              )
                                                                                                                                                    
 DefNode( TextureNode,    TEX_NODE_OUTPUT,         def_tex_output,         "OUTPUT",         Output,           "Output",            ""              )
 DefNode( TextureNode,    TEX_NODE_CHECKER,        0,                      "CHECKER",        Checker,          "Checker",           ""              )
index 2415c7842a766e7ee8ef6c33a0a07caa16aa4fbe..146f59c83f64ac43fceef850b5926ee67a872b1b 100644 (file)
@@ -104,6 +104,7 @@ set(SRC
        composite/nodes/node_composite_stabilize2d.c
        composite/nodes/node_composite_texture.c
        composite/nodes/node_composite_tonemap.c
+       composite/nodes/node_composite_trackpos.c
        composite/nodes/node_composite_transform.c
        composite/nodes/node_composite_translate.c
        composite/nodes/node_composite_valToRgb.c
index 33d6327ece16a8e2a15e53c06375b582b5e13467..3b4fa49ea05f0f12c126894d74a0c828b4958963 100644 (file)
@@ -132,4 +132,6 @@ void register_node_type_cmp_bokehimage(struct bNodeTreeType *ttype);
 void register_node_type_cmp_bokehblur(struct bNodeTreeType *ttype);
 void register_node_type_cmp_switch(struct bNodeTreeType *ttype);
 
+void register_node_type_cmp_trackpos(struct bNodeTreeType *ttype);
+
 #endif
diff --git a/source/blender/nodes/composite/nodes/node_composite_trackpos.c b/source/blender/nodes/composite/nodes/node_composite_trackpos.c
new file mode 100644 (file)
index 0000000..09eb42b
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * The Original Code is Copyright (C) 2011 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Blender Foundation,
+ *                 Sergey Sharybin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/composite/nodes/node_composite_movieclip.c
+ *  \ingroup cmpnodes
+ */
+
+
+#include "node_composite_util.h"
+
+static bNodeSocketTemplate cmp_node_trackpos_out[] = {
+       {       SOCK_FLOAT,             1,      N_("X")},
+       {       SOCK_FLOAT,             1,      N_("Y")},
+       {       -1, 0, ""       }
+};
+
+static void node_composit_exec_trackpos(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
+{
+}
+
+static void init(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
+{
+       NodeTrackPosData *data = MEM_callocN(sizeof(NodeTrackPosData), "node track position data");
+
+       node->storage = data;
+}
+
+void register_node_type_cmp_trackpos(bNodeTreeType *ttype)
+{
+       static bNodeType ntype;
+
+       node_type_base(ttype, &ntype, CMP_NODE_TRACKPOS, "Track Position", NODE_CLASS_INPUT, NODE_OPTIONS);
+       node_type_socket_templates(&ntype, NULL, cmp_node_trackpos_out);
+       node_type_size(&ntype, 120, 80, 300);
+       node_type_init(&ntype, init);
+       node_type_storage(&ntype, "NodeTrackPosData", node_free_standard_storage, node_copy_standard_storage);
+       node_type_exec(&ntype, node_composit_exec_trackpos);
+
+       nodeRegisterType(ttype, &ntype);
+}