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< double > FloatCurve
 Time-varying float. More...
 
typedef Curve< Imath::M44dMatrixCurve
 Time-varying matrix. More...
 
typedef boost::intrusive_ptr< FrustumFieldMappingPtr
 Convenience typedef. More...
 
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. More...
 
const MatrixCurve::SampleVeccameraToWorldSamples () const
 Returns a vector of all motion samples for camera to world transform. More...
 
double farPlane () const
 Returns the far plane. More...
 
const FloatCurve::SampleVecfarPlaneSamples () const
 Returns a vector of all motion samples for far plane. More...
 
double nearPlane () const
 Returns the near plane. More...
 
const FloatCurve::SampleVecnearPlaneSamples () const
 Returns a vector of all motion samples for near plane. More...
 
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. More...
 
const M44d screenToWorld () const
 Returns a reference to the screen to world space transform. More...
 
const MatrixCurve::SampleVecscreenToWorldSamples () const
 Returns a vector of all motion samples for screen to world transform. More...
 
void setTransforms (const M44d &ssToWs, const M44d &csToWs)
 Sets the screenToWorld and cameraToWorld transforms. All other internal matrices will be updated based on these. More...
 
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. More...
 
void setZDistribution (ZDistribution dist)
 Sets the z slice distribution. More...
 
ZDistribution zDistribution () const
 Returns the z slice distribution. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual std::string className () const
 Returns the FieldMapping type name. Used when writing/reading from disk. More...
 
virtual bool isIdentical (FieldMapping::Ptr other, double tolerance=0.0) const
 Whether the mapping is identical to another mapping. More...
 
virtual V3d wsVoxelSize (int i, int j, int k) const
 Returns world-space size of a voxel at the specified coordinate. More...
 
virtual FieldMapping::Ptr clone () const
 Returns a pointer to a copy of the mapping, pure virtual so ensure derived classes properly implement it. More...
 
- Public Member Functions inherited from FieldMapping
const V3dorigin () const
 Returns the origin. More...
 
const V3dresolution () const
 Returns the resolution. More...
 
void setExtents (const Box3i &extents)
 This sets the field extents information to use for defining the local coordinate space. More...
 
 FieldMapping ()
 Constructor. More...
 
 FieldMapping (const Box3i &extents)
 Construct with known extents. More...
 
virtual ~FieldMapping ()
 Destructor. More...
 
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. More...
 
void voxelToLocal (const V3d &vsP, V3d &lsP) const
 Inverse of localToVoxel. More...
 
- Public Member Functions inherited from RefBase
void ref () const
 Used by boost::intrusive_pointer. More...
 
size_t refcnt ()
 Used by boost::intrusive_pointer. More...
 
void unref () const
 Used by boost::intrusive_pointer. More...
 
WeakPtr weakPtr () const
 
 RefBase ()
 
 RefBase (const RefBase &)
 Copy constructor. More...
 
RefBaseoperator= (const RefBase &)
 Assignment operator. More...
 
virtual ~RefBase ()
 Destructor. More...
 
virtual bool checkRTTI (const char *typenameStr)=0
 This function is only implemented by concrete classes and triggers the actual RTTI check through matchRTTI();. More...
 
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. More...
 

Static Public Member Functions

static const char * staticClassType ()
 
- Static Public Member Functions inherited from FieldMapping
static const char * staticClassType ()
 
- Static Public Member Functions inherited from RefBase
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. More...
 

Private Member Functions

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

Private Attributes

MatrixCurve m_csToWsCurve
 Time-varying camera to world space transform. More...
 
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. More...
 
FloatCurve m_farCurve
 Time-varying far plane. Computed from m_lpsToWsCurve. More...
 
MatrixCurve m_lpsToWsCurve
 Time-varying local perspective to world space transform. Computed from m_ssToWsCurve. More...
 
FloatCurve m_nearCurve
 Time-varying near plane. Computed from m_lpsToWsCurve. More...
 
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. More...
 
std::vector< V3dm_wsVoxelSize
 Precomputed world-space voxel size. Calculations may assume orthogonal transformation for efficiency. More...
 
