Blender  V3.3
clip_graph_draw.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. All rights reserved. */
3 
8 #include "DNA_movieclip_types.h"
9 #include "DNA_scene_types.h"
10 
11 #include "BLI_math.h"
12 #include "BLI_utildefines.h"
13 
14 #include "BKE_context.h"
15 #include "BKE_movieclip.h"
16 #include "BKE_tracking.h"
17 
18 #include "ED_clip.h"
19 #include "ED_screen.h"
20 
21 #include "GPU_immediate.h"
22 #include "GPU_immediate_util.h"
23 #include "GPU_matrix.h"
24 #include "GPU_state.h"
25 
26 #include "WM_types.h"
27 
28 #include "UI_interface.h"
29 #include "UI_resources.h"
30 #include "UI_view2d.h"
31 
32 #include "clip_intern.h" /* own include */
33 
34 typedef struct TrackMotionCurveUserData {
37  bool sel;
38  float xscale, yscale, hsize;
41 
42 static void tracking_segment_point_cb(void *userdata,
43  MovieTrackingTrack *UNUSED(track),
44  MovieTrackingMarker *UNUSED(marker),
45  eClipCurveValueSource value_source,
46  int scene_framenr,
47  float val)
48 {
50 
51  if (!clip_graph_value_visible(data->sc, value_source)) {
52  return;
53  }
54 
55  immVertex2f(data->pos, scene_framenr, val);
56 }
57 
58 static void tracking_segment_start_cb(void *userdata,
59  MovieTrackingTrack *track,
60  eClipCurveValueSource value_source,
61  bool is_point)
62 {
64  SpaceClip *sc = data->sc;
65  float col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
66 
67  if (!clip_graph_value_visible(sc, value_source)) {
68  return;
69  }
70 
71  switch (value_source) {
73  col[0] = 1.0f;
74  break;
76  col[1] = 1.0f;
77  break;
79  col[2] = 1.0f;
80  break;
81  }
82 
83  if (track == data->act_track) {
84  col[3] = 1.0f;
85  GPU_line_width(2.0f);
86  }
87  else {
88  col[3] = 0.5f;
89  GPU_line_width(1.0f);
90  }
91 
93 
94  if (is_point) {
96  }
97  else {
98  /* Graph can be composed of smaller segments, if any marker is disabled */
100  }
101 }
102 
103 static void tracking_segment_end_cb(void *userdata, eClipCurveValueSource value_source)
104 {
106  SpaceClip *sc = data->sc;
107  if (!clip_graph_value_visible(sc, value_source)) {
108  return;
109  }
110  immEnd();
111 }
112 
113 static void tracking_segment_knot_cb(void *userdata,
114  MovieTrackingTrack *track,
115  MovieTrackingMarker *marker,
116  eClipCurveValueSource value_source,
117  int scene_framenr,
118  float val)
119 {
121  int sel = 0, sel_flag;
122 
123  if (track != data->act_track) {
124  return;
125  }
127  return;
128  }
129 
130  sel_flag = value_source == CLIP_VALUE_SOURCE_SPEED_X ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y;
131  sel = (marker->flag & sel_flag) ? 1 : 0;
132 
133  if (sel == data->sel) {
135 
136  GPU_matrix_push();
137  GPU_matrix_translate_2f(scene_framenr, val);
138  GPU_matrix_scale_2f(1.0f / data->xscale * data->hsize, 1.0f / data->yscale * data->hsize);
139 
140  imm_draw_circle_wire_2d(data->pos, 0, 0, 0.7, 8);
141 
142  GPU_matrix_pop();
143  }
144 }
145 
147 {
148  MovieClip *clip = ED_space_clip_get_clip(sc);
149  MovieTracking *tracking = &clip->tracking;
150  MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
151  const bool draw_knots = (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) != 0;
152 
153  int width, height;
154  BKE_movieclip_get_size(clip, &sc->user, &width, &height);
155  if (!width || !height) {
156  return;
157  }
158 
159  TrackMotionCurveUserData userdata;
160  userdata.sc = sc;
162  userdata.sel = false;
163  userdata.act_track = act_track;
164  userdata.pos = pos;
165 
166  /* Non-selected knot handles. */
167  if (draw_knots) {
168  UI_view2d_scale_get(v2d, &userdata.xscale, &userdata.yscale);
170  (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
171  (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
172  &userdata,
174  NULL,
175  NULL);
176  }
177 
178  /* Draw graph lines. */
181  (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
182  (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
183  &userdata,
188 
189  /* Selected knot handles on top of curves. */
190  if (draw_knots) {
191  userdata.sel = true;
193  (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
194  (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
195  &userdata,
197  NULL,
198  NULL);
199  }
200 }
201 
203 {
204  MovieClip *clip = ED_space_clip_get_clip(sc);
205  MovieTracking *tracking = &clip->tracking;
207 
208  int previous_frame;
209  float previous_error;
210  bool have_previous_point = false;
211 
212  /* Indicates whether immBegin() was called. */
213  bool is_lines_segment_open = false;
214 
215  immUniformColor3f(0.0f, 0.0f, 1.0f);
216 
217  for (int i = 0; i < reconstruction->camnr; i++) {
219 
220  const int current_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, camera->framenr);
221  const float current_error = camera->error;
222 
223  if (have_previous_point && current_frame != previous_frame + 1) {
224  if (is_lines_segment_open) {
225  immEnd();
226  is_lines_segment_open = false;
227  }
228  have_previous_point = false;
229  }
230 
231  if (have_previous_point) {
232  if (!is_lines_segment_open) {
234  is_lines_segment_open = true;
235 
236  immVertex2f(pos, previous_frame, previous_error);
237  }
238  immVertex2f(pos, current_frame, current_error);
239  }
240 
241  previous_frame = current_frame;
242  previous_error = current_error;
243  have_previous_point = true;
244  }
245 
246  if (is_lines_segment_open) {
247  immEnd();
248  }
249 }
250 
252 {
253  MovieClip *clip = ED_space_clip_get_clip(sc);
254  View2D *v2d = &region->v2d;
255 
256  /* grid */
259 
260  if (clip) {
263 
264  GPU_point_size(3.0f);
265 
268  }
269 
270  if (sc->flag & SC_SHOW_GRAPH_FRAMES) {
271  draw_frame_curves(sc, pos);
272  }
273 
275  }
276 
277  /* frame range */
279 }
void BKE_movieclip_get_size(struct MovieClip *clip, struct MovieClipUser *user, int *width, int *height)
Definition: movieclip.c:1520
float BKE_movieclip_remap_clip_to_scene_frame(const struct MovieClip *clip, float framenr)
struct MovieTrackingTrack * BKE_tracking_track_get_active(struct MovieTracking *tracking)
Definition: tracking.c:1089
struct MovieTrackingReconstruction * BKE_tracking_get_active_reconstruction(struct MovieTracking *tracking)
Definition: tracking.c:368
unsigned int uint
Definition: BLI_sys_types.h:67
#define UNUSED(x)
#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
struct MovieClip * ED_space_clip_get_clip(struct SpaceClip *sc)
Definition: clip_editor.c:570
void immUnbindProgram(void)
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)
void immUniformColor4fv(const float rgba[4])
GPUVertFormat * immVertexFormat(void)
void immUniformColor3f(float r, float g, float b)
void immEnd(void)
void imm_draw_circle_wire_2d(uint shdr_pos, float x, float y, float radius, int nsegments)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
void GPU_matrix_pop(void)
Definition: gpu_matrix.cc:126
void GPU_matrix_scale_2f(float x, float y)
Definition: gpu_matrix.cc:216
void GPU_matrix_push(void)
Definition: gpu_matrix.cc:119
void GPU_matrix_translate_2f(float x, float y)
Definition: gpu_matrix.cc:174
@ GPU_PRIM_POINTS
Definition: GPU_primitive.h:19
@ GPU_PRIM_LINE_STRIP
Definition: GPU_primitive.h:22
@ GPU_SHADER_2D_UNIFORM_COLOR
Definition: GPU_shader.h:201
@ GPU_BLEND_NONE
Definition: GPU_state.h:60
@ GPU_BLEND_ALPHA
Definition: GPU_state.h:62
void GPU_blend(eGPUBlend blend)
Definition: gpu_state.cc:39
void GPU_line_width(float width)
Definition: gpu_state.cc:158
void GPU_point_size(float size)
Definition: gpu_state.cc:164
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between camera
@ TH_HANDLE_VERTEX_SIZE
Definition: UI_resources.h:206
@ TH_HANDLE_VERTEX_SELECT
Definition: UI_resources.h:205
@ TH_HANDLE_VERTEX
Definition: UI_resources.h:204
float UI_GetThemeValuef(int colorid)
Definition: resources.c:1141
void UI_view2d_draw_lines_y__values(const struct View2D *v2d)
void UI_view2d_scale_get(const struct View2D *v2d, float *r_x, float *r_y)
void UI_view2d_draw_lines_x__values(const struct View2D *v2d)
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_start_cb(void *userdata, MovieTrackingTrack *track, eClipCurveValueSource value_source, bool is_point)
struct TrackMotionCurveUserData TrackMotionCurveUserData
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)
static void tracking_segment_point_cb(void *userdata, MovieTrackingTrack *UNUSED(track), MovieTrackingMarker *UNUSED(marker), eClipCurveValueSource value_source, int scene_framenr, float val)
void clip_graph_tracking_values_iterate(struct SpaceClip *sc, bool selected_only, bool include_hidden, void *userdata, ClipTrackValueCallback func, ClipTrackValueSegmentStartCallback segment_start, ClipTrackValueSegmentEndCallback segment_end)
Definition: clip_utils.c:251
bool clip_graph_value_visible(struct SpaceClip *sc, eClipCurveValueSource value_source)
Definition: clip_utils.c:42
eClipCurveValueSource
Definition: clip_intern.h:114
@ CLIP_VALUE_SOURCE_REPROJECTION_ERROR
Definition: clip_intern.h:117
@ CLIP_VALUE_SOURCE_SPEED_Y
Definition: clip_intern.h:116
@ CLIP_VALUE_SOURCE_SPEED_X
Definition: clip_intern.h:115
void clip_draw_sfra_efra(struct View2D *v2d, struct Scene *scene)
Definition: clip_utils.c:609
Scene scene
uint pos
uint col
const ProjectiveReconstruction & reconstruction
Definition: intersect.cc:198
struct MovieTracking tracking
struct MovieClipUser user
MovieTrackingTrack * act_track