[Bf-blender-cvs] [ffe7f41] asset-experiments: Squashed commit of the atomic-operations branch.

Bastien Montagne noreply at git.blender.org
Mon May 9 15:12:34 CEST 2016


Commit: ffe7f4175a30daada4ad75ac666515d5624a719f
Author: Bastien Montagne
Date:   Mon May 9 15:11:40 2016 +0200
Branches: asset-experiments
https://developer.blender.org/rBffe7f4175a30daada4ad75ac666515d5624a719f

Squashed commit of the atomic-operations branch.

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

M	extern/curve_fit_nd/curve_fit_nd.h
M	extern/curve_fit_nd/intern/curve_fit_corners_detect.c
M	extern/curve_fit_nd/intern/curve_fit_cubic.c
M	extern/curve_fit_nd/intern/curve_fit_inline.h
M	intern/atomic/atomic_ops.h
A	intern/atomic/intern/atomic_ops_ext.h
A	intern/atomic/intern/atomic_ops_msvc.h
A	intern/atomic/intern/atomic_ops_unix.h
A	intern/atomic/intern/atomic_ops_utils.h
M	intern/cycles/app/cycles_xml.cpp
M	intern/cycles/blender/addon/properties.py
M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/blender_python.cpp
M	intern/cycles/device/device.h
M	intern/cycles/device/device_cpu.cpp
M	intern/cycles/device/device_cuda.cpp
M	intern/cycles/kernel/geom/geom_volume.h
M	intern/cycles/kernel/kernel_bake.h
M	intern/cycles/kernel/kernel_compat_cpu.h
M	intern/cycles/kernel/kernel_globals.h
M	intern/cycles/kernel/kernel_textures.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/kernel/kernels/cpu/kernel.cpp
M	intern/cycles/kernel/kernels/cuda/kernel.cu
M	intern/cycles/kernel/svm/svm_image.h
M	intern/cycles/render/buffers.cpp
M	intern/cycles/render/camera.cpp
M	intern/cycles/render/film.cpp
M	intern/cycles/render/graph.cpp
M	intern/cycles/render/graph.h
M	intern/cycles/render/image.cpp
M	intern/cycles/render/image.h
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/osl.cpp
M	intern/cycles/render/scene.h
M	intern/cycles/render/shader.cpp
M	intern/cycles/render/svm.cpp
M	intern/cycles/render/tables.cpp
M	intern/cycles/render/tables.h
M	intern/cycles/util/util_debug.cpp
M	intern/cycles/util/util_debug.h
M	intern/cycles/util/util_texture.h
M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	release/scripts/startup/bl_ui/space_dopesheet.py
M	release/scripts/startup/bl_ui/space_info.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenkernel/intern/bvhutils.c
M	source/blender/blenkernel/intern/camera.c
M	source/blender/blenkernel/intern/dynamicpaint.c
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/seqeffects.c
M	source/blender/blenlib/intern/array_utils.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/bmesh/intern/bmesh_delete.c
M	source/blender/bmesh/intern/bmesh_operator_api.h
M	source/blender/depsgraph/intern/depsgraph.cc
M	source/blender/depsgraph/intern/depsgraph_eval.cc
M	source/blender/depsgraph/intern/depsnode.cc
M	source/blender/depsgraph/intern/depsnode.h
M	source/blender/editors/animation/anim_channels_defines.c
M	source/blender/editors/curve/editcurve_paint.c
M	source/blender/editors/gpencil/drawgpencil.c
M	source/blender/editors/gpencil/editaction_gpencil.c
M	source/blender/editors/gpencil/gpencil_brush.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_select.c
M	source/blender/editors/include/BIF_glutil.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/mesh/editmesh_bevel.c
M	source/blender/editors/mesh/editmesh_extrude.c
M	source/blender/editors/mesh/editmesh_loopcut.c
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/editors/physics/particle_edit.c
M	source/blender/editors/screen/glutil.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/space_action/CMakeLists.txt
A	source/blender/editors/space_action/action_buttons.c
M	source/blender/editors/space_action/action_intern.h
M	source/blender/editors/space_action/action_ops.c
M	source/blender/editors/space_action/space_action.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/space_graph/graph_edit.c
M	source/blender/editors/space_graph/graph_intern.h
M	source/blender/editors/space_graph/graph_ops.c
M	source/blender/editors/space_graph/graph_select.c
M	source/blender/editors/space_image/image_draw.c
M	source/blender/editors/space_image/image_intern.h
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_image/space_image.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_snap.c
M	source/blender/editors/transform/transform_snap_object.c
M	source/blender/editors/uvedit/uvedit_ops.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesdna/intern/makesdna.c
M	source/blender/makesrna/RNA_types.h
M	source/blender/makesrna/intern/rna_gpencil.c
M	source/blender/render/intern/source/pipeline.c
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/extern/curve_fit_nd/curve_fit_nd.h b/extern/curve_fit_nd/curve_fit_nd.h
index eee6485..ff6b951 100644
--- a/extern/curve_fit_nd/curve_fit_nd.h
+++ b/extern/curve_fit_nd/curve_fit_nd.h
@@ -25,8 +25,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef __SPLINE_FIT__
-#define __SPLINE_FIT__
+#ifndef __CURVE_FIT_ND_H__
+#define __CURVE_FIT_ND_H__
 
 /** \file curve_fit_nd.h
  *  \ingroup curve_fit
@@ -159,4 +159,4 @@ int curve_fit_corners_detect_fl(
         unsigned int **r_corners,
         unsigned int  *r_corners_len);
 
-#endif  /* __SPLINE_FIT__ */
+#endif  /* __CURVE_FIT_ND_H__ */
diff --git a/extern/curve_fit_nd/intern/curve_fit_corners_detect.c b/extern/curve_fit_nd/intern/curve_fit_corners_detect.c
index 67ed356..415ef40 100644
--- a/extern/curve_fit_nd/intern/curve_fit_corners_detect.c
+++ b/extern/curve_fit_nd/intern/curve_fit_corners_detect.c
@@ -382,9 +382,9 @@ int curve_fit_corners_detect_db(
 				uint i_best = i_span_start;
 				while (i_next < points_len) {
 					if ((points_angle[i_next] == 0.0) ||
-					   (len_squared_vnvn(
-					        &points[(i_next - 1) * dims],
-					        &points[i_next * dims], dims) > radius_min_sq))
+					    (len_squared_vnvn(
+					         &points[(i_next - 1) * dims],
+					         &points[i_next * dims], dims) > radius_min_sq))
 					{
 						break;
 					}
diff --git a/extern/curve_fit_nd/intern/curve_fit_cubic.c b/extern/curve_fit_nd/intern/curve_fit_cubic.c
index f4f5d11..b977634 100644
--- a/extern/curve_fit_nd/intern/curve_fit_cubic.c
+++ b/extern/curve_fit_nd/intern/curve_fit_cubic.c
@@ -29,6 +29,10 @@
  *  \ingroup curve_fit
  */
 
+#ifdef _MSC_VER
+#  define _USE_MATH_DEFINES
+#endif
+
 #include <math.h>
 #include <float.h>
 #include <stdbool.h>
@@ -39,11 +43,14 @@
 
 #include "../curve_fit_nd.h"
 
+/* Take curvature into account when calculating the least square solution isn't usable. */
+#define USE_CIRCULAR_FALLBACK
+
 /* avoid re-calculating lengths multiple times */
 #define USE_LENGTH_CACHE
 
 /* store the indices in the cubic data so we can return the original indices,
- * useful when the caller has data assosiated with the curve. */
+ * useful when the caller has data associated with the curve. */
 #define USE_ORIG_INDEX_DATA
 
 typedef unsigned int uint;
@@ -119,6 +126,11 @@ static Cubic *cubic_alloc(const uint dims)
 	return malloc(cubic_alloc_size(dims));
 }
 
