FrustumFieldMapping Class Reference
Fields

Represents the mapping of a field by a perspective transform. More...

`#include <FieldMapping.h>`

Inheritance diagram for FrustumFieldMapping:

## Public Types

typedef FrustumFieldMapping | class_type
typedef Curve< double > | FloatCurve
| Time-varying float.
typedef Curve< Imath::M44d > | MatrixCurve
| Time-varying matrix.
typedef boost::intrusive_ptr< FrustumFieldMapping > | Ptr
| Convenience typedef.
enum | ZDistribution { PerspectiveDistribution , UniformDistribution }
| Enumerates the Z slice distribution. .f3d files will store values as an int, so be very careful not to change the order of these. More...
Public Types inherited from FieldMapping
typedef FieldMapping | class_type
typedef boost::intrusive_ptr< FieldMapping > | Ptr
Public Types inherited from RefBase
typedef boost::intrusive_ptr< RefBase > | Ptr
typedef boost::weak_ptr< RefBase > | WeakPtr

## Public Member Functions

const M44d | cameraToWorld () const
| Returns a reference to the camera to world space transform.
const MatrixCurve::SampleVec & | cameraToWorldSamples () const
| Returns a vector of all motion samples for camera to world transform.
double | farPlane () const
| Returns the far plane.
const FloatCurve::SampleVec & | farPlaneSamples () const
| Returns a vector of all motion samples for far plane.
double | nearPlane () const
| Returns the near plane.
const FloatCurve::SampleVec & | nearPlaneSamples () const
| Returns a vector of all motion samples for near plane.
void | reset ()
| Resets the transform. Makes a perspective transform at the origin, looking down the negative Z axis with a 45 degree FOV and square projection.
const M44d | screenToWorld () const
| Returns a reference to the screen to world space transform.
const MatrixCurve::SampleVec & | screenToWorldSamples () const
| Returns a vector of all motion samples for screen to world transform.
void | setTransforms (const M44d &ssToWs, const M44d &csToWs)
| Sets the screenToWorld and cameraToWorld transforms. All other internal matrices will be updated based on these.
void | setTransforms (float t, const M44d &ssToWs, const M44d &csToWs)
| Sets time-varying screenToWorld and cameraToWorld transforms. All other internal matrices will be updated based on these.
void | setZDistribution (ZDistribution dist)
| Sets the z slice distribution.
ZDistribution | zDistribution () const
| Returns the z slice distribution.
Constructors & destructor
| FrustumFieldMapping ()
| FrustumFieldMapping (const Box3i &extents)
From FieldMapping
virtual void | worldToVoxel (const V3d &wsP, V3d &vsP) const
| Transform from world space position into voxel space.
virtual void | worldToVoxel (const V3d &wsP, V3d &vsP, float time) const
virtual void | voxelToWorld (const V3d &vsP, V3d &wsP) const
| Transform from voxel space position into world space.
virtual void | voxelToWorld (const V3d &vsP, V3d &wsP, float time) const
virtual void | worldToLocal (const V3d &wsP, V3d &lsP) const
| Transform from world space position into local space.
virtual void | worldToLocal (const V3d &wsP, V3d &lsP, float time) const
virtual void | localToWorld (const V3d &lsP, V3d &wsP) const
| Transform from local space position into world space.
virtual void | localToWorld (const V3d &lsP, V3d &wsP, float time) const
virtual void | extentsChanged ()
| Implement this if the subclass needs to update itself when the resolution changes.
virtual std::string | className () const
| Returns the FieldMapping type name. Used when writing/reading from disk.
virtual bool | isIdentical (FieldMapping::Ptr other, double tolerance=0.0) const
| Whether the mapping is identical to another mapping.
virtual V3d | wsVoxelSize (int i, int j, int k) const
| Returns world-space size of a voxel at the specified coordinate.
virtual FieldMapping::Ptr | clone () const
| Returns a pointer to a copy of the mapping, pure virtual so ensure derived classes properly implement it.
Public Member Functions inherited from FieldMapping
const V3d & | origin () const
| Returns the origin.
const V3d & | resolution () const
| Returns the resolution.
void | setExtents (const Box3i &extents)
| This sets the field extents information to use for defining the local coordinate space.
| FieldMapping ()
| Constructor.
| FieldMapping (const Box3i &extents)
| Construct with known extents.
virtual | ~FieldMapping ()
| Destructor.
void | localToVoxel (const V3d &lsP, V3d &vsP) const
| Transform from local space to voxel space. This is just a multiplication by the resolution of the Field that we're mapping.
void | voxelToLocal (const V3d &vsP, V3d &lsP) const
| Inverse of localToVoxel.
Public Member Functions inherited from RefBase
void | ref () const
| Used by boost::intrusive_pointer.
size_t | refcnt ()
| Used by boost::intrusive_pointer.
void | unref () const
| Used by boost::intrusive_pointer.
WeakPtr | weakPtr () const
| RefBase ()
| RefBase (const RefBase &)
| Copy constructor.
RefBase & | operator= (const RefBase &)
| Assignment operator.
virtual | ~RefBase ()
| Destructor.
virtual bool | checkRTTI (const char *typenameStr)=0
| This function is only implemented by concrete classes and triggers the actual RTTI check through matchRTTI();.
bool | matchRTTI (const char *typenameStr)
| Performs a check to see if the given typename string matches this class' This needs to be implemented in -all- subclasses, even abstract ones.

## Static Public Member Functions

static const char * | staticClassType ()
Static Public Member Functions inherited from FieldMapping
static const char * | staticClassType ()
static const char * | staticClassType ()

## Public Attributes

| DEFINE_FIELD_RTTI_CONCRETE_CLASS
Public Attributes inherited from FieldMapping
| DEFINE_FIELD_RTTI_ABSTRACT_CLASS

## Private Types

typedef FieldMapping | base
| Convenience typedef for referring to base class.

## Private Member Functions

void | clearCurves ()
| Clears all Curve data members. Used by setTransforms() to prepare for the first sample to be added.
void | computeVoxelSize ()
| Updates the local to world transformation matrix.
void | getLocalToVoxelMatrix (M44d &result)

## Private Attributes

MatrixCurve | m_csToWsCurve
| Time-varying camera to world space transform.
bool | m_defaultState
| Boolean to tell us if the mapping is in its 'default' state. This is needed because the class has a default configuration where there is a single sample in all the curves. Once a new transform is set through setTransforms(), the default samples must be cleared.
FloatCurve | m_farCurve
| Time-varying far plane. Computed from m_lpsToWsCurve.
MatrixCurve | m_lpsToWsCurve
| Time-varying local perspective to world space transform. Computed from m_ssToWsCurve.
FloatCurve | m_nearCurve
| Time-varying near plane. Computed from m_lpsToWsCurve.
MatrixCurve | m_ssToWsCurve
| Time-varying local perspective to world space transform This is not used in calculations, but rather as the public interface to the class.
std::vector< V3d > | m_wsVoxelSize
| Precomputed world-space voxel size. Calculations may assume orthogonal transformation for efficiency.
ZDistribution | m_zDistribution
| Slice distribution type.

## Additional Inherited Members

Protected Attributes inherited from FieldMapping
V3d | m_origin
| The integer voxel-space origin of the underlying Field object. Is equal to field.extents.min.
V3d | m_res
| The integer voxel-space resolution of the underlying Field object. Is equal to field.extents.max - field.extents.min + 1.

## Detailed Description

Represents the mapping of a field by a perspective transform.

Refer to using_mappings for examples of how to use this in your code.

Frustum mappings can use two approaches in determining the distribution of "Z slices". By transforming from world space into screen space and using the Z component in perspective space, the slices in Z will be distributed in world space accordingly. It is also possible to use a uniform distribution of Z slices by specifying a near and far clip plane and normalizing the camera-space Z distance between those.

Note
  Screen space is defined left-handed as [-1.0,1.0] in all three dimensions
  Camera space is defined right-handed with the camera looking down negative Z.

Todo
  Define local perspective space

Note
  Regarding time-varying matrices. If setTransforms() is called, an underlying Curve object is created with just one sample at time=0.0.

Definition at line 564 of file FieldMapping.h.

## Member Typedef Documentation

## Ptr

typedef boost::intrusive_ptr<FrustumFieldMapping> FrustumFieldMapping::Ptr

Convenience typedef.

Definition at line 571 of file FieldMapping.h.

## MatrixCurve

typedef Curve<Imath::M44d> FrustumFieldMapping::MatrixCurve

Time-varying matrix.

Definition at line 573 of file FieldMapping.h.

## FloatCurve

typedef Curve<double> FrustumFieldMapping::FloatCurve

Time-varying float.

Definition at line 575 of file FieldMapping.h.

## class_type

typedef FrustumFieldMapping FrustumFieldMapping::class_type

Definition at line 592 of file FieldMapping.h.

## base

typedef FieldMapping FrustumFieldMapping::base

private

Convenience typedef for referring to base class.

Definition at line 745 of file FieldMapping.h.

## Member Enumeration Documentation

## ZDistribution

enum FrustumFieldMapping::ZDistribution

Enumerates the Z slice distribution. .f3d files will store values as an int, so be very careful not to change the order of these.

Enumerator
PerspectiveDistribution |
UniformDistribution |

Definition at line 585 of file FieldMapping.h.

{
PerspectiveDistribution,
UniformDistribution
};
FrustumFieldMapping::PerspectiveDistribution
@ PerspectiveDistribution
Definition FieldMapping.h:586
FrustumFieldMapping::UniformDistribution
@ UniformDistribution
Definition FieldMapping.h:587

