star-camera

Camera models
git clone git://git.meso-star.fr/star-camera.git
Log | Files | Refs | README | LICENSE

test_scam_cbox.h (4131B)


      1 /* Copyright (C) 2021-2023 |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_SCAM_CBOX_H
     17 #define TEST_SCAM_CBOX_H
     18 
     19 #include <rsys/rsys.h>
     20 
     21 /*******************************************************************************
     22  * Mesh & properties
     23  ******************************************************************************/
     24 static const float cbox_vtxs[] = {
     25   /* Walls */
     26   552.f, 0.f,   0.f,
     27   0.f,   0.f,   0.f,
     28   0.f,   559.f, 0.f,
     29   552.f, 559.f, 0.f,
     30   552.f, 0.f,   548.f,
     31   0.f,   0.f,   548.f,
     32   0.f,   559.f, 548.f,
     33   552.f, 559.f, 548.f,
     34 
     35   /* Short block */
     36   130.f, 65.f,  0.f,
     37   82.f,  225.f, 0.f,
     38   240.f, 272.f, 0.f,
     39   290.f, 114.f, 0.f,
     40   130.f, 65.f,  165.f,
     41   82.f,  225.f, 165.f,
     42   240.f, 272.f, 165.f,
     43   290.f, 114.f, 165.f,
     44 
     45   /* Tall block */
     46   423.0f, 247.0f, 0.f,
     47   265.0f, 296.0f, 0.f,
     48   314.0f, 456.0f, 0.f,
     49   472.0f, 406.0f, 0.f,
     50   423.0f, 247.0f, 330.f,
     51   265.0f, 296.0f, 330.f,
     52   314.0f, 456.0f, 330.f,
     53   472.0f, 406.0f, 330.f
     54 };
     55 const unsigned cbox_tris[] = {
     56   /* Walls */
     57   0, 1, 2, 2, 3, 0, /* Bottom */
     58   4, 5, 6, 6, 7, 4, /* Top */
     59   1, 2, 6, 6, 5, 1, /* Left */
     60   0, 3, 7, 7, 4, 0, /* Right */
     61   2, 3, 7, 7, 6, 2,  /* Back */
     62 
     63   /* Short block */
     64   12, 13, 14, 14, 15, 12,
     65   9, 10, 14, 14, 13, 9,
     66   8, 11, 15, 15, 12, 8,
     67   10, 11, 15, 15, 14, 10,
     68   8, 9, 13, 13, 12, 8,
     69 
     70   /* Tall block */
     71   20, 21, 22, 22, 23, 20,
     72   17, 18, 22, 22, 21, 17,
     73   16, 19, 23, 23, 20, 16,
     74   18, 19, 23, 23, 22, 18,
     75   16, 17, 21, 21, 20, 16
     76 };
     77 
     78 #define WHITE 1.0,1.0,1.0
     79 #define RED   1.0,0.0,0.0
     80 #define GREEN 0.0,1.0,0.0
     81 
     82 const double cbox_cols[] = {
     83   /* Walls */
     84   WHITE, WHITE, /* Bottom */
     85   WHITE, WHITE, /* Top */
     86   RED, RED, /* Left */
     87   GREEN, GREEN, /* Right */
     88   WHITE, WHITE, /* Back */
     89 
     90   /* Short block */
     91   WHITE, WHITE,
     92   WHITE, WHITE,
     93   WHITE, WHITE,
     94   WHITE, WHITE,
     95   WHITE, WHITE,
     96 
     97   /* Tall block */
     98   WHITE, WHITE,
     99   WHITE, WHITE,
    100   WHITE, WHITE,
    101   WHITE, WHITE,
    102   WHITE, WHITE
    103 };
    104 
    105 #undef WHITE
    106 #undef RED
    107 #undef GREEN
    108 
    109 const unsigned cbox_nvtxs = sizeof(cbox_vtxs) / (sizeof(float)*3);
    110 const unsigned cbox_ntris = sizeof(cbox_tris) / (sizeof(unsigned)*3);
    111 STATIC_ASSERT
    112   (  sizeof(cbox_tris)/(sizeof(unsigned)*3)
    113   == sizeof(cbox_cols)/(sizeof(double)*3), Unexpected_data_layout);
    114 
    115 /*******************************************************************************
    116  * Functions
    117  ******************************************************************************/
    118 static INLINE void
    119 cbox_get_vtx(const unsigned ivtx, float vtx[3], void* data)
    120 {
    121   const unsigned id = ivtx * 3;
    122   (void)data;
    123   CHK(ivtx < cbox_nvtxs);
    124   vtx[0] = cbox_vtxs[id+0];
    125   vtx[1] = cbox_vtxs[id+1];
    126   vtx[2] = cbox_vtxs[id+2];
    127 }
    128 
    129 static INLINE void
    130 cbox_get_tri(const unsigned itri, unsigned tri[3], void* data)
    131 {
    132   const unsigned id = itri * 3;
    133   (void)data;
    134   CHK(itri < cbox_ntris);
    135   tri[0] = cbox_tris[id+0];
    136   tri[1] = cbox_tris[id+1];
    137   tri[2] = cbox_tris[id+2];
    138 }
    139 
    140 static INLINE void
    141 cbox_get_col(const unsigned itri, double col[3])
    142 {
    143   const unsigned id = itri * 3;
    144   CHK(itri < cbox_ntris);
    145   col[0] = cbox_cols[id+0];
    146   col[1] = cbox_cols[id+1];
    147   col[2] = cbox_cols[id+2];
    148 }
    149 
    150 static INLINE void
    151 cbox_dump(FILE* stream)
    152 {
    153   unsigned i;
    154 
    155   FOR_EACH(i, 0, cbox_nvtxs) {
    156     fprintf(stream, "v %g %g %g\n",
    157       cbox_vtxs[i*3+0],
    158       cbox_vtxs[i*3+1],
    159       cbox_vtxs[i*3+2]);
    160   }
    161 
    162   FOR_EACH(i, 0, cbox_ntris) {
    163     fprintf(stream, "f %u %u %u\n",
    164       cbox_tris[i*3+0]+1,
    165       cbox_tris[i*3+1]+1,
    166       cbox_tris[i*3+2]+1);
    167   }
    168 }
    169 
    170 #endif /* TEST_SCAM_CBOX_H */