[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42733] branches/soc-2011-tomato: Object tracking: configurable scale for object solution

Sergey Sharybin sergey.vfx at gmail.com
Mon Dec 19 16:12:41 CET 2011


Revision: 42733
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42733
Author:   nazgul
Date:     2011-12-19 15:12:33 +0000 (Mon, 19 Dec 2011)
Log Message:
-----------
Object tracking: configurable scale for object solution

Added slider to define scale of object solution which is used to define
"depth" of object relative to camera position. This slider effects on all
"users" of object solution such as bundles display, constrained objects and so.

Added new operator called "Set Solution Scale" to set real scale for object
solution based on real distance between two bundles reconstructed for this object.

New slider and operator can be found on "Object" panel in toolbox when in
reconstruction mode and active tracking object isn't a camera.

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
    branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
    branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_intern.h
    branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-12-19 14:46:17 UTC (rev 42732)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-12-19 15:12:33 UTC (rev 42733)
@@ -302,6 +302,37 @@
         col.prop(settings, "distance")
 
 
+class CLIP_PT_tools_object(Panel):
+    bl_space_type = 'CLIP_EDITOR'
+    bl_region_type = 'TOOLS'
+    bl_label = "Object"
+
+    @classmethod
+    def poll(cls, context):
+        sc = context.space_data
+        clip = sc.clip
+
+        if clip and sc.mode == 'RECONSTRUCTION':
+            tracking_object = clip.tracking.objects.active
+            return not tracking_object.is_camera
+
+        return False
+
+    def draw(self, context):
+        sc = context.space_data
+        clip = sc.clip
+        layout = self.layout
+        tracking_object = clip.tracking.objects.active
+        settings = sc.clip.tracking.settings
+
+        layout.prop(tracking_object, "scale")
+
+        layout.separator()
+
+        layout.operator("clip.set_solution_scale", text="Set Scale")
+        layout.prop(settings, "object_distance")
+
+
 class CLIP_PT_tools_grease_pencil(Panel):
     bl_space_type = 'CLIP_EDITOR'
     bl_region_type = 'TOOLS'

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-12-19 14:46:17 UTC (rev 42732)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-12-19 15:12:33 UTC (rev 42733)
@@ -86,6 +86,7 @@
 	tracking->settings.keyframe1= 1;
 	tracking->settings.keyframe2= 30;
 	tracking->settings.dist= 1;
+	tracking->settings.object_distance= 1;
 
 	tracking->stabilization.scaleinf= 1.0f;
 	tracking->stabilization.locinf= 1.0f;
@@ -1920,6 +1921,16 @@
 	return -1;
 }
 
+static void scale_reconstructed_camera(MovieTrackingObject *object, float mat[4][4])
+{
+	if((object->flag&TRACKING_OBJECT_CAMERA)==0) {
+		float smat[4][4];
+
+		scale_m4_fl(smat, 1.0f/object->scale);
+		mult_m4_m4m4(mat, mat, smat);
+	}
+}
+
 MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(MovieTracking *tracking,
 			MovieTrackingObject *object, int framenr)
 {
@@ -1958,6 +1969,8 @@
 	} else {
 		copy_m4_m4(mat, cameras[a].mat);
 	}
+
+	scale_reconstructed_camera(object, mat);
 }
 
 void BKE_get_tracking_mat(Scene *scene, Object *ob, float mat[4][4])

