void clip_view_center_to_point(SpaceClip *sc, float x, float y) { int width, height; float aspx, aspy; ED_space_clip_get_size(sc, &width, &height); ED_space_clip_get_aspect(sc, &aspx, &aspy); sc->xof = (x - 0.5f) * width * aspx; sc->yof = (y - 0.5f) * height * aspy; }
static MovieTrackingPlaneTrack *tracking_plane_marker_check_slide(bContext *C, const wmEvent *event, int *corner_r) { const float distance_clip_squared = 12.0f * 12.0f; SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; int width, height; float co[2]; ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); int framenr = ED_space_clip_get_clip_frame_number(sc); ED_space_clip_get_size(sc, &width, &height); if (width == 0 || height == 0) { return NULL; } ED_clip_mouse_pos(sc, ar, event->mval, co); float min_distance_squared = FLT_MAX; int min_corner = -1; MovieTrackingPlaneTrack *min_plane_track = NULL; for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track != NULL; plane_track = plane_track->next) { if (PLANE_TRACK_VIEW_SELECTED(plane_track)) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr); for (int i = 0; i < 4; i++) { float distance_squared = mouse_to_plane_slide_zone_distance_squared( co, plane_marker->corners[i], width, height); if (distance_squared < min_distance_squared) { min_distance_squared = distance_squared; min_corner = i; min_plane_track = plane_track; } } } } if (min_distance_squared < distance_clip_squared / sc->zoom) { if (corner_r != NULL) { *corner_r = min_corner; } return min_plane_track; } return NULL; }
static int view_all_exec(bContext *C, wmOperator *op) { SpaceClip *sc; ARegion *ar; int w, h, width, height; float aspx, aspy; int fit_view = RNA_boolean_get(op->ptr, "fit_view"); float zoomx, zoomy; /* retrieve state */ sc = CTX_wm_space_clip(C); ar = CTX_wm_region(C); ED_space_clip_get_size(sc, &w, &h); ED_space_clip_get_aspect(sc, &aspx, &aspy); w = w * aspx; h = h * aspy; /* check if the image will fit in the image with zoom == 1 */ width = BLI_rcti_size_x(&ar->winrct) + 1; height = BLI_rcti_size_y(&ar->winrct) + 1; if (fit_view) { const int margin = 5; /* margin from border */ zoomx = (float) width / (w + 2 * margin); zoomy = (float) height / (h + 2 * margin); sclip_zoom_set(C, min_ff(zoomx, zoomy), NULL); } else { if ((w >= width || h >= height) && (width > 0 && height > 0)) { zoomx = (float) width / w; zoomy = (float) height / h; /* find the zoom value that will fit the image in the image space */ sclip_zoom_set(C, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL); } else sclip_zoom_set(C, 1.0f, NULL); } sc->xof = sc->yof = 0.0f; ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; }
static bool selected_boundbox(SpaceClip *sc, float min[2], float max[2]) { MovieClip *clip = ED_space_clip_get_clip(sc); MovieTrackingTrack *track; int width, height; bool ok = false; ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking); int framenr = ED_space_clip_get_clip_frame_number(sc); INIT_MINMAX2(min, max); ED_space_clip_get_size(sc, &width, &height); track = tracksbase->first; while (track) { if (TRACK_VIEW_SELECTED(sc, track)) { MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr); if (marker) { float pos[3]; pos[0] = marker->pos[0] + track->offset[0]; pos[1] = marker->pos[1] + track->offset[1]; pos[2] = 0.0f; /* undistortion happens for normalized coords */ if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) { /* undistortion happens for normalized coords */ ED_clip_point_undistorted_pos(sc, pos, pos); } pos[0] *= width; pos[1] *= height; mul_v3_m4v3(pos, sc->stabmat, pos); minmax_v2v2_v2(min, max, pos); ok = true; } } track = track->next; } return ok; }
static void *slide_plane_marker_customdata(bContext *C, const wmEvent *event) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); MovieTrackingPlaneTrack *plane_track; int width, height; float co[2]; SlidePlaneMarkerData *customdata = NULL; int framenr = ED_space_clip_get_clip_frame_number(sc); int corner; ED_space_clip_get_size(sc, &width, &height); if (width == 0 || height == 0) { return NULL; } ED_clip_mouse_pos(sc, ar, event->mval, co); plane_track = tracking_plane_marker_check_slide(C, event, &corner); if (plane_track) { MovieTrackingPlaneMarker *plane_marker; customdata = MEM_callocN(sizeof(SlidePlaneMarkerData), "slide plane marker data"); customdata->event_type = event->type; plane_marker = BKE_tracking_plane_marker_ensure(plane_track, framenr); customdata->plane_track = plane_track; customdata->plane_marker = plane_marker; customdata->width = width; customdata->height = height; customdata->previous_mval[0] = event->mval[0]; customdata->previous_mval[1] = event->mval[1]; customdata->corner_index = corner; customdata->corner = plane_marker->corners[corner]; copy_v2_v2(customdata->previous_corner, customdata->corner); copy_v2_v2(customdata->old_corner, customdata->corner); } return customdata; }
static int track_mouse_area(const bContext *C, float co[2], MovieTrackingTrack *track) { SpaceClip *sc = CTX_wm_space_clip(C); int framenr = ED_space_clip_get_clip_frame_number(sc); MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr); float pat_min[2], pat_max[2]; float epsx, epsy; int width, height; ED_space_clip_get_size(sc, &width, &height); BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max); epsx = min_ffff(pat_min[0] - marker->search_min[0], marker->search_max[0] - pat_max[0], fabsf(pat_min[0]), fabsf(pat_max[0])) / 2; epsy = min_ffff(pat_min[1] - marker->search_min[1], marker->search_max[1] - pat_max[1], fabsf(pat_min[1]), fabsf(pat_max[1])) / 2; epsx = max_ff(epsx, 2.0f / width); epsy = max_ff(epsy, 2.0f / height); if (sc->flag & SC_SHOW_MARKER_SEARCH) { if (mouse_on_rect(co, marker->pos, marker->search_min, marker->search_max, epsx, epsy)) return TRACK_AREA_SEARCH; } if ((marker->flag & MARKER_DISABLED) == 0) { if (sc->flag & SC_SHOW_MARKER_PATTERN) if (mouse_on_crns(co, marker->pos, marker->pattern_corners, epsx, epsy)) return TRACK_AREA_PAT; epsx = 12.0f / width; epsy = 12.0f / height; if (fabsf(co[0] - marker->pos[0] - track->offset[0]) < epsx && fabsf(co[1] - marker->pos[1] - track->offset[1]) <= epsy) { return TRACK_AREA_POINT; } } return TRACK_AREA_NONE; }
bool ED_clip_view_selection(const bContext *C, ARegion *ar, bool fit) { SpaceClip *sc = CTX_wm_space_clip(C); int w, h, frame_width, frame_height; float min[2], max[2]; ED_space_clip_get_size(sc, &frame_width, &frame_height); if ((frame_width == 0) || (frame_height == 0) || (sc->clip == NULL)) return false; if (!selected_boundbox(sc, min, max)) return false; /* center view */ clip_view_center_to_point(sc, (max[0] + min[0]) / (2 * frame_width), (max[1] + min[1]) / (2 * frame_height)); w = max[0] - min[0]; h = max[1] - min[1]; /* set zoom to see all selection */ if (w > 0 && h > 0) { int width, height; float zoomx, zoomy, newzoom, aspx, aspy; ED_space_clip_get_aspect(sc, &aspx, &aspy); width = BLI_rcti_size_x(&ar->winrct) + 1; height = BLI_rcti_size_y(&ar->winrct) + 1; zoomx = (float)width / w / aspx; zoomy = (float)height / h / aspy; newzoom = 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)); if (fit || sc->zoom > newzoom) sc->zoom = newzoom; } return true; }
/** * \brief the reverse of ED_clip_point_stable_pos(), gets the marker region coords. * better name here? view_to_track / track_to_view or so? */ void ED_clip_point_stable_pos__reverse(SpaceClip *sc, ARegion *ar, const float co[2], float r_co[2]) { float zoomx, zoomy; float pos[3]; int width, height; int sx, sy; UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); ED_space_clip_get_size(sc, &width, &height); ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); ED_clip_point_undistorted_pos(sc, co, pos); pos[2] = 0.0f; /* untested */ mul_v3_m4v3(pos, sc->stabmat, pos); r_co[0] = (pos[0] * width * zoomx) + (float)sx; r_co[1] = (pos[1] * height * zoomy) + (float)sy; }
void ED_mask_get_size(ScrArea *sa, int *width, int *height) { if (sa && sa->spacedata.first) { switch (sa->spacetype) { case SPACE_CLIP: { SpaceClip *sc = sa->spacedata.first; ED_space_clip_get_size(sc, width, height); break; } case SPACE_SEQ: { // Scene *scene = CTX_data_scene(C); // *width = (scene->r.size * scene->r.xsch) / 100; // *height = (scene->r.size * scene->r.ysch) / 100; break; } case SPACE_IMAGE: { SpaceImage *sima = sa->spacedata.first; ED_space_image_get_size(sima, width, height); break; } default: /* possible other spaces from which mask editing is available */ BLI_assert(0); *width = 0; *height = 0; break; } } else { BLI_assert(0); *width = 0; *height = 0; } }
void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar) { MovieClip *clip = ED_space_clip_get_clip(sc); Scene *scene = CTX_data_scene(C); ImBuf *ibuf = NULL; int width, height; float zoomx, zoomy; ED_space_clip_get_size(sc, &width, &height); ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); /* if no clip, nothing to do */ if (!clip) { ED_region_grid_draw(ar, zoomx, zoomy); return; } if (sc->flag & SC_SHOW_STABLE) { float smat[4][4], ismat[4][4]; ibuf = ED_space_clip_get_stable_buffer(sc, sc->loc, &sc->scale, &sc->angle); if (ibuf) { float translation[2]; float aspect = clip->tracking.camera.pixel_aspect; if (width != ibuf->x) mul_v2_v2fl(translation, sc->loc, (float)width / ibuf->x); else copy_v2_v2(translation, sc->loc); BKE_tracking_stabilization_data_to_mat4(width, height, aspect, translation, sc->scale, sc->angle, sc->stabmat); unit_m4(smat); smat[0][0] = 1.0f / width; smat[1][1] = 1.0f / height; invert_m4_m4(ismat, smat); mul_serie_m4(sc->unistabmat, smat, sc->stabmat, ismat, NULL, NULL, NULL, NULL, NULL); } } else if ((sc->flag & SC_MUTE_FOOTAGE) == 0) { ibuf = ED_space_clip_get_buffer(sc); zero_v2(sc->loc); sc->scale = 1.0f; unit_m4(sc->stabmat); unit_m4(sc->unistabmat); } if (ibuf) { draw_movieclip_buffer(C, sc, ar, ibuf, width, height, zoomx, zoomy); IMB_freeImBuf(ibuf); } else if (sc->flag & SC_MUTE_FOOTAGE) { draw_movieclip_muted(ar, width, height, zoomx, zoomy); } else { ED_region_grid_draw(ar, zoomx, zoomy); } if (width && height) { draw_stabilization_border(sc, ar, width, height, zoomx, zoomy); draw_tracking_tracks(sc, scene, ar, clip, width, height, zoomx, zoomy); draw_distortion(sc, ar, clip, width, height, zoomx, zoomy); } }
static int circle_select_exec(bContext *C, wmOperator *op) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *track; MovieTrackingPlaneTrack *plane_track; ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking); ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); int x, y, radius, width, height, mode; bool changed = false; float zoomx, zoomy, offset[2], ellipse[2]; int framenr = ED_space_clip_get_clip_frame_number(sc); /* get operator properties */ x = RNA_int_get(op->ptr, "x"); y = RNA_int_get(op->ptr, "y"); radius = RNA_int_get(op->ptr, "radius"); mode = RNA_int_get(op->ptr, "gesture_mode"); /* compute ellipse and position in unified coordinates */ ED_space_clip_get_size(sc, &width, &height); ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); ellipse[0] = width * zoomx / radius; ellipse[1] = height * zoomy / radius; ED_clip_point_stable_pos(sc, ar, x, y, &offset[0], &offset[1]); /* do selection */ track = tracksbase->first; while (track) { if ((track->flag & TRACK_HIDDEN) == 0) { MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr); if (MARKER_VISIBLE(sc, track, marker) && marker_inside_ellipse(marker, offset, ellipse)) { if (mode == GESTURE_MODAL_SELECT) BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT); else BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT); changed = true; } } track = track->next; } for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr); int i; for (i = 0; i < 4; i++) { if (point_inside_ellipse(plane_marker->corners[i], offset, ellipse)) { if (mode == GESTURE_MODAL_SELECT) { plane_track->flag |= SELECT; } else { plane_track->flag &= ~SELECT; } } } changed = true; } } if (changed) { BKE_tracking_dopesheet_tag_update(tracking); WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL); return OPERATOR_FINISHED; } return OPERATOR_CANCELLED; }