Blender  V2.93
COM_Stabilize2dNode.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 2011, Blender Foundation.
17  */
18 
19 #include "COM_Stabilize2dNode.h"
20 #include "COM_ExecutionSystem.h"
22 #include "COM_RotateOperation.h"
23 #include "COM_ScaleOperation.h"
25 #include "COM_TranslateOperation.h"
26 
27 #include "BKE_tracking.h"
28 
29 #include "DNA_movieclip_types.h"
30 
31 namespace blender::compositor {
32 
33 Stabilize2dNode::Stabilize2dNode(bNode *editorNode) : Node(editorNode)
34 {
35  /* pass */
36 }
37 
39  const CompositorContext &context) const
40 {
41  bNode *editorNode = this->getbNode();
42  NodeInput *imageInput = this->getInputSocket(0);
43  MovieClip *clip = (MovieClip *)editorNode->id;
44  bool invert = (editorNode->custom2 & CMP_NODEFLAG_STABILIZE_INVERSE) != 0;
45 
46  ScaleOperation *scaleOperation = new ScaleOperation();
47  scaleOperation->setSampler((PixelSampler)editorNode->custom1);
48  RotateOperation *rotateOperation = new RotateOperation();
49  rotateOperation->setDoDegree2RadConversion(false);
50  TranslateOperation *translateOperation = new TranslateOperation();
55  SetSamplerOperation *psoperation = new SetSamplerOperation();
56  psoperation->setSampler((PixelSampler)editorNode->custom1);
57 
58  scaleAttribute->setAttribute(MCA_SCALE);
59  scaleAttribute->setFramenumber(context.getFramenumber());
60  scaleAttribute->setMovieClip(clip);
61  scaleAttribute->setInvert(invert);
62 
63  angleAttribute->setAttribute(MCA_ANGLE);
64  angleAttribute->setFramenumber(context.getFramenumber());
65  angleAttribute->setMovieClip(clip);
66  angleAttribute->setInvert(invert);
67 
68  xAttribute->setAttribute(MCA_X);
69  xAttribute->setFramenumber(context.getFramenumber());
70  xAttribute->setMovieClip(clip);
71  xAttribute->setInvert(invert);
72 
73  yAttribute->setAttribute(MCA_Y);
74  yAttribute->setFramenumber(context.getFramenumber());
75  yAttribute->setMovieClip(clip);
76  yAttribute->setInvert(invert);
77 
78  converter.addOperation(scaleAttribute);
79  converter.addOperation(angleAttribute);
80  converter.addOperation(xAttribute);
81  converter.addOperation(yAttribute);
82  converter.addOperation(scaleOperation);
83  converter.addOperation(translateOperation);
84  converter.addOperation(rotateOperation);
85  converter.addOperation(psoperation);
86 
87  converter.addLink(scaleAttribute->getOutputSocket(), scaleOperation->getInputSocket(1));
88  converter.addLink(scaleAttribute->getOutputSocket(), scaleOperation->getInputSocket(2));
89 
90  converter.addLink(angleAttribute->getOutputSocket(), rotateOperation->getInputSocket(1));
91 
92  converter.addLink(xAttribute->getOutputSocket(), translateOperation->getInputSocket(1));
93  converter.addLink(yAttribute->getOutputSocket(), translateOperation->getInputSocket(2));
94 
95  converter.mapOutputSocket(getOutputSocket(), psoperation->getOutputSocket());
96 
97  if (invert) {
98  // Translate -> Rotate -> Scale.
99  converter.mapInputSocket(imageInput, translateOperation->getInputSocket(0));
100 
101  converter.addLink(translateOperation->getOutputSocket(), rotateOperation->getInputSocket(0));
102  converter.addLink(rotateOperation->getOutputSocket(), scaleOperation->getInputSocket(0));
103 
104  converter.addLink(scaleOperation->getOutputSocket(), psoperation->getInputSocket(0));
105  }
106  else {
107  // Scale -> Rotate -> Translate.
108  converter.mapInputSocket(imageInput, scaleOperation->getInputSocket(0));
109 
110  converter.addLink(scaleOperation->getOutputSocket(), rotateOperation->getInputSocket(0));
111  converter.addLink(rotateOperation->getOutputSocket(), translateOperation->getInputSocket(0));
112 
113  converter.addLink(translateOperation->getOutputSocket(), psoperation->getInputSocket(0));
114  }
115 }
116 
117 } // namespace blender::compositor
@ CMP_NODEFLAG_STABILIZE_INVERSE
Overall context of the compositor.
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void addLink(NodeOperationOutput *from, NodeOperationInput *to)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
NodeOperationInput * getInputSocket(unsigned int index)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
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
NodeInput * getInputSocket(const unsigned int index) const
Definition: COM_Node.cc:113
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
short custom1
struct ID * id
short custom2
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: svm_invert.h:19