Modified: branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c	2011-12-19 14:46:17 UTC (rev 42732)
+++ branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c	2011-12-19 15:12:33 UTC (rev 42733)
@@ -12693,9 +12693,20 @@
 
 		for (clip= main->movieclip.first; clip; clip= clip->id.next) {
 			MovieTracking *tracking= &clip->tracking;
+			MovieTrackingObject *tracking_object= tracking->objects.first;
 
+			if(!tracking->settings.object_distance)
+				tracking->settings.object_distance= 1.0f;
+
 			if(tracking->objects.first == NULL)
 				BKE_tracking_new_object(tracking, "Camera");
+
+			while(tracking_object) {
+				if(!tracking_object->scale)
+					tracking_object->scale= 1.0f;
+
+				tracking_object= tracking_object->next;
+			}
 		}
 
 		for (ob= main->object.first; ob; ob= ob->id.next) {

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_intern.h
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_intern.h	2011-12-19 14:46:17 UTC (rev 42732)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_intern.h	2011-12-19 15:12:33 UTC (rev 42733)
@@ -124,6 +124,7 @@
 void CLIP_OT_set_floor(struct wmOperatorType *ot);
 void CLIP_OT_set_axis(struct wmOperatorType *ot);
 void CLIP_OT_set_scale(struct wmOperatorType *ot);
+void CLIP_OT_set_solution_scale(struct wmOperatorType *ot);
 
 void CLIP_OT_set_center_principal(struct wmOperatorType *ot);
 

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c	2011-12-19 14:46:17 UTC (rev 42732)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c	2011-12-19 15:12:33 UTC (rev 42733)
@@ -351,6 +351,7 @@
 	WM_operatortype_append(CLIP_OT_set_floor);
 	WM_operatortype_append(CLIP_OT_set_axis);
 	WM_operatortype_append(CLIP_OT_set_scale);
+	WM_operatortype_append(CLIP_OT_set_solution_scale);
 
 	/* detect */
 	WM_operatortype_append(CLIP_OT_detect_features);

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c	2011-12-19 14:46:17 UTC (rev 42732)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c	2011-12-19 15:12:33 UTC (rev 42733)
@@ -2344,7 +2344,7 @@
 
 /********************** set scale operator *********************/
 
-static int set_scale_exec(bContext *C, wmOperator *op)
+static int do_set_scale(bContext *C, wmOperator *op, int scale_solution)
 {
 	SpaceClip *sc= CTX_wm_space_clip(C);
 	MovieClip *clip= ED_space_clip(sc);
@@ -2352,24 +2352,26 @@
 	MovieTrackingObject *tracking_object= BKE_tracking_active_object(tracking);
 	MovieTrackingTrack *track;
 	Scene *scene= CTX_data_scene(C);
-	Object *object;
+	Object *object= NULL;
 	ListBase *tracksbase= BKE_tracking_get_tracks(tracking);
 	int tot= 0;
 	float vec[2][3], mat[4][4], scale;
 	float dist= RNA_float_get(op->ptr, "distance");
 
 	if(count_selected_bundles(C)!=2) {
-		BKE_report(op->reports, RPT_ERROR, "Two tracks with bundles should be selected to scale scene");
+		BKE_report(op->reports, RPT_ERROR, "Two tracks with bundles should be selected to set scale");
 
 		return OPERATOR_CANCELLED;
 	}
 
-	if(tracking_object->flag&TRACKING_OBJECT_CAMERA)
+	if(tracking_object->flag&TRACKING_OBJECT_CAMERA) {
 		object= scene->camera;
-	else
+	}
+	else if(!scale_solution) {
 		object= OBACT;
+	}
 
-	if(object->parent)
+	if(object && object->parent)
 		object= object->parent;
 
 	BKE_get_tracking_mat(scene, NULL, mat);
@@ -2392,7 +2394,8 @@
 		if(tracking_object->flag&TRACKING_OBJECT_CAMERA) {
 			mul_v3_fl(object->size, scale);
 			mul_v3_fl(object->loc, scale);
-		} else {
+		} else
+		if(!scale_solution){
 			object->size[0]= object->size[1]= object->size[2]= 1.0f/scale;
 
 			if(scene->camera) {
@@ -2401,10 +2404,15 @@
 				object->size[2]/= scene->camera->size[2];
 			}
 		}
+		else {
+			tracking_object->scale= scale;
+		}
 
 		DAG_id_tag_update(&clip->id, 0);
-		DAG_id_tag_update(&object->id, OB_RECALC_OB);
 
+		if(object)
+			DAG_id_tag_update(&object->id, OB_RECALC_OB);
+
 		WM_event_add_notifier(C, NC_MOVIECLIP|NA_EVALUATED, clip);
 		WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
 	}
@@ -2412,6 +2420,11 @@
 	return OPERATOR_FINISHED;
 }
 
+static int set_scale_exec(bContext *C, wmOperator *op)
+{
+	return do_set_scale(C, op, 0);
+}
+
 static int set_scale_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 {
 	SpaceClip *sc= CTX_wm_space_clip(C);
@@ -2444,6 +2457,60 @@
 		"Distance", "Distance between selected tracks", -100.0f, 100.0f);
 }
 
+/********************** set solution scale operator *********************/
+
+static int set_solution_scale_poll(bContext *C)
+{
+	if(space_clip_frame_poll(C)) {
+		Scene *scene= CTX_data_scene(C);
+		SpaceClip *sc= CTX_wm_space_clip(C);
+		MovieClip *clip= ED_space_clip(sc);
+		MovieTracking *tracking= &clip->tracking;
+		MovieTrackingObject *tracking_object= BKE_tracking_active_object(tracking);
+
+		return (tracking_object->flag&TRACKING_OBJECT_CAMERA) == 0;
+	}
+
+	return 0;
+}
+
+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))
+{
+	SpaceClip *sc= CTX_wm_space_clip(C);
+	MovieClip *clip= ED_space_clip(sc);
+	float dist= RNA_float_get(op->ptr, "distance");
+
+	if(dist==0.0f)
+		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 */
+	ot->name= "Set Solution Scale";
+	ot->description= "Set object solution scale using distance between two selected tracks";
+	ot->idname= "CLIP_OT_set_solution_scale";
+
+	/* api callbacks */
+	ot->exec= set_solution_scale_exec;
+	ot->invoke= set_solution_scale_invoke;
+	ot->poll= set_solution_scale_poll;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+	/* properties */
+	RNA_def_float(ot->srna, "distance", 0.0f, -FLT_MAX, FLT_MAX,
+		"Distance", "Distance between selected tracks", -100.0f, 100.0f);
+}
+
 /********************** set principal center operator *********************/
 
 static int set_center_principal_exec(bContext *C, wmOperator *UNUSED(op))

Modified: branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
===================================================================
--- branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h	2011-12-19 14:46:17 UTC (rev 42732)
+++ branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h	2011-12-19 15:12:33 UTC (rev 42733)
@@ -142,7 +142,10 @@
 
 	/* cleanup */
 	int clean_frames, clean_action;
-	float clean_error, pad;
+	float clean_error;
+
+	/* set object scale */
+	float object_distance;		/* distance between two bundles used for object scaling */
 } MovieTrackingSettings;
 
 typedef struct MovieTrackingStabilization {
@@ -176,7 +179,9 @@
 	struct MovieTrackingObject *next, *prev;
 
 	char name[24];			/* Name of tracking object */
-	int flag, pad;
+	int flag;
+	float scale;			/* scale of object solution in amera space */
+
 	ListBase tracks;		/* list of tracks use to tracking this object */
 	MovieTrackingReconstruction reconstruction;	/* reconstruction data for this object */
 } MovieTrackingObject;

Modified: branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list