Blender  V2.93
COM_TrackPositionNode.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2012, Blender Foundation.
17  */
18 
19 #include "COM_TrackPositionNode.h"
20 
21 #include "COM_ConvertOperation.h"
22 #include "COM_ExecutionSystem.h"
24 
25 #include "DNA_movieclip_types.h"
26 
27 #include "BKE_node.h"
28 
29 namespace blender::compositor {
30 
32 {
33  /* pass */
34 }
35 
37  MovieClip *clip,
38  NodeTrackPosData *trackpos_data,
39  int axis,
40  int frame_number,
41  int delta)
42 {
44  operation->setMovieClip(clip);
45  operation->setTrackingObject(trackpos_data->tracking_object);
46  operation->setTrackName(trackpos_data->track_name);
47  operation->setFramenumber(frame_number);
48  operation->setAxis(axis);
50  operation->setRelativeFrame(frame_number + delta);
51  operation->setSpeedOutput(true);
52  converter.addOperation(operation);
53  return operation;
54 }
55 
57  const CompositorContext &context) const
58 {
59  bNode *editorNode = this->getbNode();
60  MovieClip *clip = (MovieClip *)editorNode->id;
61  NodeTrackPosData *trackpos_data = (NodeTrackPosData *)editorNode->storage;
62 
63  NodeOutput *outputX = this->getOutputSocket(0);
64  NodeOutput *outputY = this->getOutputSocket(1);
65  NodeOutput *outputSpeed = this->getOutputSocket(2);
66 
67  int frame_number;
68  if (editorNode->custom1 == CMP_TRACKPOS_ABSOLUTE_FRAME) {
69  frame_number = editorNode->custom2;
70  }
71  else {
72  frame_number = context.getFramenumber();
73  }
74 
76  operationX->setMovieClip(clip);
77  operationX->setTrackingObject(trackpos_data->tracking_object);
78  operationX->setTrackName(trackpos_data->track_name);
79  operationX->setFramenumber(frame_number);
80  operationX->setAxis(0);
81  operationX->setPosition(editorNode->custom1);
82  operationX->setRelativeFrame(editorNode->custom2);
83  converter.addOperation(operationX);
84  converter.mapOutputSocket(outputX, operationX->getOutputSocket());
85 
87  operationY->setMovieClip(clip);
88  operationY->setTrackingObject(trackpos_data->tracking_object);
89  operationY->setTrackName(trackpos_data->track_name);
90  operationY->setFramenumber(frame_number);
91  operationY->setAxis(1);
92  operationY->setPosition(editorNode->custom1);
93  operationY->setRelativeFrame(editorNode->custom2);
94  converter.addOperation(operationY);
95  converter.mapOutputSocket(outputY, operationY->getOutputSocket());
96 
97  TrackPositionOperation *operationMotionPreX = create_motion_operation(
98  converter, clip, trackpos_data, 0, frame_number, -1);
99  TrackPositionOperation *operationMotionPreY = create_motion_operation(
100  converter, clip, trackpos_data, 1, frame_number, -1);
101  TrackPositionOperation *operationMotionPostX = create_motion_operation(
102  converter, clip, trackpos_data, 0, frame_number, 1);
103  TrackPositionOperation *operationMotionPostY = create_motion_operation(
104  converter, clip, trackpos_data, 1, frame_number, 1);
105 
106  CombineChannelsOperation *combine_operation = new CombineChannelsOperation();
107  converter.addOperation(combine_operation);
108  converter.addLink(operationMotionPreX->getOutputSocket(), combine_operation->getInputSocket(0));
109  converter.addLink(operationMotionPreY->getOutputSocket(), combine_operation->getInputSocket(1));
110  converter.addLink(operationMotionPostX->getOutputSocket(), combine_operation->getInputSocket(2));
111  converter.addLink(operationMotionPostY->getOutputSocket(), combine_operation->getInputSocket(3));
112  converter.mapOutputSocket(outputSpeed, combine_operation->getOutputSocket());
113 }
114 
115 } // namespace blender::compositor
#define CMP_TRACKPOS_ABSOLUTE_FRAME
Definition: BKE_node.h:1256
#define CMP_TRACKPOS_ABSOLUTE
Definition: BKE_node.h:1253
Overall context of the compositor.
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void addLink(NodeOperationOutput *from, NodeOperationInput *to)
NodeOperationInput * getInputSocket(unsigned int index)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:258
NodeOutput * getOutputSocket(const unsigned int index=0) const
Definition: COM_Node.cc:108
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
static TrackPositionOperation * create_motion_operation(NodeConverter &converter, MovieClip *clip, NodeTrackPosData *trackpos_data, int axis, int frame_number, int delta)
char tracking_object[64]
short custom1
struct ID * id
void * storage
short custom2