Skip to content

Instantly share code, notes, and snippets.

@provos
Created October 23, 2016 14:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save provos/4e88a9f13fb7354fa680c7b1d4c907b2 to your computer and use it in GitHub Desktop.
Save provos/4e88a9f13fb7354fa680c7b1d4c907b2 to your computer and use it in GitHub Desktop.
VEX code for getting an in-order traversal of the neighbours of a point; assumes connected primitives.
/* returns the in-order neighbours of a point - based on matching primitives */
void inorder_neighbours(int point_number; int points[] /* returned */) {
int nc = neighbourcount(geoself(), point_number);
resize(points, nc);
int prims[] = pointprims(geoself(), point_number);
int points_in_prim[] = primpoints(geoself(), prims[0]);
//
// WE EXPECT THREE POINTS PER PRIMITIVE!!!
//
int j = 0;
for (int i = 0; i < 3; ++i) {
if (points_in_prim[i] != point_number) {
// the first primitive determines our traversal order
points[j++] = points_in_prim[i];
}
}
for (int i = 2; i < nc; ++i) {
// we already used up one primitive
int found = 0;
for (j = i - 1; j < len(prims); ++j) {
points_in_prim = primpoints(geoself(), prims[j]);
int candidate_point = -1;
int candidate_prim_idx = -1;
foreach(int pt; points_in_prim) {
if (pt != point_number) {
if (pt == points[i-1]) {
found = 1;
} else {
candidate_point = pt;
candidate_prim_idx = j;
}
}
}
if (found) {
points[i] = candidate_point;
// each time we find a primitive we have to use it up.
if (candidate_prim_idx != i - 1) {
prims[candidate_prim_idx] = prims[i-1];
}
break;
}
}
assert(found);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment