int main(int argc, char** argv) { // (1) Open OpenNI2 Device StructureGrabber grabber; grabber.enableDepth(); grabber.disableInfrared(); grabber.disableColor(); if(argc > 1 ? grabber.open(argv[1]) : grabber.open()) { std::cerr << "Faled to open OpenNI2 device" << std::endl; return -1; } // (2) Open Viewer pcl::visualization::PCLVisualizer viewer("Point Cloud"); initViewer(viewer); viewer.addPointCloud(cloud); // (3) Iterate int key(0); while(!viewer.wasStopped()) { // (3-1) Acquire new frame grabber.acquire(); // (3-2) Visualize grabber.copyPointCloudTo(*cloud); viewer.updatePointCloud(cloud); viewer.spinOnce(); } // (4) Close OpenNI2 device grabber.close(); return 0; }
int main(int argc, char* argv[]) { double discountFactor; unsigned int maxNbEvaluations; char isTerminal = 0; char keepingTree = 0; int nbTimestep = -1; unsigned int branchingFactor = 0; #ifdef USE_SDL char isDisplayed = 1; char isFullscreen = 1; char verbose = 0; char resolution[255] = "640x480"; #else char verbose = 1; #endif uniform_instance* instance = NULL; state* crtState = NULL; state* nextState = NULL; double reward = 0.0; action* optimalAction = NULL; struct arg_dbl* g = arg_dbl1("g", "discountFactor", "<d>", "The discount factor for the problem"); struct arg_int* n = arg_int1("n", "nbEvaluations", "<n>", "The number of evaluations"); struct arg_int* s = arg_int0("s", "nbtimestep", "<n>", "The number of timestep"); struct arg_int* b = arg_int0("b", "branchingFactor", "<n>", "The branching factor of the problem"); struct arg_lit* k = arg_lit0("k", NULL, "Keep the subtree"); struct arg_str* i = arg_str0(NULL, "state", "<s>", "The initial state to use"); #ifdef USE_SDL struct arg_lit* d = arg_lit0("d", NULL, "Display the viewer"); struct arg_lit* f = arg_lit0("f", NULL, "Fullscreen"); struct arg_lit* v = arg_lit0("v", NULL, "Verbose"); struct arg_str* r = arg_str0(NULL, "resolution", "<s>", "The resolution of the display window"); void* argtable[11]; int nbArgs = 10; #else void* argtable[7]; int nbArgs = 6; #endif struct arg_end* end = arg_end(nbArgs+1); int nerrors = 0; s->ival[0] = -1; b->ival[0] = 0; argtable[0] = g; argtable[1] = n; argtable[2] = s; argtable[3] = k; argtable[4] = b; argtable[5] = i; #ifdef USE_SDL argtable[6] = d; argtable[7] = f; argtable[8] = v; argtable[9] = r; #endif argtable[nbArgs] = end; if(arg_nullcheck(argtable) != 0) { printf("error: insufficient memory\n"); arg_freetable(argtable, nbArgs+1); return EXIT_FAILURE; } nerrors = arg_parse(argc, argv, argtable); if(nerrors > 0) { printf("%s:", argv[0]); arg_print_syntax(stdout, argtable, "\n"); arg_print_errors(stdout, end, argv[0]); arg_freetable(argtable, nbArgs+1); return EXIT_FAILURE; } discountFactor = g->dval[0]; maxNbEvaluations = n->ival[0]; branchingFactor = b->ival[0]; initGenerativeModelParameters(); if(branchingFactor) K = branchingFactor; initGenerativeModel(); if(i->count) crtState = makeState(i->sval[0]); else crtState = initState(); #if USE_SDL isDisplayed = d->count; isFullscreen = f->count; verbose = v->count; if(r->count) strcpy(resolution, r->sval[0]); #endif nbTimestep = s->ival[0]; keepingTree = k->count; arg_freetable(argtable, nbArgs+1); instance = uniform_initInstance(crtState, discountFactor); #ifdef USE_SDL if(isDisplayed) { if(initViewer(resolution, uniform_drawingProcedure, isFullscreen) == -1) return EXIT_FAILURE; viewer(crtState, NULL, 0.0, instance); } #endif do { if(keepingTree) uniform_keepSubtree(instance); else uniform_resetInstance(instance, crtState); optimalAction = uniform_planning(instance, maxNbEvaluations); isTerminal = nextStateReward(crtState, optimalAction, &nextState, &reward); freeState(crtState); crtState = nextState; if(verbose) { printState(crtState); printAction(optimalAction); printf("reward: %f depth: %u\n", reward, uniform_getMaxDepth(instance)); } #ifdef USE_SDL } while(!isTerminal && (nbTimestep < 0 || --nbTimestep) && !viewer(crtState, optimalAction, reward, instance)); #else } while(!isTerminal && (nbTimestep < 0 || --nbTimestep));
/** * Main function: load and display collada file. */ int main(int argc, char** argv) { //----------------- Define program arguments -------------------// osg::ArgumentParser* OSGArguments = defineProgramArguments(&argc, argv); //----------------- Display help and quit -------------------// if (OSGArguments->read("-h") || OSGArguments->read("--help") || OSGArguments->argc()<=1 ) { OSGArguments->getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); return 0; } //----------------- Get arguments -------------------// ArgContainer* userArgs = getUserArguments(OSGArguments); //----------------- Load data in dae file -------------------// osg::Group* rootGroup = new osg::Group(); osg::Node* fileNode = osgDB::readNodeFile(userArgs->daeFile); if(!fileNode) { std::cout << OSGArguments->getApplicationName() <<": No data loaded" << std::endl; return 1; } rootGroup->addChild(fileNode); parse(fileNode, "", userArgs->verbose); //----------------- Modifiy fileNode to set the UP vector along Z -------------------// defineUpAxisInScene(fileNode, userArgs); //----------------- Create Viewer and interface -------------------// osgViewer::ViewerExt viewer; viewer.setRunMaxFrameRate(userArgs->fps); viewer.addEventHandler(new KeyEventHandler()); if (userArgs->communicationWithSocket) { SOCKET sock = OpenPort(userArgs->host.c_str(), userArgs->port); fileNode->setUpdateCallback(new SocketCallback(fileNode, sock)); } else { //----------------- Check animation data -------------------// AnimationManagerFinder finder; fileNode->accept(finder); if (finder._animManager.valid()) { userArgs->hasAnAnimation = true; fileNode->setUpdateCallback(finder._animManager.get()); AnimtkViewerGUI* gui = new AnimtkViewerGUI(&viewer, userArgs->width, userArgs->height, finder._animManager.get(), userArgs->extension_type); //interface osg::Camera* camera = gui->createParentOrthoCamera(); rootGroup->addChild(camera); viewer.addEventHandler(new osgWidget::MouseHandler(gui)); viewer.addEventHandler(new osgWidget::ResizeHandler(gui, camera)); } else { osg::notify(osg::WARN) << "no animation found in the subgraph"<<std::endl; } } viewer.setSceneData(rootGroup); //------------------- Init and Start Viewer -----------------------// initViewer(&viewer, userArgs); //------------------- What to do... -----------------------// if (userArgs->takeSnapShot) { return takeOneSnapShotAndQuit(&viewer, userArgs); } if (userArgs->recordAnimation && userArgs->hasAnAnimation) { return recordAnimationAndQuit(&viewer, userArgs); } return viewer.run(); }