## Constructor & Destructor Documentation

## FrustumFieldMapping() [1/2]

FrustumFieldMapping::FrustumFieldMapping | ( |  | ) |

Definition at line 423 of file FieldMapping.cpp.

: FieldMapping(),
m_zDistribution(PerspectiveDistribution),
m_defaultState(true)
{
reset();
}
FieldMapping::FieldMapping
FieldMapping()
Constructor.
Definition FieldMapping.cpp:113
FrustumFieldMapping::m_defaultState
bool m_defaultState
Boolean to tell us if the mapping is in its 'default' state. This is needed because the class has a d...
Definition FieldMapping.h:740
FrustumFieldMapping::reset
void reset()
Resets the transform. Makes a perspective transform at the origin, looking down the negative Z axis w...
Definition FieldMapping.cpp:501
FrustumFieldMapping::m_zDistribution
ZDistribution m_zDistribution
Slice distribution type.
Definition FieldMapping.h:716

References FieldMapping::FieldMapping(), m_defaultState, m_zDistribution, PerspectiveDistribution, and reset().

Referenced by clone().

## FrustumFieldMapping() [2/2]

FrustumFieldMapping::FrustumFieldMapping | ( | const Box3i & | extents | ) |

Definition at line 433 of file FieldMapping.cpp.

: FieldMapping(extents)
{
reset();
}

References FieldMapping::FieldMapping(), and reset().

## Member Function Documentation

## staticClassType()

const char * FrustumFieldMapping::staticClassType | ( |  | ) |

inline static

Definition at line 595 of file FieldMapping.h.

{
return "FrustumFieldMapping";
}

Referenced by className().

## setTransforms() [1/2]

void FrustumFieldMapping::setTransforms | ( | const M44d & | ssToWs,
|  | const M44d & | csToWs )

Sets the screenToWorld and cameraToWorld transforms. All other internal matrices will be updated based on these.

Note
  This resets the transform Curve instances to contain just one sample at time=0.0

Parameters

  ssToWs | See class documentation for definition.
  csToWs | See class documentation for definition.

Definition at line 441 of file FieldMapping.cpp.

{
setTransforms(0.0, ssToWs, csToWs);
}
FrustumFieldMapping::setTransforms
void setTransforms(const M44d &ssToWs, const M44d &csToWs)
Sets the screenToWorld and cameraToWorld transforms. All other internal matrices will be updated base...
Definition FieldMapping.cpp:441

References setTransforms().

Referenced by reset(), and setTransforms().

## setTransforms() [2/2]

void FrustumFieldMapping::setTransforms | ( | float | t,
|  | const M44d & | ssToWs,
|  | const M44d & | csToWs )

Sets time-varying screenToWorld and cameraToWorld transforms. All other internal matrices will be updated based on these.

Parameters

  ssToWs | See class documentation for definition.
  csToWs | See class documentation for definition.

Definition at line 448 of file FieldMapping.cpp.

{
if (m_defaultState) {
clearCurves();
m_defaultState = false;
}
// Construct local-to-world transform from ssToWs
M44d lsToSs, scale, translation;
scale.setScale(V3d(2.0, 2.0, 1.0));
translation.setTranslation(V3d(-1.0, -1.0, 0.0));
lsToSs = scale * translation;
M44d lpsToWs = lsToSs * ssToWs;
// Add samples to Curves
m_ssToWsCurve.addSample(t, ssToWs);
m_lpsToWsCurve.addSample(t, lpsToWs);
m_csToWsCurve.addSample(t, csToWs);
// Compute near and far planes ---
// Because the frustum may be skewed we can't just measure distance from
// the apex of the frustum to the world-space center point of the frustum.
// Instead, we transform into camera space and measure z depth there.
V3d lsNearP(0.5, 0.5, 0.0), lsFarP(0.5, 0.5, 1.0);
V3d wsNearP, wsFarP, csNearP, csFarP;
lpsToWs.multVecMatrix(lsNearP, wsNearP);
lpsToWs.multVecMatrix(lsFarP, wsFarP);
M44d wsToCs = csToWs.inverse();
wsToCs.multVecMatrix(wsNearP, csNearP);
wsToCs.multVecMatrix(wsFarP, csFarP);
double near = -csNearP.z;
double far = -csFarP.z;
// Catch NaN here
if (std::isnan(near) || std::isnan(far)) {
throw BadPerspectiveMatrix("FrustumFieldMapping::setTransforms "
"received bad screen-to-world matrix");
}
m_nearCurve.addSample(t, near);
m_farCurve.addSample(t, far);
computeVoxelSize();
}
V3d
Imath::V3d V3d
Definition SpiMathLib.h:74
M44d
Imath::M44d M44d
Definition SpiMathLib.h:82
FrustumFieldMapping::m_lpsToWsCurve
MatrixCurve m_lpsToWsCurve
Time-varying local perspective to world space transform. Computed from m_ssToWsCurve.
Definition FieldMapping.h:726
FrustumFieldMapping::clearCurves
void clearCurves()
Clears all Curve data members. Used by setTransforms() to prepare for the first sample to be added.
Definition FieldMapping.cpp:787
FrustumFieldMapping::m_ssToWsCurve
MatrixCurve m_ssToWsCurve
Time-varying local perspective to world space transform This is not used in calculations,...
Definition FieldMapping.h:721
FrustumFieldMapping::m_farCurve
FloatCurve m_farCurve
Time-varying far plane. Computed from m_lpsToWsCurve.
Definition FieldMapping.h:730
FrustumFieldMapping::computeVoxelSize
void computeVoxelSize()
Updates the local to world transformation matrix.
Definition FieldMapping.cpp:737
FrustumFieldMapping::m_nearCurve
FloatCurve m_nearCurve
Time-varying near plane. Computed from m_lpsToWsCurve.
Definition FieldMapping.h:728
FrustumFieldMapping::m_csToWsCurve
MatrixCurve m_csToWsCurve
Time-varying camera to world space transform.
Definition FieldMapping.h:723

