star-geometry-3d

Clean and decorate 3D geometries
git clone git://git.meso-star.fr/star-geometry-3d.git
Log | Files | Refs | README | LICENSE

commit 692675671f2caec8c4a968f07e1997a6a6eb99f2
parent 29afe82d8167ae8d49ed31fea228c1951a6b0429
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu,  6 Feb 2020 14:00:02 +0100

Continue renaming

Diffstat:
MREADME.md | 4++--
Mcmake/CMakeLists.txt | 5+++--
Msrc/sg3d.h | 6+++---
Dsrc/sg3d_s3d_helper.h | 61-------------------------------------------------------------
Asrc/sg3d_sXd_helper.h | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/sg3d_sencXd_helper.h | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/sg3d_senc_helper.h | 76----------------------------------------------------------------------------
Msrc/sgX3d.h | 500+++++--------------------------------------------------------------------------
Asrc/sgX3d_undefs.h | 35+++++++++++++++++++++++++++++++++++
9 files changed, 210 insertions(+), 614 deletions(-)

diff --git a/README.md b/README.md @@ -38,8 +38,8 @@ First version and implementation of the star-geometry-3d API. License ------- -Copyright (C) 2019-2020 |Meso|Star> +Star-geometry-3d is Copyright (C) 2019-2020 |Meso|Star> (<a href="mailto:contact@meso-star.com" class="email">contact@meso-star.com</a>). -Stardis is free software released under the GPLv3+ license: GNU GPL +Itis free software released under the GPLv3+ license: GNU GPL version 3 or later. You are welcome to redistribute it under certain conditions; refer to the COPYING files for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -71,9 +71,10 @@ set(SG3D_FILES_SRC set(SG3D_FILES_INC_API sg3d.h - sg3d_s3d_helper.h - sg3d_senc_helper.h + sg3d_sXd_helper.h + sg3d_sencXd_helper.h sgX3d.h + sgX3d_undefs.h ) set(SG3D_FILES_INC diff --git a/src/sg3d.h b/src/sg3d.h @@ -46,7 +46,7 @@ struct senc_scene; /* Forward declaration of the star-geometry opaque data types. These data * types are ref counted. Once created the caller implicitly owns the created - * data, i.e. its reference counter is set to 1. The sdis_<TYPE>_ref_<get|put> + * data, i.e. its reference counter is set to 1. The sg3d_<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. */ @@ -358,8 +358,8 @@ sg3d_geometry_dump_as_obj * - Interface (interface ID, INT_MAX for both unspecified and conflicted) * - Merge_conflict (merge conflict status) * - Property_conflict (property conflict status) - * - Created_at_sg3d_geometry_add (rank of the sg3d_geometry_add that created the - * triangle) */ + * - Created_at_sg3d_geometry_add (rank of the sg3d_geometry_add that created + * the triangle) */ SG3D_API res_T sg3d_geometry_dump_as_vtk (const struct sg3d_geometry* geometry, diff --git a/src/sg3d_s3d_helper.h b/src/sg3d_s3d_helper.h @@ -1,61 +0,0 @@ -/* Copyright (C) 2019-2020 |Meso|Star> (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 SG3D_SENC_3D_HELPER_H__ -#define SG3D_SENC_3D_HELPER_H__ - -#include "sg3d.h" -#include <star/senc.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 -sg3d_s3d_geometry_get_indices - (const unsigned itri, - unsigned indices[SG3D_GEOMETRY_DIMENSION], - void* ctx) -{ - const struct sg3d_geometry* geometry = ctx; - res_T r; - ASSERT(indices && geometry); - r = sg3d_geometry_get_unique_triangle_vertices(geometry, 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 -sg3d_s3d_geometry_get_position - (const unsigned ivert, - float coord[SG3D_GEOMETRY_DIMENSION], - void* ctx) -{ - const struct sg3d_geometry* geometry = ctx; - double tmp[3]; - res_T r; - ASSERT(coord && geometry); - r = sg3d_geometry_get_unique_vertex(geometry, ivert, tmp); - ASSERT(r == RES_OK); (void)r; - f3_set_d3(coord, tmp); -} - -END_DECLS - -#endif /* SG3D_SENC_3D_HELPER_H__ */ diff --git a/src/sg3d_sXd_helper.h b/src/sg3d_sXd_helper.h @@ -0,0 +1,61 @@ +/* Copyright (C) 2019-2020 |Meso|Star> (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 SG3D_S3D_HELPER_H__ +#define SG3D_S3D_HELPER_H__ + +#include "sg3d.h" +#include <star/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 +sg3d_sXd_geometry_get_indices + (const unsigned itri, + unsigned indices[SG3D_GEOMETRY_DIMENSION], + void* ctx) +{ + const struct sg3d_geometry* geometry = ctx; + res_T r; + ASSERT(indices && geometry); + r = sg3d_geometry_get_unique_triangle_vertices(geometry, 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 +sg3d_sXd_geometry_get_position + (const unsigned ivert, + float coord[SG3D_GEOMETRY_DIMENSION], + void* ctx) +{ + const struct sg3d_geometry* geometry = ctx; + double tmp[3]; + res_T r; + ASSERT(coord && geometry); + r = sg3d_geometry_get_unique_vertex(geometry, ivert, tmp); + ASSERT(r == RES_OK); (void)r; + f3_set_d3(coord, tmp); +} + +END_DECLS + +#endif /* SG3D_S3D_HELPER_H__ */ diff --git a/src/sg3d_sencXd_helper.h b/src/sg3d_sencXd_helper.h @@ -0,0 +1,76 @@ +/* Copyright (C) 2019-2020 |Meso|Star> (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 SG3D_SENC3D_HELPER_H__ +#define SG3D_SENC3D_HELPER_H__ + +#include "sg3d.h" +#include <star/senc3d.h> + +#include <rsys/rsys.h> + +/* Get vertex indices for the itri_th triangle. + * Suitable for use as get_indices callback in senc_scene_create calls. */ +static FINLINE void +sg3d_sencXd_geometry_get_indices + (const unsigned itri, + unsigned indices[SG3D_GEOMETRY_DIMENSION], + void* ctx) +{ + const struct sg3d_geometry* geometry = ctx; + res_T r; + ASSERT(indices && geometry); + r = sg3d_geometry_get_unique_triangle_vertices(geometry, itri, indices); + ASSERT(r == RES_OK); (void)r; +} + +/* Get vertex indices for the itri_th triangle. + * Suitable for use as get_media callback in senc_scene_create calls. */ +static FINLINE void +sg3d_sencXd_geometry_get_media + (const unsigned itri, + unsigned media[2], + void* ctx) +{ + const struct sg3d_geometry* geometry = ctx; + unsigned tmp[SG3D_PROP_TYPES_COUNT__]; + res_T r; + ASSERT(media && geometry); + r = sg3d_geometry_get_unique_triangle_properties(geometry, itri, tmp); + ASSERT(r == RES_OK); (void)r; + media[SENC3D_FRONT] = (tmp[SG3D_FRONT] == SG3D_UNSPECIFIED_PROPERTY) + ? SENC3D_UNSPECIFIED_MEDIUM : tmp[SG3D_FRONT]; + media[SENC3D_BACK] = (tmp[SG3D_BACK] == SG3D_UNSPECIFIED_PROPERTY) + ? SENC3D_UNSPECIFIED_MEDIUM : tmp[SG3D_BACK]; +} + +/* Get vertex indices for the itri_th triangle. + * Suitable for use as get_position callback in senc_scene_create calls. */ +static FINLINE void +sg3d_sencXd_geometry_get_position + (const unsigned ivert, + double coord[SG3D_GEOMETRY_DIMENSION], + void* ctx) +{ + const struct sg3d_geometry* geometry = ctx; + res_T r; + ASSERT(coord && geometry); + r = sg3d_geometry_get_unique_vertex(geometry, ivert, coord); + ASSERT(r == RES_OK); (void)r; +} + +END_DECLS + +#endif /* SG2_SENC3D_HELPER_H__ */ diff --git a/src/sg3d_senc_helper.h b/src/sg3d_senc_helper.h @@ -1,76 +0,0 @@ -/* Copyright (C) 2019-2020 |Meso|Star> (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 SG3D_SENC_3D_HELPER_H__ -#define SG3D_SENC_3D_HELPER_H__ - -#include "sg3d.h" -#include <star/senc.h> - -#include <rsys/rsys.h> - -/* Get vertex indices for the itri_th triangle. - * Suitable for use as get_indices callback in senc_scene_create calls. */ -static FINLINE void -sg3d_senc_geometry_get_indices - (const unsigned itri, - unsigned indices[SG3D_GEOMETRY_DIMENSION], - void* ctx) -{ - const struct sg3d_geometry* geometry = ctx; - res_T r; - ASSERT(indices && geometry); - r = sg3d_geometry_get_unique_triangle_vertices(geometry, itri, indices); - ASSERT(r == RES_OK); (void)r; -} - -/* Get vertex indices for the itri_th triangle. - * Suitable for use as get_media callback in senc_scene_create calls. */ -static FINLINE void -sg3d_senc_geometry_get_media - (const unsigned itri, - unsigned media[2], - void* ctx) -{ - const struct sg3d_geometry* geometry = ctx; - unsigned tmp[SG3D_PROP_TYPES_COUNT__]; - res_T r; - ASSERT(media && geometry); - r = sg3d_geometry_get_unique_triangle_properties(geometry, itri, tmp); - ASSERT(r == RES_OK); (void)r; - media[SENC_FRONT] = (tmp[SG3D_FRONT] == SG3D_UNSPECIFIED_PROPERTY) - ? SENC_UNSPECIFIED_MEDIUM : tmp[SG3D_FRONT]; - media[SENC_BACK] = (tmp[SG3D_BACK] == SG3D_UNSPECIFIED_PROPERTY) - ? SENC_UNSPECIFIED_MEDIUM : tmp[SG3D_BACK]; -} - -/* Get vertex indices for the itri_th triangle. - * Suitable for use as get_position callback in senc_scene_create calls. */ -static FINLINE void -sg3d_senc_geometry_get_position - (const unsigned ivert, - double coord[SG3D_GEOMETRY_DIMENSION], - void* ctx) -{ - const struct sg3d_geometry* geometry = ctx; - res_T r; - ASSERT(coord && geometry); - r = sg3d_geometry_get_unique_vertex(geometry, ivert, coord); - ASSERT(r == RES_OK); (void)r; -} - -END_DECLS - -#endif /* SG2_SENC_3D_HELPER_H__ */ diff --git a/src/sgX3d.h b/src/sgX3d.h @@ -16,479 +16,39 @@ #ifndef STAR_GEOMETRY3D_X_H__ #define STAR_GEOMETRY3D_X_H__ -#include <star/sg3d.h> -#include <star/sg3d_senc_helper.h> -#include <star/sg3d_s3d_helper.h> -#include <rsys/rsys.h> - -#include <stdio.h> - -/* This file can be used in conjunction with sgX2.h from the the - * star-geometry-2D library to write code for both 2D and 3D geometries using - * the following pattern: - * - * #if (DIM==2) - * #include <star/sgX2d.h> - * #elif (DIM==3) - * #include <star/sgX3d.h> - * #else - * #error DIM should be defined; possible values are 2 and 3 - * #endif - * - * Then use the sgXd_... types and functions in your code. - * - * Definitions from sgX2d.h and sgX3d.h cannot be visible at the same time - * as some of them conflict. - */ - -/* Helper macro that asserts if the invocation of the StarGeometry 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 SGXD(Func) ASSERT(sgXd_ ## Func == RES_OK) -#else -#define SGXD(Func) sgXd_ ## Func +#if !defined(SGXD_DIM) || (SGXD_DIM != 2 && SGXD_DIM != 3) +#error "SGXD_DIM must be defined; admissible values are 2 and 3" #endif -/* Forward declaration of the star-geometry opaque data types. These data - * types are ref counted. Once created the caller implicitly owns the created - * data, i.e. its reference counter is set to 1. The sdis_<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 sg3d_device sgXd_device; -typedef struct sg3d_geometry sgXd_geometry; - -/****************************************************************************** - * The dimension of the geometry used in the library. - *****************************************************************************/ -#define SGXD_GEOMETRY_DIMENSION SG3D_GEOMETRY_DIMENSION - -/****************************************************************************** - * A type to list the different user properties attached to triangles. - *****************************************************************************/ -enum sgXd_property_type { - SGXD_FRONT = SG3D_FRONT, - SGXD_BACK = SG3D_BACK, - SGXD_INTFACE = SG3D_INTFACE, - SGXD_PROP_TYPES_COUNT__ = SG3D_PROP_TYPES_COUNT__ -}; - -/****************************************************************************** - * A type to list the different possible partitions of triangles. - *****************************************************************************/ -enum sgXd_obj_dump_content { - SGXD_OBJ_DUMP_MERGE_CONFLICTS = SG3D_OBJ_DUMP_MERGE_CONFLICTS, - SGXD_OBJ_DUMP_PROPERTY_CONFLICTS = SG3D_OBJ_DUMP_PROPERTY_CONFLICTS, - SGXD_OBJ_DUMP_VALID_PRIMITIVE = SG3D_OBJ_DUMP_VALID_PRIMITIVE, - SGXD_OBJ_DUMP_ALL = SG3D_OBJ_DUMP_ALL -}; - -/****************************************************************************** - * A type to list the different qualifiers of C code variable output. - *****************************************************************************/ -enum sgXd_c_dump_qualifiers { - SGXD_C_DUMP_CONST = SG3D_C_DUMP_CONST, - SGXD_C_DUMP_STATIC = SG3D_C_DUMP_STATIC -}; - -/****************************************************************************** - * The value that should be used for properties attached to triangles (i.e. - * media or interface) when let unspecified. - * SG3D_UNSPECIFIED_PROPERTY can be used for a property that has already been - * defined; in this case the previous value will remain. - *****************************************************************************/ -#define SGXD_UNSPECIFIED_PROPERTY SG3D_UNSPECIFIED_PROPERTY - - /***************************************************************************** - * A type to hold callbacks for sg3d_geometry_add. - ****************************************************************************/ -typedef struct sg3d_geometry_add_callbacks sgXd_geometry_add_callbacks; -#define SGXD_ADD_CALLBACKS_NULL__ SG3D_ADD_CALLBACKS_NULL__ - -BEGIN_DECLS - -/****************************************************************************** - * A helper function on properties compatibility. - *****************************************************************************/ -static FINLINE int -sgXd_compatible_property - (const unsigned p1, - const unsigned p2) -{ - return sg3d_compatible_property(p1, p2); -} - -/****************************************************************************** - * star-geometry device. It is an handle toward the star-geometry library. - * It manages the star-geometry resources. - *****************************************************************************/ -static FINLINE res_T -sgXd_device_create - (struct logger* logger, /* Can be NULL <=> use default logger */ - struct mem_allocator* allocator, /* Can be NULL <=> use default allocator */ - const int verbose, /* Verbosity level */ - sgXd_device** dev) -{ - return sg3d_device_create(logger, allocator, verbose, dev); -} - -static FINLINE res_T -sgXd_device_ref_get - (sgXd_device* dev) -{ - return sg3d_device_ref_get(dev); -} - -static FINLINE res_T -sgXd_device_ref_put - (sgXd_device* dev) -{ - return sg3d_device_ref_put(dev); -} - -/****************************************************************************** - * star-geometry geometry. - * It stores decorated geometry accumulated through calls to sg3d_geometry_add, - * information related to this geometry and its creation process, including - * merge conflicts. - *****************************************************************************/ -/* Create a geometry that can be used to accumulate vertices and triangles - * decorated with properties. */ -static FINLINE res_T -sgXd_geometry_create - (sgXd_device* dev, - sgXd_geometry** geometry) -{ - return sg3d_geometry_create(dev, geometry); -} - -/* Reserve memory according to anticipated geometry size. */ -static FINLINE res_T -sgXd_geometry_reserve - (sgXd_geometry* geometry, - const unsigned vertices_count, - const unsigned triangles_count, - const unsigned properties_count) -{ - return sg3d_geometry_reserve( - geometry, vertices_count, triangles_count, properties_count); -} - -/* Add a new set of 3D vertices and triangles to the geometry; triangles can - * be decorated with 3 properties (front and back media and interface) that can - * be let unspecified using the SG3D_UNSPECIFIED_PROPERTY special value. - * Vertices can be duplicates and are silently deduplicated, always valid. - * Triangles can be duplicates, but this can be ruled invalid due to property - * inconsistency. Triangle duplicates are silently deduplicated, even if - * invalid. Consistency is to be understood as the consistency of the - * successive values for the same property across calls of sg3d_geometry_add, - * not as the consistency of the values of the 3 properties of a triangle at - * some given time (this question has its own callback (validate) in the - * sg3d_geometry_validate_properties API call). - * Duplicate triangles validity is either ruled by the user-provided - * merge_triangle callback, or is just a matter of properties consistency if no - * callback is provided. In either case, sg3d_geometry_add never stops - * prematurely nor returns an error code due to a merge conflict. - * - if provided, the callback must return the consistency status using the - * merge_conflict_status int* paramater (0 for consistent; any other value - * for inconsistent, this value being recorded); regardless of - * merge_conflict_status, the callback can change the properties of the - * triangle before the SG3D_UNSPECIFIED_PROPERTY overwriting step; - * - if not, a non-SG3D_UNSPECIFIED_PROPERTY is only consistent with itself and - * with SG3D_UNSPECIFIED_PROPERTY (if inconsistent, merge_conflict_status is - * set to 1 and recorded) ; regardless of merge_conflict_status, a - * non-SG3D_UNSPECIFIED_PROPERTY property is never overridden. - * When deduplicating triangles, the first occurence remains (with its - * original index in user world). After consistency being computed, a final - * step consists in rewriting SG3D_UNSPECIFIED_PROPERTY properties if the merged - * property is defined. */ -static FINLINE res_T -sgXd_geometry_add - (sgXd_geometry* geometry, - const unsigned vertices_count, - const unsigned triangles_count, - const sgXd_geometry_add_callbacks* callbacks, - void* context) /* Can be NULL */ -{ - return sg3d_geometry_add( - geometry, vertices_count, triangles_count, callbacks, context); -} - -/* Apply a validation callback on each triangle included in this geometry that - * is not already flagged with a merge error. If validate returns a non-RES_OK - * value, the validation stops and returns the same error value; on the other - * hand, validation goes to the end regardless of properties conflicts. - * The properties_conflict_status argument can be set to any value. Any non-0 - * value is accounted for a conflict and is kept as-is in dumps, allowing - * different shades of conflict. - * If validation is processed again, the properties conflict count is reset, - * as well as the properties_conflict_status status of the triangles. */ -static FINLINE res_T -sgXd_geometry_validate_properties - (sgXd_geometry* geometry, - res_T(*validate) - (const unsigned itri, - const unsigned properties[SGXD_PROP_TYPES_COUNT__], - void* context, - int* properties_conflict_status), - void* context) /* Can be NULL */ -{ - return sg3d_geometry_validate_properties(geometry, validate, context); -} - -/* Get the number of unique vertices. */ -static FINLINE res_T -sgXd_geometry_get_unique_vertices_count - (const sgXd_geometry* geometry, - unsigned* count) -{ - return sg3d_geometry_get_unique_vertices_count(geometry, count); -} - -/* Get the ivtx_th vertex. */ -static FINLINE res_T -sgXd_geometry_get_unique_vertex - (const sgXd_geometry* geometry, - const unsigned ivtx, - double coord[SGXD_GEOMETRY_DIMENSION]) -{ - return sg3d_geometry_get_unique_vertex(geometry, ivtx, coord); -} - -/* Get the number of triangles added to the geometry, regardless of unicity. */ -static FINLINE res_T -sgXd_geometry_get_added_primitives_count - (const sgXd_geometry* geometry, - unsigned* count) -{ - return sg3d_geometry_get_added_triangles_count(geometry, count); -} - -/* Get the number of unique triangles. */ -static FINLINE res_T -sgXd_geometry_get_unique_primitives_count - (const sgXd_geometry* geometry, - unsigned* count) -{ - return sg3d_geometry_get_unique_triangles_count(geometry, count); -} - -/* Get the vertex indices of the itri_th unique triangle. */ -static FINLINE res_T -sgXd_geometry_get_unique_primitive_vertices - (const sgXd_geometry* geometry, - const unsigned itri, - unsigned indices[SGXD_GEOMETRY_DIMENSION]) -{ - return sg3d_geometry_get_unique_triangle_vertices(geometry, itri, indices); -} - -/* Get the properties of the itri_th unique triangle. */ -static FINLINE res_T -sgXd_geometry_get_unique_primitive_properties - (const sgXd_geometry* geometry, - const unsigned itri, - unsigned properties[SG3D_PROP_TYPES_COUNT__]) -{ - return sg3d_geometry_get_unique_triangle_properties( - geometry, itri, properties); -} - -/* Get the user ID of the itri_th unique triangle, that is the user world's - * index of the triangle that first created this unique triangle. - * User world index starts at 0 and increases for every triangle that is - * submitted to sg3d_geometry_add calls, regardless of duplication or - * sg3d_geometry_add failures (non-RES_OK return value). */ -static FINLINE res_T -sgXd_geometry_get_unique_primitive_user_id - (const sgXd_geometry* geometry, - const unsigned itri, - unsigned* user_id) -{ - return sg3d_geometry_get_unique_triangle_user_id(geometry, itri, user_id); -} - -/* Get the number of triangles with (at least) one unspecified side. */ -static FINLINE res_T -sgXd_geometry_get_unique_primitives_with_unspecified_side_count - (const sgXd_geometry* geometry, - unsigned* count) -{ - return sg3d_geometry_get_unique_triangles_with_unspecified_side_count( - geometry, count); -} - -/* Get the number of triangles with unspecified interface. */ -static FINLINE res_T -sgXd_geometry_get_unique_primitives_with_unspecified_interface_count - (const sgXd_geometry* geometry, - unsigned* count) -{ - return sg3d_geometry_get_unique_triangles_with_unspecified_interface_count( - geometry, count); -} - -/* Get the number of triangles flagged with a merge conflict. */ -static FINLINE res_T -sgXd_geometry_get_unique_primitives_with_merge_conflict_count - (const sgXd_geometry* geometry, - unsigned* count) -{ - return sg3d_geometry_get_unique_triangles_with_merge_conflict_count( - geometry, count); -} - -/* Get the number of triangles flagged with a property conflict. Only - * meaningful after sg3d_geometry_validate_properties has been called. */ -static FINLINE res_T -sgXd_geometry_get_unique_primitives_with_properties_conflict_count - (const sgXd_geometry* geometry, - unsigned* count) -{ - return sg3d_geometry_get_unique_triangles_with_properties_conflict_count( - geometry, count); -} - -/* Dump a geometry in the provided stream in the OBJ format. - * The geometry can include conflicts, but cannot be empty. - * The dump is made of the vertices and some triangles, without their - * properties. The dumped triangles are defined by the flags argument, that - * must be ORed enum sg3d_obj_dump_content values. - * The dumped triangles are partitioned in the following groups: - * - Valid_triangles - * - Merge_conflicts - * - Property_conflict */ -static FINLINE res_T -sgXd_geometry_dump_as_obj - (const sgXd_geometry* geometry, - FILE* stream, - const int flags) -{ - return sg3d_geometry_dump_as_obj(geometry, stream, flags); -} - -/* Dump a geometry in the provided stream in the VTK ascii format. - * The geometry can include conflicts, but cannot be empty. - * The dump is made of the vertices and triangles, with most of their - * properties: - * - Front_medium (medium ID of the front side, INT_MAX for both unspecified - * and conflicted) - * - Back_medium (medium ID of the back side, INT_MAX for both unspecified and - * conflicted) - * - Interface (interface ID, INT_MAX for both unspecified and conflicted) - * - Merge_conflict (merge conflict status) - * - Property_conflict (property conflict status) - * - Created_at_sg3d_geometry_add (rank of the sg3d_geometry_add that created the - * triangle) */ -static FINLINE res_T -sgXd_geometry_dump_as_vtk - (const sgXd_geometry* geometry, - FILE* stream) -{ - return sg3d_geometry_dump_as_vtk(geometry, stream); -} - -/* Dump the geometry as C code. - * The geometry cannot be empty and must be conflict-free. - * The C code defines the 3 variables: - * - [static] [const] unsigned <name_prefix>_vertices_count = N1; - * - [static] [const] double <name_prefix>_vertices[<N1>] = { .... }; - * - [static] [const] unsigned <name_prefix>_triangles_count = N2; - * - [static] [const] unsigned <name_prefix>_triangles[<N2>] = { .... }; - * - [static] [const] unsigned <name_prefix>_properties[<N2>] = { .... }; - * Where <N1> is 3 * vertices_count and <N2> is 3 * triangles_count. - * The two qualifiers static and const are output or not according to flags; - * flags must be ORed enum sg3d_c_dump_qualifiers values. */ -static FINLINE res_T -sgXd_geometry_dump_as_c_code - (const sgXd_geometry* geometry, - FILE* stream, - const char* name_prefix, /* Can be NULL or "" */ - const int flags) -{ - return sg3d_geometry_dump_as_c_code(geometry, stream, name_prefix, flags); -} - -static FINLINE res_T -sgXd_geometry_ref_get - (sgXd_geometry* geometry) -{ - return sg3d_geometry_ref_get(geometry); -} - -static FINLINE res_T -sgXd_geometry_ref_put - (sgXd_geometry* geometry) -{ - return sg3d_geometry_ref_put(geometry); -} - -/****************************************************************************** - * StarGeometryXD to StarEnclosuresXD helper. - *****************************************************************************/ - - /* Get vertex indices for the itri_th triangle. - * Suitable for use as get_indices callback in senc_scene_create calls. */ -static FINLINE void -sgXd_sencX_geometry_get_indices - (const unsigned itri, - unsigned indices[SGXD_GEOMETRY_DIMENSION], - void* ctx) -{ - sg3d_senc_geometry_get_indices(itri, indices, ctx); -} - -/* Get vertex indices for the itri_th triangle. - * Suitable for use as get_media callback in senc_scene_create calls. */ -static FINLINE void -sgXd_sencX_geometry_get_media - (const unsigned itri, - unsigned media[2], - void* ctx) -{ - sg3d_senc_geometry_get_media(itri, media, ctx); -} - -/* Get vertex indices for the itri_th triangle. - * Suitable for use as get_position callback in senc_scene_create calls. */ -static FINLINE void -sgXd_sencX_geometry_get_position - (const unsigned ivert, - double coord[SGXD_GEOMETRY_DIMENSION], - void* ctx) -{ - sg3d_senc_geometry_get_position(ivert, coord, ctx); -} - -/****************************************************************************** - * StarGeometryXD to StarXD helper. - *****************************************************************************/ - - /* 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 -sgXd_sXd_geometry_get_indices - (const unsigned itri, - unsigned indices[SGXD_GEOMETRY_DIMENSION], - void* ctx) -{ - sg3d_s3d_geometry_get_indices(itri, indices, ctx); -} +#include <star/sg3d.h> -/* 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 -sgXd_sXd_geometry_get_position - (const unsigned ivert, - float coord[SGXD_GEOMETRY_DIMENSION], - void* ctx) -{ - sg3d_s3d_geometry_get_position(ivert, coord, ctx); -} +/* Star-geometry-XD macros generic to the SGXD_DIM */ +#ifndef SGXD +#define SGXD CONCAT(CONCAT(SGX, SGXD_DIM), D) +#endif +#ifndef sgXd +#define sgXd(Name) CONCAT(CONCAT(CONCAT(sg, SGXD_DIM), d_), Name) +#endif +#ifndef SGXD_ +#define SGXD_(Name) CONCAT(CONCAT(CONCAT(SGX, SGXD_DIM), D_), Name) +#endif -END_DECLS +/* Function names that require additional dedicated macros */ +#define sgXd_geometry_get_added_primitives_count \ + sg3d_geometry_get_added_triangles_count +#define sgXd_geometry_get_unique_primitives_count \ + sg3d_geometry_get_unique_triangles_count +#define sgXd_geometry_get_unique_primitive_vertices \ + sg3d_geometry_get_unique_triangle_vertices +#define sgXd_geometry_get_unique_primitive_properties \ + sg3d_geometry_get_unique_triangle_properties +#define sgXd_geometry_get_unique_primitive_user_id \ + sg3d_geometry_get_unique_triangle_user_id +#define sgXd_geometry_get_unique_primitives_with_unspecified_side_count \ + sg3d_geometry_get_unique_triangles_with_unspecified_side_count +#define sgXd_geometry_get_unique_primitives_with_unspecified_interface_count \ + sg3d_geometry_get_unique_triangles_with_unspecified_interface_count +#define sgXd_geometry_get_unique_primitives_with_properties_conflict_count \ + sg3d_geometry_get_unique_triangles_with_properties_conflict_count #endif /* STAR_GEOMETRY3D_X_H__ */ diff --git a/src/sgX3d_undefs.h b/src/sgX3d_undefs.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2019-2020 |Meso|Star> (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 STAR_GEOMETRY3D_X_H__ +#error "The sgX3d.h file must be included priorly to this file." +#endif + +/* Star-geometry-XD macros generic to the SGXD_DIM */ +#undef SENCXD +#undef sencXd +#undef SENCXD_ + +/* Function names that require additional dedicated macros */ +#undef sgXd_geometry_get_added_primitives_count +#undef sgXd_geometry_get_unique_primitives_count +#undef sgXd_geometry_get_unique_primitive_vertices +#undef sgXd_geometry_get_unique_primitive_properties +#undef sgXd_geometry_get_unique_primitive_user_id +#undef sgXd_geometry_get_unique_primitives_with_unspecified_side_count +#undef sgXd_geometry_get_unique_primitives_with_unspecified_interface_count +#undef sgXd_geometry_get_unique_primitives_with_properties_conflict_count + +#undef STAR_GEOMETRY3D_X_H__