[Bf-blender-cvs] [ff42afb] master: Math Lib: rename barycentric_transform -> transform_point_by_tri_v3

Campbell Barton noreply at git.blender.org
Wed Aug 13 07:10:10 CEST 2014


Commit: ff42afb6c5284f1c224d0c6f73e8e86facc27ff4
Author: Campbell Barton
Date:   Wed Aug 13 14:55:45 2014 +1000
Branches: master
https://developer.blender.org/rBff42afb6c5284f1c224d0c6f73e8e86facc27ff4

Math Lib: rename barycentric_transform -> transform_point_by_tri_v3

also add transform_point_by_seg_v3

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

M	source/blender/blenkernel/intern/mesh_evaluate.c
M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/bmesh/operators/bmo_fill_grid.c
M	source/blender/bmesh/operators/bmo_subdivide_edgering.c
M	source/blender/python/mathutils/mathutils_geometry.c

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

diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index d244dcc..4c9e446 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -2231,11 +2231,10 @@ void BKE_mesh_calc_relative_deform(
 
 			float tvec[3];
 
-			barycentric_transform(
-			            tvec, vert_cos_dst[v_curr],
-			            vert_cos_org[v_prev], vert_cos_org[v_curr], vert_cos_org[v_next],
-			            vert_cos_src[v_prev], vert_cos_src[v_curr], vert_cos_src[v_next]
-			            );
+			transform_point_by_tri_v3(
+			        tvec, vert_cos_dst[v_curr],
+			        vert_cos_org[v_prev], vert_cos_org[v_curr], vert_cos_org[v_next],
+			        vert_cos_src[v_prev], vert_cos_src[v_curr], vert_cos_src[v_next]);
 
 			add_v3_v3(vert_cos_new[v_curr], tvec);
 			vert_accum[v_curr] += 1;
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 9962529..d3158ef 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -215,9 +215,14 @@ void interp_cubic_v3(float x[3], float v[3],
 
 int interp_sparse_array(float *array, const int list_size, const float invalid);
 
-void barycentric_transform(float pt_tar[3], float const pt_src[3],
-                           const float tri_tar_p1[3], const float tri_tar_p2[3], const float tri_tar_p3[3],
-                           const float tri_src_p1[3], const float tri_src_p2[3], const float tri_src_p3[3]);
+void transform_point_by_tri_v3(
+        float pt_tar[3], float const pt_src[3],
+        const float tri_tar_p1[3], const float tri_tar_p2[3], const float tri_tar_p3[3],
+        const float tri_src_p1[3], const float tri_src_p2[3], const float tri_src_p3[3]);
+void transform_point_by_seg_v3(
+        float p_dst[3], const float p_src[3],
+        const float l_dst_p1[3], const float l_dst_p2[3],
+        const float l_src_p1[3], const float l_src_p2[3]);
 
 void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3[2],
                             const float co[2], float w[3]);
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 3d4cea7..6ca98e5 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -2446,9 +2446,10 @@ void barycentric_weights_v2_quad(const float v1[2], const float v2[2], const flo
 /* given 2 triangles in 3D space, and a point in relation to the first triangle.
  * calculate the location of a point in relation to the second triangle.
  * Useful for finding relative positions with geometry */
-void barycentric_transform(float pt_tar[3], float const pt_src[3],
-                           const float tri_tar_p1[3], const float tri_tar_p2[3], const float tri_tar_p3[3],
-                           const float tri_src_p1[3], const float tri_src_p2[3], const float tri_src_p3[3])
+void transform_point_by_tri_v3(
+        float pt_tar[3], float const pt_src[3],
+        const float tri_tar_p1[3], const float tri_tar_p2[3], const float tri_tar_p3[3],
+        const float tri_src_p1[3], const float tri_src_p2[3], const float tri_src_p3[3])
 {
 	/* this works by moving the source triangle so its normal is pointing on the Z
 	 * axis where its barycentric weights can be calculated in 2D and its Z offset can
@@ -2485,6 +2486,19 @@ void barycentric_transform(float pt_tar[3], float const pt_src[3],
 	madd_v3_v3v3fl(pt_tar, pt_tar, no_tar, (z_ofs_src / area_src) * area_tar);
 }
 
+/**
+ * Simply re-interpolates,
+ * assumes p_src is between \a l_src_p1-l_src_p2
+ */
+void transform_point_by_seg_v3(
+        float p_dst[3], const float p_src[3],
+        const float l_dst_p1[3], const float l_dst_p2[3],
+        const float l_src_p1[3], const float l_src_p2[3])
+{
+	float t = line_point_factor_v3(p_src, l_src_p1, l_src_p2);
+	interp_v3_v3v3(p_dst, l_dst_p1, l_dst_p2, t);
+}
+
 /* given an array with some invalid values this function interpolates valid values
  * replacing the invalid ones */
 int interp_sparse_array(float *array, const int list_size, const float skipval)
diff --git a/source/blender/bmesh/operators/bmo_fill_grid.c b/source/blender/bmesh/operators/bmo_fill_grid.c
index 6a0fca4..40f6937 100644
--- a/source/blender/bmesh/operators/bmo_fill_grid.c
+++ b/source/blender/bmesh/operators/bmo_fill_grid.c
@@ -313,12 +313,12 @@ static void bm_grid_fill_array(BMesh *bm, BMVert **v_grid, const unsigned int xt
 			if (use_interp_simple == false) {
 				float co_a[3], co_b[3];
 
-				barycentric_transform(
+				transform_point_by_tri_v3(
 				            co_a,
 				            v_grid[x]->co,
 				            tri_t[0], tri_t[1], tri_t[2],
 				            tri_a[0], tri_a[1], tri_a[2]);
-				barycentric_transform(
+				transform_point_by_tri_v3(
 				            co_b,
 				            v_grid[(xtot * ytot) + (x - xtot)]->co,
 				            tri_t[0], tri_t[1], tri_t[2],
diff --git a/source/blender/bmesh/operators/bmo_subdivide_edgering.c b/source/blender/bmesh/operators/bmo_subdivide_edgering.c
index 8bb4722..c01ad10 100644
--- a/source/blender/bmesh/operators/bmo_subdivide_edgering.c
+++ b/source/blender/bmesh/operators/bmo_subdivide_edgering.c
@@ -727,8 +727,8 @@ static void bm_edgering_pair_interpolate(BMesh *bm, LoopPairStore *lpair,
 
 					tri_tmp = tri_array[i];
 
-					barycentric_transform(co_a, v_a->co, UNPACK3(tri_tmp), UNPACK3(tri_sta));
-					barycentric_transform(co_b, v_b->co, UNPACK3(tri_tmp), UNPACK3(tri_end));
+					transform_point_by_tri_v3(co_a, v_a->co, UNPACK3(tri_tmp), UNPACK3(tri_sta));
+					transform_point_by_tri_v3(co_b, v_b->co, UNPACK3(tri_tmp), UNPACK3(tri_end));
 
 					interp_v3_v3v3(((BMVert *)v_iter->data)->co, co_a, co_b, (float)i / (float)(resolu - 1));
 				}
diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c
index 2e2e033..b4add0f 100644
--- a/source/blender/python/mathutils/mathutils_geometry.c
+++ b/source/blender/python/mathutils/mathutils_geometry.c
@@ -1114,7 +1114,7 @@ static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObje
 	VectorObject *vec_t1_src, *vec_t2_src, *vec_t3_src;
 	float vec[3];
 
-	if (!PyArg_ParseTuple(args, "O!O!O!O!O!O!O!:barycentric_transform",
+	if (!PyArg_ParseTuple(args, "O!O!O!O!O!O!O!::barycentric_transform",
 	                      &vector_Type, &vec_pt,
 	                      &vector_Type, &vec_t1_src,
 	                      &vector_Type, &vec_t2_src,
@@ -1150,9 +1150,10 @@ static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObje
 		return NULL;
 	}
 
-	barycentric_transform(vec, vec_pt->vec,
-	                      vec_t1_tar->vec, vec_t2_tar->vec, vec_t3_tar->vec,
-	                      vec_t1_src->vec, vec_t2_src->vec, vec_t3_src->vec);
+	transform_point_by_tri_v3(
+	        vec, vec_pt->vec,
+	        vec_t1_tar->vec, vec_t2_tar->vec, vec_t3_tar->vec,
+	        vec_t1_src->vec, vec_t2_src->vec, vec_t3_src->vec);
 
 	return Vector_CreatePyObject(vec, 3, Py_NEW, NULL);
 }




More information about the Bf-blender-cvs mailing list