Antkeeper  0.0.1
photometry.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_PHYSICS_LIGHT_PHOTOMETRY_HPP
21 #define ANTKEEPER_PHYSICS_LIGHT_PHOTOMETRY_HPP
22 
23 #include <engine/math/numbers.hpp>
25 
26 namespace physics {
27 namespace light {
28 
30 template <class T>
31 constexpr T max_luminous_efficacy = T(683.002);
32 
44 template <class T, class UnaryOp1, class UnaryOp2, class InputIt>
45 T luminous_efficiency(UnaryOp1 spd, UnaryOp2 lef, InputIt first, InputIt last)
46 {
47  auto spd_lef = [spd, lef](T x) -> T
48  {
49  return spd(x) * lef(x);
50  };
51 
52  const T num = math::quadrature::simpson(spd_lef, first, last);
53  const T den = math::quadrature::simpson(spd, first, last);
54 
55  return num / den;
56 }
57 
64 template <class T>
65 T luminous_efficacy(T efficiency)
66 {
67  return max_luminous_efficacy<T> * efficiency;
68 }
69 
77 template <class T>
78 T watts_to_lumens(T radiant_flux, T efficiency)
79 {
80  return radiant_flux * luminous_efficacy(efficiency);
81 }
82 
83 } // namespace light
84 } // namespace physics
85 
86 #endif // ANTKEEPER_PHYSICS_LIGHT_PHOTOMETRY_HPP
std::invoke_result< UnaryOp, typename std::iterator_traits< InputIt >::value_type >::type simpson(UnaryOp f, InputIt first, InputIt last)
Approximates the definite integral of a function using Simpson's 1/3 rule.
Definition: quadrature.hpp:43
T radiant_flux(T t, T a)
Calculates the radiant flux of a blackbody.
Definition: blackbody.hpp:110
T luminous_efficiency(UnaryOp1 spd, UnaryOp2 lef, InputIt first, InputIt last)
Calculates the luminous efficiency of a light source.
Definition: photometry.hpp:45
T luminous_efficacy(T efficiency)
Calculates luminous efficacy given luminous efficiency.
Definition: photometry.hpp:65
constexpr T max_luminous_efficacy
Maximum luminous efficacy of an ideal monochromatic source, in lumen per watt.
Definition: photometry.hpp:31
T watts_to_lumens(T radiant_flux, T efficiency)
Converts watts (radiant flux) to lumens (luminous flux).
Definition: photometry.hpp:78
Physics.
Definition: constants.hpp:23