References clearCurves(), computeVoxelSize(), m_csToWsCurve, m_defaultState, m_farCurve, m_lpsToWsCurve, m_nearCurve, and m_ssToWsCurve.

## setZDistribution()

void FrustumFieldMapping::setZDistribution | ( | ZDistribution | dist | ) |

inline

Sets the z slice distribution.

Definition at line 626 of file FieldMapping.h.

{ m_zDistribution = dist; }

References m_zDistribution.

## zDistribution()

ZDistribution FrustumFieldMapping::zDistribution | ( |  | ) | const

inline

Returns the z slice distribution.

Definition at line 629 of file FieldMapping.h.

{ return m_zDistribution; }

References m_zDistribution.

## screenToWorld()

const M44d FrustumFieldMapping::screenToWorld | ( |  | ) | const

inline

Returns a reference to the screen to world space transform.

Note
  This assumes the query to be at time=0.0

Definition at line 634 of file FieldMapping.h.

{ return m_ssToWsCurve.linear(0.0); }

References m_ssToWsCurve.

## cameraToWorld()

const M44d FrustumFieldMapping::cameraToWorld | ( |  | ) | const

inline

Returns a reference to the camera to world space transform.

Note
  This assumes the query to be at time=0.0

Definition at line 639 of file FieldMapping.h.

{ return m_csToWsCurve.linear(0.0); }

References m_csToWsCurve.

## screenToWorldSamples()

const MatrixCurve::SampleVec & FrustumFieldMapping::screenToWorldSamples | ( |  | ) | const

inline

Returns a vector of all motion samples for screen to world transform.

Definition at line 643 of file FieldMapping.h.

{ return m_ssToWsCurve.samples(); }

References m_ssToWsCurve.

## cameraToWorldSamples()

const MatrixCurve::SampleVec & FrustumFieldMapping::cameraToWorldSamples | ( |  | ) | const

inline

Returns a vector of all motion samples for camera to world transform.

Definition at line 647 of file FieldMapping.h.

{ return m_csToWsCurve.samples(); }

References m_csToWsCurve.

## nearPlaneSamples()

const FloatCurve::SampleVec & FrustumFieldMapping::nearPlaneSamples | ( |  | ) | const

inline

Returns a vector of all motion samples for near plane.

Definition at line 651 of file FieldMapping.h.

{ return m_nearCurve.samples(); }

References m_nearCurve.

## farPlaneSamples()

const FloatCurve::SampleVec & FrustumFieldMapping::farPlaneSamples | ( |  | ) | const

inline

Returns a vector of all motion samples for far plane.

Definition at line 655 of file FieldMapping.h.

{ return m_farCurve.samples(); }

References m_farCurve.

## nearPlane()

double FrustumFieldMapping::nearPlane | ( |  | ) | const

inline

Returns the near plane.

Definition at line 659 of file FieldMapping.h.

{ return m_nearCurve.linear(0.0); }

References m_nearCurve.

## farPlane()

double FrustumFieldMapping::farPlane | ( |  | ) | const

inline

Returns the far plane.

Definition at line 663 of file FieldMapping.h.

{ return m_farCurve.linear(0.0); }

References m_farCurve.

## reset()

void FrustumFieldMapping::reset | ( |  | ) |

Resets the transform. Makes a perspective transform at the origin, looking down the negative Z axis with a 45 degree FOV and square projection.

Definition at line 501 of file FieldMapping.cpp.

