Blender  V2.93
BKE_bvhutils.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2006 by NaN Holding BV.
17  * All rights reserved.
18  */
19 #pragma once
20 
25 #include "BLI_bitmap.h"
26 #include "BLI_kdopbvh.h"
27 #include "BLI_threads.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
37 struct BMEditMesh;
38 struct MFace;
39 struct MVert;
40 struct Mesh;
41 struct PointCloud;
42 
43 struct BVHCache;
44 
48 typedef struct BVHTreeFromEditMesh {
49  struct BVHTree *tree;
50 
51  /* default callbacks to bvh nearest and raycast */
54 
55  struct BMEditMesh *em;
56 
57  /* Private data */
58  bool cached;
59 
61 
65 typedef struct BVHTreeFromMesh {
66  struct BVHTree *tree;
67 
68  /* default callbacks to bvh nearest and raycast */
71 
72  /* Vertex array, so that callbacks have instante access to data */
73  const struct MVert *vert;
74  const struct MEdge *edge; /* only used for BVHTreeFromMeshEdges */
75  const struct MFace *face;
76  const struct MLoop *loop;
77  const struct MLoopTri *looptri;
83 
84  /* Private data */
85  bool cached;
86 
88 
89 typedef enum BVHCacheType {
95 
98 
102 
103  /* Keep `BVHTREE_MAX_ITEM` as last item. */
106 
119  BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, int tree_type, int axis);
120 
122  struct BMEditMesh *em,
123  const BLI_bitmap *mask,
124  int verts_num_active,
125  float epsilon,
126  int tree_type,
127  int axis,
128  const BVHCacheType bvh_cache_type,
129  struct BVHCache **bvh_cache_p,
130  ThreadMutex *mesh_eval_mutex);
131 
133  const struct MVert *vert,
134  const int verts_num,
135  const bool vert_allocated,
136  const BLI_bitmap *mask,
137  int verts_num_active,
138  float epsilon,
139  int tree_type,
140  int axis,
141  const BVHCacheType bvh_cache_type,
142  struct BVHCache **bvh_cache_p,
143  ThreadMutex *mesh_eval_mutex);
144 
146  BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, int tree_type, int axis);
147 
149  struct BMEditMesh *em,
150  const BLI_bitmap *edges_mask,
151  int edges_num_active,
152  float epsilon,
153  int tree_type,
154  int axis,
155  const BVHCacheType bvh_cache_type,
156  struct BVHCache **bvh_cache_p,
157  ThreadMutex *mesh_eval_mutex);
158 
160  const struct MVert *vert,
161  const bool vert_allocated,
162  const struct MEdge *edge,
163  const int edges_num,
164  const bool edge_allocated,
165  const BLI_bitmap *edges_mask,
166  int edges_num_active,
167  float epsilon,
168  int tree_type,
169  int axis,
170  const BVHCacheType bvh_cache_type,
171  struct BVHCache **bvh_cache_p,
172  ThreadMutex *mesh_eval_mutex);
173 
175  const struct MVert *vert,
176  const bool vert_allocated,
177  const struct MFace *face,
178  const int numFaces,
179  const bool face_allocated,
180  const BLI_bitmap *mask,
181  int faces_num_active,
182  float epsilon,
183  int tree_type,
184  int axis,
185  const BVHCacheType bvh_cache_type,
186  struct BVHCache **bvh_cache_p,
187  ThreadMutex *mesh_eval_mutex);
188 
190  BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, int tree_type, int axis);
191 
193  struct BMEditMesh *em,
194  const BLI_bitmap *mask,
195  int looptri_num_active,
196  float epsilon,
197  int tree_type,
198  int axis,
199  const BVHCacheType bvh_cache_type,
200  struct BVHCache **bvh_cache_p,
201  ThreadMutex *mesh_eval_mutex);
202 
204  const struct MVert *vert,
205  const bool vert_allocated,
206  const struct MLoop *mloop,
207  const bool loop_allocated,
208  const struct MLoopTri *looptri,
209  const int looptri_num,
210  const bool looptri_allocated,
211  const BLI_bitmap *mask,
212  int looptri_num_active,
213  float epsilon,
214  int tree_type,
215  int axis,
216  const BVHCacheType bvh_cache_type,
217  struct BVHCache **bvh_cache_p,
218  ThreadMutex *mesh_eval_mutex);
219 
221  struct Mesh *mesh,
222  const BVHCacheType bvh_cache_type,
223  const int tree_type);
224 
226  struct BMEditMesh *em,
227  const int tree_type,
228  const BVHCacheType bvh_cache_type,
229  struct BVHCache **bvh_cache_p,
230  ThreadMutex *mesh_eval_mutex);
231 
237 
242  const float m_dist,
243  const float v0[3],
244  const float v1[3],
245  const float v2[3]);
247  float radius,
248  const float m_dist,
249  const float v0[3],
250  const float v1[3],
251  const float v2[3]);
252 
253 typedef struct BVHTreeFromPointCloud {
254  struct BVHTree *tree;
255 
257 
258  const float (*coords)[3];
260 
262  const struct PointCloud *pointcloud,
263  const int tree_type);
264 
266 
271 /* Using local coordinates */
272 
273 bool bvhcache_has_tree(const struct BVHCache *bvh_cache, const BVHTree *tree);
274 struct BVHCache *bvhcache_init(void);
275 void bvhcache_free(struct BVHCache *bvh_cache);
276 
277 #ifdef __cplusplus
278 }
279 #endif
typedef float(TangentPoint)[2]
BVHTree * BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, struct Mesh *mesh, const BVHCacheType bvh_cache_type, const int tree_type)
Definition: bvhutils.c:1413
float bvhtree_ray_tri_intersection(const BVHTreeRay *ray, const float m_dist, const float v0[3], const float v1[3], const float v2[3])
BVHTree * BKE_bvhtree_from_editmesh_get(BVHTreeFromEditMesh *data, struct BMEditMesh *em, const int tree_type, const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex)
Definition: bvhutils.c:1599
BVHTree * bvhtree_from_editmesh_verts_ex(BVHTreeFromEditMesh *data, struct BMEditMesh *em, const BLI_bitmap *mask, int verts_num_active, float epsilon, int tree_type, int axis, const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex)
Definition: bvhutils.c:631
BVHTree * bvhtree_from_editmesh_looptri_ex(BVHTreeFromEditMesh *data, struct BMEditMesh *em, const BLI_bitmap *mask, int looptri_num_active, float epsilon, int tree_type, int axis, const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex)
Definition: bvhutils.c:1212
void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data)
Definition: bvhutils.c:1701
void bvhcache_free(struct BVHCache *bvh_cache)
Definition: bvhutils.c:152
struct BVHTreeFromPointCloud BVHTreeFromPointCloud
BVHTree * bvhtree_from_editmesh_looptri(BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, int tree_type, int axis)
Definition: bvhutils.c:1258
BVHCacheType
Definition: BKE_bvhutils.h:89
@ BVHTREE_FROM_EDGES
Definition: BKE_bvhutils.h:91
@ BVHTREE_FROM_EM_EDGES
Definition: BKE_bvhutils.h:100
@ BVHTREE_FROM_FACES
Definition: BKE_bvhutils.h:92
@ BVHTREE_FROM_LOOPTRI
Definition: BKE_bvhutils.h:93
@ BVHTREE_FROM_LOOSEEDGES
Definition: BKE_bvhutils.h:97
@ BVHTREE_FROM_EM_VERTS
Definition: BKE_bvhutils.h:99
@ BVHTREE_FROM_LOOSEVERTS
Definition: BKE_bvhutils.h:96
@ BVHTREE_FROM_EM_LOOPTRI
Definition: BKE_bvhutils.h:101
@ BVHTREE_FROM_LOOPTRI_NO_HIDDEN
Definition: BKE_bvhutils.h:94
@ BVHTREE_MAX_ITEM
Definition: BKE_bvhutils.h:104
@ BVHTREE_FROM_VERTS
Definition: BKE_bvhutils.h:90
BVHTree * BKE_bvhtree_from_pointcloud_get(struct BVHTreeFromPointCloud *data, const struct PointCloud *pointcloud, const int tree_type)
BVHTree * bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data, const struct MVert *vert, const bool vert_allocated, const struct MFace *face, const int numFaces, const bool face_allocated, const BLI_bitmap *mask, int faces_num_active, float epsilon, int tree_type, int axis, const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex)
BVHTree * bvhtree_from_editmesh_edges(BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, int tree_type, int axis)
Definition: bvhutils.c:889
struct BVHTreeFromMesh BVHTreeFromMesh
void free_bvhtree_from_pointcloud(struct BVHTreeFromPointCloud *data)
Definition: bvhutils.c:1754
BVHTree * bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data, const struct MVert *vert, const int verts_num, const bool vert_allocated, const BLI_bitmap *mask, int verts_num_active, float epsilon, int tree_type, int axis, const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex)
bool bvhcache_has_tree(const struct BVHCache *bvh_cache, const BVHTree *tree)
BVHTree * bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data, const struct MVert *vert, const bool vert_allocated, const struct MLoop *mloop, const bool loop_allocated, const struct MLoopTri *looptri, const int looptri_num, const bool looptri_allocated, const BLI_bitmap *mask, int looptri_num_active, float epsilon, int tree_type, int axis, const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex)
Definition: bvhutils.c:1270
void free_bvhtree_from_editmesh(struct BVHTreeFromEditMesh *data)
Definition: bvhutils.c:1690
BVHTree * bvhtree_from_mesh_edges_ex(struct BVHTreeFromMesh *data, const struct MVert *vert, const bool vert_allocated, const struct MEdge *edge, const int edges_num, const bool edge_allocated, const BLI_bitmap *edges_mask, int edges_num_active, float epsilon, int tree_type, int axis, const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex)
BVHTree * bvhtree_from_editmesh_verts(BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, int tree_type, int axis)
Definition: bvhutils.c:677
struct BVHTreeFromEditMesh BVHTreeFromEditMesh
struct BVHCache * bvhcache_init(void)
Definition: bvhutils.c:127
BVHTree * bvhtree_from_editmesh_edges_ex(BVHTreeFromEditMesh *data, struct BMEditMesh *em, const BLI_bitmap *edges_mask, int edges_num_active, float epsilon, int tree_type, int axis, const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex)
Definition: bvhutils.c:843
float bvhtree_sphereray_tri_intersection(const BVHTreeRay *ray, float radius, const float m_dist, const float v0[3], const float v1[3], const float v2[3])
Definition: bvhutils.c:190
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:32
void(* BVHTree_RayCastCallback)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
Definition: BLI_kdopbvh.h:114
void(* BVHTree_NearestPointCallback)(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
Definition: BLI_kdopbvh.h:108
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:83
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void * tree
static double epsilon
struct BVHTree * tree
Definition: BKE_bvhutils.h:49
struct BMEditMesh * em
Definition: BKE_bvhutils.h:55
BVHTree_NearestPointCallback nearest_callback
Definition: BKE_bvhutils.h:52
BVHTree_RayCastCallback raycast_callback
Definition: BKE_bvhutils.h:53
BVHTree_RayCastCallback raycast_callback
Definition: BKE_bvhutils.h:70
const struct MFace * face
Definition: BKE_bvhutils.h:75
const struct MEdge * edge
Definition: BKE_bvhutils.h:74
bool looptri_allocated
Definition: BKE_bvhutils.h:82
const struct MLoop * loop
Definition: BKE_bvhutils.h:76
struct BVHTree * tree
Definition: BKE_bvhutils.h:66
const struct MVert * vert
Definition: BKE_bvhutils.h:73
BVHTree_NearestPointCallback nearest_callback
Definition: BKE_bvhutils.h:69
const struct MLoopTri * looptri
Definition: BKE_bvhutils.h:77
struct BVHTree * tree
Definition: BKE_bvhutils.h:254
BVHTree_NearestPointCallback nearest_callback
Definition: BKE_bvhutils.h:256
const float(* coords)[3]
Definition: BKE_bvhutils.h:258
char tree_type
Definition: BLI_kdopbvh.c:102
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)