Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions utils/ctlgeom-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,10 @@ extern "C" {
matrix3x3 m_p2c;
} prism;

typedef struct mesh_bvh_node {
vector3 bbox_low;
vector3 bbox_high;
int left_child;
int right_child;
int face_start;
int face_count;
} mesh_bvh_node;

typedef struct mesh_struct {
vector3_list vertices;
int num_faces;
int *face_indices;
vector3 *face_normals;
number *face_areas;
int num_bvh_nodes;
mesh_bvh_node *bvh;
int *bvh_face_ids;
boolean is_closed;
vector3 centroid;
number lengthscale;
vector3_list face_indices;
void* internal;
} mesh;

typedef struct ellipsoid_struct {
Expand Down
46 changes: 22 additions & 24 deletions utils/geom-ctl-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ ellipsoid_copy(const ellipsoid * o0, ellipsoid * o)
o->inverse_semi_axes = o0->inverse_semi_axes;
}

/* Defined in geom.c; eagerly rebuilds the opaque mesh_internal cache. */
extern void mesh_init_internal(mesh *m);

void
mesh_copy(const mesh * o0, mesh * o)
{
Expand All @@ -58,21 +61,16 @@ mesh_copy(const mesh * o0, mesh * o)
o->vertices.items[i_t] = o0->vertices.items[i_t];
}
}
o->num_faces = o0->num_faces;
o->face_indices = (int *) malloc(sizeof(int) * 3 * o->num_faces);
memcpy(o->face_indices, o0->face_indices, sizeof(int) * 3 * o->num_faces);
o->face_normals = (vector3 *) malloc(sizeof(vector3) * o->num_faces);
memcpy(o->face_normals, o0->face_normals, sizeof(vector3) * o->num_faces);
o->face_areas = (number *) malloc(sizeof(number) * o->num_faces);
memcpy(o->face_areas, o0->face_areas, sizeof(number) * o->num_faces);
o->num_bvh_nodes = o0->num_bvh_nodes;
o->bvh = (mesh_bvh_node *) malloc(sizeof(mesh_bvh_node) * o->num_bvh_nodes);
memcpy(o->bvh, o0->bvh, sizeof(mesh_bvh_node) * o->num_bvh_nodes);
o->bvh_face_ids = (int *) malloc(sizeof(int) * o->num_faces);
memcpy(o->bvh_face_ids, o0->bvh_face_ids, sizeof(int) * o->num_faces);
o->is_closed = o0->is_closed;
o->centroid = o0->centroid;
o->lengthscale = o0->lengthscale;
{
int i_t;
o->face_indices.num_items = o0->face_indices.num_items;
o->face_indices.items = ((vector3 *) malloc(sizeof(vector3) * (o->face_indices.num_items)));
for (i_t = 0; i_t < o->face_indices.num_items; i_t++) {
o->face_indices.items[i_t] = o0->face_indices.items[i_t];
}
}
o->internal = NULL;
mesh_init_internal(o); /* rebuild BVH eagerly; safe under later concurrent queries */
}

void
Expand Down Expand Up @@ -293,12 +291,12 @@ mesh_equal(const mesh * o0, const mesh * o)
return 0;
}
}
if (o->num_faces != o0->num_faces)
return 0;
{
int i_t;
for (i_t = 0; i_t < 3 * o->num_faces; i_t++) {
if (o->face_indices[i_t] != o0->face_indices[i_t])
if (o->face_indices.num_items != o0->face_indices.num_items)
return 0;
for (i_t = 0; i_t < o->face_indices.num_items; i_t++) {
if (!vector3_equal(o->face_indices.items[i_t], o0->face_indices.items[i_t]))
return 0;
}
}
Expand Down Expand Up @@ -523,15 +521,15 @@ ellipsoid_destroy(ellipsoid o)
{
}

/* Defined in geom.c; frees the opaque mesh_internal cache. Safe on NULL. */
extern void mesh_internal_free(void *p);

void
mesh_destroy(mesh o)
{
free(o.vertices.items);
free(o.face_indices);
free(o.face_normals);
free(o.face_areas);
free(o.bvh);
free(o.bvh_face_ids);
free(o.face_indices.items);
mesh_internal_free(o.internal);
}

void
Expand Down
Loading
Loading