Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 14 Jul 2011 14:35:04 +0000 (14:35 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 14 Jul 2011 14:35:04 +0000 (14:35 +0000)
===========================

- Tracking camera presets.
- Reset principal to image center operator.

Things to think about:
- Unified presets for tracking camera and blender camera.
- If prinipal should be a part of preset.

release/scripts/startup/bl_operators/presets.py
release/scripts/startup/bl_ui/space_clip.py
source/blender/editors/space_clip/clip_intern.h
source/blender/editors/space_clip/space_clip.c
source/blender/editors/space_clip/tracking_ops.c

index f3c799c9ac28ed85035aef91d65c3cdcb5aa1a7b..fa13c4a3d648800e9b558423fab99366a6ada9c3 100644 (file)
@@ -277,6 +277,28 @@ class AddPresetInteraction(AddPresetBase, bpy.types.Operator):
     preset_subdir = "interaction"
 
 
+class AddPresetTrackingCamera(AddPresetBase, bpy.types.Operator):
+    '''Add a Tracking Camera Intrinsics  Preset'''
+    bl_idname = "clip.camera_preset_add"
+    bl_label = "Add Camera Preset"
+    preset_menu = "CLIP_MT_camera_presets"
+
+    preset_defines = [
+        "camera = bpy.context.edit_movieclip.tracking.camera"
+    ]
+
+    preset_values = [
+        "camera.focal_length",
+        "camera.sensor_width",
+        "camera.units",
+        "camera.k1",
+        "camera.k2",
+        "camera.k3"
+    ]
+
+    preset_subdir = "tracking_camera"
+
+
 class AddPresetKeyconfig(AddPresetBase, bpy.types.Operator):
     '''Add a Keyconfig Preset'''
     bl_idname = "wm.keyconfig_preset_add"
index 6811b152eef8267c46465010113bad74cf0815af..f7cde1561bac8f0aea0ed3a378eff651a1ba7d6a 100644 (file)
@@ -266,6 +266,11 @@ class CLIP_PT_tracking_camera(bpy.types.Panel):
         sc = context.space_data
         clip = sc.clip
 
+        row = layout.row(align=True)
+        row.menu('CLIP_MT_camera_presets')
+        row.operator("clip.camera_preset_add", text="", icon="ZOOMIN")
+        row.operator("clip.camera_preset_add", text="", icon="ZOOMOUT").remove_active = True
+
         layout.prop(clip.tracking.camera, "sensor_width")
 
         row = layout.row(align=True)
@@ -273,10 +278,14 @@ class CLIP_PT_tracking_camera(bpy.types.Panel):
         sub.prop(clip.tracking.camera, "focal_length")
         sub.prop(clip.tracking.camera, "units", text="")
 
-        layout.label(text="Principal Point")
-        layout.prop(clip.tracking.camera, "principal", text="")
+        col = layout.column()
+        col.label(text="Principal Point")
+        row = col.row()
+        row.prop(clip.tracking.camera, "principal", text="")
+        col.operator("clip.set_center_principal", text="Center")
 
         col = layout.column(align=True)
+        col.label(text="Undistortion:")
         col.prop(clip.tracking.camera, "k1")
         col.prop(clip.tracking.camera, "k2")
         col.prop(clip.tracking.camera, "k3")
@@ -489,5 +498,13 @@ class CLIP_MT_tracking_specials(bpy.types.Menu):
         layout.operator("clip.hide_tracks")
         layout.operator("clip.hide_tracks_clear", text="Show Tracks")
 
+
+class CLIP_MT_camera_presets(bpy.types.Menu):
+    bl_label = "Camera Presets"
+    preset_subdir = "tracking_camera"
+    preset_operator = "script.execute_preset"
+    draw = bpy.types.Menu.draw_preset
+
+
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)
index eae34efd8254bd7e72a341096714431a6b9fc110..9d102add3a4bb733a6683cb03630a83a4bd37d27 100644 (file)
@@ -82,6 +82,8 @@ 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_center_principal(struct wmOperatorType *ot);
+
 void CLIP_OT_slide_marker(struct wmOperatorType *ot);
 
 /* clip_draw.c */
index 29d90beb16f371af189b3756b3fbfc41ac81f68d..8bb443325ed17543afe5a6149269eb6973daad73 100644 (file)
@@ -218,6 +218,8 @@ static void clip_operatortypes(void)
        WM_operatortype_append(CLIP_OT_set_axis);
        WM_operatortype_append(CLIP_OT_set_scale);
 
+       WM_operatortype_append(CLIP_OT_set_center_principal);
+
        WM_operatortype_append(CLIP_OT_clear_track_path);
 
        WM_operatortype_append(CLIP_OT_slide_marker);
index 18a9eeb3f49ca9edce67cdfa48c1a2688fa49162..c6a4672148daeb3531dd698fabb5c12a7a150982 100644 (file)
@@ -1580,6 +1580,41 @@ void CLIP_OT_set_scale(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/********************** set principal center operator *********************/
+
+static int set_center_principal_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       SpaceClip *sc= CTX_wm_space_clip(C);
+       MovieClip *clip= ED_space_clip(sc);
+       int width, height;
+
+       BKE_movieclip_acquire_size(clip, &sc->user, &width, &height);
+
+       if(width==0 || height==0)
+               return OPERATOR_CANCELLED;
+
+       clip->tracking.camera.principal[0]= ((float)width)/2.0f;
+       clip->tracking.camera.principal[1]= ((float)height)/2.0f;
+
+       WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, clip);
+
+       return OPERATOR_FINISHED;
+}
+
+void CLIP_OT_set_center_principal(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Set Principal to Center";
+       ot->description= "Set principal point to center of footage";
+       ot->idname= "CLIP_OT_set_center_principal";
+
+       /* api callbacks */
+       ot->exec= set_center_principal_exec;
+       ot->poll= space_clip_tracking_poll;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
 /********************** slide marker opertaotr *********************/
 
 typedef struct {