Blender  V3.3
Classes | Typedefs | Enumerations | Functions
BKE_bvhutils.h File Reference
#include "BLI_bitmap.h"
#include "BLI_kdopbvh.h"
#include "BLI_threads.h"

Go to the source code of this file.

Classes

struct  BVHTreeFromEditMesh
 
struct  BVHTreeFromMesh
 
struct  BVHTreeFromPointCloud
 

Typedefs

typedef struct BVHTreeFromEditMesh BVHTreeFromEditMesh
 
typedef struct BVHTreeFromMesh BVHTreeFromMesh
 
typedef enum BVHCacheType BVHCacheType
 
typedef struct BVHTreeFromPointCloud BVHTreeFromPointCloud
 

Enumerations

enum  BVHCacheType {
  BVHTREE_FROM_VERTS , BVHTREE_FROM_EDGES , BVHTREE_FROM_FACES , BVHTREE_FROM_LOOPTRI ,
  BVHTREE_FROM_LOOPTRI_NO_HIDDEN , BVHTREE_FROM_LOOSEVERTS , BVHTREE_FROM_LOOSEEDGES , BVHTREE_FROM_EM_VERTS ,
  BVHTREE_FROM_EM_EDGES , BVHTREE_FROM_EM_LOOPTRI , BVHTREE_MAX_ITEM
}
 

Functions

BVHTreebvhtree_from_editmesh_verts (BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, int tree_type, int axis)
 
BVHTreebvhtree_from_editmesh_verts_ex (BVHTreeFromEditMesh *data, struct BMEditMesh *em, const BLI_bitmap *mask, int verts_num_active, float epsilon, int tree_type, int axis)
 
BVHTreebvhtree_from_mesh_verts_ex (struct BVHTreeFromMesh *data, const struct MVert *vert, int verts_num, const BLI_bitmap *verts_mask, int verts_num_active, float epsilon, int tree_type, int axis)
 
BVHTreebvhtree_from_editmesh_edges (BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, int tree_type, int axis)
 
BVHTreebvhtree_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)
 
BVHTreebvhtree_from_mesh_edges_ex (struct BVHTreeFromMesh *data, const struct MVert *vert, const struct MEdge *edge, int edges_num, const BLI_bitmap *edges_mask, int edges_num_active, float epsilon, int tree_type, int axis)
 
BVHTreebvhtree_from_editmesh_looptri (BVHTreeFromEditMesh *data, struct BMEditMesh *em, float epsilon, int tree_type, int axis)
 
BVHTreebvhtree_from_editmesh_looptri_ex (BVHTreeFromEditMesh *data, struct BMEditMesh *em, const BLI_bitmap *mask, int looptri_num_active, float epsilon, int tree_type, int axis)
 
BVHTreebvhtree_from_mesh_looptri_ex (struct BVHTreeFromMesh *data, const struct MVert *vert, const struct MLoop *mloop, const struct MLoopTri *looptri, int looptri_num, const BLI_bitmap *mask, int looptri_num_active, float epsilon, int tree_type, int axis)
 
BVHTreeBKE_bvhtree_from_mesh_get (struct BVHTreeFromMesh *data, const struct Mesh *mesh, BVHCacheType bvh_cache_type, int tree_type)
 
BVHTreeBKE_bvhtree_from_editmesh_get (BVHTreeFromEditMesh *data, struct BMEditMesh *em, int tree_type, BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex)
 
void free_bvhtree_from_editmesh (struct BVHTreeFromEditMesh *data)
 
void free_bvhtree_from_mesh (struct BVHTreeFromMesh *data)
 
float bvhtree_ray_tri_intersection (const BVHTreeRay *ray, float m_dist, const float v0[3], const float v1[3], const float v2[3])
 
float bvhtree_sphereray_tri_intersection (const BVHTreeRay *ray, float radius, float m_dist, const float v0[3], const float v1[3], const float v2[3])
 
BVHTreeBKE_bvhtree_from_pointcloud_get (struct BVHTreeFromPointCloud *data, const struct PointCloud *pointcloud, int tree_type)
 
void free_bvhtree_from_pointcloud (struct BVHTreeFromPointCloud *data)
 
bool bvhcache_has_tree (const struct BVHCache *bvh_cache, const BVHTree *tree)
 
struct BVHCachebvhcache_init (void)
 
void bvhcache_free (struct BVHCache *bvh_cache)
 

Typedef Documentation

◆ BVHCacheType

typedef enum BVHCacheType BVHCacheType

◆ BVHTreeFromEditMesh

Struct that stores basic information about a BVHTree built from a edit-mesh.

◆ BVHTreeFromMesh

