vrj::SurfaceProjection Class Reference

Surface specific class for projection definitions. More...

#include <vrj/Display/SurfaceProjection.h>

Inheritance diagram for vrj::SurfaceProjection:

Inheritance graph
[legend]
Collaboration diagram for vrj::SurfaceProjection:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SurfaceProjection (const gmtl::Point3f &llCorner, const gmtl::Point3f &lrCorner, const gmtl::Point3f &urCorner, const gmtl::Point3f &ulCorner)
 Constructs a new surface projection using the given corner points.
void validateCorners ()
 Checks the corner points to make sure they form a legal surface.
virtual void config (jccl::ConfigElementPtr element)
 Configures the projection using the element given.
virtual void calcViewMatrix (const gmtl::Matrix44f &eyePos, const float scaleFactor)
 Recalculate the projection matrix.
virtual void calcViewFrustum (const gmtl::Matrix44f &eyePos, const float scaleFactor)
 Recalculate the view frustum.
std::ostream & outStream (std::ostream &out, const unsigned int indentLevel=0)
 Virtual output oporators.

Protected Member Functions

Screen calculation functions
These calculate mOriginToScreen, etc, from the screen corners.

calculateOffsets requires that mLLCorner to mULCorner be set correctly, and it will handle calling calculateSurfaceRotation and calculateCornersInBaseFrame.

void calculateOffsets ()
void calculateSurfaceRotation ()
void calculateCornersInBaseFrame ()

Protected Attributes

float mOriginToScreen
float mOriginToRight
float mOriginToLeft
float mOriginToTop
float mOriginToBottom
Coordinate systems
Coordinate system descriptions:

Base - B - Base coordinate system of the real physical world.
Surface - S - Cordinate frame that is aligned with the surface. This is the coordinates that. The surface and frustum (projection) parameters are stored in/relative to.
Surface Transform - ST - Coordinate frame that offsets the Surface in space. Only used for tracked surfaces.
Eye - E - Coordinate system that is aligned with the eye. This is the frame that the frustum is drawn in for final projection. This is where the "view" starts from.

gmtl::Matrix44f mSurfaceRotation
 Same as m_base_M_surface.
gmtl::Matrix44f m_base_M_surface
gmtl::Matrix44f m_surface_M_base
 Stored inverse for performance.
Screen configuration (in Surface coordinate frame)
gmtl::Point3f mLLCorner
gmtl::Point3f mLRCorner
gmtl::Point3f mURCorner
gmtl::Point3f mULCorner
Corners transformed onto an XY plane
gmtl::Point3f mxLLCorner
gmtl::Point3f mxLRCorner
gmtl::Point3f mxURCorner
gmtl::Point3f mxULCorner

Detailed Description

Surface specific class for projection definitions.

Responsible for storing and computing projection information of a surface specified.

Definition at line 53 of file SurfaceProjection.h.


Constructor & Destructor Documentation

vrj::SurfaceProjection::SurfaceProjection ( const gmtl::Point3f &  llCorner,
const gmtl::Point3f &  lrCorner,
const gmtl::Point3f &  urCorner,
const gmtl::Point3f &  ulCorner 
) [inline]

Constructs a new surface projection using the given corner points.

Parameters:
llCorner Lower left corner.
lrCorner Lower right corner.
urCorner Upper right corner.
ulCorner Upper left corner.

Definition at line 64 of file SurfaceProjection.h.

00068       : mLLCorner(llCorner)
00069       , mLRCorner(lrCorner)
00070       , mURCorner(urCorner)
00071       , mULCorner(ulCorner)
00072    {
00073       /* Do nothing. */ ;
00074    }


Member Function Documentation

void vrj::SurfaceProjection::validateCorners (  ) 

Checks the corner points to make sure they form a legal surface.

If not, an exception of type vrj::InvalidSurfaceException is thrown.

Exceptions:
vrj::InvalidSurfaceException is thrown if the corners do not form a legal surface.
Since:
2.0.2

Definition at line 56 of file SurfaceProjection.cpp.

References mLLCorner, mLRCorner, mULCorner, and mURCorner.

Referenced by vrj::SurfaceViewport::config().

00057 {
00058    gmtl::Vec3f norm1, norm2;
00059    gmtl::Vec3f bot_side = mLRCorner-mLLCorner;
00060    gmtl::Vec3f diag = mULCorner-mLRCorner;
00061    gmtl::Vec3f right_side = mURCorner-mLRCorner;
00062    gmtl::cross(norm1, bot_side, diag);
00063    gmtl::cross(norm2, bot_side, right_side);
00064    gmtl::normalize( norm1 ); gmtl::normalize(norm2);
00065 
00066    if ( ! gmtl::isEqual(norm1, norm2, 1e-4f) )
00067    {
00068       std::ostringstream msg_stream;
00069       msg_stream << "The corners " << mLLCorner << ", " << mLRCorner << ", "
00070                  << mURCorner << ", " << mULCorner
00071                  << " do not form a valid surface";
00072       throw InvalidSurfaceException(msg_stream.str());
00073    }
00074 }

