diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-07-10 15:01:25 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-07-10 15:01:25 +0400 |
commit | 5cc0e5f751e2428db9ca3cf263f3a44f77a2bc5c (patch) | |
tree | 929528c44be367a740b97b445b81081c8e4fe2b9 /source/blender/compositor | |
parent | 5b57f38fb5e324f8365e135bb0abc2b5e8c57953 (diff) | |
parent | 72e170d67a1d6f3484d3a62a51bdb65719bbb2a6 (diff) |
Mango request: added an input node to use track's position in compositor
--
svn merge -r48088:48089 -r48091:48092 ^/branches/soc-2011-tomato
Diffstat (limited to 'source/blender/compositor')
6 files changed, 282 insertions, 0 deletions
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index 9bad1b55d95..870e379b343 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -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 diff --git a/source/blender/compositor/intern/COM_Converter.cpp b/source/blender/compositor/intern/COM_Converter.cpp index 4ed7ae7ca8a..37d38261ea5 100644 --- a/source/blender/compositor/intern/COM_Converter.cpp +++ b/source/blender/compositor/intern/COM_Converter.cpp @@ -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); diff --git a/source/blender/compositor/nodes/COM_TrackPositionNode.cpp b/source/blender/compositor/nodes/COM_TrackPositionNode.cpp new file mode 100644 index 00000000000..243f63a0149 --- /dev/null +++ b/source/blender/compositor/nodes/COM_TrackPositionNode.cpp @@ -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); +} diff --git a/source/blender/compositor/nodes/COM_TrackPositionNode.h b/source/blender/compositor/nodes/COM_TrackPositionNode.h new file mode 100644 index 00000000000..55fd1622437 --- /dev/null +++ b/source/blender/compositor/nodes/COM_TrackPositionNode.h @@ -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 index 00000000000..cf516401a3c --- /dev/null +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.cpp @@ -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]; +} diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.h b/source/blender/compositor/operations/COM_TrackPositionOperation.h new file mode 100644 index 00000000000..caf444db0d5 --- /dev/null +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.h @@ -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 |