Struct that stores basic information about a BVHTree built from a mesh.

◆ BVHTreeFromPointCloud

Enumeration Type Documentation

◆ BVHCacheType

Enumerator
BVHTREE_FROM_VERTS 
BVHTREE_FROM_EDGES 
BVHTREE_FROM_FACES 
BVHTREE_FROM_LOOPTRI 
BVHTREE_FROM_LOOPTRI_NO_HIDDEN 
BVHTREE_FROM_LOOSEVERTS 
BVHTREE_FROM_LOOSEEDGES 
BVHTREE_FROM_EM_VERTS 
BVHTREE_FROM_EM_EDGES 
BVHTREE_FROM_EM_LOOPTRI 
BVHTREE_MAX_ITEM 

Definition at line 69 of file BKE_bvhutils.h.

Function Documentation

◆ BKE_bvhtree_from_editmesh_get()

BVHTree* BKE_bvhtree_from_editmesh_get ( BVHTreeFromEditMesh data,
struct BMEditMesh em,
int  tree_type,
BVHCacheType  bvh_cache_type,
struct BVHCache **  bvh_cache_p,
ThreadMutex mesh_eval_mutex 
)

◆ BKE_bvhtree_from_mesh_get()

BVHTree* BKE_bvhtree_from_mesh_get ( struct BVHTreeFromMesh data,
const struct Mesh mesh,
BVHCacheType  bvh_cache_type,
int  tree_type 
)

Builds or queries a BVH-cache for the cache BVH-tree of the request type.

Note
This function only fills a cache, and therefore the mesh argument can be considered logically const. Concurrent access is protected by a mutex.

Definition at line 1213 of file bvhutils.cc.

References ATTR_FALLTHROUGH, BKE_mesh_runtime_looptri_ensure(), BKE_mesh_runtime_looptri_len(), BKE_mesh_vertex_normals_ensure(), BLI_assert, BLI_bvhtree_get_tree_type(), Mesh_Runtime::bvh_cache, bvhcache_find(), bvhcache_insert(), bvhcache_unlock(), bvhtree_balance(), BVHTREE_FROM_EDGES, BVHTREE_FROM_EM_EDGES, BVHTREE_FROM_EM_LOOPTRI, BVHTREE_FROM_EM_VERTS, BVHTREE_FROM_FACES, BVHTREE_FROM_LOOPTRI, BVHTREE_FROM_LOOPTRI_NO_HIDDEN, BVHTREE_FROM_LOOSEEDGES, BVHTREE_FROM_LOOSEVERTS, bvhtree_from_mesh_edges_create_tree(), bvhtree_from_mesh_faces_create_tree(), bvhtree_from_mesh_looptri_create_tree(), bvhtree_from_mesh_setup_data(), bvhtree_from_mesh_verts_create_tree(), BVHTREE_FROM_VERTS, BVHTREE_MAX_ITEM, data, ELEM, Mesh_Runtime::eval_mutex, looptri_no_hidden_map_get(), loose_edges_map_get(), loose_verts_map_get(), mask(), Mesh::medge, MEM_freeN, mesh, Mesh::mface, Mesh::mloop, Mesh::mpoly, Mesh::mvert, Mesh::runtime, Mesh::totedge, Mesh::totface, Mesh::totpoly, and Mesh::totvert.

Referenced by BKE_mesh_remap_calc_difference_from_mesh(), BKE_mesh_remap_calc_edges_from_mesh(), BKE_mesh_remap_calc_loops_from_mesh(), BKE_mesh_remap_calc_polys_from_mesh(), BKE_mesh_remap_calc_verts_from_mesh(), BKE_mesh_remesh_reproject_paint_mask(), BKE_remesh_reproject_sculpt_face_sets(), BKE_remesh_reproject_vertex_paint(), BKE_shrinkwrap_init_tree(), blender::nodes::node_geo_proximity_cc::calculate_mesh_proximity(), cloth_build_springs(), deformVerts(), dynamicPaint_paintMesh(), blender::ed::sculpt_paint::AddOperationExecutor::execute(), blender::ed::sculpt_paint::DensityAddOperationExecutor::execute(), blender::ed::sculpt_paint::DensitySubtractOperationExecutor::execute(), blender::ed::sculpt_paint::PuffOperationExecutor::execute(), blender::ed::sculpt_paint::SlideOperationExecutor::execute(), followtrack_project_to_depth_object_if_needed(), blender::nodes::node_geo_transfer_attribute_cc::get_closest_mesh_edges(), blender::nodes::node_geo_transfer_attribute_cc::get_closest_mesh_looptris(), blender::nodes::node_geo_transfer_attribute_cc::get_closest_mesh_points(), get_vert2geom_distance(), harmonic_coordinates_bind(), blender::ed::sculpt_paint::min_distance_edit::min_distance_edit_invoke(), PE_create_shape_tree(), blender::nodes::node_geo_raycast_cc::raycast_to_mesh(), RE_bake_pixels_populate_from_objects(), remap_hair_emitter(), blender::ed::sculpt_paint::sample_curves_3d_brush(), blender::ed::curves::snap_curves_to_surface::snap_curves_to_surface_exec_object(), snap_object_data_mesh_get(), snapMesh(), blender::draw::statvis_calc_intersect(), blender::draw::statvis_calc_thickness(), surfacedeformBind(), blender::ed::curves::convert_to_particle_system::try_convert_single_object(), and blender::ed::sculpt_paint::use_add_density_mode().

