commit 69aa9c39de08716202c9211a34ecf888c9f4a9f9
parent 27c3ed4a4b257ff403ad8dca61d88bd7aae35fb0
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 24 Jan 2020 16:41:25 +0100
Factorize some test code
Diffstat:
2 files changed, 14 insertions(+), 147 deletions(-)
diff --git a/src/test_senc_many_enclosures.c b/src/test_senc_many_enclosures.c
@@ -17,8 +17,15 @@
* cylinders instead of 4*4*4, thus making it impossible to define the geometry
* through static arrays. */
+#define NB_CYL_X 64
+#define NB_CYL_Y 64
+#define NB_CYL_Z 64
+ /* 64^3 = 262144 cylinders */
+#define NB_CYL (NB_CYL_X * NB_CYL_Y * NB_CYL_Z)
+
#include "senc.h"
#include "test_senc_utils.h"
+#include "test_senc_utils2.h"
#include <star/s3dut.h>
#include <rsys/clock_time.h>
@@ -27,91 +34,6 @@
#include <stdio.h>
#include <limits.h>
-#define NB_CYL_X 64
-#define NB_CYL_Y 64
-#define NB_CYL_Z 64
-#define NB_CYL (NB_CYL_X * NB_CYL_Y * NB_CYL_Z)
-
-struct s3dut_context {
- struct s3dut_mesh_data data;
- struct context ctx;
-};
-
-static void
-get_s3dut_indices(const unsigned itri, unsigned ids[3], void* context)
-{
- struct s3dut_context* ctx = context;
- unsigned s3dut_itri, cyl_idx, v_offset;
- ASSERT(ids && ctx);
- ASSERT(itri < NB_CYL * ctx->data.nprimitives);
- /* Get cyl_idx along with the s3dut vertice index */
- s3dut_itri = itri % (unsigned)ctx->data.nprimitives;
- cyl_idx = itri / (unsigned)ctx->data.nprimitives;
- ASSERT(ctx->data.indices[s3dut_itri * 3 + 0] <= UINT_MAX
- && ctx->data.indices[s3dut_itri * 3 + 1] <= UINT_MAX
- && ctx->data.indices[s3dut_itri * 3 + 2] <= UINT_MAX);
- /* Compute the vertex index in the user numbering
- * from cyl_idx and s3dut data; vertex related getters
- * will have to get the s3dut index back */
- v_offset = cyl_idx * (unsigned)ctx->data.nvertices;
- ids[0] = v_offset + (unsigned)ctx->data.indices[s3dut_itri * 3 + 0];
- ids[ctx->ctx.reverse_vrtx ? 2 : 1]
- = v_offset + (unsigned)ctx->data.indices[s3dut_itri * 3 + 1];
- ids[ctx->ctx.reverse_vrtx ? 1 : 2]
- = v_offset + (unsigned)ctx->data.indices[s3dut_itri * 3 + 2];
-}
-
-static void
-get_s3dut_position(const unsigned ivert, double pos[3], void* context)
-{
- struct s3dut_context* ctx = context;
- unsigned s3dut_ivert, cyl_idx;
- int i, j, k;
- double offset[3], tmp[3];
- double center_x, center_y, scale, misalignment = 0;
- ASSERT(pos && ctx);
- ASSERT(ivert < NB_CYL * ctx->data.nvertices);
- /* Get cyl_idx and cylinder imbrication along with the s3dut vertice index */
- s3dut_ivert = ivert % (unsigned)ctx->data.nvertices;
- cyl_idx = ivert / (unsigned)ctx->data.nvertices;
- /* k th cylinder of the imbrication at grid position i,j */
- i = (int)cyl_idx / (NB_CYL_Y * NB_CYL_Z);
- j = (cyl_idx / NB_CYL_Z ) % NB_CYL_Y;
- k = cyl_idx % NB_CYL_Z;
- ASSERT(i < NB_CYL_X && j < NB_CYL_Y && k < NB_CYL_Z);
- ASSERT((unsigned)(i * NB_CYL_Y * NB_CYL_Z + j * NB_CYL_Z + k)
- * ctx->data.nvertices + s3dut_ivert == ivert);
- center_x = 2 * (1 + NB_CYL_X) * (i - NB_CYL_X / 2);
- center_y = 2 * (1 + NB_CYL_Y) * (j - NB_CYL_Y / 2);
- /* Compute scale and offset from imbrication */
- scale = k + 1;
-#ifdef MITIGATE_EMBREE_181
- /* Mitigate Embree issue #181
- * We cannot keep perfect alignment of cylinders
- * or some hits are missed */
- misalignment = (k % 2) ? -0.01 : +0.01;
-#endif
- d3(offset, center_x + misalignment, center_y + misalignment, 0);
- d3_add(pos, d3_muld(tmp, ctx->data.positions + s3dut_ivert * 3, scale),
- offset);
-}
-
-static void
-get_s3dut_media(const unsigned itri, unsigned medium[2], void* context)
-{
- struct s3dut_context* ctx = context;
- unsigned cyl_idx;
- int k;
- ASSERT(medium && ctx);
- ASSERT(itri < NB_CYL * ctx->data.nprimitives);
- /* Get cyl_idx */
- cyl_idx = itri / (unsigned)ctx->data.nprimitives;
- /* k th cylinder of the imbrication at some grid position */
- k = cyl_idx % NB_CYL_Z;
- medium[ctx->ctx.reverse_med ? SENC_BACK : SENC_FRONT] = (unsigned)k;
- medium[ctx->ctx.reverse_med ? SENC_FRONT : SENC_BACK] = (unsigned)(k + 1);
-}
-
int
main(int argc, char** argv)
{
diff --git a/src/test_senc_many_triangles.c b/src/test_senc_many_triangles.c
@@ -17,8 +17,15 @@
* triangles instead of 4*1054, thus making it impossible to define the geometry
* through static arrays. */
+#define NB_CYL_X 2
+#define NB_CYL_Y 2
+#define NB_CYL_Z 1
+ /* 4 cylinders */
+#define NB_CYL (NB_CYL_X * NB_CYL_Y * NB_CYL_Z)
+
#include "senc.h"
#include "test_senc_utils.h"
+#include "test_senc_utils2.h"
#include <star/s3dut.h>
#include <rsys/clock_time.h>
@@ -27,68 +34,6 @@
#include <stdio.h>
#include <limits.h>
-#define NB_CYL 4
-
-struct s3dut_context {
- struct s3dut_mesh_data data;
- struct context ctx;
-};
-
-static void
-get_s3dut_indices(const unsigned itri, unsigned ids[3], void* context)
-{
- struct s3dut_context* ctx = context;
- unsigned s3dut_itri, cyl_idx, v_offset;
- ASSERT(ids && ctx);
- ASSERT(itri < NB_CYL * ctx->data.nprimitives);
- /* Get cyl_idx along with the s3dut vertice index */
- s3dut_itri = itri % (unsigned)ctx->data.nprimitives;
- cyl_idx = itri / (unsigned)ctx->data.nprimitives;
- ASSERT(ctx->data.indices[s3dut_itri * 3 + 0] <= UINT_MAX
- && ctx->data.indices[s3dut_itri * 3 + 1] <= UINT_MAX
- && ctx->data.indices[s3dut_itri * 3 + 2] <= UINT_MAX);
- /* Compute the vertex index in the user numbering
- * from cyl_idx and s3dut data; vertex related getters
- * will have to get the s3dut index back */
- v_offset = cyl_idx * (unsigned)ctx->data.nvertices;
- ids[0] = v_offset + (unsigned)ctx->data.indices[s3dut_itri * 3 + 0];
- ids[ctx->ctx.reverse_vrtx ? 2 : 1]
- = v_offset + (unsigned)ctx->data.indices[s3dut_itri * 3 + 1];
- ids[ctx->ctx.reverse_vrtx ? 1 : 2]
- = v_offset + (unsigned)ctx->data.indices[s3dut_itri * 3 + 2];
-}
-
-static void
-get_s3dut_position(const unsigned ivert, double pos[3], void* context)
-{
- struct s3dut_context* ctx = context;
- unsigned s3dut_ivert, cyl_idx;
- double offset[3], tmp[3];
- ASSERT(pos && ctx);
- ASSERT(ivert < NB_CYL * ctx->data.nvertices);
- /* Get cyl_idx along with the s3dut vertice index */
- s3dut_ivert = ivert % (unsigned)ctx->data.nvertices;
- cyl_idx = ivert / (unsigned)ctx->data.nvertices;
- /* Compute offset from cyl_idx */
- d3(offset, 0, 0, cyl_idx * 10);
- d3_add(pos, d3_muld(tmp, ctx->data.positions + s3dut_ivert * 3, ctx->ctx.scale),
- offset);
-}
-
-static void
-get_s3dut_media(const unsigned itri, unsigned medium[2], void* context)
-{
- struct s3dut_context* ctx = context;
- unsigned cyl_idx;
- ASSERT(medium && ctx);
- ASSERT(itri < NB_CYL * ctx->data.nprimitives);
- /* Get cyl_idx from itri */
- cyl_idx = itri / (unsigned)ctx->data.nprimitives;
- /* Compute front medium from cyl_idx */
- medium[ctx->ctx.reverse_med ? SENC_BACK : SENC_FRONT] = cyl_idx;
- medium[ctx->ctx.reverse_med ? SENC_FRONT : SENC_BACK] = *ctx->ctx.back_media;
-}
-
int
main(int argc, char** argv)
{