Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1#ifndef _BBM_CONFIG_H_
2#define _BBM_CONFIG_H_
3
4#include "concepts/macro.h"
5#include "concepts/config.h"
6
7#include "core/vec.h"
8#include "core/color.h"
9#include "core/mat.h"
10#include "core/constants.h"
11#include "core/stringconvert.h"
12
13#include "bbm/bsdf_flag.h"
14
15/*************************************************************************/
16/*! \file config.h
17
18 \brief All BBM methods are defined to operate on a variety of value types
19 and spectrum types. Each BBM class takes a config structure as a template
20 parameter (that satisfies concepts::config). To import common
21 typedefs into the current scope add the macro BBM_IMPORT_CONFIG with the
22 config template parameters as parameter. To import a single 'core' type
23 use Core_t<Config>.
24**************************************************************************/
25
26namespace bbm {
27
28 /***********************************************************************/
29 /*! \brief Helper Macro to validate a configuration
30 ***********************************************************************/
31 #define BBM_CHECK_CONFIG(CONF) \
32 BBM_CHECK_RAW_CONCEPT( bbm::concepts::config, CONF); \
33 BBM_VALIDATE_BACKBONE(typename CONF::Value); \
34 BBM_VALIDATE_BACKBONE(typename CONF::Spectrum); \
35 BBM_VALIDATE_BACKBONE( bbm::vec2d<typename CONF::Value> ); \
36 BBM_VALIDATE_BACKBONE( bbm::vec3d<typename CONF::Value> ); \
37 BBM_VALIDATE_BACKBONE( bbm::complex<typename CONF::Value> ); \
38 BBM_CHECK_RAW_CONCEPT( std::constructible_from, bbm::vec2d<typename CONF::Value>, typename CONF::Value, typename CONF::Value ); \
39 BBM_CHECK_RAW_CONCEPT( std::constructible_from, bbm::vec3d<typename CONF::Value>, typename CONF::Value, typename CONF::Value, typename CONF::Value ); \
40 BBM_CHECK_RAW_CONCEPT( bbm::concepts::backbone::has_complex_functions, bbm::complex<typename CONF::Value> ); \
41
42
43 /**********************************************************************/
44 /*! \brief get_config type trait
45
46 Get the config struct type
47 **********************************************************************/
48 template<typename T> requires concepts::has_config<T>
49 using get_config = typename std::decay_t<T>::Config;
50
51
52 /*** Forward Declarations for Config dependent types included in BBM_IMPORT_CONFIG ***/
53 #define BBM_DECLARE_FORWARD_IMPORT(STRUCT) template<typename CONF> requires concepts::config<CONF> struct STRUCT;
56
57 /*** Determine a 'core' type from a config; checks if the default needs to be overriden; use as Core_t<T> ***/
58 #define BBM_DECLARE_CORE_TYPE(Core, Type, ...) \
59 namespace detail { \
60 template<typename Type> struct Core { using type = __VA_ARGS__; }; \
61 template<typename Type> requires requires { typename std::decay_t<Type>::Core; } \
62 struct Core<Type> { using type = typename std::decay_t<Type>::Core; }; \
63 } \
64 template<typename T> requires bbm::concepts::has_config<T> \
65 using Core ## _t = typename bbm::detail::Core<get_config<T>>::type;\
66
67 template<typename T> requires concepts::has_config<T> using Value_t = typename get_config<T>::Value;
68 template<typename T> requires concepts::has_config<T> using Spectrum_t = typename get_config<T>::Spectrum;
69
70 BBM_DECLARE_CORE_TYPE(Scalar, T, bbm::scalar_t<Value_t<T>>);
71 BBM_DECLARE_CORE_TYPE(Mask, T, bbm::mask_t<Value_t<T>>);
72 BBM_DECLARE_CORE_TYPE(Size, T, bbm::index_t<Value_t<T>>);
73 BBM_DECLARE_CORE_TYPE(BsdfFlag, T, bbm::replace_scalar_t<bbm::remove_diff_t<Value_t<T>>, bbm::bsdf_flag>);
74
75 BBM_DECLARE_CORE_TYPE(Constants, T, bbm::constants<Scalar_t<T>>);
76 BBM_DECLARE_CORE_TYPE(Vec2d, T, bbm::vec2d<Value_t<T>>);
78 BBM_DECLARE_CORE_TYPE(Vec3d, T, bbm::vec3d<Value_t<T>>);
81
82 /*** Define short hand defintions similar to Core_t<T> for selected non-Core types ***/
83 #define BBM_DECLARE_SHORTHAND(SHORTHAND, TYPE) \
84 template<typename T> requires bbm::concepts::has_config<T> \
85 using SHORTHAND = TYPE<bbm::get_config<T>>; \
86
89
90 /***********************************************************************/
91 /*! \brief Import the configs typedefs in the current scope
92
93 A macro to define common shorthand type aliases in the current scope
94 based on a BBM config structure type.
95
96 Any class that meets concepts::has_config can be passed.
97
98 Using __VA_ARGS__ for passing the CONFIG argument to handle passing
99 a configs with commas.
100
101 Any class that IMPORTs a CONFIG will satisfies concepts::has_config.
102 ***********************************************************************/
103#define BBM_IMPORT_CONFIG(...) \
104 using Config = bbm::get_config<__VA_ARGS__>; \
105 BBM_CHECK_CONFIG( Config ); \
106 BBM_BACKBONE_IMPORT( Config ); \
107 \
108 /* Core types */\
109 using Value = bbm::Value_t<Config>; \
110 using Spectrum = bbm::Spectrum_t<Config>; \
111 using Scalar = bbm::Scalar_t<Config>; \
112 using Mask = bbm::Mask_t<Config>; \
113 using Size_t = bbm::Size_t<Config>; \
114 using BsdfFlag = bbm::BsdfFlag_t<Config>; \
115 \
116 using Constants = bbm::Constants_t<Config>; \
117 using Vec2d = bbm::Vec2d_t<Config>; \
118 using Mat2d = bbm::Mat2d_t<Config>; \
119 using Vec3d = bbm::Vec3d_t<Config>; \
120 using Mat3d = bbm::Mat3d_t<Config>; \
121 using Complex = bbm::Complex_t<Config>; \
122 \
123 /* Convenient Shorthands */\
124 using BsdfSample = bbm::bsdfsample<Config>; \
125 using Vec3dPair = bbm::vec3dpair<Config>; \
126
127} // end bbm namespace
128
129//////////////////////////////////////////////////////////////
130// Import Config Dependent Classes used in BBM_IMPORT_CONFIG
131//////////////////////////////////////////////////////////////
132#include "bbm/bsdfsample.h"
133#include "bbm/vec3dpair.h"
134
135#endif /* _BBM_CONFIG_H_ */
#define BBM_DECLARE_SHORTHAND(SHORTHAND, TYPE)
Definition: config.h:83
#define BBM_DECLARE_CORE_TYPE(Core, Type,...)
Definition: config.h:58
#define BBM_DECLARE_FORWARD_IMPORT(STRUCT)
Definition: config.h:53
Reflectance component flags.
Structure to hold a sampled direction and corresponding pdf.
has_config
Definition: config.h:53
config contract
Defines additional helper methods for RGB colors.
Convert a string to an object and vice versa.
Defines additional helper methods for vectors.
Macros for checking if a class meets a concept.
Definition: aggregatebsdf.h:29
bbm::detail::mat< vec3d< T >, 3 > mat3d
3D matrix
Definition: mat.h:178
bbm::detail::mat< vec2d< T >, 2 > mat2d
2D matrix
Definition: mat.h:174
typename std::decay_t< T >::Config get_config
get_config type trait
Definition: config.h:49
bsdf_flag
Reflectance Component Evaluation Flags.
Definition: bsdf_flag.h:22
typename get_config< T >::Value Value_t
Definition: config.h:67
typename get_config< T >::Spectrum Spectrum_t
Definition: config.h:68
Complex numbers.
Definition: complex.h:22
Structure to hold a sample's direction and PDF.
Definition: bsdfsample.h:21
Definition: constants.h:17
Structure to hold a pair of directions.
Definition: vec3dpair.h:21
Structure to hold a pair of directions.