Loading...
Searching...
No Matches
bsdf_ptr.h
Go to the documentation of this file.
1#ifndef _BBM_BSDF_PTR_H_
2#define _BBM_BSDF_PTR_H_
3
4#include "concepts/bsdf_ptr.h"
6
7#include "util/pointer.h"
8#include "core/error.h"
9#include "bbm/bsdf.h"
10
11/***********************************************************************/
12/*! \file bsdf_ptr.h
13 \brief A shared_ptr wrapper for bsdfs.
14
15 Implements concepts::bsdf_ptr
16************************************************************************/
17
18namespace bbm
19{
20 template<typename CONF> requires concepts::config<CONF>
21 struct bsdf_ptr : public virtual bsdf_base<CONF>
22 {
23 public:
25 static constexpr string_literal name = "BsdfPtr";
27
28 //! \brief Default (empty) constructor; shared_ptr is set to nullptr.
29 bsdf_ptr(void) = default;
30
31 //! \brief Construct from pointer
33
34 //! \brief Copy constructor
36
37 //! \brief Assignment operator
39 {
40 _bsdf = b._bsdf;
41 return *this;
42 }
43
44 //! \brief Get the internal shared pointer.
45 inline const pointer<bsdf_base<Config>>& ptr(void) const { return _bsdf; }
46
47 //! @{ \name Override the -> operator
49 {
50 if(!_bsdf) throw bbm_incomplete_init;
51 return _bsdf;
52 }
53
55 {
56 if(!_bsdf) throw bbm_incomplete_init;
57 return _bsdf;
58 }
59 //! @}
60
61 /******************************************************************/
62 /*! \brief Pointer-dereference passthrough of eval function
63
64 \param in = incoming direction
65 \param out = exitant direction
66 \param component = which reflectance component to eval
67 \param unit = unit of computation
68 \param mask = mask to enable/disable lanes
69 \returns the resulting Spectrum of the evaluation.
70 *******************************************************************/
71 virtual Spectrum eval(const Vec3d& in, const Vec3d& out, BsdfFlag component=bsdf_flag::All, unit_t unit=unit_t::Radiance, Mask mask=true) const override final
72 {
73 return (*this)->eval(in, out, component, unit, mask);
74 }
75
76
77 /******************************************************************/
78 /*! \brief Pointer-derefence passthrough of sample function
79
80 \param out = the outgoing direction
81 \param xi = two random variables stored in a Vec2d used to sample
82 \param component = which reflectance component to sample
83 \param unit = unit of computation
84 \param mask = mask to enable/disable lanes
85 \returns a BsdfSample that contains the sampled direction
86 and the corresponding pdf.
87 ******************************************************************/
88 virtual BsdfSample sample(const Vec3d& out, const Vec2d& xi, BsdfFlag component=bsdf_flag::All, unit_t unit=unit_t::Radiance, Mask mask=true) const override final
89 {
90 return (*this)->sample(out, xi, component, unit, mask);
91 }
92
93
94 /******************************************************************/
95 /*! \brief Pointer-dereference passthrough of the pdf function
96
97 \param in = the incoming direction
98 \param out = the exitant direction
99 \param component = which reflectance component was sampled
100 \param unit = unit of computation
101 \param mask = mask to enable/disable lanes
102 \returns the pdf of samling the in-out direction conbination.
103 *******************************************************************/
104 virtual Value pdf(const Vec3d& in, const Vec3d& out, BsdfFlag component=bsdf_flag::All, unit_t unit=unit_t::Radiance, Mask mask=true) const override final
105 {
106 return (*this)->pdf(in, out, component, unit, mask);
107 }
108
109
110 /******************************************************************/
111 /*! \brief Pointer-dereference passthrough of the hemispherical reflectance function
112
113 \param out = the outgoing direction
114 \param component = which reflectance component to eval
115 \param unit = unit of computation
116 \param mask = mask to enable/disable lanes
117 \returns the approximate hemispherical reflectance (Spectrum) of the BSDF
118 *******************************************************************/
119 virtual Spectrum reflectance(const Vec3d& out, BsdfFlag component=bsdf_flag::All, unit_t unit=unit_t::Radiance, Mask mask=true) const override final
120 {
121 return (*this)->reflectance(out, component, unit, mask);
122 }
123
124
125 /*******************************************************************/
126 /*! \brief Pointer-dereference passthrough of toString
127 *******************************************************************/
128 virtual std::string toString(void) const override final
129 {
130 return (*this)->toString();
131 }
132
133 /*******************************************************************/
134 /*! \name Parameter Enumeration passthrough
135 *******************************************************************/
137 {
138 return (*this)->parameter_values(flags);
139 }
140
142 {
143 return (*this)->parameter_values(flags);
144 }
145
147 {
148 return (*this)->parameter_default_values(flags);
149 }
150
152 {
153 return (*this)->parameter_lower_bound(flags);
154 }
155
157 {
158 return (*this)->parameter_upper_bound(flags);
159 }
160 //! @}
161
162 private:
163 //! \brief shared_prt to the actual BSDF implementation.
165 };
166
168
169
170 /*********************************************************************/
171 /*! \brief Helper method for making a bsdf_ptr from a BSDF (new construction)
172
173 \tparam BSDFTYPE = BSDF type that the ptr will point to.
174 \param args = constuctor arguments of the BSDF type.
175
176 This method allocates a new BSDF of BSDFTYPE, and constructs it with
177 the given arguments. The bsdf_ptr owns the BSDF type object.
178 **********************************************************************/
179 template<typename BSDFTYPE, typename... ARGS> requires concepts::bsdf<BSDFTYPE>
181 {
182 auto ptr = std::make_shared<BSDFTYPE>(args...);
183 return bsdf_ptr< get_config<BSDFTYPE> >(ptr);
184 }
185
186 /*********************************************************************/
187 /*! \brief Helper method for making a bsdf_ptr from a BSDF MODEL (new construction)
188
189 \tparam BSDFMODEL = BSDF model that the ptr will point to.
190 \param args = constuctor arguments of the BSDF type.
191
192 This method allocates a new BSDF of bsdf<BSDFMODEL>, and constructs it
193 with the given arguments. The bsdf_ptr owns the BSDF type object.
194 **********************************************************************/
195 template<typename BSDFMODEL, typename... ARGS> requires (concepts::bsdfmodel<BSDFMODEL> && !concepts::bsdf<BSDFMODEL>)
197 {
198 auto ptr = std::make_shared<bsdf<BSDFMODEL>>(args...);
200 }
201
202 /*********************************************************************/
203 /*! \brief Helper method for making a bsdf_ptr from a BSDF (copy construction)
204
205 \param arg = BSDF object we want to copy and have the bsdf_ptr point to.
206
207 This method allocates a copy of the BSDFTYPE object (arg). The bsdf_ptr
208 owns the copied object.
209 **********************************************************************/
210 template<typename BSDFTYPE> requires (concepts::bsdf<BSDFTYPE> && !concepts::bsdf_ptr<BSDFTYPE>)
212 {
213 auto ptr = std::make_shared<BSDFTYPE>(arg);
214 return bsdf_ptr< get_config<BSDFTYPE> >(ptr);
215 }
216
217 /*********************************************************************/
218 /*! \brief Helper method for making a bsdf_ptr from a BSDF MODEL (copy construction)
219
220 \param arg = BSDF model object we want to copy and have the bsdf_ptr point to.
221
222 This method allocates a bsdf<BSDFMODEL> object (copy from arg). The
223 bsdf_ptr owns the copied object.
224 **********************************************************************/
225 template<typename BSDFMODEL> requires (concepts::bsdfmodel<BSDFMODEL> && !concepts::bsdf<BSDFMODEL>)
227 {
228 auto ptr = std::make_shared<bsdf<BSDFMODEL>>(arg);
230 }
231
232 /*********************************************************************/
233 /*! \brief Helper method for making a bsdf_ptr (avoid bsdf_ptr of bsdf_ptr)
234
235 \param arg = bsdf_ptr object we want to copy
236 **********************************************************************/
237 template<typename CONF> requires concepts::config<CONF>
239 {
240 return arg;
241 }
242
243} // end bbm namespace
244
245#endif /* _BBM_BSDF_PTR_H_ */
246
247
Connects a BSDF model and a BSDF.
Pointer wrapper that takes handle both shared as well as regular (unmanaged) pointers.
Definition: pointer.h:28
Definition: vector_util.h:27
bsdf_ptr concpt
Definition: bsdf_ptr.h:24
bsdf concept
Definition: bsdf.h:29
bsdf_ptr contract
Predefined exceptions for common errors.
#define bbm_incomplete_init
Definition: error.h:42
concept to check if a type has a valid string_converter.
#define BBM_CHECK_CONCEPT(CONCEPTNAME, CLASSNAME,...)
Check a class for a concept with bbm::concepts::archetypes in the namespace.
Definition: macro.h:35
Definition: aggregatebsdf.h:29
typename std::decay_t< T >::Config get_config
get_config type trait
Definition: config.h:49
bsdf_ptr< get_config< BSDFTYPE > > make_bsdf_ptr(ARGS... args)
Helper method for making a bsdf_ptr from a BSDF (new construction)
Definition: bsdf_ptr.h:180
bsdf_attr
Attribute Property Flags.
Definition: bsdf_attr_flag.h:17
unit_t
Light Unit.
Definition: unit.h:21
Forward declaration of bbm::arg.
Definition: arg.h:27
Pointer wrapper that takes both shared and non-shared pointers. If the pointer is 'managed' then the ...
Forward declaration.
Definition: args.h:248
Forward declaration.
Definition: bsdf_base.h:55
Definition: bsdf_ptr.h:22
virtual bbm::vector< Value > parameter_upper_bound(bsdf_attr flags=bsdf_attr::All) const override final
Definition: bsdf_ptr.h:156
virtual bbm::vector< Value > parameter_lower_bound(bsdf_attr flags=bsdf_attr::All) const override final
Definition: bsdf_ptr.h:151
virtual bbm::vector< Value > parameter_default_values(bsdf_attr flags=bsdf_attr::All) const override final
Definition: bsdf_ptr.h:146
virtual Value pdf(const Vec3d &in, const Vec3d &out, BsdfFlag component=bsdf_flag::All, unit_t unit=unit_t::Radiance, Mask mask=true) const override final
Pointer-dereference passthrough of the pdf function.
Definition: bsdf_ptr.h:104
BBM_IMPORT_CONFIG(CONF)
virtual Spectrum eval(const Vec3d &in, const Vec3d &out, BsdfFlag component=bsdf_flag::All, unit_t unit=unit_t::Radiance, Mask mask=true) const override final
Pointer-dereference passthrough of eval function.
Definition: bsdf_ptr.h:71
virtual BsdfSample sample(const Vec3d &out, const Vec2d &xi, BsdfFlag component=bsdf_flag::All, unit_t unit=unit_t::Radiance, Mask mask=true) const override final
Pointer-derefence passthrough of sample function.
Definition: bsdf_ptr.h:88
BBM_BSDF_FORWARD
Definition: bsdf_ptr.h:26
bsdf_ptr(void)=default
Default (empty) constructor; shared_ptr is set to nullptr.
pointer< bsdf_base< Config > > _bsdf
shared_prt to the actual BSDF implementation.
Definition: bsdf_ptr.h:164
bsdf_ptr(const bsdf_ptr< CONF > &b)
Copy constructor.
Definition: bsdf_ptr.h:35
virtual bbm::vector< Value & > parameter_values(bsdf_attr flags=bsdf_attr::All) override final
Definition: bsdf_ptr.h:136
const pointer< bsdf_base< Config > > & ptr(void) const
Get the internal shared pointer.
Definition: bsdf_ptr.h:45
bsdf_ptr & operator=(const bsdf_ptr &b)
Assignment operator.
Definition: bsdf_ptr.h:38
const pointer< bsdf_base< Config > > & operator->(void)
Definition: bsdf_ptr.h:48
virtual bbm::vector< const Value & > parameter_values(bsdf_attr flags=bsdf_attr::All) const override final
Definition: bsdf_ptr.h:141
virtual Spectrum reflectance(const Vec3d &out, BsdfFlag component=bsdf_flag::All, unit_t unit=unit_t::Radiance, Mask mask=true) const override final
Pointer-dereference passthrough of the hemispherical reflectance function.
Definition: bsdf_ptr.h:119
static constexpr string_literal name
Definition: bsdf_ptr.h:25
pointer< const bsdf_base< Config > > operator->(void) const
Definition: bsdf_ptr.h:54
virtual std::string toString(void) const override final
Pointer-dereference passthrough of toString.
Definition: bsdf_ptr.h:128
bsdf_ptr(const pointer< bsdf_base< Config > > &ptr)
Construct from pointer.
Definition: bsdf_ptr.h:32
Definition: string_literal.h:16