void vrj::SurfaceProjection::config ( jccl::ConfigElementPtr  element  )  [virtual]

Configures the projection using the element given.

Reimplemented from vrj::Projection.

Reimplemented in vrj::TrackedSurfaceProjection.

Definition at line 77 of file SurfaceProjection.cpp.

References vrj::Projection::config().

00078 {
00079    vprASSERT( element->getID() == "surface_viewport" );
00080 
00081    Projection::config(element);        // Call base class config first
00082 }

void vrj::SurfaceProjection::calcViewMatrix ( const gmtl::Matrix44f &  eyePos,
const float  scaleFactor 
) [virtual]

Recalculate the projection matrix.

Precondition:
WallRotation matrix must be set correctly. mOrigin*'s must all be set correctly.

eyePos is scaled by position factor.

scaleFactor is the scale current used

Postcondition:
frustum has been recomputed for given eyePos.

Implements vrj::Projection.

Reimplemented in vrj::TrackedSurfaceProjection.

Definition at line 98 of file SurfaceProjection.cpp.

References calculateOffsets(), calcViewFrustum(), m_surface_M_base, and vrj::Projection::mViewMat.

Referenced by vrj::TrackedSurfaceProjection::calcViewMatrix().

00100 {
00101    calculateOffsets();
00102    calcViewFrustum(eyePos, scaleFactor);
00103 
00104    //Coord eye_coord(eyePos);
00105    const gmtl::Vec3f eye_pos(gmtl::makeTrans<gmtl::Vec3f>(eyePos));             // Non-xformed pos
00106 
00107    // Need to post translate to get the view matrix at the position of the eye
00108    mViewMat = m_surface_M_base * gmtl::makeTrans<gmtl::Matrix44f>( -eye_pos );
00109 }

void vrj::SurfaceProjection::calcViewFrustum ( const gmtl::Matrix44f &  eyePos,
const float  scaleFactor 
) [virtual]

Recalculate the view frustum.

Note:
This function is called as part of calcViewMatrix.

Definition at line 124 of file SurfaceProjection.cpp.

References m_surface_M_base, vrj::Projection::mFarDist, vrj::Projection::mFocusPlaneDist, vrj::Projection::mFrustum, vrj::Projection::mNearDist, mOriginToBottom, mOriginToLeft, mOriginToRight, mOriginToScreen, mOriginToTop, vrj::Frustum::set(), and vrjDBG_DISP_MGR().

Referenced by calcViewMatrix().

00126 {
00127    const float near_dist = mNearDist;
00128    const float far_dist = mFarDist;
00129 
00130    // Distance measurements from eye to screen/edges
00131    // Distance to edges is from the point on the screen plane
00132    // where a normal line would go through the origin.
00133    float eye_to_screen, eye_to_right, eye_to_left, eye_to_top, eye_to_bottom;
00134 
00135    // Compute transformed eye position
00136    // - Converts eye coords into the surface's coord system
00137    // Xformed position of eyes
00138    const gmtl::Point3f eye_surface =
00139       m_surface_M_base * gmtl::makeTrans<gmtl::Point3f>(eyePos);
00140 
00141    vprDEBUG(vrjDBG_DISP_MGR, vprDBG_HEX_LVL)
00142       << "SurfaceProjection::calcviewFrustum:    Base eye:" << gmtl::makeTrans<gmtl::Point3f>(eyePos)
00143       << "  Xformed eye:" << eye_surface
00144       << std::endl << vprDEBUG_FLUSH;
00145 
00146    // Compute dist from eye to screen/edges
00147    // Take into account scale since all origin to anythings are in meters
00148    eye_to_screen = (scaleFactor * mOriginToScreen) + eye_surface[gmtl::Zelt];
00149    eye_to_right =  (scaleFactor * mOriginToRight) - eye_surface[gmtl::Xelt];
00150    eye_to_left =   (scaleFactor * mOriginToLeft) + eye_surface[gmtl::Xelt];
00151    eye_to_top =    (scaleFactor * mOriginToTop) - eye_surface[gmtl::Yelt];
00152    eye_to_bottom = (scaleFactor * mOriginToBottom) + eye_surface[gmtl::Yelt];
00153 
00154    // Distances in near plane, in near plane from origin.  (Similar to above)
00155    // Find dists on near plane using similar triangles
00156    const float near_distFront = near_dist/eye_to_screen; // constant factor
00157    const float n_eye_to_left = eye_to_left*near_distFront;
00158    const float n_eye_to_right = eye_to_right*near_distFront;
00159    const float n_eye_to_top = eye_to_top*near_distFront;
00160    const float n_eye_to_bottom = eye_to_bottom*near_distFront;
00161 
00162    // Set frustum and calulcate the matrix
00163    mFrustum.set(-n_eye_to_left, n_eye_to_right,
00164                 -n_eye_to_bottom, n_eye_to_top,
00165                 near_dist, far_dist);
00166 
00167    mFocusPlaneDist = eye_to_screen;    // Needed for drawing
00168 
00169    vprDEBUG(vrjDBG_DISP_MGR, vprDBG_HEX_LVL)
00170       << "SurfaceProjection::calcWallProjection: \n\tFrustum: " << mFrustum
00171       << std::endl << vprDEBUG_FLUSH;
00172 
00173 }

