solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit 19d773cf0f86521579c5ce37a86ae6b9f9fa7b94
parent e9927078ff834d704b11919de1b0949a14919328
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon,  3 Oct 2016 20:44:06 +0200

Fix compilation errors/warnings on GCC

Note that the solver tests fail

Diffstat:
Mcmake/CMakeLists.txt | 21+++++----------------
Msrc/ssol_c.h | 12++++++------
Msrc/ssol_scene.c | 5++---
Msrc/ssol_shape.c | 123++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/ssol_shape_c.h | 15+++++----------
Msrc/ssol_solver.c | 146+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/ssol_solver_c.h | 7-------
Msrc/ssol_spectrum.c | 4++--
Dsrc/test_ssol_postprocess.h | 49-------------------------------------------------
Msrc/test_ssol_solver1.c | 1-
Msrc/test_ssol_solver2.c | 1-
Msrc/test_ssol_solver2b.c | 1-
Msrc/test_ssol_solver3.c | 1-
Msrc/test_ssol_solver3N.c | 16++++++++--------
Msrc/test_ssol_solver4.c | 1-
Msrc/test_ssol_solver5.c | 1-
Asrc/test_ssol_utils.c | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_ssol_utils.h | 12++++++++++--
18 files changed, 234 insertions(+), 244 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -121,29 +121,18 @@ rcmake_setup_devel(solstice-solver SolSolver ${VERSION} solstice/ssol_version.h) # Add tests ################################################################################ if(NOT NO_TEST) - function(build_test _name) + function(new_test _name) add_executable(${_name} - ${SSOL_SOURCE_DIR}/test_ssol_utils.h ${SSOL_SOURCE_DIR}/test_ssol_geometries.h ${SSOL_SOURCE_DIR}/test_ssol_materials.h + ${SSOL_SOURCE_DIR}/test_ssol_utils.h + ${SSOL_SOURCE_DIR}/test_ssol_utils.c ${SSOL_SOURCE_DIR}/${_name}.c) target_link_libraries(${_name} solstice-solver RSys Star3D StarSP) - set(_libraries ${ARGN}) - foreach(_lib ${_libraries}) - target_link_libraries(${_name} ${_lib}) - endforeach() - endfunction() - - function(register_test _name) - add_test(${_name} ${ARGN}) + add_test(${_name} ${_name}) rcmake_set_test_runtime_dirs(${_name} _runtime_dirs) endfunction() - function(new_test _name) - build_test(${_name} ${ARGN}) - register_test(${_name} ${_name}) - endfunction() - new_test(test_ssol_atmosphere) new_test(test_ssol_device) new_test(test_ssol_image) @@ -161,7 +150,7 @@ if(NOT NO_TEST) new_test(test_ssol_solver4) new_test(test_ssol_solver5) new_test(test_ssol_sun) -endif(NOT NO_TEST) +endif() ################################################################################ # Define output & install directories diff --git a/src/ssol_c.h b/src/ssol_c.h @@ -44,14 +44,14 @@ hit_filter_function #include <math.h> -#ifndef NAN -#define NAN (INF * 0.0) -#endif -#define ISNAN(x) (!((x) == (x))) #ifndef NDEBUG -#define ASSERT_NAN(x, sz) {int i; for (i = 0; i < (sz); i++)ASSERT(!ISNAN((x)[i]));} + #define ASSERT_NAN(x, sz) { \ + int i__; \ + FOR_EACH(i__, 0, sz) \ + ASSERT(!IS_NaN((x)[i__])); \ + } (void)0 #else -#define ASSERT_NAN(x, sz) + #define ASSERT_NAN(x, sz) #endif #define NON_BOOL 99 diff --git a/src/ssol_scene.c b/src/ssol_scene.c @@ -342,12 +342,10 @@ hit_filter_function const struct str* receiver_name; struct realisation* rs = realisation; struct segment* seg; - struct segment* prev; (void) filter_data, (void) org, (void) dir; ASSERT(rs); seg = current_segment(rs); - prev = previous_segment(rs); ASSERT(seg); /* these components have been set */ @@ -365,6 +363,7 @@ hit_filter_function double org_local[3], hit_pos_local[3], dir_local[3]; const double* transform = inst->transform; double tr[9]; + int valid; d33_inverse(tr, transform); /* get org in local coordinate */ @@ -375,7 +374,7 @@ hit_filter_function /* get dir in local */ d33_muld3(dir_local, tr, seg->dir); /* recompute hit */ - int valid = punched_shape_intersect_local(shape, org_local, dir_local, + valid = punched_shape_intersect_local(shape, org_local, dir_local, hit->distance, hit_pos_local, seg->hit_normal, &seg->hit_distance); if (!valid) return 1; /* transform point to world */ diff --git a/src/ssol_shape.c b/src/ssol_shape.c @@ -590,23 +590,6 @@ quadric_solve_second } static void -shape_release(ref_T* ref) -{ - struct ssol_device* dev; - struct ssol_shape* shape = CONTAINER_OF(ref, struct ssol_shape, ref); - ASSERT(ref); - dev = shape->dev; - ASSERT(dev && dev->allocator); - if(shape->shape_rt) S3D(shape_ref_put(shape->shape_rt)); - if(shape->shape_samp) S3D(shape_ref_put(shape->shape_samp)); - MEM_RM(dev->allocator, shape); - SSOL(device_ref_put(dev)); -} - -/******************************************************************************* - * Local functions - ******************************************************************************/ -void quadric_plane_gradient_local(double grad[3]) { grad[0] = 0; @@ -614,7 +597,7 @@ quadric_plane_gradient_local(double grad[3]) grad[2] = 1; } -void +static void quadric_parabol_gradient_local (const struct ssol_quadric_parabol* quad, const double pt[3], @@ -625,7 +608,7 @@ quadric_parabol_gradient_local grad[2] = 2 * quad->focal; } -void +static void quadric_parabolic_cylinder_gradient_local (const struct ssol_quadric_parabolic_cylinder* quad, const double pt[3], @@ -636,7 +619,7 @@ quadric_parabolic_cylinder_gradient_local grad[2] = 2 * quad->focal; } -int +static int quadric_plane_intersect_local (const double org[3], const double dir[3], @@ -655,7 +638,7 @@ quadric_plane_intersect_local return 1; } -int +static int quadric_parabol_intersect_local (const struct ssol_quadric_parabol* quad, const double org[3], @@ -677,7 +660,7 @@ quadric_parabol_intersect_local return 1; } -int +static int quadric_parabolic_cylinder_intersect_local (const struct ssol_quadric_parabolic_cylinder* quad, const double org[3], @@ -698,27 +681,45 @@ quadric_parabolic_cylinder_intersect_local return 1; } +static void +shape_release(ref_T* ref) +{ + struct ssol_device* dev; + struct ssol_shape* shape = CONTAINER_OF(ref, struct ssol_shape, ref); + ASSERT(ref); + dev = shape->dev; + ASSERT(dev && dev->allocator); + if(shape->shape_rt) S3D(shape_ref_put(shape->shape_rt)); + if(shape->shape_samp) S3D(shape_ref_put(shape->shape_samp)); + MEM_RM(dev->allocator, shape); + SSOL(device_ref_put(dev)); +} + +/******************************************************************************* + * Local functions + ******************************************************************************/ void -punched_shape_set_z_local(const struct ssol_shape* shape, double pt[3]) { +punched_shape_set_z_local(const struct ssol_shape* shape, double pt[3]) +{ ASSERT(shape && pt); ASSERT(shape->type == SHAPE_PUNCHED); switch (shape->quadric.type) { - case SSOL_QUADRIC_PLANE: { - pt[2] = 0; - break; - } - case SSOL_QUADRIC_PARABOLIC_CYLINDER: { - const struct ssol_quadric_parabolic_cylinder* quad - = &shape->quadric.data.parabolic_cylinder; - pt[2] = (pt[1] * pt[1]) / (4.0 * quad->focal); - break; - } - case SSOL_QUADRIC_PARABOL: { - const struct ssol_quadric_parabol* quad = &shape->quadric.data.parabol; - pt[2] = (pt[0] * pt[0] + pt[1] * pt[1]) / (4.0 * quad->focal); - break; - } - default: FATAL("Unreachable code\n"); break; + case SSOL_QUADRIC_PLANE: { + pt[2] = 0; + break; + } + case SSOL_QUADRIC_PARABOLIC_CYLINDER: { + const struct ssol_quadric_parabolic_cylinder* quad + = &shape->quadric.data.parabolic_cylinder; + pt[2] = (pt[1] * pt[1]) / (4.0 * quad->focal); + break; + } + case SSOL_QUADRIC_PARABOL: { + const struct ssol_quadric_parabol* quad = &shape->quadric.data.parabol; + pt[2] = (pt[0] * pt[0] + pt[1] * pt[1]) / (4.0 * quad->focal); + break; + } + default: FATAL("Unreachable code\n"); break; } } @@ -854,28 +855,28 @@ ssol_punched_surface_setup /* Define the #slices of the discretized quadric */ switch (psurf->quadric->type) { - case SSOL_QUADRIC_PLANE: - nslices = 1; - break; - case SSOL_QUADRIC_PARABOL: { - double z[2]; - z[0] = (lower[0] * lower[0] + lower[1] * lower[1]) - / (4.0 * psurf->quadric->data.parabol.focal); - z[1] = (upper[0] * upper[0] + upper[1] * upper[1]) - / (4.0 * psurf->quadric->data.parabol.focal); - nslices = MMIN(50, (size_t)(1 + MMAX(z[0], z[1]) * 4)); - break; - } - case SSOL_QUADRIC_PARABOLIC_CYLINDER: { - double z[2]; - z[0] = (lower[1] * lower[1]) / - (4.0 * psurf->quadric->data.parabolic_cylinder.focal); - z[1] = (upper[1] * upper[1]) / - (4.0 * psurf->quadric->data.parabolic_cylinder.focal); - nslices = MMIN(50, (size_t)(1 + MMAX(z[0], z[1]) * 4)); - break; - } - default: FATAL("Unreachable code\n"); break; + case SSOL_QUADRIC_PLANE: + nslices = 1; + break; + case SSOL_QUADRIC_PARABOL: { + double z[2]; + z[0] = (lower[0] * lower[0] + lower[1] * lower[1]) + / (4.0 * psurf->quadric->data.parabol.focal); + z[1] = (upper[0] * upper[0] + upper[1] * upper[1]) + / (4.0 * psurf->quadric->data.parabol.focal); + nslices = MMIN(50, (size_t)(1 + MMAX(z[0], z[1]) * 4)); + break; + } + case SSOL_QUADRIC_PARABOLIC_CYLINDER: { + double z[2]; + z[0] = (lower[1] * lower[1]) / + (4.0 * psurf->quadric->data.parabolic_cylinder.focal); + z[1] = (upper[1] * upper[1]) / + (4.0 * psurf->quadric->data.parabolic_cylinder.focal); + nslices = MMIN(50, (size_t)(1 + MMAX(z[0], z[1]) * 4)); + break; + } + default: FATAL("Unreachable code\n"); break; } res = build_triangulated_plane(&coords, &ids, lower, upper, nslices); diff --git a/src/ssol_shape_c.h b/src/ssol_shape_c.h @@ -37,28 +37,23 @@ struct ssol_shape { ref_T ref; }; -/* - * Compute the z value from x,y according to the punched face quadric's equation - */ +/* Compute the z value from x,y according to the punched face quadric's + * equation */ extern LOCAL_SYM void punched_shape_set_z_local (const struct ssol_shape* shape, double pt[3]); -/* -* set the normal to a punched shape at pt -*/ +/* set the normal to a punched shape at pt */ extern LOCAL_SYM void punched_shape_set_normal_local (const struct ssol_shape* shape, const double pt[3], double normal[3]); -/* - * Search for an exact ray intersection on a punched shape +/* Search for an exact ray intersection on a punched shape * hint is an estimate of the distance (can be from raytracing) - * Return 1 on success - */ + * Return 1 on success */ extern LOCAL_SYM int punched_shape_intersect_local (const struct ssol_shape* shape, diff --git a/src/ssol_solver.c b/src/ssol_solver.c @@ -29,11 +29,12 @@ #include "ssol_ranst_sun_dir.h" #include "ssol_ranst_sun_wl.h" +#include <rsys/float3.h> +#include <rsys/double3.h> +#include <rsys/double44.h> #include <rsys/mem_allocator.h> #include <rsys/ref_count.h> #include <rsys/rsys.h> -#include <rsys/double3.h> -#include <rsys/double44.h> #define END_TEXT__ \ { "NONE", "SUCCESS", "SHADOW", "POINTING", "MISSING", "BLOCKED", "ERROR" } @@ -87,20 +88,20 @@ check_scene(const struct ssol_scene* scene) { if (scene->atmosphere) { switch (scene->atmosphere->type) { - case ATMOS_UNIFORM: { - char ok; - CHECK(spectrum_includes( - scene->atmosphere->data.uniform.spectrum, - scene->sun->spectrum, - &ok), - RES_OK); - if (!ok) { - log_error(scene->dev, "%s: sun/atmosphere spectra mismatch.\n", FUNC_NAME); - return RES_BAD_ARG; + case ATMOS_UNIFORM: { + char ok; + CHECK(spectrum_includes( + scene->atmosphere->data.uniform.spectrum, + scene->sun->spectrum, + &ok), + RES_OK); + if (!ok) { + log_error(scene->dev, "%s: sun/atmosphere spectra mismatch.\n", FUNC_NAME); + return RES_BAD_ARG; + } + break; } - break; - } - default: FATAL("Unreachable code\n"); break; + default: FATAL("Unreachable code\n"); break; } } return RES_OK; @@ -183,7 +184,7 @@ release_solver_data(struct solver_data* data) darray_receiver_record_release(&data->receiver_record_candidates); if (data->instances_ptr.data) darray_instances_ptr_release(&data->instances_ptr); - *data = SOLVER_DATA_NULL; + memset(data, 0, sizeof(struct solver_data)); } res_T @@ -289,7 +290,7 @@ setup_next_segment(struct realisation* rs) seg = current_segment(rs); data = &rs->data; ASSERT(seg && prev && data); - + if(rs->s_idx == 1) check_fst_segment(prev); else @@ -300,7 +301,7 @@ setup_next_segment(struct realisation* rs) seg->sun_segment = 0; d3_set(seg->org, prev->hit_pos); - + res = material_shade( prev->hit_material, &data->fragment, rs->wavelength, data->brdfs); if (res != RES_OK) { @@ -325,19 +326,19 @@ reset_segment(struct segment* seg) { ASSERT(seg); #ifndef NDEBUG - d3_splat(seg->dir, NAN); + d3_splat(seg->dir, NaN); seg->hit = S3D_HIT_NULL; seg->hit_distance = 0; seg->hit_front = NON_BOOL; seg->hit_instance = NULL; seg->hit_material = NULL; - d3_splat(seg->hit_normal, NAN); - d3_splat(seg->hit_pos, NAN); + d3_splat(seg->hit_normal, NaN); + d3_splat(seg->hit_pos, NaN); seg->on_punched = NON_BOOL; - d3_splat(seg->org, NAN); + d3_splat(seg->org, NaN); seg->self_instance = NULL; seg->self_front = NON_BOOL; - seg->weight = NAN; + seg->weight = NaN; #else seg->hit = S3D_HIT_NULL; seg->hit_distance = 0; @@ -349,17 +350,17 @@ reset_starting_point(struct starting_point* start) { ASSERT(start); #ifndef NDEBUG - start->cos_sun = NAN; + start->cos_sun = NaN; start->front_exposed = NON_BOOL; start->instance = NULL; start->material = NULL; - d3_splat(start->rt_normal, NAN); - d3_splat(start->sampl_normal, NAN); + d3_splat(start->rt_normal, NaN); + d3_splat(start->sampl_normal, NaN); start->on_punched = NON_BOOL; - d3_splat(start->pos, NAN); + d3_splat(start->pos, NaN); start->sampl_primitive = S3D_PRIMITIVE_NULL; - d3_splat(start->sundir, NAN); - start->uv[0] = start->uv[1] = NAN; + d3_splat(start->sundir, NaN); + start->uv[0] = start->uv[1] = (float)NaN; #else start->sampl_primitive = S3D_PRIMITIVE_NULL; #endif @@ -415,12 +416,13 @@ init_realisation res = darray_segment_resize(&rs->segments, 16); if (res != RES_OK) goto error; - rs->data = SOLVER_DATA_NULL; + memset(&rs->data, 0, sizeof(rs->data)); + rs->data.scene = scene; rs->data.rng = rng; rs->data.out_stream = out; - darray_receiver_record_init( - scene->dev->allocator, &rs->data.receiver_record_candidates); + darray_receiver_record_init + (scene->dev->allocator, &rs->data.receiver_record_candidates); darray_instances_ptr_init(scene->dev->allocator, &rs->data.instances_ptr); /* create 2 s3d_scene_view for raytracing and sampling */ res = set_views(&rs->data); @@ -449,8 +451,7 @@ release_realisation(struct realisation* rs) /* partial setting of rs->start * front_exposed, cos_sun will be set later - * material is set to NULL and will be set later - */ + * material is set to NULL and will be set later */ static void sample_starting_point(struct realisation* rs) { @@ -485,31 +486,31 @@ sample_starting_point(struct realisation* rs) ASSERT(attrib.type == S3D_FLOAT3); d3_set_f3(start->sampl_normal, attrib.value); switch (shape->type) { - case SHAPE_MESH: { - /* no projection needed */ - /* set geometry normal */ - d3_set(start->rt_normal, start->sampl_normal); - break; - } - case SHAPE_PUNCHED: { - const double* transform = start->instance->transform; - double tr[9], pos_local[3]; - /* project the sampled point on the quadric */ - d33_inverse(tr, transform); - d3_sub(pos_local, start->pos, transform + 9); - d33_muld3(pos_local, tr, pos_local); - punched_shape_set_z_local(shape, pos_local); - /* transform point to world */ - d33_muld3(start->pos, transform, pos_local); - d3_add(start->pos, transform + 9, start->pos); - /* compute exact normal on the instance */ - punched_shape_set_normal_local(shape, pos_local, start->rt_normal); - /* transform normal to world */ - d33_invtrans(tr, transform); - d33_muld3(start->rt_normal, tr, start->rt_normal); - break; - } - default: FATAL("Unreachable code.\n"); break; + case SHAPE_MESH: { + /* no projection needed */ + /* set geometry normal */ + d3_set(start->rt_normal, start->sampl_normal); + break; + } + case SHAPE_PUNCHED: { + const double* transform = start->instance->transform; + double tr[9], pos_local[3]; + /* project the sampled point on the quadric */ + d33_inverse(tr, transform); + d3_sub(pos_local, start->pos, transform + 9); + d33_muld3(pos_local, tr, pos_local); + punched_shape_set_z_local(shape, pos_local); + /* transform point to world */ + d33_muld3(start->pos, transform, pos_local); + d3_add(start->pos, transform + 9, start->pos); + /* compute exact normal on the instance */ + punched_shape_set_normal_local(shape, pos_local, start->rt_normal); + /* transform normal to world */ + d33_invtrans(tr, transform); + d33_muld3(start->rt_normal, tr, start->rt_normal); + break; + } + default: FATAL("Unreachable code.\n"); break; } /* TODO: transform everything to world coordinate */ @@ -544,7 +545,7 @@ receive_sunlight(struct realisation* rs) const struct ssol_sun* sun; struct starting_point* start; - ASSERT(rs && rs->s_idx == 0); + ASSERT(rs && rs->s_idx == 0); seg = current_segment(rs); sun = rs->data.scene->sun; start = &rs->start; @@ -557,22 +558,19 @@ receive_sunlight(struct realisation* rs) start->front_exposed = start->geom_cos < 0; if (start->front_exposed) { start->material = start->instance->object->mtl_front; - } - else { + } else { start->material = start->instance->object->mtl_back; } /* normals must face the sun and cos must be positive */ if (start->geom_cos > 0) { d3_muld(start->rt_normal, start->rt_normal, -1); - } - else { + } else { start->geom_cos *= -1; } start->cos_sun = d3_dot(start->sampl_normal, start->sundir); if (start->cos_sun > 0) { d3_muld(start->sampl_normal, start->sampl_normal, -1); - } - else { + } else { start->cos_sun *= -1; } @@ -596,7 +594,7 @@ receive_sunlight(struct realisation* rs) return 0; } - /* fill segment to allow standard propagation + /* fill segment to allow standard propagation * pretend the ray was cast in the opposite direction */ d3_set(seg->dir, start->sundir); d3_sub(seg->org, seg->org, seg->dir); @@ -648,7 +646,7 @@ receive_sunlight(struct realisation* rs) else { rs->success_mask |= start->instance->target_back_mask; } - + return 1; } @@ -684,11 +682,10 @@ filter_receiver_hit_candidates(struct realisation* rs) candidates++) { if (candidates->hit_distance == prev_distance) { - int i = 0, is_duplicate = 0; - const struct ssol_instance** ptr - = darray_instances_ptr_data_get(inst_array); + size_t i = 0, is_duplicate = 0; + struct ssol_instance** ptr = darray_instances_ptr_data_get(inst_array); while (!is_duplicate && i < darray_instances_ptr_size_get(inst_array)) { - if (*ptr == candidates->instance) + if (*ptr == candidates->instance) is_duplicate = 1; ptr++; i++; @@ -742,7 +739,7 @@ propagate(struct realisation* rs) } check_segment(seg); - /* fill fragment and loop */ + /* fill fragment and loop */ surface_fragment_setup(&rs->data.fragment, seg->hit_pos, seg->dir, seg->hit_normal, &seg->hit.prim, seg->hit.uv); } @@ -810,7 +807,8 @@ ssol_solve else r++; } while (rs.end == TERM_ERR); } - /* TODO: overwrite trailing chars if canceled realizations wrote past the current fpos */ + /* TODO: overwrite trailing chars if canceled realizations wrote past the + * current fpos */ exit: release_realisation(&rs); diff --git a/src/ssol_solver_c.h b/src/ssol_solver_c.h @@ -38,7 +38,6 @@ struct ranst_sun_wl; #define DARRAY_DATA struct s3d_shape* #include <rsys/dynamic_array.h> -#include <rsys/dynamic_array.h> #define DARRAY_DATA struct ssol_instance* #define DARRAY_NAME instances_ptr #include <rsys/dynamic_array.h> @@ -104,12 +103,10 @@ struct receiver_record { double hit_distance; }; -#include <rsys/dynamic_array.h> #define DARRAY_DATA struct segment #define DARRAY_NAME segment #include <rsys/dynamic_array.h> -#include <rsys/dynamic_array.h> #define DARRAY_DATA struct receiver_record #define DARRAY_NAME receiver_record #include <rsys/dynamic_array.h> @@ -146,10 +143,6 @@ struct realisation { uint32_t success_mask; }; -#define SOLVER_DATA_NULL__ \ - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } -static const struct solver_data SOLVER_DATA_NULL = SOLVER_DATA_NULL__; - extern LOCAL_SYM res_T set_sun_distributions(struct solver_data* data); diff --git a/src/ssol_spectrum.c b/src/ssol_spectrum.c @@ -54,7 +54,7 @@ spectrum_includes_point return data[0] <= wavelenght && wavelenght <= data[sz - 1]; } -int +static int eq_d(const void* key, const void* base) { double k = *(double*) key; @@ -110,7 +110,7 @@ spectrum_interpolate ints = spectrum->intensities.data; next = search_lower_bound(&wavelenght, wavelengths, sz, sizeof(double), &eq_d); ASSERT(next); /* cause spectrum_includes_point */ - idx_next = next - wavelengths; + idx_next = (size_t)(next - wavelengths); ASSERT(idx_next); /* cause spectrum_includes_point */ ASSERT(ints[idx_next] >= ints[idx_next - 1]); ASSERT(wavelengths[idx_next] >= wavelengths[idx_next - 1]); diff --git a/src/test_ssol_postprocess.h b/src/test_ssol_postprocess.h @@ -1,49 +0,0 @@ -/* Copyright (C) CNRS 2016 -* -* 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/>. */ - -#ifndef TEST_SSOL_POSTPROCESS_H -#define TEST_SSOL_POSTPROCESS_H - -#include <stdio.h> -#include <math.h> - -static INLINE res_T -pp_sum(FILE* f, const char* target, const size_t count, double* mean, double* std) -{ - double sum = 0, sum2 = 0, var; - char expect_tok[256]; - ASSERT(f && target && mean && std && count); - snprintf(expect_tok, 256, "'%s':", target); - rewind(f); - while (!feof(f)) { - char buf[256]; - if (fgets(buf, 256, f)) { - char tok[256]; - double w; - if (2 == sscanf(buf, "Receiver %s %*f %*f %*f %lf", tok, &w)) { - if (strcmp(tok, expect_tok)) continue; - sum += w; - sum2 += w * w; - } - } - } - - *mean = sum / count; - var = (sum2 / count - *mean * *mean); - *std = var > 0 ? sqrt(var / count) : 0; - return RES_OK; -} - -#endif /* TEST_SSOL_POSTPROCESS_H */ diff --git a/src/test_ssol_solver1.c b/src/test_ssol_solver1.c @@ -16,7 +16,6 @@ #include "ssol.h" #include "test_ssol_utils.h" #include "test_ssol_materials.h" -#include "test_ssol_postprocess.h" #define HALF_X 1 #define HALF_Y 1 diff --git a/src/test_ssol_solver2.c b/src/test_ssol_solver2.c @@ -16,7 +16,6 @@ #include "ssol.h" #include "test_ssol_utils.h" #include "test_ssol_materials.h" -#include "test_ssol_postprocess.h" #define PLANE_NAME SQUARE #define HALF_X 1 diff --git a/src/test_ssol_solver2b.c b/src/test_ssol_solver2b.c @@ -16,7 +16,6 @@ #include "ssol.h" #include "test_ssol_utils.h" #include "test_ssol_materials.h" -#include "test_ssol_postprocess.h" #define PLANE_NAME RECT #define HALF_X 0.5 diff --git a/src/test_ssol_solver3.c b/src/test_ssol_solver3.c @@ -16,7 +16,6 @@ #include "ssol.h" #include "test_ssol_utils.h" #include "test_ssol_materials.h" -#include "test_ssol_postprocess.h" #define PLANE_NAME SQUARE #define HALF_X 1 diff --git a/src/test_ssol_solver3N.c b/src/test_ssol_solver3N.c @@ -16,7 +16,6 @@ #include "ssol.h" #include "test_ssol_utils.h" #include "test_ssol_materials.h" -#include "test_ssol_postprocess.h" #define PLANE_NAME SQUARE #define HALF_X 250 @@ -38,8 +37,8 @@ #include <star/ssp.h> /******************************************************************************* -* Helper functions -******************************************************************************/ + * Helper functions + ******************************************************************************/ struct common { struct ssol_scene* scene; struct ssol_object* m_object; @@ -47,7 +46,9 @@ struct common { double sun_dir[3]; }; -void set_1(struct common* common, const double pos[3]) { +static void +set_1(struct common* common, const double pos[3]) +{ struct ssol_instance* heliostat; double transform[12]; /* 3x4 column major matrix */ double out_dir[3], axis[3], c, a; @@ -78,8 +79,8 @@ void set_1(struct common* common, const double pos[3]) { } /******************************************************************************* -* Test main program -******************************************************************************/ + * Test main program + ******************************************************************************/ int main(int argc, char** argv) { @@ -111,7 +112,6 @@ main(int argc, char** argv) FILE* tmp; double m, std; int i, j, k; - (void) argc, (void) argv; mem_init_proxy_allocator(&allocator, &mem_default_allocator); @@ -187,7 +187,7 @@ main(int argc, char** argv) } } } - + d33_rotation_pitch(transform, PI); /* flip faces: invert normal */ d3_set(transform + 9, target_pos); diff --git a/src/test_ssol_solver4.c b/src/test_ssol_solver4.c @@ -16,7 +16,6 @@ #include "ssol.h" #include "test_ssol_utils.h" #include "test_ssol_materials.h" -#include "test_ssol_postprocess.h" #define PLANE_NAME SQUARE #define HALF_X 0.1 diff --git a/src/test_ssol_solver5.c b/src/test_ssol_solver5.c @@ -16,7 +16,6 @@ #include "ssol.h" #include "test_ssol_utils.h" #include "test_ssol_materials.h" -#include "test_ssol_postprocess.h" #define HALF_X 10 #define HALF_Y 0.1 diff --git a/src/test_ssol_utils.c b/src/test_ssol_utils.c @@ -0,0 +1,62 @@ +/* Copyright (C) CNRS 2016 + * + * 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/>. */ + +#define _POSIX_C_SOURCE 200809L /* snprintf support */ + +#include "test_ssol_utils.h" + +#include <rsys/math.h> + +#include <math.h> +#include <stdio.h> +#include <string.h> + +res_T +pp_sum + (FILE* f, + const char* target, + const size_t count, + double* mean, + double* std) +{ + double sum = 0; + double sum2 = 0; + double E, V, SE; + char expect_tok[256]; + ASSERT(f && target && mean && std && count); + + snprintf(expect_tok, 256, "'%s':", target); + rewind(f); + while (!feof(f)) { + char buf[256]; + if (fgets(buf, 256, f)) { + char tok[256]; + double w; + if (2 == sscanf(buf, "Receiver %s %*f %*f %*f %lf", tok, &w)) { + if (strcmp(tok, expect_tok)) continue; + sum += w; + sum2 += w * w; + } + } + } + + E = sum / (double)count; + V = MMAX(sum2 / (double)count - E*E, 0); + SE = sqrt(V / (double)count); + + *mean = E; + *std = SE; + return RES_OK; +} diff --git a/src/test_ssol_utils.h b/src/test_ssol_utils.h @@ -19,7 +19,7 @@ #include <rsys/mem_allocator.h> #include <stdio.h> -static void +static INLINE void log_stream(const char* msg, void* ctx) { ASSERT(msg); @@ -27,7 +27,7 @@ log_stream(const char* msg, void* ctx) printf("%s\n", msg); } -static void +static INLINE void check_memory_allocator(struct mem_allocator* allocator) { if(MEM_ALLOCATED_SIZE(allocator)) { @@ -38,4 +38,12 @@ check_memory_allocator(struct mem_allocator* allocator) } } +extern LOCAL_SYM res_T +pp_sum + (FILE* f, + const char* target, + const size_t count, + double* mean, + double* std); + #endif /* TEST_SSOL_UTILS_H */