+static void cubic_copy(Cubic *cubic_dst, const Cubic *cubic_src, const uint dims)
+{
+	memcpy(cubic_dst, cubic_src, cubic_alloc_size(dims));
+}
+
 static void cubic_init(
         Cubic *cubic,
         const double p0[], const double p1[], const double p2[], const double p3[],
@@ -283,7 +295,7 @@ static void cubic_calc_acceleration(
         double r_v[])
 {
 	CUBIC_VARS_CONST(cubic, dims, p0, p1, p2, p3);
-    const double s = 1.0 - t;
+	const double s = 1.0 - t;
 	for (uint j = 0; j < dims; j++) {
 		r_v[j] = 6.0 * ((p2[j] - 2.0 * p1[j] + p0[j]) * s +
 		                (p3[j] - 2.0 * p2[j] + p1[j]) * t);
@@ -392,12 +404,99 @@ static void points_calc_center_weighted(
 	}
 }
 
+#ifdef USE_CIRCULAR_FALLBACK
+
+/**
+ * Return a scale value, used to calculate how much the curve handles should be increased,
+ *
+ * This works by placing each end-point on an imaginary circle,
+ * the placement on the circle is based on the tangent vectors,
+ * where larger differences in tangent angle cover a larger part of the circle.
+ *
+ * Return the scale representing how much larger the distance around the circle is.
+ */
+static double points_calc_circumference_factor(
+        const double  tan_l[],
+        const double  tan_r[],
+        const uint dims)
+{
+	const double dot = dot_vnvn(tan_l, tan_r, dims);
+	const double len_tangent = dot < 0.0 ? len_vnvn(tan_l, tan_r, dims) : len_negated_vnvn(tan_l, tan_r, dims);
+	if (len_tangent > DBL_EPSILON) {
+		/* only clamp to avoid precision error */
+		double angle = acos(max(-fabs(dot), -1.0));
+		/* Angle may be less than the length when the tangents define >180 degrees of the circle,
+		 * (tangents that point away from each other).
+		 * We could try support this but will likely cause extreme >1 scales which could cause other issues. */
+		// assert(angle >= len_tangent);
+		double factor = (angle / len_tangent) / (M_PI / 2);
+		factor = 1.0 - pow(1.0 - factor, 1.75);
+		assert(factor < 1.0 + DBL_EPSILON);
+		return factor;
+	}
+	else {
+		/* tangents are exactly aligned (think two opposite sides of a circle). */
+		return 1.0;
+	}
+}
+
+/**
+ * Calculate the scale the handles, which serves as a best-guess
+ * used as a fallback when the least-square solution fails.
+ */
+static double points_calc_cubic_scale(
+        const double v_l[], const double v_r[],
+        const double  tan_l[],
+        const double  tan_r[],
+        const double coords_length, uint dims)
+{
+	const double len_direct = len_vnvn(v_l, v_r, dims);
+	const double len_circle_factor = points_calc_circumference_factor(tan_l, tan_r, dims) * 1.75;
+	const double len_points = min(coords_length, len_circle_factor * len_direct);
+	return (len_direct + ((len_points - len_direct) * len_circle_factor)) / 3.0;
+}
+
+static void cubic_from_points_fallback(
+        const double *points_offset,
+        const uint    points_offset_len,
+        const double  tan_l[],
+        const double  tan_r[],
+        const uint dims,
+
+        Cubic *r_cubic)
+{
+	const double *p0 = &points_offset[0];
+	const double *p3 = &points_offset[(points_offset_len - 1) * dims];
+
+	double alpha = len_vnvn(p0, p3, dims) / 3.0;
+
+	double *p1 = CUBIC_PT(r_cubic, 1, dims);
+	double *p2 = CUBIC_PT(r_cubic, 2, dims);
+
+	copy_vnvn(CUBIC_PT(r_cubic, 0, dims), p0, dims);
+	copy_vnvn(CUBIC_PT(r_cubic, 3, dims), p3, dims);
+
+#ifdef USE_ORIG_INDEX_DATA
+	r_cubic->orig_span = (points_offset_len - 1);
+#endif
+
+	/* p1 = p0 - (tan_l * alpha_l);
+	 * p2 = p3 + (tan_r * alpha_r);
+	 */
+	msub_vn_vnvn_fl(p1, p0, tan_l, alpha, dims);
+	madd_vn_vnvn_fl(p2, p3, tan_r, alpha, dims);
+}
+#endif  /* USE_CIRCULAR_FALLBACK */
+
 /**
  * Use least-squares method to find Bezier control points for region.
  */
 static void cubic_from_points(
         const double *points_offset,
         const uint    points_offset_len,
+#ifdef USE_CIRCULAR_FALLBACK
+        const double  points_offset_coords_length,
+#endif
         const double *u_prime,
         const double  tan_l[],
         const double  tan_r[],
@@ -477,7 +576,11 @@ static void cubic_from_points(
 	if (!(alpha_l >= 0.0) ||
 	    !(alpha_r >= 0.0))
 	{
+#ifdef USE_CIRCULAR_FALLBACK
+		alpha_l = alpha_r = points_calc_cubic_scale(p0, p3, tan_l, tan_r, points_offset_coords_length, dims);
+#else
 		alpha_l = alpha_r = len_vnvn(p0, p3, dims) / 3.0;
+#endif
 
 		/* skip clamping when we're using default handles */
 		use_clamp = false;
@@ -535,8 +638,11 @@ static void cubic_from_points(
 		if (p1_dist_sq > dist_sq_max ||
 		    p2_dist_sq > dist_sq_max)
 		{
-
+#ifdef USE_CIRCULAR_FALLBACK
+			alpha_l = alpha_r = points_calc_cubic_scale(p0, p3, tan_l, tan_r, points_offset_coords_length, dims);
+#else
 			alpha_l = alpha_r = len_vnvn(p0, p3, dims) / 3.0;
+#endif
 
 			/*
 			 * p1 = p0 - (tan_l * alpha_l);
@@ -585,8 +691,10 @@ static void points_calc_coord_length_cache(
 }
 #endif  /* USE_LENGTH_CACHE */
 
-
-static void points_calc_coord_length(
+/**
+ * \return the accumulated length of \a points_offset.
+ */
+static double points_calc_coord_length(
         const double *points_offset,
         const uint    points_offset_len,
         const uint    dims,
@@ -619,6 +727,7 @@ static void points_calc_coord_length(
 	for (uint i = 0; i < points_offset_len; i++) {
 		r_u[i] /= w;
 	}
+	return w;
 }
 
 /**
@@ -631,10 +740,10 @@ static void points_calc_coord_length(
  * \note Return value may be `nan` caller must check for this.
  */
 static double cubic_find_root(
-		const Cubic *cubic,
-		const double p[],
-		const double u,
-		const uint dims)
+        const Cubic *cubic,
+        const double p[],
+        const double u,
+        const uint dims)
 {
 	/* Newton-Raphson Method. */
 	/* all vectors */
@@ -738,6 +847,10 @@ static bool fit_cubic_to_points(
 	}
 
 	double *u = malloc(sizeof(double) * points_offset_len);
+
+#ifdef USE_CIRCULAR_FALLBACK
+	const double points_offset_coords_length  =
+#endif
 	points_calc_coord_length(
 	        points_offset, points_offset_len, dims,
 #ifdef USE_LENGTH_CACHE
@@ -750,13 +863,41 @@ static bool fit_cubic_to_points(
 
 	/* Parameterize points, and attempt to fit curve */
 	cubic_from_points(
-	        points_offset, points_offset_len, u, tan_l, tan_r, dims, r_cubic);
+	        points_offset, points_offset_len,
+#ifdef USE_CIRCULAR_FALLBACK
+	        points_offset_coords_length,
+#endif
+	        u, tan_l, tan_r, dims, r_cubic);
 
 	/* Find max deviation of points to fitted curve */
 	error_max_sq = cubic_calc_error(
 	        r_cubic, points_offset, points_offset_len, u, dims,
 	        &split_index);
 
+	Cubic *cubic_test = alloca(cubic_alloc_size(dims));
+
+#ifdef USE_CIRCULAR_FALLBACK
+	if (!(error_max_sq < error_threshold_sq)) {
+		/* Don't use the cubic calculated above, instead calculate a new fallback cubic,
+		 * since this tends to give more balanced split_index along the curve.
+		 * This is because the attempt to calcualte the cubic may contain spikes
+		 * along the curve which may give a lop-sided maximum distance. */
+		cubic_from_points_fallback(
+		        points_offset, points_offset_len,
+		        tan_l, tan_r, dims, cubic_test);
+		const double error_max_sq_test = cubic_calc_error(
+		        cubic_test, points_offset, points_offset_len, u, dims,
+		        &split_index);
+
+		/* intentionally use the newly calculated 'split_index',
+		 * even if the 'error_max_sq_test' is worse. */
+		if (error_max_sq > error_max_sq_test) {
+			error_max_sq = error_max_sq_test;
+			cubic_copy(r_cubic, cubic_test, dims);
+		}
+	}
+#endif
+
 	*r_error_max_sq = error_max_sq;
 	*r_split_index  = split_index;
 
@@ -765,8 +906,7 @@ static bool fit_cubic_to_points(
 		return true;
 	}
 	else {
-		Cubic *cubic_test = alloca(cubic_alloc_size(dims));
-		*cubic_test = *r_cubic;
+		cubic_copy(cubic_test, r_cubic, dims);
 
 		/* If err

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list