vrj::SurfaceViewport Class Reference

Defines a display surface an associated projections. More...

#include <vrj/Display/SurfaceViewport.h>

Inheritance diagram for vrj::SurfaceViewport:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SurfaceViewport ()
virtual ~SurfaceViewport ()
virtual bool config (jccl::ConfigElementPtr element)
 Takes a display element and configures the viewport based on it.
virtual void updateProjections (const float positionScale)
 Updates the projection data for this viewport.
void getCorners (gmtl::Point3f &ll, gmtl::Point3f &lr, gmtl::Point3f &ur, gmtl::Point3f &ul)
virtual std::ostream & outStream (std::ostream &out, const unsigned int indentLevel=0)

Protected Attributes

The corners in 3Space (for config)
gmtl::Point3f mLLCorner
gmtl::Point3f mLRCorner
gmtl::Point3f mURCorner
gmtl::Point3f mULCorner
Tracked surface info
Deal with tracked surfaces (HMD, movable walls, desks, etc).

bool mTracked
 Is this surface tracked?
std::string mTrackerProxyName
 If tracked, what is the name of the tracker.

Detailed Description

Defines a display surface an associated projections.

Definition at line 54 of file SurfaceViewport.h.


Constructor & Destructor Documentation

vrj::SurfaceViewport::SurfaceViewport (  )  [inline]

Definition at line 57 of file SurfaceViewport.h.

00058       : Viewport()
00059       , mTracked(false)
00060    {;}

vrj::SurfaceViewport::~SurfaceViewport (  )  [virtual]

Definition at line 57 of file SurfaceViewport.cpp.

References vrj::Viewport::mLeftProj, and vrj::Viewport::mRightProj.

00058 {
00059    if ( NULL != mLeftProj )
00060    {
00061       delete mLeftProj;
00062       mLeftProj = NULL;
00063    }
00064 
00065    if ( NULL != mRightProj )
00066    {
00067       delete mRightProj;
00068       mRightProj = NULL;
00069    }
00070 }


Member Function Documentation

bool vrj::SurfaceViewport::config ( jccl::ConfigElementPtr  element  )  [virtual]

Takes a display element and configures the viewport based on it.

Precondition:
element is a valid configuration element.
Postcondition:
display is configured. If there is an error is the specified config, we output error and "fix" the error.
Note:
All derived display classes MUST call this function after doing local configuration.

Reimplemented from vrj::Viewport.

Definition at line 72 of file SurfaceViewport.cpp.

References vrj::Projection::config(), vrj::Viewport::config(), vrj::Projection::LEFT, vrj::Viewport::mLeftProj, mLLCorner, mLRCorner, vrj::Viewport::mRightProj, mTracked, mTrackerProxyName, vrj::Viewport::mType, mULCorner, mURCorner, vrj::Projection::RIGHT, vrj::Projection::setEye(), vrj::Projection::setViewport(), vrj::Viewport::SURFACE, vrj::SurfaceProjection::validateCorners(), vrjDBG_DISP_MGR(), and vrj::InvalidSurfaceException::what().

Referenced by vrj::Display::configViewports().

