[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59425] trunk/blender/source/blender: math api edits - replace point-normal form for a plane with dist_to_plane_v3 ()

Campbell Barton ideasman42 at gmail.com
Fri Aug 23 16:37:22 CEST 2013


Revision: 59425
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59425
Author:   campbellbarton
Date:     2013-08-23 14:37:22 +0000 (Fri, 23 Aug 2013)
Log Message:
-----------
math api edits - replace point-normal form for a plane with dist_to_plane_v3()
also correct python mathutils api, was missing vector checks.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/camera.c
    trunk/blender/source/blender/blenlib/BLI_math_geom.h
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/editors/mesh/editmesh_tools.c
    trunk/blender/source/blender/python/mathutils/mathutils_geometry.c

Modified: trunk/blender/source/blender/blenkernel/intern/camera.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/camera.c	2013-08-23 14:34:34 UTC (rev 59424)
+++ trunk/blender/source/blender/blenkernel/intern/camera.c	2013-08-23 14:37:22 UTC (rev 59425)
@@ -456,6 +456,7 @@
 
 
 typedef struct CameraViewFrameData {
+	float plane_tx[4][4];  /* 4 planes (not 4x4 matrix)*/
 	float frame_tx[4][3];
 	float normal_tx[4][3];
 	float dist_vals[4];
@@ -468,7 +469,7 @@
 	unsigned int i;
 
 	for (i = 0; i < 4; i++) {
-		float nd = dist_to_plane_v3(co, data->frame_tx[i], data->normal_tx[i]);
+		float nd = dist_to_plane_v3(co, data->plane_tx[i]);
 		if (nd < data->dist_vals[i]) {
 			data->dist_vals[i] = nd;
 		}
@@ -514,8 +515,8 @@
 	}
 
 	for (i = 0; i < 4; i++) {
-		normal_tri_v3(data_cb.normal_tx[i],
-		              zero, data_cb.frame_tx[i], data_cb.frame_tx[(i + 1) % 4]);
+		normal_tri_v3(data_cb.normal_tx[i], zero, data_cb.frame_tx[i], data_cb.frame_tx[(i + 1) % 4]);
+		plane_from_point_normal_v3(data_cb.plane_tx[i], data_cb.frame_tx[i], data_cb.normal_tx[i]);
 	}
 
 	/* initialize callback data */

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h	2013-08-23 14:34:34 UTC (rev 59424)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h	2013-08-23 14:37:22 UTC (rev 59425)
@@ -81,8 +81,7 @@
 float         dist_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2]);
 void closest_to_line_segment_v2(float closest[2], const float p[2], const float l1[2], const float l2[2]);
 
-float dist_to_plane_normalized_v3(const float p[3], const float plane_co[3], const float plane_no_unit[3]);
-float dist_to_plane_v3(const float p[3], const float plane_co[3], const float plane_no[3]);
+float dist_to_plane_v3(const float p[3], const float plane[4]);
 float dist_squared_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]);
 float         dist_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]);
 float dist_to_line_v3(const float p[3], const float l1[3], const float l2[3]);

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-08-23 14:34:34 UTC (rev 59424)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-08-23 14:37:22 UTC (rev 59425)
@@ -321,27 +321,19 @@
 	madd_v3_v3v3fl(close_r, pt, plane, -side / length);
 }
 
-/* signed distance from the point to the plane in 3D */
-float dist_to_plane_normalized_v3(const float p[3], const float plane_co[3], const float plane_no_unit[3])
+float dist_to_plane_v3(const float pt[3], const float plane[4])
 {
-	float plane_co_other[3];
+	float close[3];
 
-	add_v3_v3v3(plane_co_other, plane_co, plane_no_unit);
+	/* same logic as closest_to_plane_v3() */
+	const float length = len_squared_v3(plane);
+	const float side = plane_point_side_v3(plane, pt);
+	madd_v3_v3v3fl(close, pt, plane, -side / length);
+	/* end same logic */
 
-	return line_point_factor_v3(p, plane_co, plane_co_other);
+	return copysign(len_v3v3(pt, close), side);
 }
 
