Field3D
FieldWrapper.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------//
2
3#ifndef __F3DUTIL_FIELDWRAPPER_H__
4#define __F3DUTIL_FIELDWRAPPER_H__
5
6//------------------------------------------------------------------------------
7
8// Library includes
9#include <OpenEXR/ImathMatrixAlgo.h>
10
11// Project includes
12#include "DenseField.h"
13#include "Field3DFile.h"
14#include "FieldInterp.h"
15#include "InitIO.h"
16#include "MIPField.h"
17#include "MIPUtil.h"
18#include "SparseField.h"
19#include "FieldSampler.h"
20#include "FieldMapping.h"
21
22//----------------------------------------------------------------------------//
23
24#include "ns.h"
25
27
28//------------------------------------------------------------------------------
29// ValueRemapOp
30//------------------------------------------------------------------------------
31
40{
41public:
42
43 // Typedefs ---
44
45 typedef boost::shared_ptr<ValueRemapOp> Ptr;
46
47 // To be implemented by subclasses ---
48
50 virtual float remap(const float value) const = 0;
52 virtual V3f remap(const V3f &value) const = 0;
53
54};
55
56//------------------------------------------------------------------------------
57// FieldWrapper
58//------------------------------------------------------------------------------
59
62template <typename Field_T>
64{
65 typedef Field_T field_type;
66 typedef std::vector<FieldWrapper> Vec;
67
68 FieldWrapper(const typename Field_T::Ptr f)
69 : field(f.get()),
70 fieldPtr(f),
71 mapping(f->mapping().get()),
72 vsBounds(continuousBounds(f->dataWindow())),
73 worldScale(1.0),
77 { }
78
79 void setOsToWs(const M44d &i_osToWs)
80 {
82 wsToOs = osToWs.inverse();
83 // Compute world scale
84 V3d ws(1.0);
85 if (!Imath::extractScaling(osToWs, ws, false)) {
86 Msg::print("WARNING: FieldGroup/FieldWrapper: "
87 "Couldn't extract world scale from object-to-world "
88 "transform. Defaulting to 1.0.");
89 }
90 worldScale = std::max(std::max(ws.x, ws.y), ws.z);
91 // Set boolean
92 doOsToWs = true;
93
94 // Update wsBounds
97 }
98 }
99
101 {
103 return;
104 // wsBounds can be set only if mapping is a matrix
106 dynamic_cast<const MatrixFieldMapping*>(mapping);
107 if (mtx_mapping) {
108 const float time = 0;
109 M44d vsToWs;
110 if (doOsToWs) {
112 vsToWs = wsToVs.inverse();
113 } else {
114 wsToVs = mtx_mapping->worldToVoxel(time);
115 vsToWs = wsToVs.inverse();
116 }
117 const Imath::Box3d wsBounds_d = Imath::transform(vsBounds,
118 vsToWs);
119 wsBounds = Imath::Box3f(wsBounds_d.min, wsBounds_d.max);
121 }
122 }
123
129
130 typename Field_T::LinearInterp interp;
131 const Field_T *field;
132 typename Field_T::Ptr fieldPtr;
133 const Field3D::FieldMapping *mapping;
143 Imath::Box3f wsBounds;
148};
149
150//------------------------------------------------------------------------------
151// MIPFieldWrapper
152//------------------------------------------------------------------------------
153
156template <typename Field_T>
158{
159 typedef Field_T field_type;
160 typedef std::vector<MIPFieldWrapper> Vec;
161 typedef typename Field_T::LinearInterp LinearInterp;
162
163 MIPFieldWrapper(const typename Field_T::Ptr f)
165 field(f.get()),
166 fieldPtr(f),
167 mapping(f->mapping().get()),
168 vsBounds(continuousBounds(f->dataWindow())),
169 worldScale(1.0),
172 {
173 interp = interpPtr.get();
174 }
175
177 {
179 wsToOs = osToWs.inverse();
180 // Compute world scale
181 V3d ws(1.0);
182 if (!Imath::extractScaling(osToWs, ws, false)) {
183 Msg::print("WARNING: FieldGroup/FieldWrapper: "
184 "Couldn't extract world scale from object-to-world "
185 "transform. Defaulting to 1.0.");
186 }
187 worldScale = std::max(std::max(ws.x, ws.y), ws.z);
188 // Set boolean
189 doOsToWs = true;
190
191 // Update wsBounds
194 }
195 }
196
198 {
200 return;
201 // wsBounds can be set only if mapping is a matrix
203 dynamic_cast<const MatrixFieldMapping*>(mapping);
204 if (mtx_mapping) {
205 const float time = 0;
206 M44d vsToWs;
207 if (doOsToWs) {
209 vsToWs = wsToVs.inverse();
210 } else {
211 wsToVs = mtx_mapping->worldToVoxel(time);
212 vsToWs = wsToVs.inverse();
213 }
214 const Imath::Box3d wsBounds_d = Imath::transform(vsBounds,
215 vsToWs);
216 wsBounds = Imath::Box3f(wsBounds_d.min, wsBounds_d.max);
218 }
219 }
220
226
227 boost::shared_ptr<LinearInterp> interpPtr;
229 const Field_T *field;
230 typename Field_T::Ptr fieldPtr;
231 const Field3D::FieldMapping *mapping;
241 Imath::Box3f wsBounds;
246};
247
248//----------------------------------------------------------------------------//
249
251
252//------------------------------------------------------------------------------
253
254#endif // include guard
255
256//------------------------------------------------------------------------------
Contains the DenseField class.
Contains the Field3DFile classes.
Contains the FieldInterp base class and some standard interpolation classes.
Contains the FieldMapping base class and the NullFieldMapping and MatrixFieldMapping subclasses.
Box3d continuousBounds(const Box3i &bbox)
Definition Field.h:1111
Contains the initIO function.
Contains the MIPField class.
Contains MIP-related utility functions.
Contains the SparseField class.
Imath::Box3d Box3d
Definition SpiMathLib.h:79
Imath::V3d V3d
Definition SpiMathLib.h:74
Imath::V3f V3f
Definition SpiMathLib.h:73
Imath::M44d M44d
Definition SpiMathLib.h:82
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
Represents the mapping of a field by a matrix transform.
const M44d & worldToVoxel() const
Returns a reference to the world to voxel space transform.
The ValueRemapOp class is used when shader-like calculations need to be applied to individual fields ...
boost::shared_ptr< ValueRemapOp > Ptr
virtual V3f remap(const V3f &value) const =0
Remaps a V3f value.
virtual float remap(const float value) const =0
Remaps a float value.
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition Log.cpp:70
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition ns.h:58
This class wraps up a single field to make its interpolator and its mapping easily accessible....
bool doWsBoundsOptimization
Field_T field_type
ValueRemapOp::Ptr valueRemapOpPtr
Optionally, set a ValueRemapOp to remap values.
M44d osToWs
Optionally, enable doOsToWs to apply a world to object transform before lookups.
FieldWrapper(const typename Field_T::Ptr f)
void setOsToWs(const M44d &i_osToWs)
const ValueRemapOp * valueRemapOp
double worldScale
Field_T::Ptr fieldPtr
std::vector< FieldWrapper > Vec
M44d wsToVs
Optionally, enable wsBounds optimization to use a world axis aligned bounding box in lookups.
Field_T::LinearInterp interp
void setValueRemapOp(ValueRemapOp::Ptr op)
void setWsBoundsOptimization(const bool doWsBoundsOptimization_)
Imath::Box3f wsBounds
const Field_T * field
const Field3D::FieldMapping * mapping
This class wraps up a single MIP field to make its interpolator and its mapping easily accessible....
MIPFieldWrapper(const typename Field_T::Ptr f)
void setWsBoundsOptimization(const bool doWsBoundsOptimization_)
boost::shared_ptr< LinearInterp > interpPtr
LinearInterp * interp
void setValueRemapOp(ValueRemapOp::Ptr op)
void setOsToWs(const M44d &i_osToWs)
Field_T::Ptr fieldPtr
std::vector< MIPFieldWrapper > Vec
ValueRemapOp::Ptr valueRemapOpPtr
Optionally, set a ValueRemapOp to remap values.
Field_T::LinearInterp LinearInterp
M44d osToWs
Optionally, enable doOsToWs to apply a world to object transform before lookups.
Imath::Box3f wsBounds
M44d wsToVs
Optionally, enable wsBounds optimization to use a world axis aligned bounding box in lookups.
const Field_T * field
bool doWsBoundsOptimization
const Field3D::FieldMapping * mapping
const ValueRemapOp * valueRemapOp