ZDistribution m_zDistribution
 Slice distribution type. More...
 

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. More...
 
V3d m_res
 The integer voxel-space resolution of the underlying Field object. Is equal to field.extents.max - field.extents.min + 1. More...
 

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

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.

585  {
588  };

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 }

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 {
443  setTransforms(0.0, ssToWs, csToWs);
444 }

Referenced by reset().

◆ 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
457  M44d lsToSs, scale, translation;
458  scale.setScale(V3d(2.0, 2.0, 1.0));
459  translation.setTranslation(V3d(-1.0, -1.0, 0.0));
460  lsToSs = scale * translation;
461  M44d lpsToWs = lsToSs * ssToWs;
462 
463  // Add samples to Curves
464  m_ssToWsCurve.addSample(t, ssToWs);
465  m_lpsToWsCurve.addSample(t, lpsToWs);
466  m_csToWsCurve.addSample(t, csToWs);
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);
475  V3d wsNearP, wsFarP, csNearP, csFarP;
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 
493  m_nearCurve.addSample(t, near);
494  m_farCurve.addSample(t, far);
495 
497 }

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

627  { m_zDistribution = dist; }

◆ 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); }

◆ 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(); }

◆ 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 
527  M44d csToSs = flipZ * perspective * fov;
528 
529  M44d standardSsToWs = csToSs.inverse() * csToWs;
530 
531  // Set default state ---
532 
533  clearCurves();
534  setTransforms(standardSsToWs, csToWs);
535 
536  m_defaultState = true;
537 
539 }

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

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

◆ 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;
560  worldToLocal(wsP, lsP, time);
561  localToVoxel(lsP, vsP);
562 }

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.

567 {
568  voxelToWorld(vsP, wsP, 0.0);
569 }

Referenced by computeVoxelSize().

◆ 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;
576  voxelToLocal(vsP, lsP);
577  localToWorld(lsP, wsP, time);
578 }

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.

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

Referenced by 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) {
592  case UniformDistribution:
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 }

References FIELD3D_LERPFACTOR, 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 }

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::GetIntersections::intersectFrustumMapping(), 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) {
628  case UniformDistribution:
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
637  V3d lpsCenterP, wsCenterP, csCenterP(0.0, 0.0, -wsDepthFromCam);
638  m_csToWsCurve.linear(time).multVecMatrix(csCenterP, wsCenterP);
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 }

References FIELD3D_LERP, 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 }

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 
679  FIELD_DYNAMIC_CAST<FrustumFieldMapping>(other);
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  }
707  if (!checkMatricesIdentical(lpsToWs1[i].second, lpsToWs2[i].second,
708  tolerance)) {
709  return false;
710  }
711  if (!checkMatricesIdentical(csToWs1[i].second, csToWs2[i].second,
712  tolerance)) {
713  return false;
714  }
715  }
716 
717  return true;
718 
719  } else {
720  return false;
721  }
722  }
723  return false;
724 }

References FIELD3D_NAMESPACE_OPEN::checkMatricesIdentical(), FIELD3D_NAMESPACE_OPEN::k_frustumMappingName(), 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 }

References FieldMapping::m_origin, FieldMapping::m_res, m_wsVoxelSize, detail::max(), and detail::min().

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.

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));
756  voxelToWorld(vsP, wsP);
757  voxelToWorld(vsPx, wsPx);
758  voxelToWorld(vsPy, wsPy);
759  voxelToWorld(vsPz, wsPz);
760  m_wsVoxelSize[idx] = V3d((wsPx - wsP).length(),
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 }

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.

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

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.

