[Bf-blender-cvs] [7452b43] mathutils_bvhtree: Joined the two bvh tree classes in a single type for simplicity.
Lukas Tönne
noreply at git.blender.org
Sat Jan 3 11:09:12 CET 2015
Commit: 7452b43dbf4722b41ac5bcaa599b34c67063a1c8
Author: Lukas Tönne
Date: Wed Dec 17 19:57:42 2014 +0100
Branches: mathutils_bvhtree
https://developer.blender.org/rB7452b43dbf4722b41ac5bcaa599b34c67063a1c8
Joined the two bvh tree classes in a single type for simplicity.
===================================================================
M source/blender/python/mathutils/mathutils_bvhtree.c
M source/blender/python/mathutils/mathutils_bvhtree.h
===================================================================
diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c
index da88048..8b5fee4 100644
--- a/source/blender/python/mathutils/mathutils_bvhtree.c
+++ b/source/blender/python/mathutils/mathutils_bvhtree.c
@@ -51,14 +51,10 @@
typedef struct {
PyObject_HEAD
- BVHTreeFromMesh treedata;
Object *ob;
-} PyObjectBVHTree;
-
-typedef struct {
- PyObject_HEAD
- BMBVHTree *treedata;
-} PyBMeshBVHTree;
+ BVHTreeFromMesh meshdata;
+ BMBVHTree *bmdata;
+} PyBVHTree;
/* -------------------------------------------------------------------- */
/* Utility helper functions */
@@ -105,39 +101,39 @@ static PyObject *bvhtree_ray_hit_to_py(const float co[3], const float no[3], int
}
/* -------------------------------------------------------------------- */
-/* ObjectBVHTree */
+/* BVHTree */
-static int PyObjectBVHTree__tp_init(PyObjectBVHTree *self, PyObject *args, PyObject *kwargs)
+/* generic cleanup function for resetting everything */
+static void free_BVHTree(PyBVHTree *self)
{
- const char *keywords[] = {"object", NULL};
+ BVHTreeFromMesh *meshdata = &self->meshdata;
- PyObject *py_ob;
- Object *ob;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *)"O:from_faces", (char **)keywords,
- &py_ob))
- {
- return NULL;
- }
+ self->ob = NULL;
+ free_bvhtree_from_mesh(meshdata);
- ob = PyC_RNA_AsPointer(py_ob, "Object");
- if (!ob) {
- return -1;
+ if (self->bmdata) {
+ BKE_bmbvh_free(self->bmdata);
+ self->bmdata = NULL;
}
-
- memset(&self->treedata, 0, sizeof(BVHTreeFromMesh));
- self->ob = ob;
+}
+
+static int PyBVHTree__tp_init(PyBVHTree *self, PyObject *args, PyObject *kwargs)
+{
+ self->ob = NULL;
+ memset(&self->meshdata, 0, sizeof(BVHTreeFromMesh));
+ self->bmdata = NULL;
return 0;
}
-static void PyObjectBVHTree__tp_dealloc(PyObjectBVHTree *self)
+static void PyBVHTree__tp_dealloc(PyBVHTree *self)
{
- free_bvhtree_from_mesh(&self->treedata);
+ free_BVHTree(self);
+
Py_TYPE(self)->tp_free((PyObject *)self);
}
-PyDoc_STRVAR(py_ObjectBVHTree_from_faces_doc,
+PyDoc_STRVAR(py_BVHTree_from_object_faces_doc,
".. method:: from_faces(object)\n"
"\n"
" Construct the BVHTree from mesh faces.\n"
@@ -145,41 +141,53 @@ PyDoc_STRVAR(py_ObjectBVHTree_from_faces_doc,
" :arg object: Point 3d position.\n"
" :type object: :class:`Object`\n"
);
-static PyObject *py_ObjectBVHTree_from_faces(PyObjectBVHTree *self)
+static PyObject *py_BVHTree_from_object_faces(PyBVHTree *self, PyObject *args, PyObject *kwargs)
{
- Object *ob = self->ob;
- BVHTreeFromMesh *treedata = &self->treedata;
+ BVHTreeFromMesh *meshdata = &self->meshdata;
+ const char *keywords[] = {"object", NULL};
- /* free existing data */
- free_bvhtree_from_mesh(treedata);
+ PyObject *py_ob;
+ Object *ob;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *)"O:from_faces", (char **)keywords,
+ &py_ob))
+ {
+ return NULL;
+ }
+
+ ob = PyC_RNA_AsPointer(py_ob, "Object");
+ if (!ob) {
+ return NULL;
+ }
if (ob->derivedFinal == NULL) {
PyErr_Format(PyExc_ValueError, "Object '%.200s' has no mesh data to be used for BVH tree", ob->id.name + 2);
return NULL;
}
+ /* free existing data */
+ free_BVHTree(self);
+
+ self->ob = ob;
/* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
- bvhtree_from_mesh_faces(treedata, ob->derivedFinal, 0.0f, 4, 6);
+ bvhtree_from_mesh_faces(meshdata, ob->derivedFinal, 0.0f, 4, 6);
Py_RETURN_NONE;
}
-PyDoc_STRVAR(py_ObjectBVHTree_free_doc,
+PyDoc_STRVAR(py_BVHTree_clear_doc,
".. method:: clear()\n"
"\n"
" Remove all BVH data.\n"
);
-static PyObject *py_ObjectBVHTree_free(PyObjectBVHTree *self)
+static PyObject *py_BVHTree_clear(PyBVHTree *self)
{
- BVHTreeFromMesh *treedata = &self->treedata;
-
- /* free existing data */
- free_bvhtree_from_mesh(treedata);
+ free_BVHTree(self);
Py_RETURN_NONE;
}
-PyDoc_STRVAR(py_ObjectBVHTree_ray_cast_doc,
+PyDoc_STRVAR(py_BVHTree_ray_cast_doc,
".. method:: ray_cast(ray_start, ray_end)\n"
"\n"
" Cast a ray onto the mesh.\n"
@@ -191,11 +199,11 @@ PyDoc_STRVAR(py_ObjectBVHTree_ray_cast_doc,
" :return: Returns a tuple (:class:`Vector` location, :class:`Vector` normal, int index), index==-1 if no hit was found.\n"
" :rtype: :class:`tuple`\n"
);
-static PyObject *py_ObjectBVHTree_ray_cast(PyObjectBVHTree *self, PyObject *args, PyObject *kwargs)
+static PyObject *py_BVHTree_ray_cast(PyBVHTree *self, PyObject *args, PyObject *kwargs)
{
static const float ZERO[3] = {0.0f, 0.0f, 0.0f};
- BVHTreeFromMesh *treedata = &self->treedata;
+ BVHTreeFromMesh *meshdata = &self->meshdata;
Object *ob = self->ob;
const char *keywords[] = {"ray_start", "ray_end", NULL};
@@ -215,7 +223,7 @@ static PyObject *py_ObjectBVHTree_ray_cast(PyObjectBVHTree *self, PyObject *args
return NULL;
/* may fail if the mesh has no faces, in that case the ray-cast misses */
- if (treedata->tree && ob->derivedFinal) {
+ if (meshdata->tree && ob->derivedFinal) {
BVHTreeRayHit hit;
float ray_nor[3], dist;
sub_v3_v3v3(ray_nor, end, start);
@@ -223,8 +231,8 @@ static PyObject *py_ObjectBVHTree_ray_cast(PyObjectBVHTree *self, PyObject *args
dist = hit.dist = normalize_v3(ray_nor);
hit.index = -1;
- if (BLI_bvhtree_ray_cast(treedata->tree, start, ray_nor, 0.0f, &hit,
- treedata->raycast_callback, treedata) != -1)
+ if (BLI_bvhtree_ray_cast(meshdata->tree, start, ray_nor, 0.0f, &hit,
+ meshdata->raycast_callback, meshdata) != -1)
{
if (hit.dist <= dist) {
int poly_index = dm_tessface_to_poly_index(ob->derivedFinal, hit.index);
@@ -238,23 +246,23 @@ static PyObject *py_ObjectBVHTree_ray_cast(PyObjectBVHTree *self, PyObject *args
}
-static PyMethodDef PyObjectBVHTree_methods[] = {
- {"from_faces", (PyCFunction)py_ObjectBVHTree_from_faces, METH_VARARGS | METH_KEYWORDS, py_ObjectBVHTree_from_faces_doc},
- {"free", (PyCFunction)py_ObjectBVHTree_free, METH_NOARGS, py_ObjectBVHTree_free_doc},
- {"ray_cast", (PyCFunction)py_ObjectBVHTree_ray_cast, METH_VARARGS | METH_KEYWORDS, py_ObjectBVHTree_ray_cast_doc},
+static PyMethodDef PyBVHTree_methods[] = {
+ {"from_object_faces", (PyCFunction)py_BVHTree_from_object_faces, METH_VARARGS | METH_KEYWORDS, py_BVHTree_from_object_faces_doc},
+ {"clear", (PyCFunction)py_BVHTree_clear, METH_VARARGS | METH_KEYWORDS, py_BVHTree_clear_doc},
+ {"ray_cast", (PyCFunction)py_BVHTree_ray_cast, METH_VARARGS | METH_KEYWORDS, py_BVHTree_ray_cast_doc},
{NULL, NULL, 0, NULL}
};
-PyDoc_STRVAR(py_ObjectBVHTree_doc,
+PyDoc_STRVAR(py_BVHTree_doc,
"BVH tree based on :class:`Mesh` data.\n"
);
-PyTypeObject PyObjectBVHTree_Type = {
+PyTypeObject PyBVHTree_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
- "ObjectBVHTree", /* tp_name */
- sizeof(PyObjectBVHTree), /* tp_basicsize */
+ "BVHTree", /* tp_name */
+ sizeof(PyBVHTree), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
- (destructor)PyObjectBVHTree__tp_dealloc, /* tp_dealloc */
+ (destructor)PyBVHTree__tp_dealloc, /* tp_dealloc */
NULL, /* tp_print */
NULL, /* tp_getattr */
NULL, /* tp_setattr */
@@ -270,14 +278,14 @@ PyTypeObject PyObjectBVHTree_Type = {
NULL, /* tp_setattro */
NULL, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
- py_ObjectBVHTree_doc, /* Documentation string */
+ py_BVHTree_doc, /* Documentation string */
NULL, /* tp_traverse */
NULL, /* tp_clear */
NULL, /* tp_richcompare */
0, /* tp_weaklistoffset */
NULL, /* tp_iter */
NULL, /* tp_iternext */
- (struct PyMethodDef *)PyObjectBVHTree_methods, /* tp_methods */
+ (struct PyMethodDef *)PyBVHTree_methods, /* tp_methods */
NULL, /* tp_members */
NULL, /* tp_getset */
NULL, /* tp_base */
@@ -285,7 +293,7 @@ PyTypeObject PyObjectBVHTree_Type = {
NULL, /* tp_descr_get */
NULL, /* tp_descr_set */
0, /* tp_dictoffset */
- (initproc)PyObjectBVHTree__tp_init, /* tp_init */
+ (initproc)PyBVHTree__tp_init, /* tp_init */
(allocfunc)PyType_GenericAlloc, /* tp_alloc */
(newfunc)PyType_GenericNew, /* tp_new */
(freefunc)0, /* tp_free */
@@ -324,19 +332,11 @@ PyMODINIT_FUNC PyInit_mathutils_bvhtree(void)
return NULL;
}
- /* Register the 'ObjectBVHTree' class */
- if (PyType_Ready(&PyObjectBVHTree_Type)) {
- return NULL;
- }
- PyModule_AddObject(m, "ObjectBVHTree", (PyObject *) &PyObjectBVHTree_Type);
-
-#if 0
- /* Register the 'BMeshBVHTree' class */
- if (PyType_Ready(&PyBMeshBVHTree_Type)) {
+ /* Register the 'BVHTree' class */
+ if (PyType_Ready(&PyBVHTree_Type)) {
return NULL;
}
- PyModule_AddObject(m, "BMeshBVHTree", (PyObject *) &PyBMeshBVHTree_Type);
-#endif
+ PyModule_AddObject(m, "BVHTree", (PyObject *) &PyBVHTree_Type);
return m;
}
diff --git a/source/blender/python/mathutils/mathutils_bvhtree.h b/source/blender/python/mathutils/mathutils_bvhtree.h
index fc9e5a0..bd85257 100644
--- a/source/blender/python/mathutils/mathutils_bvhtree.h
+++ b/source/blender/python/mathutils/mathutils_bvhtree.h
@@ -28,7 +28,6 @@
PyMODINIT_FUNC PyInit_mathutils_bvhtree(void);
-extern PyTypeObject PyObjectBVHTree_Type;
-extern PyTyp
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list