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 8938737e7fccbaa3fda6f5261a674c99cc887576
parent 4f82a8098ed4f2a99d0eeb4369b28a491f276b2f
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu, 20 Aug 2020 14:21:50 +0200

Add media count to components

Diffstat:
Msrc/senc3d_enclosure_data.h | 3+++
Msrc/senc3d_scene_analyze.c | 16+++++++++++-----
Msrc/senc3d_scene_analyze_c.h | 5+++--
3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/senc3d_enclosure_data.h b/src/senc3d_enclosure_data.h @@ -79,11 +79,13 @@ static FINLINE res_T bool_array_of_media_merge (struct darray_uchar* dst, const uchar* src, + const unsigned count, const size_t sz) { res_T res = RES_OK; size_t i; uchar* data_dst; + unsigned c = 0; ASSERT(src && dst); @@ -92,6 +94,7 @@ bool_array_of_media_merge FOR_EACH(i, 0, sz) { if(!src[i]) continue; data_dst[i] = 1; + if(++c == count) break; } end: return res; diff --git a/src/senc3d_scene_analyze.c b/src/senc3d_scene_analyze.c @@ -38,10 +38,10 @@ #include <stdlib.h> #define CC_DESCRIPTOR_NULL__ {\ - 0, 0, INT_MAX, VRTX_NULL__, 0,\ + 0, 0, NULL,\ + 0, INT_MAX, VRTX_NULL__, 0,\ CC_ID_NONE, CC_GROUP_ROOT_NONE, ENCLOSURE_NULL__,\ - { TRG_NULL__, 0},\ - NULL\ + { TRG_NULL__, 0}\ } #ifdef COMPILER_GCC #pragma GCC diagnostic push @@ -459,6 +459,7 @@ extract_connex_components side_id_t cc_last_side_id = crt_side_id; vrtx_id_t max_z_vrtx_id = VRTX_NULL__; struct cc_descriptor *cc; + unsigned media_count; double max_z = -DBL_MAX; component_canceled = 0; ASSERT(crt_side_id == SIDE_NULL__ || crt_side_id < 2 * scn->ntris); @@ -491,6 +492,7 @@ extract_connex_components } } current_media[m_idx] = 1; + media_count = 1; for(;;) { /* Process all sides of this component */ int i; enum side_flag crt_side_flag = TRGSIDE_2_SIDEFLAG(crt_side_id); @@ -570,7 +572,10 @@ extract_connex_components *nbour_used |= (uchar)nbour_side_id; OK2(darray_side_id_push_back(&stack, &neighbour_id)); OK2(darray_side_id_push_back(&current_component, &neighbour_id)); - current_media[nbour_med_idx] = 1; + if(!current_media[nbour_med_idx]) { + current_media[nbour_med_idx] = 1; + media_count++; + } } sz = darray_side_id_size_get(&stack); if(sz == 0) break; /* Empty stack => component is done! */ @@ -601,6 +606,7 @@ extract_connex_components /* Tranfer ownership of the array to component */ ASSERT(!cc->media && current_media); cc->media = current_media; + cc->media_count = media_count; current_media = NULL; /* Write component membership in the global structure @@ -1001,7 +1007,7 @@ group_connex_components enc->side_range.last = MMAX(enc->side_range.last, cc->side_range.last); enc->side_count += cc->side_count; tmp_res = bool_array_of_media_merge(&enc->tmp_enclosed_media, cc->media, - darray_side_range_size_get(&scn->media_use)); + cc->media_count, darray_side_range_size_get(&scn->media_use)); if(tmp_res != RES_OK) { *res = tmp_res; break; diff --git a/src/senc3d_scene_analyze_c.h b/src/senc3d_scene_analyze_c.h @@ -47,6 +47,9 @@ struct cc_descriptor { double _2area; /* Six times the signed volume of the component */ double _6volume; + /* Media used by this component */ + uchar* media; + unsigned media_count; /* Does this component is an outer border of an enclosure or an inner one? */ int is_outer_border; vrtx_id_t max_z_vrtx_id; /* id of the vrtx with max z value */ @@ -57,8 +60,6 @@ struct cc_descriptor { enclosure_id_t enclosure_id; /* Range of sides member of this component */ struct side_range side_range; - /* Media used by this component */ - uchar* media; }; extern const struct cc_descriptor CC_DESCRIPTOR_NULL;