◆ BKE_bvhtree_from_pointcloud_get()

BVHTree* BKE_bvhtree_from_pointcloud_get ( struct BVHTreeFromPointCloud data,
const struct PointCloud pointcloud,
int  tree_type 
)

◆ bvhcache_free()

void bvhcache_free ( struct BVHCache bvh_cache)

◆ bvhcache_has_tree()

bool bvhcache_has_tree ( const struct BVHCache bvh_cache,
const BVHTree tree 
)

◆ bvhcache_init()

struct BVHCache* bvhcache_init ( void  )

Definition at line 113 of file bvhutils.cc.

References BLI_mutex_init(), and BVHCache::mutex.

Referenced by bvhcache_find().

◆ bvhtree_from_editmesh_edges()

BVHTree* bvhtree_from_editmesh_edges ( BVHTreeFromEditMesh data,
struct BMEditMesh em,
float  epsilon,
int  tree_type,
int  axis 
)

◆ bvhtree_from_editmesh_edges_ex()

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 
)

Builds a BVH-tree where nodes are the edges of the given em.

Definition at line 866 of file bvhutils.cc.

References bvhtree_balance(), bvhtree_from_editmesh_edges_create_tree(), bvhtree_from_editmesh_setup_data(), BVHTREE_FROM_EM_EDGES, data, blender::robust_pred::epsilon, and tree.

Referenced by bvhtree_from_editmesh_edges(), and snapEditMesh().

◆ bvhtree_from_editmesh_looptri()

BVHTree* bvhtree_from_editmesh_looptri ( BVHTreeFromEditMesh data,
struct BMEditMesh em,
float  epsilon,
int  tree_type,
int  axis 
)

◆ bvhtree_from_editmesh_looptri_ex()

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 
)

◆ bvhtree_from_editmesh_verts()

BVHTree* bvhtree_from_editmesh_verts ( BVHTreeFromEditMesh data,
struct BMEditMesh em,
float  epsilon,
int  tree_type,
int  axis 
)

Builds a BVH tree where nodes are the relevant elements of the given mesh. Configures BVHTreeFromMesh.

The tree is build in mesh space coordinates, this means special care must be made on queries so that the coordinates and rays are first translated on the mesh local coordinates. Reason for this is that bvh_from_mesh_* can use a cache in some cases and so it becomes possible to reuse a BVHTree.

free_bvhtree_from_mesh should be called when the tree is no longer needed.

Definition at line 753 of file bvhutils.cc.

References bvhtree_from_editmesh_verts_ex(), data, and blender::robust_pred::epsilon.

◆ bvhtree_from_editmesh_verts_ex()

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 
)

Builds a BVH-tree where nodes are the vertices of the given em.

Definition at line 732 of file bvhutils.cc.

References bvhtree_balance(), bvhtree_from_editmesh_setup_data(), bvhtree_from_editmesh_verts_create_tree(), BVHTREE_FROM_EM_VERTS, data, blender::robust_pred::epsilon, and tree.

Referenced by bvhtree_from_editmesh_verts(), and snapEditMesh().

◆ bvhtree_from_mesh_edges_ex()

BVHTree* bvhtree_from_mesh_edges_ex ( struct BVHTreeFromMesh data,
const struct MVert vert,
const struct MEdge edge,
int  edges_num,
const BLI_bitmap edges_mask,
int  edges_num_active,
float  epsilon,
int  tree_type,
int  axis 
)

Builds a BVH-tree where nodes are the given edges.

Parameters
vert,vert_allocatedif true, elem freeing will be done when freeing data.
edge,edge_allocatedif true, elem freeing will be done when freeing data.
edges_maskif not null, true elements give which vert to add to BVH-tree.
edges_num_activeif >= 0, number of active edges to add to BVH-tree (else will be computed from mask).

◆ bvhtree_from_mesh_looptri_ex()

