Blender V4.3
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
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 "GPU_texture.hh"
23
24#include "RNA_access.hh"
25#include "RNA_prototypes.hh"
26
27#include "UI_interface.hh"
28#include "UI_resources.hh"
29
30#include "COM_keying_screen.hh"
31#include "COM_node_operation.hh"
32
34
35/* **************** Keying Screen ******************** */
36
38
40
42{
43 b.add_output<decl::Color>("Screen").translation_context(BLT_I18NCONTEXT_ID_SCREEN);
44}
45
47{
48 bNode *node = (bNode *)ptr->data;
49
50 NodeKeyingScreenData *data = MEM_cnew<NodeKeyingScreenData>(__func__);
51 data->smoothness = 0.0f;
52 node->storage = data;
53
54 const Scene *scene = CTX_data_scene(C);
55 if (scene->clip) {
56 MovieClip *clip = scene->clip;
57
58 node->id = &clip->id;
59 id_us_plus(&clip->id);
60
61 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
62 STRNCPY(data->tracking_object, tracking_object->name);
63 }
64}
65
67{
68 bNode *node = (bNode *)ptr->data;
69
70 uiTemplateID(layout, C, ptr, "clip", nullptr, nullptr, nullptr);
71
72 if (node->id) {
73 MovieClip *clip = (MovieClip *)node->id;
75 PointerRNA tracking_ptr = RNA_pointer_create(&clip->id, &RNA_MovieTracking, &clip->tracking);
76
77 col = uiLayoutColumn(layout, true);
78 uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA);
79 }
80
81 uiItemR(layout, ptr, "smoothness", UI_ITEM_NONE, nullptr, ICON_NONE);
82}
83
84using namespace blender::realtime_compositor;
85
87 public:
89
90 void execute() override
91 {
92 Result &keying_screen = get_result("Screen");
93 MovieTrackingObject *movie_tracking_object = get_movie_tracking_object();
94 if (!movie_tracking_object) {
95 keying_screen.allocate_invalid();
96 return;
97 }
98
99 KeyingScreen &cached_keying_screen = context().cache_manager().keying_screens.get(
100 context(), get_movie_clip(), movie_tracking_object, get_smoothness());
101
102 keying_screen.wrap_external(cached_keying_screen.texture());
103 }
104
106 {
107 return Domain(get_size());
108 }
109
111 {
112 MovieClip *movie_clip = get_movie_clip();
113 if (!movie_clip) {
114 return nullptr;
115 }
116
117 MovieTracking *movie_tracking = &movie_clip->tracking;
118
119 MovieTrackingObject *movie_tracking_object = BKE_tracking_object_get_named(
120 movie_tracking, node_storage(bnode()).tracking_object);
121 if (movie_tracking_object) {
122 return movie_tracking_object;
123 }
124
125 return BKE_tracking_object_get_active(movie_tracking);
126 }
127
129 {
131 const int scene_frame = context().get_frame_number();
132 const int clip_frame = BKE_movieclip_remap_scene_to_clip_frame(get_movie_clip(), scene_frame);
133 BKE_movieclip_user_set_frame(&movie_clip_user, clip_frame);
134
135 int2 size;
136 BKE_movieclip_get_size(get_movie_clip(), &movie_clip_user, &size.x, &size.y);
137 return size;
138 }
139
140 /* The reciprocal of the smoothness is used as a shaping parameter for the radial basis function
141 * used in the RBF interpolation. The exponential nature of the function can cause numerical
142 * instability for low smoothness values, so we empirically choose 0.15 as a lower limit. */
144 {
145 return math::interpolate(0.15f, 1.0f, node_storage(bnode()).smoothness);
146 }
147
149 {
150 return reinterpret_cast<MovieClip *>(bnode().id);
151 }
152};
153
155{
156 return new KeyingScreenOperation(context, node);
157}
158
159} // namespace blender::nodes::node_composite_keyingscreen_cc
160
162{
164
165 static blender::bke::bNodeType ntype;
166
167 cmp_node_type_base(&ntype, CMP_NODE_KEYINGSCREEN, "Keying Screen", NODE_CLASS_MATTE);
168 ntype.declare = file_ns::cmp_node_keyingscreen_declare;
169 ntype.draw_buttons = file_ns::node_composit_buts_keyingscreen;
170 ntype.initfunc_api = file_ns::node_composit_init_keyingscreen;
172 &ntype, "NodeKeyingScreenData", node_free_standard_storage, node_copy_standard_storage);
173 ntype.get_compositor_operation = file_ns::get_compositor_operation;
174
176}
Scene * CTX_data_scene(const bContext *C)
void id_us_plus(ID *id)
Definition lib_id.cc:351
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:411
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
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(dst, src)
Definition BLI_string.h:593
#define BLT_I18NCONTEXT_ID_SCREEN
#define DNA_struct_default_get(struct_name)
#define UI_ITEM_NONE
void uiItemPointerR(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *searchptr, const char *searchpropname, const char *name, int icon)
void uiTemplateID(uiLayout *layout, const bContext *C, PointerRNA *ptr, const char *propname, const char *newop, const char *openop, const char *unlinkop, int filter=UI_TEMPLATE_ID_FILTER_ALL, bool live_icon=false, const char *text=nullptr)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
KeyingScreen & 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:46
void wrap_external(GPUTexture *texture)
Definition result.cc:321
local_group_size(16, 16) .push_constant(Type b
uint col
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
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)
void register_node_type_cmp_keyingscreen()
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
PointerRNA RNA_pointer_create(ID *id, StructRNA *type, void *data)
struct MovieTracking tracking
void * data
Definition RNA_types.hh:42
struct ID * id
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
void(* initfunc_api)(const bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:280
PointerRNA * ptr
Definition wm_files.cc:4126