3 #include "utilities/aligned/vector.h" 5 #include "core/scene_data.h" 15 constexpr
auto min_element(
double x) {
return x; }
16 constexpr
auto min_element(
float x) {
return x; }
19 double min_absorption(
const T& t) {
20 return min_element(t.absorption);
23 template <
typename It>
24 double min_absorption(It begin, It end) {
26 throw std::runtime_error{
"Can't find min absorption of empty vector."};
28 return std::accumulate(begin + 1,
30 min_absorption(*begin),
31 [](
const auto& i,
const auto& j) {
33 return min(i, min_absorption(j));
38 inline size_t compute_optimum_reflection_number(
double absorption) {
39 return std::ceil(-6 / std::log10(1 - absorption));
42 template <
typename It>
43 size_t compute_optimum_reflection_number(It begin, It end) {
44 return compute_optimum_reflection_number(min_absorption(begin, end));
48 template <
typename Vertex,
typename Surface>
49 size_t compute_optimum_reflection_number(
50 const core::generic_scene_data<Vertex, Surface>& scene) {
51 std::vector<bool> used_surfaces_hash(scene.get_surfaces().size(),
false);
52 for (
const auto& tri : scene.get_triangles()) {
53 if (0 <= tri.surface && tri.surface < used_surfaces_hash.size()) {
54 used_surfaces_hash[tri.surface] =
true;
58 util::aligned::vector<Surface> used_surfaces;
59 used_surfaces.reserve(used_surfaces_hash.size());
60 for (
size_t i = 0; i != used_surfaces_hash.size(); ++i) {
61 if (used_surfaces_hash[i]) {
62 used_surfaces.emplace_back(scene.get_surfaces()[i]);
66 return compute_optimum_reflection_number(std::begin(used_surfaces),
67 std::end(used_surfaces));
Definition: pressure.h:22
Definition: capsule_base.h:9