Mango request: added an input node to use track's position in compositor

--
svn merge -r48088:48089 -r48091:48092 ^/branches/soc-2011-tomato
This commit is contained in:
2012-07-10 11:01:25 +00:00
15 changed files with 426 additions and 0 deletions

View 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

View File

@@ -1942,6 +1942,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)

View File

@@ -338,6 +338,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

View File

@@ -110,6 +110,7 @@
#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"
@@ -377,6 +378,9 @@ Node *Converter::convert(bNode *b_node, bool fast)
case CMP_NODE_KEYING:
node = new KeyingNode(b_node);
break;
case CMP_NODE_TRACKPOS:
node = new TrackPositionNode(b_node);
break;
/* not inplemented yet */
default:
node = new MuteNode(b_node);

View File

@@ -0,0 +1,68 @@
/*
* 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);
operationX->setRelative(editorNode->custom1);
operationY->setMovieClip(clip);
operationY->setTrackingObject(trackpos_data->tracking_object);
operationY->setTrackName(trackpos_data->track_name);
operationY->setFramenumber(context->getFramenumber());
operationY->setAxis(1);
operationY->setRelative(editorNode->custom1);
outputX->relinkConnections(operationX->getOutputSocket());
outputY->relinkConnections(operationY->getOutputSocket());
graph->addOperation(operationX);
}

View File

@@ -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);
};

View File

@@ -0,0 +1,100 @@
/*
* 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;
this->relative = false;
}
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->relative) {
int i;
for (i = 0; i < track->markersnr; i++) {
marker = &track->markers[i];
if ((marker->flag & MARKER_DISABLED) == 0) {
outputValue[0] -= marker->pos[this->axis];
break;
}
}
}
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];
}

View File

@@ -0,0 +1,69 @@
/*
* 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;
bool relative;
/**
* 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 setRelative(bool value) {this->relative = value;}
void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer * inputBuffers[]);
const bool isSetOperation() const { return true; }
};
#endif

View 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"
@@ -2525,6 +2526,41 @@ 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);
}
uiItemR(layout, ptr, "use_relative", 0, NULL, ICON_NONE);
}
}
/* only once called */
static void node_composit_set_butfunc(bNodeType *ntype)
{
@@ -2723,6 +2759,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;
}

View File

@@ -663,6 +663,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 */

View File

@@ -3648,6 +3648,35 @@ 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");
prop = RNA_def_property(srna, "use_relative", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "custom1", 1);
RNA_def_property_ui_text(prop, "Relative", "Return relative position to first track's marker");
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)

View 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", "" )

View File

@@ -103,6 +103,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

View 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

View File

@@ -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);
}