Field3D
ProceduralField.h
Go to the documentation of this file.
1 //----------------------------------------------------------------------------//
2 
3 /*
4  * Copyright (c) 2009 Sony Pictures Imageworks Inc
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution. Neither the name of Sony Pictures Imageworks nor the
18  * names of its contributors may be used to endorse or promote
19  * products derived from this software without specific prior written
20  * permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 //----------------------------------------------------------------------------//
37 
44 //----------------------------------------------------------------------------//
45 
46 #ifndef _INCLUDED_Field3D_ProceduralField_H_
47 #define _INCLUDED_Field3D_ProceduralField_H_
48 
49 //----------------------------------------------------------------------------//
50 
51 #include "Field.h"
52 
53 //----------------------------------------------------------------------------//
54 
55 #include "ns.h"
56 
58 
59 //----------------------------------------------------------------------------//
60 // Forward declarations
61 //----------------------------------------------------------------------------//
62 
63 template <class T>
65 
66 //----------------------------------------------------------------------------//
67 // Utility macros
68 //----------------------------------------------------------------------------//
69 
70 #define REGISTER_FIELD_TYPES(FIELDCLASS) \
71  factory.registerField(FIELDCLASS<half>::create); \
72  factory.registerField(FIELDCLASS<float>::create); \
73  factory.registerField(FIELDCLASS<double>::create); \
74  factory.registerField(FIELDCLASS<V3h>::create); \
75  factory.registerField(FIELDCLASS<V3f>::create); \
76  factory.registerField(FIELDCLASS<V3d>::create)
77 
78 #define INSTANTIATE_FIELD_TYPES(FIELDCLASS) \
79  template class FIELDCLASS<half>; \
80  template class FIELDCLASS<float>; \
81  template class FIELDCLASS<double>; \
82  template class FIELDCLASS<V3h>; \
83  template class FIELDCLASS<V3f>; \
84  template class FIELDCLASS<V3d>
85 
86 //----------------------------------------------------------------------------//
87 // ProceduralField
88 //----------------------------------------------------------------------------//
89 
117 //----------------------------------------------------------------------------//
118 
119 template <class Data_T>
120 class ProceduralField : public Field<Data_T>
121 {
122 
123 public:
124 
125  // Typedefs ------------------------------------------------------------------
126 
127  typedef boost::intrusive_ptr<ProceduralField> Ptr;
128 
131 
132  // RTTI replacement ----------------------------------------------------------
133 
136 
137  static const char *staticClassName()
138  {
139  return "ProceduralField";
140  }
141 
142  static const char *staticClassType()
143  {
145  }
146 
147  // Constructors --------------------------------------------------------------
148 
151  { /* Empty */ }
152 
153  // To be implemented by subclasses -------------------------------------------
154 
155  virtual Data_T lsSample(const V3d &lsP) const = 0;
156 
157  // From FieldBase ------------------------------------------------------------
158 
160 
161  // From Field ----------------------------------------------------------------
162 
165  virtual Data_T value(int i, int j, int k) const = 0;
166 
167  // Main methods --------------------------------------------------------------
168 
172  Data_T typedIntMetadata(const std::string &name,
173  const Data_T& defaultVal) const;
177  Data_T typedFloatMetadata(const std::string &name,
178  const Data_T& defaultVal) const;
179 
180 private:
181 
182  // Static data members -------------------------------------------------------
183 
185 
186  // Typedefs ------------------------------------------------------------------
187 
189 
190 };
191 
192 //----------------------------------------------------------------------------//
193 // Typedefs
194 //----------------------------------------------------------------------------//
195 
202 
203 //----------------------------------------------------------------------------//
204 // Static member instantiation
205 //----------------------------------------------------------------------------//
206 
208 
209 //----------------------------------------------------------------------------//
210 // Template specializations
211 //----------------------------------------------------------------------------//
212 
213 template <>
214 inline half
216  const half& defaultVal) const
217 {
218  return metadata().intMetadata(name, static_cast<int>(defaultVal));
219 }
220 
221 //----------------------------------------------------------------------------//
222 
223 template <>
224 inline float
226  const float& defaultVal) const
227 {
228  return metadata().intMetadata(name, static_cast<int>(defaultVal));
229 }
230 
231 //----------------------------------------------------------------------------//
232 
233 template <>
234 inline double
236  const double& defaultVal) const
237 {
238  return metadata().intMetadata(name, static_cast<int>(defaultVal));
239 }
240 
241 //----------------------------------------------------------------------------//
242 
243 template <>
244 inline V3h
246  const V3h& defaultVal) const
247 {
248  return V3h(metadata().vecIntMetadata(name, defaultVal));
249 }
250 
251 //----------------------------------------------------------------------------//
252 
253 template <>
254 inline V3f
256  const V3f& defaultVal) const
257 {
258  return V3f(metadata().vecIntMetadata(name, defaultVal));
259 }
260 
261 //----------------------------------------------------------------------------//
262 
263 template <>
264 inline V3d
266  const V3d& defaultVal) const
267 {
268  return V3d(metadata().vecIntMetadata(name, defaultVal));
269 }
270 
271 //----------------------------------------------------------------------------//
272 
273 template <>
274 inline half
276  const half& defaultVal) const
277 {
278  return metadata().floatMetadata(name, static_cast<float>(defaultVal));
279 }
280 
281 //----------------------------------------------------------------------------//
282 
283 template <>
284 inline float
286  const float& defaultVal) const
287 {
288  return metadata().floatMetadata(name, defaultVal);
289 }
290 
291 //----------------------------------------------------------------------------//
292 
293 template <>
294 inline double
296  const double& defaultVal) const
297 {
298  return metadata().floatMetadata(name, static_cast<float>(defaultVal));
299 }
300 
301 //----------------------------------------------------------------------------//
302 
303 template <>
304 inline V3h
306  const V3h& defaultVal) const
307 {
308  return V3h(metadata().vecFloatMetadata(name, defaultVal));
309 }
310 
311 //----------------------------------------------------------------------------//
312 
313 template <>
314 inline V3f
316  const V3f& defaultVal) const
317 {
318  return V3f(metadata().vecFloatMetadata(name, defaultVal));
319 }
320 
321 //----------------------------------------------------------------------------//
322 
323 template <>
324 inline V3d
326  const V3d& defaultVal) const
327 {
328  return V3d(metadata().vecFloatMetadata(name, defaultVal));
329 }
330 
331 //----------------------------------------------------------------------------//
332 
334 
335 //----------------------------------------------------------------------------//
336 
337 #endif // Include guard
338 
FIELD3D_NAMESPACE_HEADER_CLOSE
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
ProceduralField::staticClassType
static const char * staticClassType()
Definition: ProceduralField.h:142
ProceduralField::Ptr
boost::intrusive_ptr< ProceduralField > Ptr
Definition: ProceduralField.h:127
Field::DEFINE_FIELD_RTTI_ABSTRACT_CLASS
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Definition: Field.h:408
ProceduralField
Definition: ProceduralField.h:120
V3d
Imath::V3d V3d
Definition: SpiMathLib.h:74
ProceduralFieldLookup
Definition: FieldInterp.h:493
ProceduralField3h
ProceduralField< V3h > ProceduralField3h
Definition: ProceduralField.h:199
V3f
Imath::V3f V3f
Definition: SpiMathLib.h:73
ProceduralFieldd
ProceduralField< double > ProceduralFieldd
Definition: ProceduralField.h:198
FieldBase::name
std::string name
Optional name of the field.
Definition: Field.h:171
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(ProceduralField)
ProceduralField::LinearInterp
ProceduralFieldLookup< Data_T > LinearInterp
Definition: ProceduralField.h:129
ProceduralField::value
virtual FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION Data_T value(int i, int j, int k) const =0
Transforms the point from voxel space to subclass's space and calls the appropriate sample function.
half
FIELD3D_NAMESPACE_OPEN typedef ::half half
Definition: SpiMathLib.h:64
ns.h
ProceduralField::~ProceduralField
virtual ~ProceduralField()
Destructor.
Definition: ProceduralField.h:150
ProceduralFieldh
ProceduralField< half > ProceduralFieldh
Definition: ProceduralField.h:196
ProceduralField3f
ProceduralField< V3f > ProceduralField3f
Definition: ProceduralField.h:200
ProceduralField::staticClassName
static const DEFINE_FIELD_RTTI_ABSTRACT_CLASS char * staticClassName()
Definition: ProceduralField.h:137
ProceduralField::typedIntMetadata
Data_T typedIntMetadata(const std::string &name, const Data_T &defaultVal) const
Calls either sampleIntMetadata() if the ProceduralField is scalar (half, float, or double),...
Field.h
Contains Field, WritableField and ResizableField classes.
ProceduralFieldf
ProceduralField< float > ProceduralFieldf
Definition: ProceduralField.h:197
ProceduralField::base
Field< Data_T > base
Definition: ProceduralField.h:188
ProceduralField::typedFloatMetadata
Data_T typedFloatMetadata(const std::string &name, const Data_T &defaultVal) const
Calls either sampleFloatMetadata() if the ProceduralField is scalar (half, float, or double),...
ProceduralField::lsSample
virtual Data_T lsSample(const V3d &lsP) const =0
FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
#define FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
Definition: Field.h:473
V3h
Imath::Vec3< half > V3h
Definition: SpiMathLib.h:72
ProceduralField::ms_classType
static TemplatedFieldType< ProceduralField< Data_T > > ms_classType
Definition: ProceduralField.h:184
FIELD3D_NAMESPACE_OPEN
Definition: FieldMapping.cpp:74
Field
Definition: Field.h:389
TemplatedFieldType
Used to return a string for the name of a templated field.
Definition: Traits.h:282
ProceduralField3d
ProceduralField< V3d > ProceduralField3d
Definition: ProceduralField.h:201
ProceduralField::class_type
ProceduralField< Data_T > class_type
Definition: ProceduralField.h:134
ProceduralField::CubicInterp
ProceduralFieldLookup< Data_T > CubicInterp
Definition: ProceduralField.h:130