788 {
791  m_nearCurve.clear();
792  m_farCurve.clear();
793 }

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:
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
V3i
Imath::V3i V3i
Definition: SpiMathLib.h:71
FieldMapping::FieldMapping
FieldMapping()
Constructor.
Definition: FieldMapping.cpp:113
FrustumFieldMapping::voxelToWorld
virtual void voxelToWorld(const V3d &vsP, V3d &wsP) const
Transform from voxel space position into world space.
Definition: FieldMapping.cpp:566
V3d
Imath::V3d V3d
Definition: SpiMathLib.h:74
FrustumFieldMapping::FrustumFieldMapping
FrustumFieldMapping()
Definition: FieldMapping.cpp:423
discToCont
double discToCont(int discCoord)
Goes from discrete coordinates to continuous coordinates See Graphics Gems - What is a pixel.
Definition: Field.h:1070
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_farCurve
FloatCurve m_farCurve
Time-varying far plane. Computed from m_lpsToWsCurve.
Definition: FieldMapping.h:730
FrustumFieldMapping::worldToLocal
virtual void worldToLocal(const V3d &wsP, V3d &lsP) const
Transform from world space position into local space.
Definition: FieldMapping.cpp:582
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
FrustumFieldMapping::m_zDistribution
ZDistribution m_zDistribution
Slice distribution type.
Definition: FieldMapping.h:716
Curve::addSample
void addSample(const float t, const T &value)
Adds a sample point to the curve.
Definition: Curve.h:172
FieldMapping::voxelToLocal
void voxelToLocal(const V3d &vsP, V3d &lsP) const
Inverse of localToVoxel.
Definition: FieldMapping.cpp:162
FIELD3D_NAMESPACE_OPEN::k_frustumMappingName
const string k_frustumMappingName("FrustumFieldMapping")
FIELD3D_LERPFACTOR
#define FIELD3D_LERPFACTOR
Definition: SpiMathLib.h:92
Curve::samples
const SampleVec & samples() const
Returns a const reference to the samples in the curve.
Definition: Curve.h:103
FrustumFieldMapping::Ptr
boost::intrusive_ptr< FrustumFieldMapping > Ptr
Convenience typedef.
Definition: FieldMapping.h:571
FrustumFieldMapping::m_csToWsCurve
MatrixCurve m_csToWsCurve
Time-varying camera to world space transform.
Definition: FieldMapping.h:723
detail::max
T max(const T a, const T2 b)
Max operation on mixed types.
Definition: FieldSampler.h:32
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
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::UniformDistribution
Definition: FieldMapping.h:587
FrustumFieldMapping::m_lpsToWsCurve
MatrixCurve m_lpsToWsCurve
Time-varying local perspective to world space transform. Computed from m_ssToWsCurve.
Definition: FieldMapping.h:726
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
M44d
Imath::M44d M44d
Definition: SpiMathLib.h:82
FrustumFieldMapping::computeVoxelSize
void computeVoxelSize()
Updates the local to world transformation matrix.
Definition: FieldMapping.cpp:737
Curve< Imath::M44d >::SampleVec
std::vector< Sample > SampleVec
Definition: Curve.h:85
FIELD3D_LERP
#define FIELD3D_LERP
Definition: SpiMathLib.h:91
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::staticClassType
static const char * staticClassType()
Definition: FieldMapping.h:595
FrustumFieldMapping::m_nearCurve
FloatCurve m_nearCurve
Time-varying near plane. Computed from m_lpsToWsCurve.
Definition: FieldMapping.h:728
FIELD3D_NAMESPACE_OPEN::checkMatricesIdentical
bool checkMatricesIdentical(const Matrix_T &m1, const Matrix_T &m2, double tolerance)
Definition: FieldMapping.cpp:86
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::localToWorld
virtual void localToWorld(const V3d &lsP, V3d &wsP) const
Transform from local space position into world space.
Definition: FieldMapping.cpp:618
FrustumFieldMapping::worldToVoxel
virtual void worldToVoxel(const V3d &wsP, V3d &vsP) const
Transform from world space position into voxel space.
Definition: FieldMapping.cpp:550
detail::min
T min(const T a, const T2 b)
Min operation on mixed types.
Definition: FieldSampler.h:25
FrustumFieldMapping::m_wsVoxelSize
std::vector< V3d > m_wsVoxelSize
Precomputed world-space voxel size. Calculations may assume orthogonal transformation for efficiency.
Definition: FieldMapping.h:734
FrustumFieldMapping::PerspectiveDistribution
Definition: FieldMapping.h:586
Curve::clear
void clear()
Clears all samples in curve.
Definition: Curve.h:107
Curve::linear
T linear(const float t) const
Linearly interpolates a value from the curve.
Definition: Curve.h:199