commit e2506755a4d023faad0200bf2c7aeab257a7c873
parent ab6b651549100f912b4a7c4d1bdf41c613559cf5
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Thu, 6 Feb 2020 16:50:15 +0100
Use new star-enclosure-Xd APIs
Diffstat:
11 files changed, 188 insertions(+), 245 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -25,15 +25,15 @@ option(NO_TEST "Do not build tests" OFF)
CMAKE_DEPENDENT_OPTION(ALL_TESTS
"Perform basic and advanced tests" OFF "NOT NO_TEST" OFF)
-################################################################################
+###############################################################################
# Check dependencies
-################################################################################
+###############################################################################
find_package(RCMake 0.4 REQUIRED)
find_package(Star2D 0.3.1 REQUIRED)
find_package(Star3D 0.6.2 REQUIRED)
find_package(StarSP 0.8 REQUIRED)
-find_package(StarEnc 0.4.2 REQUIRED)
find_package(StarEnc2D 0.4.2 REQUIRED)
+find_package(StarEnc3D 0.4.2 REQUIRED)
find_package(RSys 0.8.1 REQUIRED)
find_package(OpenMP 2.0 REQUIRED)
@@ -45,15 +45,16 @@ include_directories(
${Star2D_INCLUDE_DIR}
${Star3D_INCLUDE_DIR}
${StarSP_INCLUDE_DIR}
- ${StarEnc_INCLUDE_DIR}
${StarEnc2D_INCLUDE_DIR}
+ ${StarEnc3D_INCLUDE_DIR}
${RSys_INCLUDE_DIR})
-rcmake_append_runtime_dirs(_runtime_dirs RSys Star3D StarSP StarEnc StarEnc2D)
+rcmake_append_runtime_dirs(_runtime_dirs
+ RSys Star2D Star3D StarSP StarEnc2D StarEnc3D)
-################################################################################
+###############################################################################
# Configure and define targets
-################################################################################
+###############################################################################
set(VERSION_MAJOR 0)
set(VERSION_MINOR 8)
set(VERSION_PATCH 2)
@@ -115,7 +116,8 @@ if(MSVC)
### disable verbose warnings:
# warning C4127: conditional expression is constant
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127")
- # warning C4204: nonstandard extension used : non-constant aggregate initializer
+ # warning C4204:
+ # nonstandard extension used : non-constant aggregate initializer
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4204")
# warning C4938: Floating point reduction variable may cause inconsistent
# results under /fp:strict or #pragma fenv_access
@@ -126,7 +128,8 @@ add_library(sdis SHARED
${SDIS_FILES_SRC}
${SDIS_FILES_INC}
${SDIS_FILES_INC_API})
-target_link_libraries(sdis RSys Star2D Star3D StarSP StarEnc StarEnc2D ${MATH_LIB})
+target_link_libraries(sdis
+ RSys Star2D Star3D StarSP StarEnc2D StarEnc3D ${MATH_LIB})
set_target_properties(sdis PROPERTIES
DEFINE_SYMBOL SDIS_SHARED_BUILD
@@ -141,9 +144,9 @@ endif()
rcmake_setup_devel(sdis Stardis ${VERSION} sdis_version.h)
-################################################################################
+###############################################################################
# Add tests
-################################################################################
+###############################################################################
if(NOT NO_TEST)
find_package(Star3DUT REQUIRED 0.2.0)
@@ -209,11 +212,14 @@ if(NOT NO_TEST)
target_link_libraries(test_sdis_solve_probe3_2d ${MATH_LIB})
target_link_libraries(test_sdis_solve_camera Star3DUT)
+
+ rcmake_copy_runtime_libraries(test_sdis_solid_random_walk_robustness)
+
endif()
-################################################################################
+###############################################################################
# Define output & install directories
-################################################################################
+###############################################################################
install(TARGETS sdis
ARCHIVE DESTINATION bin
LIBRARY DESTINATION lib
diff --git a/src/sdis.h b/src/sdis.h
@@ -47,8 +47,8 @@
/* Forward declaration of external opaque data types */
struct logger;
struct mem_allocator;
-struct senc2d_descriptor;
-struct senc_descriptor;
+struct senc2d_scene;
+struct senc3d_scene;
/* Forward declaration of the Stardis opaque data types. These data types are
* ref counted. Once created the caller implicitly owns the created data, i.e.
@@ -630,23 +630,17 @@ sdis_scene_boundary_project_position
const double pos[3],
double uv[]);
-/* Get the descriptor of the 3D scene's enclosures */
+/* Get the 2D scene's enclosures. Only defined for a 2D scene. */
SDIS_API res_T
-sdis_scene_get_analysis
+sdis_scene_get_senc2d_scene
(struct sdis_scene* scn,
- struct senc_descriptor** descriptor);
+ struct senc2d_scene** senc2d_scn);
-/* Get the descriptor of the 2D scene's enclosures */
+/* Get the 3D scene's enclosures. Only defined for a 3D scene. */
SDIS_API res_T
-sdis_scene_2d_get_analysis
+sdis_scene_get_senc3d_scene
(struct sdis_scene* scn,
- struct senc2d_descriptor** descriptor);
-
-/* Release the descriptor of the scene's enclosures; subsequent attempts to get
- * it will fail. */
-SDIS_API res_T
-sdis_scene_release_analysis
- (struct sdis_scene* scn);
+ struct senc3d_scene** senc3d_scn);
SDIS_API res_T
sdis_scene_get_dimension
diff --git a/src/sdis_Xd_begin.h b/src/sdis_Xd_begin.h
@@ -60,7 +60,6 @@ static const struct rwalk_context RWALK_CONTEXT_NULL = RWALK_CONTEXT_NULL__;
/* Star-XD macros generic to SDIS_XD_DIMENSION */
#define sXd(Name) CONCAT(CONCAT(CONCAT(s, DIM), d_), Name)
-#define sXd_dev CONCAT(CONCAT(s, DIM), d)
#define SXD_HIT_NONE CONCAT(CONCAT(S,DIM), D_HIT_NONE)
#define SXD_HIT_NULL CONCAT(CONCAT(S,DIM), D_HIT_NULL)
#define SXD_HIT_NULL__ CONCAT(CONCAT(S, DIM), D_HIT_NULL__)
@@ -70,6 +69,7 @@ static const struct rwalk_context RWALK_CONTEXT_NULL = RWALK_CONTEXT_NULL__;
#define SXD CONCAT(CONCAT(S, DIM), D)
#define SXD_FLOAT2 CONCAT(CONCAT(S, DIM), D_FLOAT2)
#define SXD_FLOAT3 CONCAT(CONCAT(S, DIM), D_FLOAT3)
+#define SXD_FLOATX CONCAT(CONCAT(CONCAT(S,DIM), D_FLOAT), DIM)
#define SXD_SAMPLE CONCAT(CONCAT(S, DIM), D_SAMPLE)
/* Vector macros generic to SDIS_XD_DIMENSION */
diff --git a/src/sdis_Xd_end.h b/src/sdis_Xd_end.h
@@ -21,7 +21,6 @@
#undef DIM
#undef sXd
-#undef sXd_dev
#undef SXD_HIT_NONE
#undef SXD_HIT_NULL
#undef SXD_HIT_NULL__
@@ -31,6 +30,7 @@
#undef SXD
#undef SXD_FLOAT2
#undef SXD_FLOAT3
+#undef SXD_FLOATX
#undef SXD_SAMPLE
#undef dX
diff --git a/src/sdis_device.c b/src/sdis_device.c
@@ -48,8 +48,8 @@ device_release(ref_T* ref)
struct sdis_device* dev;
ASSERT(ref);
dev = CONTAINER_OF(ref, struct sdis_device, ref);
- if(dev->s2d) S2D(device_ref_put(dev->s2d));
- if(dev->s3d) S3D(device_ref_put(dev->s3d));
+ if(dev->s2d_dev) S2D(device_ref_put(dev->s2d_dev));
+ if(dev->s3d_dev) S3D(device_ref_put(dev->s3d_dev));
ASSERT(flist_name_is_empty(&dev->interfaces_names));
ASSERT(flist_name_is_empty(&dev->media_names));
flist_name_release(&dev->interfaces_names);
@@ -98,13 +98,13 @@ sdis_device_create
flist_name_init(allocator, &dev->interfaces_names);
flist_name_init(allocator, &dev->media_names);
- res = s2d_device_create(log, allocator, 0, &dev->s2d);
+ res = s2d_device_create(log, allocator, 0, &dev->s2d_dev);
if(res != RES_OK) {
log_err(dev,
"%s: could not create the Star-2D device on Stardis.\n", FUNC_NAME);
}
- res = s3d_device_create(log, allocator, 0, &dev->s3d);
+ res = s3d_device_create(log, allocator, 0, &dev->s3d_dev);
if(res != RES_OK) {
log_err(dev,
"%s: could not create the Star-3D device on Stardis.\n", FUNC_NAME);
diff --git a/src/sdis_device_c.h b/src/sdis_device_c.h
@@ -35,8 +35,8 @@ struct sdis_device {
struct flist_name interfaces_names;
struct flist_name media_names;
- struct s2d_device* s2d;
- struct s3d_device* s3d;
+ struct s2d_device* s2d_dev;
+ struct s3d_device* s3d_dev;
ref_T ref;
};
diff --git a/src/sdis_scene.c b/src/sdis_scene.c
@@ -104,8 +104,8 @@ scene_release(ref_T * ref)
htable_d_release(&scn->tmp_hc_ub);
if(scn->s2d_view) S2D(scene_view_ref_put(scn->s2d_view));
if(scn->s3d_view) S3D(scene_view_ref_put(scn->s3d_view));
- if(scn->senc_descriptor) SENC(descriptor_ref_put(scn->senc_descriptor));
- if(scn->senc2d_descriptor) SENC2D(descriptor_ref_put(scn->senc2d_descriptor));
+ if(scn->senc2d_scn) SENC2D(scene_ref_put(scn->senc2d_scn));
+ if(scn->senc3d_scn) SENC3D(scene_ref_put(scn->senc3d_scn));
MEM_RM(dev->allocator, scn);
SDIS(device_ref_put(dev));
}
@@ -276,37 +276,26 @@ sdis_scene_boundary_project_position
}
res_T
-sdis_scene_2d_get_analysis
+sdis_scene_get_senc2d_scene
(struct sdis_scene* scn,
- struct senc2d_descriptor** descriptor)
+ struct senc2d_scene** senc2d_scn)
{
- if(!scn || !descriptor) return RES_BAD_ARG;
- if(!scn->senc2d_descriptor) return RES_BAD_ARG; /* Scene is 3D */
- SENC2D(descriptor_ref_get(scn->senc2d_descriptor));
- *descriptor = scn->senc2d_descriptor;
+ if(!scn || !senc2d_scn) return RES_BAD_ARG;
+ if(!scn->senc2d_scn) return RES_BAD_ARG; /* Scene is 3D */
+ SENC2D(scene_ref_get(scn->senc2d_scn));
+ *senc2d_scn = scn->senc2d_scn;
return RES_OK;
}
res_T
-sdis_scene_get_analysis
+sdis_scene_get_senc3d_scene
(struct sdis_scene* scn,
- struct senc_descriptor** descriptor)
+ struct senc3d_scene** senc3d_scn)
{
- if(!scn || !descriptor) return RES_BAD_ARG;
- if(!scn->senc_descriptor) return RES_BAD_ARG; /* Scene is 2D */
- SENC(descriptor_ref_get(scn->senc_descriptor));
- *descriptor = scn->senc_descriptor;
- return RES_OK;
-}
-
-res_T
-sdis_scene_release_analysis(struct sdis_scene* scn)
-{
- if(!scn) return RES_BAD_ARG;
- if(scn->senc2d_descriptor) SENC2D(descriptor_ref_put(scn->senc2d_descriptor));
- if(scn->senc_descriptor) SENC(descriptor_ref_put(scn->senc_descriptor));
- scn->senc_descriptor = NULL;
- scn->senc2d_descriptor = NULL;
+ if(!scn || !senc3d_scn) return RES_BAD_ARG;
+ if(!scn->senc3d_scn) return RES_BAD_ARG; /* Scene is 2D */
+ SENC3D(scene_ref_get(scn->senc3d_scn));
+ *senc3d_scn = scn->senc3d_scn;
return RES_OK;
}
diff --git a/src/sdis_scene_Xd.h b/src/sdis_scene_Xd.h
@@ -118,11 +118,12 @@ clear_properties(struct sdis_scene* scn)
#include <limits.h>
/* Check the submitted dimension and include its specific headers */
+#define SENCXD_DIM SDIS_SCENE_DIMENSION
#if (SDIS_SCENE_DIMENSION == 2)
- #include <star/senc2d.h>
+ #include <star/sencX2d.h>
#include <star/s2d.h>
#elif (SDIS_SCENE_DIMENSION == 3)
- #include <star/senc.h>
+ #include <star/sencX3d.h>
#include <star/s3d.h>
#else
#error "Invalid SDIS_SCENE_DIMENSION value."
@@ -131,15 +132,6 @@ clear_properties(struct sdis_scene* scn)
/* Syntactic sugar */
#define DIM SDIS_SCENE_DIMENSION
-/* Star-Enc macros generic to the SDIS_SCENE_DIMENSION */
-#if DIM == 2
- #define sencXd(Name) CONCAT(senc2d_, Name)
- #define SENCXD SENC2D
-#else
- #define sencXd(Name) CONCAT(senc_, Name)
- #define SENCXD SENC
-#endif
-
/* Star-XD macros generic to SDIS_SCENE_DIMENSION */
#define sXd(Name) CONCAT(CONCAT(CONCAT(s, DIM), d_), Name)
#define SXD CONCAT(CONCAT(S, DIM), D)
@@ -150,6 +142,7 @@ clear_properties(struct sdis_scene* scn)
#define SXD_GET_PRIMITIVE CONCAT(CONCAT(S,DIM), D_GET_PRIMITIVE)
#define SXD_HIT_NONE CONCAT(CONCAT(S,DIM), D_HIT_NONE)
#define SXD_PRIMITIVE_EQ CONCAT(CONCAT(S,DIM), D_PRIMITIVE_EQ)
+#define SXD_FLOATX CONCAT(CONCAT(CONCAT(S,DIM), D_FLOAT), DIM)
/* Vector macros generic to SDIS_SCENE_DIMENSION */
#define fX(Func) CONCAT(CONCAT(CONCAT(f, DIM), _), Func)
@@ -484,24 +477,20 @@ XD(geometry_position)(const unsigned ivert, double out_pos[DIM], void* data)
/* Retrieve the indices of a primitive of a Star-EncXD descriptor */
static void
-XD(descriptor_indices)(const unsigned iprim, unsigned ids[DIM], void* data)
+XD(scene_indices)(const unsigned iprim, unsigned ids[DIM], void* data)
{
- struct sencXd(descriptor)* desc = data;
-#if DIM == 2
- SENCXD(descriptor_get_global_segment(desc, iprim, ids));
-#else
- SENCXD(descriptor_get_global_triangle(desc, iprim, ids));
-#endif
+ struct sencXd(scene)* scn = data;
+ SENCXD(scene_get_primitive(scn, iprim, ids));
}
/* Retrieve the coordinates of a vertex of a Star-EncXD descriptor */
static void
-XD(descriptor_position)(const unsigned ivert, float out_pos[DIM], void* data)
+XD(scene_position)(const unsigned ivert, float out_pos[DIM], void* data)
{
- struct sencXd(descriptor)* desc = data;
+ struct sencXd(scene)* scn = data;
double pos[3];
int i;
- SENCXD(descriptor_get_global_vertex(desc, ivert, pos));
+ SENCXD(scene_get_vertex(scn, ivert, pos));
FOR_EACH(i, 0, DIM) out_pos[i] = (float)pos[i];
}
@@ -510,11 +499,7 @@ static void
XD(enclosure_indices)(const unsigned iprim, unsigned ids[DIM], void* data)
{
struct sencXd(enclosure)* enc = data;
-#if DIM == 2
- SENCXD(enclosure_get_segment(enc, iprim, ids));
-#else
- SENCXD(enclosure_get_triangle(enc, iprim, ids));
-#endif
+ SENCXD(enclosure_get_primitive(enc, iprim, ids));
}
/* Retrieve the coordinates of a vertex of a Star-EncXD encolsure */
@@ -542,51 +527,37 @@ XD(run_analyze)
const size_t nverts, /* #vertices */
void (*position)(const size_t ivert, double pos[], void*),
void* ctx,
- struct sencXd(descriptor)** out_desc)
+ struct sencXd(scene)** out_scn)
{
struct geometry geom;
struct sencXd(device)* senc = NULL;
- struct sencXd(scene)* senc_scn = NULL;
- struct sencXd(descriptor)* desc = NULL;
+ struct sencXd(scene)* senc3d_scn = NULL;
res_T res = RES_OK;
- ASSERT(scn && nprims && indices && interf && nverts && position && out_desc);
+ ASSERT(scn && nprims && indices && interf && nverts && position && out_scn);
res = sencXd(device_create)(scn->dev->logger, scn->dev->allocator,
scn->dev->nthreads, scn->dev->verbose, &senc);
if(res != RES_OK) goto error;
- res = sencXd(scene_create)(senc,
-#if DIM == 2
- SENC2D_CONVENTION_NORMAL_BACK | SENC2D_CONVENTION_NORMAL_OUTSIDE,
-#else
- SENC_CONVENTION_NORMAL_BACK | SENC_CONVENTION_NORMAL_OUTSIDE,
-#endif
- &senc_scn);
- if(res != RES_OK) goto error;
-
/* Setup the geometry data */
geom.indices = indices;
geom.interf = interf;
geom.position = position;
geom.data = ctx;
- res = sencXd(scene_add_geometry)
- (senc_scn, (unsigned)nprims, XD(geometry_indices), geometry_media,
- (unsigned)nverts, XD(geometry_position), NULL, NULL, &geom);
- if(res != RES_OK) goto error;
-
- /* Launch the scene analyze */
- res = sencXd(scene_analyze)(senc_scn, &desc);
+ res = sencXd(scene_create)(senc,
+ SENCXD_(CONVENTION_NORMAL_BACK) | SENCXD_(CONVENTION_NORMAL_OUTSIDE),
+ (unsigned)nprims, XD(geometry_indices), geometry_media,
+ (unsigned)nverts, XD(geometry_position), &geom, &senc3d_scn);
if(res != RES_OK) goto error;
exit:
if(senc) SENCXD(device_ref_put(senc));
- if(senc_scn) SENCXD(scene_ref_put(senc_scn));
- if(out_desc) *out_desc = desc;
+ if(out_scn) *out_scn = senc3d_scn;
return res;
error:
- if(desc) {
- SENCXD(descriptor_ref_put(desc));
- desc = NULL;
+ if(senc3d_scn) {
+ SENCXD(scene_ref_put(senc3d_scn));
+ senc3d_scn = NULL;
}
goto exit;
@@ -598,45 +569,31 @@ error:
static res_T
XD(setup_properties)
(struct sdis_scene* scn,
- struct sencXd(descriptor)* desc,
+ struct sencXd(scene)* senc3d_scn,
void (*interf)(const size_t itri, struct sdis_interface**, void*),
void* ctx)
{
unsigned iprim, nprims;
res_T res = RES_OK;
- ASSERT(scn && interf);
+ ASSERT(scn && senc3d_scn && interf);
clear_properties(scn);
-#if DIM == 2
- SENCXD(descriptor_get_global_segments_count(desc, &nprims));
-#else
- SENCXD(descriptor_get_global_triangles_count(desc, &nprims));
-#endif
+ SENCXD(scene_get_primitives_count(senc3d_scn, &nprims));
FOR_EACH(iprim, 0, nprims) {
struct prim_prop* prim_prop;
struct sdis_interface* itface;
unsigned enclosures[2];
- unsigned iprim_adjusted; /* Primitive id in user space */
unsigned id;
int i;
double* enc_upper_bound;
size_t ninterfaces;
-#if DIM == 2
- /* Retrieve the segment id in user space */
- SENCXD(descriptor_get_global_segment_global_id(desc, iprim, &iprim_adjusted));
- /* Fetch the enclosures that the segment splits */
- SENCXD(descriptor_get_global_segment_enclosures(desc, iprim, enclosures));
-#else
- /* Retrieve the triangle id in user space */
- SENCXD(descriptor_get_global_triangle_global_id(desc, iprim, &iprim_adjusted));
- /* Fetch the enclosures that the triangle splits */
- SENCXD(descriptor_get_global_triangle_enclosures(desc, iprim, enclosures));
-#endif
+ /* Fetch the enclosures that the segment/triangle splits */
+ SENCXD(scene_get_primitive_enclosures(senc3d_scn, iprim, enclosures));
/* Fetch the interface of the primitive */
- interf(iprim_adjusted, &itface, ctx);
+ interf(iprim, &itface, ctx);
/* Check that the interface is already registered against the scene */
id = interface_get_id(itface);
@@ -689,7 +646,7 @@ error:
/* Build the Star-XD scene view of the whole scene */
static res_T
-XD(setup_scene_geometry)(struct sdis_scene* scn, struct sencXd(descriptor)* desc)
+XD(setup_scene_geometry)(struct sdis_scene* scn, struct sencXd(scene)* senc3d_scn)
{
struct sXd(device)* sXd_dev = NULL;
struct sXd(shape)* sXd_shape = NULL;
@@ -697,36 +654,30 @@ XD(setup_scene_geometry)(struct sdis_scene* scn, struct sencXd(descriptor)* desc
struct sXd(vertex_data) vdata = SXD_VERTEX_DATA_NULL;
unsigned nprims, nverts;
res_T res = RES_OK;
- ASSERT(scn && desc);
+ ASSERT(scn && senc3d_scn);
- SENCXD(descriptor_get_global_vertices_count(desc, &nverts));
+ SENCXD(scene_get_vertices_count(senc3d_scn, &nverts));
/* Setup the vertex data */
vdata.usage = SXD_POSITION;
-#if DIM == 2
- vdata.type = S2D_FLOAT2;
-#else
- vdata.type = S3D_FLOAT3;
-#endif
- vdata.get = XD(descriptor_position);
+ vdata.type = SXD_FLOATX;
+ vdata.get = XD(scene_position);
/* Create the Star-XD geometry of the whole scene */
#define CALL(Func) { if(RES_OK != (res = Func)) goto error; } (void)0
+ sXd_dev = scn->dev->sXd(dev);
+ SENCXD(scene_get_primitives_count(senc3d_scn, &nprims));
#if DIM == 2
- sXd_dev = scn->dev->s2d;
- SENCXD(descriptor_get_global_segments_count(desc, &nprims));
CALL(sXd(shape_create_line_segments)(sXd_dev, &sXd_shape));
CALL(sXd(line_segments_set_hit_filter_function)(sXd_shape,
XD(hit_filter_function), NULL));
CALL(sXd(line_segments_setup_indexed_vertices)(sXd_shape, nprims,
- XD(descriptor_indices), nverts, &vdata, 1, desc));
+ XD(scene_indices), nverts, &vdata, 1, senc3d_scn));
#else
- sXd_dev = scn->dev->s3d;
- SENCXD(descriptor_get_global_triangles_count(desc, &nprims));
CALL(sXd(shape_create_mesh)(sXd_dev, &sXd_shape));
CALL(sXd(mesh_set_hit_filter_function)(sXd_shape, XD(hit_filter_function), NULL));
- CALL(sXd(mesh_setup_indexed_vertices)(sXd_shape, nprims, XD(descriptor_indices),
- nverts, &vdata, 1, desc));
+ CALL(sXd(mesh_setup_indexed_vertices)(sXd_shape, nprims, XD(scene_indices),
+ nverts, &vdata, 1, senc3d_scn));
#endif
CALL(sXd(scene_create)(sXd_dev, &sXd_scn));
CALL(sXd(scene_attach_shape)(sXd_scn, sXd_shape));
@@ -757,24 +708,15 @@ XD(setup_enclosure_geometry)(struct sdis_scene* scn, struct sencXd(enclosure)* e
float S, V;
double* p_ub;
unsigned iprim, nprims, nverts;
-#if DIM == 2
- struct senc2d_enclosure_header header;
-#else
- struct senc_enclosure_header header;
-#endif
+ struct sencXd(enclosure_header) header;
res_T res = RES_OK;
ASSERT(scn && enc);
enclosure_init(scn->dev->allocator, &enc_dummy);
SENCXD(enclosure_get_header(enc, &header));
-#if DIM == 2
- sXd_dev = scn->dev->s2d;
- nprims = header.segment_count;
-#else
- sXd_dev = scn->dev->s3d;
- nprims = header.triangle_count;
-#endif
+ sXd_dev = scn->dev->sXd(dev);
+ nprims = header.primitives_count;
nverts = header.vertices_count;
/* Register the enclosure into the scene. Use a dummy data on their
@@ -791,11 +733,7 @@ XD(setup_enclosure_geometry)(struct sdis_scene* scn, struct sencXd(enclosure)* e
/* Setup the vertex data */
vdata.usage = SXD_POSITION;
-#if DIM == 2
- vdata.type = S2D_FLOAT2;
-#else
- vdata.type = S3D_FLOAT3;
-#endif
+ vdata.type = SXD_FLOATX;
vdata.get = XD(enclosure_position);
/* Create the Star-XD geometry */
@@ -836,13 +774,8 @@ XD(setup_enclosure_geometry)(struct sdis_scene* scn, struct sencXd(enclosure)* e
if(res != RES_OK) goto error;
FOR_EACH(iprim, 0, nprims) {
enum sencXd(side) side;
-#if DIM == 2
- senc2d_enclosure_get_segment_global_id
- (enc, iprim, darray_uint_data_get(&enc_data->local2global)+iprim, &side);
-#else
- senc_enclosure_get_triangle_global_id
- (enc, iprim, darray_uint_data_get(&enc_data->local2global)+iprim, &side);
-#endif
+ SENCXD(enclosure_get_primitive_id
+ (enc, iprim, darray_uint_data_get(&enc_data->local2global)+iprim, &side));
}
/* Setup the medium id of the enclosure */
@@ -861,25 +794,21 @@ error:
/* Build the Star-XD scene view and define its associated data of the finite
* fluid enclosures */
static res_T
-XD(setup_enclosures)(struct sdis_scene* scn, struct sencXd(descriptor)* desc)
+XD(setup_enclosures)(struct sdis_scene* scn, struct sencXd(scene)* senc3d_scn)
{
struct sencXd(enclosure)* enc = NULL;
unsigned ienc, nencs;
unsigned enclosed_medium;
int outer_found = 0;
res_T res = RES_OK;
- ASSERT(scn && desc);
+ ASSERT(scn && senc3d_scn);
(void)outer_found;
- SENCXD(descriptor_get_enclosure_count(desc, &nencs));
+ SENCXD(scene_get_enclosure_count(senc3d_scn, &nencs));
FOR_EACH(ienc, 0, nencs) {
-#if DIM == 2
- struct senc2d_enclosure_header header;
-#else
- struct senc_enclosure_header header;
-#endif
+ struct sencXd(enclosure_header) header;
- SENCXD(descriptor_get_enclosure(desc, ienc, &enc));
+ SENCXD(scene_get_enclosure(senc3d_scn, ienc, &enc));
SENCXD(enclosure_get_header(enc, &header));
if(header.is_infinite) {
@@ -898,26 +827,23 @@ XD(setup_enclosures)(struct sdis_scene* scn, struct sencXd(descriptor)* desc)
unsigned i;
log_warn(scn->dev, "# Found internal enclosure with %u materials:\n",
header.enclosed_media_count);
- #if DIM == 2
FOR_EACH(i, 0, header.vertices_count) {
SENCXD(enclosure_get_vertex(enc, i, tmp));
+ #if DIM == 2
log_warn(scn->dev, "v %g %g\n", SPLIT2(tmp));
- }
- FOR_EACH(i, 0, header.segment_count) {
- ASSERT(senc2d_enclosure_get_segment(enc, i, indices) == RES_OK);
- log_warn(scn->dev, "f %u %u\n", indices[0]+1, indices[1]+1);
- }
#else
- FOR_EACH(i, 0, header.vertices_count) {
- SENCXD(enclosure_get_vertex(enc, i, tmp));
log_warn(scn->dev, "v %g %g %g\n", SPLIT3(tmp));
+ #endif
}
- FOR_EACH(i, 0, header.triangle_count) {
- ASSERT(senc_enclosure_get_triangle(enc, i, indices) == RES_OK);
+ FOR_EACH(i, 0, header.primitives_count) {
+ SENCXD(enclosure_get_primitive(enc, i, indices));
+ #if DIM == 2
+ log_warn(scn->dev, "f %u %u\n", indices[0]+1, indices[1]+1);
+ #else
log_warn(scn->dev, "f %u %u %u\n",
indices[0]+1, indices[1]+1, indices[2]+1);
- }
#endif
+ }
#else
log_warn(scn->dev, "Found internal enclosure with %u materials.\n",
header.enclosed_media_count);
@@ -961,7 +887,7 @@ XD(scene_create)
void* ctx,
struct sdis_scene** out_scn)
{
- struct sencXd(descriptor)* desc = NULL;
+ struct sencXd(scene)* senc3d_scn = NULL;
struct sdis_scene* scn = NULL;
res_T res = RES_OK;
@@ -988,38 +914,34 @@ XD(scene_create)
htable_enclosure_init(dev->allocator, &scn->enclosures);
htable_d_init(dev->allocator, &scn->tmp_hc_ub);
- res = XD(run_analyze)(scn, nprims, indices, interf, nverts, position, ctx, &desc);
+ res = XD(run_analyze)(scn, nprims, indices, interf, nverts, position, ctx, &senc3d_scn);
if(res != RES_OK) {
log_err(dev, "%s: error during the scene analysis.\n", FUNC_NAME);
goto error;
}
- res = XD(setup_properties)(scn, desc, interf, ctx);
+ res = XD(setup_properties)(scn, senc3d_scn, interf, ctx);
if(res != RES_OK) {
log_err(dev, "%s: could not setup the scene interfaces and their media.\n",
FUNC_NAME);
goto error;
}
- res = XD(setup_scene_geometry)(scn, desc);
+ res = XD(setup_scene_geometry)(scn, senc3d_scn);
if(res != RES_OK) {
log_err(dev, "%s: could not setup the scene geometry.\n", FUNC_NAME);
goto error;
}
- res = XD(setup_enclosures)(scn, desc);
+ res = XD(setup_enclosures)(scn, senc3d_scn);
if(res != RES_OK) {
log_err(dev, "%s: could not setup the enclosures.\n", FUNC_NAME);
goto error;
}
-#if DIM==2
- scn->senc2d_descriptor = desc;
-#else
- scn->senc_descriptor = desc;
-#endif
+ scn->sencXd(scn) = senc3d_scn;
exit:
if(out_scn) *out_scn = scn;
return res;
error:
- if(desc) SENCXD(descriptor_ref_put(desc));
+ if(senc3d_scn) SENCXD(scene_ref_put(senc3d_scn));
if(scn) {
SDIS(scene_ref_put(scn));
scn = NULL;
@@ -1237,10 +1159,14 @@ error:
goto exit;
}
+#if (SDIS_SCENE_DIMENSION == 2)
+#include <star/sencX2d_undefs.h>
+#else /* SDIS_SCENE_DIMENSION == 3 */
+#include <star/sencX3d_undefs.h>
+#endif
+
#undef SDIS_SCENE_DIMENSION
#undef DIM
-#undef sencXd
-#undef SENCXD
#undef sXd
#undef SXD
#undef SXD_VERTEX_DATA_NULL
@@ -1251,6 +1177,7 @@ error:
#undef SXD_GET_PRIMITIVE
#undef SXD_HIT_NONE
#undef SXD_PRIMITIVE_EQ
+#undef SXD_FLOATX
#undef fX
#undef fX_set_dX
#undef fXX_mulfX
diff --git a/src/sdis_scene_c.h b/src/sdis_scene_c.h
@@ -200,8 +200,8 @@ struct sdis_scene {
struct darray_prim_prop prim_props; /* Per primitive properties */
struct s2d_scene_view* s2d_view;
struct s3d_scene_view* s3d_view;
- struct senc_descriptor* senc_descriptor;
- struct senc2d_descriptor* senc2d_descriptor;
+ struct senc2d_scene* senc2d_scn;
+ struct senc3d_scene* senc3d_scn;
struct htable_d tmp_hc_ub; /* Map an enclosure id to its hc upper bound */
struct htable_enclosure enclosures; /* Map an enclosure id to its data */
diff --git a/src/sdis_solve_boundary_Xd.h b/src/sdis_solve_boundary_Xd.h
@@ -62,12 +62,11 @@ XD(boundary_get_position)(const unsigned ivert, float pos[DIM], void* context)
iprim = (unsigned)ctx->primitives[iprim_id];
SXD(scene_view_get_primitive(ctx->view, iprim, &prim));
#if DIM == 2
- s2d_segment_get_vertex_attrib(&prim, iprim_vert, S2D_POSITION, &attr);
- ASSERT(attr.type == S2D_FLOAT2);
+ s2d_segment_get_vertex_attrib(&prim, iprim_vert, SXD_POSITION, &attr);
#else
- s3d_triangle_get_vertex_attrib(&prim, iprim_vert, S3D_POSITION, &attr);
- ASSERT(attr.type == S3D_FLOAT3);
+ s3d_triangle_get_vertex_attrib(&prim, iprim_vert, SXD_POSITION, &attr);
#endif
+ ASSERT(attr.type == SXD_FLOATX);
fX(set)(pos, attr.value);
}
@@ -144,9 +143,9 @@ XD(solve_boundary)
/* Create the Star-XD shape of the boundary */
#if SDIS_XD_DIMENSION == 2
- res = s2d_shape_create_line_segments(scn->dev->sXd_dev, &shape);
+ res = s2d_shape_create_line_segments(scn->dev->sXd(dev), &shape);
#else
- res = s3d_shape_create_mesh(scn->dev->sXd_dev, &shape);
+ res = s3d_shape_create_mesh(scn->dev->sXd(dev), &shape);
#endif
if(res != RES_OK) goto error;
@@ -168,7 +167,7 @@ XD(solve_boundary)
if(res != RES_OK) goto error;
/* Create and setup the boundary Star-XD scene */
- res = sXd(scene_create)(scn->dev->sXd_dev, &scene);
+ res = sXd(scene_create)(scn->dev->sXd(dev), &scene);
if(res != RES_OK) goto error;
res = sXd(scene_attach_shape)(scene, shape);
if(res != RES_OK) goto error;
@@ -438,9 +437,9 @@ XD(solve_boundary_flux)
/* Create the Star-XD shape of the boundary */
#if SDIS_XD_DIMENSION == 2
- res = s2d_shape_create_line_segments(scn->dev->s2d, &shape);
+ res = s2d_shape_create_line_segments(scn->dev->sXd(dev), &shape);
#else
- res = s3d_shape_create_mesh(scn->dev->s3d, &shape);
+ res = s3d_shape_create_mesh(scn->dev->sXd(dev), &shape);
#endif
if(res != RES_OK) goto error;
@@ -463,7 +462,7 @@ XD(solve_boundary_flux)
if(res != RES_OK) goto error;
/* Create and setup the boundary Star-XD scene */
- res = sXd(scene_create)(scn->dev->sXd_dev, &scene);
+ res = sXd(scene_create)(scn->dev->sXd(dev), &scene);
if(res != RES_OK) goto error;
res = sXd(scene_attach_shape)(scene, shape);
if(res != RES_OK) goto error;
diff --git a/src/test_sdis_scene.c b/src/test_sdis_scene.c
@@ -19,8 +19,8 @@
#include <rsys/double2.h>
#include <rsys/double3.h>
#include <rsys/math.h>
-#include<star/senc.h>
#include<star/senc2d.h>
+#include<star/senc3d.h>
struct context {
const double* positions;
@@ -93,10 +93,14 @@ test_scene_3d(struct sdis_device* dev, struct sdis_interface* interf)
double lower[3], upper[3];
double uv0[2], uv1[2], pos[3], pos1[3];
struct context ctx;
- struct senc_descriptor* descriptor;
- struct senc2d_descriptor* descriptor2d;
+ struct senc2d_scene* scn2d;
+ struct senc3d_scene* scn3d;
size_t ntris, npos;
size_t i;
+ size_t duplicated_indices[] = { 0, 1, 2, 0, 2, 1 };
+ size_t degenerated_indices[] = { 0, 1, 1 };
+ double duplicated_vertices[] = { 0, 0, 0, 1, 1, 1, 0, 0, 0 };
+ size_t dup_vrtx_indices[] = { 0, 1, 2 };
enum sdis_scene_dimension dim;
ctx.positions = box_vertices;
@@ -116,6 +120,20 @@ test_scene_3d(struct sdis_device* dev, struct sdis_interface* interf)
BA(CREATE(dev, ntris, IDS, NULL, npos, POS, &ctx, &scn));
BA(CREATE(dev, ntris, IDS, IFA, 0, POS, &ctx, &scn));
BA(CREATE(dev, ntris, IDS, IFA, npos, NULL, &ctx, &scn));
+ /* Duplicated vertex */
+ ctx.positions = duplicated_vertices;
+ ctx.indices = dup_vrtx_indices;
+ BA(CREATE(dev, 1, IDS, IFA, npos, POS, &ctx, &scn));
+ /* Duplicated triangle */
+ ctx.positions = box_vertices;
+ ctx.indices = duplicated_indices;
+ BA(CREATE(dev, 2, IDS, IFA, npos, POS, &ctx, &scn));
+ /* Degenerated triangle */
+ ctx.indices = degenerated_indices;
+ BA(CREATE(dev, 1, IDS, IFA, npos, POS, &ctx, &scn));
+
+ ctx.positions = box_vertices;
+ ctx.indices = box_indices;
OK(CREATE(dev, ntris, IDS, IFA, npos, POS, &ctx, &scn));
#undef CREATE
@@ -172,19 +190,13 @@ test_scene_3d(struct sdis_device* dev, struct sdis_interface* interf)
OK(sdis_scene_get_boundary_position(scn, 6, uv1, pos1));
CHK(!d3_eq_eps(pos1, pos, 1.e-6));
- BA(sdis_scene_get_analysis(NULL, NULL));
- BA(sdis_scene_get_analysis(scn, NULL));
- BA(sdis_scene_get_analysis(NULL, &descriptor));
- OK(sdis_scene_get_analysis(scn, &descriptor));
- OK(senc_descriptor_ref_put(descriptor));
+ BA(sdis_scene_get_senc3d_scene(NULL, NULL));
+ BA(sdis_scene_get_senc3d_scene(scn, NULL));
+ BA(sdis_scene_get_senc3d_scene(NULL, &scn3d));
+ OK(sdis_scene_get_senc3d_scene(scn, &scn3d));
+ OK(senc3d_scene_ref_put(scn3d));
/* No 2D available */
- BA(sdis_scene_2d_get_analysis(scn, &descriptor2d));
- BA(sdis_scene_release_analysis(NULL));
- OK(sdis_scene_release_analysis(scn));
- /* Already released */
- OK(sdis_scene_release_analysis(scn));
- /* Descriptor released: cannot get it anymore */
- BA(sdis_scene_get_analysis(scn, &descriptor));
+ BA(sdis_scene_get_senc2d_scene(scn, &scn2d));
BA(sdis_scene_ref_get(NULL));
OK(sdis_scene_ref_get(scn));
@@ -200,10 +212,14 @@ test_scene_2d(struct sdis_device* dev, struct sdis_interface* interf)
double lower[2], upper[2];
double u0, u1, pos[2];
struct context ctx;
- struct senc2d_descriptor* descriptor;
- struct senc_descriptor* descriptor3d;
+ struct senc2d_scene* scn2d;
+ struct senc3d_scene* scn3d;
size_t nsegs, npos;
size_t i;
+ size_t duplicated_indices[] = { 0, 1, 1, 0 };
+ size_t degenerated_indices[] = { 0, 0 };
+ double duplicated_vertices[] = { 0, 0, 0, 0 };
+ size_t dup_vrtx_indices[] = { 0, 1 };
enum sdis_scene_dimension dim;
ctx.positions = square_vertices;
@@ -223,6 +239,20 @@ test_scene_2d(struct sdis_device* dev, struct sdis_interface* interf)
BA(CREATE(dev, nsegs, IDS, NULL, npos, POS, &ctx, &scn));
BA(CREATE(dev, nsegs, IDS, IFA, 0, POS, &ctx, &scn));
BA(CREATE(dev, nsegs, IDS, IFA, npos, NULL, &ctx, &scn));
+ /* Duplicated vertex */
+ ctx.positions = duplicated_vertices;
+ ctx.indices = dup_vrtx_indices;
+ BA(CREATE(dev, 1, IDS, IFA, npos, POS, &ctx, &scn));
+ /* Duplicated segment */
+ ctx.positions = square_vertices;
+ ctx.indices = duplicated_indices;
+ BA(CREATE(dev, 2, IDS, IFA, npos, POS, &ctx, &scn));
+ /* Degenerated segment */
+ ctx.indices = degenerated_indices;
+ BA(CREATE(dev, 1, IDS, IFA, npos, POS, &ctx, &scn));
+
+ ctx.positions = square_vertices;
+ ctx.indices = square_indices;
OK(CREATE(dev, nsegs, IDS, IFA, npos, POS, &ctx, &scn));
#undef CREATE
@@ -280,20 +310,18 @@ test_scene_2d(struct sdis_device* dev, struct sdis_interface* interf)
OK(sdis_scene_boundary_project_position(scn, 3, pos, &u0));
CHK(eq_eps(u0, 1, 1.e-6));
- BA(sdis_scene_2d_get_analysis(NULL, NULL));
- BA(sdis_scene_2d_get_analysis(scn, NULL));
- BA(sdis_scene_2d_get_analysis(NULL, &descriptor));
- OK(sdis_scene_2d_get_analysis(scn, &descriptor));
- OK(senc2d_descriptor_ref_put(descriptor));
+ BA(sdis_scene_get_senc2d_scene(NULL, NULL));
+ BA(sdis_scene_get_senc2d_scene(scn, NULL));
+ BA(sdis_scene_get_senc2d_scene(NULL, &scn2d));
+ OK(sdis_scene_get_senc2d_scene(scn, &scn2d));
+ OK(senc2d_scene_ref_put(scn2d));
/* No 3D available */
- BA(sdis_scene_get_analysis(scn, &descriptor3d));
- BA(sdis_scene_release_analysis(NULL));
- OK(sdis_scene_release_analysis(scn));
- /* Already released */
- OK(sdis_scene_release_analysis(scn));
- /* Descriptor released: cannot get it anymore */
- BA(sdis_scene_2d_get_analysis(scn, &descriptor));
+ BA(sdis_scene_get_senc3d_scene(scn, &scn3d));
+ BA(sdis_scene_ref_get(NULL));
+ OK(sdis_scene_ref_get(scn));
+ BA(sdis_scene_ref_put(NULL));
+ OK(sdis_scene_ref_put(scn));
OK(sdis_scene_ref_put(scn));
}