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 d700be376e401025d16c5474f7c18569e2381cb9
parent e2f31f71bf7ec05621ed1e1ce7c4e1a47791e32b
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 30 Mar 2018 16:29:49 +0200

Cosmetic changes; mostly renames and comments.

Diffstat:
Msrc/senc_scene.c | 2+-
Msrc/senc_scene_analyze.c | 84++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/senc_scene_analyze_c.h | 6+++---
Msrc/test_senc_many_enclosures.c | 4+++-
Msrc/test_senc_many_triangles.c | 4+++-
Msrc/test_senc_sample_enclosure.c | 15+++++++--------
Msrc/test_senc_scene.c | 2--
Msrc/test_senc_utils.h | 2++
8 files changed, 64 insertions(+), 55 deletions(-)

diff --git a/src/senc_scene.c b/src/senc_scene.c @@ -149,7 +149,7 @@ senc_scene_add_geometry OK(htable_vrtx_set(&scn->unique_vertices, &tmp, &unique_v)); ++actual_nuverts; } - /* The unique ID for vertex v is u */ + /* The unique ID for vertex i is unique_v */ ASSERT(i == darray_vrtx_id_size_get(&unique_vertice_ids)); OK(darray_vrtx_id_push_back(&unique_vertice_ids, &unique_v)); ++actual_nverts; diff --git a/src/senc_scene_analyze.c b/src/senc_scene_analyze.c @@ -270,7 +270,8 @@ extract_connex_components { trg_id_t tid = TRGSIDE_2_TRG(start_side_id); enum side_flag s = TRGSIDE_2_SIDE(start_side_id); - medium_id_t side_med = darray_triangle_in_data_get(&desc->scene->triangles_in)[tid].medium[s]; + medium_id_t side_med + = darray_triangle_in_data_get(&desc->scene->triangles_in)[tid].medium[s]; ASSERT(side_med == m); } #endif @@ -357,9 +358,9 @@ extract_connex_components if(change) { cc->max_z_nz = side_nz; cc->max_z_side_id = crt_side_id; - ASSERT(trg_tmp->max_z_vrtx_id < 3); - ASSERT(trg_in->vertice_id[trg_tmp->max_z_vrtx_id] < scn->nverts); - cc->max_z_vrtx_id = trg_in->vertice_id[trg_tmp->max_z_vrtx_id]; + ASSERT(trg_tmp->max_z_vrtx_rank < 3); + ASSERT(trg_in->vertice_id[trg_tmp->max_z_vrtx_rank] < scn->nverts); + cc->max_z_vrtx_id = trg_in->vertice_id[trg_tmp->max_z_vrtx_rank]; ASSERT(trg_tmp->max_z == vertices[cc->max_z_vrtx_id].pos.z); d3_set(cc->max_vrtx, vertices[cc->max_z_vrtx_id].vec); } @@ -589,7 +590,7 @@ group_connex_components if(S3D_HIT_NONE(&hit)) { cc->cc_group_root = CC_GROUP_ROOT_INFINITE; cc->enclosure_id = 0; - /* Keep the first component facing infinity */ + /* Keep track of the first component facing infinity */ ATOMIC_CAS_PTR(&infinity_first_cc, cc, NULL); if(infinity_first_cc->medium != cc->medium) { const side_id_t infinity_first_side = infinity_first_cc->max_z_side_id; @@ -688,8 +689,8 @@ group_connex_components } continue; error_: + /* Cannot goto out of openmp block */ exit_for = 1; - continue; } ASSERT(next_enclosure_id < ENCLOSURE_MAX__); desc->enclosures_count = (enclosure_id_t)next_enclosure_id; @@ -777,7 +778,8 @@ collect_and_link_neighbours OK(darray_neighbourhood_reserve(&neighbourhood_by_edge, nbedges_guess)); OK(htable_edge_id_reserve(&edge_ids, nbedges_guess)); - /* Loop on triangles to register edges. */ + /* Loop on triangles to register edges. + * All threads considering all the edges and processing some */ FOR_EACH(t, 0, scn->nutris) { struct trg_edge edge; unsigned char ee; @@ -787,7 +789,8 @@ collect_and_link_neighbours const vrtx_id_t v1 = triangles_in[t].vertice_id[(ee + 1) % 3]; /* Process only "my" edges! */ const int64_t h = - v0 + v1 + (int64_t)MMIN(v0, v1); /* v0,v1 and v1,v0 must give the same hash!!! */ + /* v0,v1 and v1,v0 must give the same hash!!! */ + v0 + v1 + (int64_t)MMIN(v0, v1); if(h % thread_count != rank) continue; /* Create edge. */ set_edge(v0, v1, &edge, &triangles_tmp[t].reversed_edge[ee]); @@ -804,7 +807,7 @@ collect_and_link_neighbours OK(darray_neighbour_resize(&n->neighbours, 1 + sz)); info = darray_neighbour_data_get(&n->neighbours) + sz; info->trg_id = t; - info->edge_rank = ee; + info->common_edge_rank = ee; } else { /* Create id */ edge_id_t id; @@ -825,10 +828,11 @@ collect_and_link_neighbours OK(darray_neighbour_resize(&n->neighbours, 1)); info = darray_neighbour_data_get(&n->neighbours); info->trg_id = t; - info->edge_rank = ee; + info->common_edge_rank = ee; } } } + /* No implicit barrier here. */ /* Loop on collected edges. * For each edge sort triangle sides by rotation angle @@ -837,13 +841,13 @@ collect_and_link_neighbours ASSERT(tmp <= EDGE_MAX__); edge_count = (edge_id_t)tmp; FOR_EACH(e, 0, edge_count) { - double edge[3], common_edge[3], basis[9], norm, mz, mz_edge; + double edge[3], common_edge[3], basis[9], norm, max_z, maxz_edge; vrtx_id_t v0, v1, v2; struct edge_neighbourhood* neighbourhood = darray_neighbourhood_data_get(&neighbourhood_by_edge) + e; struct darray_neighbour* neighbour_list = &neighbourhood->neighbours; side_id_t i, neighbour_count; - unsigned char mz_vid, mz_vid_edge; + unsigned char maxz_vrank, maxz_vrank_edge; tmp = darray_neighbour_size_get(neighbour_list); ASSERT(tmp <= SIDE_MAX__); neighbour_count = (side_id_t)tmp; @@ -852,11 +856,11 @@ collect_and_link_neighbours v1 = neighbourhood->edge.vrtx1; d3_sub(common_edge, vertices[v1].vec, vertices[v0].vec); if(vertices[v0].pos.z > vertices[v1].pos.z) { - mz_edge = vertices[v0].pos.z; - mz_vid_edge = 0; + maxz_edge = vertices[v0].pos.z; + maxz_vrank_edge = 0; } else { - mz_edge = vertices[v1].pos.z; - mz_vid_edge = 1; + maxz_edge = vertices[v1].pos.z; + maxz_vrank_edge = 1; } norm = d3_normalize(common_edge, common_edge); ASSERT(norm); (void)norm; @@ -865,31 +869,33 @@ collect_and_link_neighbours FOR_EACH(i, 0, neighbour_count) { struct neighbour_info* neighbour_info = darray_neighbour_data_get(neighbour_list) + i; - const struct triangle_in *trg_in = triangles_in + neighbour_info->trg_id; - struct triangle_tmp *neighbour = triangles_tmp + neighbour_info->trg_id; - unsigned char actual_vid; - v2 = trg_in->vertice_id[(neighbour_info->edge_rank + 2) % 3]; - if(vertices[v2].pos.z > mz_edge) { - mz = vertices[v2].pos.z; - mz_vid = 2; + const struct triangle_in* trg_in = triangles_in + neighbour_info->trg_id; + struct triangle_tmp* neighbour = triangles_tmp + neighbour_info->trg_id; + unsigned char actual_vrank; + v2 = trg_in->vertice_id[(neighbour_info->common_edge_rank + 2) % 3]; + if(vertices[v2].pos.z > maxz_edge) { + max_z = vertices[v2].pos.z; + maxz_vrank = 2; } else { - mz = mz_edge; - mz_vid = mz_vid_edge; + max_z = maxz_edge; + maxz_vrank = maxz_vrank_edge; } /* Compute the actual vertex id * as vertices are not in the v0 v1 v2 order in the actual triangle */ - if(mz_vid == 2) { - actual_vid = (unsigned char)((2 + neighbour_info->edge_rank) % 3); + if(maxz_vrank == 2) { + actual_vrank = + (unsigned char)((neighbour_info->common_edge_rank + 2) % 3); } else { - int is_r = neighbour->reversed_edge[neighbour_info->edge_rank]; - ASSERT(mz_vid == 0 || mz_vid == 1); - actual_vid = (unsigned char)(((is_r ? 1 - mz_vid : mz_vid) - + neighbour_info->edge_rank) % 3); + unsigned char is_r = + neighbour->reversed_edge[neighbour_info->common_edge_rank]; + ASSERT(maxz_vrank == 0 || maxz_vrank == 1); + actual_vrank = ((is_r ? 1 - maxz_vrank : maxz_vrank) + + neighbour_info->common_edge_rank) % 3; } - ASSERT(neighbour->max_z <= mz); - neighbour->max_z = mz; - ASSERT(actual_vid <= 2); - neighbour->max_z_vrtx_id = actual_vid; + ASSERT(neighbour->max_z <= max_z); + neighbour->max_z = max_z; + ASSERT(actual_vrank <= 2); + neighbour->max_z_vrtx_rank = actual_vrank; /* Compute rotation angle around common edge */ d3_sub(edge, vertices[v2].vec, vertices[v0].vec); d33_muld3(edge, basis, edge); @@ -911,8 +917,8 @@ collect_and_link_neighbours const struct neighbour_info* ccw_neighbour = darray_neighbour_cdata_get(neighbour_list) + (i + 1) % neighbour_count; /* Rank of the edge of interest in triangles */ - const unsigned char crt_edge = current->edge_rank; - const unsigned char ccw_edge = ccw_neighbour->edge_rank; + const unsigned char crt_edge = current->common_edge_rank; + const unsigned char ccw_edge = ccw_neighbour->common_edge_rank; /* User id of current triangles */ const trg_id_t crt_id = current->trg_id; const trg_id_t ccw_id = ccw_neighbour->trg_id; @@ -998,7 +1004,7 @@ build_result /* Implicit barrier here */ /* Resize/push operations on enclosure's fields are valid in the - * openmp block as a given enclosure is processed by a single thread */ + * openmp block as a given enclosure is processed by a single thread */ htable_vrtx_id_init(alloc, &vtable); ASSERT(desc->enclosures_count <= ENCLOSURE_MAX__); @@ -1027,7 +1033,7 @@ build_result OK(darray_triangle_in_resize(&enc->sides, enc->side_count)); /* Size is just a int */ OK(darray_vrtx_id_reserve(&enc->vertices, - enc->side_count / 2 + enc->side_count / 8)); + (size_t)(enc->side_count * 0.6))); /* New vertex numbering scheme local to the enclosure */ htable_vrtx_id_clear(&vtable); ASSERT(desc->scene->nutris diff --git a/src/senc_scene_analyze_c.h b/src/senc_scene_analyze_c.h @@ -173,7 +173,7 @@ struct triangle_tmp { * the edges they are linked to? */ unsigned char reversed_edge[3]; /* tmp data used to find the +Z-most vertex of components */ - unsigned char max_z_vrtx_id; + unsigned char max_z_vrtx_rank; double max_z; }; @@ -184,7 +184,7 @@ triangle_tmp_init(struct mem_allocator* alloc, struct triangle_tmp* trg) { (void) alloc; ASSERT(trg); FOR_EACH(i, 0, 3) trg->reversed_edge[i] = UCHAR_MAX; - trg->max_z_vrtx_id = UCHAR_MAX; + trg->max_z_vrtx_rank = UCHAR_MAX; trg->max_z = -DBL_MAX; } #define DARRAY_FUNCTOR_INIT triangle_tmp_init @@ -204,7 +204,7 @@ struct neighbour_info { double angle; trg_id_t trg_id; /* Rank of the edge in the triangle (in [0 2]) */ - unsigned char edge_rank; + unsigned char common_edge_rank; }; #define DARRAY_NAME neighbour #define DARRAY_DATA struct neighbour_info diff --git a/src/test_senc_many_enclosures.c b/src/test_senc_many_enclosures.c @@ -99,7 +99,7 @@ main(int argc, char** argv) ctx.ctx.front_media = &m_in; ctx.ctx.back_media = &m_out; /* A 20 triangles 12 vertices cylinder template */ - CHK(s3dut_create_cylinder(&allocator, 1, 1, 5, 1, &cyl) == RES_OK); + S3DUT(create_cylinder(&allocator, 1, 1, 5, 1, &cyl)); S3DUT(mesh_get_data(cyl, &ctx.data)); ASSERT(ctx.data.nprimitives < UINT_MAX); ASSERT(ctx.data.nvertices < UINT_MAX); @@ -133,6 +133,8 @@ main(int argc, char** argv) time_dump(&t0, TIME_MSEC | TIME_SEC | TIME_MIN, NULL, dump, sizeof(dump)); printf("Scene analyzed in: %s\n", dump); + /* dump_global(desc, "test_many_enclosures.obj"); */ + CHK(senc_descriptor_get_global_vertices_count(desc, &count) == RES_OK); CHK(count == NB_CYL * cyl_vrtx_count); CHK(senc_descriptor_get_global_triangles_count(desc, &count) == RES_OK); diff --git a/src/test_senc_many_triangles.c b/src/test_senc_many_triangles.c @@ -97,7 +97,7 @@ main(int argc, char** argv) ctx.ctx.back_media = &m0; ctx.ctx.front_media = &m1; /* A 2,562,560 triangles 1,281,282 vertices cylinder template */ - CHK(s3dut_create_cylinder(&allocator, 1, 2, 1280, 1000, &cyl) == RES_OK); + S3DUT(create_cylinder(&allocator, 1, 2, 1280, 1000, &cyl)); S3DUT(mesh_get_data(cyl, &ctx.data)); ASSERT(ctx.data.nprimitives < UINT_MAX); ASSERT(ctx.data.nvertices < UINT_MAX); @@ -118,6 +118,8 @@ main(int argc, char** argv) time_dump(&t0, TIME_MSEC | TIME_SEC | TIME_MIN, NULL, dump, sizeof(dump)); printf("Scene analyzed in: %s\n", dump); + /* dump_global(desc, "test_many_triangles.obj"); */ + CHK(senc_descriptor_get_global_vertices_count(desc, &count) == RES_OK); CHK(count == NB_CYL * cyl_vrtx_count); CHK(senc_descriptor_get_global_triangles_count(desc, &count) == RES_OK); diff --git a/src/test_senc_sample_enclosure.c b/src/test_senc_sample_enclosure.c @@ -54,9 +54,9 @@ main(int argc, char** argv) vrtx_get.usage = S3D_POSITION; vrtx_get.get = senc_enclosure_get_vertex__; - CHK(s3d_device_create(NULL, &allocator, 0, &s3d) == RES_OK); + S3D(device_create(NULL, &allocator, 0, &s3d)); - CHK(s3d_scene_create(s3d, &s3d_scn) == RES_OK); + S3D(scene_create(s3d, &s3d_scn)); /* A 3D cube, but with a hole (incomplete). * 1 single enclosure including both sides of triangles */ @@ -79,15 +79,14 @@ main(int argc, char** argv) CHK(senc_enclosure_get_header(enclosure, &header) == RES_OK); /* Put enclosure in a 3D view... */ - CHK(s3d_shape_create_mesh(s3d, &s3d_shp) == RES_OK); - CHK(s3d_mesh_setup_indexed_vertices(s3d_shp, header->triangle_count, + S3D(shape_create_mesh(s3d, &s3d_shp)); + S3D(mesh_setup_indexed_vertices(s3d_shp, header->triangle_count, senc_enclosure_get_triangle__, header->vertices_count, &vrtx_get, 1, - enclosure) - == RES_OK); + enclosure)); - CHK(s3d_scene_attach_shape(s3d_scn, s3d_shp) == RES_OK); + S3D(scene_attach_shape(s3d_scn, s3d_shp)); - CHK(s3d_scene_view_create(s3d_scn, S3D_SAMPLE, &s3d_view) == RES_OK); + S3D(scene_view_create(s3d_scn, S3D_SAMPLE, &s3d_view)); /* ... and sample it. */ CHK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng) == RES_OK); diff --git a/src/test_senc_scene.c b/src/test_senc_scene.c @@ -19,8 +19,6 @@ #include <rsys/float3.h> #include <rsys/double3.h> -#include <star/s3d.h> - int main(int argc, char** argv) { diff --git a/src/test_senc_utils.h b/src/test_senc_utils.h @@ -16,7 +16,9 @@ #ifndef TEST_UTILS_H #define TEST_UTILS_H +#include <rsys/rsys.h> #include <rsys/mem_allocator.h> + #include <stdio.h> /*******************************************************************************