Blender V5.0
node_composite_keyingscreen.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_math_base.hh"
11#include "BLI_string_utf8.h"
12
13#include "DNA_defaults.h"
14#include "DNA_movieclip_types.h"
15#include "DNA_tracking_types.h"
16
17#include "BKE_context.hh"
18#include "BKE_lib_id.hh"
19#include "BKE_movieclip.h"
20#include "BKE_tracking.h"
21
22#include "RNA_access.hh"
23#include "RNA_prototypes.hh"
24
25#include "UI_interface_c.hh"
27#include "UI_resources.hh"
28
29#include "COM_keying_screen.hh"
30#include "COM_node_operation.hh"
31
33
34/* **************** Keying Screen ******************** */
35
37
39
41{
42 b.add_input<decl::Float>("Smoothness")
43 .default_value(0.0f)
44 .subtype(PROP_FACTOR)
45 .min(0.0f)
46 .max(1.0f)
47 .description("Specifies the smoothness of the keying screen");
48
49 b.add_output<decl::Color>("Screen")
51 .structure_type(StructureType::Dynamic);
52}
53
55{
56 bNode *node = (bNode *)ptr->data;
57
59 node->storage = data;
60
61 const Scene *scene = CTX_data_scene(C);
62 if (scene->clip) {
63 MovieClip *clip = scene->clip;
64
65 node->id = &clip->id;
66 id_us_plus(&clip->id);
67
68 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
69 STRNCPY_UTF8(data->tracking_object, tracking_object->name);
70 }
71}
72
74{
75 bNode *node = (bNode *)ptr->data;
76
77 uiTemplateID(layout, C, ptr, "clip", nullptr, nullptr, nullptr);
78
79 if (node->id) {
80 MovieClip *clip = (MovieClip *)node->id;
83 &clip->id, &RNA_MovieTracking, &clip->tracking);
84
85 col = &layout->column(true);
86 col->prop_search(ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA);
87 }
88}
89
90using namespace blender::compositor;
91
93 public:
95
96 void execute() override
97 {
98 Result &keying_screen = get_result("Screen");
99 MovieTrackingObject *movie_tracking_object = get_movie_tracking_object();
100 if (!movie_tracking_object) {
101 keying_screen.allocate_invalid();
102 return;
103 }
104
105 Result &cached_keying_screen = context().cache_manager().keying_screens.get(
106 context(), get_movie_clip(), movie_tracking_object, get_smoothness());
107
108 if (!cached_keying_screen.is_allocated()) {
109 keying_screen.allocate_invalid();
110 return;
111 }
112
113 keying_screen.wrap_external(cached_keying_screen);
114 }
115
117 {
118 return Domain(get_size());
119 }
120
122 {
123 MovieClip *movie_clip = get_movie_clip();
124 if (!movie_clip) {
125 return nullptr;
126 }
127
128 MovieTracking *movie_tracking = &movie_clip->tracking;
129
130 MovieTrackingObject *movie_tracking_object = BKE_tracking_object_get_named(
131 movie_tracking, node_storage(bnode()).tracking_object);
132 if (movie_tracking_object) {
133 return movie_tracking_object;
134 }
135
136 return BKE_tracking_object_get_active(movie_tracking);
137 }
138
140 {
142 const int scene_frame = context().get_frame_number();
143 const int clip_frame = BKE_movieclip_remap_scene_to_clip_frame(get_movie_clip(), scene_frame);
144 BKE_movieclip_user_set_frame(&movie_clip_user, clip_frame);
145
146 int2 size;
147 BKE_movieclip_get_size(get_movie_clip(), &movie_clip_user, &size.x, &size.y);
148 return size;
149 }
150
151 /* The reciprocal of the smoothness is used as a shaping parameter for the radial basis function
152 * used in the RBF interpolation. The exponential nature of the function can cause numerical
153 * instability for low smoothness values, so we empirically choose 0.15 as a lower limit. */
155 {
156 return math::interpolate(
157 0.15f,
158 1.0f,
159 math::clamp(this->get_input("Smoothness").get_single_value_default(0.0f), 0.0f, 1.0f));
160 }
161
163 {
164 return reinterpret_cast<MovieClip *>(bnode().id);
165 }
166};
167
169{
170 return new KeyingScreenOperation(context, node);
171}
172
173} // namespace blender::nodes::node_composite_keyingscreen_cc
174
176{
178
179 static blender::bke::bNodeType ntype;
180
181 cmp_node_type_base(&ntype, "CompositorNodeKeyingScreen", CMP_NODE_KEYINGSCREEN);
182 ntype.ui_name = "Keying Screen";
183 ntype.ui_description = "Create plates for use as a color reference for keying nodes";
184 ntype.enum_name_legacy = "KEYINGSCREEN";
185 ntype.nclass = NODE_CLASS_MATTE;
186 ntype.declare = file_ns::cmp_node_keyingscreen_declare;
187 ntype.draw_buttons = file_ns::node_composit_buts_keyingscreen;
188 ntype.initfunc_api = file_ns::node_composit_init_keyingscreen;
190 ntype, "NodeKeyingScreenData", node_free_standard_storage, node_copy_standard_storage);
191 ntype.get_compositor_operation = file_ns::get_compositor_operation;
192
194}
Scene * CTX_data_scene(const bContext *C)
void id_us_plus(ID *id)
Definition lib_id.cc:358
float BKE_movieclip_remap_scene_to_clip_frame(const struct MovieClip *clip, float framenr)
void BKE_movieclip_user_set_frame(struct MovieClipUser *user, int framenr)
void BKE_movieclip_get_size(struct MovieClip *clip, const struct MovieClipUser *user, int *r_width, int *r_height)
#define NODE_CLASS_MATTE
Definition BKE_node.hh:454
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1240
#define CMP_NODE_KEYINGSCREEN
struct MovieTrackingObject * BKE_tracking_object_get_named(struct MovieTracking *tracking, const char *name)
Definition tracking.cc:1966
struct MovieTrackingObject * BKE_tracking_object_get_active(const struct MovieTracking *tracking)
#define STRNCPY_UTF8(dst, src)
#define BLT_I18NCONTEXT_ID_SCREEN
#define DNA_struct_default_get(struct_name)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_FACTOR
Definition RNA_types.hh:251
#define C
Definition RandGen.cpp:29
void uiTemplateID(uiLayout *layout, const bContext *C, PointerRNA *ptr, blender::StringRefNull propname, const char *newop, const char *openop, const char *unlinkop, int filter=UI_TEMPLATE_ID_FILTER_ALL, bool live_icon=false, std::optional< blender::StringRef > text=std::nullopt)
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
Result & get(Context &context, MovieClip *movie_clip, MovieTrackingObject *movie_tracking_object, float smoothness)
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 wrap_external(blender::gpu::Texture *texture)
Definition result.cc:584
bool is_allocated() const
Definition result.cc:763
std::optional< std::string > translation_context
uint col
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
T clamp(const T &a, const T &min, const T &max)
T interpolate(const T &a, const T &b, const FactorT &t)
static void cmp_node_keyingscreen_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_composit_buts_keyingscreen(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void node_composit_init_keyingscreen(const bContext *C, PointerRNA *ptr)
VecBase< int32_t, 2 > int2
static void register_node_type_cmp_keyingscreen()
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
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
#define min(a, b)
Definition sort.cc:36
struct MovieTracking tracking
struct MovieClip * clip
struct ID * id
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
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
void(* initfunc_api)(const bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:302
uiLayout & column(bool align)
max
Definition text_draw.cc:251
PointerRNA * ptr
Definition wm_files.cc:4238