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 132b7dc198713ce6d764f58170e093d50dafc5fa
parent acae3736a9595dab4b4606ffef961a7365781743
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu,  6 Feb 2020 14:13:03 +0100

Continue renaming

Diffstat:
Mcmake/CMakeLists.txt | 5+++--
Msrc/senc3d.h | 27++++++++++++++-------------
Msrc/senc3d_descriptor.c | 4++--
Msrc/senc3d_device.c | 14+++++++-------
Msrc/senc3d_enclosure.c | 12++++++------
Msrc/senc3d_enclosure_data.h | 4++--
Dsrc/senc3d_s3d_helper.h | 92-------------------------------------------------------------------------------
Asrc/senc3d_sXd_helper.h | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/senc3d_scene.c | 10+++++-----
Msrc/senc3d_scene_analyze.c | 10+++++-----
Msrc/senc3d_scene_analyze_c.h | 2+-
Msrc/senc3d_scene_c.h | 4++--
Msrc/senc3d_side_range.h | 2+-
Msrc/sencX3d.h | 490++++---------------------------------------------------------------------------
Asrc/sencX3d_undefs.h | 33+++++++++++++++++++++++++++++++++
Msrc/test_senc3d_cube_behind_cube.c | 2+-
Msrc/test_senc3d_cube_in_cube.c | 2+-
Msrc/test_senc3d_cube_on_cube.c | 2+-
Msrc/test_senc3d_device.c | 2+-
Msrc/test_senc3d_enclosure.c | 8++++----
Msrc/test_senc3d_inconsistant_cube.c | 2+-
Msrc/test_senc3d_sample_enclosure.c | 8++++----
Msrc/test_senc3d_scene.c | 2+-
Msrc/test_senc3d_some_enclosures.c | 4++--
Msrc/test_senc3d_some_triangles.c | 4++--
Msrc/test_senc3d_unspecified_medium.c | 6+++---
Msrc/test_senc3d_utils.h | 12++++++------
27 files changed, 223 insertions(+), 632 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -81,8 +81,9 @@ set(SENC3D_FILES_SRC set(SENC3D_FILES_INC_API senc3d.h - senc3d_s3d_helper.h - sencX3d.h) + senc3d_sXd_helper.h + sencX3d.h + sencX3d_undefs.h) set(SENC3D_FILES_INC senc3d_device_c.h diff --git a/src/senc3d.h b/src/senc3d.h @@ -49,20 +49,21 @@ struct logger; struct mem_allocator; -/* Forward declaration of StarEnclosures opaque data types. These data types - * are ref counted. Once created with the appropriated `SENC3D_<TYPE>_create' - * function, the caller implicitly owns the created data, i.e. its reference - * counter is set to 1. The SENC3D_<TYPE>_ref_<get|put> functions get or release - * a reference on the data, i.e. they increment or decrement the reference - * counter, respectively. When this counter reaches 0, the object is silently - * destroyed and cannot be used anymore. */ +/* Forward declaration of star_enclosures-3d opaque data types. These data + * types are ref counted. Once created with the appropriated + * `senc3d__<TYPE>_create' function, the caller implicitly owns the created + * data, i.e. its reference counter is set to 1. + * The senc3d__<TYPE>_ref_<get|put> functions get or release a reference on the + * data, i.e. they increment or decrement the reference counter, respectively. + * When this counter reaches 0, the object is silently destroyed and cannot be + * used anymore. */ struct senc3d_device; struct senc3d_scene; struct senc3d_enclosure; -/******************************************************************************* +/****************************************************************************** * The dimension of the geometry used in the library. - ******************************************************************************/ + *****************************************************************************/ #define SENC3D_GEOMETRY_DIMENSION 3 /* A type to discriminate triangle sides */ @@ -136,7 +137,7 @@ enum senc3d_convention { BEGIN_DECLS /****************************************************************************** - * StarEnclosures device. It is an handle toward the StarEnc library. + * star_enclosures-3d device. It is an handle toward the StarEnc library. * It manages the lib resources. * If provided, the allocator has to be suitable for parallel high frequency * allocations. As a consequence, a rsys proxy allocator should be avoided. @@ -158,8 +159,8 @@ senc3d_device_ref_put (struct senc3d_device* device); /****************************************************************************** - * StarEnclosures scene. A scene is a collection of triangles. Each triangle is - * defined with a medium on each side. + * star_enclosures-3d scene. A scene is a collection of triangles. Each + * triangle is defined with a medium on each side. *****************************************************************************/ /* Creates a scene from some vertices and triangles. * Neither vertices nor triangles can include duplicates. @@ -300,7 +301,7 @@ senc3d_scene_ref_put (struct senc3d_scene* scene); /****************************************************************************** - * StarEnclosures enclosure. It is an handle toward an enclosure. + * star_enclosures-3d enclosure. It is an handle toward an enclosure. * Counts and other information on enclosures are not individually accessible, * but as a whole through header access. * An enclosure can list the "same" triangle twice if both sides are in. In diff --git a/src/senc3d_descriptor.c b/src/senc3d_descriptor.c @@ -21,9 +21,9 @@ #include <rsys/double3.h> #include <rsys/mem_allocator.h> -/******************************************************************************* +/****************************************************************************** * Exported functions - ******************************************************************************/ + *****************************************************************************/ res_T senc3d_scene_get_max_medium (const struct senc3d_scene* scn, unsigned* max_medium_id) diff --git a/src/senc3d_device.c b/src/senc3d_device.c @@ -21,9 +21,9 @@ #include <omp.h> -/******************************************************************************* +/****************************************************************************** * Helper functions - ******************************************************************************/ + *****************************************************************************/ static void log_msg (struct senc3d_device* dev, @@ -48,9 +48,9 @@ device_release(ref_T* ref) MEM_RM(dev->allocator, dev); } -/******************************************************************************* +/****************************************************************************** * Local functions - ******************************************************************************/ + *****************************************************************************/ void log_err(struct senc3d_device* dev, const char* msg, ...) { @@ -84,9 +84,9 @@ log_info(struct senc3d_device* dev, const char* msg, ...) va_end(vargs_list); } -/******************************************************************************* +/****************************************************************************** * Exported functions - ******************************************************************************/ + *****************************************************************************/ res_T senc3d_device_create (struct logger* logger, @@ -108,7 +108,7 @@ senc3d_device_create if(verbose) { /* Do not use helper log functions since dev is not initialised */ CHK(logger_print(log, LOG_ERROR, - "%s: could not allocate the StarEnclosures device.\n", FUNC_NAME) == RES_OK); + "%s: could not allocate the star_enclosures-3d device.\n", FUNC_NAME) == RES_OK); } res = RES_MEM_ERR; goto error; diff --git a/src/senc3d_enclosure.c b/src/senc3d_enclosure.c @@ -24,9 +24,9 @@ #include <rsys/mem_allocator.h> -/******************************************************************************* +/****************************************************************************** * Helper function - ******************************************************************************/ + *****************************************************************************/ static void enclosure_release(ref_T * ref) { @@ -39,9 +39,9 @@ enclosure_release(ref_T * ref) SENC3D(scene_ref_put(scn)); } -/******************************************************************************* +/****************************************************************************** * Local functions - ******************************************************************************/ + *****************************************************************************/ struct senc3d_enclosure* enclosure_create (struct senc3d_scene* scn, @@ -61,9 +61,9 @@ enclosure_create return enc; } -/******************************************************************************* +/****************************************************************************** * Exported functions - ******************************************************************************/ + *****************************************************************************/ res_T senc3d_enclosure_get_header (const struct senc3d_enclosure* enclosure, diff --git a/src/senc3d_enclosure_data.h b/src/senc3d_enclosure_data.h @@ -17,8 +17,8 @@ #define SENC3D_ENCLOSURE_DATA_H #include "senc3d.h" -#include "SENC3D_internal_types.h" -#include "SENC3D_side_range.h" +#include "senc3d_internal_types.h" +#include "senc3d_side_range.h" #include <rsys/rsys.h> #include <rsys/ref_count.h> diff --git a/src/senc3d_s3d_helper.h b/src/senc3d_s3d_helper.h @@ -1,92 +0,0 @@ -/* Copyright (C) |Meso|Star> 2016-2020 (contact@meso-star.com) -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. */ - -#ifndef SENC3D_S3D_WRAPPER_H -#define SENC3D_S3D_WRAPPER_H - -#include "senc3d.h" - -#include <rsys/rsys.h> -#include <rsys/float3.h> - -/* Get vertex indices for the itri_th triangle. - * Suitable for use as get_indice callback in s3d_mesh_setup_indexed_vertices - * calls. */ -static FINLINE void -SENC3D_s3d_scene_get_indices - (const unsigned itri, - unsigned indices[3], - void* ctx) -{ - const struct senc3d_scene* scene = ctx; - res_T r; - ASSERT(indices && scene); - r = senc3d_scene_get_triangle(scene, itri, indices); - ASSERT(r == RES_OK); (void)r; -} - -/* Get coordinates for the ivert_th vertex. - * Suitable for use as s3d_vertex_data getter for S3D_POSITION s3d_attrib_usage - * in s3d_mesh_setup_indexed_vertices calls. */ -static FINLINE void -SENC3D_s3d_scene_get_position - (const unsigned ivert, - float coord[3], - void* ctx) -{ - const struct senc3d_scene* scene = ctx; - double tmp[3]; - res_T r; - ASSERT(coord && scene); - r = senc3d_scene_get_vertex(scene, ivert, tmp); - ASSERT(r == RES_OK); (void)r; - f3_set_d3(coord, tmp); -} - -/* Get vertex indices for the itri_th triangle of the enclosure. - * Suitable for use as get_indice callback in s3d_mesh_setup_indexed_vertices - * calls. */ -static FINLINE void -SENC3D_s3d_enclosure_get_indices - (const unsigned itri, - unsigned indices[3], - void* ctx) -{ - const struct senc3d_enclosure* enclosure = ctx; - res_T r; - ASSERT(indices && ctx); - r = senc3d_enclosure_get_triangle(enclosure, itri, indices); - ASSERT(r == RES_OK); (void)r; -} - -/* Get coordinates for the ivert_th vertex of the enclosure. - * Suitable for use as s3d_vertex_data getter for S3D_POSITION s3d_attrib_usage - * in s3d_mesh_setup_indexed_vertices calls. */ -static FINLINE void -SENC3D_s3d_enclosure_get_position - (const unsigned ivert, - float coord[3], - void* ctx) -{ - const struct senc3d_enclosure* enclosure = ctx; - double tmp[3]; - res_T r; - ASSERT(coord && ctx); - r = senc3d_enclosure_get_vertex(enclosure, ivert, tmp); - ASSERT(r == RES_OK); (void)r; - f3_set_d3(coord, tmp); -} - -#endif /* SENC3D_S3D_WRAPPER_H */ diff --git a/src/senc3d_sXd_helper.h b/src/senc3d_sXd_helper.h @@ -0,0 +1,92 @@ +/* Copyright (C) |Meso|Star> 2016-2020 (contact@meso-star.com) +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SENC3D_S3D_WRAPPER_H +#define SENC3D_S3D_WRAPPER_H + +#include "senc3d.h" + +#include <rsys/rsys.h> +#include <rsys/float3.h> + +/* Get vertex indices for the itri_th triangle. + * Suitable for use as get_indice callback in s3d_mesh_setup_indexed_vertices + * calls. */ +static FINLINE void +senc3d_sXd_scene_get_indices + (const unsigned itri, + unsigned indices[3], + void* ctx) +{ + const struct senc3d_scene* scene = ctx; + res_T r; + ASSERT(indices && scene); + r = senc3d_scene_get_triangle(scene, itri, indices); + ASSERT(r == RES_OK); (void)r; +} + +/* Get coordinates for the ivert_th vertex. + * Suitable for use as s3d_vertex_data getter for S3D_POSITION s3d_attrib_usage + * in s3d_mesh_setup_indexed_vertices calls. */ +static FINLINE void +senc3d_sXd_scene_get_position + (const unsigned ivert, + float coord[3], + void* ctx) +{ + const struct senc3d_scene* scene = ctx; + double tmp[3]; + res_T r; + ASSERT(coord && scene); + r = senc3d_scene_get_vertex(scene, ivert, tmp); + ASSERT(r == RES_OK); (void)r; + f3_set_d3(coord, tmp); +} + +/* Get vertex indices for the itri_th triangle of the enclosure. + * Suitable for use as get_indice callback in s3d_mesh_setup_indexed_vertices + * calls. */ +static FINLINE void +senc3d_sXd_enclosure_get_indices + (const unsigned itri, + unsigned indices[3], + void* ctx) +{ + const struct senc3d_enclosure* enclosure = ctx; + res_T r; + ASSERT(indices && ctx); + r = senc3d_enclosure_get_triangle(enclosure, itri, indices); + ASSERT(r == RES_OK); (void)r; +} + +/* Get coordinates for the ivert_th vertex of the enclosure. + * Suitable for use as s3d_vertex_data getter for S3D_POSITION s3d_attrib_usage + * in s3d_mesh_setup_indexed_vertices calls. */ +static FINLINE void +senc3d_sXd_enclosure_get_position + (const unsigned ivert, + float coord[3], + void* ctx) +{ + const struct senc3d_enclosure* enclosure = ctx; + double tmp[3]; + res_T r; + ASSERT(coord && ctx); + r = senc3d_enclosure_get_vertex(enclosure, ivert, tmp); + ASSERT(r == RES_OK); (void)r; + f3_set_d3(coord, tmp); +} + +#endif /* SENC3D_S3D_WRAPPER_H */ diff --git a/src/senc3d_scene.c b/src/senc3d_scene.c @@ -24,9 +24,9 @@ #include <limits.h> -/******************************************************************************* +/****************************************************************************** * Helper function - ******************************************************************************/ + *****************************************************************************/ static void scene_release(ref_T * ref) { @@ -57,9 +57,9 @@ compatible_medium return (m1 == m2); } -/******************************************************************************* +/****************************************************************************** * Exported functions - ******************************************************************************/ + *****************************************************************************/ res_T senc3d_scene_create (struct senc3d_device* dev, @@ -87,7 +87,7 @@ senc3d_scene_create scn = MEM_CALLOC(dev->allocator, 1, sizeof(struct senc3d_scene)); if(!scn) { - log_err(dev, "%s: could not allocate the StarEnclosures scene.\n", FUNC_NAME); + log_err(dev, "%s: could not allocate the star_enclosures-3d scene.\n", FUNC_NAME); res = RES_MEM_ERR; goto error; } diff --git a/src/senc3d_scene_analyze.c b/src/senc3d_scene_analyze.c @@ -17,7 +17,7 @@ #include "senc3d_device_c.h" #include "senc3d_scene_c.h" #include "senc3d_scene_analyze_c.h" -#include "SENC3D_internal_types.h" +#include "senc3d_internal_types.h" #include <rsys/rsys.h> #include <rsys/float3.h> @@ -53,9 +53,9 @@ const struct cc_descriptor CC_DESCRIPTOR_NULL = CC_DESCRIPTOR_NULL__; #define DARRAY_DATA component_id_t #include <rsys/dynamic_array.h> -/******************************************************************************* +/****************************************************************************** * Helper function - ******************************************************************************/ + *****************************************************************************/ static INLINE int neighbour_cmp(const void* w1, const void* w2) { @@ -1147,9 +1147,9 @@ build_result /* No barrier here */ } -/******************************************************************************* +/****************************************************************************** * Exported functions - ******************************************************************************/ + *****************************************************************************/ res_T scene_analyze (struct senc3d_scene* scn) diff --git a/src/senc3d_scene_analyze_c.h b/src/senc3d_scene_analyze_c.h @@ -16,7 +16,7 @@ #ifndef SENC3D_SCNENE_ANALYZE_C_H #define SENC3D_SCNENE_ANALYZE_C_H -#include "SENC3D_internal_types.h" +#include "senc3d_internal_types.h" #include "senc3d.h" #include <rsys/mem_allocator.h> diff --git a/src/senc3d_scene_c.h b/src/senc3d_scene_c.h @@ -16,9 +16,9 @@ #ifndef SENC3D_SCENE_C_H #define SENC3D_SCENE_C_H -#include "SENC3D_internal_types.h" +#include "senc3d_internal_types.h" #include "senc3d_enclosure_data.h" -#include "SENC3D_side_range.h" +#include "senc3d_side_range.h" #include "senc3d.h" #include <rsys/ref_count.h> diff --git a/src/senc3d_side_range.h b/src/senc3d_side_range.h @@ -16,7 +16,7 @@ #ifndef SENC3D_SIDE_RANGE_H #define SENC3D_SIDE_RANGE_H -#include "SENC3D_internal_types.h" +#include "senc3d_internal_types.h" #include <rsys/dynamic_array.h> diff --git a/src/sencX3d.h b/src/sencX3d.h @@ -13,476 +13,32 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SENC3D_X_3D_H -#define SENC3D_X_3D_H +#ifndef SENC_X_3D_H +#define SENC_X_3D_H -#include <star/senc3d.h> -#include <star/SENC3D_s3d_helper.h> -#include <rsys/rsys.h> - -/* This file can be used in conjunction with sencX2.h from the the - * star-enclosures-2D library to write code for both 2D and 3D geometries using - * the following pattern: - * - * #if (DIM==2) - * #include <star/sencX2.h> - * #elif (DIM==3) - * #include <star/sencX3d.h> - * #else - * #error DIM should be defined; possible values are 2 and 3 - * #endif - * - * Then use the sencX_... types and functions in your code. - * - * Definitions from sencX2.h and sencX3d.h cannot be visible at the same time - * as some of them conflict. - */ - -/* Helper macro that asserts if the invocation of the StarEnclosures function - * `Func' returns an error. One should use this macro on StarEnc function calls - * for which no explicit error checking is performed. */ -#ifndef NDEBUG -#define SENCX(Func) ASSERT(sencX_ ## Func == RES_OK) -#else -#define SENCX(Func) sencX_ ## Func +#if !defined(SENCXD_DIM) || (SENCXD_DIM != 2 && SENCXD_DIM != 3) +#error "SENCXD_DIM must be defined; admissible values are 2 and 3" #endif -/* Forward declaration of external opaque data types */ -struct logger; -struct mem_allocator; - -/* Forward declaration of StarEnclosures opaque data types. These data types - * are ref counted. Once created with the appropriated `SENC3D_<TYPE>_create' - * function, the caller implicitly owns the created data, i.e. its reference - * counter is set to 1. The SENC3D_<TYPE>_ref_<get|put> functions get or release - * a reference on the data, i.e. they increment or decrement the reference - * counter, respectively. When this counter reaches 0, the object is silently - * destroyed and cannot be used anymore. */ -typedef struct senc3d_device sencX_device; -typedef struct senc3d_scene sencX_scene; -typedef struct senc3d_enclosure sencX_enclosure; - -/******************************************************************************* - * The dimension of the geometry used in the library. - ******************************************************************************/ -#define SENCX_GEOMETRY_DIMENSION SENC3D_GEOMETRY_DIMENSION - -/* A type to discriminate triangle sides */ -enum sencX_side { - SENCX_FRONT = SENC3D_FRONT, - SENCX_BACK = SENC3D_BACK -}; - -/* Enclosure header type */ -typedef struct senc3d_enclosure_header sencX_enclosure_header; - -/* We consider the geometrical normal Ng to a triangle V0 V1 V2 - * that verifies "(V0, V0V1, V0V2, Ng) is a direct system" - * (right-handed system). - * - * The user can set the convention used to determine which side of - * a triangle is to be considered front/back by using the flags : - * SENC3D_CONVENTION_NORMAL_FRONT => Ng points toward the front side, - * SENC3D_CONVENTION_NORMAL_BACK => Ng points toward the back side. - * - * Additionaly the user can set the convention used to output enclosures - * so that Ng points toward the enclosure or on the opposite direction - * (for a closed enclosure Ng points toward the inside or toward the outside) - * by using the flags : - * SENC3D_CONVENTION_NORMAL_INSIDE => Ng points toward the enclosure, - * SENC3D_CONVENTION_NORMAL_OUTSIDE => Ng points to the opposite of the enclosure. - * - * Note that normals in output data can be opposite to normals in input data - * (vertices are then given in reverse order). - * - * Also note that both sides of a triangle can be part of the same enclosure; - * in this case the 2 sides will be given with opposite Ng (meaning they - * will be given with opposite vertices order). - */ -enum sencX_convention { - /* - * Convention regarding FRONT/BACK sides in input data - */ - - /* Geometrical normals point toward the front side */ - SENCX_CONVENTION_NORMAL_FRONT = SENC3D_CONVENTION_NORMAL_FRONT, - /* Geometrical normals point toward the back side */ - SENCX_CONVENTION_NORMAL_BACK = SENC3D_CONVENTION_NORMAL_BACK, - - /* - * Convention regarding geometrical normals in output data - */ - - /* Geometrical normals point toward the enclosure */ - SENCX_CONVENTION_NORMAL_INSIDE = SENC3D_CONVENTION_NORMAL_INSIDE, - /* Geometrical normals point to the opposite of the enclosure */ - SENCX_CONVENTION_NORMAL_OUTSIDE = SENC3D_CONVENTION_NORMAL_OUTSIDE -}; - -/****************************************************************************** - * The value that should be used to let media unspecified. - *****************************************************************************/ -#define SENCX_UNSPECIFIED_MEDIUM SENC3D_UNSPECIFIED_MEDIUM - -BEGIN_DECLS - -/****************************************************************************** - * StarEnclosures device. It is an handle toward the StarEnc library. - * It manages the lib resources. - * If provided, the allocator has to be suitable for parallel high frequency - * allocations. As a consequence, a rsys proxy allocator should be avoided. - *****************************************************************************/ -static FINLINE res_T -sencX_device_create - (struct logger* logger, /* May be NULL <=> use default logger */ - struct mem_allocator* allocator, /* May be NULL <=> use default allocator */ - const unsigned nthreads_hint, - const int verbose, - sencX_device** device) -{ - return senc3d_device_create(logger, allocator, nthreads_hint, verbose, device); -} - -static FINLINE res_T -sencX_device_ref_get - (sencX_device* device) -{ - return senc3d_device_ref_get(device); -} - -static FINLINE res_T -sencX_device_ref_put - (sencX_device* device) -{ - return senc3d_device_ref_put(device); -} - -/****************************************************************************** - * StarEnclosures scene. A scene is a collection of triangles. Each triangle is - * defined with a medium on each side. - *****************************************************************************/ -/* Creates a scene from some vertices and triangles. - * Neither vertices nor triangles can include duplicates. - * Triangles cannot be degenerated. */ -static FINLINE res_T -sencX_scene_create - (sencX_device* device, - const int convention, - /* Number of triangles */ - const unsigned triangles_count, - /* User function that provides vertices ids for triangles */ - void(*get_indices)( - const unsigned itri, - unsigned ids[SENCX_GEOMETRY_DIMENSION], - void* context), - /* User function that provides media ids for triangles */ - void(*get_media) /* Can be NULL <=> SENC3D_UNSPECIFIED_MEDIUM medium used */ - (const unsigned itri, unsigned med[2], void* context), - /* Number of vertices */ - const unsigned vertices_count, - /* User function that provides coordinates for vertices */ - void(*get_position)( - const unsigned ivert, - double pos[SENCX_GEOMETRY_DIMENSION], - void* context), - /* Context provided to user callbacks; can be NULL */ - void* context, - /* The created scene */ - sencX_scene** scene) -{ - return senc3d_scene_create(device, convention, triangles_count, get_indices, - get_media, vertices_count, get_position, context, scene); -} - -/* Returns the convention flags in use with the scene. */ -static FINLINE res_T -sencX_scene_get_convention - (const sencX_scene* scene, - int* convention) -{ - return senc3d_scene_get_convention(scene, convention); -} - -/* Returns the number of triangles in the scene. */ -static FINLINE res_T -sencX_scene_get_primitives_count - (const sencX_scene* scene, - unsigned* count) -{ - return senc3d_scene_get_triangles_count(scene, count); -} - -/* Returns the itri_th triangle vertices' indices. */ -static FINLINE res_T -sencX_scene_get_primitive - (const sencX_scene* scene, - const unsigned itri, - unsigned indices[SENCX_GEOMETRY_DIMENSION]) -{ - return senc3d_scene_get_triangle(scene, itri, indices); -} - -/* Returns the media for the itri_th triangle. */ -static FINLINE res_T -sencX_scene_get_primitive_media - (const sencX_scene* scene, - const unsigned itri, - unsigned media[2]) -{ - return senc3d_scene_get_triangle_media(scene, itri, media); -} - -/* Returns the number of vertices in the scene. */ -static FINLINE res_T -sencX_scene_get_vertices_count - (const sencX_scene* scene, - unsigned* count) -{ - return senc3d_scene_get_vertices_count(scene, count); -} - -/* Returns the coordinates of the ivert_th vertex. */ -static FINLINE res_T -sencX_scene_get_vertex - (const sencX_scene* scene, - const unsigned ivert, - double coord[SENCX_GEOMETRY_DIMENSION]) -{ - return senc3d_scene_get_vertex(scene, ivert, coord); -} - -/* Returns the greater medium id found in added geometry. In API calls using a - * medium, any value in the [0 max_medium_id[ range is valid. However there can - * be unused ids (no geometry refered to this medium id). */ -static FINLINE res_T -sencX_scene_get_max_medium - (const sencX_scene* scene, - unsigned* max_medium_id) -{ - return senc3d_scene_get_max_medium(scene, max_medium_id); -} - -/* Returns the number of enclosures. */ -static FINLINE res_T -sencX_scene_get_enclosure_count - (const sencX_scene* scene, - unsigned* count) -{ - return senc3d_scene_get_enclosure_count(scene, count); -} - -/* Returns the number of enclosures that have some geometry refering to the - * imed_th medium or SENC3D_UNSPECIFIED_MEDIUM. */ -static FINLINE res_T -sencX_scene_get_enclosure_count_by_medium - (const sencX_scene* scene, - const unsigned imed, - unsigned* count) -{ - return senc3d_scene_get_enclosure_count_by_medium(scene, imed, count); -} - -/* Returns the idx_th enclosure. */ -static FINLINE res_T -sencX_scene_get_enclosure - (sencX_scene* scene, - const unsigned idx, - sencX_enclosure** enclosure) -{ - return senc3d_scene_get_enclosure(scene, idx, enclosure); -} - -/* Returns the idx_th enclosure using the imed_th medium or - * SENC3D_UNSPECIFIED_MEDIUM. */ -static FINLINE res_T -sencX_scene_get_enclosure_by_medium - (sencX_scene* scene, - const unsigned imed, - const unsigned idx, - sencX_enclosure** enclosure) -{ - return senc3d_scene_get_enclosure_by_medium(scene, imed, idx, enclosure); -} - -/* Returns the enclosures the itri_th triangle front and back sides are member - * of. */ -static FINLINE res_T -sencX_scene_get_primitive_enclosures - (const sencX_scene* scene, - const unsigned itri, - unsigned enclosures[2]) -{ - return senc3d_scene_get_triangle_enclosures(scene, itri, enclosures); -} - -/* Returns the number of segments that are frontier segments: - * - that have arity 1 (single triangle using the segment) - * - that connect 2 different media */ -static FINLINE res_T -sencX_scene_get_frontier_elements_count - (const sencX_scene* scene, - unsigned* count) -{ - return senc3d_scene_get_frontier_segments_count(scene, count); -} - -/* Returns the iseg_th frontier segment; the returned indices are global vertex - * indices whose coordinates can be retrieved using sencX_scene_get_vertex. */ -static FINLINE res_T -sencX_scene_get_frontier_element - (const sencX_scene* scene, - const unsigned iseg, - unsigned vrtx_id[SENCX_GEOMETRY_DIMENSION-1]) -{ - return senc3d_scene_get_frontier_segment(scene, iseg, vrtx_id); -} - -static FINLINE res_T -sencX_scene_ref_get - (sencX_scene* scene) -{ - return senc3d_scene_ref_get(scene); -} - -static FINLINE res_T -sencX_scene_ref_put - (sencX_scene* scene) -{ - return senc3d_scene_ref_put(scene); -} - -/******************************************************************************* - * StarEnclosures enclosure. It is an handle toward an enclosure. - * Counts and other information on enclosures are not individually accessible, - * but as a whole through header access. - * An enclosure can list the "same" triangle twice if both sides are in. In this - * case the 2 occurences of the triangle have reversed vertices order and - * unique_triangle_count and triangle_count differ. - * Vertices and triangles numbering schemes are specific to each enclosure: - * the "same" item appearing in 2 different enclosures has no reason to get the - * same index twice or to have the same index in the global numbering scheme. - * By-index API accesses of triangles (or properties) visit unique triangles - * for indices in the [0 unique_triangle_count[ range and back-faces of the - * doubly-included triangles in the [unique_triangle_count triangle_count[ range. - ******************************************************************************/ -/* Returns the header of an enclosure. */ -static FINLINE res_T -sencX_enclosure_get_header - (const sencX_enclosure* enclosure, - sencX_enclosure_header* header) -{ - return senc3d_enclosure_get_header(enclosure, header); -} - -/* Returns the itri_th triangle of an enclosure. - * Indices are local to the enclosure. */ -static FINLINE res_T -sencX_enclosure_get_primitive - (const sencX_enclosure* enclosure, - const unsigned itri, - unsigned indices[SENCX_GEOMETRY_DIMENSION]) -{ - return senc3d_enclosure_get_triangle(enclosure, itri, indices); -} - -/* Returns the coordinates of the ivert_th vertex of an enclosure. */ -static FINLINE res_T -sencX_enclosure_get_vertex - (const sencX_enclosure* enclosure, - const unsigned ivert, - double coord[SENCX_GEOMETRY_DIMENSION]) -{ - return senc3d_enclosure_get_vertex(enclosure, ivert, coord); -} - -/* Returns the global id of the itri_th triangle of an enclosure - * and the involved side. */ -static FINLINE res_T -sencX_enclosure_get_primitive_id - (const sencX_enclosure* enclosure, - const unsigned itri, - unsigned* gid, - enum senc3d_side* side) -{ - return senc3d_enclosure_get_triangle_id(enclosure, itri, gid, side); -} - -/* Returns the id of the imed_th medium of an enclosure. */ -static FINLINE res_T -sencX_enclosure_get_medium - (const sencX_enclosure* enclosure, - const unsigned imed, - unsigned* medium) -{ - return senc3d_enclosure_get_medium(enclosure, imed, medium); -} - -static FINLINE res_T -sencX_enclosure_ref_get - (sencX_enclosure* enclosure) -{ - return senc3d_enclosure_ref_get(enclosure); -} - -static FINLINE res_T -sencX_enclosure_ref_put - (sencX_enclosure* enclosure) -{ - return senc3d_enclosure_ref_put(enclosure); -} - -/****************************************************************************** - * StarEnclosuresXD to StarXD helper. - *****************************************************************************/ - - /* Get vertex indices for the iseg_th segment. - * Suitable for use as get_indice callback in s3d_mesh_setup_indexed_vertices - * calls. */ -static FINLINE void -sencX_sXd_scene_get_indices - (const unsigned iseg, - unsigned indices[SENCX_GEOMETRY_DIMENSION], - void* ctx) -{ - SENC3D_s3d_scene_get_indices(iseg, indices, ctx); -} - -/* Get coordinates for the ivert_th vertex. - * Suitable for use as s3d_vertex_data getter for S3D_POSITION s3d_attrib_usage - * in s3d_mesh_setup_indexed_vertices calls. */ -static FINLINE void -sencX_sXd_scene_get_position - (const unsigned ivert, - float coord[SENCX_GEOMETRY_DIMENSION], - void* ctx) -{ - SENC3D_s3d_scene_get_position(ivert, coord, ctx); -} - -/* Get vertex indices for the iseg_th segment of the enclosure. - * Suitable for use as get_indice callback in s3d_mesh_setup_indexed_vertices - * calls. */ -static FINLINE void -sencX_sXd_enclosure_get_indices - (const unsigned iseg, - unsigned indices[SENCX_GEOMETRY_DIMENSION], - void* ctx) -{ - SENC3D_s3d_enclosure_get_indices(iseg, indices, ctx); -} +#include <star/senc3d.h> -/* Get coordinates for the ivert_th vertex of the enclosure. - * Suitable for use as s3d_vertex_data getter for S3D_POSITION s3d_attrib_usage - * in s3d_mesh_setup_indexed_vertices calls. */ -static FINLINE void -sencX_sXd_enclosure_get_position - (const unsigned ivert, - float coord[SENCX_GEOMETRY_DIMENSION], - void* ctx) -{ - SENC3D_s3d_enclosure_get_position(ivert, coord, ctx); -} +/* Star-enclosures-XD macros generic to the SENCXD_DIM */ +#ifndef SENCXD +#define SENCXD CONCAT(CONCAT(SENC, SENCXD_DIM), D) +#endif +#ifndef sencXd +#define sencXd(Name) CONCAT(CONCAT(CONCAT(senc, SENCXD_DIM), d_), Name) +#endif +#ifndef SENCXD_ +#define SENCXD_(Name) CONCAT(CONCAT(CONCAT(SENC, SENCXD_DIM), D_), Name) +#endif -END_DECLS +/* Function names that require additional dedicated macros */ +#define senc3d_scene_get_primitives_count senc3d_scene_get_triangles_count +#define senc3d_scene_get_primitive senc3d_scene_get_triangle +#define senc3d_scene_get_primitive_media senc3d_scene_get_triangle_media +#define senc3d_scene_get_primitive_enclosures senc3d_scene_get_triangle_enclosures +#define senc3d_enclosure_get_primitive senc3d_enclosure_get_triangle +#define senc3d_enclosure_get_primitive_id senc3d_enclosure_get_triangle_id -#endif /* SENC3D_X_3D_H */ +#endif /* SENC_X_3D_H */ diff --git a/src/sencX3d_undefs.h b/src/sencX3d_undefs.h @@ -0,0 +1,33 @@ +/* Copyright (C) |Meso|Star> 2016-2020 (contact@meso-star.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SENC_X_3D_H +#error "The sencX3d.h file must be included priorly to this file." +#endif + + /* Star-enclosures-XD macros generic to the SENCXD_DIM */ +#undef SENCXD +#undef sencXd +#undef SENCXD_ + +/* Function names that require additional dedicated macros */ +#undef senc3d_scene_get_primitives_count +#undef senc3d_scene_get_primitive +#undef senc3d_scene_get_primitive_media +#undef senc3d_scene_get_primitive_enclosures +#undef senc3d_enclosure_get_primitive +#undef senc3d_enclosure_get_primitive_id + +#undef SENC_X_3D_H diff --git a/src/test_senc3d_cube_behind_cube.c b/src/test_senc3d_cube_behind_cube.c @@ -17,7 +17,7 @@ * of star-geometry. It uses output from test_sg3_cube_behind_cube. */ #include "senc3d.h" -#include "test_SENC3D_utils.h" +#include "test_senc3d_utils.h" #include <rsys/double3.h> diff --git a/src/test_senc3d_cube_in_cube.c b/src/test_senc3d_cube_in_cube.c @@ -17,7 +17,7 @@ * of star-geometry. It uses output from test_sg3_cube_in_cube. */ #include "senc3d.h" -#include "test_SENC3D_utils.h" +#include "test_senc3d_utils.h" #include <rsys/double3.h> diff --git a/src/test_senc3d_cube_on_cube.c b/src/test_senc3d_cube_on_cube.c @@ -19,7 +19,7 @@ #define _POSIX_C_SOURCE 200112L /* snprintf */ #include "senc3d.h" -#include "test_SENC3D_utils.h" +#include "test_senc3d_utils.h" #include <rsys/double3.h> diff --git a/src/test_senc3d_device.c b/src/test_senc3d_device.c @@ -14,7 +14,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "senc3d.h" -#include "test_SENC3D_utils.h" +#include "test_senc3d_utils.h" #include <rsys/logger.h> diff --git a/src/test_senc3d_enclosure.c b/src/test_senc3d_enclosure.c @@ -14,8 +14,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "senc3d.h" -#include "SENC3D_s3d_helper.h" -#include "test_SENC3D_utils.h" +#include "senc3d_sXd_helper.h" +#include "test_senc3d_utils.h" #include <rsys/double3.h> @@ -215,12 +215,12 @@ test(const int convention) /* Put geometry in a 3D view using helper functions */ s3d_attribs.type = S3D_FLOAT3; s3d_attribs.usage = S3D_POSITION; - s3d_attribs.get = SENC3D_s3d_enclosure_get_position; + s3d_attribs.get = senc3d_sXd_enclosure_get_position; OK(s3d_device_create(NULL, &allocator, 0, &s3d)); OK(s3d_scene_create(s3d, &s3d_scn)); OK(s3d_shape_create_mesh(s3d, &s3d_shp)); OK(s3d_mesh_setup_indexed_vertices(s3d_shp, header.primitives_count, - SENC3D_s3d_enclosure_get_indices, header.vertices_count, &s3d_attribs, + senc3d_sXd_enclosure_get_indices, header.vertices_count, &s3d_attribs, 1, enclosure)); OK(s3d_scene_attach_shape(s3d_scn, s3d_shp)); S3D(shape_ref_put(s3d_shp)); diff --git a/src/test_senc3d_inconsistant_cube.c b/src/test_senc3d_inconsistant_cube.c @@ -14,7 +14,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "senc3d.h" -#include "test_SENC3D_utils.h" +#include "test_senc3d_utils.h" #include <rsys/double3.h> diff --git a/src/test_senc3d_sample_enclosure.c b/src/test_senc3d_sample_enclosure.c @@ -14,8 +14,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "senc3d.h" -#include "SENC3D_s3d_helper.h" -#include "test_SENC3D_utils.h" +#include "senc3d_sXd_helper.h" +#include "test_senc3d_utils.h" #include <rsys/float3.h> #include <rsys/double3.h> @@ -64,12 +64,12 @@ main(int argc, char** argv) /* Put enclosure in a 3D view... */ vrtx_get.type = S3D_FLOAT3; vrtx_get.usage = S3D_POSITION; - vrtx_get.get = SENC3D_s3d_enclosure_get_position; + vrtx_get.get = senc3d_sXd_enclosure_get_position; S3D(device_create(NULL, &allocator, 0, &s3d)); S3D(scene_create(s3d, &s3d_scn)); S3D(shape_create_mesh(s3d, &s3d_shp)); S3D(mesh_setup_indexed_vertices(s3d_shp, header.primitives_count, - SENC3D_s3d_enclosure_get_indices, header.vertices_count, &vrtx_get, 1, + senc3d_sXd_enclosure_get_indices, header.vertices_count, &vrtx_get, 1, enclosure)); S3D(scene_attach_shape(s3d_scn, s3d_shp)); S3D(scene_view_create(s3d_scn, S3D_SAMPLE, &s3d_view)); diff --git a/src/test_senc3d_scene.c b/src/test_senc3d_scene.c @@ -14,7 +14,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "senc3d.h" -#include "test_SENC3D_utils.h" +#include "test_senc3d_utils.h" #include <rsys/float3.h> #include <rsys/double3.h> diff --git a/src/test_senc3d_some_enclosures.c b/src/test_senc3d_some_enclosures.c @@ -15,11 +15,11 @@ /* This test has been created using the sg3_geometry_dump_as_C_code feature * of star-geometry. It uses output from test_sg3_some_enclosures. - * This test is similar to test_SENC3D_many_enclosures that creates a huge + * This test is similar to test_senc3d_many_enclosures that creates a huge * geometry by program. */ #include "senc3d.h" -#include "test_SENC3D_utils.h" +#include "test_senc3d_utils.h" #include <rsys/double3.h> diff --git a/src/test_senc3d_some_triangles.c b/src/test_senc3d_some_triangles.c @@ -15,11 +15,11 @@ /* This test has been created using the sg3_geometry_dump_as_C_code feature * of star-geometry. It uses output from test_sg3_some_triangles. - * This test is similar to test_SENC3D_many_triangles that creates a huge + * This test is similar to test_senc3d_many_triangles that creates a huge * geometry by program. */ #include "senc3d.h" -#include "test_SENC3D_utils.h" +#include "test_senc3d_utils.h" #include <rsys/double3.h> diff --git a/src/test_senc3d_unspecified_medium.c b/src/test_senc3d_unspecified_medium.c @@ -15,12 +15,12 @@ /* This test has been created using the sg3_geometry_dump_as_C_code feature * of star-geometry. It uses output from test_sg3_unspecified_properties. - * This test is similar to test_SENC3D_many_enclosures that creates a huge + * This test is similar to test_senc3d_many_enclosures that creates a huge * geometry by program. */ #include "senc3d.h" -#include "SENC3D_s3d_helper.h" -#include "test_SENC3D_utils.h" +#include "senc3d_sXd_helper.h" +#include "test_senc3d_utils.h" #include <rsys/double3.h> diff --git a/src/test_senc3d_utils.h b/src/test_senc3d_utils.h @@ -25,9 +25,9 @@ #define OK(Expr) CHK((Expr) == RES_OK) #define BA(Expr) CHK((Expr) == RES_BAD_ARG) -/******************************************************************************* +/****************************************************************************** * Geometry - ******************************************************************************/ + *****************************************************************************/ /* Distorded cube */ static const double box_vertices[8/*#vertices*/*3/*#coords per vertex*/] = { 0.1, 0.0, 0.0, @@ -136,9 +136,9 @@ get_media_from_properties(const unsigned itri, unsigned medium[2], void* context medium[ctx->reverse_med ? 0 : 1] = ctx->properties[3 * itri + 1]; } -/******************************************************************************* +/****************************************************************************** * Miscellaneous - ******************************************************************************/ + *****************************************************************************/ static INLINE void dump_global (struct senc3d_scene* scn, @@ -214,9 +214,9 @@ check_memory_allocator(struct mem_allocator* allocator) } } -/******************************************************************************* +/****************************************************************************** * Check functions - ******************************************************************************/ + *****************************************************************************/ /* Compare the itri-th triangle of enclosure with a triangle described by trg2 & vertices2 */ static INLINE void cmp_trg