std::ostream & vrj::SurfaceProjection::outStream ( std::ostream &  out,
const unsigned int  indentLevel = 0 
) [virtual]

Virtual output oporators.

Every class derived from us shoudl just define this, and the opertetor<< will "just work".

Reimplemented from vrj::Projection.

Reimplemented in vrj::TrackedSurfaceProjection.

Definition at line 175 of file SurfaceProjection.cpp.

References vrj::Projection::outStream().

Referenced by vrj::TrackedSurfaceProjection::outStream().

00177 {
00178 //   const int pad_width_dot(20 - indentLevel);
00179    out.setf(std::ios::left);
00180 
00181    const std::string indent_text(indentLevel, ' ');
00182 
00183    out << indent_text << "vrj::SurfaceProjection:\n";
00184 
00185    return Projection::outStream(out, indentLevel);
00186 }

void vrj::SurfaceProjection::calculateOffsets (  )  [protected]

Definition at line 188 of file SurfaceProjection.cpp.

References calculateCornersInBaseFrame(), calculateSurfaceRotation(), m_base_M_surface, m_surface_M_base, mOriginToBottom, mOriginToLeft, mOriginToRight, mOriginToScreen, mOriginToTop, mSurfaceRotation, mxLLCorner, mxLRCorner, and mxURCorner.

Referenced by calcViewMatrix(), and vrj::TrackedSurfaceProjection::updateSurfaceParams().

00188                                         {
00189       calculateSurfaceRotation();
00190 
00191       m_base_M_surface=mSurfaceRotation;
00192       gmtl::invert(m_surface_M_base,m_base_M_surface);
00193       
00194       calculateCornersInBaseFrame();
00195 
00196       mOriginToScreen=-mxLLCorner[gmtl::Zelt];
00197       mOriginToRight=mxLRCorner[gmtl::Xelt];
00198       mOriginToLeft=-mxLLCorner[gmtl::Xelt];
00199       mOriginToTop=mxURCorner[gmtl::Yelt];
00200       mOriginToBottom=-mxLRCorner[gmtl::Yelt];
00201 }

void vrj::SurfaceProjection::calculateSurfaceRotation (  )  [protected]

Definition at line 203 of file SurfaceProjection.cpp.

References mLLCorner, mLRCorner, mSurfaceRotation, and mURCorner.

Referenced by calculateOffsets().

00204 {
00205    // Find the base vectors for the surface axiis (in terms of the base coord system)
00206    // With z out, x to the right, and y up
00207    gmtl::Vec3f x_base, y_base, z_base;
00208    x_base = (mLRCorner-mLLCorner);
00209    y_base = (mURCorner-mLRCorner);
00210    gmtl::cross( z_base, x_base, y_base);
00211 
00212    // They must be normalized
00213    gmtl::normalize(x_base); gmtl::normalize(y_base); gmtl::normalize(z_base);
00214 
00215    // Calculate the surfaceRotMat using law of cosines
00216    mSurfaceRotation = gmtl::makeDirCos<gmtl::Matrix44f>(x_base, y_base, z_base );
00217 }

void vrj::SurfaceProjection::calculateCornersInBaseFrame (  )  [protected]

Definition at line 219 of file SurfaceProjection.cpp.

References m_surface_M_base, mLLCorner, mLRCorner, mULCorner, mURCorner, mxLLCorner, mxLRCorner, mxULCorner, and mxURCorner.

Referenced by calculateOffsets().

