Field3D
FrustumFieldMapping Class Reference

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

#include <FieldMapping.h>

Inheritance diagram for FrustumFieldMapping:
FieldMapping RefBase

Public Types

typedef FrustumFieldMapping class_type
 
typedef Curve< doubleFloatCurve
 Time-varying float.
 
typedef Curve< Imath::M44d > MatrixCurve
 Time-varying matrix.
 
typedef boost::intrusive_ptr< FrustumFieldMappingPtr
 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< FieldMappingPtr
 
- Public Types inherited from RefBase
typedef boost::intrusive_ptr< RefBasePtr
 
typedef boost::weak_ptr< RefBaseWeakPtr
 

Public Member Functions

const M44d cameraToWorld () const
 Returns a reference to the camera to world space transform.
 
const MatrixCurve::SampleVeccameraToWorldSamples () const
 Returns a vector of all motion samples for camera to world transform.
 
double farPlane () const
 Returns the far plane.
 
const FloatCurve::SampleVecfarPlaneSamples () const
 Returns a vector of all motion samples for far plane.
 
double nearPlane () const
 Returns the near plane.
 
const FloatCurve::SampleVecnearPlaneSamples () 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::SampleVecscreenToWorldSamples () 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 V3dorigin () const
 Returns the origin.
 
const V3dresolution () 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.
 
