Blender V4.3
node_composite_translate.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_math_matrix.hh"
10
11#include "UI_interface.hh"
12#include "UI_resources.hh"
13
15#include "COM_node_operation.hh"
16
18
19/* **************** Translate ******************** */
20
22
24
26{
27 b.add_input<decl::Color>("Image")
28 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
29 .compositor_domain_priority(0);
30 b.add_input<decl::Float>("X")
31 .default_value(0.0f)
32 .min(-10000.0f)
33 .max(10000.0f)
35 b.add_input<decl::Float>("Y")
36 .default_value(0.0f)
37 .min(-10000.0f)
38 .max(10000.0f)
40 b.add_output<decl::Color>("Image");
41}
42
43static void node_composit_init_translate(bNodeTree * /*ntree*/, bNode *node)
44{
45 NodeTranslateData *data = MEM_cnew<NodeTranslateData>(__func__);
46 node->storage = data;
47}
48
50{
51 uiItemR(layout, ptr, "interpolation", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
52 uiItemR(layout, ptr, "use_relative", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
53 uiItemR(layout, ptr, "wrap_axis", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
54}
55
56using namespace blender::realtime_compositor;
57
59 public:
61
62 void execute() override
63 {
64 Result &input = get_input("Image");
65 Result &result = get_result("Image");
66 input.pass_through(result);
67
68 float x = get_input("X").get_float_value_default(0.0f);
69 float y = get_input("Y").get_float_value_default(0.0f);
70 if (get_use_relative()) {
71 x *= input.domain().size.x;
72 y *= input.domain().size.y;
73 }
74
75 const float2 translation = float2(x, y);
76 const float3x3 transformation = math::from_location<float3x3>(translation);
77
78 RealizationOptions realization_options = input.get_realization_options();
79 realization_options.wrap_x = get_wrap_x();
80 realization_options.wrap_y = get_wrap_y();
81 realization_options.interpolation = get_interpolation();
82
83 transform(context(), input, result, transformation, realization_options);
84 }
85
87 {
88 switch (node_storage(bnode()).interpolation) {
90 return Interpolation::Nearest;
92 return Interpolation::Bilinear;
94 return Interpolation::Bicubic;
95 }
96
98 return Interpolation::Nearest;
99 }
100
102 {
103 return node_storage(bnode()).relative;
104 }
105
107 {
108 return ELEM(node_storage(bnode()).wrap_axis, CMP_NODE_WRAP_X, CMP_NODE_WRAP_XY);
109 }
110
112 {
113 return ELEM(node_storage(bnode()).wrap_axis, CMP_NODE_WRAP_Y, CMP_NODE_WRAP_XY);
114 }
115};
116
118{
119 return new TranslateOperation(context, node);
120}
121
122} // namespace blender::nodes::node_composite_translate_cc
123
125{
127
128 static blender::bke::bNodeType ntype;
129
130 cmp_node_type_base(&ntype, CMP_NODE_TRANSLATE, "Translate", NODE_CLASS_DISTORT);
131 ntype.declare = file_ns::cmp_node_translate_declare;
132 ntype.draw_buttons = file_ns::node_composit_buts_translate;
133 ntype.initfunc = file_ns::node_composit_init_translate;
135 &ntype, "NodeTranslateData", node_free_standard_storage, node_copy_standard_storage);
136 ntype.get_compositor_operation = file_ns::get_compositor_operation;
137
139}
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:412
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
#define ELEM(...)
@ CMP_NODE_INTERPOLATION_NEAREST
@ CMP_NODE_INTERPOLATION_BILINEAR
@ CMP_NODE_INTERPOLATION_BICUBIC
@ CMP_NODE_WRAP_X
@ CMP_NODE_WRAP_Y
@ CMP_NODE_WRAP_XY
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
NodeOperation(Context &context, DNode node)
Result & get_input(StringRef identifier) const
Definition operation.cc:144
Result & get_result(StringRef identifier)
Definition operation.cc:46
float get_float_value_default(float default_value) const
Definition result.cc:413
local_group_size(16, 16) .push_constant(Type b
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
MatT from_location(const typename MatT::loc_type &location)
static void node_composit_init_translate(bNodeTree *, bNode *node)
static void node_composit_buts_translate(uiLayout *layout, bContext *, PointerRNA *ptr)
static void cmp_node_translate_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
void transform(Context &context, Result &input, Result &output, const float3x3 &transformation, RealizationOptions realization_options)
VecBase< float, 2 > float2
void register_node_type_cmp_translate()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126