[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43242] trunk/blender/source/blender: Camera tracking: improvements of python api

Sergey Sharybin sergey.vfx at gmail.com
Mon Jan 9 21:18:29 CET 2012


Revision: 43242
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43242
Author:   nazgul
Date:     2012-01-09 20:18:28 +0000 (Mon, 09 Jan 2012)
Log Message:
-----------
Camera tracking: improvements of python api

- marker_find_frame moved to MovieTrack.markers and called find_frame
- Added MovieTrack.markers.insert_frame to insert marker at specified frame
- Added MovieTrack.markers.delete_frame to delete marker from specified frame

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_tracking.h
    trunk/blender/source/blender/blenkernel/intern/tracking.c
    trunk/blender/source/blender/makesrna/intern/rna_tracking.c

Modified: trunk/blender/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_tracking.h	2012-01-09 20:13:03 UTC (rev 43241)
+++ trunk/blender/source/blender/blenkernel/BKE_tracking.h	2012-01-09 20:18:28 UTC (rev 43242)
@@ -53,7 +53,8 @@
 
 struct MovieTrackingTrack *BKE_tracking_add_track(struct MovieTracking *tracking, struct ListBase *tracksbase,
 			float x, float y, int framenr, int width, int height);
-void BKE_tracking_insert_marker(struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker);
+struct MovieTrackingMarker *BKE_tracking_insert_marker(struct MovieTrackingTrack *track,
+			struct MovieTrackingMarker *marker);
 void BKE_tracking_delete_marker(struct MovieTrackingTrack *track, int framenr);
 
 struct MovieTrackingMarker *BKE_tracking_get_marker(struct MovieTrackingTrack *track, int framenr);

Modified: trunk/blender/source/blender/blenkernel/intern/tracking.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/tracking.c	2012-01-09 20:13:03 UTC (rev 43241)
+++ trunk/blender/source/blender/blenkernel/intern/tracking.c	2012-01-09 20:18:28 UTC (rev 43242)
@@ -261,7 +261,7 @@
 	return track;
 }
 
-void BKE_tracking_insert_marker(MovieTrackingTrack *track, MovieTrackingMarker *marker)
+MovieTrackingMarker *BKE_tracking_insert_marker(MovieTrackingTrack *track, MovieTrackingMarker *marker)
 {
 	MovieTrackingMarker *old_marker= NULL;
 
@@ -270,6 +270,8 @@
 
 	if(old_marker) {
 		*old_marker= *marker;
+
+		return old_marker;
 	} else {
 		int a= track->markersnr;
 
@@ -287,6 +289,8 @@
 		track->markers[a+1]= *marker;
 
 		track->last_marker= a+1;
+
+		return &track->markers[a+1];
 	}
 }
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_tracking.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_tracking.c	2012-01-09 20:13:03 UTC (rev 43241)
+++ trunk/blender/source/blender/makesrna/intern/rna_tracking.c	2012-01-09 20:18:28 UTC (rev 43242)
@@ -31,6 +31,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_math.h"
 #include "BKE_movieclip.h"
 #include "BKE_tracking.h"
 
@@ -372,7 +373,7 @@
 
 	add_tracks_to_base(clip, tracking, &tracking->tracks, frame, number);
 
-	WM_main_add_notifier(NC_MOVIECLIP|NA_EDITED, NULL);
+	WM_main_add_notifier(NC_MOVIECLIP|NA_EDITED, clip);
 }
 
 static void rna_trackingObject_tracks_add(ID *id, MovieTrackingObject *object, int frame, int number)
@@ -404,11 +405,36 @@
 	WM_main_add_notifier(NC_MOVIECLIP|NA_EDITED, NULL);
 }
 
-static MovieTrackingMarker *rna_trackingTrack_marker_find_frame(MovieTrackingTrack *track, int framenr)
+static MovieTrackingMarker *rna_trackingMarkers_find_frame(MovieTrackingTrack *track, int framenr)
 {
-	return BKE_tracking_get_marker(track, framenr);
+	return BKE_tracking_exact_marker(track, framenr);
 }
 
