I have a bool function used in a test to see whether or not two objects are neighbours. If they are, a previous function InitFaceCheck() will write either 0 or 1 into a global array N[16] (16 cases to check for).
for (n = 0; n < count; n++ )
{
int l = 0;
for (m = 0; m < count; m++ )
{ InitFaceCheck(tet[n], tet_copy[m]); //
if( (tet[n].ID != tet_copy[m].ID) && (isNeighbour(N) == 1) ) // if T's
{
for(j = 0; j < 16; j++){
printf("N[%i] = %i ",j, N[j]);
}
printf("\n");
tet[n].next[l] = tet_copy[m].ID; // mark them as neighbours
l++; // neighbour counter
};
}
}
The InitFaceCheck() function evaluates if any the two tetrahedra share any of their faces (i.e. they share a face if the share the x,y,z coords of the three vertices that constitute that face) in total there are 16 tests, only 2 are included here:
void InitFaceCheck (TETRA a, TETRA b)
{
/*... Setup of bool variables to be used in CheckFace () ....
a bit tedious due to having .x .y .z components but it is solid for our purposes ... */
bool f11 = ( (a.vert[0].x == b.vert[0].x) && (a.vert[0].y == b.vert[0].y) && (a.vert[0].z == b.vert[0].z) &&
(a.vert[1].x == b.vert[1].x) && (a.vert[1].y == b.vert[1].y) && (a.vert[1].z == b.vert[1].z) &&
(a.vert[2].x == b.vert[2].x) && (a.vert[2].y == b.vert[2].y) && (a.vert[2].z == b.vert[2].z) );
bool f12 = ( (a.vert[0].x == b.vert[0].x) && (a.vert[0].y == b.vert[0].y) && (a.vert[0].z == b.vert[0].z) &&
(a.vert[1].x == b.vert[3].x) && (a.vert[1].y == b.vert[3].y) && (a.vert[1].z == b.vert[3].z) &&
(a.vert[2].x == b.vert[2].x) && (a.vert[2].y == b.vert[2].y) && (a.vert[2].z == b.vert[2].z) );
.......
// write output of tests to global array N, so as to make them accessible to all functions
N[0] = f11;
N[1] = f12;
N[2] = f13;
N[3] = f14;
N[4] = f21;
N[5] = f22;
N[6] = f23;
N[7] = f24;
N[8] = f31;
N[9] = f32;
N[10] = f33;
N[11] = f34;
N[12] = f41;
N[13] = f42;
N[14] = f43;
N[15] = f44;
The isNeighbour function looks like this:
bool isNeighbour (int a[16])
{
return (a[0] || a[1] || a[2] || a[3] || a[4] || a[5] || a[6] || a[7] || a[8]
|| a[9] || a[10] || a[11] || a[12] || a[13] || a[14] || a[15]);
// int i = 0;
//for (i = 0; i < 16; i++)
// {
// if ( a[i] == 1 ) return true;
//
// }
}
The output looks something like this:
T4092
T4100
N[0] = 0 N[1] = 0 N[2] = 0 N[3] = 0 N[4] = 0 N[5] = 0 N[6] = 0 N[7] = 0 N[8] = 1 N[9] = 0 N[10] = 0 N[11] = 0 N[12] = 0 N[13] = 0 N[14] = 0 N[15] = 0
T4101
T4120
N[0] = 0 N[1] = 0 N[2] = 1 N[3] = 0 N[4] = 0 N[5] = 0 N[6] = 0 N[7] = 0 N[8] = 0 N[9] = 0 N[10] = 0 N[11] = 0 N[12] = 0 N[13] = 0 N[14] = 0 N[15] = 0
T4169
N[0] = 0 N[1] = 0 N[2] = 0 N[3] = 0 N[4] = 0 N[5] = 0 N[6] = 0 N[7] = 0 N[8] = 0 N[9] = 0 N[10] = 0 N[11] = 0 N[12] = 1 N[13] = 0 N[14] = 0 N[15] = 0
N[0] = 0 N[1] = 1 N[2] = 0 N[3] = 0 N[4] = 0 N[5] = 0 N[6] = 0 N[7] = 0 N[8] = 0 N[9] = 0 N[10] = 0 N[11] = 0 N[12] = 0 N[13] = 0 N[14] = 0 N[15] = 0
My questions are the following:
why won't the commented out part of isNeighbour() work (it crashes) ? is the condition in the if loop correct ? (is it doing what I think it is doing?)
why is N[] being rewritten as 0 when a tetrahedron has more than 1 neighbour (see T4169 with two lines of N[], in the second line, N[12] was previously evaluated to be true (=1),
why is it when evaluating for the second time and it finds N[1]=1; N[12] is reset to 0.
-and for the love of god is there anyway I could achieve a similar result but in a more elegant manner ? Also I am aware that I might be violating basic rules of coding so please do not hesitate to point them out!
Thank you EDIT: this indeed C. I asked around and was told to include and bool should work just fine.