[Bf-blender-cvs] [f4dee67] soc-2016-multiview: use name instead of pointer in correspondence

Tianwei Shen noreply at git.blender.org
Sun Aug 21 18:37:37 CEST 2016


Commit: f4dee67e8bdcd50059d348008be22efefeb380f8
Author: Tianwei Shen
Date:   Mon Aug 22 00:35:33 2016 +0800
Branches: soc-2016-multiview
https://developer.blender.org/rBf4dee67e8bdcd50059d348008be22efefeb380f8

use name instead of pointer in correspondence

- remove self_track and other_track pointers in MovieTrackCorrespondence,
instead use self_track_name and other_track_name.
- now we can save and load correspondences reliably.
- one issue after this change is that the color of linked tracks are not
  shown correctly.

===================================================================

M	source/blender/blenkernel/intern/tracking_correspondence.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/space_clip/clip_draw.c
M	source/blender/editors/space_clip/tracking_ops_correspondence.c
M	source/blender/makesdna/DNA_tracking_types.h

===================================================================

diff --git a/source/blender/blenkernel/intern/tracking_correspondence.c b/source/blender/blenkernel/intern/tracking_correspondence.c
index d93cf79..5ce0ab3 100644
--- a/source/blender/blenkernel/intern/tracking_correspondence.c
+++ b/source/blender/blenkernel/intern/tracking_correspondence.c
@@ -95,28 +95,28 @@ MovieTrackingCorrespondence *BKE_tracking_correspondence_add(ListBase *corr_base
                                                              char *error_msg, int error_size)
 {
 	MovieTrackingCorrespondence *corr = NULL;
-	// check self correspondences
+	/* check self correspondences */
 	if (self_track == other_track) {
 		BLI_strncpy(error_msg, N_("Cannot link a track to itself"), error_size);
 		return NULL;
 	}
-	// check duplicate correspondences or conflict correspondence
+	/* check duplicate correspondences or conflict correspondence */
 	for (corr = corr_base->first; corr != NULL; corr = corr->next)
 	{
-		if (corr->self_clip == self_clip && corr->self_track == self_track) {
-			// duplicate correspondences
-			if (corr->other_clip == other_clip && corr->other_track == other_track) {
+		if (corr->self_clip == self_clip && strcmp(corr->self_track_name, self_track->name) == 0) {
+			/* duplicate correspondences */
+			if (corr->other_clip == other_clip && strcmp(corr->other_track_name, other_track->name) == 0) {
 				BLI_strncpy(error_msg, N_("This correspondence has been added"), error_size);
 				return NULL;
 			}
-			// conflict correspondence
+			/* conflict correspondence */
 			else {
 				BLI_strncpy(error_msg, N_("Conflict correspondence, consider first deleting the old one"), error_size);
 				return NULL;
 			}
 		}
-		if (corr->other_clip == other_clip && corr->other_track == other_track) {
-			if (corr->self_clip == self_clip && corr->self_track == self_track) {
+		if (corr->other_clip == other_clip && strcmp(corr->other_track_name, other_track->name) == 0) {
+			if (corr->self_clip == self_clip && strcmp(corr->self_track_name, self_track->name) == 0) {
 				BLI_strncpy(error_msg, N_("This correspondence has been added"), error_size);
 				return NULL;
 			}
@@ -129,8 +129,8 @@ MovieTrackingCorrespondence *BKE_tracking_correspondence_add(ListBase *corr_base
 
 	corr = MEM_callocN(sizeof(MovieTrackingCorrespondence), "add correspondence");
 	strcpy(corr->name, "Correspondence");
-	corr->self_track = self_track;
-	corr->other_track = other_track;
+	strcpy(corr->self_track_name, self_track->name);
+	strcpy(corr->other_track_name, other_track->name);
 	corr->self_clip = self_clip;
 	corr->other_clip = other_clip;
 
@@ -260,18 +260,18 @@ static int libmv_CorrespondencesFromTracking(ListBase *tracking_correspondences,
 		int clip1 = -1, clip2 = -1, track1 = -1, track2 = -1;
 		MovieClip *self_clip = corr->self_clip;
 		MovieClip *other_clip = corr->other_clip;
-		// iterate through all the clips to get the local clip id
+		/* iterate through all the clips to get the local clip id */
 		for (int i = 0; i < clip_num; i++) {
 			MovieTracking *tracking = &clips[i]->tracking;
 			ListBase *tracksbase = &tracking->tracks;
 			MovieTrackingTrack *track = tracksbase->first;
 			int tracknr = 0;
-			// check primary clip
+			/* check primary clip */
 			if (self_clip == clips[i]) {
 				printf("check primary clip\n");
 				clip1 = i;
 				while (track) {
-					if (corr->self_track == track) {
+					if (strcmp(corr->self_track_name, track->name) == 0) {
 						printf("check primary track\n");
 						track1 = tracknr;
 						break;
@@ -280,12 +280,12 @@ static int libmv_CorrespondencesFromTracking(ListBase *tracking_correspondences,
 					tracknr++;
 				}
 			}
-			// check witness clip
+			/* check witness clip */
 			if (other_clip == clips[i]) {
 				printf("check witness clip\n");
 				clip2 = i;
 				while (track) {
-					if (corr->other_track == track) {
+					if (strcmp(corr->other_track_name, track->name) == 0) {
 						printf("check witness track\n");
 						track2 = tracknr;
 						break;
@@ -299,7 +299,7 @@ static int libmv_CorrespondencesFromTracking(ListBase *tracking_correspondences,
 			libmv_AddCorrespondenceN(libmv_correspondences, clip1, clip2, track1, track2);
 			num_valid_corrs++;
 		}
-		// change the global index of clip2-track2 to clip1-track1
+		/* change the global index of clip2-track2 to clip1-track1 */
 		global_track_index[clip2][track2] = global_track_index[clip1][track1];
 		corr = corr->next;
 	}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index b750d02..b2d06b5 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7459,12 +7459,7 @@ static void direct_link_moviePlaneTracks(FileData *fd, ListBase *plane_tracks_ba
 static void direct_link_movieCorrespondences(FileData *fd,
                                              ListBase *correspondences)
 {
-	MovieTrackingCorrespondence *corr;
 	link_list(fd, correspondences);
-	for (corr = correspondences->first; corr != NULL; corr = corr->next) {
-		corr->self_track = newdataadr(fd, corr->self_track);
-		corr->other_track = newdataadr(fd, corr->other_track);
-	}
 }
 
 static void direct_link_movieclip(FileData *fd, MovieClip *clip)
@@ -7532,7 +7527,6 @@ static void lib_link_movieCorrespondences(FileData *fd,
 {
 	MovieTrackingCorrespondence *corr;
 	for (corr = correspondences->first; corr != NULL; corr = corr->next) {
-		corr->other_track = newlibadr(fd, clip->id.lib, corr->other_track);
 		corr->other_clip = newlibadr(fd, clip->id.lib, corr->other_clip);
 		corr->self_clip = newlibadr(fd, clip->id.lib, corr->self_clip);
 	}
diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c
index 5d1145d..7889550 100644
--- a/source/blender/editors/space_clip/clip_draw.c
+++ b/source/blender/editors/space_clip/clip_draw.c
@@ -548,14 +548,16 @@ static void draw_marker_outline(SpaceClip *sc, ARegion *ar, MovieTrackingTrack *
 	glPopMatrix();
 }
 
-// return whether the track is a linked track
-// by iterating the correpsondence base in tracking.
-static bool is_track_linked(MovieTracking *tracking, MovieTrackingTrack *track)
+/* return whether the track is a linked track by iterating the correspondence base in tracking. */
+static bool is_track_linked(MovieTracking *tracking, MovieClip *clip, MovieTrackingTrack *track)
 {
 	MovieTrackingCorrespondence *corr = tracking->correspondences.first;
 	while (corr) {
-		if (corr->self_track == track || corr->other_track == track)
+		if ((corr->self_clip == clip && strcmp(corr->self_track_name, track->name) == 0) ||
+		    (corr->other_clip == clip && strcmp(corr->other_track_name, track->name) == 0))
+		{
 			return true;
+		}
 		corr = corr->next;
 	}
 	return false;
@@ -594,8 +596,9 @@ static void draw_marker_areas(SpaceClip *sc, ARegion *ar, MovieTrackingTrack *tr
 	bool show_search = false;
 	float col[3], scol[3], px[2];
 
-	MovieTracking *tracking = &sc->clip->tracking;
-	bool link = is_track_linked(tracking, track);
+	MovieClip *mc = ED_space_clip_get_clip_in_region(sc, ar);
+	MovieTracking *tracking = &mc->tracking;
+	bool link = is_track_linked(tracking, mc, track);
 	track_colors(track, act, link, col, scol);
 
 	RegionSpaceClip *rsc = (RegionSpaceClip*) ar->regiondata;
@@ -821,8 +824,9 @@ static void draw_marker_slide_zones(SpaceClip *sc, ARegion *ar, MovieTrackingTra
 	if (!TRACK_VIEW_SELECTED(sc, track) || track->flag & TRACK_LOCKED)
 		return;
 
-	MovieTracking *tracking = &sc->clip->tracking;
-	bool link = is_track_linked(tracking, track);
+	MovieClip *mc = ED_space_clip_get_clip_in_region(sc, ar);
+	MovieTracking *tracking = &mc->tracking;
+	bool link = is_track_linked(tracking, mc, track);
 	track_colors(track, act, link, col, scol);
 
 	if (outline) {
diff --git a/source/blender/editors/space_clip/tracking_ops_correspondence.c b/source/blender/editors/space_clip/tracking_ops_correspondence.c
index 555575d..4c48632 100644
--- a/source/blender/editors/space_clip/tracking_ops_correspondence.c
+++ b/source/blender/editors/space_clip/tracking_ops_correspondence.c
@@ -146,13 +146,14 @@ static int delete_correspondence_exec(bContext *C, wmOperator *UNUSED(op))
 	bool changed = false;
 
 	/* Remove track correspondences from correspondence base */
+	MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
 	ListBase *correspondence_base = &tracking->correspondences;
 	for (MovieTrackingCorrespondence *corr = correspondence_base->first;
 	     corr != NULL;
 	     corr = corr->next)
 	{
 		MovieTrackingTrack *track;
-		track = corr->self_track;
+		track = BKE_tracking_track_get_named(tracking, object, corr->self_track_name);
 		if (TRACK_VIEW_SELECTED(sc, track)) {
 			BLI_freelinkN(correspondence_base, corr);
 			changed = true;
diff --git a/source/blender/makesdna/DNA_tracking_types.h b/source/blender/makesdna/DNA_tracking_types.h
index 54465f6..3df4546 100644
--- a/source/blender/makesdna/DNA_tracking_types.h
+++ b/source/blender/makesdna/DNA_tracking_types.h
@@ -171,8 +171,8 @@ typedef struct MovieTrackingCorrespondence {
 
 	char name[64];  /* MAX_NAME */
 
-	MovieTrackingTrack *self_track;
-	MovieTrackingTrack *other_track;
+	char self_track_name[64];
+	char other_track_name[64];
 
 	struct MovieClip *self_clip;
 	struct MovieClip *other_clip;




More information about the Bf-blender-cvs mailing list