BVHTree* bvhtree_from_mesh_looptri_ex ( struct BVHTreeFromMesh data,
const struct MVert vert,
const struct MLoop mloop,
const struct MLoopTri looptri,
int  looptri_num,
const BLI_bitmap mask,
int  looptri_num_active,
float  epsilon,
int  tree_type,
int  axis 
)

Builds a BVH-tree where nodes are the looptri faces of the given mesh.

Definition at line 1100 of file bvhutils.cc.

References bvhtree_balance(), BVHTREE_FROM_LOOPTRI, bvhtree_from_mesh_looptri_create_tree(), bvhtree_from_mesh_setup_data(), data, blender::robust_pred::epsilon, and tree.

Referenced by BKE_mesh_remap_calc_loops_from_mesh().

◆ bvhtree_from_mesh_verts_ex()

BVHTree* bvhtree_from_mesh_verts_ex ( struct BVHTreeFromMesh data,
const struct MVert vert,
int  verts_num,
const BLI_bitmap verts_mask,
int  verts_num_active,
float  epsilon,
int  tree_type,
int  axis 
)

Builds a BVH-tree where nodes are the given vertices (NOTE: does not copy given vert!).

Parameters
vert_allocatedif true, vert freeing will be done when freeing data.
verts_maskif not null, true elements give which vert to add to BVH-tree.
verts_num_activeif >= 0, number of active verts to add to BVH-tree (else will be computed from mask).

Referenced by BKE_mesh_remap_calc_loops_from_mesh().

◆ bvhtree_ray_tri_intersection()

float bvhtree_ray_tri_intersection ( const BVHTreeRay ray,
float  m_dist,
const float  v0[3],
const float  v1[3],
const float  v2[3] 
)

◆ bvhtree_sphereray_tri_intersection()

float bvhtree_sphereray_tri_intersection ( const BVHTreeRay ray,
float  radius,
float  m_dist,
const float  v0[3],
const float  v1[3],
const float  v2[3] 
)

◆ free_bvhtree_from_editmesh()

void free_bvhtree_from_editmesh ( struct BVHTreeFromEditMesh data)

Frees data allocated by a call to bvhtree_from_editmesh_*.

Definition at line 1400 of file bvhutils.cc.

References BLI_bvhtree_free(), and data.

Referenced by SnapData_EditMesh::clear().

◆ free_bvhtree_from_mesh()

void free_bvhtree_from_mesh ( struct BVHTreeFromMesh data)

Frees data allocated by a call to bvhtree_from_mesh_*.

Definition at line 1410 of file bvhutils.cc.

References BLI_bvhtree_free(), and data.

Referenced by BKE_mesh_remap_calc_edges_from_mesh(), BKE_mesh_remap_calc_loops_from_mesh(), BKE_mesh_remap_calc_polys_from_mesh(), BKE_mesh_remap_calc_verts_from_mesh(), BKE_mesh_remesh_reproject_paint_mask(), BKE_remesh_reproject_sculpt_face_sets(), BKE_remesh_reproject_vertex_paint(), BKE_shrinkwrap_free_tree(), SnapData_Mesh::clear(), cloth_build_springs(), deformVerts(), dynamicPaint_paintMesh(), blender::ed::sculpt_paint::AddOperationExecutor::execute(), blender::ed::sculpt_paint::DensityAddOperationExecutor::execute(), blender::ed::sculpt_paint::DensitySubtractOperationExecutor::execute(), blender::ed::sculpt_paint::PuffOperationExecutor::execute(), blender::ed::sculpt_paint::SlideOperationExecutor::execute(), followtrack_project_to_depth_object_if_needed(), freeData(), blender::nodes::node_geo_transfer_attribute_cc::get_closest_mesh_edges(), blender::nodes::node_geo_transfer_attribute_cc::get_closest_mesh_looptris(), blender::nodes::node_geo_transfer_attribute_cc::get_closest_mesh_points(), get_vert2geom_distance(), harmonic_coordinates_bind(), blender::ed::sculpt_paint::min_distance_edit::min_distance_edit_invoke(), PE_free_shape_tree(), blender::nodes::node_geo_raycast_cc::raycast_to_mesh(), RE_bake_pixels_populate_from_objects(), remap_hair_emitter(), blender::ed::sculpt_paint::sample_curves_3d_brush(), blender::ed::curves::snap_curves_to_surface::snap_curves_to_surface_exec_object(), surfacedeformBind(), blender::ed::curves::convert_to_particle_system::try_convert_single_object(), and blender::ed::sculpt_paint::use_add_density_mode().

◆ free_bvhtree_from_pointcloud()

void free_bvhtree_from_pointcloud ( struct BVHTreeFromPointCloud data)