star-enclosures-3d

Extract enclosures from 3D geometry
git clone git://git.meso-star.fr/star-enclosures-3d.git
Log | Files | Refs | README | LICENSE

commit a204de119a9cfbdd7f777d5fdfb0e3551b39bcbb
parent 2c790d9bd6008d905e1be557fb4836602282213e
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu, 10 Oct 2019 16:26:41 +0200

Add a reserve API call

Diffstat:
Msrc/senc.h | 14++++++++++++++
Msrc/senc_scene.c | 22++++++++++++++++++++++
Msrc/test_senc_many_enclosures.c | 2++
Msrc/test_senc_many_triangles.c | 2++
4 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/src/senc.h b/src/senc.h @@ -151,6 +151,14 @@ senc_scene_create const enum senc_convention convention, struct senc_scene** scene); +/* Reserve memory according to anticipated scene size. */ +SENC_API res_T +senc_scene_reserve + (const struct senc_scene* scene, + const unsigned vertices_count, + const unsigned triangles_count, + const unsigned media_count); + /* Add a new set of vertices and triangles to the scene. * Vertices can be duplicates and are deduplicated on the fly. * Triangles can be duplicates as long as they constantly define the same @@ -208,6 +216,12 @@ senc_scene_get_unique_vertices_count (const struct senc_scene* scene, unsigned* count); +/* Returns the number of triangles in the scene. */ +SENC_API res_T +senc_scene_get_triangles_count + (const struct senc_scene* scene, + unsigned* count); + SENC_API res_T senc_scene_ref_get (struct senc_scene* scene); diff --git a/src/senc_scene.c b/src/senc_scene.c @@ -94,6 +94,28 @@ error: } res_T +senc_scene_reserve + (const struct senc_scene* scn, + const unsigned vertices_count, + const unsigned triangles_count, + const unsigned media_count) +{ + res_T res = RES_OK; + if(!scn) return RES_BAD_ARG; + + OK(darray_position_reserve(&scn->vertices, vertices_count)); + OK(darray_triangle_in_reserve(&scn->triangles_in, triangles_count)); + OK(htable_vrtx_reserve(&scn->unique_vertices, vertices_count)); + OK(htable_trg_reserve(&scn->unique_triangles, triangles_count)); + OK(darray_side_range_reserve(&scn->media_use, media_count)); + +end: + return res; +error: + goto end; +} + +res_T senc_scene_add_geometry (struct senc_scene* scn, const unsigned ntris, diff --git a/src/test_senc_many_enclosures.c b/src/test_senc_many_enclosures.c @@ -106,6 +106,8 @@ main(int argc, char** argv) ASSERT(ctx.data.nvertices < UINT_MAX); cyl_trg_count = (unsigned)ctx.data.nprimitives; cyl_vrtx_count = (unsigned)ctx.data.nvertices; + CHK(senc_scene_reserve(scn, NB_CYL * cyl_vrtx_count, NB_CYL * cyl_trg_count, 0) + == RES_OK); FOR_EACH(i, 0, NB_CYL_1) { double center_x = 2 * (1 + NB_CYL_1) * (i - NB_CYL_1 / 2); FOR_EACH(j, 0, NB_CYL_1) { diff --git a/src/test_senc_many_triangles.c b/src/test_senc_many_triangles.c @@ -104,6 +104,8 @@ main(int argc, char** argv) ASSERT(ctx.data.nvertices < UINT_MAX); cyl_trg_count = (unsigned)ctx.data.nprimitives; cyl_vrtx_count = (unsigned)ctx.data.nvertices; + CHK(senc_scene_reserve(scn, NB_CYL * cyl_vrtx_count, NB_CYL * cyl_trg_count, 0) + == RES_OK); FOR_EACH(i, 0, NB_CYL) { m1 = i; d3(ctx.ctx.offset, 0, 0, i * 10);