RefBaseoperator= (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 charstaticClassType ()
 
- Static Public Member Functions inherited from FieldMapping
static const charstaticClassType ()
 
- Static Public Member Functions inherited from RefBase
static const charstaticClassType ()
 

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< V3dm_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

Convenience typedef.

Definition at line 571 of file FieldMapping.h.

◆ MatrixCurve

Time-varying matrix.

Definition at line 573 of file FieldMapping.h.

◆ FloatCurve

Time-varying float.

Definition at line 575 of file FieldMapping.h.

◆ class_type

◆ base

Convenience typedef for referring to base class.

Definition at line 745 of file FieldMapping.h.

Member Enumeration Documentation

◆ 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.

Constructor & Destructor Documentation

◆ FrustumFieldMapping() [1/2]

FrustumFieldMapping::FrustumFieldMapping ( )

Definition at line 423 of file FieldMapping.cpp.

424 : FieldMapping(),
426 m_defaultState(true)
427{
428 reset();
429}
FieldMapping()
Constructor.
bool m_defaultState
Boolean to tell us if the mapping is in its 'default' state. This is needed because the class has a d...
void reset()
Resets the transform. Makes a perspective transform at the origin, looking down the negative Z axis w...
ZDistribution m_zDistribution
Slice distribution type.

References reset().

Referenced by clone().

◆ FrustumFieldMapping() [2/2]

FrustumFieldMapping::FrustumFieldMapping ( const Box3i & extents)

Definition at line 433 of file FieldMapping.cpp.

434 : FieldMapping(extents)
435{
436 reset();
437}

References reset().

Member Function Documentation

◆ staticClassType()

static const char * FrustumFieldMapping::staticClassType ( )
inlinestatic

Definition at line 595 of file FieldMapping.h.

596 {
597 return "FrustumFieldMapping";
598 }

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
ssToWsSee class documentation for definition.
csToWsSee class documentation for definition.

Definition at line 441 of file FieldMapping.cpp.

442{
444}
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
void setTransforms(const M44d &ssToWs, const M44d &csToWs)
Sets the screenToWorld and cameraToWorld transforms. All other internal matrices will be updated base...

References FIELD3D_MTX_T, and 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
ssToWsSee class documentation for definition.
csToWsSee class documentation for definition.

Definition at line 448 of file FieldMapping.cpp.

450{
451 if (m_defaultState) {
452 clearCurves();
453 m_defaultState = false;
454 }
455
456 // Construct local-to-world transform from ssToWs
458 scale.setScale(V3d(2.0, 2.0, 1.0));
459 translation.setTranslation(V3d(-1.0, -1.0, 0.0));
462
463 // Add samples to Curves
467
468 // Compute near and far planes ---
469
470 // Because the frustum may be skewed we can't just measure distance from
471 // the apex of the frustum to the world-space center point of the frustum.
472 // Instead, we transform into camera space and measure z depth there.
473
474 V3d lsNearP(0.5, 0.5, 0.0), lsFarP(0.5, 0.5, 1.0);
476
477 lpsToWs.multVecMatrix(lsNearP, wsNearP);
478 lpsToWs.multVecMatrix(lsFarP, wsFarP);
479
480 M44d wsToCs = csToWs.inverse();
481 wsToCs.multVecMatrix(wsNearP, csNearP);
482 wsToCs.multVecMatrix(wsFarP, csFarP);
483
484 double near = -csNearP.z;
485 double far = -csFarP.z;
486
487 // Catch NaN here
488 if (std::isnan(near) || std::isnan(far)) {
489 throw BadPerspectiveMatrix("FrustumFieldMapping::setTransforms "
490 "received bad screen-to-world matrix");
491 }
492
495
497}
Imath::V3d V3d
Definition SpiMathLib.h:74
Imath::M44d M44d
Definition SpiMathLib.h:82
void addSample(const float t, const T &value)
Adds a sample point to the curve.
Definition Curve.h:189
MatrixCurve m_lpsToWsCurve
Time-varying local perspective to world space transform. Computed from m_ssToWsCurve.
void clearCurves()
Clears all Curve data members. Used by setTransforms() to prepare for the first sample to be added.
MatrixCurve m_ssToWsCurve
Time-varying local perspective to world space transform This is not used in calculations,...
FloatCurve m_farCurve
Time-varying far plane. Computed from m_lpsToWsCurve.
void computeVoxelSize()
Updates the local to world transformation matrix.
FloatCurve m_nearCurve
Time-varying near plane. Computed from m_lpsToWsCurve.
MatrixCurve m_csToWsCurve
Time-varying camera to world space transform.

References Curve< T >::addSample(), clearCurves(), computeVoxelSize(), FIELD3D_MTX_T, 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.

627 { m_zDistribution = dist; }

References FIELD3D_MTX_T.

◆ zDistribution()

ZDistribution FrustumFieldMapping::zDistribution ( ) const
inline

Returns the z slice distribution.

Definition at line 629 of file FieldMapping.h.

630 { return 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.

635 { return m_ssToWsCurve.linear(0.0); }
T linear(const float t) const
Linearly interpolates a value from the curve.
Definition Curve.h:216

◆ 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.

640 { return m_csToWsCurve.linear(0.0); }

◆ 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.

644 { return m_ssToWsCurve.samples(); }
const SampleVec & samples() const
Returns a const reference to the samples in the curve.
Definition Curve.h:120

◆ 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.

648 { return m_csToWsCurve.samples(); }

◆ 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.

652 { return m_nearCurve.samples(); }

◆ 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.

656 { return m_farCurve.samples(); }

◆ nearPlane()

double FrustumFieldMapping::nearPlane ( ) const
inline

Returns the near plane.

Definition at line 659 of file FieldMapping.h.

660 { return m_nearCurve.linear(0.0); }

◆ farPlane()

double FrustumFieldMapping::farPlane ( ) const
inline

Returns the far plane.

Definition at line 663 of file FieldMapping.h.

664 { return m_farCurve.linear(0.0); }

◆ 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.

502{
503 // Default camera to world ---
504
505 M44d csToWs;
506 csToWs.makeIdentity();
507
508 // Default screen to world ---
509
510 double near = 1;
511 double far = 2;
512 double fovRadians = 45.0 * M_PI / 180.0;
513 double invTan = 1.0 / std::tan(fovRadians / 2.0);
514 double imageAspectRatio = 1.0;
515
516 M44d perspective(1, 0, 0, 0,
517 0, 1, 0, 0,
518 0, 0, (far) / (far - near), 1,
519 0, 0, (- far * near) / (far - near), 0);
520
521 M44d fov;
522 fov.setScale(V3d(invTan / imageAspectRatio, invTan, 1.0));
523
524 M44d flipZ;
525 flipZ.setScale(V3d(1.0, 1.0, -1.0));
526
528
529 M44d standardSsToWs = csToSs.inverse() * csToWs;
530
531 // Set default state ---
532
533 clearCurves();
535
536 m_defaultState = true;
537
539}

References clearCurves(), computeVoxelSize(), FIELD3D_MTX_T, 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.

551{
552 worldToVoxel(wsP, vsP, 0.0);
553}
virtual void worldToVoxel(const V3d &wsP, V3d &vsP) const
Transform from world space position into voxel space.

References FIELD3D_MTX_T, and 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.

558{
559 V3d lsP;
562}
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...
virtual void worldToLocal(const V3d &wsP, V3d &lsP) const
Transform from world space position into local space.

References FIELD3D_MTX_T, 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.

567{
568 voxelToWorld(vsP, wsP, 0.0);
569}
virtual void voxelToWorld(const V3d &vsP, V3d &wsP) const
Transform from voxel space position into world space.

References FIELD3D_MTX_T, and 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.

574{
575 V3d lsP;
578}
void voxelToLocal(const V3d &vsP, V3d &lsP) const
Inverse of localToVoxel.
virtual void localToWorld(const V3d &lsP, V3d &wsP) const
Transform from local space position into world space.

References FIELD3D_MTX_T, 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.

583{
584 worldToLocal(wsP, lsP, 0.0);
585}

References FIELD3D_MTX_T, and 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.

590{
591 switch (m_zDistribution) {
593 {
594 // First transform to local perspective space
595 V3d lpsP;
596 m_lpsToWsCurve.linear(time).inverse().multVecMatrix(wsP, lpsP);
597 // Also transform to camera space
598 V3d csP;
599 m_csToWsCurve.linear(time).inverse().multVecMatrix(wsP, csP);
600 // Interpolate near and far plane at current time
601 double near = m_nearCurve.linear(time);
602 double far = m_farCurve.linear(time);
603 // Use perspective-space X/Y and normalized depth for Z.
604 lsP = V3d(lpsP.x, lpsP.y, FIELD3D_LERPFACTOR(-csP.z, near, far));
605 break;
606 }
608 default:
609 {
610 m_lpsToWsCurve.linear(time).inverse().multVecMatrix(wsP, lsP);
611 break;
612 }
613 }
614}
#define FIELD3D_LERPFACTOR
Definition SpiMathLib.h:92

References FIELD3D_LERPFACTOR, FIELD3D_MTX_T, Curve< T >::linear(), 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.

619{
620 localToWorld(lsP, wsP, 0.0);
621}

References FIELD3D_MTX_T, and localToWorld().

Referenced by 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.

626{
627 switch (m_zDistribution) {
629 {
630 // Interpolate near and far plane at current time
631 double near = m_nearCurve.linear(time);
632 double far = m_farCurve.linear(time);
633 // In this case, local space is -not- equal to local perspective space
634 // Determine distance from camera
635 double wsDepthFromCam = FIELD3D_LERP(near, far, lsP.z);
636 // Transform point right in front of camera, X units away into world space
639 // Transform center point into screen space so we know what depth
640 // (in screen space) the voxel would live at -if- it were in local
641 // perspective space.
642 m_lpsToWsCurve.linear(time).inverse().multVecMatrix(wsCenterP, lpsCenterP);
643 // Now we create a local perspective coordinate that can be transformed
644 // using m_lpsToWsCurve
645 V3d lpsP(lsP.x, lsP.y, lpsCenterP.z);
646 // Now we can use m_lpsToWsCurve to transform the actual voxel location
647 m_lpsToWsCurve.linear(time).multVecMatrix(lpsP, wsP);
648 break;
649 }
651 default:
652 {
653 // In this case, local space and local perspective space are the same.
654 m_lpsToWsCurve.linear(time).multVecMatrix(lsP, wsP);
655 break;
656 }
657 }
658}
#define FIELD3D_LERP
Definition SpiMathLib.h:91

References FIELD3D_LERP, FIELD3D_MTX_T, Curve< T >::linear(), 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.

544{
546}

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.

663{
664 return std::string(staticClassType());
665}
static const char * staticClassType()

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.

671{
673
674 if (other->className() != k_frustumMappingName) {
675 return false;
676 } else {
677
680
681 if (fm) {
682
683 const SampleVec lpsToWs1 = m_lpsToWsCurve.samples();
684 const SampleVec lpsToWs2 = fm->m_lpsToWsCurve.samples();
685 const SampleVec csToWs1 = m_csToWsCurve.samples();
686 const SampleVec csToWs2 = fm->m_csToWsCurve.samples();
687
688 size_t numSamples = lpsToWs1.size();
689
690 // Check that slice distributions match
691 if (m_zDistribution != fm->m_zDistribution) {
692 return false;
693 }
694
695 // First check if time sample counts differ
696 // lpsToWs and csToWs are guaranteed to have same sample count.
697 if (lpsToWs1.size() != lpsToWs2.size()) {
698 return false;
699 }
700
701 // Then check if all time samples match, then check localToWorld
702 // and voxelToWorld matrices
703 for (size_t i = 0; i < numSamples; ++i) {
704 if (lpsToWs1[i].first != lpsToWs2[i].first) {
705 return false;
706 }
708 tolerance)) {
709 return false;
710 }
712 tolerance)) {
713 return false;
714 }
715 }
716
717 return true;
718
719 } else {
720 return false;
721 }
722 }
723 return false;
724}
std::vector< Sample > SampleVec
Definition Curve.h:102
boost::intrusive_ptr< FrustumFieldMapping > Ptr
Convenience typedef.
bool checkMatricesIdentical(const Matrix_T &m1, const Matrix_T &m2, double tolerance)

