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
63template <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
119template <class Data_T>
120class ProceduralField : public Field<Data_T>
121{
122
123public:
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
180private:
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
213template <>
214inline half
216 const half& defaultVal) const
217{
218 return metadata().intMetadata(name, static_cast<int>(defaultVal));
219}
220
221//----------------------------------------------------------------------------//
222
223template <>
224inline float
226 const float& defaultVal) const
227{
228 return metadata().intMetadata(name, static_cast<int>(defaultVal));
229}
230
231//----------------------------------------------------------------------------//
232
233template <>
234inline double
236 const double& defaultVal) const
237{
238 return metadata().intMetadata(name, static_cast<int>(defaultVal));
239}
240
241//----------------------------------------------------------------------------//
242
243template <>
244inline V3h
246 const V3h& defaultVal) const
247{
248 return V3h(metadata().vecIntMetadata(name, defaultVal));
249}
250
251//----------------------------------------------------------------------------//
252
253template <>
254inline V3f
256 const V3f& defaultVal) const
257{
258 return V3f(metadata().vecIntMetadata(name, defaultVal));
259}
260
261//----------------------------------------------------------------------------//
262
263template <>
264inline V3d
266 const V3d& defaultVal) const
267{
268 return V3d(metadata().vecIntMetadata(name, defaultVal));
269}
270
271//----------------------------------------------------------------------------//
272
273template <>
274inline half
276 const half& defaultVal) const
277{
278 return metadata().floatMetadata(name, static_cast<float>(defaultVal));
279}
280
281//----------------------------------------------------------------------------//
282
283template <>
284inline float
286 const float& defaultVal) const
287{
288 return metadata().floatMetadata(name, defaultVal);
289}
290
291//----------------------------------------------------------------------------//
292
293template <>
294inline double
296 const double& defaultVal) const
297{
298 return metadata().floatMetadata(name, static_cast<float>(defaultVal));
299}
300
301//----------------------------------------------------------------------------//
302
303template <>
304inline V3h
306 const V3h& defaultVal) const
307{
308 return V3h(metadata().vecFloatMetadata(name, defaultVal));
309}
310
311//----------------------------------------------------------------------------//
312
313template <>
314inline V3f
316 const V3f& defaultVal) const
317{
318 return V3f(metadata().vecFloatMetadata(name, defaultVal));
319}
320
321//----------------------------------------------------------------------------//
322
323template <>
324inline 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
Contains Field, WritableField and ResizableField classes.
#define FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(field)
Definition Field.h:479
#define FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
Definition Field.h:473
ProceduralField< V3f > ProceduralField3f
ProceduralField< half > ProceduralFieldh
ProceduralField< float > ProceduralFieldf
ProceduralField< V3h > ProceduralField3h
ProceduralField< V3d > ProceduralField3d
ProceduralField< double > ProceduralFieldd
Imath::V3d V3d
Definition SpiMathLib.h:74
FIELD3D_NAMESPACE_OPENtypedef ::half half
Definition SpiMathLib.h:64
Imath::Vec3< half > V3h
Definition SpiMathLib.h:72
Imath::V3f V3f
Definition SpiMathLib.h:73
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
std::string name
Optional name of the field.
Definition Field.h:171
Definition Field.h:390
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Definition Field.h:408
ProceduralField< Data_T > class_type
Data_T typedIntMetadata(const std::string &name, const Data_T &defaultVal) const
Calls either sampleIntMetadata() if the ProceduralField is scalar (half, float, or double),...
static const char * staticClassType()
static DEFINE_FIELD_RTTI_ABSTRACT_CLASS const char * staticClassName()
ProceduralFieldLookup< Data_T > LinearInterp
virtual ~ProceduralField()
Destructor.
static TemplatedFieldType< ProceduralField< Data_T > > ms_classType
ProceduralFieldLookup< Data_T > CubicInterp
virtual Data_T lsSample(const V3d &lsP) const =0
Field< Data_T > base
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.
Data_T typedFloatMetadata(const std::string &name, const Data_T &defaultVal) const
Calls either sampleFloatMetadata() if the ProceduralField is scalar (half, float, or double),...
boost::intrusive_ptr< ProceduralField > Ptr
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition ns.h:58
Used to return a string for the name of a templated field.
Definition Traits.h:283