Field3D
FieldInterp.h File Reference

Contains the FieldInterp base class and some standard interpolation classes. More...

#include "Field.h"
#include "DenseField.h"
#include "MACField.h"
#include "ProceduralField.h"
#include "RefCount.h"
#include "ns.h"

Go to the source code of this file.

Classes

class  CubicFieldInterp< Data_T >
 
class  CubicGenericFieldInterp< Field_T >
 
class  CubicMACFieldInterp< Data_T >
 
class  FieldInterp< Data_T >
 Base class for interpolators. More...
 
class  LinearFieldInterp< Data_T >
 
class  LinearGenericFieldInterp< Field_T >
 
class  LinearMACFieldInterp< Data_T >
 
class  ProceduralFieldLookup< Data_T >
 

Functions

 FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION (FieldInterp)
 
 FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION (LinearFieldInterp)
 
 FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION (CubicFieldInterp)
 
 FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION (LinearGenericFieldInterp)
 
 FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION (LinearMACFieldInterp)
 
 FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION (CubicGenericFieldInterp)
 
 FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION (CubicMACFieldInterp)
 
 FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION (ProceduralFieldLookup)
 
bool isLegalVoxelCoord (const V3d &vsP, const Box3d &vsDataWindow)
 Checks whether the floating - point voxel coordinate is within the given (floating point) data window. More...
 
bool isPointInField (const FieldRes::Ptr f, const V3d &wsP)
 Checks whether the point is within the given field. More...
 
template<class Data_T >
Data_T monotonicCubicInterpolant (const Data_T &f1, const Data_T &f2, const Data_T &f3, const Data_T &f4, double t)
 Monotonic cubic interpolation References: http://en.wikipedia.org/wiki/Monotone_cubic_interpolation http://en.wikipedia.org/wiki/Cubic_Hermite_spline. More...
 
template<class T >
monotonicCubicInterpolant (const T &f1, const T &f2, const T &f3, const T &f4, double t)
 
template<>
V3d monotonicCubicInterpolant< V3d > (const V3d &f1, const V3d &f2, const V3d &f3, const V3d &f4, double t)
 
template<>
V3f monotonicCubicInterpolant< V3f > (const V3f &f1, const V3f &f2, const V3f &f3, const V3f &f4, double t)
 
template<>
V3h monotonicCubicInterpolant< V3h > (const V3h &f1, const V3h &f2, const V3h &f3, const V3h &f4, double t)
 
template<class Data_T >
Data_T monotonicCubicInterpolantVec (const Data_T &f1, const Data_T &f2, const Data_T &f3, const Data_T &f4, double t)
 Monotonic cubic interpolation on 3 - vectors References: http://en.wikipedia.org/wiki/Monotone_cubic_interpolation http://en.wikipedia.org/wiki/Cubic_Hermite_spline. More...
 
template<class S , class T >
FIELD3D_VEC3_T< T > operator* (S s, const FIELD3D_VEC3_T< T > vec)
 Scalar times Vec3 multiplication. Makes the interpolation calls cleaner. More...
 
template<class Data_T >
Data_T wsSample (const typename Field< Data_T >::Ptr f, const FieldInterp< Data_T > &interp, const V3d &wsP)
 Helper function for interpolating in world space. More...
 

Detailed Description

Contains the FieldInterp base class and some standard interpolation classes.

Definition in file FieldInterp.h.

Function Documentation

FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION ( FieldInterp  )
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION ( LinearFieldInterp  )
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION ( CubicFieldInterp  )
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION ( LinearGenericFieldInterp  )
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION ( LinearMACFieldInterp  )
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION ( CubicGenericFieldInterp  )
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION ( CubicMACFieldInterp  )
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION ( ProceduralFieldLookup  )
template<class Data_T >
Data_T wsSample ( const typename Field< Data_T >::Ptr  f,
const FieldInterp< Data_T > &  interp,
const V3d wsP 
)

Helper function for interpolating in world space.

Definition at line 546 of file FieldInterp.h.

References isLegalVoxelCoord(), isPointInField(), FieldRes::mapping(), monotonicCubicInterpolant(), monotonicCubicInterpolantVec(), operator*(), and FieldInterp< Data_T >::sample().

549 {
550  V3d vsP;
551  f->mapping()->worldToVoxel(wsP, vsP);
552  return interp.sample(*f, vsP);
553 }
virtual Data_T sample(const Field< Data_T > &data, const V3d &vsP) const =0
Imath::V3d V3d
Definition: SpiMathLib.h:74
bool isPointInField ( const FieldRes::Ptr  f,
const V3d wsP 
)

Checks whether the point is within the given field.

Definition at line 52 of file FieldInterp.cpp.

Referenced by wsSample().

53 {
54  V3d lsP;
55  f->mapping()->worldToLocal(wsP, lsP);
56  return (lsP.x > 0.0 && lsP.x <= 1.0 &&
57  lsP.y > 0.0 && lsP.y <= 1.0 &&
58  lsP.z > 0.0 && lsP.z <= 1.0);
59 }
Imath::V3d V3d
Definition: SpiMathLib.h:74
bool isLegalVoxelCoord ( const V3d vsP,
const Box3d vsDataWindow 
)

Checks whether the floating - point voxel coordinate is within the given (floating point) data window.

Definition at line 63 of file FieldInterp.cpp.

References FIELD3D_NAMESPACE_SOURCE_CLOSE.

Referenced by wsSample().