00073 {
00074    vprASSERT(element.get() != NULL);
00075    vprASSERT(element->getID() == "surface_viewport");
00076 
00077    // Call base class config
00078    if ( ! Viewport::config(element) )
00079    {
00080       return false;
00081    }
00082 
00083    bool result(true);
00084 
00085    mType = SURFACE;
00086 
00087    // Read in the corners
00088    mLLCorner.set(element->getProperty<float>("lower_left_corner", 0),
00089                  element->getProperty<float>("lower_left_corner", 1),
00090                  element->getProperty<float>("lower_left_corner", 2));
00091    mLRCorner.set(element->getProperty<float>("lower_right_corner", 0),
00092                  element->getProperty<float>("lower_right_corner", 1),
00093                  element->getProperty<float>("lower_right_corner", 2));
00094    mURCorner.set(element->getProperty<float>("upper_right_corner", 0),
00095                  element->getProperty<float>("upper_right_corner", 1),
00096                  element->getProperty<float>("upper_right_corner", 2));
00097    mULCorner.set(element->getProperty<float>("upper_left_corner", 0),
00098                  element->getProperty<float>("upper_left_corner", 1),
00099                  element->getProperty<float>("upper_left_corner", 2));
00100 
00101    // Calculate the rotation and the pts
00102 //   calculateSurfaceRotation();
00103 //   calculateCornersInBaseFrame();
00104 
00105    // Get info about being tracked
00106    mTracked = element->getProperty<bool>("tracked");
00107    if(mTracked)
00108    {
00109       mTrackerProxyName = element->getProperty<std::string>("tracker_proxy");
00110    }
00111 
00112    if ( NULL != mLeftProj )
00113    {
00114       delete mLeftProj;
00115    }
00116 
00117    if ( NULL != mRightProj )
00118    {
00119       delete mRightProj;
00120    }
00121 
00122    // Create Projection objects
00123    // NOTE: The -'s are because we are measuring distance to
00124    //  the left(bottom) which is opposite the normal axis direction
00125    //vjMatrix rot_inv;
00126    //rot_inv.invert(mSurfaceRotation);
00127    SurfaceProjection* left_proj(NULL);
00128    SurfaceProjection* right_proj(NULL);
00129 
00130    if(!mTracked)
00131    {
00132       left_proj = new SurfaceProjection(mLLCorner, mLRCorner, mURCorner,
00133                                         mULCorner);
00134       right_proj = new SurfaceProjection(mLLCorner, mLRCorner, mURCorner,
00135                                          mULCorner);
00136    }
00137    else
00138    {
00139       left_proj = new TrackedSurfaceProjection(mLLCorner, mLRCorner,
00140                                                mURCorner, mULCorner,
00141                                                mTrackerProxyName);
00142       right_proj = new TrackedSurfaceProjection(mLLCorner, mLRCorner,
00143                                                 mURCorner, mULCorner,
00144                                                 mTrackerProxyName);
00145    }
00146 
00147    try
00148    {
00149       left_proj->validateCorners();
00150       right_proj->validateCorners();
00151 
00152       // NOTE: Even if the corner validation above failed, we still proceed with
00153       // setting up mLeftProj and mRightProj. This is because other code is not
00154       // written to handle the case of a viewport having no projections. This
00155       // could definitely be improved.
00156       mLeftProj  = left_proj;
00157       mRightProj = right_proj;
00158 
00159       // Configure the projections
00160       mLeftProj->config(element);
00161       mLeftProj->setEye(Projection::LEFT);
00162       mLeftProj->setViewport(this);
00163 
00164       mRightProj->config(element);
00165       mRightProj->setEye(Projection::RIGHT);
00166       mRightProj->setViewport(this);
00167    }
00168    catch (InvalidSurfaceException& ex)
00169    {
00170       vprDEBUG(vrjDBG_DISP_MGR, vprDBG_CRITICAL_LVL)
00171          << clrOutBOLD(clrRED, "ERROR")
00172          << ": The surface defined by the viewport named\n" << vprDEBUG_FLUSH;
00173       vprDEBUG_NEXT(vrjDBG_DISP_MGR, vprDBG_CRITICAL_LVL)
00174          << "       '" << element->getName() << "' is invalid!\n"
00175          << vprDEBUG_FLUSH;
00176       vprDEBUG_NEXT(vrjDBG_DISP_MGR, vprDBG_CRITICAL_LVL)
00177          << ex.what() << std::endl << vprDEBUG_FLUSH;
00178 
00179       delete left_proj;
00180       delete right_proj;
00181 
00182       result = false;
00183    }
00184 
00185    return result;
00186 }

void vrj::SurfaceViewport::updateProjections ( const float  positionScale  )  [virtual]

Updates the projection data for this viewport.

This uses the data from the head position for this viewport.

Parameters:
positionScale Scale value for converting from Juggler units (meters) to the display units

Implements vrj::Viewport.

Definition at line 188 of file SurfaceViewport.cpp.

References vrj::Projection::calcViewMatrix(), vrj::User::getHeadPosProxy(), vrj::User::getInterocularDistance(), vrj::Viewport::mLeftProj, vrj::Viewport::mRightProj, and vrj::Viewport::mUser.

