diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-06-19 21:29:58 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-06-19 21:29:58 +0400 |
commit | 72e170d67a1d6f3484d3a62a51bdb65719bbb2a6 (patch) | |
tree | 1e5155377f77599322f814b09be54373836ed8a9 /source/blender/compositor | |
parent | a3680a35a6f57e54c0cfb9392e16bb62d052b7c3 (diff) |
Implementation of node for track position input
Diffstat (limited to 'source/blender/compositor')
6 files changed, 263 insertions, 0 deletions
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index d0093c58d23..2b1e8b6f9c4 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -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 diff --git a/source/blender/compositor/intern/COM_Converter.cpp b/source/blender/compositor/intern/COM_Converter.cpp index 0a8862e4017..926276c09a7 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" @@ -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 index 00000000000..c692bb4cb98 --- /dev/null +++ b/source/blender/compositor/nodes/COM_TrackPositionNode.cpp @@ -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 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..359e973adc7 --- /dev/null +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.cpp @@ -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 index 00000000000..5ef745c7593 --- /dev/null +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.h @@ -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 |