star-gf

Compute Gebhart factors
git clone git://git.meso-star.fr/star-gf.git
Log | Files | Refs | README | LICENSE

test_sgf_scene.c (6722B)


      1 /* Copyright (C) 2021, 2024 |Meso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2015-2018 EDF S.A., France (syrthes-support@edf.fr)
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     16 
     17 #include "sgf.h"
     18 #include "test_sgf_utils.h"
     19 
     20 /*******************************************************************************
     21  * Plane data
     22  ******************************************************************************/
     23 static const float plane_verts[] = {
     24   0.f, 0.f, 0.f,
     25   1.f, 0.f, 0.f,
     26   0.f, 1.f, 0.f,
     27   1.f, 1.f, 0.f,
     28 };
     29 static const size_t plane_nverts = sizeof(plane_verts) / (3*sizeof(float));
     30 static const unsigned plane_ids[] = { 0, 2, 1, 1, 2, 3 };
     31 static const size_t plane_nprims = sizeof(plane_ids) / (3*sizeof(unsigned));
     32 static const double plane_emi[] = { 0.6, 0.6 };
     33 static const double plane_emi_bad[] = { 0.6, 1.1 };
     34 static const double plane_spec[] = { 0.0, 0.0 };
     35 static const double plane_spec_bad[] = { 1.1, 0.0 };
     36 static const double plane_abs[] = { 0.0, 0.0 };
     37 static const double plane_abs_bad[] = { -0.1, 0.0 };
     38 
     39 /*******************************************************************************
     40  * Square data
     41  ******************************************************************************/
     42 static const float square_verts[] = {
     43   1.f, 0.f,
     44   0.f, 0.f,
     45   0.f, 1.f,
     46   1.f, 1.f
     47 };
     48 const unsigned square_nverts = sizeof(square_verts)/(2*sizeof(float));
     49 const unsigned square_ids[] = {
     50   0, 1, /* Bottom */
     51   1, 2, /* Left */
     52   2, 3, /* Top */
     53   3, 0  /* Right */
     54 };
     55 const unsigned square_nprims = sizeof(square_ids)/(2*sizeof(unsigned));
     56 static const double square_emi[] = {
     57   1.0, /* Bottom */
     58   1.0, /* Left */
     59   1.0, /* Top */
     60   1.0  /* Right */
     61 };
     62 static const double square_spec[] = {
     63   0.0, /* Bottom */
     64   0.0, /* Left */
     65   0.0, /* Top */
     66   0.0  /* Right */
     67 };
     68 
     69 /*******************************************************************************
     70  * Test function
     71  ******************************************************************************/
     72 int
     73 main(int argc, char** argv)
     74 {
     75   struct mem_allocator allocator;
     76   struct sgf_device* sgf;
     77   struct sgf_scene* scn;
     78   struct sgf_scene_desc desc = SGF_SCENE_DESC_NULL;
     79   struct shape_context shape;
     80   unsigned n;
     81   (void)argc, (void)argv;
     82 
     83   mem_init_proxy_allocator(&allocator, &mem_default_allocator);
     84 
     85   CHK(sgf_device_create(NULL, &allocator, 1, &sgf) == RES_OK);
     86 
     87   CHK(sgf_scene_create(NULL, NULL) == RES_BAD_ARG);
     88   CHK(sgf_scene_create(sgf, NULL) == RES_BAD_ARG);
     89   CHK(sgf_scene_create(NULL, &scn) == RES_BAD_ARG);
     90   CHK(sgf_scene_create(sgf, &scn) == RES_OK);
     91 
     92   shape.emissivity = plane_emi;
     93   shape.specularity = plane_spec;
     94   shape.vertices = plane_verts;
     95   shape.nvertices = plane_nverts;
     96   shape.indices = plane_ids;
     97   shape.nprimitives = plane_nprims;
     98   shape.dim = 3;
     99 
    100   desc.get_position = get_position;
    101   desc.get_indices = get_indices;
    102   desc.get_emissivity = get_emissivity;
    103   desc.get_reflectivity = get_reflectivity;
    104   desc.get_specularity = get_specularity;
    105   desc.context = &shape;
    106   desc.nprims = (unsigned)plane_nprims;
    107   desc.nverts = (unsigned)plane_nverts;
    108   desc.nbands = 1;
    109 
    110   CHK(sgf_scene_setup_3d(NULL, NULL) == RES_BAD_ARG);
    111   CHK(sgf_scene_setup_3d(scn, NULL) == RES_BAD_ARG);
    112   CHK(sgf_scene_setup_3d(NULL, &desc) == RES_BAD_ARG);
    113   CHK(sgf_scene_setup_3d(scn, &desc) == RES_OK);
    114 
    115   CHK(sgf_scene_primitives_count(NULL, NULL) == RES_BAD_ARG);
    116   CHK(sgf_scene_primitives_count(scn, NULL) == RES_BAD_ARG);
    117   CHK(sgf_scene_primitives_count(NULL, &n) == RES_BAD_ARG);
    118   CHK(sgf_scene_primitives_count(scn, &n) == RES_OK);
    119   CHK(n == 2);
    120 
    121   desc.get_position = NULL;
    122   CHK(sgf_scene_setup_3d(scn, &desc) == RES_BAD_ARG);
    123   desc.get_position = get_position;
    124   desc.get_indices = NULL;
    125   CHK(sgf_scene_setup_3d(scn, &desc) == RES_BAD_ARG);
    126   desc.get_indices = get_indices;
    127   desc.get_emissivity = NULL;
    128   CHK(sgf_scene_setup_3d(scn, &desc) == RES_BAD_ARG);
    129   desc.get_emissivity = get_emissivity;
    130   desc.get_reflectivity = NULL;
    131   CHK(sgf_scene_setup_3d(scn, &desc) == RES_BAD_ARG);
    132   desc.get_reflectivity = get_reflectivity;
    133   desc.get_specularity = NULL;
    134   CHK(sgf_scene_setup_3d(scn, &desc) == RES_BAD_ARG);
    135   desc.get_specularity = get_specularity;
    136   desc.nprims = 0;
    137   CHK(sgf_scene_setup_3d(scn, &desc) == RES_BAD_ARG);
    138   desc.nprims = (unsigned)plane_nprims;
    139   desc.nverts = 0;
    140   CHK(sgf_scene_setup_3d(scn, &desc) == RES_BAD_ARG);
    141   desc.nverts = (unsigned)plane_nverts;
    142   desc.nbands = 0;
    143   CHK(sgf_scene_setup_3d(scn, &desc) == RES_BAD_ARG);
    144   desc.nbands = 1;
    145   shape.emissivity = plane_emi_bad;
    146   CHK(sgf_scene_setup_3d(scn, &desc) == RES_BAD_ARG);
    147   shape.emissivity = plane_emi;
    148   shape.specularity = plane_spec_bad;
    149   CHK(sgf_scene_setup_3d(scn, &desc) == RES_BAD_ARG);
    150   shape.specularity = plane_spec;
    151   desc.get_absorption = get_absorption;
    152   shape.absorption = plane_abs;
    153   CHK(sgf_scene_setup_3d(scn, &desc) == RES_OK);
    154   shape.absorption = plane_abs_bad;
    155   CHK(sgf_scene_setup_3d(scn, &desc) == RES_BAD_ARG);
    156 
    157   CHK(sgf_scene_begin_integration(NULL) == RES_BAD_ARG);
    158   CHK(sgf_scene_begin_integration(scn) == RES_OK);
    159   CHK(sgf_scene_begin_integration(scn) == RES_BAD_OP);
    160 
    161   CHK(sgf_scene_end_integration(NULL) == RES_BAD_ARG);
    162   CHK(sgf_scene_end_integration(scn) == RES_OK);
    163   CHK(sgf_scene_end_integration(scn) == RES_BAD_OP);
    164 
    165   shape.emissivity = square_emi;
    166   shape.specularity = square_spec;
    167   shape.vertices = square_verts;
    168   shape.indices = square_ids;
    169   shape.nprimitives = square_nprims;
    170   shape.dim = 2;
    171 
    172   desc.nprims = (unsigned)square_nprims;
    173   desc.nverts = (unsigned)square_nverts;
    174 
    175   CHK(sgf_scene_begin_integration(scn) == RES_OK);
    176   CHK(sgf_scene_begin_integration(scn) == RES_BAD_OP);
    177 
    178   CHK(sgf_scene_end_integration(scn) == RES_OK);
    179   CHK(sgf_scene_end_integration(scn) == RES_BAD_OP);
    180 
    181   CHK(sgf_scene_ref_get(NULL) == RES_BAD_ARG);
    182   CHK(sgf_scene_ref_get(scn) == RES_OK);
    183   CHK(sgf_scene_ref_put(NULL) == RES_BAD_ARG);
    184   CHK(sgf_scene_ref_put(scn) == RES_OK);
    185   CHK(sgf_scene_ref_put(scn) == RES_OK);
    186 
    187   CHK(sgf_device_ref_put(sgf) == RES_OK);
    188 
    189   check_memory_allocator(&allocator);
    190   mem_shutdown_proxy_allocator(&allocator);
    191   CHK(mem_allocated_size() == 0);
    192   return RES_OK;
    193 }