[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46733] branches/soc-2011-tomato: Remove debug code and clean up sources to match common style used

Sergey Sharybin sergey.vfx at gmail.com
Thu May 17 15:53:20 CEST 2012


Revision: 46733
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46733
Author:   nazgul
Date:     2012-05-17 13:53:20 +0000 (Thu, 17 May 2012)
Log Message:
-----------
Remove debug code and clean up sources to match common style used

Also made BKE_tracking_get_search_imbuf use space conversion utility functions,
so now it's not so annoying that search area calculation is happening differently
in different paces.

Also allow even sizes for search area.

Another small fix is about flipping search area dumping by libmv-capi.
It used to be flipped since in blender Y axis is up-aimed.

Modified Paths:
--------------
    branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c

Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2012-05-17 13:44:15 UTC (rev 46732)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2012-05-17 13:53:20 UTC (rev 46733)
@@ -239,14 +239,14 @@
 		row_pointers[y]= (png_bytep)malloc(sizeof(png_byte)*4*image.Width());
 
 		for (x = 0; x < image.Width(); x++) {
-			if (x0 == x && y0 == y) {
+			if (x0 == x && image.Height() - y0 - 1 == y) {
 				row_pointers[y][x*4+0]= 255;
 				row_pointers[y][x*4+1]= 0;
 				row_pointers[y][x*4+2]= 0;
 				row_pointers[y][x*4+3]= 255;
 			}
 			else {
-				float pixel = image(y, x, 0);
+				float pixel = image(image.Height() - y - 1, x, 0);
 				row_pointers[y][x*4+0]= pixel*255;
 				row_pointers[y][x*4+1]= pixel*255;
 				row_pointers[y][x*4+2]= pixel*255;

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2012-05-17 13:44:15 UTC (rev 46732)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2012-05-17 13:53:20 UTC (rev 46733)
@@ -75,8 +75,7 @@
                                              struct MovieTrackingMarker *marker, int margin, int anchored,
                                              float pos[2], int origin[2]);
 struct ImBuf *BKE_tracking_get_search_imbuf(struct ImBuf *ibuf, struct MovieTrackingTrack *track,
-                                            struct MovieTrackingMarker *marker, int margin, int anchored,
-                                            float pos[2], int origin[2]);
+                                            struct MovieTrackingMarker *marker);
 struct ImBuf *BKE_tracking_track_mask_get(struct MovieTracking *tracking, struct MovieTrackingTrack *track, int width, int height);
 
 void BKE_track_unique_name(struct ListBase *tracksbase, struct MovieTrackingTrack *track);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2012-05-17 13:44:15 UTC (rev 46732)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2012-05-17 13:53:20 UTC (rev 46733)
@@ -76,6 +76,78 @@
 	ListBase tracks;
 } tracking_clipboard;
 
+/*********************** space transformation functions  *************************/
+
+/* Three coordinate frames: Frame, Search, and Marker
+ * Two units: Pixels, Unified
+ * Notation: {coordinate frame}_{unit}; for example, "search_pixel" are search
+ * window relative coordinates in pixels, and "frame_unified" are unified 0..1
+ * coordinates relative to the entire frame.
+ */
+static void unified_to_pixel(const ImBuf *ibuf, const float unified_coords[2], float pixel_coords[2])
+{
+	pixel_coords[0] = unified_coords[0] * ibuf->x;
+	pixel_coords[1] = unified_coords[1] * ibuf->y;
+}
+
+static void marker_to_frame_unified(const MovieTrackingMarker *marker, const float marker_unified_coords[2],
+                                    float frame_unified_coords[2])
+{
+	frame_unified_coords[0] = marker_unified_coords[0] + marker->pos[0];
+	frame_unified_coords[1] = marker_unified_coords[1] + marker->pos[1];
+}
+
+static void marker_unified_to_frame_pixel_coordinates(const ImBuf *ibuf, const MovieTrackingMarker *marker,
+                                                      const float marker_unified_coords[2], float frame_pixel_coords[2])
+{
+	marker_to_frame_unified(marker, marker_unified_coords, frame_pixel_coords);
+	unified_to_pixel(ibuf, frame_pixel_coords, frame_pixel_coords);
+}
+
+static void get_search_origin_frame_pixel(const ImBuf *ibuf, const MovieTrackingTrack *track,
+                                          const MovieTrackingMarker *marker, float frame_pixel[2])
+{
+	/* Get the lower left coordinate of the search window and snap to pixel coordinates */
+	marker_unified_to_frame_pixel_coordinates(ibuf, marker, track->search_min, frame_pixel);
+	frame_pixel[0] = (int)frame_pixel[0];
+	frame_pixel[1] = (int)frame_pixel[1];
+}
+
+#ifdef WITH_LIBMV
+static void pixel_to_unified(const ImBuf *ibuf, const float pixel_coords[2], float unified_coords[2])
+{
+	unified_coords[0] = pixel_coords[0] / ibuf->x;
+	unified_coords[1] = pixel_coords[1] / ibuf->y;
+}
+
+static void marker_unified_to_search_pixel(const ImBuf *ibuf, const MovieTrackingTrack *track,
+                                           const MovieTrackingMarker *marker, const float marker_unified[2],
+                                           float search_pixel[2])
+{
+	float frame_pixel[2];
+	float search_origin_frame_pixel[2];
+
+	marker_unified_to_frame_pixel_coordinates(ibuf, marker, marker_unified, frame_pixel);
+	get_search_origin_frame_pixel(ibuf, track, marker, search_origin_frame_pixel);
+	sub_v2_v2v2(search_pixel, frame_pixel, search_origin_frame_pixel);
+}
+
+static void search_pixel_to_marker_unified(const ImBuf *ibuf, const MovieTrackingTrack *track,
+                                           const MovieTrackingMarker *marker, const float search_pixel[2],
+                                           float marker_unified[2])
+{
+	float frame_unified[2];
+	float search_origin_frame_pixel[2];
+
+	get_search_origin_frame_pixel(ibuf, track, marker, search_origin_frame_pixel);
+	add_v2_v2v2(frame_unified, search_pixel, search_origin_frame_pixel);
+	pixel_to_unified(ibuf, frame_unified, frame_unified);
+
+	/* marker pos is in frame unified */
+	sub_v2_v2v2(marker_unified, frame_unified, marker->pos);
+}
+#endif
+
 /*********************** common functions *************************/
 
 void BKE_tracking_init_settings(MovieTracking *tracking)