00189 {
00190    gmtl::Matrix44f left_eye_pos, right_eye_pos;     // NOTE: Eye coord system is -z forward, x-right, y-up
00191 
00192    // -- Calculate Eye Positions -- //
00193    gmtl::Matrix44f cur_head_pos = mUser->getHeadPosProxy()->getData(positionScale);
00194    /*
00195    Coord  head_coord(cur_head_pos);       // Create a user readable version
00196 
00197    vprDEBUG(vprDBG_ALL, vprDBG_HVERB_LVL)
00198       << "vjDisplay::updateProjections: Getting head position" << std::endl
00199       << vprDEBUG_FLUSH;
00200    vprDEBUG(vprDBG_ALL, vprDBG_HVERB_LVL) << "\tHeadPos:" << head_coord.pos << "\tHeadOr:"
00201                         << head_coord.orient << std::endl << vprDEBUG_FLUSH;
00202                         */
00203 
00204    // Compute location of left and right eyes
00205    //float interocularDist = 2.75f/12.0f;
00206    float interocular_dist = mUser->getInterocularDistance();
00207    interocular_dist *= positionScale;              // Scale eye separation
00208    float eye_offset = interocular_dist/2.0f;      // Distance to move eye
00209 
00210    left_eye_pos = cur_head_pos * gmtl::makeTrans<gmtl::Matrix44f>(gmtl::Vec3f( -eye_offset, 0, 0));
00211    right_eye_pos = cur_head_pos * gmtl::makeTrans<gmtl::Matrix44f>(gmtl::Vec3f(eye_offset, 0, 0));
00212 
00213    mLeftProj->calcViewMatrix(left_eye_pos, positionScale);
00214    mRightProj->calcViewMatrix(right_eye_pos, positionScale);
00215 }

void vrj::SurfaceViewport::getCorners ( gmtl::Point3f &  ll,
gmtl::Point3f &  lr,
gmtl::Point3f &  ur,
gmtl::Point3f &  ul 
) [inline]

Definition at line 80 of file SurfaceViewport.h.

References mLLCorner, mLRCorner, mULCorner, and mURCorner.

00082    {
00083       ll = mLLCorner; lr = mLRCorner; ur = mURCorner; ul = mULCorner;
00084    }

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

Reimplemented from vrj::Viewport.

Definition at line 217 of file SurfaceViewport.cpp.

References vrj::Viewport::LEFT_EYE, vrj::Viewport::mLeftProj, vrj::Viewport::mRightProj, vrj::Viewport::mView, vrj::Projection::outStream(), vrj::Viewport::outStream(), vrj::Viewport::RIGHT_EYE, and vrj::Viewport::STEREO.

00219 {
00220    Viewport::outStream(out, indentLevel);
00221    out << std::endl;
00222 
00223    const std::string indent_text(indentLevel, ' ');
00224 
00225    /*
00226    out << "LL: " << mLLCorner << ", LR: " << mLRCorner
00227        << ", UR: " << mURCorner << ", UL:" << mULCorner << std::endl;
00228    out << "surfRot: \n" << mSurfaceRotation << std::endl;
00229    */
00230    if ( mView == vrj::Viewport::LEFT_EYE || mView == vrj::Viewport::STEREO )
00231    {
00232       out << indent_text << "Left projection:\n";
00233       mLeftProj->outStream(out, indentLevel + 2);
00234       out << std::endl;
00235    }
00236    if ( mView == vrj::Viewport::RIGHT_EYE || mView == vrj::Viewport::STEREO )
00237    {
00238       out << indent_text << "Right projection:\n";
00239       mRightProj->outStream(out, indentLevel + 2);
00240       out << std::endl;
00241    }
00242 
00243    return out;
00244 }


Member Data Documentation

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

Definition at line 92 of file SurfaceViewport.h.

Referenced by config(), and getCorners().

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

Definition at line 93 of file SurfaceViewport.h.

Referenced by config(), and getCorners().

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

Definition at line 94 of file SurfaceViewport.h.

Referenced by config(), and getCorners().

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

Definition at line 95 of file SurfaceViewport.h.

Referenced by config(), and getCorners().

bool vrj::SurfaceViewport::mTracked [protected]

Is this surface tracked?

Definition at line 103 of file SurfaceViewport.h.

Referenced by config().

std::string vrj::SurfaceViewport::mTrackerProxyName [protected]

If tracked, what is the name of the tracker.

Definition at line 104 of file SurfaceViewport.h.

Referenced by config().


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