00220 {
00221    mxLLCorner = m_surface_M_base * mLLCorner;
00222    mxLRCorner = m_surface_M_base * mLRCorner;
00223    mxURCorner = m_surface_M_base * mURCorner;
00224    mxULCorner = m_surface_M_base * mULCorner;
00225 
00226    // Verify that they are all in the same x,y plane
00227    vprDEBUG(vprDBG_ALL, vprDBG_HVERB_LVL) << std::setprecision(10)
00228                                           << mxLLCorner[gmtl::Zelt] << " "
00229                                           << mxLRCorner[gmtl::Zelt] << " "
00230                                           << mxURCorner[gmtl::Zelt] << " "
00231                                           << mxULCorner[gmtl::Zelt] << "\n"
00232                                           << vprDEBUG_FLUSH;
00233 
00234 #ifdef VJ_DEBUG
00235    // Use 1e-4f here, otherwise the floating point error can get big enough to mess this up for tracked surfaces
00236    vprASSERT(gmtl::Math::isEqual(mxLLCorner[gmtl::Zelt], mxLRCorner[gmtl::Zelt], 1e-4f) &&
00237              gmtl::Math::isEqual(mxURCorner[gmtl::Zelt], mxULCorner[gmtl::Zelt], 1e-4f) &&
00238              gmtl::Math::isEqual(mxLLCorner[gmtl::Zelt], mxULCorner[gmtl::Zelt], 1e-4f));
00239 #endif
00240 }


Member Data Documentation

gmtl::Matrix44f vrj::SurfaceProjection::mSurfaceRotation [protected]

Same as m_base_M_surface.

Definition at line 145 of file SurfaceProjection.h.

Referenced by calculateOffsets(), and calculateSurfaceRotation().

gmtl::Matrix44f vrj::SurfaceProjection::m_base_M_surface [protected]

Definition at line 151 of file SurfaceProjection.h.

Referenced by calculateOffsets().

gmtl::Matrix44f vrj::SurfaceProjection::m_surface_M_base [protected]

Stored inverse for performance.

Definition at line 152 of file SurfaceProjection.h.

Referenced by calculateCornersInBaseFrame(), calculateOffsets(), calcViewFrustum(), and calcViewMatrix().

gmtl::Point3f vrj::SurfaceProjection::mLLCorner [protected]

Definition at line 157 of file SurfaceProjection.h.

Referenced by calculateCornersInBaseFrame(), calculateSurfaceRotation(), vrj::TrackedSurfaceProjection::updateSurfaceParams(), and validateCorners().

gmtl::Point3f vrj::SurfaceProjection::mLRCorner [protected]

Definition at line 158 of file SurfaceProjection.h.

Referenced by calculateCornersInBaseFrame(), calculateSurfaceRotation(), vrj::TrackedSurfaceProjection::updateSurfaceParams(), and validateCorners().

gmtl::Point3f vrj::SurfaceProjection::mURCorner [protected]

Definition at line 159 of file SurfaceProjection.h.

Referenced by calculateCornersInBaseFrame(), calculateSurfaceRotation(), vrj::TrackedSurfaceProjection::updateSurfaceParams(), and validateCorners().

gmtl::Point3f vrj::SurfaceProjection::mULCorner [protected]

Definition at line 160 of file SurfaceProjection.h.

Referenced by calculateCornersInBaseFrame(), vrj::TrackedSurfaceProjection::updateSurfaceParams(), and validateCorners().

gmtl::Point3f vrj::SurfaceProjection::mxLLCorner [protected]

Definition at line 165 of file SurfaceProjection.h.

Referenced by calculateCornersInBaseFrame(), and calculateOffsets().

gmtl::Point3f vrj::SurfaceProjection::mxLRCorner [protected]

Definition at line 166 of file SurfaceProjection.h.

Referenced by calculateCornersInBaseFrame(), and calculateOffsets().

gmtl::Point3f vrj::SurfaceProjection::mxURCorner [protected]

Definition at line 167 of file SurfaceProjection.h.

Referenced by calculateCornersInBaseFrame(), and calculateOffsets().

gmtl::Point3f vrj::SurfaceProjection::mxULCorner [protected]

Definition at line 168 of file SurfaceProjection.h.

Referenced by calculateCornersInBaseFrame().

float vrj::SurfaceProjection::mOriginToScreen [protected]

Definition at line 171 of file SurfaceProjection.h.

Referenced by calculateOffsets(), and calcViewFrustum().

float vrj::SurfaceProjection::mOriginToRight [protected]

Definition at line 172 of file SurfaceProjection.h.

Referenced by calculateOffsets(), and calcViewFrustum().

float vrj::SurfaceProjection::mOriginToLeft [protected]

Definition at line 173 of file SurfaceProjection.h.

Referenced by calculateOffsets(), and calcViewFrustum().

float vrj::SurfaceProjection::mOriginToTop [protected]

Definition at line 174 of file SurfaceProjection.h.

Referenced by calculateOffsets(), and calcViewFrustum().

float vrj::SurfaceProjection::mOriginToBottom [protected]

Definition at line 175 of file SurfaceProjection.h.

Referenced by calculateOffsets(), and calcViewFrustum().


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:58:07 2007 for VR Juggler by  doxygen 1.5.1