@@ -114,7 +186,8 @@
 	}
 
 	/* XXX: currently search area is global, pattern size is per-marker, so we'll need to
-	 *      find maximal size of pattern to clamp search size nicely */
+	 *      find maximal size of pattern to clamp search size nicely
+	 */
 	INIT_MINMAX2(pat_min, pat_max);
 
 	for (a = 0; a < track->markersnr; a++) {
@@ -127,7 +200,8 @@
 	}
 
 	/* compute the effective pattern size, which differs from the fine resolution
-	 * pattern size for the pyramid KLT tracker */
+	 * pattern size for the pyramid KLT tracker
+	 */
 	for (a = 0; a < 2; a++) {
 		eff_pat_min[a] = max_pyramid_level_factor * pat_min[a];
 		eff_pat_max[a] = max_pyramid_level_factor * pat_max[a];
@@ -147,7 +221,8 @@
 
 #if 0
 		/* XXX: needs porting, but we need to know marker here, will be ported after a bit
-		 *      more global refactoring */
+		 *      more global refactoring
+		 */
 		for (a = 0; a < 2; a++) {
 			/* pattern shouldn't be moved outside of search */
 			if (eff_pat_min[a] < track->search_min[a]) {
@@ -192,7 +267,8 @@
 			float search_ratio = 2.3f * max_pyramid_level_factor;
 
 			/* resize the search area to something sensible based
-			 * on the number of pyramid levels */
+			 * on the number of pyramid levels
+			 */
 			for (a = 0; a < 2; a++) {
 				track->search_min[a] = search_ratio * pat_min[a];
 				track->search_max[a] = search_ratio * pat_max[a];
@@ -542,7 +618,8 @@
 				if ((dst_track->markers[b].flag & MARKER_DISABLED) == 0) {
 					/* both tracks are enabled on this frame, so find the whole segment
 					 * on which tracks are intersecting and blend tracks using linear
-					 * interpolation to prevent jumps */
+					 * interpolation to prevent jumps
+					 */
 
 					MovieTrackingMarker *marker_a, *marker_b;
 					int start_a = a, start_b = b, len = 0, frame = src_track->markers[a].framenr;
@@ -842,7 +919,8 @@
 
 	/* duplicate currently operating tracks to temporary list.
 	 * this is needed to keep names in unique state and it's faster to change names
-	 * of currently operating tracks (if needed) */
+	 * of currently operating tracks (if needed)
+	 */
 	for (a = 0; a < map->num_tracks; a++) {
 		int replace_sel = 0, replace_rot = 0;
 		MovieTrackingTrack *new_track, *old;
@@ -1034,7 +1112,8 @@
 	 *   would be used for images
 	 * - MCLIP_USE_PROXY_CUSTOM_DIR is needed because proxy/timecode files might
 	 *   be stored in a different location
-	 * ignore all the rest possible flags for now */
+	 * ignore all the rest possible flags for now
+	 */
 	context->clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;
 
 	context->user = *user;
@@ -1072,7 +1151,8 @@
 
 /* zap channels from the imbuf that are disabled by the user. this can lead to
  * better tracks sometimes. however, instead of simply zeroing the channels
- * out, do a partial grayscale conversion so the display is better. */
+ * out, do a partial grayscale conversion so the display is better.
+ */
 void BKE_tracking_disable_imbuf_channels(ImBuf *ibuf, int disable_red, int disable_green, int disable_blue,
                                          int grayscale)
 {
@@ -1083,7 +1163,8 @@
 		return;
 
 	/* If only some components are selected, it's important to rescale the result
-	 * appropriately so that e.g. if only blue is selected, it's not zeroed out. */
+	 * appropriately so that e.g. if only blue is selected, it's not zeroed out.
+	 */
 	scale = (disable_red   ? 0.0f : 0.2126f) +
 	        (disable_green ? 0.0f : 0.7152f) +
 	        (disable_blue  ? 0.0f : 0.0722f);
@@ -1203,16 +1284,41 @@
 	float pat_min[2], pat_max[2];
 
 	/* XXX: need to do real quad sampling here, but currently just assume
-	 *      corners represents quad pattern */
+	 *      corners represents quad pattern
+	 */
 	BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
 
 	return get_area_imbuf(ibuf, track, marker, pat_min, pat_max, margin, anchored, pos, origin);
 }
 
-ImBuf *BKE_tracking_get_search_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker,
-                                     int margin, int anchored, float pos[2], int origin[2])
+ImBuf *BKE_tracking_get_search_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker)
 {
-	return get_area_imbuf(ibuf, track, marker, track->search_min, track->search_max, margin, anchored, pos, origin);
+	ImBuf *searchibuf;
+	int x, y, w, h;
+	float search_origin[2];
+
+	get_search_origin_frame_pixel(ibuf, track, marker, search_origin);
+
+	x = search_origin[0];
+	y = search_origin[1];
+
+	w = (track->search_max[0] - track->search_min[0]) * ibuf->x;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list