star-geometry-3d

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

test_sg3d_utils2.h (2306B)


      1 /* Copyright (C) 2019, 2020, 2023, 2024 |Méso|Star> (contact@meso-star.com)
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #ifndef TEST_SG3D_UTILS2_H
     17 #define TEST_SG3D_UTILS2_H
     18 
     19 #include <star/sg3d.h>
     20 
     21 #include <rsys/double3.h>
     22 #include <star/s3dut.h>
     23 
     24 struct s3dut_context {
     25   struct s3dut_mesh_data data;
     26   struct context ctx;
     27 };
     28 
     29 static INLINE void
     30 get_s3dut_indices(const unsigned itri, unsigned ids[3], void* context)
     31 {
     32   const struct s3dut_context* ctx = context;
     33   ASSERT(ids && ctx);
     34   ASSERT(itri < ctx->data.nprimitives);
     35   ASSERT(ctx->data.indices[itri * 3 + 0] < UINT_MAX
     36     && ctx->data.indices[itri * 3 + 1] < UINT_MAX
     37     && ctx->data.indices[itri * 3 + 2] < UINT_MAX);
     38   ids[0] = (unsigned)ctx->data.indices[itri * 3 + 0];
     39   ids[ctx->ctx.reverse_vrtx ? 2 : 1] = (unsigned)ctx->data.indices[itri * 3 + 1];
     40   ids[ctx->ctx.reverse_vrtx ? 1 : 2] = (unsigned)ctx->data.indices[itri * 3 + 2];
     41 }
     42 
     43 static INLINE void
     44 get_s3dut_position(const unsigned ivert, double pos[3], void* context)
     45 {
     46   const struct s3dut_context* ctx = context;
     47   double tmp[3];
     48   ASSERT(pos && ctx);
     49   ASSERT(ivert < ctx->data.nvertices);
     50   (void)ivert;
     51   d3_add(pos, d3_mul(tmp, ctx->data.positions + ivert * 3, ctx->ctx.scale),
     52     ctx->ctx.offset);
     53 }
     54 
     55 static INLINE void
     56 get_s3dut_properties
     57   (const unsigned itri,
     58    unsigned property[SG3D_PROP_TYPES_COUNT__],
     59    void* context)
     60 {
     61   const struct s3dut_context* ctx = context;
     62   ASSERT(property && ctx);
     63   (void)itri;
     64   property[ctx->ctx.reverse_med ? SG3D_BACK : SG3D_FRONT] = *ctx->ctx.front_media;
     65   property[ctx->ctx.reverse_med ? SG3D_FRONT : SG3D_BACK] = *ctx->ctx.back_media;
     66   property[SG3D_INTFACE] = *ctx->ctx.intface;
     67 }
     68 
     69 #endif /* TEST_SG3D_UTILS2_H */