64 {
65  return vsP.x > (vsDataWindow.min.x) &&
66  vsP.x < (vsDataWindow.max.x) &&
67  vsP.y > (vsDataWindow.min.y) &&
68  vsP.y < (vsDataWindow.max.y) &&
69  vsP.z > (vsDataWindow.min.z) &&
70  vsP.z < (vsDataWindow.max.z);
71 }
template<class S , class T >
FIELD3D_VEC3_T< T > operator* ( s,
const FIELD3D_VEC3_T< T >  vec 
)

Scalar times Vec3 multiplication. Makes the interpolation calls cleaner.

Definition at line 1558 of file FieldInterp.h.

Referenced by wsSample().

1559 {
1560  return FIELD3D_VEC3_T<T>(vec.x * s, vec.y * s, vec.z * s);
1561 }
template<class Data_T >
Data_T monotonicCubicInterpolant ( const Data_T &  f1,
const Data_T &  f2,
const Data_T &  f3,
const Data_T &  f4,
double  t 
)
template<class Data_T >
Data_T monotonicCubicInterpolantVec ( const Data_T &  f1,
const Data_T &  f2,
const Data_T &  f3,
const Data_T &  f4,
double  t 
)

Monotonic cubic interpolation on 3 - vectors References: http://en.wikipedia.org/wiki/Monotone_cubic_interpolation http://en.wikipedia.org/wiki/Cubic_Hermite_spline.

Monotonic cubic interpolation on 3-vectors.

Definition at line 1597 of file FieldInterp.h.

Referenced by monotonicCubicInterpolant< V3d >(), monotonicCubicInterpolant< V3f >(), monotonicCubicInterpolant< V3h >(), and wsSample().

1600 {
1601  typedef typename Data_T::BaseType T;
1602 
1603  Data_T d_k = T(.5) * (f3 - f1);
1604  Data_T d_k1 = T(.5) * (f4 - f2);
1605  Data_T delta_k = f3 - f2;
1606 
1607  for (int i = 0; i < 3; i++) {
1608  if (delta_k[i] == static_cast<T>(0)) {
1609  d_k[i] = static_cast<T>(0);
1610  d_k1[i]= static_cast<T>(0);
1611  }
1612  }
1613 
1614  Data_T a0 = f2;
1615  Data_T a1 = d_k;
1616  Data_T a2 = (delta_k * T(3)) - (d_k * T(2)) - d_k1;
1617  Data_T a3 = d_k + d_k1 - (delta_k * T(2));
1618 
1619  T t1 = t;
1620  T t2 = t1 * t1;
1621  T t3 = t2 * t1;
1622 
1623  return a3 * t3 + a2 * t2 + a1 * t1 + a0;
1624 }
template<class T >
T monotonicCubicInterpolant ( const T &  f1,
const T &  f2,
const T &  f3,
const T &  f4,
double  t 
)

Definition at line 1566 of file FieldInterp.h.

1568 {
1569  T d_k = T(.5) * (f3 - f1);
1570  T d_k1 = T(.5) * (f4 - f2);
1571  T delta_k = f3 - f2;
1572 
1573  if (delta_k == static_cast<T>(0)) {
1574  d_k = static_cast<T>(0);
1575  d_k1 = static_cast<T>(0);
1576  }
1577 
1578  T a0 = f2;
1579  T a1 = d_k;
1580  T a2 = (T(3) * delta_k) - (T(2) * d_k) - d_k1;
1581  T a3 = d_k + d_k1 - (T(2) * delta_k);
1582 
1583  T t1 = t;
1584  T t2 = t1 * t1;
1585  T t3 = t2 * t1;
1586 
1587  return a3 * t3 + a2 * t2 + a1 * t1 + a0;
1588 }
template<>
V3h monotonicCubicInterpolant< V3h > ( const V3h f1,
const V3h f2,
const V3h f3,
const V3h f4,
double  t 
)
inline

Definition at line 1632 of file FieldInterp.h.

References monotonicCubicInterpolantVec().

1634 {
1635  return monotonicCubicInterpolantVec(f1, f2, f3, f4, t);
1636 }
Data_T monotonicCubicInterpolantVec(const Data_T &f1, const Data_T &f2, const Data_T &f3, const Data_T &f4, double t)
Monotonic cubic interpolation on 3 - vectors References: http://en.wikipedia.org/wiki/Monotone_cubic_...
Definition: FieldInterp.h:1597
template<>
V3f monotonicCubicInterpolant< V3f > ( const V3f f1,
const V3f f2,
const V3f f3,
const V3f f4,
double  t 
)
inline

Definition at line 1642 of file FieldInterp.h.

References monotonicCubicInterpolantVec().

1644 {
1645  return monotonicCubicInterpolantVec(f1, f2, f3, f4, t);
1646 }
Data_T monotonicCubicInterpolantVec(const Data_T &f1, const Data_T &f2, const Data_T &f3, const Data_T &f4, double t)
Monotonic cubic interpolation on 3 - vectors References: http://en.wikipedia.org/wiki/Monotone_cubic_...
Definition: FieldInterp.h:1597
template<>
V3d monotonicCubicInterpolant< V3d > ( const V3d f1,
const V3d f2,
const V3d f3,
const V3d f4,
double  t 
)
inline

Definition at line 1652 of file FieldInterp.h.

References FIELD3D_NAMESPACE_HEADER_CLOSE, and monotonicCubicInterpolantVec().

1654 {
1655  return monotonicCubicInterpolantVec(f1, f2, f3, f4, t);
1656 }
Data_T monotonicCubicInterpolantVec(const Data_T &f1, const Data_T &f2, const Data_T &f3, const Data_T &f4, double t)
Monotonic cubic interpolation on 3 - vectors References: http://en.wikipedia.org/wiki/Monotone_cubic_...
Definition: FieldInterp.h:1597