References FIELD3D_MTX_T, m_csToWsCurve, m_lpsToWsCurve, m_zDistribution, and Curve< T >::samples().

◆ 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.

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

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

◆ 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.

798{
799 return Ptr(new FrustumFieldMapping(*this));
800}

References FrustumFieldMapping().

◆ computeVoxelSize()

void FrustumFieldMapping::computeVoxelSize ( )
private

Updates the local to world transformation matrix.

Definition at line 737 of file FieldMapping.cpp.

738{
739 // Precompute the voxel size ---
740
741 m_wsVoxelSize.resize(static_cast<int>(m_res.z),V3d(0.0));
742
743 int i = static_cast<int>(m_origin.x + m_res.x / 2);
744 int j = static_cast<int>(m_origin.y + m_res.y / 2);
745
746 // Do all z slices except last
747 int zMin = static_cast<int>(m_origin.z);
748 int zMax = static_cast<int>(m_origin.z + m_res.z - 1);
749
750 for (int k = zMin, idx = 0; k < zMax; ++k, ++idx) {
751 V3d wsP, wsPx, wsPy, wsPz;
752 V3d vsP = discToCont(V3i(i, j, k));
753 V3d vsPx = discToCont(V3i(i + 1, j, k));
754 V3d vsPy = discToCont(V3i(i, j + 1, k));
755 V3d vsPz = discToCont(V3i(i, j, k + 1));
761 (wsPy - wsP).length(),
762 (wsPz - wsP).length());
763 }
764
765 // Duplicate last value since there are no further slices to differentiate
766 // against
767 if (m_res.z >= 2) {
768 m_wsVoxelSize[static_cast<int>(m_res.z - 1)] = m_wsVoxelSize[static_cast<int>(m_res.z - 2)];
769 }
770
771}
double discToCont(int discCoord)
Goes from discrete coordinates to continuous coordinates See Graphics Gems - What is a pixel.
Definition Field.h:1070
Imath::V3i V3i
Definition SpiMathLib.h:71

References discToCont(), FIELD3D_MTX_T, 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.

776{
777 // Local to voxel is a scale by the resolution of the field, offset
778 // to the origin of the extents
780 scaling.setScale(m_res);
781 translation.setTranslation(m_origin);
782 result = scaling * translation;
783}

References FIELD3D_MTX_T, 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.

788{
793}
void clear()
Clears all samples in curve.
Definition Curve.h:124

References Curve< T >::clear(), 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 isIdentical(), localToWorld(), and worldToLocal().

◆ 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 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 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(), 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(), 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 reset(), and setTransforms().


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