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 *classType()
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 
159  virtual std::string className() const
160  { return staticClassName(); }
161 
162  // From Field ----------------------------------------------------------------
163 
166  virtual Data_T value(int i, int j, int k) const = 0;
167 
168  // Main methods --------------------------------------------------------------
169 
173  Data_T typedIntMetadata(const std::string &name,
174  const Data_T& defaultVal) const;
178  Data_T typedFloatMetadata(const std::string &name,
179  const Data_T& defaultVal) const;
180 
181 private:
182 
183  // Static data members -------------------------------------------------------
184 
186 
187  // Typedefs ------------------------------------------------------------------
188 
190 
191 };
192 
193 //----------------------------------------------------------------------------//
194 // Typedefs
195 //----------------------------------------------------------------------------//
196 
203 
204 //----------------------------------------------------------------------------//
205 // Static member instantiation
206 //----------------------------------------------------------------------------//
207 
209 
210 //----------------------------------------------------------------------------//
211 // Template specializations
212 //----------------------------------------------------------------------------//
213 
214 template <>
215 inline half
217  const half& defaultVal) const
218 {
219  return metadata().intMetadata(name, static_cast<int>(defaultVal));
220 }
221 
222 //----------------------------------------------------------------------------//
223 
224 template <>
225 inline float
227  const float& defaultVal) const
228 {
229  return metadata().intMetadata(name, static_cast<int>(defaultVal));
230 }
231 
232 //----------------------------------------------------------------------------//
233 
234 template <>
235 inline double
237  const double& defaultVal) const
238 {
239  return metadata().intMetadata(name, static_cast<int>(defaultVal));
240 }
241 
242 //----------------------------------------------------------------------------//
243 
244 template <>
245 inline V3h
247  const V3h& defaultVal) const
248 {
249  return V3h(metadata().vecIntMetadata(name, defaultVal));
250 }
251 
252 //----------------------------------------------------------------------------//
253 
254 template <>
255 inline V3f
257  const V3f& defaultVal) const
258 {
259  return V3f(metadata().vecIntMetadata(name, defaultVal));
260 }
261 
262 //----------------------------------------------------------------------------//
263 
264 template <>
265 inline V3d
267  const V3d& defaultVal) const
268 {
269  return V3d(metadata().vecIntMetadata(name, defaultVal));
270 }
271 
272 //----------------------------------------------------------------------------//
273 
274 template <>
275 inline half
277  const half& defaultVal) const
278 {
279  return metadata().floatMetadata(name, static_cast<float>(defaultVal));
280 }
281 
282 //----------------------------------------------------------------------------//
283 
284 template <>
285 inline float
287  const float& defaultVal) const
288 {
289  return metadata().floatMetadata(name, defaultVal);
290 }
291 
292 //----------------------------------------------------------------------------//
293 
294 template <>
295 inline double
297  const double& defaultVal) const
298 {
299  return metadata().floatMetadata(name, static_cast<float>(defaultVal));
300 }
301 
302 //----------------------------------------------------------------------------//
303 
304 template <>
305 inline V3h
307  const V3h& defaultVal) const
308 {
309  return V3h(metadata().vecFloatMetadata(name, defaultVal));
310 }
311 
312 //----------------------------------------------------------------------------//
313 
314 template <>
315 inline V3f
317  const V3f& defaultVal) const
318 {
319  return V3f(metadata().vecFloatMetadata(name, defaultVal));
320 }
321 
322 //----------------------------------------------------------------------------//
323 
324 template <>
325 inline V3d
327  const V3d& defaultVal) const
328 {
329  return V3d(metadata().vecFloatMetadata(name, defaultVal));
330 }
331 
332 //----------------------------------------------------------------------------//
333 
335 
336 //----------------------------------------------------------------------------//
337 
338 #endif // Include guard
339 
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
static TemplatedFieldType< ProceduralField< Data_T > > ms_classType
Field< Data_T > base
ProceduralFieldLookup< Data_T > LinearInterp
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(ProceduralField)
ProceduralField< double > ProceduralFieldd
Definition: Field.h:376
virtual ~ProceduralField()
Destructor.
ProceduralField< V3f > ProceduralField3f
ProceduralField< float > ProceduralFieldf
boost::intrusive_ptr< ProceduralField > Ptr
ProceduralField< half > ProceduralFieldh
virtual std::string className() const
Returns the class name of the object. Used by the class pool and when writing the data to disk...
static DEFINE_FIELD_RTTI_ABSTRACT_CLASS const char * staticClassName()
Imath::Vec3< half > V3h
Definition: SpiMathLib.h:72
FIELD3D_NAMESPACE_OPEN typedef::half half
Definition: SpiMathLib.h:64
ProceduralFieldLookup< Data_T > CubicInterp
virtual Data_T lsSample(const V3d &lsP) const =0
Data_T typedIntMetadata(const std::string &name, const Data_T &defaultVal) const
Calls either sampleIntMetadata() if the ProceduralField is scalar (half, float, or double)...
virtual 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...
Imath::V3d V3d
Definition: SpiMathLib.h:74
ProceduralField< Data_T > class_type
static const char * classType()
Imath::V3f V3f
Definition: SpiMathLib.h:73
ProceduralField< V3d > ProceduralField3d
ProceduralField< V3h > ProceduralField3h
Used to return a string for the name of a templated field.
Definition: Traits.h:116
Contains Field, WritableField and ResizableField classes.
Data_T typedFloatMetadata(const std::string &name, const Data_T &defaultVal) const
Calls either sampleFloatMetadata() if the ProceduralField is scalar (half, float, or double)...
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Definition: Field.h:395
std::string name
Optional name of the field.
Definition: Field.h:173