Commit: bfabe7cdf3589c1396727020f511c5bef8e0d5af Author: Tianwei Shen Date: Mon May 23 17:39:52 2016 +0800 Branches: soc-2016-multiview https://developer.blender.org/rBbfabe7cdf3589c1396727020f511c5bef8e0d5af
add two correspondence operators users can specify correspondence in tracking mode placeholder for now, unfinished =================================================================== A source/blender/editors/space_clip/tracking_ops_correspondence.c =================================================================== diff --git a/source/blender/editors/space_clip/tracking_ops_correspondence.c b/source/blender/editors/space_clip/tracking_ops_correspondence.c new file mode 100644 index 0000000..26d25f5 --- /dev/null +++ b/source/blender/editors/space_clip/tracking_ops_correspondence.c @@ -0,0 +1,225 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2016 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation, + * Tianwei Shen + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_clip/tracking_ops_correspondence.c + * \ingroup spclip + */ + +#include "MEM_guardedalloc.h" + +#include "DNA_screen_types.h" +#include "DNA_space_types.h" + +#include "BLI_utildefines.h" +#include "BLI_ghash.h" +#include "BLI_math.h" +#include "BLI_blenlib.h" + +#include "BKE_context.h" +#include "BKE_movieclip.h" +#include "BKE_tracking.h" +#include "BKE_depsgraph.h" +#include "BKE_report.h" +#include "BKE_sound.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_screen.h" +#include "ED_clip.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "BLT_translation.h" + +#include "clip_intern.h" +#include "tracking_ops_intern.h" + +/********************** add correspondence operator *********************/ + +static bool add_correspondence(const bContext *C, float x, float y) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTracking *tracking = &clip->tracking; + ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking); + ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); + MovieTrackingTrack *track; + int width, height; + int framenr = ED_space_clip_get_clip_frame_number(sc); + + ED_space_clip_get_size(sc, &width, &height); + + if (width == 0 || height == 0) { + return false; + } + + track = BKE_tracking_track_add(tracking, tracksbase, x, y, framenr, width, height); + + BKE_tracking_track_select(tracksbase, track, TRACK_AREA_ALL, 0); + BKE_tracking_plane_tracks_deselect_all(plane_tracks_base); + + clip->tracking.act_track = track; + clip->tracking.act_plane_track = NULL; + + return true; +} + +static int add_correspondence_invoke(bContext *C, + wmOperator *op, + const wmEvent *UNUSED(event)) +{ + ED_area_headerprint( + CTX_wm_area(C), + IFACE_("Use RMB click to define tracker correspondence in primary and witness camera")); + + /* Add modal handler for ESC. */ + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; +} + +static int add_correspondence_modal(bContext *C, + wmOperator *UNUSED(op), + const wmEvent *event) +{ + switch (event->type) { + case MOUSEMOVE: + return OPERATOR_RUNNING_MODAL; + + case LEFTMOUSE: + { + SpaceClip *sc = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(sc); + ARegion *ar = CTX_wm_region(C); + float pos[2]; + + ED_area_headerprint(CTX_wm_area(C), NULL); + + ED_clip_point_stable_pos(sc, ar, + event->x - ar->winrct.xmin, + event->y - ar->winrct.ymin, + &pos[0], &pos[1]); + + if (!add_correspondence(C, pos[0], pos[1])) { + return OPERATOR_CANCELLED; + } + + WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip); + return OPERATOR_FINISHED; + } + + case ESCKEY: + ED_area_headerprint(CTX_wm_area(C), NULL); + return OPERATOR_CANCELLED; + } + + return OPERATOR_PASS_THROUGH; +} + +void CLIP_OT_add_correspondence(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Add Correspondence"; + ot->idname = "CLIP_OT_add_correspondence"; + ot->description = "Add correspondence between primary camera and witness camera"; + + /* api callbacks */ + ot->invoke = add_correspondence_invoke; + ot->poll = ED_space_clip_tracking_poll; + ot->modal = add_correspondence_modal; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; +} + +/********************** delete correspondence operator *********************/ + +static int delete_correspondence_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTracking *tracking = &clip->tracking; + bool changed = false; + + /* Delete selected plane tracks. */ + ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); + for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first, + *next_plane_track; + plane_track != NULL; + plane_track = next_plane_track) + { + next_plane_track = plane_track->next; + + if (PLANE_TRACK_VIEW_SELECTED(plane_track)) { + BKE_tracking_plane_track_free(plane_track); + BLI_freelinkN(plane_tracks_base, plane_track); + changed = true; + } + } + + /* Remove selected point tracks (they'll also be removed from planes which + * uses them). + */ + ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking); + for (MovieTrackingTrack *track = tracksbase->first, *next_track; + track != NULL; + track = next_track) + { + next_track = track->next; + if (TRACK_VIEW_SELECTED(sc, track)) { + clip_delete_track(C, clip, track); + changed = true; + } + } + + /* Nothing selected now, unlock view so it can be scrolled nice again. */ + sc->flag &= ~SC_LOCK_SELECTION; + + if (changed) { + WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip); + } + + return OPERATOR_FINISHED; +} + +void CLIP_OT_delete_correspondence(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Delete Correspondence"; + ot->idname = "CLIP_OT_delete_correspondence"; + ot->description = "Delete selected tracker correspondene between primary and witness camera"; + + /* api callbacks */ + ot->invoke = WM_operator_confirm; + ot->exec = delete_correspondence_exec; + ot->poll = ED_space_clip_tracking_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs