src/config/materials.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief A configuration's material map and its Hapke photometry: specs, fields and checks. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "config/common.h" | ||
| 8 | |||
| 9 | #include "terraingen/albedo/albedo_fields.h" | ||
| 10 | #include "terraingen/albedo/photometry.h" | ||
| 11 | #include "terraingen/pipeline/materials.h" | ||
| 12 | #include "terraingen/pipeline/materials_fields.h" | ||
| 13 | #include "terraingen/pipeline/terrain.h" | ||
| 14 | |||
| 15 | #include <array> | ||
| 16 | #include <cstddef> | ||
| 17 | #include <string> | ||
| 18 | #include <string_view> | ||
| 19 | |||
| 20 | namespace terraingen { | ||
| 21 | |||
| 22 | /// A published set of Hapke parameters per material class. | ||
| 23 | enum class PhotometryReference { | ||
| 24 | None, ///< No parameters; each class present must be given. | ||
| 25 | MarsPancam, ///< `MarsPancamPhotometry`: Pancam fits at 753 nm. | ||
| 26 | }; | ||
| 27 | |||
| 28 | /// The Hapke parameters of each material class: `reference`'s, replaced by any given. | ||
| 29 | struct PhotometrySpec { | ||
| 30 | PhotometryReference reference = PhotometryReference::None; | ||
| 31 | MaterialPhotometry classes{}; ///< Parameters given per class, over the reference's. | ||
| 32 | }; | ||
| 33 | |||
| 34 | /// The material map (`MaterialsAt`), read by "materials" and "photometry" outputs. | ||
| 35 | struct MaterialsSpec { | ||
| 36 | MaterialOptions options{}; | ||
| 37 | PhotometrySpec photometry{}; | ||
| 38 | }; | ||
| 39 | |||
| 40 | template <> struct EnumNames<PhotometryReference> { | ||
| 41 | static constexpr std::array<EnumEntry<PhotometryReference>, 2> kValues{{ | ||
| 42 | {"none", PhotometryReference::None, "No parameters: each class present must be given."}, | ||
| 43 | {"mars_pancam", PhotometryReference::MarsPancam, | ||
| 44 | "Pancam fits at 753 nm (Johnson et al. 2006a, b, tabulated by Fernando et al. 2013): " | ||
| 45 | "soil, sand, dust, bedrock (Eagle crater outcrop, Johnson et al. 2006b) and rock."}, | ||
| 46 | }}; | ||
| 47 | }; | ||
| 48 | |||
| 49 | /// The JSON key of each material class, in `MaterialClass` order. | ||
| 50 | inline constexpr std::array<std::string_view, kMaterialClasses> kMaterialClassKeys{ | ||
| 51 | "soil", "sand", "dust", "bedrock", "rock"}; | ||
| 52 | |||
| 53 | 74 | template <typename IO> void Fields(IO& io, PhotometrySpec& photometry) { | |
| 54 | 74 | io("reference", photometry.reference, | |
| 55 | "Published Hapke parameters to start from; each class given below replaces its own."); | ||
| 56 | 74 | constexpr auto kRock = static_cast<std::size_t>(MaterialClass::Rock); | |
| 57 | 441 | for (std::size_t k = 0; k < kMaterialClasses; ++k) { | |
| 58 | 368 | const std::string_view what = k == kRock ? "rocks and boulders" : kMaterialClassKeys[k]; | |
| 59 | 1105 | io(kMaterialClassKeys[k], photometry.classes[k], | |
| 60 | 735 | "Hapke parameters of " + std::string(what) + "; unset keeps the reference's."); | |
| 61 | } | ||
| 62 | 73 | } | |
| 63 | |||
| 64 | 60 | template <typename IO> void Fields(IO& io, MaterialsSpec& materials) { | |
| 65 | 60 | Fields(io, materials.options); | |
| 66 | 59 | io("photometry", materials.photometry, | |
| 67 | "Hapke parameters of each material class, which photometry outputs mix."); | ||
| 68 | 58 | } | |
| 69 | |||
| 70 | namespace config { | ||
| 71 | |||
| 72 | /// The Hapke parameters of each material class a spec describes, unchecked: its reference's, | ||
| 73 | /// replaced by any it gives. | ||
| 74 | MaterialPhotometry BuildPhotometry(const PhotometrySpec& spec); | ||
| 75 | |||
| 76 | /// Checks a material map's options and photometry and, when a photometry output needs them, that | ||
| 77 | /// every class the terrain's surface can have has parameters. | ||
| 78 | /// @throws ConfigError under "materials" for invalid options or photometry, or a class without | ||
| 79 | /// parameters. | ||
| 80 | void CheckMaterials(const MaterialsSpec& materials, bool photometryOutput, const Terrain& terrain); | ||
| 81 | |||
| 82 | } // namespace config | ||
| 83 | |||
| 84 | } // namespace terraingen | ||
| 85 |