Blender V4.5
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.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.hh"
26#include "UI_resources.hh"
27
28#include "COM_keying_screen.hh"
29#include "COM_node_operation.hh"
30
32
33/* **************** Keying Screen ******************** */
34
36
38
40{
41 b.add_input<decl::Float>("Smoothness")
42 .default_value(0.0f)
43 .subtype(PROP_FACTOR)
44 .min(0.0f)
45 .max(1.0f)
46 .description("Specifies the smoothness of the keying screen");
47
49}
50
52{
53 bNode *node = (bNode *)ptr->data;
54
56 node->storage = data;
57
58 const Scene *scene = CTX_data_scene(C);
59 if (scene->clip) {
60 MovieClip *clip = scene->clip;
61
62 node->id = &clip->id;
63 id_us_plus(&clip->id);
64
65 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
66 STRNCPY(data->tracking_object, tracking_object->name);
67 }
68}
69
71{
72 bNode *node = (bNode *)ptr->data;
73
74 uiTemplateID(layout, C, ptr, "clip", nullptr, nullptr, nullptr);
75
76 if (node->id) {
77 MovieClip *clip = (MovieClip *)node->id;
80 &clip->id, &RNA_MovieTracking, &clip->tracking);
81
82 col = &layout->column(true);
83 uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA);
84 }
85}
86
87using namespace blender::compositor;
88
90 public:
92
93 void execute() override
94 {
95 Result &keying_screen = get_result("Screen");
96 MovieTrackingObject *movie_tracking_object = get_movie_tracking_object();
97 if (!movie_tracking_object) {
98 keying_screen.allocate_invalid();
99 return;
100 }
101
102 Result &cached_keying_screen = context().cache_manager().keying_screens.get(
103 context(), get_movie_clip(), movie_tracking_object, get_smoothness());
104
105 if (!cached_keying_screen.is_allocated()) {
106 keying_screen.allocate_invalid();
107 return;
108 }
109
110 keying_screen.wrap_external(cached_keying_screen);
111 }
112
114 {
115 return Domain(get_size());
116 }
117
119 {
120 MovieClip *movie_clip = get_movie_clip();
121 if (!movie_clip) {
122 return nullptr;
123 }
124
125 MovieTracking *movie_tracking = &movie_clip->tracking;
126
127 MovieTrackingObject *movie_tracking_object = BKE_tracking_object_get_named(
128 movie_tracking, node_storage(bnode()).tracking_object);
129 if (movie_tracking_object) {
130 return movie_tracking_object;
131 }
132
133 return BKE_tracking_object_get_active(movie_tracking);
134 }
135
137 {
139 const int scene_frame = context().get_frame_number();
140 const int clip_frame = BKE_movieclip_remap_scene_to_clip_frame(get_movie_clip(), scene_frame);
141 BKE_movieclip_user_set_frame(&movie_clip_user, clip_frame);
142
143 int2 size;
144 BKE_movieclip_get_size(get_movie_clip(), &movie_clip_user, &size.x, &size.y);
145 return size;
146 }
147
148 /* The reciprocal of the smoothness is used as a shaping parameter for the radial basis function
149 * used in the RBF interpolation. The exponential nature of the function can cause numerical
150 * instability for low smoothness values, so we empirically choose 0.15 as a lower limit. */
152 {
153 return math::interpolate(
154 0.15f,
155 1.0f,
156 math::clamp(this->get_input("Smoothness").get_single_value_default(0.0f), 0.0f, 1.0f));
157 }
158
160 {
161 return reinterpret_cast<MovieClip *>(bnode().id);
162 }
163};
164
166{
167 return new KeyingScreenOperation(context, node);
168}
169
170} // namespace blender::nodes::node_composite_keyingscreen_cc
171
173{
175
176 static blender::bke::bNodeType ntype;
177
178 cmp_node_type_base(&ntype, "CompositorNodeKeyingScreen", CMP_NODE_KEYINGSCREEN);
179 ntype.ui_name = "Keying Screen";
180 ntype.ui_description = "Create plates for use as a color reference for keying nodes";
181 ntype.enum_name_legacy = "KEYINGSCREEN";
182 ntype.nclass = NODE_CLASS_MATTE;
183 ntype.declare = file_ns::cmp_node_keyingscreen_declare;
184 ntype.draw_buttons = file_ns::node_composit_buts_keyingscreen;
185 ntype.initfunc_api = file_ns::node_composit_init_keyingscreen;
187 ntype, "NodeKeyingScreenData", node_free_standard_storage, node_copy_standard_storage);
188 ntype.get_compositor_operation = file_ns::get_compositor_operation;
189
191}
Scene * CTX_data_scene(const bContext *C)
void id_us_plus(ID *id)
Definition lib_id.cc:353
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:440
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1215
#define CMP_NODE_KEYINGSCREEN
struct MovieTrackingObject * BKE_tracking_object_get_named(struct MovieTracking *tracking, const char *name)
Definition tracking.cc:1965
struct MovieTrackingObject * BKE_tracking_object_get_active(const struct MovieTracking *tracking)
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
#define BLT_I18NCONTEXT_ID_SCREEN
#define DNA_struct_default_get(struct_name)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_FACTOR
Definition RNA_types.hh:239
#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)
void uiItemPointerR(uiLayout *layout, PointerRNA *ptr, blender::StringRefNull propname, PointerRNA *searchptr, blender::StringRefNull searchpropname, std::optional< blender::StringRefNull > name, int icon)
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
bool is_allocated() const
Definition result.cc:627
void wrap_external(GPUTexture *texture)
Definition result.cc:448
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:2748
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:5603
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:226
std::string ui_description
Definition BKE_node.hh:232
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:336
const char * enum_name_legacy
Definition BKE_node.hh:235
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:355
void(* initfunc_api)(const bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
uiLayout & column(bool align)
max
Definition text_draw.cc:251
PointerRNA * ptr
Definition wm_files.cc:4226