[Bf-blender-cvs] [df41f7b] master: Use const for BVH mesh arrays

Campbell Barton noreply at git.blender.org
Wed Jul 22 13:45:55 CEST 2015


Commit: df41f7bf4f1b16d833eb548e57b4512dfb1a3bfa
Author: Campbell Barton
Date:   Wed Jul 22 17:39:33 2015 +1000
Branches: master
https://developer.blender.org/rBdf41f7bf4f1b16d833eb548e57b4512dfb1a3bfa

Use const for BVH mesh arrays

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

M	source/blender/blenkernel/BKE_bvhutils.h
M	source/blender/blenkernel/intern/bvhutils.c
M	source/blender/blenkernel/intern/dynamicpaint.c

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

diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h
index a360511..e78fa65 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -53,9 +53,9 @@ typedef struct BVHTreeFromMesh {
 	BVHTree_RayCastCallback raycast_callback;
 
 	/* Vertex array, so that callbacks have instante access to data */
-	struct MVert *vert;
-	struct MEdge *edge;     /* only used for BVHTreeFromMeshEdges */
-	struct MFace *face;
+	const struct MVert *vert;
+	const struct MEdge *edge;     /* only used for BVHTreeFromMeshEdges */
+	const struct MFace *face;
 	bool vert_allocated;
 	bool edge_allocated;
 	bool face_allocated;
@@ -69,7 +69,7 @@ typedef struct BVHTreeFromMesh {
 
 } BVHTreeFromMesh;
 
-/*
+/**
  * Builds a bvh tree where nodes are the relevant elements of the given mesh.
  * Configures BVHTreeFromMesh.
  *
@@ -79,18 +79,26 @@ typedef struct BVHTreeFromMesh {
  * 
  * free_bvhtree_from_mesh should be called when the tree is no longer needed.
  */
-BVHTree *bvhtree_from_mesh_verts(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis);
-BVHTree *bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data, struct MVert *vert, const int numVerts,
-                                    const bool vert_allocated, BLI_bitmap *mask, int numVerts_active,
-                                    float epsilon, int tree_type, int axis);
-
-BVHTree *bvhtree_from_mesh_edges(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis);
-
-BVHTree *bvhtree_from_mesh_faces(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis);
-BVHTree *bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data, struct MVert *vert, const bool vert_allocated,
-                                    struct MFace *face, const int numFaces, const bool face_allocated,
-                                    BLI_bitmap *mask, int numFaces_active,
-                                    float epsilon, int tree_type, int axis);
+BVHTree *bvhtree_from_mesh_verts(
+        struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis);
+BVHTree *bvhtree_from_mesh_verts_ex(
+        struct BVHTreeFromMesh *data, struct MVert *vert, const int numVerts,
+        const bool vert_allocated, BLI_bitmap *mask, int numVerts_active,
+        float epsilon, int tree_type, int axis);
+
+BVHTree *bvhtree_from_mesh_edges(
+        struct BVHTreeFromMesh *data, struct DerivedMesh *mesh,
+        float epsilon, int tree_type, int axis);
+
+BVHTree *bvhtree_from_mesh_faces(
+        struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon,
+        int tree_type, int axis);
+BVHTree *bvhtree_from_mesh_faces_ex(
+        struct BVHTreeFromMesh *data,
+        struct MVert *vert, const bool vert_allocated,
+        struct MFace *face, const int numFaces, const bool face_allocated,
+        BLI_bitmap *mask, int numFaces_active,
+        float epsilon, int tree_type, int axis);
 
 /*
  * Frees data allocated by a call to bvhtree_from_mesh_*.
diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c
index 1a4a4bd..4472e93 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -84,8 +84,8 @@ static float sphereray_tri_intersection(const BVHTreeRay *ray, float radius, con
 static void mesh_faces_nearest_point(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
 {
 	const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
-	MVert *vert = data->vert;
-	MFace *face = data->face + index;
+	const MVert *vert = data->vert;
+	const MFace *face = data->face + index;
 
 	const float *t0, *t1, *t2, *t3;
 	t0 = vert[face->v1].co;
@@ -148,8 +148,8 @@ static void editmesh_faces_nearest_point(void *userdata, int index, const float
 static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
 {
 	const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
-	MVert *vert = data->vert;
-	MFace *face = data->face + index;
+	const MVert *vert = data->vert;
+	const MFace *face = &data->face[index];
 
 	const float *t0, *t1, *t2, *t3;
 	t0 = vert[face->v1].co;
@@ -217,8 +217,8 @@ static void editmesh_faces_spherecast(void *userdata, int index, const BVHTreeRa
 static void mesh_edges_nearest_point(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
 {
 	const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
-	MVert *vert = data->vert;
-	MEdge *edge = data->edge + index;
+	const MVert *vert = data->vert;
+	const MEdge *edge = data->edge + index;
 	float nearest_tmp[3], dist_sq;
 
 	const float *t0, *t1;
@@ -262,7 +262,7 @@ static void mesh_verts_spherecast_do(
 static void mesh_verts_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
 {
 	const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
-	float *v = data->vert[index].co;
+	const float *v = data->vert[index].co;
 
 	mesh_verts_spherecast_do(data, index, v, ray, hit);
 }
@@ -272,8 +272,8 @@ static void mesh_verts_spherecast(void *userdata, int index, const BVHTreeRay *r
 static void mesh_edges_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
 {
 	const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
-	MVert *vert = data->vert;
-	MEdge *edge = &data->edge[index];
+	const MVert *vert = data->vert;
+	const MEdge *edge = &data->edge[index];
 
 	const float radius_sq = SQUARE(data->sphere_radius);
 	float dist;
@@ -624,10 +624,11 @@ static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon, int tree_type
 	return tree;
 }
 
-static void bvhtree_from_mesh_faces_setup_data(BVHTreeFromMesh *data, BVHTree *tree, const bool is_cached,
-                                               float epsilon, BMEditMesh *em,
-                                               MVert *vert, const bool vert_allocated,
-                                               MFace *face, const bool face_allocated)
+static void bvhtree_from_mesh_faces_setup_data(
+        BVHTreeFromMesh *data, BVHTree *tree, const bool is_cached,
+        float epsilon, BMEditMesh *em,
+        MVert *vert, const bool vert_allocated,
+        MFace *face, const bool face_allocated)
 {
 	memset(data, 0, sizeof(*data));
 	data->em_evil = em;
@@ -727,12 +728,14 @@ BVHTree *bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *dm, float e
  * \param mask if not null, true elements give which faces to add to BVH tree.
  * \param numFaces_active if >= 0, number of active faces to add to BVH tree (else will be computed from mask).
  */