{
// Default camera to world ---
M44d csToWs;
csToWs.makeIdentity();
// Default screen to world ---
double near = 1;
double far = 2;
double fovRadians = 45.0 * M_PI / 180.0;
double invTan = 1.0 / std::tan(fovRadians / 2.0);
double imageAspectRatio = 1.0;
M44d perspective(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, (far) / (far - near), 1,
0, 0, (- far * near) / (far - near), 0);
M44d fov;
fov.setScale(V3d(invTan / imageAspectRatio, invTan, 1.0));
M44d flipZ;
flipZ.setScale(V3d(1.0, 1.0, -1.0));
M44d csToSs = flipZ * perspective * fov;
M44d standardSsToWs = csToSs.inverse() * csToWs;
// Set default state ---
clearCurves();
setTransforms(standardSsToWs, csToWs);
m_defaultState = true;
computeVoxelSize();
}

References clearCurves(), computeVoxelSize(), m_defaultState, and setTransforms().

Referenced by FrustumFieldMapping(), and FrustumFieldMapping().

## worldToVoxel() [1/2]

void FrustumFieldMapping::worldToVoxel | ( | const V3d & | wsP,
|  | V3d & | vsP ) const

virtual

Transform from world space position into voxel space.

Implements FieldMapping.

Definition at line 550 of file FieldMapping.cpp.

{
worldToVoxel(wsP, vsP, 0.0);
}
FrustumFieldMapping::worldToVoxel
virtual void worldToVoxel(const V3d &wsP, V3d &vsP) const
Transform from world space position into voxel space.
Definition FieldMapping.cpp:550

References worldToVoxel().

Referenced by worldToVoxel().

## worldToVoxel() [2/2]

void FrustumFieldMapping::worldToVoxel | ( | const V3d & | wsP,
|  | V3d & | vsP,
|  | float | time ) const

virtual

Implements FieldMapping.

Definition at line 557 of file FieldMapping.cpp.

{
V3d lsP;
worldToLocal(wsP, lsP, time);
localToVoxel(lsP, vsP);
}
FieldMapping::localToVoxel
void localToVoxel(const V3d &lsP, V3d &vsP) const
Transform from local space to voxel space. This is just a multiplication by the resolution of the Fie...
Definition FieldMapping.cpp:155
FrustumFieldMapping::worldToLocal
virtual void worldToLocal(const V3d &wsP, V3d &lsP) const
Transform from world space position into local space.
Definition FieldMapping.cpp:582

References FieldMapping::localToVoxel(), and worldToLocal().

## voxelToWorld() [1/2]

void FrustumFieldMapping::voxelToWorld | ( | const V3d & | vsP,
|  | V3d & | wsP ) const

virtual

Transform from voxel space position into world space.

Implements FieldMapping.

Definition at line 566 of file FieldMapping.cpp.

{
voxelToWorld(vsP, wsP, 0.0);
}
FrustumFieldMapping::voxelToWorld
virtual void voxelToWorld(const V3d &vsP, V3d &wsP) const
Transform from voxel space position into world space.
Definition FieldMapping.cpp:566

References voxelToWorld().

Referenced by computeVoxelSize(), and voxelToWorld().

## voxelToWorld() [2/2]

void FrustumFieldMapping::voxelToWorld | ( | const V3d & | vsP,
|  | V3d & | wsP,
|  | float | time ) const

virtual

Implements FieldMapping.

Definition at line 573 of file FieldMapping.cpp.

{
V3d lsP;
voxelToLocal(vsP, lsP);
localToWorld(lsP, wsP, time);
}
FieldMapping::voxelToLocal
void voxelToLocal(const V3d &vsP, V3d &lsP) const
Inverse of localToVoxel.
Definition FieldMapping.cpp:162
FrustumFieldMapping::localToWorld
virtual void localToWorld(const V3d &lsP, V3d &wsP) const
Transform from local space position into world space.
Definition FieldMapping.cpp:618

References localToWorld(), and FieldMapping::voxelToLocal().

## worldToLocal() [1/2]

void FrustumFieldMapping::worldToLocal | ( | const V3d & | wsP,
|  | V3d & | lsP ) const

virtual

Transform from world space position into local space.

Implements FieldMapping.

Definition at line 582 of file FieldMapping.cpp.

{
worldToLocal(wsP, lsP, 0.0);
}

References worldToLocal().

Referenced by worldToLocal(), and worldToVoxel().

## worldToLocal() [2/2]

void FrustumFieldMapping::worldToLocal | ( | const V3d & | wsP,
|  | V3d & | lsP,
|  | float | time ) const

virtual

Implements FieldMapping.

Definition at line 589 of file FieldMapping.cpp.

