diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-12-27 04:32:58 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-12-27 04:32:58 +0300 |
commit | fde4686d77dd72ccfa88febdea360136bfd17a36 (patch) | |
tree | 52a715e72488c70457f5c29a74e24c0e3977e470 /source/blender/python/generic/Geometry.c | |
parent | 9c82e1efc32bdff04c3136ef5a2959ed73711ca7 (diff) |
barycentric transform utility geometry function.
From 2 triangles and 1 point, the relative position between the point and the first triangle is applied to the second triangle to find the target point.
the barycentric weights are calculated in 2D space with a signed area so values outside the triangle bounds are supported.
wrapped by python:
pt_to = Geometry.BarycentricTransform(pt_from, t1a, t1b, t1c, t2a, t1b, t1c)
NOTE:
- moved some barycentric weight functions out of projection painting into the math lib.
- ended up making some of the math functions use const args.
TODO:
- support exceptional cases. zero area tries and similar.
Diffstat (limited to 'source/blender/python/generic/Geometry.c')
-rw-r--r-- | source/blender/python/generic/Geometry.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/python/generic/Geometry.c b/source/blender/python/generic/Geometry.c index 0d59df6ceca..579c9d987cf 100644 --- a/source/blender/python/generic/Geometry.c +++ b/source/blender/python/generic/Geometry.c @@ -55,6 +55,7 @@ static PyObject *M_Geometry_PointInTriangle2D( PyObject * self, PyObject * args static PyObject *M_Geometry_PointInQuad2D( PyObject * self, PyObject * args ); static PyObject *M_Geometry_BoxPack2D( PyObject * self, PyObject * args ); static PyObject *M_Geometry_BezierInterp( PyObject * self, PyObject * args ); +static PyObject *M_Geometry_BarycentricTransform( PyObject * self, PyObject * args ); /*-------------------------DOC STRINGS ---------------------------*/ @@ -75,6 +76,7 @@ struct PyMethodDef M_Geometry_methods[] = { {"PointInQuad2D", ( PyCFunction ) M_Geometry_PointInQuad2D, METH_VARARGS, M_Geometry_PointInQuad2D_doc}, {"BoxPack2D", ( PyCFunction ) M_Geometry_BoxPack2D, METH_O, M_Geometry_BoxPack2D_doc}, {"BezierInterp", ( PyCFunction ) M_Geometry_BezierInterp, METH_VARARGS, M_Geometry_BezierInterp_doc}, + {"BarycentricTransform", ( PyCFunction ) M_Geometry_BarycentricTransform, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; @@ -534,3 +536,36 @@ static PyObject *M_Geometry_BezierInterp( PyObject * self, PyObject * args ) MEM_freeN(coord_array); return list; } + +static PyObject *M_Geometry_BarycentricTransform(PyObject * self, PyObject * args) +{ + VectorObject *vec_pt; + VectorObject *vec_t1_tar, *vec_t2_tar, *vec_t3_tar; + VectorObject *vec_t1_src, *vec_t2_src, *vec_t3_src; + float vec[3]; + + if( !PyArg_ParseTuple ( args, "O!O!O!O!O!O!O!", + &vector_Type, &vec_pt, + &vector_Type, &vec_t1_src, + &vector_Type, &vec_t2_src, + &vector_Type, &vec_t3_src, + &vector_Type, &vec_t1_tar, + &vector_Type, &vec_t2_tar, + &vector_Type, &vec_t3_tar) || ( vec_pt->size != 3 || + vec_t1_src->size != 3 || + vec_t2_src->size != 3 || + vec_t3_src->size != 3 || + vec_t1_tar->size != 3 || + vec_t2_tar->size != 3 || + vec_t3_tar->size != 3) + ) { + PyErr_SetString( PyExc_TypeError, "expected 7, 3D vector types\n" ); + 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); + + return newVectorObject(vec, 3, Py_NEW, NULL); +} |