Commit: 6a0c221bd096a93cc632819164cfc8a210b70f71
Author: Campbell Barton
Date:   Tue Jan 6 14:45:24 2015 +1100
Branches: mathutils_bvhtree
https://developer.blender.org/rB6a0c221bd096a93cc632819164cfc8a210b70f71

Merge branch 'master' into mathutils_bvhtree

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



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

diff --cc source/blender/python/mathutils/mathutils_bvhtree.c
index deda0b1,0000000..5d80500
mode 100644,000000..100644
--- a/source/blender/python/mathutils/mathutils_bvhtree.c
+++ b/source/blender/python/mathutils/mathutils_bvhtree.c
@@@ -1,678 -1,0 +1,678 @@@
 +/*
 + * ***** BEGIN GPL LICENSE BLOCK *****
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * Contributor(s): Lukas Toenne
 + *
 + * ***** END GPL LICENSE BLOCK *****
 + */
 +
 +/** \file blender/python/mathutils/mathutils_bvhtree.c
 + *  \ingroup mathutils
 + *
 + * This file defines the 'mathutils.bvhtree' module, a general purpose module 
to access
 + * blenders bvhtree for mesh surface nearest-element search and ray casting.
 + */
 +
 +#include <Python.h>
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "BLI_utildefines.h"
 +#include "BLI_kdopbvh.h"
 +#include "BLI_math.h"
 +
 +#include "DNA_object_types.h"
 +
 +#include "BKE_bvhutils.h"
 +#include "BKE_customdata.h"
 +#include "BKE_DerivedMesh.h"
 +#include "BKE_editmesh_bvh.h"
 +
 +#include "bmesh.h"
 +
 +#include "../generic/py_capi_utils.h"
 +#include "../bmesh/bmesh_py_types.h"
 +
 +#include "mathutils.h"
 +#include "mathutils_bvhtree.h"  /* own include */
 +
 +#include "BLI_strict_flags.h"
 +
 +typedef struct {
 +      PyObject_HEAD
 +} PyBVHTree;
 +
 +typedef struct {
 +      PyBVHTree base;
 +      /* Object DerivedMesh data */
 +      Object *ob;
 +      BVHTreeFromMesh meshdata;
 +      bool use_poly_index;
 +} PyDerivedMeshBVHTree;
 +
 +typedef struct {
 +      PyBVHTree base;
 +      /* BMesh data */
 +      BMBVHTree *bmdata;
 +      BMLoop *(*bmlooptris)[3];
 +      int bmtotlooptris;
 +} PyBMeshBVHTree;
 +
 +/* -------------------------------------------------------------------- */
 +/* Utility helper functions */
 +
 +static int dm_tessface_to_poly_index(DerivedMesh *dm, int tessface_index)
 +{
 +      if (tessface_index != ORIGINDEX_NONE && tessface_index < 
dm->getNumTessFaces(dm)) {
 +              /* double lookup */
 +              const int *index_mf_to_mpoly;
 +              if ((index_mf_to_mpoly = dm->getTessFaceDataArray(dm, 
CD_ORIGINDEX))) {
 +                      const int *index_mp_to_orig = dm->getPolyDataArray(dm, 
CD_ORIGINDEX);
 +                      return DM_origindex_mface_mpoly(index_mf_to_mpoly, 
index_mp_to_orig, tessface_index);
 +              }
 +      }
 +
 +      return ORIGINDEX_NONE;
 +}
 +
 +static PyObject *bvhtree_ray_hit_to_py(const float co[3], const float no[3], 
int index, float dist)
 +{
 +      PyObject *py_retval = PyTuple_New(4);
 +
-       PyTuple_SET_ITEM(py_retval, 0, Vector_CreatePyObject((float *)co, 3, 
Py_NEW, NULL));
-       PyTuple_SET_ITEM(py_retval, 1, Vector_CreatePyObject((float *)no, 3, 
Py_NEW, NULL));
++      PyTuple_SET_ITEM(py_retval, 0, Vector_CreatePyObject(co, 3, NULL));
++      PyTuple_SET_ITEM(py_retval, 1, Vector_CreatePyObject(no, 3, NULL));
 +      PyTuple_SET_ITEM(py_retval, 2, PyLong_FromLong(index));
 +      PyTuple_SET_ITEM(py_retval, 3, PyFloat_FromDouble(dist));
 +
 +      return py_retval;
 +}
 +
 +static PyObject *bvhtree_nearest_to_py(const float co[3], const float no[3], 
int index, float dist_sq)
 +{
 +      PyObject *py_retval = PyTuple_New(4);
 +
-       PyTuple_SET_ITEM(py_retval, 0, Vector_CreatePyObject((float *)co, 3, 
Py_NEW, NULL));
-       PyTuple_SET_ITEM(py_retval, 1, Vector_CreatePyObject((float *)no, 3, 
Py_NEW, NULL));
++      PyTuple_SET_ITEM(py_retval, 0, Vector_CreatePyObject(co, 3, NULL));
++      PyTuple_SET_ITEM(py_retval, 1, Vector_CreatePyObject(no, 3, NULL));
 +      PyTuple_SET_ITEM(py_retval, 2, PyLong_FromLong(index));
 +      PyTuple_SET_ITEM(py_retval, 3, PyFloat_FromDouble(dist_sq));
 +
 +      return py_retval;
 +}
 +
 +/* -------------------------------------------------------------------- */
 +/* BVHTree */
 +
 +static int PyBVHTree__tp_init(PyBVHTree *UNUSED(self), PyObject 
*UNUSED(args), PyObject *UNUSED(kwargs))
 +{
 +      return 0;
 +}
 +
 +static void PyBVHTree__tp_dealloc(PyBVHTree *self)
 +{
 +      Py_TYPE(self)->tp_free((PyObject *)self);
 +}
 +
 +static PyMethodDef PyBVHTree_methods[] = {
 +      {NULL, NULL, 0, NULL}
 +};
 +
 +PyDoc_STRVAR(py_BVHTree_doc,
 +"BVH tree based on :class:`Mesh` data.\n"
 +);
 +PyTypeObject PyBVHTree_Type = {
 +      PyVarObject_HEAD_INIT(NULL, 0)
 +      "BVHTree",                                   /* tp_name */
 +      sizeof(PyBVHTree),                           /* tp_basicsize */
 +      0,                                           /* tp_itemsize */
 +      /* methods */
 +      (destructor)PyBVHTree__tp_dealloc,           /* tp_dealloc */
 +      NULL,                                        /* tp_print */
 +      NULL,                                        /* tp_getattr */
 +      NULL,                                        /* tp_setattr */
 +      NULL,                                        /* tp_compare */
 +      NULL,                                        /* tp_repr */
 +      NULL,                                        /* tp_as_number */
 +      NULL,                                        /* tp_as_sequence */
 +      NULL,                                        /* tp_as_mapping */
 +      NULL,                                        /* tp_hash */
 +      NULL,                                        /* tp_call */
 +      NULL,                                        /* tp_str */
 +      NULL,                                        /* tp_getattro */
 +      NULL,                                        /* tp_setattro */
 +      NULL,                                        /* tp_as_buffer */
 +      Py_TPFLAGS_DEFAULT,                          /* tp_flags */
 +      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 *)PyBVHTree_methods,     /* tp_methods */
 +      NULL,                                        /* tp_members */
 +      NULL,                                        /* tp_getset */
 +      NULL,                                        /* tp_base */
 +      NULL,                                        /* tp_dict */
 +      NULL,                                        /* tp_descr_get */
 +      NULL,                                        /* tp_descr_set */
 +      0,                                           /* tp_dictoffset */
 +      (initproc)PyBVHTree__tp_init,                /* tp_init */
 +      (allocfunc)PyType_GenericAlloc,              /* tp_alloc */
 +      (newfunc)PyType_GenericNew,                  /* tp_new */
 +      (freefunc)0,                                 /* tp_free */
 +      NULL,                                        /* tp_is_gc */
 +      NULL,                                        /* tp_bases */
 +      NULL,                                        /* tp_mro */
 +      NULL,                                        /* tp_cache */
 +      NULL,                                        /* tp_subclasses */
 +      NULL,                                        /* tp_weaklist */
 +      (destructor) NULL                            /* tp_del */
 +};
 +
 +/* -------------------------------------------------------------------- */
 +/* DerivedMeshBVHTree */
 +
 +static int PyDerivedMeshBVHTree__tp_init(PyDerivedMeshBVHTree *self, PyObject 
*args, PyObject *kwargs)
 +{
 +      BVHTreeFromMesh *meshdata = &self->meshdata;
 +      const char *keywords[] = {"object", "type", NULL};
 +      
 +      PyObject *py_ob;
 +      Object *ob;
 +      const char *type = "POLYS";
 +      
 +      if (PyBVHTree_Type.tp_init((PyObject *)self, args, kwargs) < 0)
 +              return -1;
 +      
 +      if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char 
*)"O|s:DerivedMeshBVHTree", (char **)keywords,
 +                                       &py_ob, &type))
 +      {
 +              return -1;
 +      }
 +      
 +      ob = PyC_RNA_AsPointer(py_ob, "Object");
 +      if (!ob) {
 +              return -1;
 +      }
 +      
 +      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 -1;
 +      }
 +      
 +      self->ob = ob;
 +      
 +      if (STREQ(type, "FACES")) {
 +              bvhtree_from_mesh_faces(meshdata, ob->derivedFinal, 0.0f, 4, 6);
 +              self->use_poly_index = false;
 +      }
 +      else if (STREQ(type, "POLYS")) {
 +              bvhtree_from_mesh_faces(meshdata, ob->derivedFinal, 0.0f, 4, 6);
 +              self->use_poly_index = true;
 +      }
 +      else if (STREQ(type, "VERTS")) {
 +              bvhtree_from_mesh_verts(meshdata, ob->derivedFinal, 0.0f, 4, 6);
 +              self->use_poly_index = false;
 +      }
 +      else if (STREQ(type, "EDGES")) {
 +              bvhtree_from_mesh_edges(meshdata, ob->derivedFinal, 0.0f, 4, 6);
 +              self->use_poly_index = false;
 +      }
 +      else {
 +              PyErr_Format(PyExc_ValueError, "'type' must be 'FACES', 
'POLYS', 'VERTS' or 'EDGES', not '%.200s'", type);
 +              return -1;
 +      }
 +      
 +      return 0;
 +}
 +
 +static void PyDerivedMeshBVHTree__tp_dealloc(PyDerivedMeshBVHTree *self)
 +{
 +      BVHTreeFromMesh *meshdata = &self->meshdata;
 +      
 +      self->ob = NULL;
 +      free_bvhtree_from_mesh(meshdata);
 +      
 +      Py_TYPE(self)->tp_free((PyObject *)self);
 +}
 +
 +PyDoc_STRVAR(py_DerivedMeshBVHTree_ray_cast_doc,
 +".. method:: ray_cast(ray_start, ray_end)\n"
 +"\n"
 +"   Cast a ray onto the mesh.\n"
 +"\n"
 +"   :arg ray_start: Start location of the ray in object space.\n"
 +"   :type ray_start: :class:`Vector`\n"
 +"   :arg ray_end: End location of the ray in object space.\n"
 +"   :type ray_end: :class:`Vector`\n"
 +"   :return: Returns a tuple (:class:`Vector` location, :class:`Vector` 
normal, int index, float distance), index==-1 if no hit was found.\n"
 +"   :rtype: :class:`tuple`\n"
 +);
 +static PyObject *py_DerivedMeshBVHTree_ray_cast(PyDerivedMeshBVHTree *self, 
PyObject *ar

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to