minor cleanup to mirror code

- MirrTopoPair.hash was 'long' when only needed to be 'int'
- use 'intptr_t' rather than 'long' when the value is cast back to a pointer.
This commit is contained in:
2011-12-16 07:27:56 +00:00
parent 724868b400
commit d39adcb478
2 changed files with 57 additions and 56 deletions

View File

@@ -88,7 +88,7 @@ struct rcti;
/* meshtools.c */ /* meshtools.c */
intptr_t mesh_octree_table(struct Object *ob, struct EditMesh *em, float *co, char mode); intptr_t mesh_octree_table(struct Object *ob, struct EditMesh *em, float *co, char mode);
long mesh_mirrtopo_table(struct Object *ob, char mode); int mesh_mirrtopo_table(struct Object *ob, char mode);
struct EditVert *editmesh_get_x_mirror_vert(struct Object *ob, struct EditMesh *em, struct EditVert *eve, float *co, int index); struct EditVert *editmesh_get_x_mirror_vert(struct Object *ob, struct EditMesh *em, struct EditVert *eve, float *co, int index);
int mesh_get_x_mirror_vert(struct Object *ob, int index); int mesh_get_x_mirror_vert(struct Object *ob, int index);

View File

@@ -671,17 +671,17 @@ static void mesh_octree_free_node(MocNode **bt)
/* temporal define, just to make nicer code below */ /* temporal define, just to make nicer code below */
#define MOC_ADDNODE(vx, vy, vz) mesh_octree_add_node(basetable + ((vx)*MOC_RES*MOC_RES) + (vy)*MOC_RES + (vz), index) #define MOC_INDEX(vx, vy, vz) (((vx)*MOC_RES*MOC_RES) + (vy)*MOC_RES + (vz))
static void mesh_octree_add_nodes(MocNode **basetable, float *co, float *offs, float *div, intptr_t index) static void mesh_octree_add_nodes(MocNode **basetable, float *co, float *offs, float *div, intptr_t index)
{ {
float fx, fy, fz; float fx, fy, fz;
int vx, vy, vz; int vx, vy, vz;
if (!finite(co[0]) || if ( !finite(co[0]) ||
!finite(co[1]) || !finite(co[1]) ||
!finite(co[2]) !finite(co[2]))
) { {
return; return;
} }
@@ -692,32 +692,32 @@ static void mesh_octree_add_nodes(MocNode **basetable, float *co, float *offs, f
CLAMP(fy, 0.0f, MOC_RES-MOC_THRESH); CLAMP(fy, 0.0f, MOC_RES-MOC_THRESH);
CLAMP(fz, 0.0f, MOC_RES-MOC_THRESH); CLAMP(fz, 0.0f, MOC_RES-MOC_THRESH);
vx= floor(fx); vx= (int)floorf(fx);
vy= floor(fy); vy= (int)floorf(fy);
vz= floor(fz); vz= (int)floorf(fz);
MOC_ADDNODE(vx, vy, vz); mesh_octree_add_node(basetable + MOC_INDEX(vx, vy, vz), index);
if( vx>0 ) if (vx > 0)
if( fx-((float)vx)-MOC_THRESH < 0.0f) if (fx-((float)vx)-MOC_THRESH < 0.0f)
MOC_ADDNODE(vx-1, vy, vz); mesh_octree_add_node(basetable + MOC_INDEX(vx - 1, vy, vz), index);
if( vx<MOC_RES-2 ) if (vx < MOC_RES - 2)
if( fx-((float)vx)+MOC_THRESH > 1.0f) if (fx-((float)vx)+MOC_THRESH > 1.0f)
MOC_ADDNODE(vx+1, vy, vz); mesh_octree_add_node(basetable + MOC_INDEX(vx + 1, vy, vz), index);
if( vy>0 ) if (vy > 0)
if( fy-((float)vy)-MOC_THRESH < 0.0f) if (fy-((float)vy)-MOC_THRESH < 0.0f)
MOC_ADDNODE(vx, vy-1, vz); mesh_octree_add_node(basetable + MOC_INDEX(vx, vy - 1, vz), index);
if( vy<MOC_RES-2 ) if (vy < MOC_RES - 2)
if( fy-((float)vy)+MOC_THRESH > 1.0f) if (fy-((float)vy)+MOC_THRESH > 1.0f)
MOC_ADDNODE(vx, vy+1, vz); mesh_octree_add_node(basetable + MOC_INDEX(vx, vy + 1, vz), index);
if( vz>0 ) if (vz > 0)
if( fz-((float)vz)-MOC_THRESH < 0.0f) if (fz-((float)vz)-MOC_THRESH < 0.0f)
MOC_ADDNODE(vx, vy, vz-1); mesh_octree_add_node(basetable + MOC_INDEX(vx, vy, vz - 1), index);
if( vz<MOC_RES-2 ) if (vz <MOC_RES - 2)
if( fz-((float)vz)+MOC_THRESH > 1.0f) if (fz-((float)vz)+MOC_THRESH > 1.0f)
MOC_ADDNODE(vx, vy, vz+1); mesh_octree_add_node(basetable + MOC_INDEX(vx, vy, vz + 1), index);
} }
@@ -851,35 +851,36 @@ intptr_t mesh_octree_table(Object *ob, EditMesh *em, float *co, char mode)
/* ********************* MESH VERTEX MIRR TOPO LOOKUP *************** */ /* ********************* MESH VERTEX MIRR TOPO LOOKUP *************** */
#define MIRRHASH_TYPE int typedef int MirrTopoHash_t;
typedef struct MirrTopoPair { typedef struct MirrTopoPair_t {
long hash; MirrTopoHash_t hash;
int vIndex; int vIndex;
} MirrTopoPair; } MirrTopoPair_t;
static int MirrTopo_long_sort(const void *l1, const void *l2) static int MirrTopo_long_sort(const void *l1, const void *l2)
{ {
if( (MIRRHASH_TYPE)(intptr_t)l1 > (MIRRHASH_TYPE)(intptr_t)l2 ) return 1; if ((MirrTopoHash_t)(intptr_t)l1 > (MirrTopoHash_t)(intptr_t)l2 ) return 1;
else if( (MIRRHASH_TYPE)(intptr_t)l1 < (MIRRHASH_TYPE)(intptr_t)l2 ) return -1; else if ((MirrTopoHash_t)(intptr_t)l1 < (MirrTopoHash_t)(intptr_t)l2 ) return -1;
return 0; return 0;
} }
static int MirrTopo_item_sort(const void *v1, const void *v2) static int MirrTopo_item_sort(const void *v1, const void *v2)
{ {
if( ((MirrTopoPair *)v1)->hash > ((MirrTopoPair *)v2)->hash ) return 1; if (((MirrTopoPair_t *)v1)->hash > ((MirrTopoPair_t *)v2)->hash ) return 1;
else if( ((MirrTopoPair *)v1)->hash < ((MirrTopoPair *)v2)->hash ) return -1; else if (((MirrTopoPair_t *)v1)->hash < ((MirrTopoPair_t *)v2)->hash ) return -1;
return 0; return 0;
} }
static long *mesh_topo_lookup = NULL; static intptr_t *mesh_topo_lookup = NULL;
static int mesh_topo_lookup_vert_tot = -1; static int mesh_topo_lookup_vert_tot = -1;
static int mesh_topo_lookup_edge_tot = -1; static int mesh_topo_lookup_edge_tot = -1;
static int mesh_topo_lookup_mode = -1; static int mesh_topo_lookup_mode = -1;
/* mode is 's' start, or 'e' end, or 'u' use */ /* mode is 's' start, or 'e' end, or 'u' use */
/* if end, ob can be NULL */ /* if end, ob can be NULL */
long mesh_mirrtopo_table(Object *ob, char mode) /* note, is supposed return -1 on error, which callers are currently checking for, but is not used so far */
int mesh_mirrtopo_table(Object *ob, char mode)
{ {
if(mode=='u') { /* use table */ if(mode=='u') { /* use table */
Mesh *me= ob->data; Mesh *me= ob->data;
@@ -906,9 +907,9 @@ long mesh_mirrtopo_table(Object *ob, char mode)
int totvert, totedge; int totvert, totedge;
int totUnique= -1, totUniqueOld= -1; int totUnique= -1, totUniqueOld= -1;
MIRRHASH_TYPE *MirrTopoHash = NULL; MirrTopoHash_t *MirrTopoHash = NULL;
MIRRHASH_TYPE *MirrTopoHash_Prev = NULL; MirrTopoHash_t *MirrTopoHash_Prev = NULL;
MirrTopoPair *MirrTopoPairs; MirrTopoPair_t *MirrTopoPairs;
mesh_topo_lookup_mode= ob->mode; mesh_topo_lookup_mode= ob->mode;
/* reallocate if needed */ /* reallocate if needed */
@@ -930,7 +931,7 @@ long mesh_mirrtopo_table(Object *ob, char mode)
totvert = me->totvert; totvert = me->totvert;
} }
MirrTopoHash = MEM_callocN( totvert * sizeof(MIRRHASH_TYPE), "TopoMirr" ); MirrTopoHash = MEM_callocN( totvert * sizeof(MirrTopoHash_t), "TopoMirr" );
/* Initialize the vert-edge-user counts used to detect unique topology */ /* Initialize the vert-edge-user counts used to detect unique topology */
if(em) { if(em) {
@@ -967,10 +968,10 @@ long mesh_mirrtopo_table(Object *ob, char mode)
MirrTopoHash[medge->v2] += MirrTopoHash_Prev[medge->v1]; MirrTopoHash[medge->v2] += MirrTopoHash_Prev[medge->v1];
} }
} }
memcpy(MirrTopoHash_Prev, MirrTopoHash, sizeof(MIRRHASH_TYPE) * totvert); memcpy(MirrTopoHash_Prev, MirrTopoHash, sizeof(MirrTopoHash_t) * totvert);
/* sort so we can count unique values */ /* sort so we can count unique values */
qsort(MirrTopoHash_Prev, totvert, sizeof(MIRRHASH_TYPE), MirrTopo_long_sort); qsort(MirrTopoHash_Prev, totvert, sizeof(MirrTopoHash_t), MirrTopo_long_sort);
totUnique = 1; /* account for skiping the first value */ totUnique = 1; /* account for skiping the first value */
for(a=1; a<totvert; a++) { for(a=1; a<totvert; a++) {
@@ -987,7 +988,7 @@ long mesh_mirrtopo_table(Object *ob, char mode)
totUniqueOld = totUnique; totUniqueOld = totUnique;
} }
/* Copy the hash calculated this iter, so we can use them next time */ /* Copy the hash calculated this iter, so we can use them next time */
memcpy(MirrTopoHash_Prev, MirrTopoHash, sizeof(MIRRHASH_TYPE) * totvert); memcpy(MirrTopoHash_Prev, MirrTopoHash, sizeof(MirrTopoHash_t) * totvert);
} }
/* restore eve->tmp.* */ /* restore eve->tmp.* */
@@ -1004,7 +1005,7 @@ long mesh_mirrtopo_table(Object *ob, char mode)
/* Hash/Index pairs are needed for sorting to find index pairs */ /* Hash/Index pairs are needed for sorting to find index pairs */
MirrTopoPairs= MEM_callocN( sizeof(MirrTopoPair) * totvert, "MirrTopoPairs"); MirrTopoPairs= MEM_callocN( sizeof(MirrTopoPair_t) * totvert, "MirrTopoPairs");
/* since we are looping through verts, initialize these values here too */ /* since we are looping through verts, initialize these values here too */
mesh_topo_lookup = MEM_mallocN( totvert * sizeof(long), "mesh_topo_lookup" ); mesh_topo_lookup = MEM_mallocN( totvert * sizeof(long), "mesh_topo_lookup" );
@@ -1022,7 +1023,7 @@ long mesh_mirrtopo_table(Object *ob, char mode)
mesh_topo_lookup[a] = -1; mesh_topo_lookup[a] = -1;
} }
qsort(MirrTopoPairs, totvert, sizeof(MirrTopoPair), MirrTopo_item_sort); qsort(MirrTopoPairs, totvert, sizeof(MirrTopoPair_t), MirrTopo_item_sort);
/* Since the loop starts at 2, we must define the last index where the hash's differ */ /* Since the loop starts at 2, we must define the last index where the hash's differ */
last = ((totvert >= 2) && (MirrTopoPairs[0].hash == MirrTopoPairs[1].hash)) ? 0 : 1; last = ((totvert >= 2) && (MirrTopoPairs[0].hash == MirrTopoPairs[1].hash)) ? 0 : 1;
@@ -1034,8 +1035,8 @@ long mesh_mirrtopo_table(Object *ob, char mode)
if ((a==totvert) || (MirrTopoPairs[a-1].hash != MirrTopoPairs[a].hash)) { if ((a==totvert) || (MirrTopoPairs[a-1].hash != MirrTopoPairs[a].hash)) {
if (a-last==2) { if (a-last==2) {
if(em) { if(em) {
mesh_topo_lookup[MirrTopoPairs[a-1].vIndex] = (long)EM_get_vert_for_index(MirrTopoPairs[a-2].vIndex); mesh_topo_lookup[MirrTopoPairs[a-1].vIndex] = (intptr_t)EM_get_vert_for_index(MirrTopoPairs[a-2].vIndex);
mesh_topo_lookup[MirrTopoPairs[a-2].vIndex] = (long)EM_get_vert_for_index(MirrTopoPairs[a-1].vIndex); mesh_topo_lookup[MirrTopoPairs[a-2].vIndex] = (intptr_t)EM_get_vert_for_index(MirrTopoPairs[a-1].vIndex);
} else { } else {
mesh_topo_lookup[MirrTopoPairs[a-1].vIndex] = MirrTopoPairs[a-2].vIndex; mesh_topo_lookup[MirrTopoPairs[a-1].vIndex] = MirrTopoPairs[a-2].vIndex;
mesh_topo_lookup[MirrTopoPairs[a-2].vIndex] = MirrTopoPairs[a-1].vIndex; mesh_topo_lookup[MirrTopoPairs[a-2].vIndex] = MirrTopoPairs[a-1].vIndex;
@@ -1123,7 +1124,7 @@ static EditVert *editmesh_get_x_mirror_vert_spacial(Object *ob, EditMesh *em, fl
static EditVert *editmesh_get_x_mirror_vert_topo(Object *ob, struct EditMesh *em, EditVert *eve, int index) static EditVert *editmesh_get_x_mirror_vert_topo(Object *ob, struct EditMesh *em, EditVert *eve, int index)
{ {
long poinval; intptr_t poinval;
if (mesh_mirrtopo_table(ob, 'u')==-1) if (mesh_mirrtopo_table(ob, 'u')==-1)
return NULL; return NULL;