{
switch (m_zDistribution) {
case UniformDistribution:
{
// First transform to local perspective space
V3d lpsP;
m_lpsToWsCurve.linear(time).inverse().multVecMatrix(wsP, lpsP);
// Also transform to camera space
V3d csP;
m_csToWsCurve.linear(time).inverse().multVecMatrix(wsP, csP);
// Interpolate near and far plane at current time
double near = m_nearCurve.linear(time);
double far = m_farCurve.linear(time);
// Use perspective-space X/Y and normalized depth for Z.
lsP = V3d(lpsP.x, lpsP.y, FIELD3D_LERPFACTOR(-csP.z, near, far));
break;
}
case PerspectiveDistribution:
default:
{
m_lpsToWsCurve.linear(time).inverse().multVecMatrix(wsP, lsP);
break;
}
}
}
FIELD3D_LERPFACTOR
#define FIELD3D_LERPFACTOR
Definition SpiMathLib.h:92

References FIELD3D_LERPFACTOR, m_csToWsCurve, m_farCurve, m_lpsToWsCurve, m_nearCurve, m_zDistribution, PerspectiveDistribution, and UniformDistribution.

## localToWorld() [1/2]

void FrustumFieldMapping::localToWorld | ( | const V3d & | lsP,
|  | V3d & | wsP ) const

virtual

Transform from local space position into world space.

Implements FieldMapping.

Definition at line 618 of file FieldMapping.cpp.

{
localToWorld(lsP, wsP, 0.0);
}

References localToWorld().

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::GetIntersections::intersectFrustumMapping(), localToWorld(), and voxelToWorld().

## localToWorld() [2/2]

void FrustumFieldMapping::localToWorld | ( | const V3d & | lsP,
|  | V3d & | wsP,
|  | float | time ) const

virtual

Implements FieldMapping.

Definition at line 625 of file FieldMapping.cpp.

{
switch (m_zDistribution) {
case UniformDistribution:
{
// Interpolate near and far plane at current time
double near = m_nearCurve.linear(time);
double far = m_farCurve.linear(time);
// In this case, local space is -not- equal to local perspective space
// Determine distance from camera
double wsDepthFromCam = FIELD3D_LERP(near, far, lsP.z);
// Transform point right in front of camera, X units away into world space
V3d lpsCenterP, wsCenterP, csCenterP(0.0, 0.0, -wsDepthFromCam);
m_csToWsCurve.linear(time).multVecMatrix(csCenterP, wsCenterP);
// Transform center point into screen space so we know what depth
// (in screen space) the voxel would live at -if- it were in local
// perspective space.
m_lpsToWsCurve.linear(time).inverse().multVecMatrix(wsCenterP, lpsCenterP);
// Now we create a local perspective coordinate that can be transformed
// using m_lpsToWsCurve
V3d lpsP(lsP.x, lsP.y, lpsCenterP.z);
// Now we can use m_lpsToWsCurve to transform the actual voxel location
m_lpsToWsCurve.linear(time).multVecMatrix(lpsP, wsP);
break;
}
case PerspectiveDistribution:
default:
{
// In this case, local space and local perspective space are the same.
m_lpsToWsCurve.linear(time).multVecMatrix(lsP, wsP);
break;
}
}
}
FIELD3D_LERP
#define FIELD3D_LERP
Definition SpiMathLib.h:91

References FIELD3D_LERP, m_csToWsCurve, m_farCurve, m_lpsToWsCurve, m_nearCurve, m_zDistribution, PerspectiveDistribution, and UniformDistribution.

## extentsChanged()

void FrustumFieldMapping::extentsChanged | ( |  | ) |

virtual

Implement this if the subclass needs to update itself when the resolution changes.

Reimplemented from FieldMapping.

Definition at line 543 of file FieldMapping.cpp.

{
computeVoxelSize();
}

References computeVoxelSize().

## className()

std::string FrustumFieldMapping::className | ( |  | ) | const

virtual

Returns the FieldMapping type name. Used when writing/reading from disk.

Implements FieldMapping.

Definition at line 662 of file FieldMapping.cpp.

{
return std::string(staticClassType());
}
FrustumFieldMapping::staticClassType
static const char * staticClassType()
Definition FieldMapping.h:595

References staticClassType().

## isIdentical()

bool FrustumFieldMapping::isIdentical | ( | FieldMapping::Ptr | other,
|  | double | tolerance = 0.0 ) const

virtual

Whether the mapping is identical to another mapping.

Implements FieldMapping.

Definition at line 669 of file FieldMapping.cpp.

