solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

commit bafc434eebc83049b19e330ded71a4745680f058
parent e389085596a11ac127f35fe6f9caed03423e17e8
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  7 Apr 2017 12:05:45 +0200

Test the loading of the normal map for all materials

Diffstat:
Mcmake/parser/CMakeLists.txt | 2+-
Dsrc/parser/test_solparser9.c | 95-------------------------------------------------------------------------------
Asrc/parser/test_solparser_normal_map.c | 335+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/solstice_material.c | 2+-
4 files changed, 337 insertions(+), 97 deletions(-)

diff --git a/cmake/parser/CMakeLists.txt b/cmake/parser/CMakeLists.txt @@ -105,7 +105,7 @@ if(NOT NO_TEST) new_test(test_solparser6) new_test(test_solparser7) new_test(test_solparser8) - new_test(test_solparser9) + new_test(test_solparser_normal_map) rcmake_copy_runtime_libraries(test_solparser) endif() diff --git a/src/parser/test_solparser9.c b/src/parser/test_solparser9.c @@ -1,95 +0,0 @@ -/* Copyright (C) CNRS 2016-2017 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ - -#include "solparser.h" -#include "test_solstice_utils.h" - -int -main(int argc, char** argv) -{ - struct mem_allocator allocator; - struct solparser* parser; - struct solparser_entity_iterator it, end; - struct solparser_entity_id entity_id; - struct solparser_object_id obj_id; - const struct solparser_entity* entity; - const struct solparser_image* img; - const struct solparser_geometry* geom; - const struct solparser_material_double_sided* mtl2; - const struct solparser_material* mtl; - const struct solparser_material_matte* matte; - const struct solparser_object* obj; - const struct solparser_shape* shape; - FILE* stream; - (void)argc, (void)argv; - - stream = tmpfile(); - NCHECK(stream, NULL); - - fprintf(stream, "- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1} ] }\n"); - fprintf(stream, "- entity:\n"); - fprintf(stream, " name: test\n"); - fprintf(stream, " primary: 0\n"); - fprintf(stream, " geometry:\n"); - fprintf(stream, " - sphere: { radius: 1 }\n"); - fprintf(stream, " material:\n"); - fprintf(stream, " matte:\n"); - fprintf(stream, " reflectivity: 0.123\n"); - fprintf(stream, " normal_map: { path: \"path to normal map\" }\n"); - rewind(stream); - - CHECK(mem_init_proxy_allocator(&allocator, &mem_default_allocator), RES_OK); - CHECK(solparser_create(&allocator, &parser), RES_OK); - CHECK(solparser_setup(parser, NULL, stream), RES_OK); - CHECK(solparser_load(parser), RES_OK); - - solparser_entity_iterator_begin(parser, &it); - solparser_entity_iterator_end(parser, &end); - CHECK(solparser_entity_iterator_eq(&it, &end), 0); - - entity_id = solparser_entity_iterator_get(&it); - entity = solparser_get_entity(parser, entity_id); - - CHECK(strcmp("test", str_cget(&entity->name)), 0); - CHECK(solparser_entity_get_children_count(entity), 0); - CHECK(entity->type, SOLPARSER_ENTITY_GEOMETRY); - geom = solparser_get_geometry(parser, entity->data.geometry); - CHECK(solparser_geometry_get_objects_count(geom), 1); - obj_id = solparser_geometry_get_object(geom, 0); - obj = solparser_get_object(parser, obj_id); - shape = solparser_get_shape(parser, obj->shape); - CHECK(shape->type, SOLPARSER_SHAPE_SPHERE); - mtl2 = solparser_get_material_double_sided(parser, obj->mtl2); - CHECK(mtl2->front.i, mtl2->back.i); - - mtl = solparser_get_material(parser, mtl2->front); - CHECK(mtl->type, SOLPARSER_MATERIAL_MATTE); - matte = solparser_get_material_matte(parser, mtl->data.matte); - CHECK(matte->reflectivity, 0.123); - CHECK(SOLPARSER_ID_IS_VALID(matte->normal_map), 1); - img = solparser_get_image(parser, matte->normal_map); - CHECK(strcmp(str_cget(&img->filename), "path to normal map"), 0); - - CHECK(solparser_load(parser), RES_BAD_OP); - solparser_ref_put(parser); - - fclose(stream); - - check_memory_allocator(&allocator); - mem_shutdown_proxy_allocator(&allocator); - CHECK(mem_allocated_size(), 0); - return 0; -} - diff --git a/src/parser/test_solparser_normal_map.c b/src/parser/test_solparser_normal_map.c @@ -0,0 +1,335 @@ +/* Copyright (C) CNRS 2016-2017 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "solparser.h" +#include "test_solstice_utils.h" + +static void +test_dielectric(struct solparser* parser) +{ + struct solparser_entity_iterator it, end; + struct solparser_entity_id entity_id; + struct solparser_object_id obj_id; + const struct solparser_entity* entity; + const struct solparser_image* img; + const struct solparser_geometry* geom; + const struct solparser_material_double_sided* mtl2; + const struct solparser_material* mtl; + const struct solparser_material_dielectric* dielectric; + const struct solparser_object* obj; + const struct solparser_shape* shape; + FILE* stream; + + stream = tmpfile(); + NCHECK(stream, NULL); + + fprintf(stream, "- sun: {dni: 1, spectrum: [{wavelength: 1, data: 1} ]}\n"); + fprintf(stream, "\n"); + fprintf(stream, "- material: &glass\n"); + fprintf(stream, " front:\n"); + fprintf(stream, " dielectric:\n"); + fprintf(stream, " medium_i: &out {refractive_index: 1, absorptivity: 0}\n"); + fprintf(stream, " medium_t: &in {refractive_index: 1.5, absorptivity: 20}\n"); + fprintf(stream, " normal_map: {path: my_normal_map}\n"); + fprintf(stream, " back: {dielectric: {medium_i: *in, medium_t: *out}}\n"); + fprintf(stream, "\n"); + fprintf(stream, "- entity:\n"); + fprintf(stream, " name: foo\n"); + fprintf(stream, " primary: 1\n"); + fprintf(stream, " geometry:\n"); + fprintf(stream, " - cylinder: { radius: 2, height: 2 }\n"); + fprintf(stream, " material: *glass\n"); + rewind(stream); + + CHECK(solparser_setup(parser, NULL, stream), RES_OK); + CHECK(solparser_load(parser), RES_OK); + + solparser_entity_iterator_begin(parser, &it); + solparser_entity_iterator_end(parser, &end); + CHECK(solparser_entity_iterator_eq(&it, &end), 0); + + entity_id = solparser_entity_iterator_get(&it); + entity = solparser_get_entity(parser, entity_id); + + CHECK(strcmp("foo", str_cget(&entity->name)), 0); + CHECK(solparser_entity_get_children_count(entity), 0); + CHECK(entity->type, SOLPARSER_ENTITY_GEOMETRY); + CHECK(entity->primary, 1); + geom = solparser_get_geometry(parser, entity->data.geometry); + CHECK(solparser_geometry_get_objects_count(geom), 1); + obj_id = solparser_geometry_get_object(geom, 0); + obj = solparser_get_object(parser, obj_id); + shape = solparser_get_shape(parser, obj->shape); + CHECK(shape->type, SOLPARSER_SHAPE_CYLINDER); + mtl2 = solparser_get_material_double_sided(parser, obj->mtl2); + NCHECK(mtl2->front.i, mtl2->back.i); + + mtl = solparser_get_material(parser, mtl2->front); + CHECK(mtl->type, SOLPARSER_MATERIAL_DIELECTRIC); + dielectric = solparser_get_material_dielectric(parser, mtl->data.dielectric); + CHECK(SOLPARSER_ID_IS_VALID(dielectric->normal_map), 1); + img = solparser_get_image(parser, dielectric->normal_map); + CHECK(strcmp(str_cget(&img->filename), "my_normal_map"), 0); + + mtl = solparser_get_material(parser, mtl2->back); + CHECK(mtl->type, SOLPARSER_MATERIAL_DIELECTRIC); + dielectric = solparser_get_material_dielectric(parser, mtl->data.dielectric); + CHECK(SOLPARSER_ID_IS_VALID(dielectric->normal_map), 0); + + solparser_entity_iterator_next(&it); + CHECK(solparser_entity_iterator_eq(&it, &end), 1); + + CHECK(solparser_load(parser), RES_BAD_OP); + fclose(stream); +} + +static void +test_matte(struct solparser* parser) +{ + struct solparser_entity_iterator it, end; + struct solparser_entity_id entity_id; + struct solparser_object_id obj_id; + const struct solparser_entity* entity; + const struct solparser_image* img; + const struct solparser_geometry* geom; + const struct solparser_material_double_sided* mtl2; + const struct solparser_material* mtl; + const struct solparser_material_matte* matte; + const struct solparser_object* obj; + const struct solparser_shape* shape; + FILE* stream; + + stream = tmpfile(); + NCHECK(stream, NULL); + + fprintf(stream, "- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1} ] }\n"); + fprintf(stream, "- entity:\n"); + fprintf(stream, " name: test\n"); + fprintf(stream, " primary: 0\n"); + fprintf(stream, " geometry:\n"); + fprintf(stream, " - sphere: { radius: 1 }\n"); + fprintf(stream, " material:\n"); + fprintf(stream, " matte:\n"); + fprintf(stream, " reflectivity: 0.123\n"); + fprintf(stream, " normal_map: { path: \"path to normal map\" }\n"); + rewind(stream); + + CHECK(solparser_setup(parser, NULL, stream), RES_OK); + CHECK(solparser_load(parser), RES_OK); + + solparser_entity_iterator_begin(parser, &it); + solparser_entity_iterator_end(parser, &end); + CHECK(solparser_entity_iterator_eq(&it, &end), 0); + + entity_id = solparser_entity_iterator_get(&it); + entity = solparser_get_entity(parser, entity_id); + + CHECK(strcmp("test", str_cget(&entity->name)), 0); + CHECK(solparser_entity_get_children_count(entity), 0); + CHECK(entity->primary, 0); + CHECK(entity->type, SOLPARSER_ENTITY_GEOMETRY); + geom = solparser_get_geometry(parser, entity->data.geometry); + CHECK(solparser_geometry_get_objects_count(geom), 1); + obj_id = solparser_geometry_get_object(geom, 0); + obj = solparser_get_object(parser, obj_id); + shape = solparser_get_shape(parser, obj->shape); + CHECK(shape->type, SOLPARSER_SHAPE_SPHERE); + mtl2 = solparser_get_material_double_sided(parser, obj->mtl2); + CHECK(mtl2->front.i, mtl2->back.i); + + mtl = solparser_get_material(parser, mtl2->front); + CHECK(mtl->type, SOLPARSER_MATERIAL_MATTE); + matte = solparser_get_material_matte(parser, mtl->data.matte); + CHECK(matte->reflectivity, 0.123); + CHECK(SOLPARSER_ID_IS_VALID(matte->normal_map), 1); + img = solparser_get_image(parser, matte->normal_map); + CHECK(strcmp(str_cget(&img->filename), "path to normal map"), 0); + + solparser_entity_iterator_next(&it); + CHECK(solparser_entity_iterator_eq(&it, &end), 1); + + CHECK(solparser_load(parser), RES_BAD_OP); + fclose(stream); +} + +static void +test_mirror(struct solparser* parser) +{ + struct solparser_entity_iterator it, end; + struct solparser_entity_id entity_id; + struct solparser_object_id obj_id; + const struct solparser_entity* entity; + const struct solparser_image* img; + const struct solparser_geometry* geom; + const struct solparser_material_double_sided* mtl2; + const struct solparser_material* mtl; + const struct solparser_material_mirror* mirror; + const struct solparser_object* obj; + const struct solparser_shape* shape; + FILE* stream; + + stream = tmpfile(); + NCHECK(stream, NULL); + + fprintf(stream, "- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1} ] }\n"); + fprintf(stream, "- entity: \n"); + fprintf(stream, " name: my entity\n"); + fprintf(stream, " primary: 0\n"); + fprintf(stream, " geometry: \n"); + fprintf(stream, " - cuboid: { size: [1, 1, 1] }\n"); + fprintf(stream, " material: \n"); + fprintf(stream, " mirror:\n"); + fprintf(stream, " reflectivity: 1\n"); + fprintf(stream, " roughness: 0.1\n"); + fprintf(stream, " normal_map: { path: Normal map } \n"); + rewind(stream); + + CHECK(solparser_setup(parser, NULL, stream), RES_OK); + CHECK(solparser_load(parser), RES_OK); + + solparser_entity_iterator_begin(parser, &it); + solparser_entity_iterator_end(parser, &end); + CHECK(solparser_entity_iterator_eq(&it, &end), 0); + + entity_id = solparser_entity_iterator_get(&it); + entity = solparser_get_entity(parser, entity_id); + + CHECK(strcmp("my entity", str_cget(&entity->name)), 0); + CHECK(solparser_entity_get_children_count(entity), 0); + CHECK(entity->primary, 0); + CHECK(entity->type, SOLPARSER_ENTITY_GEOMETRY); + geom = solparser_get_geometry(parser, entity->data.geometry); + CHECK(solparser_geometry_get_objects_count(geom), 1); + obj_id = solparser_geometry_get_object(geom, 0); + obj = solparser_get_object(parser, obj_id); + shape = solparser_get_shape(parser, obj->shape); + CHECK(shape->type, SOLPARSER_SHAPE_CUBOID); + mtl2 = solparser_get_material_double_sided(parser, obj->mtl2); + CHECK(mtl2->front.i, mtl2->back.i); + + mtl = solparser_get_material(parser, mtl2->front); + CHECK(mtl->type, SOLPARSER_MATERIAL_MIRROR); + mirror = solparser_get_material_mirror(parser, mtl->data.mirror); + CHECK(mirror->reflectivity, 1); + CHECK(mirror->roughness, 0.1); + CHECK(SOLPARSER_ID_IS_VALID(mirror->normal_map), 1); + img = solparser_get_image(parser, mirror->normal_map); + CHECK(strcmp(str_cget(&img->filename), "Normal map"), 0); + + solparser_entity_iterator_next(&it); + CHECK(solparser_entity_iterator_eq(&it, &end), 1); + + CHECK(solparser_load(parser), RES_BAD_OP); + fclose(stream); +} + +static void +test_thin_dielectric(struct solparser* parser) +{ + struct solparser_entity_iterator it, end; + struct solparser_entity_id entity_id; + struct solparser_object_id obj_id; + const struct solparser_entity* entity; + const struct solparser_image* img; + const struct solparser_geometry* geom; + const struct solparser_material_double_sided* mtl2; + const struct solparser_material* mtl; + const struct solparser_material_thin_dielectric* thin; + const struct solparser_object* obj; + const struct solparser_shape* shape; + FILE* stream; + + stream = tmpfile(); + NCHECK(stream, NULL); + fprintf(stream, "- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1} ] }\n"); + fprintf(stream, "- entity:\n"); + fprintf(stream, " name: test\n"); + fprintf(stream, " primary: 0\n"); + fprintf(stream, " geometry:\n"); + fprintf(stream, " - sphere: { radius: 1 }\n"); + fprintf(stream, " material:\n"); + fprintf(stream, " thin_dielectric:\n"); + fprintf(stream, " thickness: 0.1\n"); + fprintf(stream, " medium_i:\n"); + fprintf(stream, " refractive_index: 1\n"); + fprintf(stream, " absorptivity: 0\n"); + fprintf(stream, " medium_t:\n"); + fprintf(stream, " refractive_index: 1.5\n"); + fprintf(stream, " absorptivity: 20\n"); + fprintf(stream, " normal_map: { path: Bump }\n"); + rewind(stream); + + CHECK(solparser_setup(parser, NULL, stream), RES_OK); + CHECK(solparser_load(parser), RES_OK); + + solparser_entity_iterator_begin(parser, &it); + solparser_entity_iterator_end(parser, &end); + CHECK(solparser_entity_iterator_eq(&it, &end), 0); + + entity_id = solparser_entity_iterator_get(&it); + entity = solparser_get_entity(parser, entity_id); + + CHECK(strcmp("test", str_cget(&entity->name)), 0); + CHECK(solparser_entity_get_children_count(entity), 0); + CHECK(entity->primary, 0); + CHECK(entity->type, SOLPARSER_ENTITY_GEOMETRY); + geom = solparser_get_geometry(parser, entity->data.geometry); + CHECK(solparser_geometry_get_objects_count(geom), 1); + obj_id = solparser_geometry_get_object(geom, 0); + obj = solparser_get_object(parser, obj_id); + shape = solparser_get_shape(parser, obj->shape); + CHECK(shape->type, SOLPARSER_SHAPE_SPHERE); + mtl2 = solparser_get_material_double_sided(parser, obj->mtl2); + CHECK(mtl2->front.i, mtl2->back.i); + + mtl = solparser_get_material(parser, mtl2->front); + CHECK(mtl->type, SOLPARSER_MATERIAL_THIN_DIELECTRIC); + thin = solparser_get_material_thin_dielectric(parser, mtl->data.thin_dielectric); + CHECK(thin->thickness, 0.1); + NCHECK(thin->medium_i.i, thin->medium_t.i); + CHECK(SOLPARSER_ID_IS_VALID(thin->normal_map), 1); + img = solparser_get_image(parser, thin->normal_map); + CHECK(strcmp(str_cget(&img->filename), "Bump"), 0); + + solparser_entity_iterator_next(&it); + CHECK(solparser_entity_iterator_eq(&it, &end), 1); + + CHECK(solparser_load(parser), RES_BAD_OP); + fclose(stream); +} + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct solparser* parser; + (void)argc, (void)argv; + + CHECK(mem_init_proxy_allocator(&allocator, &mem_default_allocator), RES_OK); + CHECK(solparser_create(&allocator, &parser), RES_OK); + + test_dielectric(parser); + test_matte(parser); + test_mirror(parser); + test_thin_dielectric(parser); + + solparser_ref_put(parser); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHECK(mem_allocated_size(), 0); + return 0; +} + diff --git a/src/solstice_material.c b/src/solstice_material.c @@ -41,7 +41,7 @@ perturb_normal { double basis[9]; double N[3]; - ASSERT(frag && img && normal); + ASSERT(frag && normal_map && normal); SSOL(image_sample(normal_map, SSOL_FILTER_NEAREST, SSOL_ADDRESS_CLAMP, SSOL_ADDRESS_CLAMP, frag->uv, N));