Equalizer  1.2.1
seqPly.cpp
00001 
00002 /* Copyright (c) 2011, Stefan Eilemann <eile@eyescale.ch> 
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 "seqPly.h"
00030 
00031 #include "renderer.h"
00032 
00033 #ifndef MIN
00034 #  define MIN EQ_MIN
00035 #endif
00036 #include <tclap/CmdLine.h>
00037 
00038 namespace seqPly
00039 {
00040 
00041 bool Application::init( const int argc, char** argv )
00042 {
00043     if( !seq::Application::init( argc, argv, 0 ))
00044         return false;
00045 
00046     _loadModel( argc, argv );
00047     return true;
00048 }
00049 
00050 bool Application::run()
00051 {
00052     return seq::Application::run( &_frameData );
00053 }
00054 
00055 bool Application::exit()
00056 {
00057     _unloadModel();
00058     return seq::Application::exit();
00059 }
00060 
00061 co::Object* Application::createObject( const uint32_t type )
00062 {
00063 //    switch( type )
00064     {
00065 //      default:
00066           EQUNIMPLEMENTED;
00067           return 0;
00068     }
00069 }
00070 
00071 seq::Renderer* Application::createRenderer()
00072 {
00073     return new Renderer( *this );
00074 }
00075 
00076 namespace
00077 {
00078 static bool _isPlyfile( const std::string& filename )
00079 {
00080     const size_t size = filename.length();
00081     if( size < 5 )
00082         return false;
00083 
00084     if( filename[size-4] != '.' || filename[size-3] != 'p' ||
00085         filename[size-2] != 'l' || filename[size-1] != 'y' )
00086     {
00087         return false;
00088     }
00089     return true;
00090 }
00091 }
00092 
00093 void Application::_loadModel( const int argc, char** argv )
00094 {
00095     TCLAP::CmdLine command( "seqPly - Sequel polygonal rendering example" );
00096     TCLAP::ValueArg<std::string> modelArg( "m", "model", "ply model file name",
00097                                            false, "", "string", command );
00098     TCLAP::VariableSwitchArg ignoreEqArgs( "eq", "Ignored Equalizer options",
00099                                            command );
00100     TCLAP::UnlabeledMultiArg< std::string > 
00101         ignoreArgs( "ignore", "Ignored unlabeled arguments", false, "any",
00102                     command );
00103     command.parse( argc, argv );
00104 
00105     eq::Strings filenames;
00106 #ifdef EQ_RELEASE
00107 #  ifdef _WIN32 // final INSTALL_DIR is not known at compile time
00108     filenames.push_back( "../share/Equalizer/data" );
00109 #  else
00110     filenames.push_back( std::string( EQ_INSTALL_DIR ) +
00111                          std::string( "share/Equalizer/data" ));
00112 #  endif
00113 #else
00114     filenames.push_back( std::string( EQ_SOURCE_DIR ) + 
00115                          std::string( "examples/eqPly" ));
00116 #endif
00117 
00118     if( modelArg.isSet( ))
00119         filenames.push_back( modelArg.getValue( ));
00120 
00121     while( !filenames.empty( ))
00122     {
00123         const std::string filename = filenames.back();
00124         filenames.pop_back();
00125      
00126         if( _isPlyfile( filename ))
00127         {
00128             _model = new Model;
00129             if( _model->readFromFile( filename.c_str( )))
00130             {
00131                 _modelDist = new ModelDist( _model );
00132                 _modelDist->registerTree( this );
00133                 _frameData.setModelID( _modelDist->getID( ));
00134                 return;
00135             }
00136             delete _model;
00137             _model = 0;
00138         }
00139         else
00140         {
00141             const std::string basename = co::base::getFilename( filename );
00142             if( basename == "." || basename == ".." )
00143                 continue;
00144 
00145             // recursively search directories
00146             const eq::Strings subFiles = co::base::searchDirectory( filename,
00147                                                                     "*" );
00148 
00149             for(eq::StringsCIter i = subFiles.begin(); i != subFiles.end(); ++i)
00150                 filenames.push_back( filename + '/' + *i );
00151         }
00152     }
00153 }
00154 
00155 void Application::_unloadModel()
00156 {
00157     if( !_modelDist )
00158         return;
00159 
00160     _modelDist->deregisterTree();
00161     delete _modelDist;
00162     _modelDist = 0;
00163 
00164     delete _model;
00165     _model = 0;
00166 }
00167 
00168 const Model* Application::getModel( const eq::uint128_t& modelID )
00169 {
00170     if( modelID == eq::UUID::ZERO )
00171         return 0;
00172     if( _model )
00173         return _model;
00174     co::base::memoryBarrier();
00175 
00176     // Accessed concurrently from render threads
00177     co::base::ScopedMutex<> mutex( _modelLock );
00178 
00179     EQASSERT( !_modelDist );
00180     _modelDist = new ModelDist;
00181     Model* model = _modelDist->mapModel( this, modelID );
00182     EQASSERT( model );
00183     _model = model;
00184 
00185     return model;
00186 }
00187 
00188 
00189 }
00190 
Generated on Fri Jun 8 2012 15:44:32 for Equalizer 1.2.1 by  doxygen 1.8.0