Blender V5.0
node_composite_rotate.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
8
10#include "BLI_math_matrix.hh"
11
12#include "DNA_node_types.h"
13
14#include "RNA_enum_types.hh"
15
16#include "BKE_node.hh"
17
18#include "COM_domain.hh"
19#include "COM_node_operation.hh"
20
22
24
26{
27 b.use_custom_socket_order();
28 b.allow_any_socket_order();
29
30 b.add_input<decl::Color>("Image")
31 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
32 .hide_value()
34 .structure_type(StructureType::Dynamic);
35 b.add_output<decl::Color>("Image").structure_type(StructureType::Dynamic).align_with_previous();
36
37 b.add_input<decl::Float>("Angle").default_value(0.0f).min(-10000.0f).max(10000.0f).subtype(
39
40 PanelDeclarationBuilder &sampling_panel = b.add_panel("Sampling").default_closed(true);
41 sampling_panel.add_input<decl::Menu>("Interpolation")
45 .description("Interpolation method");
46 sampling_panel.add_input<decl::Menu>("Extension X")
47 .default_value(CMP_NODE_EXTENSION_MODE_CLIP)
50 .description("The extension mode applied to the X axis");
51 sampling_panel.add_input<decl::Menu>("Extension Y")
52 .default_value(CMP_NODE_EXTENSION_MODE_CLIP)
55 .description("The extension mode applied to the Y axis");
56}
57
58static void node_composit_init_rotate(bNodeTree * /*ntree*/, bNode *node)
59{
60 /* Unused, kept for forward compatibility. */
62 node->storage = data;
63}
64
65using namespace blender::compositor;
66
68 public:
70
71 void execute() override
72 {
73 const math::AngleRadian rotation = this->get_input("Angle").get_single_value_default(0.0f);
74 const float3x3 transformation = math::from_rotation<float3x3>(rotation);
75
76 const Result &input = this->get_input("Image");
77 Result &output = this->get_result("Image");
78 output.share_data(input);
79 output.transform(transformation);
80 output.get_realization_options().interpolation = this->get_interpolation();
83 }
84
86 {
87 const Result &input = this->get_input("Interpolation");
88 const MenuValue default_menu_value = MenuValue(CMP_NODE_INTERPOLATION_BILINEAR);
89 const MenuValue menu_value = input.get_single_value_default(default_menu_value);
90 const CMPNodeInterpolation interpolation = static_cast<CMPNodeInterpolation>(menu_value.value);
91 switch (interpolation) {
99 }
100
102 }
103
105 {
106 const Result &input = this->get_input("Extension X");
107 const MenuValue default_menu_value = MenuValue(CMP_NODE_EXTENSION_MODE_CLIP);
108 const MenuValue menu_value = input.get_single_value_default(default_menu_value);
109 const CMPExtensionMode extension_x = static_cast<CMPExtensionMode>(menu_value.value);
110 switch (extension_x) {
112 return ExtensionMode::Clip;
117 }
118
119 return ExtensionMode::Clip;
120 }
121
123 {
124 const Result &input = this->get_input("Extension Y");
125 const MenuValue default_menu_value = MenuValue(CMP_NODE_EXTENSION_MODE_CLIP);
126 const MenuValue menu_value = input.get_single_value_default(default_menu_value);
127 const CMPExtensionMode extension_y = static_cast<CMPExtensionMode>(menu_value.value);
128 switch (extension_y) {
130 return ExtensionMode::Clip;
135 }
136
137 return ExtensionMode::Clip;
138 }
139};
140
142{
143 return new RotateOperation(context, node);
144}
145
146} // namespace blender::nodes::node_composite_rotate_cc
147
149{
151
152 static blender::bke::bNodeType ntype;
153
154 cmp_node_type_base(&ntype, "CompositorNodeRotate", CMP_NODE_ROTATE);
155 ntype.ui_name = "Rotate";
156 ntype.ui_description = "Rotate image by specified angle";
157 ntype.enum_name_legacy = "ROTATE";
159 ntype.declare = file_ns::cmp_node_rotate_declare;
160 ntype.initfunc = file_ns::node_composit_init_rotate;
161 ntype.get_compositor_operation = file_ns::get_compositor_operation;
164
166}
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:455
#define CMP_NODE_ROTATE
CMPNodeInterpolation
@ CMP_NODE_INTERPOLATION_NEAREST
@ CMP_NODE_INTERPOLATION_BILINEAR
@ CMP_NODE_INTERPOLATION_BICUBIC
@ CMP_NODE_INTERPOLATION_ANISOTROPIC
CMPExtensionMode
@ CMP_NODE_EXTENSION_MODE_EXTEND
@ CMP_NODE_EXTENSION_MODE_CLIP
@ CMP_NODE_EXTENSION_MODE_REPEAT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_ANGLE
Definition RNA_types.hh:252
BMesh const char void * data
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Definition operation.cc:39
Result & get_input(StringRef identifier) const
Definition operation.cc:138
void share_data(const Result &source)
Definition result.cc:523
RealizationOptions & get_realization_options()
Definition result.cc:630
T get_single_value_default(const T &default_value) const
DeclType::Builder & add_input(StringRef name, StringRef identifier="")
const CompositorInputRealizationMode & compositor_realization_mode() const
#define input
#define output
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:5414
AngleRadianBase< float > AngleRadian
MatT from_rotation(const RotationT &rotation)
static void cmp_node_rotate_declare(NodeDeclarationBuilder &b)
static void node_composit_init_rotate(bNodeTree *, bNode *node)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
MatBase< float, 3, 3 > float3x3
static void register_node_type_cmp_rotate()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
const EnumPropertyItem rna_enum_node_compositor_extension_items[]
const EnumPropertyItem rna_enum_node_compositor_interpolation_items[]
void * storage
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:348
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362