int main( int argc, char** argv ) { namespace bpo = boost::program_options; try { std::string configFile ; std::string omsEclSettings; try { // only command-line options bpo::options_description genericOptions("Generic options"); genericOptions.add_options() ("version,v", "print version string") ("help,h", "produce help message") ("config,c", bpo::value<std::string>(&configFile)->default_value("utrade.conf"), "configuration file.") ; // both on command line and config file options bpo::options_description configFileOptions( "Configuration" ) ; configFileOptions.add_options() ("OMS.ecl_settings", bpo::value<std::string>(&omsEclSettings) ->default_value("oms-ecl-settings"), "OMS-ECL QuickFIX settings file") ; bpo::options_description cmdLineOptions; cmdLineOptions.add(genericOptions).add(configFileOptions); bpo::variables_map vm; store(bpo::command_line_parser(argc, argv). options(cmdLineOptions).run(), vm); notify(vm); std::ifstream ifs(configFile.c_str()); if (ifs) { store(parse_config_file(ifs, configFileOptions, true), vm); notify(vm); } else { std::cout << "Unable to open file: " << configFile << "\n" << std::endl ; return 1 ; } if (vm.count("help")) { std::cout << cmdLineOptions << "\n"; return 0; } if (vm.count("version")) { std::cout << "uTrade OMS version " VERSION_STRING "\n"; return 0; } bool validationSuccessful = true ; const std::vector< boost::shared_ptr<bpo::option_description> >& myoptions = configFileOptions.options() ; for( int i = myoptions.size() - 1; i >= 0 ; i-- ) { if( vm.count( myoptions[ i ]->long_name() ) == 0 ) { ERROR_3( CONFIG_ERROR_KEY_MISSING, configFile, "ECL_TEST", myoptions[ i ]->long_name() ) ; validationSuccessful = false ; } } if( !validationSuccessful ) { std::cout << "\n\nPress any key to exit ... " << std::endl ; std::cin.get() ; return 1 ; } } catch(boost::program_options::error &e) { std::cout << "Bad Options: " << e.what() << std::endl; return 1; } catch(std::exception& e) { std::cout << "Error when configuring : " << e.what() << std::endl ; return 1; } std::string command( "" ) ; while ( command != "0" ) { std::cout << "\nOptions are : \n" << " 1. Place Orders\n" << " 2. Round Trip Time \n" << " 0. Exit " << std::endl; getline( std::cin, command ) ; if( command == "1" ) { UT::ECL::TESTS::PlaceOrder p( omsEclSettings ) ; } else if( command == "2" ) { UT::ECL::TESTS::RoundTripTime rtt( omsEclSettings ) ; } } } catch( std::exception &e ) { std::cout << "Error : " << e.what() << std::endl ; return 1; } return 0; }
int GenericCLIInterface(int argc, char** argv, boost::shared_ptr<ElVis::Scene> scene, boost::shared_ptr<ElVis::Model> model, boost::shared_ptr<ElVis::ColorMap> colorMap, unsigned int width, unsigned int height, const std::string& outFilePath, const ElVis::Camera& c) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize(100, 100); glutCreateWindow("fake"); std::cout << "Generic CLI Interface." << std::endl; const char* isovaluesLabel = "Isovalues"; const char* isosurfaceModuleEnabledLabel = "IsosurfaceModuleEnabled"; const char* volumeRenderingModuleEnabledLabel = "VolumeRenderingModuleEnabled"; const char* contourModuleEnabledLabel = "ContourModuleEnabled"; const char* meshModuleEnabledLabel = "MeshModuleEnabled"; const char* boundarySurfacesLabel = "BoundarySurfaces"; // Volume Rendering labels const char* integrationTypeLabel = "IntegrationType"; const char* breakpointLabel = "Breakpoints"; const char* colorsLabel = "Colors"; const char* hLabel = "h"; const char* epsilonLabel = "Epsilon"; const char* traceLabel = "EnableTrace"; const char* traceXLabel = "TraceX"; const char* traceYLabel = "TraceY"; const char* trackNumSamplesLabel = "TrackNumSamples"; const char* renderIntegrationTypeLabel = "RenderIntegrationType"; const char* emptySpaceSkippingLabel = "EnableEmptySpaceSkipping"; const char* cutPlaneNormalLabel = "CutPlaneNormal"; const char* cutPlanePointLabel= "CutPlanePoint"; const char* fieldLabel="Field"; const char* numTestsLabel = "NumTests"; std::vector<double> cutPlaneNormal; std::vector<double> cutPlanePoint; std::vector<double> breakpoints; std::vector<double> colors; std::vector<int> boundarySurfaces; std::vector<double> isovalues; bool isosurfaceModuleEnabled = false; bool volumeRenderingModuleEnabled = false; bool contourModuleEnabled = false; bool meshModuleEnabled = false; unsigned int numTests = 1; std::string configFile; int fieldIndex = 0; boost::program_options::options_description desc("GenericCLIOptions"); desc.add_options() (isovaluesLabel, boost::program_options::value<std::vector<double> >(&isovalues)->multitoken(), "Isovalues") (boundarySurfacesLabel, boost::program_options::value<std::vector<int> >(&boundarySurfaces)->multitoken(), "Boundary Surfaces") (isosurfaceModuleEnabledLabel, boost::program_options::value<bool>(&isosurfaceModuleEnabled), "Isosurface Module Enabled") (volumeRenderingModuleEnabledLabel, boost::program_options::value<bool>(&volumeRenderingModuleEnabled), "Volume Rendering Module Enabled") (contourModuleEnabledLabel, boost::program_options::value<bool>(&contourModuleEnabled), "Contour Module Enabled") (meshModuleEnabledLabel, boost::program_options::value<bool>(&meshModuleEnabled), "Mesh Module Enabled") (integrationTypeLabel, boost::program_options::value<int>(), "Integration Type") (breakpointLabel, boost::program_options::value<std::vector<double> >(&breakpoints)->multitoken(), "Breakpoints") (colorsLabel, boost::program_options::value<std::vector<double> >(&colors)->multitoken(), "Colors") (hLabel, boost::program_options::value<double>(), "h") (epsilonLabel, boost::program_options::value<double>(), "Epsilon") (traceLabel, boost::program_options::value<int>(), "Enable Trace") (traceXLabel, boost::program_options::value<int>(), "Trace X") (traceYLabel, boost::program_options::value<int>(), "Trace Y") (trackNumSamplesLabel, boost::program_options::value<int>(), "Track Num Samples") (renderIntegrationTypeLabel, boost::program_options::value<int>(), "RenderIntegrationType") (emptySpaceSkippingLabel, boost::program_options::value<int>(), "EnableEmptySpaceSkipping") (numTestsLabel, boost::program_options::value<unsigned int>(&numTests), "Number of Tests") (cutPlaneNormalLabel, boost::program_options::value<std::vector<double> >(&cutPlaneNormal)->multitoken(), "Cut Plane Normal") (cutPlanePointLabel, boost::program_options::value<std::vector<double> >(&cutPlanePoint)->multitoken(), "Cut Plane Point") (fieldLabel, boost::program_options::value<int>(&fieldIndex), "Field Index") ; const char* configFileNameLabel = "ConfigFile"; boost::program_options::options_description configFileOptions("ConfigFileOptions"); configFileOptions.add_options() (configFileNameLabel, boost::program_options::value<std::string>(&configFile), "Config File") ; boost::program_options::options_description commandLineOptions("CommandLineOptions"); commandLineOptions.add(desc).add(configFileOptions); boost::program_options::variables_map vm; boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(commandLineOptions).style(boost::program_options::command_line_style::allow_long | boost::program_options::command_line_style::long_allow_adjacent).allow_unregistered().run(), vm); boost::program_options::notify(vm); if( !configFile.empty() ) { std::ifstream inFile(configFile.c_str()); if( inFile ) { boost::program_options::store(boost::program_options::parse_config_file(inFile, desc, true), vm); boost::program_options::notify(vm); } inFile.close(); } #ifdef __GNUC__ system("nvidia-smi"); #endif ElVis::PointLight* l = new ElVis::PointLight(); ElVis::Color lightColor; lightColor.SetRed(.5); lightColor.SetGreen(.5); lightColor.SetBlue(.5); ElVis::WorldPoint lightPos(10.0, 0.0, 0.0); l->SetColor(lightColor); l->SetPosition(lightPos); scene->AddLight(l); ElVis::Color ambientColor; ambientColor.SetRed(.5); ambientColor.SetGreen(.5); ambientColor.SetBlue(.5); scene->SetAmbientLightColor(ambientColor); boost::shared_ptr<ElVis::SceneView> view(new ElVis::SceneView()); view->SetCamera(c); view->SetScalarFieldIndex(fieldIndex); boost::shared_ptr<ElVis::PrimaryRayModule> primaryRayModule(new ElVis::PrimaryRayModule()); view->AddRenderModule(primaryRayModule); if( cutPlaneNormal.size() == 3 && cutPlanePoint.size() == 3 ) { ElVis::WorldPoint normal(cutPlaneNormal[0], cutPlaneNormal[1], cutPlaneNormal[2]); ElVis::WorldPoint p(cutPlanePoint[0], cutPlanePoint[1], cutPlanePoint[2]); boost::shared_ptr<ElVis::Plane> cutPlane(new ElVis::Plane(normal, p)); boost::shared_ptr<ElVis::SampleVolumeSamplerObject> sampler(new ElVis::SampleVolumeSamplerObject(cutPlane)); primaryRayModule->AddObject(sampler); } if( contourModuleEnabled ) { std::cout << "Contour Module enabled. Number of isovalues = " << isovalues.size() << std::endl; boost::shared_ptr<ElVis::CutSurfaceContourModule> contourModule(new ElVis::CutSurfaceContourModule()); view->AddRenderModule(contourModule); for(unsigned int i = 0; i < isovalues.size(); ++i) { contourModule->AddIsovalue(isovalues[i]); } } if( meshModuleEnabled ) { boost::shared_ptr<ElVis::CutSurfaceMeshModule> meshModule(new ElVis::CutSurfaceMeshModule()); view->AddRenderModule(meshModule); } if( isosurfaceModuleEnabled ) { boost::shared_ptr<ElVis::IsosurfaceModule> isosurfaceModule(new ElVis::IsosurfaceModule()); view->AddRenderModule(isosurfaceModule); for(unsigned int i = 0; i < isovalues.size(); ++i) { isosurfaceModule->AddIsovalue(isovalues[i]); } } boost::shared_ptr<ElVis::ColorMapperModule> colorMapperModule(new ElVis::ColorMapperModule()); view->AddRenderModule(colorMapperModule); colorMapperModule->SetColorMap(colorMap); if( boundarySurfaces.size() > 0) { boost::shared_ptr<ElVis::FaceObject> faceObject(new ElVis::FaceObject(scene)); boost::shared_ptr<ElVis::SampleFaceObject> obj(new ElVis::SampleFaceObject(faceObject)); primaryRayModule->AddObject(obj); for(int i = 0; i < boundarySurfaces.size(); ++i) { std::vector<int> faceIds; std::string boundaryName; model->GetBoundarySurface(boundarySurfaces[i], boundaryName, faceIds); if( faceIds.empty() ) continue; for(unsigned int j = 0; j < faceIds.size(); ++j) { obj->EnableFace(faceIds[j]); } } } if( volumeRenderingModuleEnabled ) { if( vm.count(integrationTypeLabel) == 0 ) { return 1; } if( breakpoints.size()*4 != colors.size() ) { std::cerr << "Invalid transfer specification." << std::endl; std::cerr << "Breakpoint size " << breakpoints.size() << std::endl; std::cerr << "Color size " << colors.size() << std::endl; return 1; } ElVis::VolumeRenderingIntegrationType integrationType = static_cast<ElVis::VolumeRenderingIntegrationType>(vm[integrationTypeLabel].as<int>()); double h = .1; if( vm.count(hLabel) == 1 ) { h = vm[hLabel].as<double>(); } double epsilon = .001; if( vm.count(epsilonLabel) == 1 ) { epsilon = vm[epsilonLabel].as<double>(); } bool trackNumSamples = false; if( vm.count(trackNumSamplesLabel) == 1 ) { trackNumSamples = (vm[trackNumSamplesLabel].as<int>() == 1); } bool renderIntegrationType = false; if( vm.count(renderIntegrationTypeLabel) == 1 ) { renderIntegrationType = (vm[renderIntegrationTypeLabel].as<int>() == 1); } bool enableEmptySpaceSkipping = true; if( vm.count(emptySpaceSkippingLabel) == 1 ) { enableEmptySpaceSkipping = (vm[emptySpaceSkippingLabel].as<int>() == 1); } boost::shared_ptr<ElVis::VolumeRenderingModule> m_volumeRenderingModule(new ElVis::VolumeRenderingModule()); m_volumeRenderingModule->SetIntegrationType(integrationType); m_volumeRenderingModule->SetCompositingStepSize(h); m_volumeRenderingModule->SetEpsilon(epsilon); m_volumeRenderingModule->SetRenderIntegrationType(renderIntegrationType); m_volumeRenderingModule->SetEnableEmptySpaceSkipping(enableEmptySpaceSkipping); m_volumeRenderingModule->SetTrackNumberOfSamples(trackNumSamples); // Setup the transfer function. boost::shared_ptr<ElVis::HostTransferFunction> transferFunction = m_volumeRenderingModule->GetTransferFunction(); for(unsigned int i = 0; i < breakpoints.size(); ++ i) { ElVis::Color c(colors[i*4], colors[i*4+1], colors[i*4+2], colors[i*4+3]); transferFunction->SetBreakpoint(breakpoints[i], c); } view->AddRenderModule(m_volumeRenderingModule); } boost::shared_ptr<ElVis::LightingModule> lighting(new ElVis::LightingModule()); view->AddRenderModule(lighting); view->SetScene(scene); view->Resize(width, height); // Don't time to take care of initialization artifacts. view->Draw(); double* times = new double[numTests-1]; for(unsigned int testNum = 1; testNum < numTests; ++testNum) { // Repeated redraws will do nothing if we don't signal that the view has changed in some way. view->OnSceneViewChanged(*view); ElVis::Timer t = view->Draw(); times[testNum-1] = t.TimePerTest(1); } view->WriteColorBufferToFile(outFilePath.c_str()); if( numTests > 1 ) { ElVis::Stat runtimeStats(times, std::numeric_limits<ElVisFloat>::max(), numTests-1, .95); std::cout << "Average Time Per Run: " << runtimeStats.Mean << std::endl; #ifdef __GNUC__ system("nvidia-smi"); #endif } return 0; }