{
typedef MatrixFieldMapping::MatrixCurve::SampleVec SampleVec;
if (other->className() != k_frustumMappingName) {
return false;
} else {
FrustumFieldMapping::Ptr fm =
FIELD_DYNAMIC_CAST<FrustumFieldMapping>(other);
if (fm) {
const SampleVec lpsToWs1 = m_lpsToWsCurve.samples();
const SampleVec lpsToWs2 = fm->m_lpsToWsCurve.samples();
const SampleVec csToWs1 = m_csToWsCurve.samples();
const SampleVec csToWs2 = fm->m_csToWsCurve.samples();
size_t numSamples = lpsToWs1.size();
// Check that slice distributions match
if (m_zDistribution != fm->m_zDistribution) {
return false;
}
// First check if time sample counts differ
// lpsToWs and csToWs are guaranteed to have same sample count.
if (lpsToWs1.size() != lpsToWs2.size()) {
return false;
}
// Then check if all time samples match, then check localToWorld
// and voxelToWorld matrices
for (size_t i = 0; i < numSamples; ++i) {
if (lpsToWs1[i].first != lpsToWs2[i].first) {
return false;
}
if (!checkMatricesIdentical(lpsToWs1[i].second, lpsToWs2[i].second,
tolerance)) {
return false;
}
if (!checkMatricesIdentical(csToWs1[i].second, csToWs2[i].second,
tolerance)) {
return false;
}
}
return true;
} else {
return false;
}
}
return false;
}
FIELD_DYNAMIC_CAST
#define FIELD_DYNAMIC_CAST
Definition RefCount.h:271
Curve< Imath::M44d >::SampleVec
std::vector< Sample > SampleVec
Definition Curve.h:102
FrustumFieldMapping::Ptr
boost::intrusive_ptr< FrustumFieldMapping > Ptr
Convenience typedef.
Definition FieldMapping.h:571
FIELD3D_NAMESPACE_OPEN::checkMatricesIdentical
bool checkMatricesIdentical(const Matrix_T &m1, const Matrix_T &m2, double tolerance)
Definition FieldMapping.cpp:86

References FIELD_DYNAMIC_CAST, m_csToWsCurve, m_lpsToWsCurve, and m_zDistribution.

## wsVoxelSize()

V3d FrustumFieldMapping::wsVoxelSize | ( | int | i,
|  | int | j,
|  | int | k ) const

virtual

Returns world-space size of a voxel at the specified coordinate.

Implements FieldMapping.

Definition at line 728 of file FieldMapping.cpp.

{
k = std::min(std::max(k, static_cast<int>(m_origin.z)),
static_cast<int>(m_origin.z + m_res.z - 1));
return m_wsVoxelSize[k - static_cast<int>(m_origin.z)];
}
FieldMapping::m_origin
V3d m_origin
The integer voxel-space origin of the underlying Field object. Is equal to field.extents....
Definition FieldMapping.h:190
FieldMapping::m_res
V3d m_res
The integer voxel-space resolution of the underlying Field object. Is equal to field....
Definition FieldMapping.h:193
FrustumFieldMapping::m_wsVoxelSize
std::vector< V3d > m_wsVoxelSize
Precomputed world-space voxel size. Calculations may assume orthogonal transformation for efficiency.
Definition FieldMapping.h:734

References FieldMapping::m_origin, FieldMapping::m_res, and m_wsVoxelSize.

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::GetIntersections::intersectFrustumMapping().

## clone()

FieldMapping::Ptr FrustumFieldMapping::clone | ( |  | ) | const

virtual

Returns a pointer to a copy of the mapping, pure virtual so ensure derived classes properly implement it.

Implements FieldMapping.

Definition at line 797 of file FieldMapping.cpp.

{
return Ptr(new FrustumFieldMapping(*this));
}
FrustumFieldMapping::FrustumFieldMapping
FrustumFieldMapping()
Definition FieldMapping.cpp:423

References FrustumFieldMapping().

## computeVoxelSize()

void FrustumFieldMapping::computeVoxelSize | ( |  | ) |

private

Updates the local to world transformation matrix.

Definition at line 737 of file FieldMapping.cpp.

{
// Precompute the voxel size ---
m_wsVoxelSize.resize(static_cast<int>(m_res.z),V3d(0.0));
int i = static_cast<int>(m_origin.x + m_res.x / 2);
int j = static_cast<int>(m_origin.y + m_res.y / 2);
// Do all z slices except last
int zMin = static_cast<int>(m_origin.z);
int zMax = static_cast<int>(m_origin.z + m_res.z - 1);
for (int k = zMin, idx = 0; k < zMax; ++k, ++idx) {
V3d wsP, wsPx, wsPy, wsPz;
V3d vsP = discToCont(V3i(i, j, k));
V3d vsPx = discToCont(V3i(i + 1, j, k));
V3d vsPy = discToCont(V3i(i, j + 1, k));
V3d vsPz = discToCont(V3i(i, j, k + 1));
voxelToWorld(vsP, wsP);
voxelToWorld(vsPx, wsPx);
voxelToWorld(vsPy, wsPy);
voxelToWorld(vsPz, wsPz);
m_wsVoxelSize[idx] = V3d((wsPx - wsP).length(),
(wsPy - wsP).length(),
(wsPz - wsP).length());
}
// Duplicate last value since there are no further slices to differentiate
// against
if (m_res.z >= 2) {
m_wsVoxelSize[static_cast<int>(m_res.z - 1)] = m_wsVoxelSize[static_cast<int>(m_res.z - 2)];
}
}
discToCont
double discToCont(int discCoord)
Goes from discrete coordinates to continuous coordinates See Graphics Gems - What is a pixel.
Definition Field.h:1070
V3i
Imath::V3i V3i
Definition SpiMathLib.h:71

