Equalizer  1.6.1
eqPly/localInitData.cpp
1 
2 /* Copyright (c) 2007-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * - Neither the name of Eyescale Software GmbH nor the names of its
13  * contributors may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "localInitData.h"
30 #include "frameData.h"
31 
32 #include <algorithm>
33 #include <cctype>
34 #include <functional>
35 
36 #ifndef MIN
37 # define MIN LB_MIN
38 #endif
39 #include <tclap/CmdLine.h>
40 
41 namespace eqPly
42 {
43 LocalInitData::LocalInitData()
44  : _maxFrames( 0xffffffffu )
45  , _color( true )
46  , _isResident( false )
47 {
48 #ifdef EQ_RELEASE
49 # ifdef _WIN32 // final INSTALL_DIR is not known at compile time
50  _filenames.push_back( "../share/Equalizer/data" );
51 # else
52  _filenames.push_back( std::string( EQ_INSTALL_DIR ) +
53  std::string( "share/Equalizer/data" ));
54  _filenames.push_back( std::string( "/usr/share/Equalizer/data" ));
55 # endif
56 #else
57  _filenames.push_back( std::string( EQ_SOURCE_DIR ) +
58  std::string( "examples/eqPly" ));
59 #endif
60 }
61 
62 const LocalInitData& LocalInitData::operator = ( const LocalInitData& from )
63 {
64  _maxFrames = from._maxFrames;
65  _color = from._color;
66  _isResident = from._isResident;
67  _filenames = from._filenames;
68  _pathFilename = from._pathFilename;
69 
70  setWindowSystem( from.getWindowSystem( ));
71  setRenderMode( from.getRenderMode( ));
72  if( from.useGLSL( ))
73  enableGLSL();
74  if( from.useInvertedFaces( ))
75  enableInvertedFaces();
76  if( !from.showLogo( ))
77  disableLogo();
78  if( !from.useROI( ))
79  disableROI();
80 
81  return *this;
82 }
83 
84 void LocalInitData::parseArguments( const int argc, char** argv )
85 {
86  try
87  {
88  std::string wsHelp = "Window System API ( one of: ";
89 #ifdef AGL
90  wsHelp += "AGL ";
91 #endif
92 #ifdef GLX
93  wsHelp += "glX ";
94 #endif
95 #ifdef WGL
96  wsHelp += "WGL ";
97 #endif
98  wsHelp += ")";
99 
100  const std::string& desc = EqPly::getHelp();
101 
102  TCLAP::CmdLine command( desc, ' ', eq::Version::getString( ));
103  TCLAP::MultiArg<std::string> modelArg( "m", "model",
104  "ply model file name or directory",
105  false, "string", command );
106  TCLAP::SwitchArg colorArg( "b", "blackAndWhite",
107  "Don't use colors from ply file",
108  command, false );
109  TCLAP::SwitchArg residentArg( "r", "resident",
110  "Keep client resident (see resident node documentation on website)",
111  command, false );
112  TCLAP::ValueArg<uint32_t> framesArg( "n", "numFrames",
113  "Maximum number of rendered frames",
114  false, 0xffffffffu, "unsigned",
115  command );
116  TCLAP::ValueArg<std::string> wsArg( "w", "windowSystem", wsHelp,
117  false, "auto", "string", command );
118  TCLAP::ValueArg<std::string> modeArg( "c", "renderMode",
119  "Rendering Mode (immediate, displayList, VBO)",
120  false, "auto", "string",
121  command );
122  TCLAP::SwitchArg glslArg( "g", "glsl", "Enable GLSL shaders",
123  command, false );
124  TCLAP::SwitchArg invFacesArg( "i", "invertFaces",
125  "Invert faces (valid during binary file creation)",
126  command, false );
127  TCLAP::ValueArg<std::string> pathArg( "a", "cameraPath",
128  "File containing camera path animation",
129  false, "", "string", command );
130  TCLAP::SwitchArg overlayArg( "o", "noOverlay", "Disable overlay logo",
131  command, false );
132  TCLAP::UnlabeledMultiArg< std::string >
133  ignoreArgs( "ignore", "Ignored unlabeled arguments", false, "any",
134  command );
135  TCLAP::SwitchArg roiArg( "d", "disableROI", "Disable ROI", command,
136  false );
137 
138 #ifdef TCPLAP_HAS_IGNOREUNMATCHED
139  command.ignoreUnmatched( true );
140 #endif
141  command.parse( argc, argv );
142 
143  if( modelArg.isSet( ))
144  {
145  _filenames.clear();
146  _filenames = modelArg.getValue();
147  }
148  if( wsArg.isSet( ))
149  {
150  std::string windowSystem = wsArg.getValue();
151  transform( windowSystem.begin(), windowSystem.end(),
152  windowSystem.begin(), (int(*)(int))std::toupper );
153 
154  setWindowSystem( windowSystem );
155  }
156 
157  _color = !colorArg.isSet();
158 
159  if( framesArg.isSet( ))
160  _maxFrames = framesArg.getValue();
161 
162  if( residentArg.isSet( ))
163  _isResident = true;
164 
165  if( modeArg.isSet() )
166  {
167  std::string mode = modeArg.getValue();
168  transform( mode.begin(), mode.end(), mode.begin(),
169  (int(*)(int))std::tolower );
170 
171  if( mode == "immediate" )
172  setRenderMode( mesh::RENDER_MODE_IMMEDIATE );
173  else if( mode == "displaylist" )
174  setRenderMode( mesh::RENDER_MODE_DISPLAY_LIST );
175  else if( mode == "vbo" )
176  setRenderMode( mesh::RENDER_MODE_BUFFER_OBJECT );
177  }
178 
179  if( pathArg.isSet( ))
180  _pathFilename = pathArg.getValue();
181 
182  if( glslArg.isSet() )
183  enableGLSL();
184  if( invFacesArg.isSet() )
185  enableInvertedFaces();
186  if( overlayArg.isSet( ))
187  disableLogo();
188  if( roiArg.isSet( ))
189  disableROI();
190  }
191  catch( const TCLAP::ArgException& exception )
192  {
193  LBERROR << "Command line parse error: " << exception.error()
194  << " for argument " << exception.argId() << std::endl;
195  ::exit( EXIT_FAILURE );
196  }
197 }
198 }
static std::string getString()
bool exit()
De-initialize the Equalizer fabric namespace.