Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Display.cpp

Go to the documentation of this file.
00001 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00002  *
00003  * VR Juggler is (C) Copyright 1998-2003 by Iowa State University
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Christopher Just,
00007  *   Patrick Hartling, Kevin Meinert,
00008  *   Carolina Cruz-Neira, Albert Baker
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Library General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public
00021  * License along with this library; if not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023  * Boston, MA 02111-1307, USA.
00024  *
00025  * -----------------------------------------------------------------
00026  * File:          $RCSfile: Display.cpp,v $
00027  * Date modified: $Date: 2003/10/06 19:28:33 $
00028  * Version:       $Revision: 1.62 $
00029  * -----------------------------------------------------------------
00030  *
00031  *************** <auto-copyright.pl END do not edit this line> ***************/
00032 
00033 #include <vrj/vrjConfig.h>
00034 
00035 #include <jccl/Config/ConfigElement.h>
00036 #include <vrj/Display/Display.h>
00037 #include <vrj/Display/Viewport.h>
00038 #include <vrj/Display/SimViewport.h>
00039 #include <vrj/Display/SurfaceViewport.h>
00040 
00041 namespace vrj
00042 {
00043 
00044 void Display::updateProjections(const float positionScale)
00045 {
00046    for(unsigned i=0;i<mViewports.size();i++)
00047    {
00048       mViewports[i]->updateProjections(positionScale);
00049    }
00050 }
00051 
00052 
00053 void Display::setOriginAndSize(int xo, int yo, int xs, int ys, bool updateConfig)
00054 { 
00055    _xo = xo; _yo = yo; _xs = xs; _ys = ys;
00056    if(updateConfig)
00057    {
00058       mDisplayElement->setProperty<int>("origin", 0, xo);
00059       mDisplayElement->setProperty<int>("origin", 1, yo);
00060       mDisplayElement->setProperty<int>("size", 0, xs);
00061       mDisplayElement->setProperty<int>("size", 1, ys);
00062    }
00063 }
00064 
00065 
00066 void Display::config(jccl::ConfigElementPtr element)
00067 {
00068    vprASSERT(element.get() != NULL);
00069 
00070    configDisplayWindow(element);
00071    configViewports(element);
00072 }
00073 
00074 void Display::configDisplayWindow(jccl::ConfigElementPtr element)
00075 {
00076    vprASSERT(element.get() != NULL);
00077 
00078    // -- Get config info from element -- //
00079    int originX      = element->getProperty<int>("origin", 0);
00080    int originY      = element->getProperty<int>("origin", 1);
00081    int sizeX        = element->getProperty<int>("size", 0);
00082    int sizeY        = element->getProperty<int>("size", 1);
00083    std::string name = element->getName();
00084    mBorder          = element->getProperty<bool>("border");
00085    int pipe         = element->getProperty<int>("pipe");
00086    mActive          = element->getProperty<bool>("active");
00087    mStereoRequested = element->getProperty<bool>("stereo");
00088 
00089    // -- Check for error in configuration -- //
00090    // NOTE: If there are errors, set them to some default value
00091    if(sizeX <= 0)
00092    {
00093       vprDEBUG(vrjDBG_DISP_MGR, vprDBG_WARNING_LVL)
00094          << "WARNING: window sizeX set to: " << sizeX
00095          << ".  Setting to 10." << std::endl << vprDEBUG_FLUSH;
00096       sizeX = 10;
00097    }
00098 
00099    if(sizeY <= 0)
00100    {
00101       vprDEBUG(vrjDBG_DISP_MGR, vprDBG_WARNING_LVL)
00102          << "WARNING: window sizeY set to: " << sizeY
00103          << ".  Setting to 10." << std::endl << vprDEBUG_FLUSH;
00104       sizeY = 10;
00105    }
00106 
00107    if(pipe < 0)
00108    {
00109       vprDEBUG(vrjDBG_DISP_MGR, vprDBG_WARNING_LVL)
00110          << "WARNING: pipe was negative, pipe set to: " << pipe
00111          << ".  Setting to 0.\n" << vprDEBUG_FLUSH;
00112       pipe = 0;
00113    }
00114 
00115       // -- Set local window attributes --- //
00116     setOriginAndSize(originX, originY, sizeX, sizeY);
00117 
00118     setName(name);
00119     setPipe(pipe);
00120 
00121     mDisplayElement = element;        // Save the element for later use
00122 }
00123 
00124 void Display::configViewports(jccl::ConfigElementPtr element)
00125 {
00126    vprASSERT(element.get() != NULL);
00127 
00128    unsigned num_sim_vps = element->getNum("simulator_viewports");
00129    unsigned num_surface_vps = element->getNum("surface_viewports");
00130 
00131    jccl::ConfigElementPtr vp_elt;
00132    SimViewport* sim_vp = NULL;
00133    SurfaceViewport* surf_vp = NULL;
00134 
00135    unsigned i(0);
00136 
00137    // Create sim viewports
00138    // - Set the parent display
00139    // - Configure it
00140    for(i=0;i<num_sim_vps;i++)
00141    {
00142       vp_elt = element->getProperty<jccl::ConfigElementPtr>("simulator_viewports",i);
00143       sim_vp = new SimViewport;
00144       sim_vp->setDisplay(this);
00145       sim_vp->config(vp_elt);
00146       mViewports.push_back(sim_vp);
00147    }
00148 
00149    // Create surface viewports
00150    // - Set the parent display
00151    // - Configure it
00152    for(i=0;i<num_surface_vps;i++)
00153    {
00154       vp_elt = element->getProperty<jccl::ConfigElementPtr>("surface_viewports",i);
00155       surf_vp = new SurfaceViewport;
00156       surf_vp->setDisplay(this);
00157       surf_vp->config(vp_elt);
00158       mViewports.push_back(surf_vp);
00159    }
00160 }
00161 
00162 jccl::ConfigElementPtr Display::getGlFrameBufferConfig()
00163 {
00164    jccl::ConfigElementPtr element;
00165 
00166    // XXX: Refactor this to allow different frame buffer child elements.  Right
00167    // now, this assumes that the child element type is OpenGLFBConfig.
00168    if ( mDisplayElement->getNum("frame_buffer_config") == 1 )
00169    {
00170       element =
00171          mDisplayElement->getProperty<jccl::ConfigElementPtr>("frame_buffer_config");
00172    }
00173 
00174    return element;
00175 }
00176 
00177 std::ostream& operator<<(std::ostream& out, Display& disp)
00178 {
00179    out.setf(std::ios::left);
00180 
00181    char fill_char(out.fill());
00182    out.fill('.');
00183 
00184    const unsigned int indent_level(2);
00185    const std::string indent_text(indent_level, ' ');
00186    const int pad_width_dot(20 - indent_level);
00187 
00188    out << indent_text << std::setw(pad_width_dot)
00189        << "Name " << " " << disp.mName.c_str() << std::endl;
00190    out << indent_text << std::setw(pad_width_dot)
00191        << "Origin " << " " << disp._xo << ", " << disp._yo << std::endl;
00192    out << indent_text << std::setw(pad_width_dot)
00193        << "Size " << " " << disp._xs << "x" << disp._ys << std::endl;
00194    out << indent_text << std::setw(pad_width_dot)
00195        << "Pipe number " << " " << disp.mPipe << std::endl;
00196    out << indent_text << std::setw(pad_width_dot)
00197        << "Stereo requested " << " " << (disp.mStereoRequested ? "Yes" : "No")
00198        << std::endl;
00199    out << indent_text << std::setw(pad_width_dot)
00200        << "Active " << " " << (disp.mActive ? "Yes" : "No") << std::endl;
00201 
00202    for(unsigned i=0;i<disp.mViewports.size();i++)
00203    {
00204       out << indent_text << "Viewport " << i << ":\n";
00205       disp.mViewports[i]->outStream(out, 4);
00206    }
00207 
00208    // Restore the previous state.
00209    out.fill(fill_char);
00210 
00211    return out;
00212 }
00213 
00214 }

Generated on Sun May 2 15:10:16 2004 for VR Juggler by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002