physics/reflectance_library.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | /// @file reflectance_library.cpp | ||
| 3 | /// @brief The embedded ECOSTRESS reflectances and their lookup. | ||
| 4 | #include "ernie/physics/reflectance_library.h" | ||
| 5 | |||
| 6 | #include "ernie/physics/reflectance_table.h" | ||
| 7 | |||
| 8 | #include <iterator> | ||
| 9 | #include <utility> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | namespace ernie { | ||
| 13 | namespace { | ||
| 14 | |||
| 15 | 34 | const std::vector<MeasuredReflectance>& Library() { | |
| 16 | 2 | static const std::vector<MeasuredReflectance> library = [] { | |
| 17 | 2 | std::vector<MeasuredReflectance> entries; | |
| 18 | 40 | for (const reflectance_table::Entry& entry : reflectance_table::kEntries) { | |
| 19 | 38 | std::vector<double> wavelengths; | |
| 20 | 38 | std::vector<double> values; | |
| 21 | 11132 | for (int i = entry.first; i < entry.first + entry.count; ++i) { | |
| 22 | 11094 | wavelengths.push_back(reflectance_table::kPairs[2 * i]); | |
| 23 | 11094 | values.push_back(reflectance_table::kPairs[2 * i + 1]); | |
| 24 | } | ||
| 25 | 76 | entries.push_back({entry.id, entry.name, entry.source, | |
| 26 | Spectrum(std::move(wavelengths), std::move(values))}); | ||
| 27 | 38 | } | |
| 28 | 2 | return entries; | |
| 29 | 110 | }(); | |
| 30 | 34 | return library; | |
| 31 | } | ||
| 32 | |||
| 33 | } // namespace | ||
| 34 | |||
| 35 | 1 | std::span<const MeasuredReflectance> ReflectanceLibrary() { | |
| 36 | 1 | return Library(); | |
| 37 | } | ||
| 38 | |||
| 39 | 33 | const MeasuredReflectance* FindReflectance(std::string_view id) { | |
| 40 | 275 | for (const MeasuredReflectance& entry : Library()) { | |
| 41 | 274 | if (entry.id == id) { | |
| 42 | 32 | return &entry; | |
| 43 | } | ||
| 44 | } | ||
| 45 | 1 | return nullptr; | |
| 46 | } | ||
| 47 | |||
| 48 | } // namespace ernie | ||
| 49 |