[Bf-blender-cvs] [c458725] soc-2016-multiview: complete new and free multiview reconstruction context, so far so good
Tianwei Shen
noreply at git.blender.org
Wed Jun 8 08:14:23 CEST 2016
Commit: c458725976b502db0703ba616df1d5392f052ed4
Author: Tianwei Shen
Date: Wed Jun 8 14:14:13 2016 +0800
Branches: soc-2016-multiview
https://developer.blender.org/rBc458725976b502db0703ba616df1d5392f052ed4
complete new and free multiview reconstruction context, so far so good
===================================================================
M source/blender/blenkernel/BKE_tracking.h
M source/blender/blenkernel/intern/tracking_correspondence.c
M source/blender/editors/space_clip/tracking_ops_correspondence.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h
index 7432207..9c7ec2f 100644
--- a/source/blender/blenkernel/BKE_tracking.h
+++ b/source/blender/blenkernel/BKE_tracking.h
@@ -289,7 +289,7 @@ void BKE_tracking_stabilization_data_to_mat4(int width, int height, float aspect
void BKE_tracking_dopesheet_tag_update(struct MovieTracking *tracking);
void BKE_tracking_dopesheet_update(struct MovieTracking *tracking);
-/* Correspondence */
+/* Correspondence and multiview */
void BKE_tracking_correspondence_unique_name(struct ListBase *tracksbase, struct MovieTrackingCorrespondence *corr);
struct MovieTrackingCorrespondence *BKE_tracking_correspondence_add(struct ListBase *corr_base,
struct MovieTrackingTrack *self_track,
@@ -303,8 +303,11 @@ struct MovieMultiviewReconstructContext *BKE_tracking_multiview_reconstruction_c
struct MovieTrackingObject *object,
int keyframe1, int keyframe2,
int width, int height);
+void BKE_tracking_multiview_reconstruction_context_free(struct MovieMultiviewReconstructContext *context);
bool BKE_tracking_multiview_reconstruction_check(struct MovieClip **clips, struct MovieTrackingObject *object,
int clip_num, char *error_msg, int error_size);
+bool BKE_tracking_multiview_reconstruction_finish(struct MovieMultiviewReconstructContext *context,
+ struct MovieTracking *tracking);
#define TRACK_SELECTED(track) ((track)->flag & SELECT || (track)->pat_flag & SELECT || (track)->search_flag & SELECT)
diff --git a/source/blender/blenkernel/intern/tracking_correspondence.c b/source/blender/blenkernel/intern/tracking_correspondence.c
index 068a93b..7f4a462 100644
--- a/source/blender/blenkernel/intern/tracking_correspondence.c
+++ b/source/blender/blenkernel/intern/tracking_correspondence.c
@@ -57,8 +57,8 @@
struct ReconstructProgressData;
typedef struct MovieMultiviewReconstructContext {
+ int clip_num; /* number of clips in this reconstruction */
struct libmv_TracksN **all_tracks; /* set of tracks from all clips (API in autotrack) */
-
// TODO(tianwei): might be proper to make it libmv_multiview_Reconstruction
struct libmv_ReconstructionN **all_reconstruction; /* reconstruction for each clip (API in autotrack) */
libmv_CameraIntrinsicsOptions *all_camera_intrinsics_options; /* camera intrinsic of each camera */
@@ -174,6 +174,7 @@ BKE_tracking_multiview_reconstruction_context_new(MovieClip **clips,
context->all_efra = MEM_callocN(num_clips * sizeof(int), "MRC end frames");
context->keyframe1 = keyframe1;
context->keyframe2 = keyframe2;
+ context->clip_num = num_clips;
for(int i = 0; i < num_clips; i++)
{
@@ -243,6 +244,27 @@ BKE_tracking_multiview_reconstruction_context_new(MovieClip **clips,
return context;
}
+/* Free memory used by a reconstruction process. */
+void BKE_tracking_multiview_reconstruction_context_free(MovieMultiviewReconstructContext *context)
+{
+ for(int i = 0; i < context->clip_num; i++)
+ {
+ libmv_tracksDestroy(context->all_tracks[i]);
+ if (context->all_reconstruction[i])
+ libmv_reconstructionDestroy(context->all_reconstruction[i]);
+ tracks_map_free(context->all_tracks_map[i], NULL);
+ }
+ MEM_freeN(context->all_tracks);
+ MEM_freeN(context->all_reconstruction);
+ MEM_freeN(context->all_camera_intrinsics_options);
+ MEM_freeN(context->all_tracks_map);
+ MEM_freeN(context->all_sfra);
+ MEM_freeN(context->all_efra);
+
+ MEM_freeN(context);
+}
+
+
/* Fill in multiview reconstruction options structure from reconstruction context. */
static void reconstructionOptionsFromContext(libmv_ReconstructionOptions *reconstruction_options,
MovieMultiviewReconstructContext *context)
@@ -268,7 +290,7 @@ static void multiview_reconstruct_update_solve_cb(void *customdata, double progr
BLI_snprintf(progressdata->stats_message, progressdata->message_size, "Solving cameras | %s", message);
}
-/* Solve camera/object motion and reconstruct 3D markers position
+/* TODO(tianwei): Solve camera/object motion and reconstruct 3D markers position
* from a prepared reconstruction context from multiple views.
*
* stop is not actually used at this moment, so reconstruction
@@ -318,3 +340,42 @@ void BKE_tracking_multiview_reconstruction_solve(MovieMultiviewReconstructContex
//context->reprojection_error = error;
context->reprojection_error = 0;
}
+
+/* TODO(tianwei): Finish multiview reconstruction process by copying reconstructed data
+ * to the primary movie clip datablock.
+ */
+bool BKE_tracking_multiview_reconstruction_finish(MovieMultiviewReconstructContext *context, MovieTracking *tracking)
+{
+ MovieTrackingReconstruction *reconstruction;
+ MovieTrackingObject *object;
+
+ return false;
+ //if (!libmv_reconstructionIsValid(context->all_reconstruction)) {
+ // printf("Failed solve the motion: most likely there are no good keyframes\n");
+ // return false;
+ //}
+
+ //tracks_map_merge(context->all_tracks_map, tracking);
+ //BKE_tracking_dopesheet_tag_update(tracking);
+
+ //object = BKE_tracking_object_get_named(tracking, context->object_name);
+
+ //if (context->is_camera)
+ // reconstruction = &tracking->reconstruction;
+ //else
+ // reconstruction = &object->reconstruction;
+
+ ///* update keyframe in the interface */
+ //if (context->select_keyframes) {
+ // object->keyframe1 = context->keyframe1;
+ // object->keyframe2 = context->keyframe2;
+ //}
+
+ //reconstruction->error = context->reprojection_error;
+ //reconstruction->flag |= TRACKING_RECONSTRUCTED;
+
+ //if (!reconstruct_retrieve_libmv(context, tracking))
+ // return false;
+
+ //return true;
+}
diff --git a/source/blender/editors/space_clip/tracking_ops_correspondence.c b/source/blender/editors/space_clip/tracking_ops_correspondence.c
index f700546..be9a293 100644
--- a/source/blender/editors/space_clip/tracking_ops_correspondence.c
+++ b/source/blender/editors/space_clip/tracking_ops_correspondence.c
@@ -311,6 +311,7 @@ static bool solve_multiview_initjob(bContext *C,
smj->user = sc->user;
// create multiview reconstruction context and pass the tracks and markers to libmv
+ printf("new multiview reconstruction context\n");
smj->context = BKE_tracking_multiview_reconstruction_context_new(smj->clips,
smj->clip_num,
object,
@@ -348,27 +349,26 @@ static void solve_multiview_startjob(void *scv, short *stop, short *do_update, f
static void solve_multiview_freejob(void *scv)
{
- SolveMultiviewJob *scj = (SolveMultiviewJob *)scv;
- MovieClip *clip = scj->clips[0]; // primary camera
+ SolveMultiviewJob *smj = (SolveMultiviewJob *)scv;
+ MovieClip *clip = smj->clips[0]; // primary camera
MovieTracking *tracking = &clip->tracking;
- Scene *scene = scj->scene;
- //MovieClip *clip = scj->clip;
+ Scene *scene = smj->scene;
int solved;
- if (!scj->context) {
+ if (!smj->context) {
/* job weren't fully initialized due to some error */
- MEM_freeN(scj);
+ MEM_freeN(smj);
return;
}
- solved = BKE_tracking_reconstruction_finish(scj->context, tracking);
+ solved = BKE_tracking_multiview_reconstruction_finish(smj->context, tracking);
if (!solved) {
- BKE_report(scj->reports,
+ BKE_report(smj->reports,
RPT_WARNING,
"Some data failed to reconstruct (see console for details)");
}
else {
- BKE_reportf(scj->reports,
+ BKE_reportf(smj->reports,
RPT_INFO,
"Average re-projection error: %.3f",
tracking->reconstruction.error);
@@ -388,7 +388,7 @@ static void solve_multiview_freejob(void *scv)
{
Camera *camera = (Camera *)scene->camera->data;
int width, height;
- BKE_movieclip_get_size(clip, &scj->user, &width, &height);
+ BKE_movieclip_get_size(clip, &smj->user, &width, &height);
BKE_tracking_camera_to_blender(tracking, scene, camera, width, height);
WM_main_add_notifier(NC_OBJECT, camera);
}
@@ -404,8 +404,9 @@ static void solve_multiview_freejob(void *scv)
/* Update active clip displayed in scene buttons. */
WM_main_add_notifier(NC_SCENE, scene);
- BKE_tracking_reconstruction_context_free(scj->context);
- MEM_freeN(scj);
+ printf("free multiview reconstruction context\n");
+ BKE_tracking_multiview_reconstruction_context_free(smj->context);
+ MEM_freeN(smj);
}
static int solve_multiview_exec(bContext *C, wmOperator *op)
@@ -449,13 +450,12 @@ static int solve_multiview_invoke(bContext *C,
if (error_msg[0]) {
BKE_report(op->reports, RPT_ERROR, error_msg);
}
- //solve_multiview_freejob(scj);
+ solve_multiview_freejob(scj);
return OPERATOR_CANCELLED;
}
- return OPERATOR_CANCELLED;
BLI_strncpy(tracking->stats->message,
- "Solving multiview| Preparing solve",
+ "Solving multiview | Preparing solve",
sizeof(tracking->stats->message));
/* Hide reconstruction statistics from previous solve. */
More information about the Bf-blender-cvs
mailing list