Blender V4.3
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
10#include "DNA_scene_types.h"
11
12#include "BLI_utildefines.h"
13
14#include "BKE_movieclip.h"
15#include "BKE_tracking.h"
16
17#include "ED_clip.hh"
18#include "ED_screen.hh"
19
20#include "GPU_immediate.hh"
21#include "GPU_immediate_util.hh"
22#include "GPU_matrix.hh"
23#include "GPU_state.hh"
24
25#include "WM_types.hh"
26
27#include "UI_resources.hh"
28#include "UI_view2d.hh"
29
30#include "clip_intern.hh" /* own include */
31
39
40static void tracking_segment_point_cb(void *userdata,
41 MovieTrackingTrack * /*track*/,
42 MovieTrackingMarker * /*marker*/,
43 eClipCurveValueSource value_source,
44 int scene_framenr,
45 float val)
46{
48
49 if (!clip_graph_value_visible(data->sc, value_source)) {
50 return;
51 }
52
53 immVertex2f(data->pos, scene_framenr, val);
54}
55
56static void tracking_segment_start_cb(void *userdata,
57 MovieTrackingTrack *track,
58 eClipCurveValueSource value_source,
59 bool is_point)
60{
62 SpaceClip *sc = data->sc;
63 float col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
64
65 if (!clip_graph_value_visible(sc, value_source)) {
66 return;
67 }
68
69 switch (value_source) {
71 col[0] = 1.0f;
72 break;
74 col[1] = 1.0f;
75 break;
77 col[2] = 1.0f;
78 break;
79 }
80
81 if (track == data->act_track) {
82 col[3] = 1.0f;
83 GPU_line_width(2.0f);
84 }
85 else {
86 col[3] = 0.5f;
87 GPU_line_width(1.0f);
88 }
89
91
92 if (is_point) {
94 }
95 else {
96 /* Graph can be composed of smaller segments, if any marker is disabled */
98 }
99}
100
101static void tracking_segment_end_cb(void *userdata, eClipCurveValueSource value_source)
102{
104 SpaceClip *sc = data->sc;
105 if (!clip_graph_value_visible(sc, value_source)) {
106 return;
107 }
108 immEnd();
109}
110
111static void tracking_segment_knot_cb(void *userdata,
112 MovieTrackingTrack *track,
113 MovieTrackingMarker *marker,
114 eClipCurveValueSource value_source,
115 int scene_framenr,
116 float val)
117{
119
120 if (track != data->act_track) {
121 return;
122 }
124 return;
125 }
126
127 const int sel_flag = value_source == CLIP_VALUE_SOURCE_SPEED_X ? MARKER_GRAPH_SEL_X :
129 const bool sel = (marker->flag & sel_flag) != 0;
130
131 if (sel == data->sel) {
133
135 GPU_matrix_translate_2f(scene_framenr, val);
136 GPU_matrix_scale_2f(1.0f / data->xscale * data->hsize, 1.0f / data->yscale * data->hsize);
137
138 imm_draw_circle_wire_2d(data->pos, 0, 0, 0.7, 8);
139
141 }
142}
143
145{
147 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
148 MovieTrackingTrack *active_track = tracking_object->active_track;
149 const bool draw_knots = (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) != 0;
150
151 int width, height;
152 BKE_movieclip_get_size(clip, &sc->user, &width, &height);
153 if (!width || !height) {
154 return;
155 }
156
158 userdata.sc = sc;
160 userdata.sel = false;
161 userdata.act_track = active_track;
162 userdata.pos = pos;
163
164 /* Non-selected knot handles. */
165 if (draw_knots) {
166 UI_view2d_scale_get(v2d, &userdata.xscale, &userdata.yscale);
168 (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
169 (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
170 &userdata,
172 nullptr,
173 nullptr);
174 }
175
176 /* Draw graph lines. */
179 (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
180 (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
181 &userdata,
186
187 /* Selected knot handles on top of curves. */
188 if (draw_knots) {
189 userdata.sel = true;
191 (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
192 (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
193 &userdata,
195 nullptr,
196 nullptr);
197 }
198}
199
201{
203 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
205
206 int previous_frame;
207 float previous_error;
208 bool have_previous_point = false;
209
210 /* Indicates whether immBegin() was called. */
211 bool is_lines_segment_open = false;
212
213 immUniformColor3f(0.0f, 0.0f, 1.0f);
214
215 for (int i = 0; i < reconstruction->camnr; i++) {
216 MovieReconstructedCamera *camera = &reconstruction->cameras[i];
217
218 const int current_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, camera->framenr);
219 const float current_error = camera->error;
220
221 if (have_previous_point && current_frame != previous_frame + 1) {
222 if (is_lines_segment_open) {
223 immEnd();
224 is_lines_segment_open = false;
225 }
226 have_previous_point = false;
227 }
228
229 if (have_previous_point) {
230 if (!is_lines_segment_open) {
232 is_lines_segment_open = true;
233
234 immVertex2f(pos, previous_frame, previous_error);
235 }
236 immVertex2f(pos, current_frame, current_error);
237 }
238
239 previous_frame = current_frame;
240 previous_error = current_error;
241 have_previous_point = true;
242 }
243
244 if (is_lines_segment_open) {
245 immEnd();
246 }
247}
248
249void clip_draw_graph(SpaceClip *sc, ARegion *region, Scene *scene)
250{
252 View2D *v2d = &region->v2d;
253
254 /* grid */
257
258 if (clip) {
261
262 GPU_point_size(3.0f);
263
266 }
267
268 if (sc->flag & SC_SHOW_GRAPH_FRAMES) {
270 }
271
273 }
274
275 /* frame range */
276 clip_draw_sfra_efra(v2d, scene);
277}
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 immVertex2f(uint attr_id, float x, float y)
void immUniformThemeColor(int color_id)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
GPUVertFormat * immVertexFormat()
void immUniformColor4fv(const float rgba[4])
void immUniformColor3f(float r, float g, float b)
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_BLEND_NONE
Definition GPU_state.hh:85
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:87
void GPU_blend(eGPUBlend blend)
Definition gpu_state.cc:42
void GPU_line_width(float width)
Definition gpu_state.cc:161
void GPU_point_size(float size)
Definition gpu_state.cc:167
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
@ TH_HANDLE_VERTEX_SIZE
@ TH_HANDLE_VERTEX_SELECT
@ TH_HANDLE_VERTEX
float UI_GetThemeValuef(int colorid)
void UI_view2d_draw_lines_x__values(const View2D *v2d)
void UI_view2d_draw_lines_y__values(const View2D *v2d)
void UI_view2d_scale_get(const View2D *v2d, float *r_x, float *r_y)
Definition view2d.cc:1907
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:41
void clip_draw_sfra_efra(View2D *v2d, Scene *scene)
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 col
const ProjectiveReconstruction & reconstruction
Definition intersect.cc:198
MovieTrackingReconstruction reconstruction
MovieTrackingTrack * active_track
struct MovieClipUser user
MovieTrackingTrack * act_track