Blender  V2.93
clip_graph_draw.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2011 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "DNA_movieclip_types.h"
25 #include "DNA_scene_types.h"
26 
27 #include "BLI_math.h"
28 #include "BLI_utildefines.h"
29 
30 #include "BKE_context.h"
31 #include "BKE_movieclip.h"
32 #include "BKE_tracking.h"
33 
34 #include "ED_clip.h"
35 #include "ED_screen.h"
36 
37 #include "GPU_immediate.h"
38 #include "GPU_immediate_util.h"
39 #include "GPU_matrix.h"
40 #include "GPU_state.h"
41 
42 #include "WM_types.h"
43 
44 #include "UI_interface.h"
45 #include "UI_resources.h"
46 #include "UI_view2d.h"
47 
48 #include "clip_intern.h" /* own include */
49 
50 typedef struct TrackMotionCurveUserData {
53  bool sel;
54  float xscale, yscale, hsize;
57 
58 static void tracking_segment_point_cb(void *userdata,
59  MovieTrackingTrack *UNUSED(track),
60  MovieTrackingMarker *UNUSED(marker),
61  eClipCurveValueSource value_source,
62  int scene_framenr,
63  float val)
64 {
66 
67  if (!clip_graph_value_visible(data->sc, value_source)) {
68  return;
69  }
70 
71  immVertex2f(data->pos, scene_framenr, val);
72 }
73 
74 static void tracking_segment_start_cb(void *userdata,
75  MovieTrackingTrack *track,
76  eClipCurveValueSource value_source,
77  bool is_point)
78 {
80  SpaceClip *sc = data->sc;
81  float col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
82 
83  if (!clip_graph_value_visible(sc, value_source)) {
84  return;
85  }
86 
87  switch (value_source) {
89  col[0] = 1.0f;
90  break;
92  col[1] = 1.0f;
93  break;
95  col[2] = 1.0f;
96  break;
97  }
98 
99  if (track == data->act_track) {
100  col[3] = 1.0f;
101  GPU_line_width(2.0f);
102  }
103  else {
104  col[3] = 0.5f;
105  GPU_line_width(1.0f);
106  }
107 
109 
110  if (is_point) {
112  }
113  else {
114  /* Graph can be composed of smaller segments, if any marker is disabled */
116  }
117 }
118 
119 static void tracking_segment_end_cb(void *userdata, eClipCurveValueSource value_source)
120 {
122  SpaceClip *sc = data->sc;
123  if (!clip_graph_value_visible(sc, value_source)) {
124  return;
125  }
126  immEnd();
127 }
128 
129 static void tracking_segment_knot_cb(void *userdata,
130  MovieTrackingTrack *track,
131  MovieTrackingMarker *marker,
132  eClipCurveValueSource value_source,
133  int scene_framenr,
134  float val)
135 {
137  int sel = 0, sel_flag;
138 
139  if (track != data->act_track) {
140  return;
141  }
143  return;
144  }
145 
146  sel_flag = value_source == CLIP_VALUE_SOURCE_SPEED_X ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y;
147  sel = (marker->flag & sel_flag) ? 1 : 0;
148 
149  if (sel == data->sel) {
151 
152  GPU_matrix_push();
153  GPU_matrix_translate_2f(scene_framenr, val);
154  GPU_matrix_scale_2f(1.0f / data->xscale * data->hsize, 1.0f / data->yscale * data->hsize);
155 
156  imm_draw_circle_wire_2d(data->pos, 0, 0, 0.7, 8);
157 
158  GPU_matrix_pop();
159  }
160 }
161 
163 {
164  MovieClip *clip = ED_space_clip_get_clip(sc);
165  MovieTracking *tracking = &clip->tracking;
166  MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
167  const bool draw_knots = (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) != 0;
168 
169  int width, height;
170  BKE_movieclip_get_size(clip, &sc->user, &width, &height);
171  if (!width || !height) {
172  return;
173  }
174 
175  TrackMotionCurveUserData userdata;
176  userdata.sc = sc;
178  userdata.sel = false;
179  userdata.act_track = act_track;
180  userdata.pos = pos;
181 
182  /* Non-selected knot handles. */
183  if (draw_knots) {
184  UI_view2d_scale_get(v2d, &userdata.xscale, &userdata.yscale);
186  (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
187  (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
188  &userdata,
190  NULL,
191  NULL);
192  }
193 
194  /* Draw graph lines. */
197  (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
198  (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
199  &userdata,
204 
205  /* Selected knot handles on top of curves. */
206  if (draw_knots) {
207  userdata.sel = true;
209  (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
210  (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
211  &userdata,
213  NULL,
214  NULL);
215  }
216 }
217 
219 {
220  MovieClip *clip = ED_space_clip_get_clip(sc);
221  MovieTracking *tracking = &clip->tracking;
223 
224  int previous_frame;
225  float previous_error;
226  bool have_previous_point = false;
227 
228  /* Indicates whether immBegin() was called. */
229  bool is_lines_segment_open = false;
230 
231  immUniformColor3f(0.0f, 0.0f, 1.0f);
232 
233  for (int i = 0; i < reconstruction->camnr; i++) {
234  MovieReconstructedCamera *camera = &reconstruction->cameras[i];
235 
236  const int current_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, camera->framenr);
237  const float current_error = camera->error;
238 
239  if (have_previous_point && current_frame != previous_frame + 1) {
240  if (is_lines_segment_open) {
241  immEnd();
242  is_lines_segment_open = false;
243  }
244  have_previous_point = false;
245  }
246 
247  if (have_previous_point) {
248  if (!is_lines_segment_open) {
250  is_lines_segment_open = true;
251 
252  immVertex2f(pos, previous_frame, previous_error);
253  }
254  immVertex2f(pos, current_frame, current_error);
255  }
256 
257  previous_frame = current_frame;
258  previous_error = current_error;
259  have_previous_point = true;
260  }
261 
262  if (is_lines_segment_open) {
263  immEnd();
264  }
265 }
266 
268 {
269  MovieClip *clip = ED_space_clip_get_clip(sc);
270  View2D *v2d = &region->v2d;
271 
272  /* grid */
275 
276  if (clip) {
279 
280  GPU_point_size(3.0f);
281 
284  }
285 
286  if (sc->flag & SC_SHOW_GRAPH_FRAMES) {
287  draw_frame_curves(sc, pos);
288  }
289 
291  }
292 
293  /* frame range */
295 }
void BKE_movieclip_get_size(struct MovieClip *clip, struct MovieClipUser *user, int *width, int *height)
Definition: movieclip.c:1540
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:1170
struct MovieTrackingReconstruction * BKE_tracking_get_active_reconstruction(struct MovieTracking *tracking)
Definition: tracking.c:389
unsigned int uint
Definition: BLI_sys_types.h:83
#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:572
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 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
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
void GPU_matrix_pop(void)
Definition: gpu_matrix.cc:142
void GPU_matrix_scale_2f(float x, float y)
Definition: gpu_matrix.cc:232
void GPU_matrix_push(void)
Definition: gpu_matrix.cc:135
void GPU_matrix_translate_2f(float x, float y)
Definition: gpu_matrix.cc:190
@ GPU_PRIM_POINTS
Definition: GPU_primitive.h:35
@ GPU_PRIM_LINE_STRIP
Definition: GPU_primitive.h:38
@ GPU_SHADER_2D_UNIFORM_COLOR
Definition: GPU_shader.h:171
@ GPU_BLEND_NONE
Definition: GPU_state.h:55
@ GPU_BLEND_ALPHA
Definition: GPU_state.h:57
void GPU_blend(eGPUBlend blend)
Definition: gpu_state.cc:55
void GPU_line_width(float width)
Definition: gpu_state.cc:173
void GPU_point_size(float size)
Definition: gpu_state.cc:179
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
@ TH_HANDLE_VERTEX_SIZE
Definition: UI_resources.h:222
@ TH_HANDLE_VERTEX_SELECT
Definition: UI_resources.h:221
@ TH_HANDLE_VERTEX
Definition: UI_resources.h:220
float UI_GetThemeValuef(int colorid)
Definition: resources.c:1164
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:267
bool clip_graph_value_visible(struct SpaceClip *sc, eClipCurveValueSource value_source)
Definition: clip_utils.c:58
eClipCurveValueSource
Definition: clip_intern.h:118
@ CLIP_VALUE_SOURCE_REPROJECTION_ERROR
Definition: clip_intern.h:121
@ CLIP_VALUE_SOURCE_SPEED_Y
Definition: clip_intern.h:120
@ CLIP_VALUE_SOURCE_SPEED_X
Definition: clip_intern.h:119
void clip_draw_sfra_efra(struct View2D *v2d, struct Scene *scene)
Definition: clip_utils.c:628
Scene scene
uint pos
uint col
const ProjectiveReconstruction & reconstruction
Definition: intersect.cc:198
struct MovieTracking tracking
struct MovieClipUser user
MovieTrackingTrack * act_track