2011-11-07 12:55:18 +00:00
/*
* * * * * * 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 ) 2011 Blender Foundation .
* All rights reserved .
*
*
* Contributor ( s ) : Blender Foundation ,
* Sergey Sharybin
*
* * * * * * END GPL LICENSE BLOCK * * * * *
*/
/** \file blender/editors/space_clip/tracking_ops.c
* \ ingroup spclip
*/
# include "MEM_guardedalloc.h"
# include "DNA_camera_types.h"
2011-12-15 16:09:57 +00:00
# include "DNA_constraint_types.h"
2011-11-07 12:55:18 +00:00
# include "DNA_gpencil_types.h"
# include "DNA_movieclip_types.h"
2012-06-10 19:59:02 +00:00
# include "DNA_object_types.h" /* SELECT */
2011-11-07 12:55:18 +00:00
# include "DNA_scene_types.h"
# include "BLI_utildefines.h"
# include "BLI_math.h"
# include "BLI_listbase.h"
# include "BLI_rect.h"
# include "BLI_blenlib.h"
# include "BKE_main.h"
# include "BKE_context.h"
2011-12-15 16:09:57 +00:00
# include "BKE_constraint.h"
2011-11-07 12:55:18 +00:00
# include "BKE_movieclip.h"
# include "BKE_tracking.h"
# include "BKE_global.h"
# include "BKE_depsgraph.h"
# include "BKE_object.h"
# include "BKE_report.h"
# include "BKE_scene.h"
# include "BKE_library.h"
# include "BKE_sound.h"
# include "WM_api.h"
# include "WM_types.h"
# include "ED_screen.h"
# include "ED_clip.h"
# include "ED_keyframing.h"
# include "IMB_imbuf_types.h"
# include "IMB_imbuf.h"
# include "UI_interface.h"
# include "RNA_access.h"
# include "RNA_define.h"
# include "PIL_time.h"
# include "UI_view2d.h"
2012-06-10 19:59:02 +00:00
# include "clip_intern.h" // own include
2011-11-07 12:55:18 +00:00
/********************** add marker operator *********************/
2012-06-20 10:28:51 +00:00
static void add_marker ( const bContext * C , float x , float y )
2011-11-07 12:55:18 +00:00
{
2012-06-20 10:28:51 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
int width , height ;
2012-06-19 14:26:29 +00:00
int framenr = ED_space_clip_get_clip_frame_number ( sc ) ;
2012-03-25 23:19:21 +00:00
2012-07-26 22:41:40 +00:00
ED_space_clip_get_size ( sc , & width , & height ) ;
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
track = BKE_tracking_track_add ( tracking , tracksbase , x , y , framenr , width , height ) ;
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_track_select ( tracksbase , track , TRACK_AREA_ALL , 0 ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
clip - > tracking . act_track = track ;
2011-11-07 12:55:18 +00:00
}
static int add_marker_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2011-11-07 12:55:18 +00:00
float pos [ 2 ] ;
int width , height ;
2012-07-26 22:41:40 +00:00
ED_space_clip_get_size ( sc , & width , & height ) ;
2012-06-07 16:36:19 +00:00
2012-03-24 06:38:07 +00:00
if ( ! width | | ! height )
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
RNA_float_get_array ( op - > ptr , " location " , pos ) ;
2012-06-20 10:28:51 +00:00
add_marker ( C , pos [ 0 ] , pos [ 1 ] ) ;
2011-11-07 12:55:18 +00:00
/* reset offset from locked position, so frame jumping wouldn't be so confusing */
2012-03-25 23:19:21 +00:00
sc - > xlockof = 0 ;
sc - > ylockof = 0 ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EDITED , clip ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
static int add_marker_invoke ( bContext * C , wmOperator * op , wmEvent * event )
{
2012-07-26 22:41:40 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
ARegion * ar = CTX_wm_region ( C ) ;
2011-11-07 12:55:18 +00:00
float co [ 2 ] ;
2012-07-27 15:15:55 +00:00
ED_clip_mouse_pos ( sc , ar , event - > mval , co ) ;
2011-11-07 12:55:18 +00:00
RNA_float_set_array ( op - > ptr , " location " , co ) ;
return add_marker_exec ( C , op ) ;
}
void CLIP_OT_add_marker ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Add Marker " ;
ot - > idname = " CLIP_OT_add_marker " ;
ot - > description = " Place new marker at specified location " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > invoke = add_marker_invoke ;
ot - > exec = add_marker_exec ;
2012-06-07 16:36:19 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* properties */
2012-10-11 23:46:12 +00:00
RNA_def_float_vector ( ot - > srna , " location " , 2 , NULL , - FLT_MAX , FLT_MAX ,
2012-06-10 19:59:02 +00:00
" Location " , " Location of marker on frame " , - 1.0f , 1.0f ) ;
2011-11-07 12:55:18 +00:00
}
/********************** delete track operator *********************/
static int delete_track_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2012-03-25 23:19:21 +00:00
MovieTrackingTrack * track = tracksbase - > first , * next ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
next = track - > next ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( TRACK_VIEW_SELECTED ( sc , track ) )
2011-12-05 18:57:17 +00:00
clip_delete_track ( C , clip , tracksbase , track ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = next ;
2011-11-07 12:55:18 +00:00
}
/* nothing selected now, unlock view so it can be scrolled nice again */
2012-03-25 23:19:21 +00:00
sc - > flag & = ~ SC_LOCK_SELECTION ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_delete_track ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Delete Track " ;
ot - > idname = " CLIP_OT_delete_track " ;
ot - > description = " Delete selected tracks " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > invoke = WM_operator_confirm ;
ot - > exec = delete_track_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** delete marker operator *********************/
static int delete_marker_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( & clip - > tracking ) ;
2012-03-25 23:19:21 +00:00
MovieTrackingTrack * track = tracksbase - > first , * next ;
2012-06-19 14:26:29 +00:00
int framenr = ED_space_clip_get_clip_frame_number ( sc ) ;
2012-03-25 23:19:21 +00:00
int has_selection = 0 ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
next = track - > next ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( TRACK_VIEW_SELECTED ( sc , track ) ) {
2012-06-15 11:03:23 +00:00
MovieTrackingMarker * marker = BKE_tracking_marker_get_exact ( track , framenr ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( marker ) {
2012-05-07 08:53:59 +00:00
has_selection | = track - > markersnr > 1 ;
2011-11-07 12:55:18 +00:00
2011-12-05 18:57:17 +00:00
clip_delete_marker ( C , clip , tracksbase , track , marker ) ;
2011-11-07 12:55:18 +00:00
}
}
2012-03-25 23:19:21 +00:00
track = next ;
2011-11-07 12:55:18 +00:00
}
2012-03-24 06:38:07 +00:00
if ( ! has_selection ) {
2011-11-07 12:55:18 +00:00
/* nothing selected now, unlock view so it can be scrolled nice again */
2012-03-25 23:19:21 +00:00
sc - > flag & = ~ SC_LOCK_SELECTION ;
2011-11-07 12:55:18 +00:00
}
return OPERATOR_FINISHED ;
}
void CLIP_OT_delete_marker ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Delete Marker " ;
ot - > idname = " CLIP_OT_delete_marker " ;
ot - > description = " Delete marker for current frame from selected tracks " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > invoke = WM_operator_confirm ;
ot - > exec = delete_marker_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** slide marker operator *********************/
2012-06-15 18:31:46 +00:00
# define SLIDE_ACTION_POS 0
# define SLIDE_ACTION_SIZE 1
# define SLIDE_ACTION_OFFSET 2
# define SLIDE_ACTION_TILT_SIZE 3
2011-11-07 12:55:18 +00:00
typedef struct {
2012-06-15 16:07:33 +00:00
short area , action ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
MovieTrackingMarker * marker ;
int mval [ 2 ] ;
int width , height ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
float * min , * max , * pos , * offset , ( * corners ) [ 2 ] ;
2012-06-15 16:07:33 +00:00
float spos [ 2 ] ;
2011-11-07 12:55:18 +00:00
2012-06-15 18:31:46 +00:00
short lock , accurate ;
2012-06-15 16:07:33 +00:00
/* data to restore on cancel */
float old_search_min [ 2 ] , old_search_max [ 2 ] , old_pos [ 2 ] , old_offset [ 2 ] ;
float old_corners [ 4 ] [ 2 ] ;
float ( * old_markers ) [ 2 ] ;
2011-11-07 12:55:18 +00:00
} SlideMarkerData ;
2012-06-15 18:31:46 +00:00
static void slide_marker_tilt_slider ( MovieTrackingMarker * marker , float slider [ 2 ] )
{
add_v2_v2v2 ( slider , marker - > pattern_corners [ 1 ] , marker - > pattern_corners [ 2 ] ) ;
add_v2_v2 ( slider , marker - > pos ) ;
}
2011-11-07 12:55:18 +00:00
static SlideMarkerData * create_slide_marker_data ( SpaceClip * sc , MovieTrackingTrack * track ,
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
MovieTrackingMarker * marker , wmEvent * event ,
2012-06-10 19:59:02 +00:00
int area , int corner , int action , int width , int height )
2011-11-07 12:55:18 +00:00
{
2012-03-25 23:19:21 +00:00
SlideMarkerData * data = MEM_callocN ( sizeof ( SlideMarkerData ) , " slide marker data " ) ;
2012-06-19 14:26:29 +00:00
int framenr = ED_space_clip_get_clip_frame_number ( sc ) ;
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
marker = BKE_tracking_marker_ensure ( track , framenr ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
data - > area = area ;
data - > action = action ;
data - > track = track ;
data - > marker = marker ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( area = = TRACK_AREA_POINT ) {
data - > pos = marker - > pos ;
data - > offset = track - > offset ;
2012-03-24 06:38:07 +00:00
}
2012-03-25 23:19:21 +00:00
else if ( area = = TRACK_AREA_PAT ) {
if ( action = = SLIDE_ACTION_SIZE ) {
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
data - > corners = marker - > pattern_corners ;
2012-03-24 06:38:07 +00:00
}
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
else if ( action = = SLIDE_ACTION_OFFSET ) {
2011-11-07 12:55:18 +00:00
int a ;
2012-03-25 23:19:21 +00:00
data - > pos = marker - > pos ;
data - > offset = track - > offset ;
2011-11-07 12:55:18 +00:00
2012-06-15 16:07:33 +00:00
data - > old_markers = MEM_callocN ( sizeof ( * data - > old_markers ) * track - > markersnr , " slide marekrs " ) ;
2012-03-25 23:19:21 +00:00
for ( a = 0 ; a < track - > markersnr ; a + + )
2012-06-15 16:07:33 +00:00
copy_v2_v2 ( data - > old_markers [ a ] , track - > markers [ a ] . pos ) ;
2011-11-07 12:55:18 +00:00
}
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
else if ( action = = SLIDE_ACTION_POS ) {
data - > corners = marker - > pattern_corners ;
data - > pos = marker - > pattern_corners [ corner ] ;
copy_v2_v2 ( data - > spos , data - > pos ) ;
}
2012-06-15 18:31:46 +00:00
else if ( action = = SLIDE_ACTION_TILT_SIZE ) {
data - > corners = marker - > pattern_corners ;
slide_marker_tilt_slider ( marker , data - > spos ) ;
}
2012-03-24 06:38:07 +00:00
}
2012-03-25 23:19:21 +00:00
else if ( area = = TRACK_AREA_SEARCH ) {
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
data - > min = marker - > search_min ;
data - > max = marker - > search_max ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
data - > mval [ 0 ] = event - > mval [ 0 ] ;
data - > mval [ 1 ] = event - > mval [ 1 ] ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
data - > width = width ;
data - > height = height ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( action = = SLIDE_ACTION_SIZE )
data - > lock = 1 ;
2011-11-07 12:55:18 +00:00
2012-06-15 16:07:33 +00:00
/* backup marker's settings */
memcpy ( data - > old_corners , marker - > pattern_corners , sizeof ( data - > old_corners ) ) ;
copy_v2_v2 ( data - > old_search_min , marker - > search_min ) ;
copy_v2_v2 ( data - > old_search_max , marker - > search_max ) ;
copy_v2_v2 ( data - > old_pos , marker - > pos ) ;
copy_v2_v2 ( data - > old_offset , track - > offset ) ;
2011-11-07 12:55:18 +00:00
return data ;
}
2012-06-15 18:31:46 +00:00
static int mouse_on_slide_zone ( SpaceClip * sc , MovieTrackingMarker * marker ,
int area , float co [ 2 ] , float slide_zone [ 2 ] ,
float padding , int width , int height )
2011-11-07 12:55:18 +00:00
{
2012-06-15 18:31:46 +00:00
const float size = 12.0f ;
2012-03-25 23:19:21 +00:00
int inside = 0 ;
2011-11-07 12:55:18 +00:00
float min [ 2 ] , max [ 2 ] ;
2012-06-15 18:31:46 +00:00
float dx , dy ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( area = = TRACK_AREA_SEARCH ) {
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
copy_v2_v2 ( min , marker - > search_min ) ;
copy_v2_v2 ( max , marker - > search_max ) ;
2012-03-24 06:38:07 +00:00
}
else {
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
BKE_tracking_marker_pattern_minmax ( marker , min , max ) ;
2011-11-07 12:55:18 +00:00
}
2012-06-15 18:31:46 +00:00
min [ 0 ] - = padding / width ;
min [ 1 ] - = padding / height ;
max [ 0 ] + = padding / width ;
max [ 1 ] + = padding / height ;
2012-03-25 23:19:21 +00:00
dx = size / width / sc - > zoom ;
dy = size / height / sc - > zoom ;
2011-11-07 12:55:18 +00:00
2012-07-29 16:59:51 +00:00
dx = minf ( dx , ( max [ 0 ] - min [ 0 ] ) / 6.0f ) ;
dy = minf ( dy , ( max [ 1 ] - min [ 1 ] ) / 6.0f ) ;
2012-06-15 18:31:46 +00:00
return IN_RANGE_INCL ( co [ 0 ] , slide_zone [ 0 ] - dx , slide_zone [ 0 ] + dx ) & &
IN_RANGE_INCL ( co [ 1 ] , slide_zone [ 1 ] - dy , slide_zone [ 1 ] + dy ) ;
return inside ;
}
static int mouse_on_corner ( SpaceClip * sc , MovieTrackingMarker * marker ,
int area , float co [ 2 ] , int corner , float padding ,
int width , int height )
{
float min [ 2 ] , max [ 2 ] , crn [ 2 ] ;
if ( area = = TRACK_AREA_SEARCH ) {
copy_v2_v2 ( min , marker - > search_min ) ;
copy_v2_v2 ( max , marker - > search_max ) ;
}
else {
BKE_tracking_marker_pattern_minmax ( marker , min , max ) ;
}
2011-11-07 12:55:18 +00:00
2012-06-15 18:31:46 +00:00
min [ 0 ] - = padding / width ;
min [ 1 ] - = padding / height ;
max [ 0 ] + = padding / width ;
max [ 1 ] + = padding / height ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( corner = = 0 ) {
crn [ 0 ] = marker - > pos [ 0 ] + max [ 0 ] ;
crn [ 1 ] = marker - > pos [ 1 ] + min [ 1 ] ;
2012-03-24 06:38:07 +00:00
}
else {
2012-05-07 08:53:59 +00:00
crn [ 0 ] = marker - > pos [ 0 ] + min [ 0 ] ;
crn [ 1 ] = marker - > pos [ 1 ] + max [ 1 ] ;
2011-11-07 12:55:18 +00:00
}
2012-06-15 18:31:46 +00:00
return mouse_on_slide_zone ( sc , marker , area , co , crn , padding , width , height ) ;
2011-11-07 12:55:18 +00:00
}
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
static int get_mouse_pattern_corner ( SpaceClip * sc , MovieTrackingMarker * marker , float co [ 2 ] , int width , int height )
{
int i , next ;
float len = FLT_MAX , dx , dy ;
for ( i = 0 ; i < 4 ; i + + ) {
float cur_len ;
next = ( i + 1 ) % 4 ;
cur_len = len_v2v2 ( marker - > pattern_corners [ i ] , marker - > pattern_corners [ next ] ) ;
2012-07-29 16:59:51 +00:00
len = minf ( cur_len , len ) ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
}
2012-06-15 18:31:46 +00:00
dx = 12.0f / width / sc - > zoom ;
dy = 12.0f / height / sc - > zoom ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
2012-07-29 16:59:51 +00:00
dx = minf ( dx , len * 2.0f / 3.0f ) ;
dy = minf ( dy , len * width / height * 2.0f / 3.0f ) ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
for ( i = 0 ; i < 4 ; i + + ) {
float crn [ 2 ] ;
int inside ;
add_v2_v2v2 ( crn , marker - > pattern_corners [ i ] , marker - > pos ) ;
inside = IN_RANGE_INCL ( co [ 0 ] , crn [ 0 ] - dx , crn [ 0 ] + dx ) & &
IN_RANGE_INCL ( co [ 1 ] , crn [ 1 ] - dy , crn [ 1 ] + dy ) ;
if ( inside )
return i ;
}
return - 1 ;
}
2011-11-07 12:55:18 +00:00
static int mouse_on_offset ( SpaceClip * sc , MovieTrackingTrack * track , MovieTrackingMarker * marker ,
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
float co [ 2 ] , int width , int height )
2011-11-07 12:55:18 +00:00
{
float pos [ 2 ] , dx , dy ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
float pat_min [ 2 ] , pat_max [ 2 ] ;
BKE_tracking_marker_pattern_minmax ( marker , pat_min , pat_max ) ;
2011-11-07 12:55:18 +00:00
add_v2_v2v2 ( pos , marker - > pos , track - > offset ) ;
2012-03-25 23:19:21 +00:00
dx = 12.0f / width / sc - > zoom ;
2012-05-07 08:53:59 +00:00
dy = 12.0f / height / sc - > zoom ;
2011-11-07 12:55:18 +00:00
2012-07-29 16:59:51 +00:00
dx = minf ( dx , ( pat_max [ 0 ] - pat_min [ 0 ] ) / 2.0f ) ;
dy = minf ( dy , ( pat_max [ 1 ] - pat_min [ 1 ] ) / 2.0f ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
return co [ 0 ] > = pos [ 0 ] - dx & & co [ 0 ] < = pos [ 0 ] + dx & & co [ 1 ] > = pos [ 1 ] - dy & & co [ 1 ] < = pos [ 1 ] + dy ;
2011-11-07 12:55:18 +00:00
}
2012-06-15 18:31:46 +00:00
static int mouse_on_tilt ( SpaceClip * sc , MovieTrackingMarker * marker , float co [ 2 ] , int width , int height )
{
float slider [ 2 ] ;
slide_marker_tilt_slider ( marker , slider ) ;
return mouse_on_slide_zone ( sc , marker , TRACK_AREA_PAT , co , slider , 0.0f , width , height ) ;
}
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
static int slide_check_corners ( float ( * corners ) [ 2 ] )
{
int i , next , prev ;
float cross = 0.0f ;
float p [ 2 ] = { 0.0f , 0.0f } ;
if ( ! isect_point_quad_v2 ( p , corners [ 0 ] , corners [ 1 ] , corners [ 2 ] , corners [ 3 ] ) )
return FALSE ;
for ( i = 0 ; i < 4 ; i + + ) {
float v1 [ 2 ] , v2 [ 2 ] , cur_cross ;
next = ( i + 1 ) % 4 ;
prev = ( 4 + i - 1 ) % 4 ;
sub_v2_v2v2 ( v1 , corners [ i ] , corners [ prev ] ) ;
sub_v2_v2v2 ( v2 , corners [ next ] , corners [ i ] ) ;
cur_cross = cross_v2v2 ( v1 , v2 ) ;
if ( fabsf ( cur_cross ) > FLT_EPSILON ) {
if ( cross = = 0.0f ) {
cross = cur_cross ;
}
else if ( cross * cur_cross < 0.0f ) {
return FALSE ;
}
}
}
return TRUE ;
}
2011-11-07 12:55:18 +00:00
static void hide_cursor ( bContext * C )
{
2012-03-25 23:19:21 +00:00
wmWindow * win = CTX_wm_window ( C ) ;
2011-11-07 12:55:18 +00:00
WM_cursor_set ( win , CURSOR_NONE ) ;
}
static void show_cursor ( bContext * C )
{
2012-03-25 23:19:21 +00:00
wmWindow * win = CTX_wm_window ( C ) ;
2011-11-07 12:55:18 +00:00
WM_cursor_set ( win , CURSOR_STD ) ;
}
2012-06-15 14:26:27 +00:00
MovieTrackingTrack * tracking_marker_check_slide ( bContext * C , wmEvent * event , int * area_r , int * action_r , int * corner_r )
2012-06-15 11:40:04 +00:00
{
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-07-26 22:41:40 +00:00
ARegion * ar = CTX_wm_region ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-06-15 11:40:04 +00:00
MovieTrackingTrack * track ;
int width , height ;
float co [ 2 ] ;
ListBase * tracksbase = BKE_tracking_get_active_tracks ( & clip - > tracking ) ;
2012-06-19 14:26:29 +00:00
int framenr = ED_space_clip_get_clip_frame_number ( sc ) ;
2012-06-15 14:26:27 +00:00
int action = - 1 , area = 0 , corner = - 1 ;
2012-06-15 11:40:04 +00:00
2012-07-26 22:41:40 +00:00
ED_space_clip_get_size ( sc , & width , & height ) ;
2012-06-15 11:40:04 +00:00
if ( width = = 0 | | height = = 0 )
return NULL ;
2012-07-27 15:15:55 +00:00
ED_clip_mouse_pos ( sc , ar , event - > mval , co ) ;
2012-06-15 11:40:04 +00:00
track = tracksbase - > first ;
while ( track ) {
if ( TRACK_VIEW_SELECTED ( sc , track ) & & ( track - > flag & TRACK_LOCKED ) = = 0 ) {
MovieTrackingMarker * marker = BKE_tracking_marker_get ( track , framenr ) ;
int ok = FALSE ;
if ( ( marker - > flag & MARKER_DISABLED ) = = 0 ) {
2012-06-15 14:26:27 +00:00
if ( mouse_on_offset ( sc , track , marker , co , width , height ) ) {
area = TRACK_AREA_POINT ;
action = SLIDE_ACTION_POS ;
2012-06-15 11:40:04 +00:00
ok = TRUE ;
2012-06-15 14:26:27 +00:00
}
2012-06-15 11:40:04 +00:00
if ( ! ok & & ( sc - > flag & SC_SHOW_MARKER_SEARCH ) ) {
2012-06-15 18:31:46 +00:00
if ( mouse_on_corner ( sc , marker , TRACK_AREA_SEARCH , co , 1 , 0.0f , width , height ) ) {
2012-06-15 14:26:27 +00:00
area = TRACK_AREA_SEARCH ;
action = SLIDE_ACTION_OFFSET ;
2012-06-15 11:40:04 +00:00
ok = TRUE ;
}
2012-06-15 18:31:46 +00:00
else if ( mouse_on_corner ( sc , marker , TRACK_AREA_SEARCH , co , 0 , 0.0f , width , height ) ) {
2012-06-15 14:26:27 +00:00
area = TRACK_AREA_SEARCH ;
action = SLIDE_ACTION_SIZE ;
2012-06-15 11:40:04 +00:00
ok = TRUE ;
}
}
if ( ! ok & & ( sc - > flag & SC_SHOW_MARKER_PATTERN ) ) {
2012-06-15 18:31:46 +00:00
int current_corner = get_mouse_pattern_corner ( sc , marker , co , width , height ) ;
2012-06-15 11:40:04 +00:00
2012-06-15 18:31:46 +00:00
if ( current_corner ! = - 1 ) {
area = TRACK_AREA_PAT ;
action = SLIDE_ACTION_POS ;
corner = current_corner ;
ok = TRUE ;
2012-06-15 11:40:04 +00:00
}
else {
2012-06-18 14:02:59 +00:00
#if 0
/* TODO: disable for now, needs better approaches for visualization */
2012-06-15 18:31:46 +00:00
if ( mouse_on_corner ( sc , marker , TRACK_AREA_PAT , co , 1 , 12.0f , width , height ) ) {
2012-06-15 14:26:27 +00:00
area = TRACK_AREA_PAT ;
action = SLIDE_ACTION_OFFSET ;
2012-06-15 11:40:04 +00:00
ok = TRUE ;
}
2012-06-15 18:31:46 +00:00
if ( ! ok & & mouse_on_corner ( sc , marker , TRACK_AREA_PAT , co , 0 , 12.0f , width , height ) ) {
2012-06-15 14:26:27 +00:00
area = TRACK_AREA_PAT ;
action = SLIDE_ACTION_SIZE ;
2012-06-15 11:40:04 +00:00
ok = TRUE ;
}
2012-06-18 14:02:59 +00:00
# endif
2012-06-15 18:31:46 +00:00
if ( ! ok & & mouse_on_tilt ( sc , marker , co , width , height ) ) {
area = TRACK_AREA_PAT ;
action = SLIDE_ACTION_TILT_SIZE ;
ok = TRUE ;
}
2012-06-15 11:40:04 +00:00
}
}
2012-06-15 14:26:27 +00:00
if ( ok ) {
if ( area_r )
* area_r = area ;
if ( action_r )
* action_r = action ;
if ( corner_r )
* corner_r = corner ;
2012-06-15 11:40:04 +00:00
return track ;
2012-06-15 14:26:27 +00:00
}
2012-06-15 11:40:04 +00:00
}
}
track = track - > next ;
}
return NULL ;
}
2011-11-07 12:55:18 +00:00
static void * slide_marker_customdata ( bContext * C , wmEvent * event )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-07-26 22:41:40 +00:00
ARegion * ar = CTX_wm_region ( C ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
int width , height ;
float co [ 2 ] ;
2012-03-25 23:19:21 +00:00
void * customdata = NULL ;
2012-06-19 14:26:29 +00:00
int framenr = ED_space_clip_get_clip_frame_number ( sc ) ;
2012-06-15 14:26:27 +00:00
int area , action , corner ;
2011-11-07 12:55:18 +00:00
2012-07-26 22:41:40 +00:00
ED_space_clip_get_size ( sc , & width , & height ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( width = = 0 | | height = = 0 )
2011-11-07 12:55:18 +00:00
return NULL ;
2012-07-27 15:15:55 +00:00
ED_clip_mouse_pos ( sc , ar , event - > mval , co ) ;
2011-11-07 12:55:18 +00:00
2012-06-15 14:26:27 +00:00
track = tracking_marker_check_slide ( C , event , & area , & action , & corner ) ;
if ( track ) {
MovieTrackingMarker * marker = BKE_tracking_marker_get ( track , framenr ) ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
2012-06-15 14:26:27 +00:00
customdata = create_slide_marker_data ( sc , track , marker , event , area , corner , action , width , height ) ;
2011-11-07 12:55:18 +00:00
}
return customdata ;
}
static int slide_marker_invoke ( bContext * C , wmOperator * op , wmEvent * event )
{
2012-03-25 23:19:21 +00:00
SlideMarkerData * slidedata = slide_marker_customdata ( C , event ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( slidedata ) {
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
tracking - > act_track = slidedata - > track ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
op - > customdata = slidedata ;
2011-11-07 12:55:18 +00:00
hide_cursor ( C ) ;
WM_event_add_modal_handler ( C , op ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_GEOM | ND_SELECT , NULL ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_RUNNING_MODAL ;
}
return OPERATOR_PASS_THROUGH ;
}
static void cancel_mouse_slide ( SlideMarkerData * data )
{
2012-06-15 16:07:33 +00:00
MovieTrackingTrack * track = data - > track ;
MovieTrackingMarker * marker = data - > marker ;
2011-11-07 12:55:18 +00:00
2012-06-15 16:07:33 +00:00
memcpy ( marker - > pattern_corners , data - > old_corners , sizeof ( marker - > pattern_corners ) ) ;
copy_v2_v2 ( marker - > search_min , data - > old_search_min ) ;
copy_v2_v2 ( marker - > search_max , data - > old_search_max ) ;
copy_v2_v2 ( marker - > pos , data - > old_pos ) ;
copy_v2_v2 ( track - > offset , data - > old_offset ) ;
2011-11-07 12:55:18 +00:00
2012-06-15 16:07:33 +00:00
if ( data - > old_markers ) {
int a ;
for ( a = 0 ; a < data - > track - > markersnr ; a + + )
copy_v2_v2 ( data - > track - > markers [ a ] . pos , data - > old_markers [ a ] ) ;
2011-11-07 12:55:18 +00:00
}
}
static void free_slide_data ( SlideMarkerData * data )
{
2012-06-15 16:07:33 +00:00
if ( data - > old_markers )
MEM_freeN ( data - > old_markers ) ;
2012-03-25 23:19:21 +00:00
2011-11-07 12:55:18 +00:00
MEM_freeN ( data ) ;
}
static int slide_marker_modal ( bContext * C , wmOperator * op , wmEvent * event )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-07-26 22:41:40 +00:00
ARegion * ar = CTX_wm_region ( C ) ;
2012-03-25 23:19:21 +00:00
SlideMarkerData * data = ( SlideMarkerData * ) op - > customdata ;
2011-11-07 12:55:18 +00:00
float dx , dy , mdelta [ 2 ] ;
2012-04-28 06:31:57 +00:00
switch ( event - > type ) {
2011-11-07 12:55:18 +00:00
case LEFTCTRLKEY :
case RIGHTCTRLKEY :
case LEFTSHIFTKEY :
case RIGHTSHIFTKEY :
2012-03-25 23:19:21 +00:00
if ( data - > action = = SLIDE_ACTION_SIZE )
2012-03-24 06:38:07 +00:00
if ( ELEM ( event - > type , LEFTCTRLKEY , RIGHTCTRLKEY ) )
2012-03-25 23:19:21 +00:00
data - > lock = event - > val = = KM_RELEASE ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( ELEM ( event - > type , LEFTSHIFTKEY , RIGHTSHIFTKEY ) )
2012-03-25 23:19:21 +00:00
data - > accurate = event - > val = = KM_PRESS ;
2011-11-07 12:55:18 +00:00
2012-06-10 19:59:02 +00:00
/* no break! update area size */
2011-11-07 12:55:18 +00:00
case MOUSEMOVE :
2012-05-07 08:53:59 +00:00
mdelta [ 0 ] = event - > mval [ 0 ] - data - > mval [ 0 ] ;
mdelta [ 1 ] = event - > mval [ 1 ] - data - > mval [ 1 ] ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
dx = mdelta [ 0 ] / data - > width / sc - > zoom ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( data - > lock )
dy = - dx / data - > height * data - > width ;
else
dy = mdelta [ 1 ] / data - > height / sc - > zoom ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( data - > accurate ) {
2012-03-25 23:19:21 +00:00
dx / = 5 ;
dy / = 5 ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
if ( data - > area = = TRACK_AREA_POINT ) {
if ( data - > action = = SLIDE_ACTION_OFFSET ) {
2012-06-15 16:07:33 +00:00
data - > offset [ 0 ] = data - > old_offset [ 0 ] + dx ;
data - > offset [ 1 ] = data - > old_offset [ 1 ] + dy ;
2012-03-24 06:38:07 +00:00
}
else {
2012-06-15 16:07:33 +00:00
data - > pos [ 0 ] = data - > old_pos [ 0 ] + dx ;
data - > pos [ 1 ] = data - > old_pos [ 1 ] + dy ;
2011-11-07 12:55:18 +00:00
}
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_OBJECT | ND_TRANSFORM , NULL ) ;
2011-11-07 12:55:18 +00:00
DAG_id_tag_update ( & sc - > clip - > id , 0 ) ;
2012-03-24 06:38:07 +00:00
}
2012-06-15 16:07:33 +00:00
else if ( data - > area = = TRACK_AREA_PAT ) {
2012-03-25 23:19:21 +00:00
if ( data - > action = = SLIDE_ACTION_SIZE ) {
2012-06-15 18:31:46 +00:00
float start [ 2 ] , end [ 2 ] ;
float scale ;
2012-07-26 22:41:40 +00:00
ED_clip_point_stable_pos ( sc , ar , data - > mval [ 0 ] , data - > mval [ 1 ] , & start [ 0 ] , & start [ 1 ] ) ;
2012-06-15 18:31:46 +00:00
sub_v2_v2 ( start , data - > old_pos ) ;
if ( len_v2 ( start ) > 0.0f ) {
float mval [ 2 ] ;
if ( data - > accurate ) {
mval [ 0 ] = data - > mval [ 0 ] + ( event - > mval [ 0 ] - data - > mval [ 0 ] ) / 5.0f ;
mval [ 1 ] = data - > mval [ 1 ] + ( event - > mval [ 1 ] - data - > mval [ 1 ] ) / 5.0f ;
}
else {
mval [ 0 ] = event - > mval [ 0 ] ;
mval [ 1 ] = event - > mval [ 1 ] ;
}
2012-07-26 22:41:40 +00:00
ED_clip_point_stable_pos ( sc , ar , mval [ 0 ] , mval [ 1 ] , & end [ 0 ] , & end [ 1 ] ) ;
2012-06-15 18:31:46 +00:00
sub_v2_v2 ( end , data - > old_pos ) ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
2012-06-15 18:31:46 +00:00
scale = len_v2 ( end ) / len_v2 ( start ) ;
2011-11-07 12:55:18 +00:00
2012-06-15 18:31:46 +00:00
if ( scale > 0.0f ) {
int a ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
2012-06-15 18:31:46 +00:00
for ( a = 0 ; a < 4 ; a + + ) {
mul_v2_v2fl ( data - > corners [ a ] , data - > old_corners [ a ] , scale ) ;
}
}
}
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
2012-06-15 16:07:33 +00:00
BKE_tracking_marker_clamp ( data - > marker , CLAMP_PAT_DIM ) ;
2012-03-24 06:38:07 +00:00
}
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
else if ( data - > action = = SLIDE_ACTION_OFFSET ) {
2012-03-25 23:19:21 +00:00
float d [ 2 ] = { dx , dy } ;
2012-06-15 16:07:33 +00:00
int a ;
2011-11-07 12:55:18 +00:00
2012-06-15 16:07:33 +00:00
for ( a = 0 ; a < data - > track - > markersnr ; a + + )
add_v2_v2v2 ( data - > track - > markers [ a ] . pos , data - > old_markers [ a ] , d ) ;
2011-11-07 12:55:18 +00:00
2012-06-15 16:07:33 +00:00
sub_v2_v2v2 ( data - > offset , data - > old_offset , d ) ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
}
else if ( data - > action = = SLIDE_ACTION_POS ) {
2012-06-15 18:31:46 +00:00
float spos [ 2 ] ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
2012-06-15 18:31:46 +00:00
copy_v2_v2 ( spos , data - > pos ) ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
2012-06-15 18:31:46 +00:00
data - > pos [ 0 ] = data - > spos [ 0 ] + dx ;
data - > pos [ 1 ] = data - > spos [ 1 ] + dy ;
if ( ! slide_check_corners ( data - > corners ) ) {
copy_v2_v2 ( data - > pos , spos ) ;
}
/* currently only patterns are allowed to have such combination of event and data */
BKE_tracking_marker_clamp ( data - > marker , CLAMP_PAT_DIM ) ;
}
else if ( data - > action = = SLIDE_ACTION_TILT_SIZE ) {
float start [ 2 ] , end [ 2 ] ;
float scale = 1.0f , angle = 0.0f ;
int a ;
float mval [ 2 ] ;
if ( data - > accurate ) {
mval [ 0 ] = data - > mval [ 0 ] + ( event - > mval [ 0 ] - data - > mval [ 0 ] ) / 5.0f ;
mval [ 1 ] = data - > mval [ 1 ] + ( event - > mval [ 1 ] - data - > mval [ 1 ] ) / 5.0f ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
}
else {
2012-06-15 18:31:46 +00:00
mval [ 0 ] = event - > mval [ 0 ] ;
mval [ 1 ] = event - > mval [ 1 ] ;
}
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
2012-06-15 18:31:46 +00:00
sub_v2_v2v2 ( start , data - > spos , data - > old_pos ) ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
2012-07-26 22:41:40 +00:00
ED_clip_point_stable_pos ( sc , ar , mval [ 0 ] , mval [ 1 ] , & end [ 0 ] , & end [ 1 ] ) ;
2012-06-15 18:31:46 +00:00
sub_v2_v2 ( end , data - > old_pos ) ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
2012-06-15 18:31:46 +00:00
if ( len_v2 ( start ) > 0.0f ) {
scale = len_v2 ( end ) / len_v2 ( start ) ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
2012-06-15 18:31:46 +00:00
if ( scale < 0.0f ) {
scale = 0.0 ;
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
}
}
2012-06-15 18:31:46 +00:00
angle = - angle_signed_v2v2 ( start , end ) ;
for ( a = 0 ; a < 4 ; a + + ) {
float vec [ 2 ] ;
mul_v2_v2fl ( data - > corners [ a ] , data - > old_corners [ a ] , scale ) ;
copy_v2_v2 ( vec , data - > corners [ a ] ) ;
vec [ 0 ] * = data - > width ;
vec [ 1 ] * = data - > height ;
data - > corners [ a ] [ 0 ] = ( vec [ 0 ] * cos ( angle ) - vec [ 1 ] * sin ( angle ) ) / data - > width ;
data - > corners [ a ] [ 1 ] = ( vec [ 1 ] * cos ( angle ) + vec [ 0 ] * sin ( angle ) ) / data - > height ;
}
2012-06-15 11:03:23 +00:00
BKE_tracking_marker_clamp ( data - > marker , CLAMP_PAT_DIM ) ;
2012-06-15 18:31:46 +00:00
2011-11-07 12:55:18 +00:00
}
}
2012-06-15 16:07:33 +00:00
else if ( data - > area = = TRACK_AREA_SEARCH ) {
if ( data - > action = = SLIDE_ACTION_SIZE ) {
data - > min [ 0 ] = data - > old_search_min [ 0 ] - dx ;
data - > max [ 0 ] = data - > old_search_max [ 0 ] + dx ;
data - > min [ 1 ] = data - > old_search_min [ 1 ] + dy ;
data - > max [ 1 ] = data - > old_search_max [ 1 ] - dy ;
BKE_tracking_marker_clamp ( data - > marker , CLAMP_SEARCH_DIM ) ;
}
else if ( data - > area = = TRACK_AREA_SEARCH ) {
float d [ 2 ] = { dx , dy } ;
add_v2_v2v2 ( data - > min , data - > old_search_min , d ) ;
add_v2_v2v2 ( data - > max , data - > old_search_max , d ) ;
}
BKE_tracking_marker_clamp ( data - > marker , CLAMP_SEARCH_POS ) ;
}
2011-11-07 12:55:18 +00:00
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
data - > marker - > flag & = ~ MARKER_TRACKED ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EDITED , NULL ) ;
2011-11-07 12:55:18 +00:00
break ;
case LEFTMOUSE :
2012-03-25 23:19:21 +00:00
if ( event - > val = = KM_RELEASE ) {
2011-11-07 12:55:18 +00:00
free_slide_data ( op - > customdata ) ;
show_cursor ( C ) ;
return OPERATOR_FINISHED ;
}
break ;
case ESCKEY :
cancel_mouse_slide ( op - > customdata ) ;
free_slide_data ( op - > customdata ) ;
show_cursor ( C ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EDITED , NULL ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
}
return OPERATOR_RUNNING_MODAL ;
}
void CLIP_OT_slide_marker ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Slide Marker " ;
ot - > description = " Slide marker areas " ;
ot - > idname = " CLIP_OT_slide_marker " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-06-07 16:36:19 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2012-03-22 07:26:09 +00:00
ot - > invoke = slide_marker_invoke ;
ot - > modal = slide_marker_modal ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_POINTER | OPTYPE_BLOCKING ;
2011-11-07 12:55:18 +00:00
/* properties */
RNA_def_float_vector ( ot - > srna , " offset " , 2 , NULL , - FLT_MAX , FLT_MAX ,
2012-06-10 19:59:02 +00:00
" Offset " , " Offset in floating point units, 1.0 is the width and height of the image " , - FLT_MAX , FLT_MAX ) ;
2011-11-07 12:55:18 +00:00
}
/********************** track operator *********************/
typedef struct TrackMarkersJob {
2012-06-10 19:59:02 +00:00
struct MovieTrackingContext * context ; /* tracking context */
int sfra , efra , lastfra ; /* Start, end and recently tracked frames */
int backwards ; /* Backwards tracking flag */
MovieClip * clip ; /* Clip which is tracking */
float delay ; /* Delay in milliseconds to allow tracking at fixed FPS */
2011-11-07 12:55:18 +00:00
struct Main * main ;
struct Scene * scene ;
struct bScreen * screen ;
} TrackMarkersJob ;
static int track_markers_testbreak ( void )
{
2012-08-08 18:37:06 +00:00
return G . is_break ;
2011-11-07 12:55:18 +00:00
}
static int track_count_markers ( SpaceClip * sc , MovieClip * clip )
{
2012-03-25 23:19:21 +00:00
int tot = 0 ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( & clip - > tracking ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-06-19 14:26:29 +00:00
int framenr = ED_space_clip_get_clip_frame_number ( sc ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
if ( TRACK_VIEW_SELECTED ( sc , track ) & & ( track - > flag & TRACK_LOCKED ) = = 0 ) {
2012-06-15 11:03:23 +00:00
MovieTrackingMarker * marker = BKE_tracking_marker_get ( track , framenr ) ;
2011-12-04 10:57:36 +00:00
2012-03-25 23:19:21 +00:00
if ( ! marker | | ( marker - > flag & MARKER_DISABLED ) = = 0 )
2011-12-04 10:57:36 +00:00
tot + + ;
}
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
return tot ;
}
2012-01-09 20:18:48 +00:00
static void clear_invisible_track_selection ( SpaceClip * sc , MovieClip * clip )
{
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( & clip - > tracking ) ;
2012-01-09 20:18:48 +00:00
int hidden = 0 ;
2012-05-07 08:53:59 +00:00
if ( ( sc - > flag & SC_SHOW_MARKER_PATTERN ) = = 0 )
2012-01-09 20:18:48 +00:00
hidden | = TRACK_AREA_PAT ;
2012-05-07 08:53:59 +00:00
if ( ( sc - > flag & SC_SHOW_MARKER_SEARCH ) = = 0 )
2012-01-09 20:18:48 +00:00
hidden | = TRACK_AREA_SEARCH ;
if ( hidden ) {
MovieTrackingTrack * track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-02-26 08:14:14 +00:00
if ( ( track - > flag & TRACK_HIDDEN ) = = 0 )
2012-06-15 11:03:23 +00:00
BKE_tracking_track_flag_clear ( track , hidden , SELECT ) ;
2012-01-09 20:18:48 +00:00
track = track - > next ;
}
}
}
2011-11-28 13:26:46 +00:00
static void track_init_markers ( SpaceClip * sc , MovieClip * clip , int * frames_limit_r )
2011-11-07 12:55:18 +00:00
{
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( & clip - > tracking ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-06-19 14:26:29 +00:00
int framenr = ED_space_clip_get_clip_frame_number ( sc ) ;
2012-03-25 23:19:21 +00:00
int frames_limit = 0 ;
2011-11-07 12:55:18 +00:00
2012-01-09 20:18:48 +00:00
clear_invisible_track_selection ( sc , clip ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
if ( TRACK_VIEW_SELECTED ( sc , track ) ) {
2012-05-07 08:53:59 +00:00
if ( ( track - > flag & TRACK_HIDDEN ) = = 0 & & ( track - > flag & TRACK_LOCKED ) = = 0 ) {
2012-06-15 11:03:23 +00:00
BKE_tracking_marker_ensure ( track , framenr ) ;
2011-11-28 13:26:46 +00:00
2012-03-24 06:38:07 +00:00
if ( track - > frames_limit ) {
2012-03-25 23:19:21 +00:00
if ( frames_limit = = 0 )
frames_limit = track - > frames_limit ;
2011-11-28 13:26:46 +00:00
else
2012-03-25 23:19:21 +00:00
frames_limit = MIN2 ( frames_limit , track - > frames_limit ) ;
2011-11-28 13:26:46 +00:00
}
}
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2011-11-28 13:26:46 +00:00
2012-03-25 23:19:21 +00:00
* frames_limit_r = frames_limit ;
2011-11-07 12:55:18 +00:00
}
static int track_markers_check_direction ( int backwards , int curfra , int efra )
{
2012-03-24 06:38:07 +00:00
if ( backwards ) {
2012-03-25 23:19:21 +00:00
if ( curfra < efra )
return FALSE ;
2011-11-07 12:55:18 +00:00
}
else {
2012-03-25 23:19:21 +00:00
if ( curfra > efra )
return FALSE ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
return TRUE ;
2011-11-07 12:55:18 +00:00
}
static int track_markers_initjob ( bContext * C , TrackMarkersJob * tmj , int backwards )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
Scene * scene = CTX_data_scene ( C ) ;
MovieTrackingSettings * settings = & clip - > tracking . settings ;
2011-11-28 13:26:46 +00:00
int frames_limit ;
track_init_markers ( sc , clip , & frames_limit ) ;
2011-11-07 12:55:18 +00:00
2012-06-19 14:26:29 +00:00
tmj - > sfra = ED_space_clip_get_clip_frame_number ( sc ) ;
2012-03-25 23:19:21 +00:00
tmj - > clip = clip ;
tmj - > backwards = backwards ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( backwards )
tmj - > efra = SFRA ;
else
tmj - > efra = EFRA ;
2011-11-07 12:55:18 +00:00
/* limit frames to be tracked by user setting */
2012-03-24 06:38:07 +00:00
if ( frames_limit ) {
2012-03-25 23:19:21 +00:00
if ( backwards )
tmj - > efra = MAX2 ( tmj - > efra , tmj - > sfra - frames_limit ) ;
else
tmj - > efra = MIN2 ( tmj - > efra , tmj - > sfra + frames_limit ) ;
2011-11-07 12:55:18 +00:00
}
2012-06-06 18:58:30 +00:00
tmj - > efra = BKE_movieclip_remap_scene_to_clip_frame ( clip , tmj - > efra ) ;
2012-03-25 23:19:21 +00:00
if ( settings - > speed ! = TRACKING_SPEED_FASTEST ) {
tmj - > delay = 1.0f / scene - > r . frs_sec * 1000.0f ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( settings - > speed = = TRACKING_SPEED_HALF )
tmj - > delay * = 2 ;
else if ( settings - > speed = = TRACKING_SPEED_QUARTER )
tmj - > delay * = 4 ;
else if ( settings - > speed = = TRACKING_SPEED_DOUBLE )
tmj - > delay / = 2 ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
tmj - > context = BKE_tracking_context_new ( clip , & sc - > user , backwards , 1 ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
clip - > tracking_context = tmj - > context ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
tmj - > lastfra = tmj - > sfra ;
2011-11-07 12:55:18 +00:00
2012-03-04 04:35:12 +00:00
/* XXX: silly to store this, but this data is needed to update scene and movie-clip
2012-03-03 16:31:46 +00:00
* frame numbers when tracking is finished . This introduces better feedback for artists .
* Maybe there ' s another way to solve this problem , but can ' t think better way atm .
* Anyway , this way isn ' t more unstable as animation rendering animation
* which uses the same approach ( except storing screen ) . */
2012-03-25 23:19:21 +00:00
tmj - > scene = scene ;
tmj - > main = CTX_data_main ( C ) ;
tmj - > screen = CTX_wm_screen ( C ) ;
2011-11-07 12:55:18 +00:00
return track_markers_check_direction ( backwards , tmj - > sfra , tmj - > efra ) ;
}
static void track_markers_startjob ( void * tmv , short * stop , short * do_update , float * progress )
{
2012-03-25 23:19:21 +00:00
TrackMarkersJob * tmj = ( TrackMarkersJob * ) tmv ;
int framenr = tmj - > sfra ;
//double t = PIL_check_seconds_timer();
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
while ( framenr ! = tmj - > efra ) {
2012-03-25 23:19:21 +00:00
if ( tmj - > delay > 0 ) {
2011-11-07 12:55:18 +00:00
/* tracking should happen with fixed fps. Calculate time
2012-03-03 16:31:46 +00:00
* using current timer value before tracking frame and after .
*
* Small ( and maybe unneeded optimization ) : do not calculate exec_time
* for " Fastest " tracking */
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
double start_time = PIL_check_seconds_timer ( ) , exec_time ;
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
if ( ! BKE_tracking_context_step ( tmj - > context ) )
2011-11-07 12:55:18 +00:00
break ;
2012-05-07 08:53:59 +00:00
exec_time = PIL_check_seconds_timer ( ) - start_time ;
2012-03-24 06:38:07 +00:00
if ( tmj - > delay > ( float ) exec_time )
2012-05-07 08:53:59 +00:00
PIL_sleep_ms ( tmj - > delay - ( float ) exec_time ) ;
2012-03-24 06:38:07 +00:00
}
2012-06-15 11:03:23 +00:00
else if ( ! BKE_tracking_context_step ( tmj - > context ) )
2012-06-10 19:59:02 +00:00
break ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
* do_update = TRUE ;
2012-05-07 08:53:59 +00:00
* progress = ( float ) ( framenr - tmj - > sfra ) / ( tmj - > efra - tmj - > sfra ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( tmj - > backwards )
framenr - - ;
else
framenr + + ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
tmj - > lastfra = framenr ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( * stop | | track_markers_testbreak ( ) )
2011-11-07 12:55:18 +00:00
break ;
}
//printf("Tracking time: %lf\n", PIL_check_seconds_timer()-t);
}
static void track_markers_updatejob ( void * tmv )
{
2012-03-25 23:19:21 +00:00
TrackMarkersJob * tmj = ( TrackMarkersJob * ) tmv ;
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_context_sync ( tmj - > context ) ;
2011-11-07 12:55:18 +00:00
}
static void track_markers_freejob ( void * tmv )
{
2012-03-25 23:19:21 +00:00
TrackMarkersJob * tmj = ( TrackMarkersJob * ) tmv ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
tmj - > clip - > tracking_context = NULL ;
2012-06-06 18:58:30 +00:00
tmj - > scene - > r . cfra = BKE_movieclip_remap_clip_to_scene_frame ( tmj - > clip , tmj - > lastfra ) ;
2012-05-25 12:37:11 +00:00
ED_update_for_newframe ( tmj - > main , tmj - > scene , 0 ) ;
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_context_sync ( tmj - > context ) ;
2011-11-07 12:55:18 +00:00
BKE_tracking_context_free ( tmj - > context ) ;
MEM_freeN ( tmj ) ;
2012-05-07 08:53:59 +00:00
WM_main_add_notifier ( NC_SCENE | ND_FRAME , tmj - > scene ) ;
2011-11-07 12:55:18 +00:00
}
static int track_markers_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
Scene * scene = CTX_data_scene ( C ) ;
2011-11-07 12:55:18 +00:00
struct MovieTrackingContext * context ;
2012-06-19 14:26:29 +00:00
int framenr = ED_space_clip_get_clip_frame_number ( sc ) ;
2012-03-25 23:19:21 +00:00
int sfra = framenr , efra ;
int backwards = RNA_boolean_get ( op - > ptr , " backwards " ) ;
int sequence = RNA_boolean_get ( op - > ptr , " sequence " ) ;
2011-11-28 13:26:46 +00:00
int frames_limit ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
if ( track_count_markers ( sc , clip ) = = 0 )
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
2011-11-28 13:26:46 +00:00
track_init_markers ( sc , clip , & frames_limit ) ;
2012-03-25 23:19:21 +00:00
if ( backwards )
efra = SFRA ;
else
efra = EFRA ;
2011-11-07 12:55:18 +00:00
/* limit frames to be tracked by user setting */
2012-03-24 06:38:07 +00:00
if ( frames_limit ) {
2012-05-07 08:53:59 +00:00
if ( backwards )
efra = MAX2 ( efra , sfra - frames_limit ) ;
else
efra = MIN2 ( efra , sfra + frames_limit ) ;
2011-11-07 12:55:18 +00:00
}
2012-06-06 18:58:30 +00:00
efra = BKE_movieclip_remap_scene_to_clip_frame ( clip , efra ) ;
2012-03-24 06:38:07 +00:00
if ( ! track_markers_check_direction ( backwards , framenr , efra ) )
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
/* do not disable tracks due to threshold when tracking frame-by-frame */
2012-03-25 23:19:21 +00:00
context = BKE_tracking_context_new ( clip , & sc - > user , backwards , sequence ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
while ( framenr ! = efra ) {
2012-06-15 11:03:23 +00:00
if ( ! BKE_tracking_context_step ( context ) )
2011-11-07 12:55:18 +00:00
break ;
2012-03-24 06:38:07 +00:00
if ( backwards ) framenr - - ;
2011-11-07 12:55:18 +00:00
else framenr + + ;
2012-03-24 06:38:07 +00:00
if ( ! sequence )
2011-11-07 12:55:18 +00:00
break ;
}
2012-06-15 11:03:23 +00:00
BKE_tracking_context_sync ( context ) ;
2011-11-07 12:55:18 +00:00
BKE_tracking_context_free ( context ) ;
/* update scene current frame to the lastes tracked frame */
2012-06-06 18:58:30 +00:00
scene - > r . cfra = BKE_movieclip_remap_clip_to_scene_frame ( clip , framenr ) ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EVALUATED , clip ) ;
WM_event_add_notifier ( C , NC_SCENE | ND_FRAME , scene ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
static int track_markers_invoke ( bContext * C , wmOperator * op , wmEvent * UNUSED ( event ) )
{
TrackMarkersJob * tmj ;
2012-03-25 23:19:21 +00:00
ScrArea * sa = CTX_wm_area ( C ) ;
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-08-15 10:03:29 +00:00
wmJob * wm_job ;
2012-03-25 23:19:21 +00:00
int backwards = RNA_boolean_get ( op - > ptr , " backwards " ) ;
int sequence = RNA_boolean_get ( op - > ptr , " sequence " ) ;
2011-11-07 12:55:18 +00:00
2012-08-15 09:42:06 +00:00
if ( WM_jobs_test ( CTX_wm_manager ( C ) , CTX_wm_area ( C ) , WM_JOB_TYPE_ANY ) ) {
2011-12-05 18:57:17 +00:00
/* only one tracking is allowed at a time */
return OPERATOR_CANCELLED ;
}
2012-03-24 06:38:07 +00:00
if ( clip - > tracking_context )
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
2012-05-07 08:53:59 +00:00
if ( track_count_markers ( sc , clip ) = = 0 )
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
2012-03-24 06:38:07 +00:00
if ( ! sequence )
2011-11-07 12:55:18 +00:00
return track_markers_exec ( C , op ) ;
2012-03-25 23:19:21 +00:00
tmj = MEM_callocN ( sizeof ( TrackMarkersJob ) , " TrackMarkersJob data " ) ;
2012-03-24 06:38:07 +00:00
if ( ! track_markers_initjob ( C , tmj , backwards ) ) {
2011-11-07 12:55:18 +00:00
track_markers_freejob ( tmj ) ;
return OPERATOR_CANCELLED ;
}
/* setup job */
2012-08-15 10:03:29 +00:00
wm_job = WM_jobs_get ( CTX_wm_manager ( C ) , CTX_wm_window ( C ) , sa , " Track Markers " ,
WM_JOB_PROGRESS , WM_JOB_TYPE_CLIP_TRACK_MARKERS ) ;
WM_jobs_customdata_set ( wm_job , tmj , track_markers_freejob ) ;
2011-11-07 12:55:18 +00:00
/* if there's delay set in tracking job, tracking should happen
2012-03-08 04:12:11 +00:00
* with fixed FPS . To deal with editor refresh we have to synchronize
2012-03-03 16:31:46 +00:00
* tracks from job and tracks in clip . Do this in timer callback
* to prevent threading conflicts . */
2012-05-07 08:53:59 +00:00
if ( tmj - > delay > 0 )
2012-08-15 10:03:29 +00:00
WM_jobs_timer ( wm_job , tmj - > delay / 1000.0f , NC_MOVIECLIP | NA_EVALUATED , 0 ) ;
2012-05-07 08:53:59 +00:00
else
2012-08-15 10:03:29 +00:00
WM_jobs_timer ( wm_job , 0.2 , NC_MOVIECLIP | NA_EVALUATED , 0 ) ;
2011-11-07 12:55:18 +00:00
2012-08-15 10:03:29 +00:00
WM_jobs_callbacks ( wm_job , track_markers_startjob , NULL , track_markers_updatejob , NULL ) ;
2011-11-07 12:55:18 +00:00
2012-08-08 18:37:06 +00:00
G . is_break = FALSE ;
2011-11-07 12:55:18 +00:00
2012-08-15 10:03:29 +00:00
WM_jobs_start ( CTX_wm_manager ( C ) , wm_job ) ;
2011-11-07 12:55:18 +00:00
WM_cursor_wait ( 0 ) ;
/* add modal handler for ESC */
WM_event_add_modal_handler ( C , op ) ;
return OPERATOR_RUNNING_MODAL ;
}
static int track_markers_modal ( bContext * C , wmOperator * UNUSED ( op ) , wmEvent * event )
{
2011-11-28 13:49:42 +00:00
/* no running tracking, remove handler and pass through */
2012-08-15 09:42:06 +00:00
if ( 0 = = WM_jobs_test ( CTX_wm_manager ( C ) , CTX_wm_area ( C ) , WM_JOB_TYPE_ANY ) )
2012-05-07 08:53:59 +00:00
return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH ;
2011-11-07 12:55:18 +00:00
/* running tracking */
switch ( event - > type ) {
case ESCKEY :
return OPERATOR_RUNNING_MODAL ;
break ;
}
return OPERATOR_PASS_THROUGH ;
}
void CLIP_OT_track_markers ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Track Markers " ;
ot - > description = " Track selected markers " ;
ot - > idname = " CLIP_OT_track_markers " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = track_markers_exec ;
ot - > invoke = track_markers_invoke ;
2012-06-07 16:36:19 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2012-03-22 07:26:09 +00:00
ot - > modal = track_markers_modal ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-03-22 07:26:09 +00:00
ot - > flag = OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* properties */
RNA_def_boolean ( ot - > srna , " backwards " , 0 , " Backwards " , " Do backwards tracking " ) ;
RNA_def_boolean ( ot - > srna , " sequence " , 0 , " Track Sequence " , " Track marker during image sequence rather than single image " ) ;
}
/********************** solve camera operator *********************/
2011-11-28 13:49:42 +00:00
typedef struct {
Scene * scene ;
MovieClip * clip ;
MovieClipUser user ;
ReportList * reports ;
char stats_message [ 256 ] ;
struct MovieReconstructContext * context ;
} SolveCameraJob ;
static int solve_camera_initjob ( bContext * C , SolveCameraJob * scj , wmOperator * op , char * error_msg , int max_error )
2011-11-07 12:55:18 +00:00
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
Scene * scene = CTX_data_scene ( C ) ;
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
MovieTrackingObject * object = BKE_tracking_object_get_active ( tracking ) ;
2011-11-07 12:55:18 +00:00
int width , height ;
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
2012-06-15 11:03:23 +00:00
if ( ! BKE_tracking_reconstruction_check ( tracking , object , error_msg , max_error ) )
2011-11-28 13:49:42 +00:00
return 0 ;
2011-11-07 12:55:18 +00:00
/* could fail if footage uses images with different sizes */
2011-11-08 06:11:23 +00:00
BKE_movieclip_get_size ( clip , & sc - > user , & width , & height ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
scj - > clip = clip ;
scj - > scene = scene ;
scj - > reports = op - > reports ;
scj - > user = sc - > user ;
2011-11-28 13:49:42 +00:00
2012-03-25 23:19:21 +00:00
scj - > context = BKE_tracking_reconstruction_context_new ( tracking , object ,
2012-10-09 10:33:18 +00:00
object - > keyframe1 , object - > keyframe2 , width , height ) ;
2011-11-28 13:49:42 +00:00
2012-03-25 23:19:21 +00:00
tracking - > stats = MEM_callocN ( sizeof ( MovieTrackingStats ) , " solve camera stats " ) ;
2011-11-28 13:49:42 +00:00
return 1 ;
}
static void solve_camera_updatejob ( void * scv )
{
2012-03-25 23:19:21 +00:00
SolveCameraJob * scj = ( SolveCameraJob * ) scv ;
MovieTracking * tracking = & scj - > clip - > tracking ;
2011-11-28 13:49:42 +00:00
BLI_strncpy ( tracking - > stats - > message , scj - > stats_message , sizeof ( tracking - > stats - > message ) ) ;
}
static void solve_camera_startjob ( void * scv , short * stop , short * do_update , float * progress )
{
2012-03-25 23:19:21 +00:00
SolveCameraJob * scj = ( SolveCameraJob * ) scv ;
2011-11-28 13:49:42 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_reconstruction_solve ( scj - > context , stop , do_update , progress ,
2012-06-10 19:59:02 +00:00
scj - > stats_message , sizeof ( scj - > stats_message ) ) ;
2011-11-28 13:49:42 +00:00
}
static void solve_camera_freejob ( void * scv )
{
2012-03-25 23:19:21 +00:00
SolveCameraJob * scj = ( SolveCameraJob * ) scv ;
MovieTracking * tracking = & scj - > clip - > tracking ;
Scene * scene = scj - > scene ;
MovieClip * clip = scj - > clip ;
2011-11-28 13:49:42 +00:00
int solved ;
2012-03-24 06:38:07 +00:00
if ( ! scj - > context ) {
2011-11-28 13:49:42 +00:00
/* job weren't fully initialized due to some error */
MEM_freeN ( scj ) ;
return ;
}
2012-06-15 11:03:23 +00:00
solved = BKE_tracking_reconstruction_finish ( scj - > context , tracking ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( ! solved )
2011-11-28 13:49:42 +00:00
BKE_report ( scj - > reports , RPT_WARNING , " Some data failed to reconstruct, see console for details " ) ;
2011-11-07 12:55:18 +00:00
else
2012-03-08 04:12:11 +00:00
BKE_reportf ( scj - > reports , RPT_INFO , " Average re-projection error %.3f " , tracking - > reconstruction . error ) ;
2011-11-07 12:55:18 +00:00
2011-11-28 13:49:42 +00:00
/* set currently solved clip as active for scene */
2012-03-24 06:38:07 +00:00
if ( scene - > clip )
2011-11-08 06:11:23 +00:00
id_us_min ( & clip - > id ) ;
2012-03-25 23:19:21 +00:00
scene - > clip = clip ;
2011-11-07 12:55:18 +00:00
id_us_plus ( & clip - > id ) ;
2011-11-28 13:49:42 +00:00
/* set blender camera focal length so result would look fine there */
2012-03-24 06:38:07 +00:00
if ( scene - > camera ) {
2012-06-10 19:59:02 +00:00
Camera * camera = ( Camera * ) scene - > camera - > data ;
2011-11-28 13:49:42 +00:00
int width , height ;
BKE_movieclip_get_size ( clip , & scj - > user , & width , & height ) ;
2011-11-07 12:55:18 +00:00
BKE_tracking_camera_to_blender ( tracking , scene , camera , width , height ) ;
2011-11-28 13:49:42 +00:00
WM_main_add_notifier ( NC_OBJECT , camera ) ;
2011-11-07 12:55:18 +00:00
}
2011-11-28 13:49:42 +00:00
MEM_freeN ( tracking - > stats ) ;
2012-03-25 23:19:21 +00:00
tracking - > stats = NULL ;
2011-11-28 13:49:42 +00:00
2011-11-07 12:55:18 +00:00
DAG_id_tag_update ( & clip - > id , 0 ) ;
2012-05-07 08:53:59 +00:00
WM_main_add_notifier ( NC_MOVIECLIP | NA_EVALUATED , clip ) ;
WM_main_add_notifier ( NC_OBJECT | ND_TRANSFORM , NULL ) ;
2011-11-07 12:55:18 +00:00
/* update active clip displayed in scene buttons */
2011-11-28 13:49:42 +00:00
WM_main_add_notifier ( NC_SCENE , scene ) ;
BKE_tracking_reconstruction_context_free ( scj - > context ) ;
MEM_freeN ( scj ) ;
}
static int solve_camera_exec ( bContext * C , wmOperator * op )
{
SolveCameraJob * scj ;
2012-03-25 23:19:21 +00:00
char error_msg [ 256 ] = " \0 " ;
2011-11-28 13:49:42 +00:00
2012-03-25 23:19:21 +00:00
scj = MEM_callocN ( sizeof ( SolveCameraJob ) , " SolveCameraJob data " ) ;
2012-03-24 06:38:07 +00:00
if ( ! solve_camera_initjob ( C , scj , op , error_msg , sizeof ( error_msg ) ) ) {
if ( error_msg [ 0 ] )
2011-11-28 13:49:42 +00:00
BKE_report ( op - > reports , RPT_ERROR , error_msg ) ;
solve_camera_freejob ( scj ) ;
return OPERATOR_CANCELLED ;
}
solve_camera_startjob ( scj , NULL , NULL , NULL ) ;
solve_camera_freejob ( scj ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
2011-11-28 13:49:42 +00:00
static int solve_camera_invoke ( bContext * C , wmOperator * op , wmEvent * UNUSED ( event ) )
{
SolveCameraJob * scj ;
2012-03-25 23:19:21 +00:00
ScrArea * sa = CTX_wm_area ( C ) ;
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
MovieTrackingReconstruction * reconstruction = BKE_tracking_get_active_reconstruction ( tracking ) ;
2012-08-15 10:03:29 +00:00
wmJob * wm_job ;
2012-03-25 23:19:21 +00:00
char error_msg [ 256 ] = " \0 " ;
2011-11-28 13:49:42 +00:00
2012-08-15 09:42:06 +00:00
if ( WM_jobs_test ( CTX_wm_manager ( C ) , CTX_wm_area ( C ) , WM_JOB_TYPE_ANY ) ) {
2011-12-05 18:57:17 +00:00
/* only one solve is allowed at a time */
return OPERATOR_CANCELLED ;
}
2012-03-25 23:19:21 +00:00
scj = MEM_callocN ( sizeof ( SolveCameraJob ) , " SolveCameraJob data " ) ;
2012-03-24 06:38:07 +00:00
if ( ! solve_camera_initjob ( C , scj , op , error_msg , sizeof ( error_msg ) ) ) {
if ( error_msg [ 0 ] )
2011-11-28 13:49:42 +00:00
BKE_report ( op - > reports , RPT_ERROR , error_msg ) ;
solve_camera_freejob ( scj ) ;
return OPERATOR_CANCELLED ;
}
BLI_strncpy ( tracking - > stats - > message , " Solving camera | Preparing solve " , sizeof ( tracking - > stats - > message ) ) ;
/* hide reconstruction statistics from previous solve */
2012-03-25 23:19:21 +00:00
reconstruction - > flag & = ~ TRACKING_RECONSTRUCTED ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EVALUATED , clip ) ;
2011-11-28 13:49:42 +00:00
/* setup job */
2012-08-15 10:03:29 +00:00
wm_job = WM_jobs_get ( CTX_wm_manager ( C ) , CTX_wm_window ( C ) , sa , " Solve Camera " ,
WM_JOB_PROGRESS , WM_JOB_TYPE_CLIP_SOLVE_CAMERA ) ;
WM_jobs_customdata_set ( wm_job , scj , solve_camera_freejob ) ;
WM_jobs_timer ( wm_job , 0.1 , NC_MOVIECLIP | NA_EVALUATED , 0 ) ;
WM_jobs_callbacks ( wm_job , solve_camera_startjob , NULL , solve_camera_updatejob , NULL ) ;
2011-11-28 13:49:42 +00:00
2012-08-08 18:37:06 +00:00
G . is_break = FALSE ;
2011-11-28 13:49:42 +00:00
2012-08-15 10:03:29 +00:00
WM_jobs_start ( CTX_wm_manager ( C ) , wm_job ) ;
2011-11-28 13:49:42 +00:00
WM_cursor_wait ( 0 ) ;
/* add modal handler for ESC */
WM_event_add_modal_handler ( C , op ) ;
return OPERATOR_RUNNING_MODAL ;
}
static int solve_camera_modal ( bContext * C , wmOperator * UNUSED ( op ) , wmEvent * event )
{
/* no running solver, remove handler and pass through */
2012-08-15 09:42:06 +00:00
if ( 0 = = WM_jobs_test ( CTX_wm_manager ( C ) , CTX_wm_area ( C ) , WM_JOB_TYPE_ANY ) )
2012-05-07 08:53:59 +00:00
return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH ;
2011-11-28 13:49:42 +00:00
/* running tracking */
switch ( event - > type ) {
case ESCKEY :
return OPERATOR_RUNNING_MODAL ;
break ;
}
return OPERATOR_PASS_THROUGH ;
}
2011-11-07 12:55:18 +00:00
void CLIP_OT_solve_camera ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Solve Camera " ;
ot - > description = " Solve camera motion from tracks " ;
ot - > idname = " CLIP_OT_solve_camera " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = solve_camera_exec ;
ot - > invoke = solve_camera_invoke ;
ot - > modal = solve_camera_modal ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** clear solution operator *********************/
static int clear_solution_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( & clip - > tracking ) ;
MovieTrackingReconstruction * reconstruction = BKE_tracking_get_active_reconstruction ( tracking ) ;
2012-03-25 23:19:21 +00:00
MovieTrackingTrack * track = tracksbase - > first ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
track - > flag & = ~ TRACK_HAS_BUNDLE ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2012-03-24 06:38:07 +00:00
if ( reconstruction - > cameras )
2011-12-05 18:57:17 +00:00
MEM_freeN ( reconstruction - > cameras ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
reconstruction - > cameras = NULL ;
reconstruction - > camnr = 0 ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
reconstruction - > flag & = ~ TRACKING_RECONSTRUCTED ;
2011-11-07 12:55:18 +00:00
DAG_id_tag_update ( & clip - > id , 0 ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EVALUATED , clip ) ;
WM_event_add_notifier ( C , NC_SPACE | ND_SPACE_VIEW3D , NULL ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_clear_solution ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Clear Solution " ;
ot - > description = " Clear all calculated data " ;
ot - > idname = " CLIP_OT_clear_solution " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = clear_solution_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** clear track operator *********************/
static int clear_track_path_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-06-24 18:00:14 +00:00
MovieTracking * tracking = & clip - > tracking ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-06-24 18:00:14 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2012-03-25 23:19:21 +00:00
int action = RNA_enum_get ( op - > ptr , " action " ) ;
int clear_active = RNA_boolean_get ( op - > ptr , " clear_active " ) ;
2012-06-19 14:26:29 +00:00
int framenr = ED_space_clip_get_clip_frame_number ( sc ) ;
2011-11-07 12:55:18 +00:00
2012-03-08 16:27:53 +00:00
if ( clear_active ) {
2012-06-24 18:00:14 +00:00
track = BKE_tracking_track_get_active ( tracking ) ;
2012-06-15 11:03:23 +00:00
BKE_tracking_track_path_clear ( track , framenr , action ) ;
2012-03-08 16:27:53 +00:00
}
else {
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
if ( TRACK_VIEW_SELECTED ( sc , track ) )
2012-06-15 11:03:23 +00:00
BKE_tracking_track_path_clear ( track , framenr , action ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = track - > next ;
2012-03-08 16:27:53 +00:00
}
2011-11-07 12:55:18 +00:00
}
2012-06-24 18:00:14 +00:00
BKE_tracking_dopesheet_tag_update ( tracking ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EVALUATED , clip ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_clear_track_path ( wmOperatorType * ot )
{
static EnumPropertyItem clear_path_actions [ ] = {
2012-06-10 19:59:02 +00:00
{ TRACK_CLEAR_UPTO , " UPTO " , 0 , " Clear up-to " , " Clear path up to current frame " } ,
{ TRACK_CLEAR_REMAINED , " REMAINED " , 0 , " Clear remained " , " Clear path at remaining frames (after current) " } ,
{ TRACK_CLEAR_ALL , " ALL " , 0 , " Clear all " , " Clear the whole path " } ,
{ 0 , NULL , 0 , NULL , NULL }
2011-11-07 12:55:18 +00:00
} ;
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Clear Track Path " ;
ot - > description = " Clear tracks after/before current position or clear the whole track " ;
ot - > idname = " CLIP_OT_clear_track_path " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = clear_track_path_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* proeprties */
RNA_def_enum ( ot - > srna , " action " , clear_path_actions , TRACK_CLEAR_REMAINED , " Action " , " Clear action to execute " ) ;
2012-03-08 16:27:53 +00:00
RNA_def_boolean ( ot - > srna , " clear_active " , 0 , " Clear Active " , " Clear active track only instead of all selected tracks " ) ;
2011-11-07 12:55:18 +00:00
}
/********************** disable markers operator *********************/
static int disable_markers_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2012-03-25 23:19:21 +00:00
MovieTrackingTrack * track = tracksbase - > first ;
int action = RNA_enum_get ( op - > ptr , " action " ) ;
2012-06-19 14:26:29 +00:00
int framenr = ED_space_clip_get_clip_frame_number ( sc ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-05-07 08:53:59 +00:00
if ( TRACK_VIEW_SELECTED ( sc , track ) & & ( track - > flag & TRACK_LOCKED ) = = 0 ) {
2012-06-15 11:03:23 +00:00
MovieTrackingMarker * marker = BKE_tracking_marker_ensure ( track , framenr ) ;
2012-03-25 23:19:21 +00:00
if ( action = = 0 )
marker - > flag | = MARKER_DISABLED ;
else if ( action = = 1 )
marker - > flag & = ~ MARKER_DISABLED ;
else marker - > flag ^ = MARKER_DISABLED ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
DAG_id_tag_update ( & clip - > id , 0 ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EVALUATED , clip ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_disable_markers ( wmOperatorType * ot )
{
static EnumPropertyItem actions_items [ ] = {
2012-06-10 19:59:02 +00:00
{ 0 , " DISABLE " , 0 , " Disable " , " Disable selected markers " } ,
{ 1 , " ENABLE " , 0 , " Enable " , " Enable selected markers " } ,
{ 2 , " TOGGLE " , 0 , " Toggle " , " Toggle disabled flag for selected markers " } ,
{ 0 , NULL , 0 , NULL , NULL }
2011-11-07 12:55:18 +00:00
} ;
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Disable Markers " ;
ot - > description = " Disable/enable selected markers " ;
ot - > idname = " CLIP_OT_disable_markers " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = disable_markers_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* properties */
RNA_def_enum ( ot - > srna , " action " , actions_items , 0 , " Action " , " Disable action to execute " ) ;
}
/********************** set origin operator *********************/
2011-12-21 14:51:01 +00:00
static Object * get_camera_with_movieclip ( Scene * scene , MovieClip * clip )
{
2012-03-25 23:19:21 +00:00
Object * camera = scene - > camera ;
2011-12-21 14:51:01 +00:00
Base * base ;
2012-05-07 08:53:59 +00:00
if ( camera & & BKE_object_movieclip_get ( scene , camera , 0 ) = = clip )
2011-12-21 14:51:01 +00:00
return camera ;
2012-03-25 23:19:21 +00:00
base = scene - > base . first ;
2012-03-24 06:38:07 +00:00
while ( base ) {
if ( base - > object - > type = = OB_CAMERA ) {
2012-05-07 08:53:59 +00:00
if ( BKE_object_movieclip_get ( scene , base - > object , 0 ) = = clip ) {
2012-03-25 23:19:21 +00:00
camera = base - > object ;
2011-12-21 14:51:01 +00:00
break ;
}
}
2012-03-25 23:19:21 +00:00
base = base - > next ;
2011-12-21 14:51:01 +00:00
}
return camera ;
}
static Object * get_orientation_object ( bContext * C )
{
2012-03-25 23:19:21 +00:00
Scene * scene = CTX_data_scene ( C ) ;
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
MovieTrackingObject * tracking_object = BKE_tracking_object_get_active ( tracking ) ;
2012-03-25 23:19:21 +00:00
Object * object = NULL ;
2011-12-21 14:51:01 +00:00
2012-03-25 23:19:21 +00:00
if ( tracking_object - > flag & TRACKING_OBJECT_CAMERA ) {
object = get_camera_with_movieclip ( scene , clip ) ;
2011-12-21 14:51:01 +00:00
}
else {
2012-03-25 23:19:21 +00:00
object = OBACT ;
2011-12-21 14:51:01 +00:00
}
2012-03-24 06:38:07 +00:00
if ( object & & object - > parent )
2012-03-25 23:19:21 +00:00
object = object - > parent ;
2011-12-21 14:51:01 +00:00
return object ;
}
2011-12-18 18:31:02 +00:00
static int set_orientation_poll ( bContext * C )
{
2012-06-07 16:36:19 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-03-25 23:19:21 +00:00
2012-06-08 08:24:08 +00:00
if ( sc ) {
Scene * scene = CTX_data_scene ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-06-08 08:24:08 +00:00
2012-06-10 09:04:49 +00:00
if ( clip ) {
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
MovieTrackingObject * tracking_object = BKE_tracking_object_get_active ( tracking ) ;
2012-06-10 09:04:49 +00:00
if ( tracking_object - > flag & TRACKING_OBJECT_CAMERA ) {
return TRUE ;
}
else {
return OBACT ! = NULL ;
}
2012-06-08 08:24:08 +00:00
}
2011-12-18 18:31:02 +00:00
}
2012-03-25 23:19:21 +00:00
return FALSE ;
2011-12-18 18:31:02 +00:00
}
2011-11-07 12:55:18 +00:00
static int count_selected_bundles ( bContext * C )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( & clip - > tracking ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-03-25 23:19:21 +00:00
int tot = 0 ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
if ( TRACK_VIEW_SELECTED ( sc , track ) & & ( track - > flag & TRACK_HAS_BUNDLE ) )
2011-11-07 12:55:18 +00:00
tot + + ;
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
return tot ;
}
2011-12-15 16:09:57 +00:00
static void object_solver_inverted_matrix ( Scene * scene , Object * ob , float invmat [ 4 ] [ 4 ] )
{
bConstraint * con ;
2012-03-25 23:19:21 +00:00
int found = FALSE ;
2011-12-15 16:09:57 +00:00
2012-03-25 23:19:21 +00:00
for ( con = ob - > constraints . first ; con ; con = con - > next ) {
bConstraintTypeInfo * cti = constraint_get_typeinfo ( con ) ;
2011-12-15 16:09:57 +00:00
2012-03-24 06:38:07 +00:00
if ( ! cti )
2011-12-15 16:09:57 +00:00
continue ;
2012-03-25 23:19:21 +00:00
if ( cti - > type = = CONSTRAINT_TYPE_OBJECTSOLVER ) {
bObjectSolverConstraint * data = ( bObjectSolverConstraint * ) con - > data ;
2011-12-15 16:09:57 +00:00
2012-03-24 06:38:07 +00:00
if ( ! found ) {
2012-03-25 23:19:21 +00:00
Object * cam = data - > camera ? data - > camera : scene - > camera ;
2011-12-21 14:51:01 +00:00
2012-05-05 14:03:12 +00:00
BKE_object_where_is_calc_mat4 ( scene , cam , invmat ) ;
2011-12-21 14:51:01 +00:00
}
2011-12-19 10:39:40 +00:00
mult_m4_m4m4 ( invmat , invmat , data - > invmat ) ;
2011-12-21 14:51:01 +00:00
2012-03-25 23:19:21 +00:00
found = TRUE ;
2011-12-15 16:09:57 +00:00
}
}
2012-03-24 06:38:07 +00:00
if ( found )
2011-12-21 14:51:01 +00:00
invert_m4 ( invmat ) ;
else
unit_m4 ( invmat ) ;
}
static Object * object_solver_camera ( Scene * scene , Object * ob )
{
bConstraint * con ;
2012-03-25 23:19:21 +00:00
for ( con = ob - > constraints . first ; con ; con = con - > next ) {
bConstraintTypeInfo * cti = constraint_get_typeinfo ( con ) ;
2011-12-21 14:51:01 +00:00
2012-03-24 06:38:07 +00:00
if ( ! cti )
2011-12-21 14:51:01 +00:00
continue ;
2012-03-25 23:19:21 +00:00
if ( cti - > type = = CONSTRAINT_TYPE_OBJECTSOLVER ) {
bObjectSolverConstraint * data = ( bObjectSolverConstraint * ) con - > data ;
2011-12-21 14:51:01 +00:00
return data - > camera ? data - > camera : scene - > camera ;
}
}
return NULL ;
2011-12-15 16:09:57 +00:00
}
2011-11-07 12:55:18 +00:00
static int set_origin_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2011-12-05 18:57:17 +00:00
MovieTrackingObject * tracking_object ;
2012-03-25 23:19:21 +00:00
Scene * scene = CTX_data_scene ( C ) ;
2011-12-05 18:57:17 +00:00
Object * object ;
2012-03-25 23:19:21 +00:00
Object * camera = get_camera_with_movieclip ( scene , clip ) ;
2011-12-05 18:57:17 +00:00
ListBase * tracksbase ;
2011-12-15 16:09:57 +00:00
float mat [ 4 ] [ 4 ] , vec [ 3 ] , median [ 3 ] ;
2012-03-25 23:19:21 +00:00
int selected_count = count_selected_bundles ( C ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( selected_count = = 0 ) {
2012-06-15 14:11:23 +00:00
BKE_report ( op - > reports , RPT_ERROR ,
" At least one track with bundle should be selected to define origin position " ) ;
2011-12-05 18:57:17 +00:00
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
}
2012-03-25 23:19:21 +00:00
object = get_orientation_object ( C ) ;
2012-03-24 06:38:07 +00:00
if ( ! object ) {
2011-12-21 14:51:01 +00:00
BKE_report ( op - > reports , RPT_ERROR , " No object to apply orientation on " ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
}
2012-06-15 11:03:23 +00:00
tracking_object = BKE_tracking_object_get_active ( tracking ) ;
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
tracksbase = BKE_tracking_object_get_tracks ( tracking , tracking_object ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2011-12-15 16:09:57 +00:00
zero_v3 ( median ) ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
if ( TRACK_VIEW_SELECTED ( sc , track ) & & ( track - > flag & TRACK_HAS_BUNDLE ) ) {
2011-12-15 16:09:57 +00:00
add_v3_v3 ( median , track - > bundle_pos ) ;
}
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2012-05-07 08:53:59 +00:00
mul_v3_fl ( median , 1.0f / selected_count ) ;
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_get_camera_object_matrix ( scene , camera , mat ) ;
2011-11-07 12:55:18 +00:00
2011-12-15 16:09:57 +00:00
mul_v3_m4v3 ( vec , mat , median ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( tracking_object - > flag & TRACKING_OBJECT_CAMERA ) {
2011-12-05 18:57:17 +00:00
sub_v3_v3 ( object - > loc , vec ) ;
2011-12-15 16:09:57 +00:00
}
else {
object_solver_inverted_matrix ( scene , object , mat ) ;
mul_v3_m4v3 ( vec , mat , vec ) ;
2011-12-05 18:57:17 +00:00
copy_v3_v3 ( object - > loc , vec ) ;
2011-12-15 16:09:57 +00:00
}
2011-11-07 12:55:18 +00:00
DAG_id_tag_update ( & clip - > id , 0 ) ;
2011-12-05 18:57:17 +00:00
DAG_id_tag_update ( & object - > id , OB_RECALC_OB ) ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EVALUATED , clip ) ;
WM_event_add_notifier ( C , NC_OBJECT | ND_TRANSFORM , NULL ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_set_origin ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Set Origin " ;
ot - > description = " Set active marker as origin by moving camera (or it's parent if present) in 3D space " ;
ot - > idname = " CLIP_OT_set_origin " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = set_origin_exec ;
ot - > poll = set_orientation_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-12-15 16:09:57 +00:00
/* properties */
RNA_def_boolean ( ot - > srna , " use_median " , 0 , " Use Median " , " Set origin to median point of selected bundles " ) ;
2011-11-07 12:55:18 +00:00
}
/********************** set floor operator *********************/
2011-12-21 14:51:01 +00:00
static void set_axis ( Scene * scene , Object * ob , MovieClip * clip , MovieTrackingObject * tracking_object ,
2012-06-10 19:59:02 +00:00
MovieTrackingTrack * track , char axis )
2011-11-07 12:55:18 +00:00
{
2012-03-25 23:19:21 +00:00
Object * camera = get_camera_with_movieclip ( scene , clip ) ;
int is_camera = tracking_object - > flag & TRACKING_OBJECT_CAMERA ;
2012-06-10 19:59:02 +00:00
int flip = FALSE ;
2011-12-05 18:57:17 +00:00
float mat [ 4 ] [ 4 ] , vec [ 3 ] , obmat [ 4 ] [ 4 ] , dvec [ 3 ] ;
2012-05-05 14:03:12 +00:00
BKE_object_to_mat4 ( ob , obmat ) ;
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_get_camera_object_matrix ( scene , camera , mat ) ;
2011-11-07 12:55:18 +00:00
mul_v3_m4v3 ( vec , mat , track - > bundle_pos ) ;
2011-12-05 18:57:17 +00:00
copy_v3_v3 ( dvec , vec ) ;
2012-03-24 06:38:07 +00:00
if ( ! is_camera ) {
2011-12-05 18:57:17 +00:00
float imat [ 4 ] [ 4 ] ;
2011-12-15 16:09:57 +00:00
object_solver_inverted_matrix ( scene , ob , imat ) ;
mul_v3_m4v3 ( vec , imat , vec ) ;
2011-12-05 18:57:17 +00:00
invert_m4_m4 ( imat , obmat ) ;
mul_v3_m4v3 ( dvec , imat , vec ) ;
sub_v3_v3 ( vec , obmat [ 3 ] ) ;
}
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( len_v2 ( vec ) < 1e-3 f )
2011-11-07 12:55:18 +00:00
return ;
unit_m4 ( mat ) ;
2012-03-25 23:19:21 +00:00
if ( axis = = ' X ' ) {
if ( fabsf ( dvec [ 1 ] ) < 1e-3 f ) {
flip = TRUE ;
2011-12-05 18:57:17 +00:00
2012-03-25 23:19:21 +00:00
mat [ 0 ] [ 0 ] = - 1.0f ; mat [ 0 ] [ 1 ] = 0.0f ; mat [ 0 ] [ 2 ] = 0.0f ;
mat [ 1 ] [ 0 ] = 0.0f ; mat [ 1 ] [ 1 ] = - 1.0f ; mat [ 1 ] [ 2 ] = 0.0f ;
mat [ 2 ] [ 0 ] = 0.0f ; mat [ 2 ] [ 1 ] = 0.0f ; mat [ 2 ] [ 2 ] = 1.0f ;
2012-03-24 06:38:07 +00:00
}
else {
2011-11-07 12:55:18 +00:00
copy_v3_v3 ( mat [ 0 ] , vec ) ;
2011-12-05 18:57:17 +00:00
2012-03-25 23:19:21 +00:00
if ( is_camera | | fabsf ( vec [ 2 ] ) < 1e-3 f ) {
mat [ 0 ] [ 2 ] = 0.0f ;
mat [ 2 ] [ 0 ] = 0.0f ; mat [ 2 ] [ 1 ] = 0.0f ; mat [ 2 ] [ 2 ] = 1.0f ;
2011-12-05 18:57:17 +00:00
cross_v3_v3v3 ( mat [ 1 ] , mat [ 2 ] , mat [ 0 ] ) ;
}
else {
2012-03-25 23:19:21 +00:00
vec [ 2 ] = 0.0f ;
2011-12-05 18:57:17 +00:00
cross_v3_v3v3 ( mat [ 1 ] , mat [ 0 ] , vec ) ;
cross_v3_v3v3 ( mat [ 2 ] , mat [ 0 ] , mat [ 1 ] ) ;
}
2011-11-07 12:55:18 +00:00
}
2012-03-24 06:38:07 +00:00
}
else {
2012-03-25 23:19:21 +00:00
if ( fabsf ( dvec [ 0 ] ) < 1e-3 f ) {
flip = TRUE ;
2011-12-05 18:57:17 +00:00
2012-03-25 23:19:21 +00:00
mat [ 0 ] [ 0 ] = - 1.0f ; mat [ 0 ] [ 1 ] = 0.0f ; mat [ 0 ] [ 2 ] = 0.0f ;
mat [ 1 ] [ 0 ] = 0.0f ; mat [ 1 ] [ 1 ] = - 1.0f ; mat [ 1 ] [ 2 ] = 0.0f ;
mat [ 2 ] [ 0 ] = 0.0f ; mat [ 2 ] [ 1 ] = 0.0f ; mat [ 2 ] [ 2 ] = 1.0f ;
2012-03-24 06:38:07 +00:00
}
else {
2011-11-07 12:55:18 +00:00
copy_v3_v3 ( mat [ 1 ] , vec ) ;
2011-12-05 18:57:17 +00:00
2012-05-07 08:53:59 +00:00
if ( is_camera | | fabsf ( vec [ 2 ] ) < 1e-3 f ) {
2012-03-25 23:19:21 +00:00
mat [ 1 ] [ 2 ] = 0.0f ;
mat [ 2 ] [ 0 ] = 0.0f ; mat [ 2 ] [ 1 ] = 0.0f ; mat [ 2 ] [ 2 ] = 1.0f ;
2011-12-05 18:57:17 +00:00
cross_v3_v3v3 ( mat [ 0 ] , mat [ 1 ] , mat [ 2 ] ) ;
}
else {
2012-03-25 23:19:21 +00:00
vec [ 2 ] = 0.0f ;
2011-12-05 18:57:17 +00:00
cross_v3_v3v3 ( mat [ 0 ] , vec , mat [ 1 ] ) ;
cross_v3_v3v3 ( mat [ 2 ] , mat [ 0 ] , mat [ 1 ] ) ;
}
2011-11-07 12:55:18 +00:00
}
}
normalize_v3 ( mat [ 0 ] ) ;
normalize_v3 ( mat [ 1 ] ) ;
normalize_v3 ( mat [ 2 ] ) ;
2012-03-24 06:38:07 +00:00
if ( is_camera ) {
2011-12-05 18:57:17 +00:00
invert_m4 ( mat ) ;
2011-12-19 10:39:40 +00:00
mult_m4_m4m4 ( mat , mat , obmat ) ;
2011-12-05 18:57:17 +00:00
}
else {
2012-03-24 06:38:07 +00:00
if ( ! flip ) {
2011-12-15 16:09:57 +00:00
float lmat [ 4 ] [ 4 ] , ilmat [ 4 ] [ 4 ] , rmat [ 3 ] [ 3 ] ;
2011-12-05 18:57:17 +00:00
2012-05-05 14:03:12 +00:00
BKE_object_rot_to_mat3 ( ob , rmat ) ;
2011-12-15 16:09:57 +00:00
invert_m3 ( rmat ) ;
mul_m4_m4m3 ( mat , mat , rmat ) ;
2011-12-05 18:57:17 +00:00
2011-12-15 16:09:57 +00:00
unit_m4 ( lmat ) ;
copy_v3_v3 ( lmat [ 3 ] , obmat [ 3 ] ) ;
invert_m4_m4 ( ilmat , lmat ) ;
2011-12-05 18:57:17 +00:00
2011-12-15 16:09:57 +00:00
mul_serie_m4 ( mat , lmat , mat , ilmat , obmat , NULL , NULL , NULL , NULL ) ;
}
else {
2011-12-19 10:39:40 +00:00
mult_m4_m4m4 ( mat , obmat , mat ) ;
2011-12-15 16:09:57 +00:00
}
2011-12-05 18:57:17 +00:00
}
2011-11-07 12:55:18 +00:00
2012-05-05 14:03:12 +00:00
BKE_object_apply_mat4 ( ob , mat , 0 , 0 ) ;
2011-11-07 12:55:18 +00:00
}
2012-03-06 12:27:42 +00:00
static int set_plane_exec ( bContext * C , wmOperator * op )
2011-11-07 12:55:18 +00:00
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
Scene * scene = CTX_data_scene ( C ) ;
MovieTracking * tracking = & clip - > tracking ;
2011-12-05 18:57:17 +00:00
MovieTrackingObject * tracking_object ;
2012-03-25 23:19:21 +00:00
MovieTrackingTrack * track , * axis_track = NULL , * act_track ;
2011-12-05 18:57:17 +00:00
ListBase * tracksbase ;
Object * object ;
2012-03-25 23:19:21 +00:00
Object * camera = get_camera_with_movieclip ( scene , clip ) ;
int tot = 0 ;
float vec [ 3 ] [ 3 ] , mat [ 4 ] [ 4 ] , obmat [ 4 ] [ 4 ] , newmat [ 4 ] [ 4 ] , orig [ 3 ] = { 0.0f , 0.0f , 0.0f } ;
int plane = RNA_enum_get ( op - > ptr , " plane " ) ;
float rot [ 4 ] [ 4 ] = { { 0.0f , 0.0f , - 1.0f , 0.0f } ,
{ 0.0f , 1.0f , 0.0f , 0.0f } ,
{ 1.0f , 0.0f , 0.0f , 0.0f } ,
2012-06-10 19:59:02 +00:00
{ 0.0f , 0.0f , 0.0f , 1.0f } } ; /* 90 degrees Y-axis rotation matrix */
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
if ( count_selected_bundles ( C ) ! = 3 ) {
2011-11-07 12:55:18 +00:00
BKE_report ( op - > reports , RPT_ERROR , " Three tracks with bundles are needed to orient the floor " ) ;
2011-12-05 18:57:17 +00:00
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
}
2012-06-15 11:03:23 +00:00
tracking_object = BKE_tracking_object_get_active ( tracking ) ;
tracksbase = BKE_tracking_object_get_tracks ( tracking , tracking_object ) ;
act_track = BKE_tracking_track_get_active ( tracking ) ;
2011-12-05 18:57:17 +00:00
2012-03-25 23:19:21 +00:00
object = get_orientation_object ( C ) ;
2012-03-24 06:38:07 +00:00
if ( ! object ) {
2011-12-21 14:51:01 +00:00
BKE_report ( op - > reports , RPT_ERROR , " No object to apply orientation on " ) ;
2011-12-05 18:57:17 +00:00
2011-12-21 14:51:01 +00:00
return OPERATOR_CANCELLED ;
}
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_get_camera_object_matrix ( scene , camera , mat ) ;
2011-11-07 12:55:18 +00:00
/* get 3 bundles to use as reference */
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-05-07 08:53:59 +00:00
while ( track & & tot < 3 ) {
2012-03-25 23:19:21 +00:00
if ( track - > flag & TRACK_HAS_BUNDLE & & TRACK_VIEW_SELECTED ( sc , track ) ) {
2011-11-07 12:55:18 +00:00
mul_v3_m4v3 ( vec [ tot ] , mat , track - > bundle_pos ) ;
2012-03-25 23:19:21 +00:00
if ( tot = = 0 | | track = = act_track )
2011-11-07 12:55:18 +00:00
copy_v3_v3 ( orig , vec [ tot ] ) ;
else
2012-03-25 23:19:21 +00:00
axis_track = track ;
2011-11-07 12:55:18 +00:00
tot + + ;
}
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
sub_v3_v3 ( vec [ 1 ] , vec [ 0 ] ) ;
sub_v3_v3 ( vec [ 2 ] , vec [ 0 ] ) ;
/* construct ortho-normal basis */
unit_m4 ( mat ) ;
2012-03-06 12:27:42 +00:00
if ( plane = = 0 ) { /* floor */
cross_v3_v3v3 ( mat [ 0 ] , vec [ 1 ] , vec [ 2 ] ) ;
copy_v3_v3 ( mat [ 1 ] , vec [ 1 ] ) ;
cross_v3_v3v3 ( mat [ 2 ] , mat [ 0 ] , mat [ 1 ] ) ;
}
else if ( plane = = 1 ) { /* wall */
cross_v3_v3v3 ( mat [ 2 ] , vec [ 1 ] , vec [ 2 ] ) ;
copy_v3_v3 ( mat [ 1 ] , vec [ 1 ] ) ;
cross_v3_v3v3 ( mat [ 0 ] , mat [ 1 ] , mat [ 2 ] ) ;
}
2011-11-07 12:55:18 +00:00
normalize_v3 ( mat [ 0 ] ) ;
normalize_v3 ( mat [ 1 ] ) ;
normalize_v3 ( mat [ 2 ] ) ;
/* move to origin point */
2012-03-25 23:19:21 +00:00
mat [ 3 ] [ 0 ] = orig [ 0 ] ;
mat [ 3 ] [ 1 ] = orig [ 1 ] ;
mat [ 3 ] [ 2 ] = orig [ 2 ] ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( tracking_object - > flag & TRACKING_OBJECT_CAMERA ) {
2011-12-05 18:57:17 +00:00
invert_m4 ( mat ) ;
2011-11-07 12:55:18 +00:00
2012-05-05 14:03:12 +00:00
BKE_object_to_mat4 ( object , obmat ) ;
2011-12-19 10:39:40 +00:00
mult_m4_m4m4 ( mat , mat , obmat ) ;
Math lib: matrix multiplication order fix for two functions that were
inconsistent with similar functions & math notation:
mul_m4_m4m4(R, B, A) => mult_m4_m4m4(R, A, B)
mul_m3_m3m4(R, B, A) => mult_m3_m3m4(R, A, B)
For branch maintainers, it should be relatively simple to fix things manually,
it's also possible run this script after merging to do automatic replacement:
http://www.pasteall.org/27459/python
2011-12-16 19:53:12 +00:00
mult_m4_m4m4 ( newmat , rot , mat ) ;
2012-05-05 14:03:12 +00:00
BKE_object_apply_mat4 ( object , newmat , 0 , 0 ) ;
2011-12-05 18:57:17 +00:00
/* make camera have positive z-coordinate */
2012-05-07 08:53:59 +00:00
if ( object - > loc [ 2 ] < 0 ) {
2011-12-30 18:06:02 +00:00
invert_m4 ( rot ) ;
mult_m4_m4m4 ( newmat , rot , mat ) ;
2012-05-05 14:03:12 +00:00
BKE_object_apply_mat4 ( object , newmat , 0 , 0 ) ;
2011-12-05 18:57:17 +00:00
}
}
else {
2012-05-05 14:03:12 +00:00
BKE_object_apply_mat4 ( object , mat , 0 , 0 ) ;
2011-11-07 12:55:18 +00:00
}
2012-05-05 14:03:12 +00:00
BKE_object_where_is_calc ( scene , object ) ;
2011-12-21 14:51:01 +00:00
set_axis ( scene , object , clip , tracking_object , axis_track , ' X ' ) ;
2011-11-07 12:55:18 +00:00
DAG_id_tag_update ( & clip - > id , 0 ) ;
2011-12-05 18:57:17 +00:00
DAG_id_tag_update ( & object - > id , OB_RECALC_OB ) ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EVALUATED , clip ) ;
WM_event_add_notifier ( C , NC_OBJECT | ND_TRANSFORM , NULL ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
2012-03-06 12:27:42 +00:00
void CLIP_OT_set_plane ( wmOperatorType * ot )
2011-11-07 12:55:18 +00:00
{
2012-03-06 12:27:42 +00:00
static EnumPropertyItem plane_items [ ] = {
2012-06-10 19:59:02 +00:00
{ 0 , " FLOOR " , 0 , " Floor " , " Set floor plane " } ,
{ 1 , " WALL " , 0 , " Wall " , " Set wall plane " } ,
{ 0 , NULL , 0 , NULL , NULL }
2012-03-06 12:27:42 +00:00
} ;
2011-11-07 12:55:18 +00:00
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Set Plane " ;
ot - > description = " Set plane based on 3 selected bundles by moving camera (or it's parent if present) in 3D space " ;
ot - > idname = " CLIP_OT_set_plane " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = set_plane_exec ;
ot - > poll = set_orientation_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2012-03-06 12:27:42 +00:00
/* properties */
2012-04-14 15:44:31 +00:00
RNA_def_enum ( ot - > srna , " plane " , plane_items , 0 , " Plane " , " Plane to be used for orientation " ) ;
2011-11-07 12:55:18 +00:00
}
/********************** set axis operator *********************/
static int set_axis_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
MovieTrackingObject * tracking_object = BKE_tracking_object_get_active ( tracking ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-03-25 23:19:21 +00:00
Scene * scene = CTX_data_scene ( C ) ;
2011-12-05 18:57:17 +00:00
Object * object ;
ListBase * tracksbase ;
2012-03-25 23:19:21 +00:00
int axis = RNA_enum_get ( op - > ptr , " axis " ) ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
if ( count_selected_bundles ( C ) ! = 1 ) {
2011-11-07 12:55:18 +00:00
BKE_report ( op - > reports , RPT_ERROR , " Single track with bundle should be selected to define axis " ) ;
return OPERATOR_CANCELLED ;
}
2012-03-25 23:19:21 +00:00
object = get_orientation_object ( C ) ;
2012-03-24 06:38:07 +00:00
if ( ! object ) {
2011-12-21 14:51:01 +00:00
BKE_report ( op - > reports , RPT_ERROR , " No object to apply orientation on " ) ;
2011-11-07 12:55:18 +00:00
2011-12-21 14:51:01 +00:00
return OPERATOR_CANCELLED ;
}
2011-12-05 18:57:17 +00:00
2012-06-15 11:03:23 +00:00
tracksbase = BKE_tracking_object_get_tracks ( tracking , tracking_object ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
if ( TRACK_VIEW_SELECTED ( sc , track ) )
2011-11-07 12:55:18 +00:00
break ;
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
set_axis ( scene , object , clip , tracking_object , track , axis = = 0 ? ' X ' : ' Y ' ) ;
2011-11-07 12:55:18 +00:00
DAG_id_tag_update ( & clip - > id , 0 ) ;
2011-12-05 18:57:17 +00:00
DAG_id_tag_update ( & object - > id , OB_RECALC_OB ) ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EVALUATED , clip ) ;
WM_event_add_notifier ( C , NC_OBJECT | ND_TRANSFORM , NULL ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_set_axis ( wmOperatorType * ot )
{
static EnumPropertyItem axis_actions [ ] = {
2012-06-10 19:59:02 +00:00
{ 0 , " X " , 0 , " X " , " Align bundle align X axis " } ,
{ 1 , " Y " , 0 , " Y " , " Align bundle align Y axis " } ,
{ 0 , NULL , 0 , NULL , NULL }
2011-11-07 12:55:18 +00:00
} ;
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Set Axis " ;
ot - > description = " Set direction of scene axis rotating camera (or it's parent if present) and assuming selected track lies on real axis joining it with the origin " ;
ot - > idname = " CLIP_OT_set_axis " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = set_axis_exec ;
ot - > poll = set_orientation_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* properties */
RNA_def_enum ( ot - > srna , " axis " , axis_actions , 0 , " Axis " , " Axis to use to align bundle along " ) ;
}
/********************** set scale operator *********************/
2011-12-19 15:12:33 +00:00
static int do_set_scale ( bContext * C , wmOperator * op , int scale_solution )
2011-11-07 12:55:18 +00:00
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
MovieTrackingObject * tracking_object = BKE_tracking_object_get_active ( tracking ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-03-25 23:19:21 +00:00
Scene * scene = CTX_data_scene ( C ) ;
Object * object = NULL ;
Object * camera = get_camera_with_movieclip ( scene , clip ) ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2012-03-25 23:19:21 +00:00
int tot = 0 ;
2011-11-07 12:55:18 +00:00
float vec [ 2 ] [ 3 ] , mat [ 4 ] [ 4 ] , scale ;
2012-03-25 23:19:21 +00:00
float dist = RNA_float_get ( op - > ptr , " distance " ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( count_selected_bundles ( C ) ! = 2 ) {
2011-12-19 15:12:33 +00:00
BKE_report ( op - > reports , RPT_ERROR , " Two tracks with bundles should be selected to set scale " ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
}
2012-03-25 23:19:21 +00:00
object = get_orientation_object ( C ) ;
2012-03-24 06:38:07 +00:00
if ( ! object ) {
2011-12-21 14:51:01 +00:00
BKE_report ( op - > reports , RPT_ERROR , " No object to apply orientation on " ) ;
2011-12-18 18:31:02 +00:00
2011-12-21 14:51:01 +00:00
return OPERATOR_CANCELLED ;
}
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_get_camera_object_matrix ( scene , camera , mat ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
if ( TRACK_VIEW_SELECTED ( sc , track ) ) {
2011-11-07 12:55:18 +00:00
mul_v3_m4v3 ( vec [ tot ] , mat , track - > bundle_pos ) ;
tot + + ;
}
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
sub_v3_v3 ( vec [ 0 ] , vec [ 1 ] ) ;
2012-05-07 08:53:59 +00:00
if ( len_v3 ( vec [ 0 ] ) > 1e-5 f ) {
2012-03-25 23:19:21 +00:00
scale = dist / len_v3 ( vec [ 0 ] ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( tracking_object - > flag & TRACKING_OBJECT_CAMERA ) {
2011-12-18 18:31:02 +00:00
mul_v3_fl ( object - > size , scale ) ;
mul_v3_fl ( object - > loc , scale ) ;
2011-12-31 08:26:32 +00:00
}
2012-03-24 06:38:07 +00:00
else if ( ! scale_solution ) {
2012-03-25 23:19:21 +00:00
Object * solver_camera = object_solver_camera ( scene , object ) ;
2011-12-21 14:51:01 +00:00
2012-05-07 08:53:59 +00:00
object - > size [ 0 ] = object - > size [ 1 ] = object - > size [ 2 ] = 1.0f / scale ;
2011-12-18 18:31:02 +00:00
2012-03-24 06:38:07 +00:00
if ( solver_camera ) {
2012-03-25 23:19:21 +00:00
object - > size [ 0 ] / = solver_camera - > size [ 0 ] ;
object - > size [ 1 ] / = solver_camera - > size [ 1 ] ;
object - > size [ 2 ] / = solver_camera - > size [ 2 ] ;
2011-12-18 18:31:02 +00:00
}
}
2011-12-19 15:12:33 +00:00
else {
2012-03-25 23:19:21 +00:00
tracking_object - > scale = scale ;
2011-12-19 15:12:33 +00:00
}
2011-11-07 12:55:18 +00:00
DAG_id_tag_update ( & clip - > id , 0 ) ;
2011-12-19 15:12:33 +00:00
2012-03-24 06:38:07 +00:00
if ( object )
2011-12-19 15:12:33 +00:00
DAG_id_tag_update ( & object - > id , OB_RECALC_OB ) ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EVALUATED , clip ) ;
WM_event_add_notifier ( C , NC_OBJECT | ND_TRANSFORM , NULL ) ;
2011-11-07 12:55:18 +00:00
}
return OPERATOR_FINISHED ;
}
2011-12-19 15:12:33 +00:00
static int set_scale_exec ( bContext * C , wmOperator * op )
{
return do_set_scale ( C , op , 0 ) ;
}
2011-11-07 12:55:18 +00:00
static int set_scale_invoke ( bContext * C , wmOperator * op , wmEvent * UNUSED ( event ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( ! RNA_struct_property_is_set ( op - > ptr , " distance " ) )
2011-11-07 12:55:18 +00:00
RNA_float_set ( op - > ptr , " distance " , clip - > tracking . settings . dist ) ;
return set_scale_exec ( C , op ) ;
}
void CLIP_OT_set_scale ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Set Scale " ;
ot - > description = " Set scale of scene by scaling camera (or it's parent if present) " ;
ot - > idname = " CLIP_OT_set_scale " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = set_scale_exec ;
ot - > invoke = set_scale_invoke ;
ot - > poll = set_orientation_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* properties */
RNA_def_float ( ot - > srna , " distance " , 0.0f , - FLT_MAX , FLT_MAX ,
2012-06-10 19:59:02 +00:00
" Distance " , " Distance between selected tracks " , - 100.0f , 100.0f ) ;
2011-11-07 12:55:18 +00:00
}
2011-12-19 15:12:33 +00:00
/********************** set solution scale operator *********************/
static int set_solution_scale_poll ( bContext * C )
{
2012-06-07 16:36:19 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2011-12-19 15:12:33 +00:00
2012-06-08 08:24:08 +00:00
if ( sc ) {
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-06-08 08:24:08 +00:00
2012-06-10 09:04:49 +00:00
if ( clip ) {
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
MovieTrackingObject * tracking_object = BKE_tracking_object_get_active ( tracking ) ;
2012-06-10 09:04:49 +00:00
return ( tracking_object - > flag & TRACKING_OBJECT_CAMERA ) = = 0 ;
}
2012-06-08 08:24:08 +00:00
}
return FALSE ;
2011-12-19 15:12:33 +00:00
}
static int set_solution_scale_exec ( bContext * C , wmOperator * op )
{
return do_set_scale ( C , op , 1 ) ;
}
static int set_solution_scale_invoke ( bContext * C , wmOperator * op , wmEvent * UNUSED ( event ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2011-12-19 15:12:33 +00:00
2012-03-24 06:38:07 +00:00
if ( ! RNA_struct_property_is_set ( op - > ptr , " distance " ) )
2011-12-19 15:12:33 +00:00
RNA_float_set ( op - > ptr , " distance " , clip - > tracking . settings . object_distance ) ;
return set_solution_scale_exec ( C , op ) ;
}
void CLIP_OT_set_solution_scale ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Set Solution Scale " ;
ot - > description = " Set object solution scale using distance between two selected tracks " ;
ot - > idname = " CLIP_OT_set_solution_scale " ;
2011-12-19 15:12:33 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = set_solution_scale_exec ;
ot - > invoke = set_solution_scale_invoke ;
ot - > poll = set_solution_scale_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* properties */
RNA_def_float ( ot - > srna , " distance " , 0.0f , - FLT_MAX , FLT_MAX ,
2012-06-10 19:59:02 +00:00
" Distance " , " Distance between selected tracks " , - 100.0f , 100.0f ) ;
2011-11-07 12:55:18 +00:00
}
/********************** set principal center operator *********************/
static int set_center_principal_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2011-11-07 12:55:18 +00:00
int width , height ;
BKE_movieclip_get_size ( clip , & sc - > user , & width , & height ) ;
2012-03-25 23:19:21 +00:00
if ( width = = 0 | | height = = 0 )
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
2012-05-07 08:53:59 +00:00
clip - > tracking . camera . principal [ 0 ] = ( ( float ) width ) / 2.0f ;
clip - > tracking . camera . principal [ 1 ] = ( ( float ) height ) / 2.0f ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EDITED , clip ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_set_center_principal ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Set Principal to Center " ;
ot - > description = " Set optical center to center of footage " ;
ot - > idname = " CLIP_OT_set_center_principal " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = set_center_principal_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** hide tracks operator *********************/
static int hide_tracks_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
MovieTrackingTrack * act_track = BKE_tracking_track_get_active ( tracking ) ;
2011-11-07 12:55:18 +00:00
int unselected ;
2012-03-25 23:19:21 +00:00
unselected = RNA_boolean_get ( op - > ptr , " unselected " ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
if ( unselected = = 0 & & TRACK_VIEW_SELECTED ( sc , track ) ) {
track - > flag | = TRACK_HIDDEN ;
2012-03-24 06:38:07 +00:00
}
2012-03-25 23:19:21 +00:00
else if ( unselected = = 1 & & ! TRACK_VIEW_SELECTED ( sc , track ) ) {
track - > flag | = TRACK_HIDDEN ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
if ( act_track & & act_track - > flag & TRACK_HIDDEN )
clip - > tracking . act_track = NULL ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( unselected = = 0 ) {
2011-11-07 12:55:18 +00:00
/* no selection on screen now, unlock view so it can be scrolled nice again */
2012-03-25 23:19:21 +00:00
sc - > flag & = ~ SC_LOCK_SELECTION ;
2011-11-07 12:55:18 +00:00
}
2012-05-03 23:15:01 +00:00
BKE_tracking_dopesheet_tag_update ( tracking ) ;
2012-04-30 16:19:20 +00:00
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | ND_DISPLAY , NULL ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_hide_tracks ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Hide Tracks " ;
ot - > description = " Hide selected tracks " ;
ot - > idname = " CLIP_OT_hide_tracks " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = hide_tracks_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* properties */
RNA_def_boolean ( ot - > srna , " unselected " , 0 , " Unselected " , " Hide unselected tracks " ) ;
}
/********************** hide tracks clear operator *********************/
static int hide_tracks_clear_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-05-03 23:15:01 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
track - > flag & = ~ TRACK_HIDDEN ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2012-05-03 23:15:01 +00:00
BKE_tracking_dopesheet_tag_update ( tracking ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | ND_DISPLAY , NULL ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_hide_tracks_clear ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Hide Tracks Clear " ;
ot - > description = " Clear hide selected tracks " ;
ot - > idname = " CLIP_OT_hide_tracks_clear " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = hide_tracks_clear_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** detect features operator *********************/
static bGPDlayer * detect_get_layer ( MovieClip * clip )
{
bGPDlayer * layer ;
2012-03-24 06:38:07 +00:00
if ( ! clip - > gpd )
2011-11-07 12:55:18 +00:00
return NULL ;
2012-03-25 23:19:21 +00:00
layer = clip - > gpd - > layers . first ;
2012-03-24 06:38:07 +00:00
while ( layer ) {
2012-03-25 23:19:21 +00:00
if ( layer - > flag & GP_LAYER_ACTIVE )
2011-11-07 12:55:18 +00:00
return layer ;
2012-03-25 23:19:21 +00:00
layer = layer - > next ;
2011-11-07 12:55:18 +00:00
}
return NULL ;
}
static int detect_features_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
int clip_flag = clip - > flag & MCLIP_TIMECODE_FLAGS ;
ImBuf * ibuf = BKE_movieclip_get_ibuf_flag ( clip , & sc - > user , clip_flag , MOVIECLIP_CACHE_SKIP ) ;
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2012-03-25 23:19:21 +00:00
MovieTrackingTrack * track = tracksbase - > first ;
int placement = RNA_enum_get ( op - > ptr , " placement " ) ;
int margin = RNA_int_get ( op - > ptr , " margin " ) ;
int min_trackability = RNA_int_get ( op - > ptr , " min_trackability " ) ;
int min_distance = RNA_int_get ( op - > ptr , " min_distance " ) ;
int place_outside_layer = 0 ;
2012-06-19 14:26:29 +00:00
int framenr = ED_space_clip_get_clip_frame_number ( sc ) ;
2012-03-25 23:19:21 +00:00
bGPDlayer * layer = NULL ;
2012-06-07 16:36:19 +00:00
if ( ! ibuf ) {
BKE_report ( op - > reports , RPT_ERROR , " Feature detection requires valid clip frame " ) ;
return OPERATOR_CANCELLED ;
}
2012-03-25 23:19:21 +00:00
if ( placement ! = 0 ) {
layer = detect_get_layer ( clip ) ;
place_outside_layer = placement = = 2 ;
2011-11-07 12:55:18 +00:00
}
/* deselect existing tracks */
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
track - > flag & = ~ SELECT ;
track - > pat_flag & = ~ SELECT ;
track - > search_flag & = ~ SELECT ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2012-06-06 18:58:30 +00:00
BKE_tracking_detect_fast ( tracking , tracksbase , ibuf , framenr , margin ,
2012-06-10 19:59:02 +00:00
min_trackability , min_distance , layer , place_outside_layer ) ;
2011-11-07 12:55:18 +00:00
IMB_freeImBuf ( ibuf ) ;
2012-06-24 18:00:14 +00:00
BKE_tracking_dopesheet_tag_update ( tracking ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EDITED , NULL ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_detect_features ( wmOperatorType * ot )
{
static EnumPropertyItem placement_items [ ] = {
2012-06-10 19:59:02 +00:00
{ 0 , " FRAME " , 0 , " Whole Frame " , " Place markers across the whole frame " } ,
{ 1 , " INSIDE_GPENCIL " , 0 , " Inside grease pencil " , " Place markers only inside areas outlined with grease pencil " } ,
{ 2 , " OUTSIDE_GPENCIL " , 0 , " Outside grease pencil " , " Place markers only outside areas outlined with grease pencil " } ,
{ 0 , NULL , 0 , NULL , NULL }
2011-11-07 12:55:18 +00:00
} ;
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Detect Features " ;
ot - > description = " Automatically detect features and place markers to track " ;
ot - > idname = " CLIP_OT_detect_features " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = detect_features_exec ;
2012-06-07 16:36:19 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* properties */
RNA_def_enum ( ot - > srna , " placement " , placement_items , 0 , " Placement " , " Placement for detected features " ) ;
RNA_def_int ( ot - > srna , " margin " , 16 , 0 , INT_MAX , " Margin " , " Only corners further than margin pixels from the image edges are considered " , 0 , 300 ) ;
2011-11-22 10:42:48 +00:00
RNA_def_int ( ot - > srna , " min_trackability " , 16 , 0 , INT_MAX , " Trackability " , " Minimum trackability score to add a corner " , 0 , 300 ) ;
2011-11-07 12:55:18 +00:00
RNA_def_int ( ot - > srna , " min_distance " , 120 , 0 , INT_MAX , " Distance " , " Minimal distance accepted between two corners " , 0 , 300 ) ;
}
/********************** frame jump operator *********************/
static int frame_jump_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
Scene * scene = CTX_data_scene ( C ) ;
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-03-25 23:19:21 +00:00
int pos = RNA_enum_get ( op - > ptr , " position " ) ;
2011-11-07 12:55:18 +00:00
int delta ;
2012-06-10 19:59:02 +00:00
if ( pos < = 1 ) { /* jump to path */
2012-06-15 11:03:23 +00:00
track = BKE_tracking_track_get_active ( & clip - > tracking ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( ! track )
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
2012-03-25 23:19:21 +00:00
delta = pos = = 1 ? 1 : - 1 ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
while ( sc - > user . framenr + delta > = SFRA & & sc - > user . framenr + delta < = EFRA ) {
2012-06-06 18:58:30 +00:00
int framenr = BKE_movieclip_remap_scene_to_clip_frame ( clip , sc - > user . framenr + delta ) ;
2012-06-15 11:03:23 +00:00
MovieTrackingMarker * marker = BKE_tracking_marker_get_exact ( track , framenr ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( ! marker | | marker - > flag & MARKER_DISABLED )
2011-11-07 12:55:18 +00:00
break ;
2012-03-25 23:19:21 +00:00
sc - > user . framenr + = delta ;
2011-11-07 12:55:18 +00:00
}
}
2012-06-10 19:59:02 +00:00
else { /* to to failed frame */
2012-03-25 23:19:21 +00:00
if ( clip - > tracking . reconstruction . flag & TRACKING_RECONSTRUCTED ) {
2012-06-19 14:26:29 +00:00
int a = ED_space_clip_get_clip_frame_number ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
MovieTrackingObject * object = BKE_tracking_object_get_active ( tracking ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
delta = pos = = 3 ? 1 : - 1 ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
a + = delta ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
while ( a + delta > = SFRA & & a + delta < = EFRA ) {
2011-12-05 18:57:17 +00:00
MovieReconstructedCamera * cam ;
2012-06-15 11:03:23 +00:00
cam = BKE_tracking_camera_get_reconstructed ( tracking , object , a ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( ! cam ) {
2012-06-06 18:58:30 +00:00
sc - > user . framenr = BKE_movieclip_remap_clip_to_scene_frame ( clip , a ) ;
2011-11-07 12:55:18 +00:00
break ;
}
2012-03-25 23:19:21 +00:00
a + = delta ;
2011-11-07 12:55:18 +00:00
}
}
}
2012-03-25 23:19:21 +00:00
if ( CFRA ! = sc - > user . framenr ) {
CFRA = sc - > user . framenr ;
2011-11-07 12:55:18 +00:00
sound_seek_scene ( CTX_data_main ( C ) , CTX_data_scene ( C ) ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_SCENE | ND_FRAME , scene ) ;
2011-11-07 12:55:18 +00:00
}
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | ND_DISPLAY , NULL ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_frame_jump ( wmOperatorType * ot )
{
static EnumPropertyItem position_items [ ] = {
2012-06-10 19:59:02 +00:00
{ 0 , " PATHSTART " , 0 , " Path Start " , " Jump to start of current path " } ,
{ 1 , " PATHEND " , 0 , " Path End " , " Jump to end of current path " } ,
{ 2 , " FAILEDPREV " , 0 , " Previous Failed " , " Jump to previous failed frame " } ,
{ 2 , " FAILNEXT " , 0 , " Next Failed " , " Jump to next failed frame " } ,
{ 0 , NULL , 0 , NULL , NULL }
2011-11-07 12:55:18 +00:00
} ;
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Jump to Frame " ;
ot - > description = " Jump to special frame " ;
ot - > idname = " CLIP_OT_frame_jump " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = frame_jump_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* properties */
2012-03-17 14:27:46 +00:00
RNA_def_enum ( ot - > srna , " position " , position_items , 0 , " Position " , " Position to jump to " ) ;
2011-11-07 12:55:18 +00:00
}
/********************** join tracks operator *********************/
static int join_tracks_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * act_track , * track , * next ;
2012-06-15 11:03:23 +00:00
act_track = BKE_tracking_track_get_active ( tracking ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( ! act_track ) {
2011-11-07 12:55:18 +00:00
BKE_report ( op - > reports , RPT_ERROR , " No active track to join to " ) ;
return OPERATOR_CANCELLED ;
}
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
next = track - > next ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( TRACK_VIEW_SELECTED ( sc , track ) & & track ! = act_track ) {
2012-06-15 11:03:23 +00:00
BKE_tracking_tracks_join ( act_track , track ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( tracking - > stabilization . rot_track = = track )
2012-03-25 23:19:21 +00:00
tracking - > stabilization . rot_track = act_track ;
2012-03-09 10:01:29 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_track_free ( track ) ;
2011-12-05 18:57:17 +00:00
BLI_freelinkN ( tracksbase , track ) ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
track = next ;
2011-11-07 12:55:18 +00:00
}
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EDITED , clip ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_join_tracks ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Join Tracks " ;
ot - > description = " Join selected tracks " ;
ot - > idname = " CLIP_OT_join_tracks " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = join_tracks_exec ;
2012-06-07 16:36:19 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** lock tracks operator *********************/
static int lock_tracks_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2012-03-25 23:19:21 +00:00
MovieTrackingTrack * track = tracksbase - > first ;
int action = RNA_enum_get ( op - > ptr , " action " ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
while ( track ) {
if ( TRACK_VIEW_SELECTED ( sc , track ) ) {
2012-03-25 23:19:21 +00:00
if ( action = = 0 )
track - > flag | = TRACK_LOCKED ;
else if ( action = = 1 )
track - > flag & = ~ TRACK_LOCKED ;
else track - > flag ^ = TRACK_LOCKED ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EVALUATED , clip ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_lock_tracks ( wmOperatorType * ot )
{
static EnumPropertyItem actions_items [ ] = {
2012-06-10 19:59:02 +00:00
{ 0 , " LOCK " , 0 , " Lock " , " Lock selected tracks " } ,
{ 1 , " UNLOCK " , 0 , " Unlock " , " Unlock selected tracks " } ,
{ 2 , " TOGGLE " , 0 , " Toggle " , " Toggle locked flag for selected tracks " } ,
{ 0 , NULL , 0 , NULL , NULL }
2011-11-07 12:55:18 +00:00
} ;
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Lock Tracks " ;
ot - > description = " Lock/unlock selected tracks " ;
ot - > idname = " CLIP_OT_lock_tracks " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = lock_tracks_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* properties */
RNA_def_enum ( ot - > srna , " action " , actions_items , 0 , " Action " , " Lock action to execute " ) ;
}
2012-07-26 09:50:27 +00:00
/********************** set keyframe operator *********************/
static int set_solver_keyframe_exec ( bContext * C , wmOperator * op )
{
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
MovieTracking * tracking = & clip - > tracking ;
2012-10-09 10:33:18 +00:00
MovieTrackingObject * object = BKE_tracking_object_get_active ( tracking ) ;
2012-07-26 09:50:27 +00:00
int keyframe = RNA_enum_get ( op - > ptr , " keyframe " ) ;
int framenr = BKE_movieclip_remap_scene_to_clip_frame ( clip , sc - > user . framenr ) ;
if ( keyframe = = 0 )
2012-10-09 10:33:18 +00:00
object - > keyframe1 = framenr ;
2012-07-26 09:50:27 +00:00
else
2012-10-09 10:33:18 +00:00
object - > keyframe2 = framenr ;
2012-07-26 09:50:27 +00:00
2012-07-27 13:49:26 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | ND_DISPLAY , clip ) ;
2012-07-26 09:50:27 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_set_solver_keyframe ( wmOperatorType * ot )
{
static EnumPropertyItem keyframe_items [ ] = {
{ 0 , " KEYFRAME_A " , 0 , " Keyframe A " , " " } ,
{ 1 , " KEYFRAME_B " , 0 , " Keyframe B " , " " } ,
{ 0 , NULL , 0 , NULL , NULL }
} ;
/* identifiers */
2012-07-26 10:06:08 +00:00
ot - > name = " Set Solver Keyframe " ;
2012-07-26 09:50:27 +00:00
ot - > description = " Set keyframe used by solver " ;
ot - > idname = " CLIP_OT_set_solver_keyframe " ;
/* api callbacks */
ot - > exec = set_solver_keyframe_exec ;
ot - > poll = ED_space_clip_tracking_poll ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
/* properties */
RNA_def_enum ( ot - > srna , " keyframe " , keyframe_items , 0 , " Keyframe " , " keyframe to set " ) ;
}
2011-11-07 12:55:18 +00:00
/********************** track copy color operator *********************/
static int track_copy_color_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
MovieTrackingTrack * track , * act_track = BKE_tracking_track_get_active ( tracking ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( ! act_track )
2011-11-07 12:55:18 +00:00
return OPERATOR_CANCELLED ;
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
if ( TRACK_VIEW_SELECTED ( sc , track ) & & track ! = act_track ) {
track - > flag & = ~ TRACK_CUSTOMCOLOR ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( act_track - > flag & TRACK_CUSTOMCOLOR ) {
2011-11-07 12:55:18 +00:00
copy_v3_v3 ( track - > color , act_track - > color ) ;
2012-03-25 23:19:21 +00:00
track - > flag | = TRACK_CUSTOMCOLOR ;
2011-11-07 12:55:18 +00:00
}
}
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | ND_DISPLAY , clip ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_track_copy_color ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Copy Color " ;
ot - > description = " Copy color to all selected tracks " ;
ot - > idname = " CLIP_OT_track_copy_color " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = track_copy_color_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** add 2d stabilization tracks operator *********************/
static int stabilize_2d_add_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-03-25 23:19:21 +00:00
MovieTrackingStabilization * stab = & tracking - > stabilization ;
int update = 0 ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-05-07 08:53:59 +00:00
if ( TRACK_VIEW_SELECTED ( sc , track ) & & ( track - > flag & TRACK_USE_2D_STAB ) = = 0 ) {
2012-03-25 23:19:21 +00:00
track - > flag | = TRACK_USE_2D_STAB ;
2011-11-07 12:55:18 +00:00
stab - > tot_track + + ;
2012-03-25 23:19:21 +00:00
update = 1 ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2012-03-24 06:38:07 +00:00
if ( update ) {
2012-03-25 23:19:21 +00:00
stab - > ok = 0 ;
2011-11-07 12:55:18 +00:00
DAG_id_tag_update ( & clip - > id , 0 ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | ND_DISPLAY , clip ) ;
2011-11-07 12:55:18 +00:00
}
return OPERATOR_FINISHED ;
}
void CLIP_OT_stabilize_2d_add ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Add Stabilization Tracks " ;
ot - > description = " Add selected tracks to 2D stabilization tool " ;
ot - > idname = " CLIP_OT_stabilize_2d_add " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = stabilize_2d_add_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** remove 2d stabilization tracks operator *********************/
static int stabilize_2d_remove_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
MovieTrackingStabilization * stab = & tracking - > stabilization ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-03-25 23:19:21 +00:00
int a = 0 , update = 0 ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
if ( track - > flag & TRACK_USE_2D_STAB ) {
if ( a = = stab - > act_track ) {
track - > flag & = ~ TRACK_USE_2D_STAB ;
2011-11-07 12:55:18 +00:00
stab - > act_track - - ;
stab - > tot_track - - ;
2012-05-07 08:53:59 +00:00
if ( stab - > act_track < 0 )
2012-03-25 23:19:21 +00:00
stab - > act_track = 0 ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
update = 1 ;
2011-11-07 12:55:18 +00:00
break ;
}
a + + ;
}
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2012-03-24 06:38:07 +00:00
if ( update ) {
2012-03-25 23:19:21 +00:00
stab - > ok = 0 ;
2011-11-07 12:55:18 +00:00
DAG_id_tag_update ( & clip - > id , 0 ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | ND_DISPLAY , clip ) ;
2011-11-07 12:55:18 +00:00
}
return OPERATOR_FINISHED ;
}
void CLIP_OT_stabilize_2d_remove ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Remove Stabilization Track " ;
ot - > description = " Remove selected track from stabilization " ;
ot - > idname = " CLIP_OT_stabilize_2d_remove " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = stabilize_2d_remove_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** select 2d stabilization tracks operator *********************/
static int stabilize_2d_select_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
2011-11-07 12:55:18 +00:00
MovieTrackingTrack * track ;
2012-03-25 23:19:21 +00:00
int update = 0 ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
if ( track - > flag & TRACK_USE_2D_STAB ) {
2012-06-15 11:03:23 +00:00
BKE_tracking_track_flag_set ( track , TRACK_AREA_ALL , SELECT ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
update = 1 ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
track = track - > next ;
2011-11-07 12:55:18 +00:00
}
2012-03-24 06:38:07 +00:00
if ( update )
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | ND_SELECT , clip ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_stabilize_2d_select ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Select Stabilization Tracks " ;
ot - > description = " Select track which are used for stabilization " ;
ot - > idname = " CLIP_OT_stabilize_2d_select " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = stabilize_2d_select_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** set 2d stabilization rotation track operator *********************/
static int stabilize_2d_set_rotation_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
MovieTrackingTrack * act_track = BKE_tracking_track_get_active ( tracking ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( act_track ) {
2012-03-25 23:19:21 +00:00
MovieTrackingStabilization * stab = & tracking - > stabilization ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
stab - > rot_track = act_track ;
stab - > ok = 0 ;
2011-11-07 12:55:18 +00:00
DAG_id_tag_update ( & clip - > id , 0 ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | ND_DISPLAY , clip ) ;
2011-11-07 12:55:18 +00:00
}
return OPERATOR_FINISHED ;
}
void CLIP_OT_stabilize_2d_set_rotation ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Set Rotation Track " ;
ot - > description = " Use active track to compensate rotation when doing 2D stabilization " ;
ot - > idname = " CLIP_OT_stabilize_2d_set_rotation " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = stabilize_2d_set_rotation_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
}
/********************** clean tracks operator *********************/
static int is_track_clean ( MovieTrackingTrack * track , int frames , int del )
{
2012-03-25 23:19:21 +00:00
int ok = 1 , a , prev = - 1 , count = 0 ;
MovieTrackingMarker * markers = track - > markers , * new_markers = NULL ;
int start_disabled = 0 ;
int markersnr = track - > markersnr ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( del )
2012-06-10 19:59:02 +00:00
new_markers = MEM_callocN ( markersnr * sizeof ( MovieTrackingMarker ) , " track cleaned markers " ) ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
for ( a = 0 ; a < markersnr ; a + + ) {
2012-03-25 23:19:21 +00:00
int end = 0 ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( prev = = - 1 ) {
2012-05-07 08:53:59 +00:00
if ( ( markers [ a ] . flag & MARKER_DISABLED ) = = 0 )
2012-03-25 23:19:21 +00:00
prev = a ;
2011-11-07 12:55:18 +00:00
else
2012-03-25 23:19:21 +00:00
start_disabled = 1 ;
2011-11-07 12:55:18 +00:00
}
2012-03-24 06:38:07 +00:00
if ( prev > = 0 ) {
2012-05-07 08:53:59 +00:00
end = a = = markersnr - 1 ;
end | = ( a < markersnr - 1 ) & & ( markers [ a ] . framenr ! = markers [ a + 1 ] . framenr - 1 | |
markers [ a ] . flag & MARKER_DISABLED ) ;
2011-11-07 12:55:18 +00:00
}
2012-03-24 06:38:07 +00:00
if ( end ) {
2012-03-25 23:19:21 +00:00
int segok = 1 , len = 0 ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
if ( a ! = prev & & markers [ a ] . framenr ! = markers [ a - 1 ] . framenr + 1 )
len = a - prev ;
2012-03-25 23:19:21 +00:00
else if ( markers [ a ] . flag & MARKER_DISABLED )
2012-05-07 08:53:59 +00:00
len = a - prev ;
else len = a - prev + 1 ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( frames ) {
if ( len < frames ) {
2012-03-25 23:19:21 +00:00
segok = 0 ;
ok = 0 ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( ! del )
2011-11-07 12:55:18 +00:00
break ;
}
}
2012-03-24 06:38:07 +00:00
if ( del ) {
if ( segok ) {
2012-03-25 23:19:21 +00:00
int t = len ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( markers [ a ] . flag & MARKER_DISABLED )
2011-11-07 12:55:18 +00:00
t + + ;
/* place disabled marker in front of current segment */
2012-03-24 06:38:07 +00:00
if ( start_disabled ) {
2012-05-07 08:53:59 +00:00
memcpy ( new_markers + count , markers + prev , sizeof ( MovieTrackingMarker ) ) ;
2011-11-07 12:55:18 +00:00
new_markers [ count ] . framenr - - ;
2012-03-25 23:19:21 +00:00
new_markers [ count ] . flag | = MARKER_DISABLED ;
2011-11-07 12:55:18 +00:00
count + + ;
2012-03-25 23:19:21 +00:00
start_disabled = 0 ;
2011-11-07 12:55:18 +00:00
}
2012-05-07 08:53:59 +00:00
memcpy ( new_markers + count , markers + prev , t * sizeof ( MovieTrackingMarker ) ) ;
2012-03-25 23:19:21 +00:00
count + = t ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
else if ( markers [ a ] . flag & MARKER_DISABLED ) {
2011-11-07 12:55:18 +00:00
/* current segment which would be deleted was finished by disabled marker,
2012-03-03 16:31:46 +00:00
* so next segment should be started from disabled marker */
2012-03-25 23:19:21 +00:00
start_disabled = 1 ;
2011-11-07 12:55:18 +00:00
}
}
2012-03-25 23:19:21 +00:00
prev = - 1 ;
2011-11-07 12:55:18 +00:00
}
}
2012-03-24 06:38:07 +00:00
if ( del ) {
2011-11-07 12:55:18 +00:00
MEM_freeN ( track - > markers ) ;
2012-03-24 06:38:07 +00:00
if ( count ) {
2012-03-25 23:19:21 +00:00
track - > markers = new_markers ;
2011-11-07 12:55:18 +00:00
}
else {
2012-03-25 23:19:21 +00:00
track - > markers = NULL ;
2011-11-07 12:55:18 +00:00
MEM_freeN ( new_markers ) ;
}
2012-03-25 23:19:21 +00:00
track - > markersnr = count ;
2011-11-07 12:55:18 +00:00
}
return ok ;
}
static int clean_tracks_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
ListBase * tracksbase = BKE_tracking_get_active_tracks ( tracking ) ;
MovieTrackingTrack * track , * next , * act_track = BKE_tracking_track_get_active ( tracking ) ;
2012-03-25 23:19:21 +00:00
int frames = RNA_int_get ( op - > ptr , " frames " ) ;
int action = RNA_enum_get ( op - > ptr , " action " ) ;
float error = RNA_float_get ( op - > ptr , " error " ) ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
if ( error & & action = = TRACKING_CLEAN_DELETE_SEGMENT )
action = TRACKING_CLEAN_DELETE_TRACK ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
track = tracksbase - > first ;
2012-03-24 06:38:07 +00:00
while ( track ) {
2012-03-25 23:19:21 +00:00
next = track - > next ;
2011-11-07 12:55:18 +00:00
2012-05-07 08:53:59 +00:00
if ( ( track - > flag & TRACK_HIDDEN ) = = 0 & & ( track - > flag & TRACK_LOCKED ) = = 0 ) {
2012-03-25 23:19:21 +00:00
int ok = 1 ;
2011-11-07 12:55:18 +00:00
2012-03-25 23:19:21 +00:00
ok = ( is_track_clean ( track , frames , action = = TRACKING_CLEAN_DELETE_SEGMENT ) ) & &
2012-06-10 19:59:02 +00:00
( error = = 0.0f | | ( track - > flag & TRACK_HAS_BUNDLE ) = = 0 | | track - > error < error ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( ! ok ) {
2012-03-25 23:19:21 +00:00
if ( action = = TRACKING_CLEAN_SELECT ) {
2012-06-15 11:03:23 +00:00
BKE_tracking_track_flag_set ( track , TRACK_AREA_ALL , SELECT ) ;
2011-11-07 12:55:18 +00:00
}
2012-03-25 23:19:21 +00:00
else if ( action = = TRACKING_CLEAN_DELETE_TRACK ) {
if ( track = = act_track )
clip - > tracking . act_track = NULL ;
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_track_free ( track ) ;
2011-12-05 18:57:17 +00:00
BLI_freelinkN ( tracksbase , track ) ;
2012-03-25 23:19:21 +00:00
track = NULL ;
2011-11-07 12:55:18 +00:00
}
/* happens when all tracking segments are not long enough */
2012-03-25 23:19:21 +00:00
if ( track & & track - > markersnr = = 0 ) {
if ( track = = act_track )
clip - > tracking . act_track = NULL ;
2011-11-07 12:55:18 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_track_free ( track ) ;
2011-12-05 18:57:17 +00:00
BLI_freelinkN ( tracksbase , track ) ;
2011-11-07 12:55:18 +00:00
}
}
}
2012-03-25 23:19:21 +00:00
track = next ;
2011-11-07 12:55:18 +00:00
}
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | ND_SELECT , clip ) ;
2011-11-07 12:55:18 +00:00
return OPERATOR_FINISHED ;
}
static int clean_tracks_invoke ( bContext * C , wmOperator * op , wmEvent * UNUSED ( event ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2011-11-07 12:55:18 +00:00
2012-03-24 06:38:07 +00:00
if ( ! RNA_struct_property_is_set ( op - > ptr , " frames " ) )
2011-11-07 12:55:18 +00:00
RNA_int_set ( op - > ptr , " frames " , clip - > tracking . settings . clean_frames ) ;
2012-02-02 19:37:50 +00:00
2012-03-24 06:38:07 +00:00
if ( ! RNA_struct_property_is_set ( op - > ptr , " error " ) )
2011-11-07 12:55:18 +00:00
RNA_float_set ( op - > ptr , " error " , clip - > tracking . settings . clean_error ) ;
2012-02-02 19:37:50 +00:00
2012-03-24 06:38:07 +00:00
if ( ! RNA_struct_property_is_set ( op - > ptr , " action " ) )
2011-11-07 12:55:18 +00:00
RNA_enum_set ( op - > ptr , " action " , clip - > tracking . settings . clean_action ) ;
return clean_tracks_exec ( C , op ) ;
}
void CLIP_OT_clean_tracks ( wmOperatorType * ot )
{
static EnumPropertyItem actions_items [ ] = {
2012-06-10 19:59:02 +00:00
{ TRACKING_CLEAN_SELECT , " SELECT " , 0 , " Select " , " Select unclean tracks " } ,
{ TRACKING_CLEAN_DELETE_TRACK , " DELETE_TRACK " , 0 , " Delete Track " , " Delete unclean tracks " } ,
{ TRACKING_CLEAN_DELETE_SEGMENT , " DELETE_SEGMENTS " , 0 , " Delete Segments " , " Delete unclean segments of tracks " } ,
{ 0 , NULL , 0 , NULL , NULL }
2011-11-07 12:55:18 +00:00
} ;
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Clean Tracks " ;
ot - > description = " Clean tracks with high error values or few frames " ;
ot - > idname = " CLIP_OT_clean_tracks " ;
2011-11-07 12:55:18 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = clean_tracks_exec ;
ot - > invoke = clean_tracks_invoke ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-11-07 12:55:18 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-11-07 12:55:18 +00:00
/* properties */
2012-04-14 15:44:31 +00:00
RNA_def_int ( ot - > srna , " frames " , 0 , 0 , INT_MAX , " Tracked Frames " ,
" Effect on tracks which are tracked less than specified amount of frames " , 0 , INT_MAX ) ;
RNA_def_float ( ot - > srna , " error " , 0.0f , 0.0f , FLT_MAX , " Reprojection Error " ,
" Effect on tracks which have got larger re-projection error " , 0.0f , 100.0f ) ;
2011-11-07 12:55:18 +00:00
RNA_def_enum ( ot - > srna , " action " , actions_items , 0 , " Action " , " Cleanup action to execute " ) ;
}
2011-12-05 18:57:17 +00:00
/********************** add tracking object *********************/
static int tracking_object_new_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2011-12-05 18:57:17 +00:00
2012-06-15 11:03:23 +00:00
BKE_tracking_object_add ( tracking , " Object " ) ;
2011-12-05 18:57:17 +00:00
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EDITED , clip ) ;
2011-12-05 18:57:17 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_tracking_object_new ( wmOperatorType * ot )
{
/* identifiers */
2012-03-22 07:26:09 +00:00
ot - > name = " Add Tracking Object " ;
ot - > description = " Add new object for tracking " ;
ot - > idname = " CLIP_OT_tracking_object_new " ;
2011-12-05 18:57:17 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = tracking_object_new_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-12-05 18:57:17 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-12-05 18:57:17 +00:00
}
/********************** remove tracking object *********************/
static int tracking_object_remove_exec ( bContext * C , wmOperator * op )
{
2012-03-25 23:19:21 +00:00
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-03-25 23:19:21 +00:00
MovieTracking * tracking = & clip - > tracking ;
2011-12-05 18:57:17 +00:00
MovieTrackingObject * object ;
2012-06-15 11:03:23 +00:00
object = BKE_tracking_object_get_active ( tracking ) ;
2011-12-05 18:57:17 +00:00
2012-03-25 23:19:21 +00:00
if ( object - > flag & TRACKING_OBJECT_CAMERA ) {
2011-12-05 18:57:17 +00:00
BKE_report ( op - > reports , RPT_WARNING , " Object used for camera tracking can't be deleted " ) ;
return OPERATOR_CANCELLED ;
}
2012-06-15 11:03:23 +00:00
BKE_tracking_object_delete ( tracking , object ) ;
2011-12-05 18:57:17 +00:00
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EDITED , clip ) ;
2011-12-05 18:57:17 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_tracking_object_remove ( wmOperatorType * ot )
{
/* identifiers */
2012-06-24 13:52:20 +00:00
ot - > name = " Remove Tracking Object " ;
2012-03-22 07:26:09 +00:00
ot - > description = " Remove object for tracking " ;
ot - > idname = " CLIP_OT_tracking_object_remove " ;
2011-12-05 18:57:17 +00:00
/* api callbacks */
2012-03-22 07:26:09 +00:00
ot - > exec = tracking_object_remove_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2011-12-05 18:57:17 +00:00
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2011-12-05 18:57:17 +00:00
}
2012-01-09 20:18:48 +00:00
/********************** copy tracks to clipboard operator *********************/
static int copy_tracks_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-01-09 20:18:48 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
MovieTrackingObject * object = BKE_tracking_object_get_active ( tracking ) ;
2012-01-09 20:18:48 +00:00
clear_invisible_track_selection ( sc , clip ) ;
BKE_tracking_clipboard_copy_tracks ( tracking , object ) ;
return OPERATOR_FINISHED ;
}
void CLIP_OT_copy_tracks ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Copy Tracks " ;
ot - > description = " Copy selected tracks to clipboard " ;
ot - > idname = " CLIP_OT_copy_tracks " ;
/* api callbacks */
ot - > exec = copy_tracks_exec ;
2012-04-29 12:32:26 +00:00
ot - > poll = ED_space_clip_tracking_poll ;
2012-01-09 20:18:48 +00:00
/* flags */
2012-03-22 07:26:09 +00:00
ot - > flag = OPTYPE_REGISTER ;
2012-01-09 20:18:48 +00:00
}
/********************** paste tracks from clipboard operator *********************/
static int paste_tracks_poll ( bContext * C )
{
2012-04-29 12:32:26 +00:00
if ( ED_space_clip_tracking_poll ( C ) ) {
2012-01-09 20:18:48 +00:00
return BKE_tracking_clipboard_has_tracks ( ) ;
}
return 0 ;
}
static int paste_tracks_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
SpaceClip * sc = CTX_wm_space_clip ( C ) ;
2012-06-19 14:26:29 +00:00
MovieClip * clip = ED_space_clip_get_clip ( sc ) ;
2012-01-09 20:18:48 +00:00
MovieTracking * tracking = & clip - > tracking ;
2012-06-15 11:03:23 +00:00
MovieTrackingObject * object = BKE_tracking_object_get_active ( tracking ) ;
2012-01-09 20:18:48 +00:00
BKE_tracking_clipboard_paste_tracks ( tracking , object ) ;
2012-05-07 08:53:59 +00:00
WM_event_add_notifier ( C , NC_MOVIECLIP | NA_EDITED , clip ) ;
2012-01-09 20:18:48 +00:00
return OPERATOR_FINISHED ;
}
void CLIP_OT_paste_tracks ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Paste Tracks " ;
ot - > description = " Paste tracks from clipboard " ;
ot - > idname = " CLIP_OT_paste_tracks " ;
/* api callbacks */
ot - > exec = paste_tracks_exec ;
ot - > poll = paste_tracks_poll ;
/* flags */
2012-05-07 08:53:59 +00:00
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2012-01-09 20:18:48 +00:00
}