-float dist_to_plane_v3(const float p[3], const float plane_co[3], const float plane_no[3])
-{
-	float plane_no_unit[3];
-	float plane_co_other[3];
-
-	normalize_v3_v3(plane_no_unit, plane_no);
-	add_v3_v3v3(plane_co_other, plane_co, plane_no_unit);
-
-	return line_point_factor_v3(p, plane_co, plane_co_other);
-}
-
 /* distance v1 to line-piece l1-l2 in 3D */
 float dist_squared_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3])
 {

Modified: trunk/blender/source/blender/editors/mesh/editmesh_tools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_tools.c	2013-08-23 14:34:34 UTC (rev 59424)
+++ trunk/blender/source/blender/editors/mesh/editmesh_tools.c	2013-08-23 14:37:22 UTC (rev 59425)
@@ -4486,7 +4486,6 @@
 	invert_m4_m4(imat, obedit->obmat);
 	mul_m4_v3(imat, plane_co);
 	mul_mat3_m4_v3(imat, plane_no);
-	normalize_v3(plane_no);
 
 	EDBM_op_init(em, &bmop, op,
 	             "bisect_plane geom=%hvef plane_co=%v plane_no=%v dist=%f clear_inner=%b clear_outer=%b",
@@ -4553,9 +4552,11 @@
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
 
-	prop = RNA_def_float_vector(ot->srna, "plane_co", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
+	prop = RNA_def_float_vector(ot->srna, "plane_co", 3, NULL, -FLT_MAX, FLT_MAX,
+	                            "Plane Point", "A point on the plane", -FLT_MAX, FLT_MAX);
 	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-	prop = RNA_def_float_vector(ot->srna, "plane_no", 3, NULL, -FLT_MAX, FLT_MAX, "Direction", "", -FLT_MAX, FLT_MAX);
+	prop = RNA_def_float_vector(ot->srna, "plane_no", 3, NULL, -FLT_MAX, FLT_MAX,
+	                            "Plane Normal", "The direction the plane points", -FLT_MAX, FLT_MAX);
 	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 
 	RNA_def_boolean(ot->srna, "use_fill", false, "Fill", "Fill in the cut");

Modified: trunk/blender/source/blender/python/mathutils/mathutils_geometry.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_geometry.c	2013-08-23 14:34:34 UTC (rev 59424)
+++ trunk/blender/source/blender/python/mathutils/mathutils_geometry.c	2013-08-23 14:37:22 UTC (rev 59425)
@@ -981,6 +981,7 @@
 static PyObject *M_Geometry_distance_point_to_plane(PyObject *UNUSED(self), PyObject *args)
 {
 	VectorObject *pt, *plene_co, *plane_no;
+	float plane[4];
 
 	if (!PyArg_ParseTuple(args, "O!O!O!:distance_point_to_plane",
 	                      &vector_Type, &pt,
@@ -990,6 +991,15 @@
 		return NULL;
 	}
 
+	if (pt->size != 3 ||
+	    plene_co->size != 3 ||
+	    plane_no->size != 3)
+	{
+		PyErr_SetString(PyExc_ValueError,
+		                "One of more of the vector arguments wasn't a 3D vector");
+		return NULL;
+	}
+
 	if (BaseMath_ReadCallback(pt) == -1 ||
 	    BaseMath_ReadCallback(plene_co) == -1 ||
 	    BaseMath_ReadCallback(plane_no) == -1)
@@ -997,7 +1007,8 @@
 		return NULL;
 	}
 
-	return PyFloat_FromDouble(dist_to_plane_v3(pt->vec, plene_co->vec, plane_no->vec));
+	plane_from_point_normal_v3(plane, plene_co->vec, plane_no->vec);
+	return PyFloat_FromDouble(dist_to_plane_v3(pt->vec, plane));
 }
 
 PyDoc_STRVAR(M_Geometry_barycentric_transform_doc,
@@ -1054,6 +1065,17 @@
 		return NULL;
 	}
 
+	if (BaseMath_ReadCallback(vec_pt) == -1 ||
+	    BaseMath_ReadCallback(vec_t1_src) == -1 ||
+	    BaseMath_ReadCallback(vec_t2_src) == -1 ||
+	    BaseMath_ReadCallback(vec_t3_src) == -1 ||
+	    BaseMath_ReadCallback(vec_t1_tar) == -1 ||
+	    BaseMath_ReadCallback(vec_t2_tar) == -1 ||
+	    BaseMath_ReadCallback(vec_t3_tar) == -1)
+	{
+		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);




More information about the Bf-blender-cvs mailing list