+static MovieTrackingMarker* rna_trackingMarkers_insert_frame(MovieTrackingTrack *track, int framenr, float *co)
+{
+	MovieTrackingMarker marker, *new_marker;
+
+	memset(&marker, 0, sizeof(marker));
+	marker.framenr = framenr;
+	copy_v2_v2(marker.pos, co);
+
+	new_marker = BKE_tracking_insert_marker(track, &marker);
+
+	WM_main_add_notifier(NC_MOVIECLIP|NA_EDITED, NULL);
+
+	return new_marker;
+}
+
+void rna_trackingMarkers_delete_frame(MovieTrackingTrack *track, int framenr)
+{
+	if(track->markersnr==1)
+		return;
+
+	BKE_tracking_delete_marker(track, framenr);
+
+	WM_main_add_notifier(NC_MOVIECLIP|NA_EDITED, NULL);
+}
+
 #else
 
 static EnumPropertyItem tracker_items[] = {
@@ -704,14 +730,48 @@
 	RNA_def_property_update(prop, NC_MOVIECLIP|NA_EDITED, NULL);
 }
 
+static void rna_def_trackingMarkers(BlenderRNA *brna, PropertyRNA *cprop)
+{
+	StructRNA *srna;
+	FunctionRNA *func;
+	PropertyRNA *parm;
+
+	RNA_def_property_srna(cprop, "MovieTrackingMarkers");
+	srna= RNA_def_struct(brna, "MovieTrackingMarkers", NULL);
+	RNA_def_struct_sdna(srna, "MovieTrackingTrack");
+	RNA_def_struct_ui_text(srna, "Movie Tracking Markers", "Collection of markers for movie tracking track");
+
+	func= RNA_def_function(srna, "find_frame", "rna_trackingMarkers_find_frame");
+	RNA_def_function_ui_description(func, "Get marker for specified frame");
+	parm= RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame",
+			 "Frame number to find marker for", MINFRAME, MAXFRAME);
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	parm= RNA_def_pointer(func, "marker", "MovieTrackingMarker", "", "Marker for specified frame");
+	RNA_def_function_return(func, parm);
+
+	func= RNA_def_function(srna, "insert_frame", "rna_trackingMarkers_insert_frame");
+	RNA_def_function_ui_description(func, "Add a number of tracks to this movie clip");
+	parm= RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame",
+			"Frame number to insert marker to", MINFRAME, MAXFRAME);
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	RNA_def_float_vector(func, "co", 2, 0, -1.0, 1.0, "Coordinate",
+			"Place new marker at the given frame using specified in normalized space coordinates", -1.0, 1.0);
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	parm= RNA_def_pointer(func, "marker", "MovieTrackingMarker", "", "Newly created marker");
+	RNA_def_function_return(func, parm);
+
+	func= RNA_def_function(srna, "delete_frame", "rna_trackingMarkers_delete_frame");
+	RNA_def_function_ui_description(func, "Delete marker at specified frame");
+	parm= RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame",
+			"Frame number to delete marker from", MINFRAME, MAXFRAME);
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+}
+
 static void rna_def_trackingTrack(BlenderRNA *brna)
 {
 	StructRNA *srna;
 	PropertyRNA *prop;
 
-	FunctionRNA *func;
-	PropertyRNA *parm;
-
 	rna_def_trackingMarker(brna);
 
 	srna= RNA_def_struct(brna, "MovieTrackingTrack", NULL);
@@ -805,6 +865,7 @@
 	RNA_def_property_struct_type(prop, "MovieTrackingMarker");
 	RNA_def_property_collection_sdna(prop, NULL, "markers", "markersnr");
 	RNA_def_property_ui_text(prop, "Markers", "Collection of markers in track");
+	rna_def_trackingMarkers(brna, prop);
 
 	/* ** channels ** */
 
@@ -899,15 +960,6 @@
 	RNA_def_property_float_sdna(prop, NULL, "error");
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Average Error", "Average error of re-projection");
-
-	/* ** api ** */
-
-	func= RNA_def_function(srna, "marker_find_frame", "rna_trackingTrack_marker_find_frame");
-	RNA_def_function_ui_description(func, "Get marker for specified frame");
-	parm= RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame", "type for the new spline", MINFRAME, MAXFRAME);
-	RNA_def_property_flag(parm, PROP_REQUIRED);
-	parm= RNA_def_pointer(func, "marker", "MovieTrackingMarker", "", "Marker for specified frame");
-	RNA_def_function_return(func, parm);
 }
 
 static void rna_def_trackingStabilization(BlenderRNA *brna)



More information about the Bf-blender-cvs mailing list