-BVHTree *bvhtree_from_mesh_faces_ex(BVHTreeFromMesh *data, MVert *vert, const bool vert_allocated,
-                                    MFace *face, const int numFaces, const bool face_allocated,
-                                    BLI_bitmap *mask, int numFaces_active, float epsilon, int tree_type, int axis)
+BVHTree *bvhtree_from_mesh_faces_ex(
+        BVHTreeFromMesh *data, MVert *vert, const bool vert_allocated,
+        MFace *face, const int numFaces, const bool face_allocated,
+        BLI_bitmap *mask, int numFaces_active, float epsilon, int tree_type, int axis)
 {
-	BVHTree *tree = bvhtree_from_mesh_faces_create_tree(epsilon, tree_type, axis, NULL, vert, face, numFaces,
-	                                                    mask, numFaces_active);
+	BVHTree *tree = bvhtree_from_mesh_faces_create_tree(
+	        epsilon, tree_type, axis, NULL, vert, face, numFaces,
+	        mask, numFaces_active);
 
 	/* Setup BVHTreeFromMesh */
 	bvhtree_from_mesh_faces_setup_data(data, tree, false, epsilon, NULL, vert, vert_allocated, face, face_allocated);
@@ -749,13 +752,13 @@ void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data)
 		}
 
 		if (data->vert_allocated) {
-			MEM_freeN(data->vert);
+			MEM_freeN((void *)data->vert);
 		}
 		if (data->edge_allocated) {
-			MEM_freeN(data->edge);
+			MEM_freeN((void *)data->edge);
 		}
 		if (data->face_allocated) {
-			MEM_freeN(data->face);
+			MEM_freeN((void *)data->face);
 		}
 
 		memset(data, 0, sizeof(*data));
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index c6a04c7..4372f96 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -2894,8 +2894,8 @@ static void dynamicPaint_doMaterialTex(BrushMaterials *bMats, float color[3], fl
 static void mesh_faces_spherecast_dp(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
 {
 	const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
-	MVert *vert = data->vert;
-	MFace *face = data->face + index;
+	const MVert *vert = data->vert;
+	const MFace *face = data->face + index;
 	short quad = 0;
 
 	const float *t0, *t1, *t2, *t3;
@@ -2930,8 +2930,8 @@ static void mesh_faces_spherecast_dp(void *userdata, int index, const BVHTreeRay
 static void mesh_faces_nearest_point_dp(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
 {
 	const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
-	MVert *vert = data->vert;
-	MFace *face = data->face + index;
+	const MVert *vert = data->vert;
+	const MFace *face = data->face + index;
 	short quad = 0;
 
 	const float *t0, *t1, *t2, *t3;




More information about the Bf-blender-cvs mailing list