Loading...
Searching...
No Matches
bsdf_enumerate.h
Go to the documentation of this file.
1#ifndef _BBM_BSDF_ENUMERATE_H_
2#define _BBM_BSDF_ENUMERATE_H_
3
4#include <type_traits>
5
6#include "core/attribute.h"
7#include "core/enumerate.h"
9
10#include "util/flags.h"
11#include "util/constfor.h"
12#include "util/reflection.h"
13#include "util/vector_util.h"
14
15#include "bbm/bsdf_base.h"
16#include "bbm/bsdfmodel.h"
17
18/***********************************************************************/
19/*! \file bsdf_enumerate.h
20 \brief Enumerate all BSDF parameters (e.g., stack in a vector).
21************************************************************************/
22
23namespace bbm {
24
25 /*** Implementation Details ***/
26 namespace detail {
27
28 //! \brief Enumerate all unnamed bsdf_attributes in a BSDF that meet the flag, and call the SELECT method on each and pass the result to CALLBACK.
29 template<typename MODEL, typename CALLBACK, typename SELECT> requires concepts::bsdfmodel<MODEL>
30 inline void enumerate_parameter_helper(bsdf_attr flag, MODEL&& model, CALLBACK&& callback, SELECT&& select)
31 {
32 // enumeration type
33 using Value = std::conditional_t< bbm::is_const_v<MODEL>,
34 const typename std::decay_t<MODEL>::Value&,
35 typename std::decay_t<MODEL>::Value&
36 >;
37
38 // enumerate if it is an enumerable attribute that meets the flag
39 CONSTFOR(idx, reflection::attributes_size<MODEL>,
40 {
41 auto&& val = std::get<idx>( reflection::attributes(std::forward<MODEL>(model)) );
42 using val_t = decltype(val);
43
44 if constexpr (concepts::bsdf_attribute<val_t> && is_enumerable_v<Value, val_t>)
45 if( is_set(flag, std::decay_t<val_t>::prop::flag) )
46 enumerate<Value>( select(std::forward<val_t>(val)), callback );
47 });
48
49 // Done.
50 }
51
52 } // end detail namespace
53
54
55 /*********************************************************************/
56 /*! \brief Enumerate the values of the attributes from a bsdf model
57 *********************************************************************/
58 template<typename MODEL, typename CALLBACK> requires concepts::bsdfmodel<MODEL>
59 inline void enumerate_parameters(bsdf_attr flag, MODEL&& model, CALLBACK&& callback)
60 {
61 bbm::detail::enumerate_parameter_helper(flag, std::forward<MODEL>(model), callback, [](auto&& val) -> decltype(value(val)) { return value(val); } );
62 }
63
64
65 /*********************************************************************/
66 /*! \brief Enumerate the default values of the attributes from a bsdf model
67 *********************************************************************/
68 template<typename MODEL, typename CALLBACK> requires concepts::bsdfmodel<MODEL>
69 inline void enumerate_default_parameters(bsdf_attr flag, MODEL&& model, CALLBACK&& callback)
70 {
71 bbm::detail::enumerate_parameter_helper(flag, std::forward<MODEL>(model), callback, [](auto&& val) { return default_value(val); } );
72 }
73
74
75 /*********************************************************************/
76 /*! \brief Enumerate the lower bounds of the attributes from a bsdf model
77 *********************************************************************/
78 template<typename MODEL, typename CALLBACK> requires concepts::bsdfmodel<MODEL>
79 inline void enumerate_lower_bound(bsdf_attr flag, MODEL&& model, CALLBACK&& callback)
80 {
81 bbm::detail::enumerate_parameter_helper(flag, std::forward<MODEL>(model), callback, [](auto&& val) { return lower_bound(val); } );
82 }
83
84
85 /*********************************************************************/
86 /*! \brief Enumerate the upper bounds of the attributes from a bsdf model
87 *********************************************************************/
88 template<typename MODEL, typename CALLBACK> requires concepts::bsdfmodel<MODEL>
89 inline void enumerate_upper_bound(bsdf_attr flag, MODEL&& model, CALLBACK&& callback)
90 {
91 bbm::detail::enumerate_parameter_helper(flag, std::forward<MODEL>(model), callback, [](auto&& val) { return upper_bound(val); } );
92 }
93
94
95 /*********************************************************************/
96 /*! \brief Enumerate the parameters of a BSDF model in a vector
97
98 \param model = bsdf model to extract parameters from
99 \param flag = bsdf_attr flag to select a subset of the parameters
100 \returns vector of references to the bsdf parameter values
101 **********************************************************************/
102 template<typename MODEL> requires (concepts::bsdfmodel<MODEL> && !concepts::bsdf<MODEL>)
103 inline auto parameter_values(MODEL&& model, bsdf_attr flag=bsdf_attr::All)
104 {
105 // value type
106 using Value = std::conditional_t< bbm::is_const_v<MODEL>,
107 const typename std::decay_t<MODEL>::Value&,
108 typename std::decay_t<MODEL>::Value&
109 >;
110
111 // create vector
112 bbm::vector<Value> result;
113 enumerate_parameters(flag, std::forward<MODEL>(model), [&result](auto&& val) { result.push_back(std::forward<Value>(val)); });
114
115 // Done.
116 return result;
117 }
118
119
120 /*********************************************************************/
121 /*! \brief Enumerate the parameters of a BSDF in a vector
122
123 \param model = bsdf model to extract parameters from
124 \param flag = bsdf_attr flag to select a subset of the parameters
125 \returns vector of references to the bsdf parameter values
126 **********************************************************************/
127 template<typename BSDF> requires concepts::bsdf<BSDF>
129 {
130 return bsdf.parameter_values(flag);
131 }
132
133
134 /*********************************************************************/
135 /*! \brief Enumerate the default parameters of a BSDF model in a vector
136
137 \param model = bsdf model to extract default parameters from
138 \param flag = bsdf_attr flag to select a subset of the parameters
139 \returns vector of references to the bsdf parameter values
140 **********************************************************************/
141 template<typename MODEL> requires (concepts::bsdfmodel<MODEL> && !concepts::bsdf<MODEL>)
142 inline auto parameter_default_values(MODEL&& model, bsdf_attr flag=bsdf_attr::All)
143 {
144 // value type
145 using Value = typename std::decay_t<MODEL>::Value;
146
147 // create vector
148 bbm::vector<Value> result;
149 enumerate_default_parameters(flag, std::forward<MODEL>(model), [&result](auto&& val) { result.push_back(std::forward<decltype(val)>(val)); });
150
151 // Done.
152 return result;
153 }
154
155
156 /*********************************************************************/
157 /*! \brief Enumerate the default parameters of a BSDF in a vector
158
159 \param model = bsdf model to extract default parameters from
160 \param flag = bsdf_attr flag to select a subset of the parameters
161 \returns vector of references to the bsdf parameter values
162 **********************************************************************/
163 template<typename BSDF> requires concepts::bsdf<BSDF>
165 {
166 return bsdf.parameter_default_values(flag);
167 }
168
169
170 /*********************************************************************/
171 /*! \brief Enumerate the lower bound of the parameters of a BSDF model in a vector
172
173 \param model = bsdf model to extract lower bound from
174 \param flag = bsdf_attr flag to select a subset of the parameters
175 \returns vector of references to the bsdf parameter values
176 **********************************************************************/
177 template<typename MODEL> requires (concepts::bsdfmodel<MODEL> && !concepts::bsdf<MODEL>)
178 inline auto parameter_lower_bound(MODEL&& model, bsdf_attr flag=bsdf_attr::All)
179 {
180 // value type
181 using Value = typename std::decay_t<MODEL>::Value;
182
183 // create vector
184 bbm::vector<Value> result;
185 enumerate_lower_bound(flag, std::forward<MODEL>(model), [&result](auto&& val) { result.push_back(std::forward<decltype(val)>(val)); });
186
187 // Done.
188 return result;
189 }
190
191 /*********************************************************************/
192 /*! \brief Enumerate the lower bound of the parameters of a BSDF in a vector
193
194 \param model = bsdf model to extract lower bound from
195 \param flag = bsdf_attr flag to select a subset of the parameters
196 \returns vector of references to the bsdf parameter values
197 **********************************************************************/
198 template<typename BSDF> requires concepts::bsdf<BSDF>
199 inline auto parameter_lower_bound(const BSDF& bsdf, bsdf_attr flag=bsdf_attr::All)
200 {
201 return bsdf.parameter_lower_bound(flag);
202 }
203
204
205 /*********************************************************************/
206 /*! \brief Enumerate the upper bound of the parameters of a BSDF model in a vector
207
208 \param model = bsdf model to extract upper bound from
209 \param flag = bsdf_attr flag to select a subset of the parameters
210 \returns vector of references to the bsdf parameter values
211 **********************************************************************/
212 template<typename MODEL> requires (concepts::bsdfmodel<MODEL> && !concepts::bsdf<MODEL>)
213 inline auto parameter_upper_bound(MODEL&& model, bsdf_attr flag=bsdf_attr::All)
214 {
215 // value type
216 using Value = typename std::decay_t<MODEL>::Value;
217
218 // create vector
219 bbm::vector<Value> result;
220 enumerate_upper_bound(flag, model, [&result](auto&& val) { result.push_back(std::forward<decltype(val)>(val)); });
221
222 // Done.
223 return result;
224 }
225
226 /*********************************************************************/
227 /*! \brief Enumerate the upper bound of the parameters of a BSDF in a vector
228
229 \param model = bsdf model to extract upper bound from
230 \param flag = bsdf_attr flag to select a subset of the parameters
231 \returns vector of references to the bsdf parameter values
232 **********************************************************************/
233 template<typename BSDF> requires concepts::bsdf<BSDF>
234 inline auto parameter_upper_bound(const BSDF& bsdf, bsdf_attr flag=bsdf_attr::All)
235 {
236 return bsdf.parameter_upper_bound(flag);
237 }
238
239} // end bbm namespace
240
241#endif /* _BBM_BSDF_ENUMERATE_H_ */
All includes and helpers needed for declaring new bsdfmodels.
Abstract base definition of a BSDF (with virtual functions)
BSDF implementation of a BSDF model.
Definition: bsdf.h:30
virtual bbm::vector< Value > parameter_upper_bound(bsdf_attr flags=bsdf_attr::All) const override final
Definition: bsdf.h:149
virtual bbm::vector< Value > parameter_lower_bound(bsdf_attr flags=bsdf_attr::All) const override final
Definition: bsdf.h:144
virtual bbm::vector< Value > parameter_default_values(bsdf_attr flags=bsdf_attr::All) const override final
Definition: bsdf.h:139
virtual bbm::vector< Value & > parameter_values(bsdf_attr flags=bsdf_attr::All) override final
Definition: bsdf.h:129
Definition: vector_util.h:27
bsdf attribute contract
Complile-time for loop.
#define CONSTFOR(IDX, NUMITR,...)
HELPER MACRO.
Definition: constfor.h:63
A warpper class to attach a properties to a class via a property struct. The propert expects by defau...
Enumerate all elements in iterators recursively.
Scoped enum operators and methods.
constexpr decltype(auto) attributes(T &&t)
Definition: reflection.h:200
Definition: aggregatebsdf.h:29
auto parameter_default_values(MODEL &&model, bsdf_attr flag=bsdf_attr::All)
Enumerate the default parameters of a BSDF model in a vector.
Definition: bsdf_enumerate.h:142
void enumerate_default_parameters(bsdf_attr flag, MODEL &&model, CALLBACK &&callback)
Enumerate the default values of the attributes from a bsdf model.
Definition: bsdf_enumerate.h:69
constexpr auto default_value(T)
Definition: bsdf_attribute.h:37
void enumerate_lower_bound(bsdf_attr flag, MODEL &&model, CALLBACK &&callback)
Enumerate the lower bounds of the attributes from a bsdf model.
Definition: bsdf_enumerate.h:79
void enumerate_parameters(bsdf_attr flag, MODEL &&model, CALLBACK &&callback)
Enumerate the values of the attributes from a bsdf model.
Definition: bsdf_enumerate.h:59
auto parameter_upper_bound(MODEL &&model, bsdf_attr flag=bsdf_attr::All)
Enumerate the upper bound of the parameters of a BSDF model in a vector.
Definition: bsdf_enumerate.h:213
constexpr auto lower_bound(T)
Definition: bsdf_attribute.h:40
constexpr auto upper_bound(T)
Definition: bsdf_attribute.h:43
auto parameter_lower_bound(MODEL &&model, bsdf_attr flag=bsdf_attr::All)
Enumerate the lower bound of the parameters of a BSDF model in a vector.
Definition: bsdf_enumerate.h:178
constexpr auto is_set(const FLAGNAME &a, const FLAG &flag)
Check if all in 'flag' are also set in 'a'; compatible with packet types.
Definition: flags.h:100
decltype(auto) value(T &&t)
return the value of an attribute, or if not an attribute the object
Definition: attribute_value.h:20
auto parameter_values(MODEL &&model, bsdf_attr flag=bsdf_attr::All)
Enumerate the parameters of a BSDF model in a vector.
Definition: bsdf_enumerate.h:103
bsdf_attr
Attribute Property Flags.
Definition: bsdf_attr_flag.h:17
void enumerate_upper_bound(bsdf_attr flag, MODEL &&model, CALLBACK &&callback)
Enumerate the upper bounds of the attributes from a bsdf model.
Definition: bsdf_enumerate.h:89
Compile-time reflection of:
Extensions for the STL vector class.