FieldWrapper.h
Go to the documentation of this file.
//----------------------------------------------------------------------------//
#ifndef __F3DUTIL_FIELDWRAPPER_H__
#define __F3DUTIL_FIELDWRAPPER_H__
//------------------------------------------------------------------------------
// Library includes
#include <OpenEXR/ImathMatrixAlgo.h>
// Project includes
#include "DenseField.h"
#include "Field3DFile.h"
#include "FieldInterp.h"
#include "InitIO.h"
#include "MIPField.h"
#include "MIPUtil.h"
#include "SparseField.h"
#include "FieldSampler.h"
#include "FieldMapping.h"
//----------------------------------------------------------------------------//
#include "ns.h"
FIELD3D_NAMESPACE_OPEN
//------------------------------------------------------------------------------
// ValueRemapOp
//------------------------------------------------------------------------------
class ValueRemapOp
{
public:
// Typedefs ---
typedef boost::shared_ptr<ValueRemapOp> Ptr;
// To be implemented by subclasses ---
virtual float remap(const float value) const = 0;
virtual V3f remap(const V3f &value) const = 0;
};
//------------------------------------------------------------------------------
// FieldWrapper
//------------------------------------------------------------------------------
template <typename Field_T>
struct FieldWrapper
{
typedef Field_T field_type;
typedef std::vector<FieldWrapper> Vec;
FieldWrapper(const typename Field_T::Ptr f)
: field(f.get()),
fieldPtr(f),
mapping(f->mapping().get()),
vsBounds(continuousBounds(f->dataWindow())),
worldScale(1.0),
doOsToWs(false),
doWsBoundsOptimization(false),
valueRemapOp(NULL)
{ }
void setOsToWs(const M44d &i_osToWs)
{
osToWs = i_osToWs;
wsToOs = osToWs.inverse();
// Compute world scale
V3d ws(1.0);
if (!Imath::extractScaling(osToWs, ws, false)) {
Msg::print("WARNING: FieldGroup/FieldWrapper: "
"Couldn't extract world scale from object-to-world "
"transform. Defaulting to 1.0.");
}
worldScale = std::max(std::max(ws.x, ws.y), ws.z);
// Set boolean
doOsToWs = true;
// Update wsBounds
if (doWsBoundsOptimization) {
setWsBoundsOptimization(doWsBoundsOptimization);
}
}
void setWsBoundsOptimization(const bool doWsBoundsOptimization_)
{
if (!doWsBoundsOptimization_)
return;
// wsBounds can be set only if mapping is a matrix
const MatrixFieldMapping *mtx_mapping =
dynamic_cast<const MatrixFieldMapping*>(mapping);
if (mtx_mapping) {
const float time = 0;
M44d vsToWs;
if (doOsToWs) {
wsToVs = wsToOs * mtx_mapping->worldToVoxel(time);
vsToWs = wsToVs.inverse();
} else {
wsToVs = mtx_mapping->worldToVoxel(time);
vsToWs = wsToVs.inverse();
}
const Imath::Box3d wsBounds_d = Imath::transform(vsBounds,
vsToWs);
wsBounds = Imath::Box3f(wsBounds_d.min, wsBounds_d.max);
doWsBoundsOptimization = true;
}
}
void setValueRemapOp(ValueRemapOp::Ptr op)
{
valueRemapOpPtr = op;
valueRemapOp = valueRemapOpPtr.get();
}
typename Field_T::LinearInterp interp;
const Field_T *field;
typename Field_T::Ptr fieldPtr;
const Field3D::FieldMapping *mapping;
Box3d vsBounds;
M44d osToWs, wsToOs;
double worldScale;
bool doOsToWs;
M44d wsToVs;
Imath::Box3f wsBounds;
bool doWsBoundsOptimization;
ValueRemapOp::Ptr valueRemapOpPtr;
const ValueRemapOp *valueRemapOp;
};
//------------------------------------------------------------------------------
// MIPFieldWrapper
//------------------------------------------------------------------------------
template <typename Field_T>
struct MIPFieldWrapper
{
typedef Field_T field_type;
typedef std::vector<MIPFieldWrapper> Vec;
typedef typename Field_T::LinearInterp LinearInterp;
MIPFieldWrapper(const typename Field_T::Ptr f)
: interpPtr(new LinearInterp(*f)),
field(f.get()),
fieldPtr(f),
mapping(f->mapping().get()),
vsBounds(continuousBounds(f->dataWindow())),
worldScale(1.0),
doOsToWs(false),
valueRemapOp(NULL)
{
interp = interpPtr.get();
}
void setOsToWs(const M44d &i_osToWs)
{
osToWs = i_osToWs;
wsToOs = osToWs.inverse();
// Compute world scale
V3d ws(1.0);
if (!Imath::extractScaling(osToWs, ws, false)) {
Msg::print("WARNING: FieldGroup/FieldWrapper: "
"Couldn't extract world scale from object-to-world "
"transform. Defaulting to 1.0.");
}
worldScale = std::max(std::max(ws.x, ws.y), ws.z);
// Set boolean
doOsToWs = true;
// Update wsBounds
if (doWsBoundsOptimization) {
setWsBoundsOptimization(doWsBoundsOptimization);
}
}
void setWsBoundsOptimization(const bool doWsBoundsOptimization_)
{
if (!doWsBoundsOptimization_)
return;
// wsBounds can be set only if mapping is a matrix
const MatrixFieldMapping *mtx_mapping =
dynamic_cast<const MatrixFieldMapping*>(mapping);
if (mtx_mapping) {
const float time = 0;
M44d vsToWs;
if (doOsToWs) {
wsToVs = wsToOs * mtx_mapping->worldToVoxel(time);
vsToWs = wsToVs.inverse();
} else {
wsToVs = mtx_mapping->worldToVoxel(time);
vsToWs = wsToVs.inverse();
}
const Imath::Box3d wsBounds_d = Imath::transform(vsBounds,
vsToWs);
wsBounds = Imath::Box3f(wsBounds_d.min, wsBounds_d.max);
doWsBoundsOptimization = true;
}
}
void setValueRemapOp(ValueRemapOp::Ptr op)
{
valueRemapOpPtr = op;
valueRemapOp = valueRemapOpPtr.get();
}
boost::shared_ptr<LinearInterp> interpPtr;
LinearInterp *interp;
const Field_T *field;
typename Field_T::Ptr fieldPtr;
const Field3D::FieldMapping *mapping;
Box3d vsBounds;
M44d osToWs, wsToOs;
double worldScale;
bool doOsToWs;
M44d wsToVs;
Imath::Box3f wsBounds;
bool doWsBoundsOptimization;
ValueRemapOp::Ptr valueRemapOpPtr;
const ValueRemapOp *valueRemapOp;
};
//----------------------------------------------------------------------------//
FIELD3D_NAMESPACE_HEADER_CLOSE
//------------------------------------------------------------------------------
#endif // include guard
//------------------------------------------------------------------------------
DenseField.h
Contains the DenseField class.
Field3DFile.h
Contains the Field3DFile classes.
FieldInterp.h
Contains the FieldInterp base class and some standard interpolation classes.
FieldMapping.h
Contains the FieldMapping base class and the NullFieldMapping and MatrixFieldMapping subclasses.
FieldSampler.h
continuousBounds
Box3d continuousBounds(const Box3i &bbox)
Definition Field.h:1111
InitIO.h
Contains the initIO function.
MIPField.h
Contains the MIPField class.
MIPUtil.h
Contains MIP-related utility functions.
SparseField.h
Contains the SparseField class.
Box3d
Imath::Box3d Box3d
Definition SpiMathLib.h:79
V3d
Imath::V3d V3d
Definition SpiMathLib.h:74
V3f
Imath::V3f V3f
Definition SpiMathLib.h:73
M44d
Imath::M44d M44d
Definition SpiMathLib.h:82
MatrixFieldMapping
Represents the mapping of a field by a matrix transform.
Definition FieldMapping.h:335
MatrixFieldMapping::worldToVoxel
const M44d & worldToVoxel() const
Returns a reference to the world to voxel space transform.
Definition FieldMapping.h:381
ValueRemapOp
The ValueRemapOp class is used when shader-like calculations need to be applied to individual fields ...
Definition FieldWrapper.h:40
ValueRemapOp::Ptr
boost::shared_ptr< ValueRemapOp > Ptr
Definition FieldWrapper.h:45
ValueRemapOp::remap
virtual V3f remap(const V3f &value) const =0
Remaps a V3f value.
ValueRemapOp::remap
virtual float remap(const float value) const =0
Remaps a float value.
FIELD3D_NAMESPACE_OPEN
Definition FieldMapping.cpp:74
Msg::print
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
ns.h
FIELD3D_NAMESPACE_HEADER_CLOSE
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition ns.h:58
Vec::doWsBoundsOptimization
bool doWsBoundsOptimization
Definition FieldWrapper.h:144
Vec::field_type
Field3D::DenseField< T > field_type
Definition FieldWrapper.h:65
Vec::valueRemapOpPtr
ValueRemapOp::Ptr valueRemapOpPtr
Definition FieldWrapper.h:146
Vec::osToWs
M44d osToWs
Definition FieldWrapper.h:137
FieldWrapper::FieldWrapper
FieldWrapper(const typename Field_T::Ptr f)
Definition FieldWrapper.h:68
FieldWrapper::setOsToWs
void setOsToWs(const M44d &i_osToWs)
Definition FieldWrapper.h:79
Vec::valueRemapOp
const ValueRemapOp * valueRemapOp
Definition FieldWrapper.h:147
Vec::worldScale
double worldScale
Definition FieldWrapper.h:138
Vec::fieldPtr
Field3D::DenseField< T >::Ptr fieldPtr
Definition FieldWrapper.h:132
Vec::Vec
std::vector< FieldWrapper > Vec
Definition FieldWrapper.h:66
Vec::wsToVs
M44d wsToVs
Definition FieldWrapper.h:142
Vec::vsBounds
Box3d vsBounds
Definition FieldWrapper.h:134
Vec::interp
Field3D::DenseField< T >::LinearInterp interp
Definition FieldWrapper.h:130
FieldWrapper::setValueRemapOp
void setValueRemapOp(ValueRemapOp::Ptr op)
Definition FieldWrapper.h:124
FieldWrapper::setWsBoundsOptimization
void setWsBoundsOptimization(const bool doWsBoundsOptimization_)
Definition FieldWrapper.h:100
Vec::wsBounds
Imath::Box3f wsBounds
Definition FieldWrapper.h:143
Vec::wsToOs
M44d wsToOs
Definition FieldWrapper.h:137
Vec::field
const Field3D::DenseField< T > * field
Definition FieldWrapper.h:131
Vec::mapping
const Field3D::FieldMapping * mapping
Definition FieldWrapper.h:133
Vec::doOsToWs
bool doOsToWs
Definition FieldWrapper.h:139
MIPFieldWrapper::MIPFieldWrapper
MIPFieldWrapper(const typename Field_T::Ptr f)
Definition FieldWrapper.h:163
Vec::vsBounds
Box3d vsBounds
Definition FieldWrapper.h:232
MIPFieldWrapper::setWsBoundsOptimization
void setWsBoundsOptimization(const bool doWsBoundsOptimization_)
Definition FieldWrapper.h:197
Vec::worldScale
double worldScale
Definition FieldWrapper.h:236
Vec::interpPtr
boost::shared_ptr< LinearInterp > interpPtr
Definition FieldWrapper.h:227
Vec::interp
LinearInterp * interp
Definition FieldWrapper.h:228
MIPFieldWrapper::setValueRemapOp
void setValueRemapOp(ValueRemapOp::Ptr op)
Definition FieldWrapper.h:221
MIPFieldWrapper::setOsToWs
void setOsToWs(const M44d &i_osToWs)
Definition FieldWrapper.h:176
Vec::fieldPtr
Field3D::MIPField< Field3D::DenseField< T > >::Ptr fieldPtr
Definition FieldWrapper.h:230
Vec::Vec
std::vector< MIPFieldWrapper > Vec
Definition FieldWrapper.h:160
Vec::valueRemapOpPtr
ValueRemapOp::Ptr valueRemapOpPtr
Definition FieldWrapper.h:244
Vec::LinearInterp
Field3D::MIPField< Field3D::DenseField< T > >::LinearInterp LinearInterp
Definition FieldWrapper.h:161
Vec::osToWs
M44d osToWs
Definition FieldWrapper.h:235
Vec::field_type
Field3D::MIPField< Field3D::DenseField< T > > field_type
Definition FieldWrapper.h:159
Vec::doOsToWs
bool doOsToWs
Definition FieldWrapper.h:237
Vec::wsBounds
Imath::Box3f wsBounds
Definition FieldWrapper.h:241
Vec::wsToVs
M44d wsToVs
Definition FieldWrapper.h:240
Vec::field
const Field3D::MIPField< Field3D::DenseField< T > > * field
Definition FieldWrapper.h:229
Vec::doWsBoundsOptimization
bool doWsBoundsOptimization
Definition FieldWrapper.h:242
Vec::wsToOs
M44d wsToOs
Definition FieldWrapper.h:235
Vec::mapping
const Field3D::FieldMapping * mapping
Definition FieldWrapper.h:231
Vec::valueRemapOp
const ValueRemapOp * valueRemapOp
Definition FieldWrapper.h:245