Equalizer  1.2.1
eVolve.cpp
00001 
00002 /* Copyright (c) 2005-2010, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *
00007  * - Redistributions of source code must retain the above copyright notice, this
00008  *   list of conditions and the following disclaimer.
00009  * - Redistributions in binary form must reproduce the above copyright notice,
00010  *   this list of conditions and the following disclaimer in the documentation
00011  *   and/or other materials provided with the distribution.
00012  * - Neither the name of Eyescale Software GmbH nor the names of its
00013  *   contributors may be used to endorse or promote products derived from this
00014  *   software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026  * POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #include "eVolve.h"
00030 
00031 #include "config.h"
00032 #include "localInitData.h"
00033 
00034 #include <stdlib.h>
00035 
00036 namespace eVolve
00037 {
00038 
00039 static const std::string _help(
00040     std::string( "eVolve - Equalizer volume rendering example\n" ) +
00041     std::string( "\tRun-time commands:\n" ) +
00042     std::string( "\t\tLeft Mouse Button:         Rotate model\n" ) +
00043     std::string( "\t\tMiddle Mouse Button:       Move model in X, Y\n" ) +
00044     std::string( "\t\tRight Mouse Button:        Move model in Z\n" ) +
00045     std::string( "\t\t<Esc>, All Mouse Buttons:  Exit program\n" ) +
00046     std::string( "\t\t<Space>, r:                Reset camera\n" ) +
00047     std::string( "\t\td:                         Toggle demo color mode\n" ) +
00048     std::string( "\t\tb:                         Toggle background color\n" ) +
00049     std::string( "\t\tn:                         Toggle normals Quality mode (raw data only)\n" ) +
00050     std::string( "\t\to:                         Toggle " ) +
00051     std::string( "perspective/orthographic\n" ) +
00052     std::string( "\t\ts:                         Toggle statistics " ) +
00053     std::string( "overlay\n" ) +
00054     std::string( "\t\tl:                         Switch layout for active canvas\n")+
00055     std::string( "\t\tF1, h:                     Toggle help overlay\n" )
00056  );
00057 
00058 const std::string& EVolve::getHelp()
00059 {
00060     return _help;
00061 }
00062 
00063 EVolve::EVolve( const LocalInitData& initData )
00064         : _initData( initData )
00065 {}
00066 
00067 int EVolve::run()
00068 {
00069     // 1. connect to server
00070     eq::ServerPtr server = new eq::Server;
00071     if( !connectServer( server ))
00072     {
00073         EQERROR << "Can't open server" << std::endl;
00074         return EXIT_FAILURE;
00075     }
00076 
00077     // 2. choose config
00078     eq::ConfigParams configParams;
00079     Config* config = static_cast<Config*>(server->chooseConfig( configParams ));
00080 
00081     if( !config )
00082     {
00083         EQERROR << "No matching config on server" << std::endl;
00084         disconnectServer( server );
00085         return EXIT_FAILURE;
00086     }
00087 
00088     // 3. init config
00089     co::base::Clock clock;
00090 
00091     config->setInitData( _initData );
00092     if( !config->init( ))
00093     {
00094         server->releaseConfig( config );
00095         disconnectServer( server );
00096         return EXIT_FAILURE;
00097     }
00098     else if( config->getError( ))
00099         EQWARN << "Error during initialization: " << config->getError()
00100                << std::endl;
00101 
00102     EQLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms"
00103                        << std::endl;
00104 
00105     // 4. run main loop
00106     uint32_t maxFrames = _initData.getMaxFrames();
00107     
00108     clock.reset();
00109     while( config->isRunning( ) && maxFrames-- )
00110     {
00111         config->startFrame();
00112         if( config->getError( ))
00113             EQWARN << "Error during frame start: " << config->getError()
00114                    << std::endl;
00115         config->finishFrame();
00116     }
00117     const uint32_t frame = config->finishAllFrames();
00118     const float    time  = clock.getTimef();
00119     EQLOG( LOG_STATS ) << "Rendering took " << time << " ms (" << frame
00120                        << " frames @ " << ( frame / time * 1000.f) << " FPS)"
00121                        << std::endl;
00122 
00123     // 5. exit config
00124     clock.reset();
00125     config->exit();
00126     EQLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<std::endl;
00127 
00128     // 6. cleanup and exit
00129     server->releaseConfig( config );
00130     if( !disconnectServer( server ))
00131         EQERROR << "Client::disconnectServer failed" << std::endl;
00132     server = 0;
00133 
00134     return EXIT_SUCCESS;
00135 }
00136 
00137 void EVolve::clientLoop()
00138 {
00139     do
00140     {
00141          eq::Client::clientLoop();
00142          EQINFO << "Configuration run successfully executed" << std::endl;
00143     }
00144     while( _initData.isResident( )); // execute at lease one config run
00145 }
00146 }
Generated on Fri Jun 8 2012 15:44:30 for Equalizer 1.2.1 by  doxygen 1.8.0