Blender V5.0
clip_graph_draw.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
10#include "DNA_scene_types.h"
11#include "DNA_screen_types.h"
12
13#include "BLI_utildefines.h"
14
15#include "BKE_movieclip.h"
16#include "BKE_tracking.h"
17
18#include "ED_anim_api.hh"
19#include "ED_clip.hh"
20
21#include "GPU_immediate.hh"
22#include "GPU_immediate_util.hh"
23#include "GPU_matrix.hh"
24#include "GPU_state.hh"
25
26#include "UI_resources.hh"
27#include "UI_view2d.hh"
28
29#include "clip_intern.hh" /* own include */
30
38
39static void tracking_segment_point_cb(void *userdata,
40 MovieTrackingTrack * /*track*/,
41 MovieTrackingMarker * /*marker*/,
42 eClipCurveValueSource value_source,
43 int scene_framenr,
44 float val)
45{
47
48 if (!clip_graph_value_visible(data->sc, value_source)) {
49 return;
50 }
51
52 immVertex2f(data->pos, scene_framenr, val);
53}
54
55static void tracking_segment_start_cb(void *userdata,
56 MovieTrackingTrack *track,
57 eClipCurveValueSource value_source,
58 bool is_point)
59{
61 SpaceClip *sc = data->sc;
62 float col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
63
64 if (!clip_graph_value_visible(sc, value_source)) {
65 return;
66 }
67
68 switch (value_source) {
71 break;
74 break;
77 break;
78 }
79
80 if (track == data->act_track) {
81 col[3] = 1.0f;
82 GPU_line_width(2.0f);
83 }
84 else {
85 col[3] = 0.5f;
86 GPU_line_width(1.0f);
87 }
88
89 if (is_point) {
91 immUniform1f("size", 3.0f);
92 }
93 else {
95 }
97
98 if (is_point) {
100 }
101 else {
102 /* Graph can be composed of smaller segments, if any marker is disabled */
104 }
105}
106
107static void tracking_segment_end_cb(void *userdata, eClipCurveValueSource value_source)
108{
110 SpaceClip *sc = data->sc;
111 if (!clip_graph_value_visible(sc, value_source)) {
112 return;
113 }
114 immEnd();
116}
117
118static void tracking_segment_knot_cb(void *userdata,
119 MovieTrackingTrack *track,
120 MovieTrackingMarker *marker,
121 eClipCurveValueSource value_source,
122 int scene_framenr,
123 float val)
124{
126
127 if (track != data->act_track) {
128 return;
129 }
131 return;
132 }
133
134 const int sel_flag = value_source == CLIP_VALUE_SOURCE_SPEED_X ? MARKER_GRAPH_SEL_X :
136 const bool sel = (marker->flag & sel_flag) != 0;
137
138 if (sel == data->sel) {
139 GPU_line_width(1.0f);
142
144 GPU_matrix_translate_2f(scene_framenr, val);
145 GPU_matrix_scale_2f(1.0f / data->xscale * data->hsize, 1.0f / data->yscale * data->hsize);
146
147 imm_draw_circle_wire_2d(data->pos, 0, 0, 0.7, 8);
148
151 }
152}
153
155{
157 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
158 MovieTrackingTrack *active_track = tracking_object->active_track;
159 const bool draw_knots = (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) != 0;
160
161 int width, height;
162 BKE_movieclip_get_size(clip, &sc->user, &width, &height);
163 if (!width || !height) {
164 return;
165 }
166
168 userdata.sc = sc;
170 userdata.sel = false;
171 userdata.act_track = active_track;
172 userdata.pos = pos;
173
174 /* Non-selected knot handles. */
175 if (draw_knots) {
176 UI_view2d_scale_get(v2d, &userdata.xscale, &userdata.yscale);
178 (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
179 (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
180 &userdata,
182 nullptr,
183 nullptr);
184 }
185
186 /* Draw graph lines. */
189 (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
190 (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
191 &userdata,
196
197 /* Selected knot handles on top of curves. */
198 if (draw_knots) {
199 userdata.sel = true;
201 (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
202 (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
203 &userdata,
205 nullptr,
206 nullptr);
207 }
208}
209
211{
213 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
214 const MovieTrackingReconstruction *reconstruction = &tracking_object->reconstruction;
215
216 int previous_frame;
217 float previous_error;
218 bool have_previous_point = false;
219
220 /* Indicates whether immBegin() was called. */
221 bool is_lines_segment_open = false;
222
223 GPU_line_width(1.0f);
225 immUniformColor4f(0.0f, 0.0f, 1.0f, 1.0f);
226
227 for (int i = 0; i < reconstruction->camnr; i++) {
228 MovieReconstructedCamera *camera = &reconstruction->cameras[i];
229
230 const int current_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, camera->framenr);
231 const float current_error = camera->error;
232
233 if (have_previous_point && current_frame != previous_frame + 1) {
234 if (is_lines_segment_open) {
235 immEnd();
236 is_lines_segment_open = false;
237 }
238 have_previous_point = false;
239 }
240
241 if (have_previous_point) {
242 if (!is_lines_segment_open) {
243 immBeginAtMost(GPU_PRIM_LINE_STRIP, reconstruction->camnr);
244 is_lines_segment_open = true;
245
246 immVertex2f(pos, previous_frame, previous_error);
247 }
248 immVertex2f(pos, current_frame, current_error);
249 }
250
251 previous_frame = current_frame;
252 previous_error = current_error;
253 have_previous_point = true;
254 }
255
256 if (is_lines_segment_open) {
257 immEnd();
258 }
260}
261
262void clip_draw_graph(SpaceClip *sc, ARegion *region, Scene *scene)
263{
265 View2D *v2d = &region->v2d;
266
267 /* grid */
270
271 if (clip) {
273 immVertexFormat(), "pos", blender::gpu::VertAttrType::SFLOAT_32_32);
274
277 }
278
279 if (sc->flag & SC_SHOW_GRAPH_FRAMES) {
281 }
282 }
283
284 /* Frame and preview range. */
286 ANIM_draw_framerange(scene, v2d);
287 ANIM_draw_previewrange(scene, v2d, 0);
288}
void BKE_movieclip_get_size(struct MovieClip *clip, const struct MovieClipUser *user, int *r_width, int *r_height)
float BKE_movieclip_remap_clip_to_scene_frame(const struct MovieClip *clip, float framenr)
struct MovieTrackingObject * BKE_tracking_object_get_active(const struct MovieTracking *tracking)
unsigned int uint
#define ELEM(...)
@ SC_SHOW_GRAPH_HIDDEN
@ SC_SHOW_GRAPH_FRAMES
@ SC_SHOW_GRAPH_SEL_ONLY
@ SC_SHOW_GRAPH_TRACKS_MOTION
@ SC_SHOW_GRAPH_TRACKS_ERROR
@ MARKER_GRAPH_SEL_X
@ MARKER_GRAPH_SEL_Y
MovieClip * ED_space_clip_get_clip(const SpaceClip *sc)
void immEnd()
void immUnbindProgram()
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
void immUniformColor4f(float r, float g, float b, float a)
void immVertex2f(uint attr_id, float x, float y)
void immUniformThemeColor(int color_id)
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
void immUniform1f(const char *name, float x)
GPUVertFormat * immVertexFormat()
void immUniformColor4fv(const float rgba[4])
void imm_draw_circle_wire_2d(uint shdr_pos, float x, float y, float radius, int nsegments)
void GPU_matrix_scale_2f(float x, float y)
void GPU_matrix_push()
void GPU_matrix_pop()
void GPU_matrix_translate_2f(float x, float y)
@ GPU_PRIM_POINTS
@ GPU_PRIM_LINE_STRIP
@ GPU_SHADER_3D_UNIFORM_COLOR
@ GPU_SHADER_3D_POINT_UNIFORM_COLOR
void GPU_line_width(float width)
Definition gpu_state.cc:166
@ GPU_BLEND_NONE
Definition GPU_state.hh:85
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:87
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:42
uint GPU_vertformat_attr_add(GPUVertFormat *format, blender::StringRef name, blender::gpu::VertAttrType type)
@ TH_HANDLE_VERTEX_SIZE
@ TH_HANDLE_VERTEX_SELECT
@ TH_HANDLE_VERTEX
@ TH_AXIS_Y
@ TH_AXIS_X
@ TH_AXIS_Z
void UI_GetThemeColor4fv(int colorid, float col[4])
float UI_GetThemeValuef(int colorid)
void UI_view2d_draw_lines_y__values(const View2D *v2d, int base)
void UI_view2d_draw_lines_x__values(const View2D *v2d, int base)
void UI_view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1095
void UI_view2d_scale_get(const View2D *v2d, float *r_x, float *r_y)
Definition view2d.cc:1912
void ANIM_draw_previewrange(const Scene *scene, View2D *v2d, int end_frame_width)
Definition anim_draw.cc:82
void ANIM_draw_framerange(Scene *scene, View2D *v2d)
Definition anim_draw.cc:171
BMesh const char void * data
static void draw_frame_curves(SpaceClip *sc, uint pos)
static void draw_tracks_motion_and_error_curves(View2D *v2d, SpaceClip *sc, uint pos)
static void tracking_segment_end_cb(void *userdata, eClipCurveValueSource value_source)
static void tracking_segment_point_cb(void *userdata, MovieTrackingTrack *, MovieTrackingMarker *, eClipCurveValueSource value_source, int scene_framenr, float val)
static void tracking_segment_start_cb(void *userdata, MovieTrackingTrack *track, eClipCurveValueSource value_source, bool is_point)
static void tracking_segment_knot_cb(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker, eClipCurveValueSource value_source, int scene_framenr, float val)
void clip_draw_graph(SpaceClip *sc, ARegion *region, Scene *scene)
bool clip_graph_value_visible(SpaceClip *sc, eClipCurveValueSource value_source)
Definition clip_utils.cc:40
void clip_graph_tracking_values_iterate(SpaceClip *sc, bool selected_only, bool include_hidden, void *userdata, ClipTrackValueCallback func, ClipTrackValueSegmentStartCallback segment_start, ClipTrackValueSegmentEndCallback segment_end)
eClipCurveValueSource
@ CLIP_VALUE_SOURCE_REPROJECTION_ERROR
@ CLIP_VALUE_SOURCE_SPEED_Y
@ CLIP_VALUE_SOURCE_SPEED_X
uint pos
uint col
struct MovieTracking tracking
MovieTrackingReconstruction reconstruction
MovieTrackingTrack * active_track
struct MovieReconstructedCamera * cameras
struct MovieClipUser user
MovieTrackingTrack * act_track
i
Definition text_draw.cc:230