References discToCont(), FieldMapping::m_origin, FieldMapping::m_res, m_wsVoxelSize, and voxelToWorld().

Referenced by extentsChanged(), reset(), and setTransforms().

## getLocalToVoxelMatrix()

void FrustumFieldMapping::getLocalToVoxelMatrix | ( | M44d & | result | ) |

private

Todo
  Unit test this

Definition at line 775 of file FieldMapping.cpp.

{
// Local to voxel is a scale by the resolution of the field, offset
// to the origin of the extents
M44d scaling, translation;
scaling.setScale(m_res);
translation.setTranslation(m_origin);
result = scaling * translation;
}

References FieldMapping::m_origin, and FieldMapping::m_res.

## clearCurves()

void FrustumFieldMapping::clearCurves | ( |  | ) |

private

Clears all Curve data members. Used by setTransforms() to prepare for the first sample to be added.

Definition at line 787 of file FieldMapping.cpp.

{
m_lpsToWsCurve.clear();
m_csToWsCurve.clear();
m_nearCurve.clear();
m_farCurve.clear();
}

References m_csToWsCurve, m_farCurve, m_lpsToWsCurve, and m_nearCurve.

Referenced by reset(), and setTransforms().

## Member Data Documentation

## DEFINE_FIELD_RTTI_CONCRETE_CLASS

FrustumFieldMapping::DEFINE_FIELD_RTTI_CONCRETE_CLASS

Definition at line 593 of file FieldMapping.h.

## m_zDistribution

ZDistribution FrustumFieldMapping::m_zDistribution

private

Slice distribution type.

Definition at line 716 of file FieldMapping.h.

Referenced by FrustumFieldMapping(), isIdentical(), localToWorld(), setZDistribution(), worldToLocal(), and zDistribution().

## m_ssToWsCurve

MatrixCurve FrustumFieldMapping::m_ssToWsCurve

private

Time-varying local perspective to world space transform This is not used in calculations, but rather as the public interface to the class.

Definition at line 721 of file FieldMapping.h.

Referenced by screenToWorld(), screenToWorldSamples(), and setTransforms().

## m_csToWsCurve

MatrixCurve FrustumFieldMapping::m_csToWsCurve

private

Time-varying camera to world space transform.

Definition at line 723 of file FieldMapping.h.

Referenced by cameraToWorld(), cameraToWorldSamples(), clearCurves(), isIdentical(), localToWorld(), setTransforms(), and worldToLocal().

## m_lpsToWsCurve

MatrixCurve FrustumFieldMapping::m_lpsToWsCurve

private

Time-varying local perspective to world space transform. Computed from m_ssToWsCurve.

Definition at line 726 of file FieldMapping.h.

Referenced by clearCurves(), isIdentical(), localToWorld(), setTransforms(), and worldToLocal().

## m_nearCurve

FloatCurve FrustumFieldMapping::m_nearCurve

private

Time-varying near plane. Computed from m_lpsToWsCurve.

Definition at line 728 of file FieldMapping.h.

Referenced by clearCurves(), localToWorld(), nearPlane(), nearPlaneSamples(), setTransforms(), and worldToLocal().

## m_farCurve

FloatCurve FrustumFieldMapping::m_farCurve

private

Time-varying far plane. Computed from m_lpsToWsCurve.

Definition at line 730 of file FieldMapping.h.

Referenced by clearCurves(), farPlane(), farPlaneSamples(), localToWorld(), setTransforms(), and worldToLocal().

## m_wsVoxelSize

std::vector<V3d> FrustumFieldMapping::m_wsVoxelSize

private

Precomputed world-space voxel size. Calculations may assume orthogonal transformation for efficiency.

Definition at line 734 of file FieldMapping.h.

Referenced by computeVoxelSize(), and wsVoxelSize().

## m_defaultState

bool FrustumFieldMapping::m_defaultState

private

Boolean to tell us if the mapping is in its 'default' state. This is needed because the class has a default configuration where there is a single sample in all the curves. Once a new transform is set through setTransforms(), the default samples must be cleared.

Definition at line 740 of file FieldMapping.h.

Referenced by FrustumFieldMapping(), reset(), and setTransforms().

The documentation for this class was generated from the following files:

- export/FieldMapping.h
- src/FieldMapping.cpp