这篇教程C++ viewer函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中viewer函数的典型用法代码示例。如果您正苦于以下问题:C++ viewer函数的具体用法?C++ viewer怎么用?C++ viewer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了viewer函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: mainintmain (int argc, char** argv){ if (argc < 2) { std::cerr << "Usage: " << argv[0] << " [PCD file] [-s smoothness] [-c curvature] [-n neighbors]" << std::endl; return 1; } const char *filename = argv[1]; double smoothness = 7.0 / 180.0 * M_PI; double curvature = 1.0; int neighbors = 30; for (int i=2; i<argc; i++) { if (strcmp(argv[i], "-s")==0) { smoothness = atof(argv[++i])/180.0*M_PI; } else if(strcmp(argv[i], "-c")==0) { curvature = atof(argv[++i]); } else if(strcmp(argv[i], "-n")==0) { neighbors = atoi(argv[++i]); } } std::cout << "smoothness = " << smoothness*180.0/M_PI << "[deg]" << std::endl; std::cout << "curvature = " << curvature << std::endl; std::cout << "neighbors = " << neighbors << std::endl; pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); pcl::PCDReader reader; reader.read (filename, *cloud); int npoint = cloud->points.size(); std::cout << "npoint = " << npoint << std::endl; pcl::search::Search<pcl::PointXYZ>::Ptr tree = boost::shared_ptr<pcl::search::Search<pcl::PointXYZ> > (new pcl::search::KdTree<pcl::PointXYZ>); pcl::PointCloud <pcl::Normal>::Ptr normals (new pcl::PointCloud <pcl::Normal>); pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normal_estimator; normal_estimator.setSearchMethod (tree); normal_estimator.setInputCloud (cloud); normal_estimator.setKSearch (50); normal_estimator.compute (*normals); pcl::IndicesPtr indices (new std::vector <int>); pcl::PassThrough<pcl::PointXYZ> pass; pass.setInputCloud (cloud); pass.setFilterFieldName ("z"); pass.setFilterLimits (0.0, 1.0); pass.filter (*indices); pcl::RegionGrowing<pcl::PointXYZ, pcl::Normal> reg; reg.setMinClusterSize (100); reg.setMaxClusterSize (10000); reg.setSearchMethod (tree); reg.setNumberOfNeighbours (neighbors); reg.setInputCloud (cloud); //reg.setIndices (indices); reg.setInputNormals (normals); reg.setSmoothnessThreshold (smoothness); reg.setCurvatureThreshold (curvature); std::vector <pcl::PointIndices> clusters; reg.extract (clusters); std::cout << "Number of clusters is equal to " << clusters.size () << std::endl; std::cout << "First cluster has " << clusters[0].indices.size () << " points." << endl; std::cout << "These are the indices of the points of the initial" << std::endl << "cloud that belong to the first cluster:" << std::endl; int counter = 0; while (counter < 5 || counter > clusters[0].indices.size ()) { std::cout << clusters[0].indices[counter] << std::endl; counter++; } pcl::PointCloud <pcl::PointXYZRGB>::Ptr colored_cloud = reg.getColoredCloud (); pcl::visualization::CloudViewer viewer ("Cluster viewer"); viewer.showCloud(colored_cloud); while (!viewer.wasStopped ()) { } return (0);}
开发者ID:fkanehiro,项目名称:etc,代码行数:84,
示例2: main// --------------// -----Main-----// --------------intmain (int argc, char** argv){ // -------------------------------------- // -----Parse Command Line Arguments----- // -------------------------------------- if (pcl::console::find_argument (argc, argv, "-h") >= 0) { printUsage (argv[0]); return 0; } if (pcl::console::find_argument (argc, argv, "-m") >= 0) { setUnseenToMaxRange = true; cout << "Setting unseen values in range image to maximum range readings./n"; } if (pcl::console::parse (argc, argv, "-o", rotation_invariant) >= 0) cout << "Switching rotation invariant feature version "<< (rotation_invariant ? "on" : "off")<<"./n"; int tmp_coordinate_frame; if (pcl::console::parse (argc, argv, "-c", tmp_coordinate_frame) >= 0) { coordinate_frame = pcl::RangeImage::CoordinateFrame (tmp_coordinate_frame); cout << "Using coordinate frame "<< (int)coordinate_frame<<"./n"; } if (pcl::console::parse (argc, argv, "-s", support_size) >= 0) cout << "Setting support size to "<<support_size<<"./n"; if (pcl::console::parse (argc, argv, "-r", angular_resolution) >= 0) cout << "Setting angular resolution to "<<angular_resolution<<"deg./n"; angular_resolution = pcl::deg2rad (angular_resolution); // ------------------------------------------------------------------ // -----Read pcd file or create example point cloud if not given----- // ------------------------------------------------------------------ pcl::PointCloud<PointType>::Ptr point_cloud_ptr (new pcl::PointCloud<PointType>); pcl::PointCloud<PointType>& point_cloud = *point_cloud_ptr; pcl::PointCloud<pcl::PointWithViewpoint> far_ranges; Eigen::Affine3f scene_sensor_pose (Eigen::Affine3f::Identity ()); std::vector<int> pcd_filename_indices = pcl::console::parse_file_extension_argument (argc, argv, "pcd"); if (!pcd_filename_indices.empty ()) { std::string filename = argv[pcd_filename_indices[0]]; if (pcl::io::loadPCDFile (filename, point_cloud) == -1) { cerr << "Was not able to open file /""<<filename<<"/"./n"; printUsage (argv[0]); return 0; } scene_sensor_pose = Eigen::Affine3f (Eigen::Translation3f (point_cloud.sensor_origin_[0], point_cloud.sensor_origin_[1], point_cloud.sensor_origin_[2])) * Eigen::Affine3f (point_cloud.sensor_orientation_); std::string far_ranges_filename = pcl::getFilenameWithoutExtension (filename)+"_far_ranges.pcd"; if (pcl::io::loadPCDFile (far_ranges_filename.c_str (), far_ranges) == -1) std::cout << "Far ranges file /""<<far_ranges_filename<<"/" does not exists./n"; } else { setUnseenToMaxRange = true; cout << "/nNo *.pcd file given => Genarating example point cloud./n/n"; for (float x=-0.5f; x<=0.5f; x+=0.01f) { for (float y=-0.5f; y<=0.5f; y+=0.01f) { PointType point; point.x = x; point.y = y; point.z = 2.0f - y; point_cloud.points.push_back (point); } } point_cloud.width = (int) point_cloud.points.size (); point_cloud.height = 1; } // ----------------------------------------------- // -----Create RangeImage from the PointCloud----- // ----------------------------------------------- float noise_level = 0.0; float min_range = 0.0f; int border_size = 1; boost::shared_ptr<pcl::RangeImage> range_image_ptr (new pcl::RangeImage); pcl::RangeImage& range_image = *range_image_ptr; range_image.createFromPointCloud (point_cloud, angular_resolution, pcl::deg2rad (360.0f), pcl::deg2rad (180.0f), scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size); range_image.integrateFarRanges (far_ranges); if (setUnseenToMaxRange) range_image.setUnseenToMaxRange (); // -------------------------------------------- // -----Open 3D viewer and add point cloud----- // -------------------------------------------- pcl::visualization::PCLVisualizer viewer ("3D Viewer"); viewer.setBackgroundColor (1, 1, 1); pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> range_image_color_handler (range_image_ptr, 0, 0, 0); viewer.addPointCloud (range_image_ptr, range_image_color_handler, "range image"); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "range image"); //viewer.addCoordinateSystem (1.0f);//.........这里部分代码省略.........
开发者ID:nttputus,项目名称:PCL,代码行数:101,
示例3: main//.........这里部分代码省略......... cout << "-----------------" << endl << endl; } /** * Hypothesis Verification */ cout << "--- Hypotheses Verification ---" << endl; std::vector<bool> hypotheses_mask; // Mask Vector to identify positive hypotheses pcl::GlobalHypothesesVerification<PointType, PointType> GoHv; GoHv.setSceneCloud (scene); // Scene Cloud GoHv.addModels (registered_instances, true); //Models to verify GoHv.setInlierThreshold (hv_inlier_th_); GoHv.setOcclusionThreshold (hv_occlusion_th_); GoHv.setRegularizer (hv_regularizer_); GoHv.setRadiusClutter (hv_rad_clutter_); GoHv.setClutterRegularizer (hv_clutter_reg_); GoHv.setDetectClutter (hv_detect_clutter_); GoHv.setRadiusNormals (hv_rad_normals_); GoHv.verify (); GoHv.getMask (hypotheses_mask); // i-element TRUE if hvModels[i] verifies hypotheses for (int i = 0; i < hypotheses_mask.size (); i++) { if (hypotheses_mask[i]) { cout << "Instance " << i << " is GOOD! <---" << endl; } else { cout << "Instance " << i << " is bad!" << endl; } } cout << "-------------------------------" << endl; /** * Visualization */ pcl::visualization::PCLVisualizer viewer ("Hypotheses Verification"); viewer.addPointCloud (scene, "scene_cloud"); pcl::PointCloud<PointType>::Ptr off_scene_model (new pcl::PointCloud<PointType> ()); pcl::PointCloud<PointType>::Ptr off_scene_model_keypoints (new pcl::PointCloud<PointType> ()); pcl::PointCloud<PointType>::Ptr off_model_good_kp (new pcl::PointCloud<PointType> ()); pcl::transformPointCloud (*model, *off_scene_model, Eigen::Vector3f (-1, 0, 0), Eigen::Quaternionf (1, 0, 0, 0)); pcl::transformPointCloud (*model_keypoints, *off_scene_model_keypoints, Eigen::Vector3f (-1, 0, 0), Eigen::Quaternionf (1, 0, 0, 0)); pcl::transformPointCloud (*model_good_kp, *off_model_good_kp, Eigen::Vector3f (-1, 0, 0), Eigen::Quaternionf (1, 0, 0, 0)); if (show_keypoints_) { CloudStyle modelStyle = style_white; pcl::visualization::PointCloudColorHandlerCustom<PointType> off_scene_model_color_handler (off_scene_model, modelStyle.r, modelStyle.g, modelStyle.b); viewer.addPointCloud (off_scene_model, off_scene_model_color_handler, "off_scene_model"); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, modelStyle.size, "off_scene_model"); } if (show_keypoints_) { CloudStyle goodKeypointStyle = style_violet; pcl::visualization::PointCloudColorHandlerCustom<PointType> model_good_keypoints_color_handler (off_model_good_kp, goodKeypointStyle.r, goodKeypointStyle.g, goodKeypointStyle.b); viewer.addPointCloud (off_model_good_kp, model_good_keypoints_color_handler, "model_good_keypoints"); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, goodKeypointStyle.size, "model_good_keypoints"); pcl::visualization::PointCloudColorHandlerCustom<PointType> scene_good_keypoints_color_handler (scene_good_kp, goodKeypointStyle.r, goodKeypointStyle.g, goodKeypointStyle.b); viewer.addPointCloud (scene_good_kp, scene_good_keypoints_color_handler, "scene_good_keypoints"); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, goodKeypointStyle.size, "scene_good_keypoints"); } for (size_t i = 0; i < instances.size (); ++i) { std::stringstream ss_instance; ss_instance << "instance_" << i; CloudStyle clusterStyle = style_red; pcl::visualization::PointCloudColorHandlerCustom<PointType> instance_color_handler (instances[i], clusterStyle.r, clusterStyle.g, clusterStyle.b); viewer.addPointCloud (instances[i], instance_color_handler, ss_instance.str ()); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, clusterStyle.size, ss_instance.str ()); CloudStyle registeredStyles = hypotheses_mask[i] ? style_green : style_cyan; ss_instance << "_registered" << endl; pcl::visualization::PointCloudColorHandlerCustom<PointType> registered_instance_color_handler (registered_instances[i], registeredStyles.r, registeredStyles.g, registeredStyles.b); viewer.addPointCloud (registered_instances[i], registered_instance_color_handler, ss_instance.str ()); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, registeredStyles.size, ss_instance.str ()); } while (!viewer.wasStopped ()) { viewer.spinOnce (); } return (0);}
开发者ID:vanstorm9,项目名称:pcl-experiments,代码行数:101,
示例4: mainint main( int argc, char** argv ){ // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments( &argc, argv ); arguments.getApplicationUsage()->setApplicationName( arguments.getApplicationName() ); arguments.getApplicationUsage()->setDescription( arguments.getApplicationName() + " is the standard OpenSceneGraph example which loads and visualises 3d models." ); arguments.getApplicationUsage()->setCommandLineUsage( arguments.getApplicationName() + " [options] filename ..." ); arguments.getApplicationUsage()->addCommandLineOption( "--image <filename>", "Load an image and render it on a quad" ); arguments.getApplicationUsage()->addCommandLineOption( "--dem <filename>", "Load an image/DEM and render it on a HeightField" ); arguments.getApplicationUsage()->addCommandLineOption( "--login <url> <username> <password>", "Provide authentication information for http file access." ); osgViewer::Viewer viewer( arguments ); unsigned int helpType = 0; if ( ( helpType = arguments.readHelpType() ) ) { arguments.getApplicationUsage()->write( std::cout, helpType ); return 1; } // report any errors if they have occurred when parsing the program arguments. if ( arguments.errors() ) { arguments.writeErrorMessages( std::cout ); return 1; } if ( arguments.argc() <= 1 ) { arguments.getApplicationUsage()->write( std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION ); return 1; } std::string url, username, password; while( arguments.read( "--login", url, username, password ) ) { if ( !osgDB::Registry::instance()->getAuthenticationMap() ) { osgDB::Registry::instance()->setAuthenticationMap( new osgDB::AuthenticationMap ); osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails( url, new osgDB::AuthenticationDetails( username, password ) ); } } // set up the camera manipulators. { osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); keyswitchManipulator->addMatrixManipulator( '5', "Orbit", new osgGA::OrbitManipulator() ); keyswitchManipulator->addMatrixManipulator( '6', "FirstPerson", new osgGA::FirstPersonManipulator() ); keyswitchManipulator->addMatrixManipulator( '7', "Spherical", new osgGA::SphericalManipulator() ); std::string pathfile; double animationSpeed = 1.0; while( arguments.read( "--speed", animationSpeed ) ) {} char keyForAnimationPath = '8'; while ( arguments.read( "-p", pathfile ) ) { osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator( pathfile ); if ( apm || !apm->valid() ) { apm->setTimeScale( animationSpeed ); unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); keyswitchManipulator->selectMatrixManipulator( num ); ++keyForAnimationPath; } } viewer.setCameraManipulator( keyswitchManipulator.get() ); } // add the state manipulator viewer.addEventHandler( new osgGA::StateSetManipulator( viewer.getCamera()->getOrCreateStateSet() ) ); // add the thread model handler viewer.addEventHandler( new osgViewer::ThreadingHandler ); // add the window size toggle handler viewer.addEventHandler( new osgViewer::WindowSizeHandler ); // add the stats handler viewer.addEventHandler( new osgViewer::StatsHandler ); // add the help handler viewer.addEventHandler( new osgViewer::HelpHandler( arguments.getApplicationUsage() ) ); // add the record camera path handler viewer.addEventHandler( new osgViewer::RecordCameraPathHandler ); // add the LOD Scale handler viewer.addEventHandler( new osgViewer::LODScaleHandler );//.........这里部分代码省略.........
开发者ID:kanbang,项目名称:myexercise,代码行数:101,
示例5: mainintmain(int argc, const char **argv) { const char *me; char *err; hestOpt *hopt=NULL; hestParm *hparm; airArray *mop; /* variables learned via hest */ Nrrd *nin; float camfr[3], camat[3], camup[3], camnc, camfc, camFOV; int camortho, hitandquit; unsigned int camsize[2]; double isovalue, sliso, isomin, isomax; /* boilerplate hest code */ me = argv[0]; mop = airMopNew(); hparm = hestParmNew(); hparm->respFileEnable = AIR_TRUE; airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); /* setting up the command-line options */ hparm->respFileEnable = AIR_TRUE; hestOptAdd(&hopt, "i", "volume", airTypeOther, 1, 1, &nin, NULL, "input volume to isosurface", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "v", "isovalue", airTypeDouble, 1, 1, &isovalue, "nan", "isovalue at which to run Marching Cubes"); hestOptAdd(&hopt, "fr", "x y z", airTypeFloat, 3, 3, camfr, "3 4 5", "look-from point"); hestOptAdd(&hopt, "at", "x y z", airTypeFloat, 3, 3, camat, "0 0 0", "look-at point"); hestOptAdd(&hopt, "up", "x y z", airTypeFloat, 3, 3, camup, "0 0 1", "up direction"); hestOptAdd(&hopt, "nc", "dist", airTypeFloat, 1, 1, &(camnc), "-2", "at-relative near clipping distance"); hestOptAdd(&hopt, "fc", "dist", airTypeFloat, 1, 1, &(camfc), "2", "at-relative far clipping distance"); hestOptAdd(&hopt, "fov", "angle", airTypeFloat, 1, 1, &(camFOV), "20", "vertical field-of-view, in degrees. Full vertical " "extent of image plane subtends this angle."); hestOptAdd(&hopt, "sz", "s0 s1", airTypeUInt, 2, 2, &(camsize), "640 480", "# samples (horz vert) of image plane. "); hestOptAdd(&hopt, "ortho", NULL, airTypeInt, 0, 0, &(camortho), NULL, "use orthographic instead of (the default) " "perspective projection "); hestOptAdd(&hopt, "haq", NULL, airTypeBool, 0, 0, &(hitandquit), NULL, "save a screenshot rather than display the viewer"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, "demo program", AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); /* learn value range, and set initial isovalue if needed */ NrrdRange *range = nrrdRangeNewSet(nin, AIR_FALSE); airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways); isomin = range->min; isomax = range->max; if (!AIR_EXISTS(isovalue)) { isovalue = (isomin + isomax)/2; } /* first, make sure we can isosurface ok */ limnPolyData *lpld = limnPolyDataNew(); seekContext *sctx = seekContextNew(); airMopAdd(mop, sctx, (airMopper)seekContextNix, airMopAlways); sctx->pldArrIncr = nrrdElementNumber(nin); seekVerboseSet(sctx, 0); seekNormalsFindSet(sctx, AIR_TRUE); if (seekDataSet(sctx, nin, NULL, 0) || seekTypeSet(sctx, seekTypeIsocontour) || seekIsovalueSet(sctx, isovalue) || seekUpdate(sctx) || seekExtract(sctx, lpld)) { airMopAdd(mop, err=biffGetDone(SEEK), airFree, airMopAlways); fprintf(stderr, "trouble with isosurfacing:/n%s", err); airMopError(mop); return 1; } if (!lpld->xyzwNum) { fprintf(stderr, "%s: warning: No isocontour generated at isovalue %g/n", me, isovalue); } /* then create empty scene */ Hale::init(); Hale::Scene scene; /* then create viewer (in order to create the OpenGL context) */ Hale::Viewer viewer(camsize[0], camsize[1], "Iso", &scene); viewer.lightDir(glm::vec3(-1.0f, 1.0f, 3.0f)); viewer.camera.init(glm::vec3(camfr[0], camfr[1], camfr[2]), glm::vec3(camat[0], camat[1], camat[2]), glm::vec3(camup[0], camup[1], camup[2]), camFOV, (float)camsize[0]/camsize[1], camnc, camfc, camortho); viewer.refreshCB((Hale::ViewerRefresher)render); viewer.refreshData(&viewer); sliso = isovalue; viewer.slider(&sliso, isomin, isomax); viewer.current();//.........这里部分代码省略.........
开发者ID:kindlmann,项目名称:hale,代码行数:101,
示例6: mainint main (int argc, char** argv){ if(argc<2){ std::cout << "need ply/pcd file. " << std::endl; return -1; } // 确定文件格式 char tmpStr[100]; strcpy(tmpStr,argv[1]); char* pext = strrchr(tmpStr, '.'); std::string extply("ply"); std::string extpcd("pcd"); if(pext){ *pext='/0'; pext++; } std::string ext(pext); //如果不支持文件格式,退出程序 if (!((ext == extply)||(ext == extpcd))){ std::cout << "文件格式不支持!" << std::endl; std::cout << "支持文件格式:*.pcd和*.ply!" << std::endl; return(-1); } //根据文件格式选择输入方式 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>) ; //创建点云对象指针,用于存储输入 if (ext == extply){ if (pcl::io::loadPLYFile(argv[1] , *cloud) == -1){ PCL_ERROR("Could not read ply file!/n") ; return -1; } } else{ if (pcl::io::loadPCDFile(argv[1] , *cloud) == -1){ PCL_ERROR("Could not read pcd file!/n") ; return -1; } } // 估计法向量 x,y,x + 法向量 + 曲率 pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n; pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>); pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>); tree->setInputCloud(cloud); n.setInputCloud(cloud); n.setSearchMethod(tree); n.setKSearch(20);//20个邻居 n.compute (*normals); //计算法线,结果存储在normals中 //* normals 不能同时包含点的法向量和表面的曲率 //将点云和法线放到一起 pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>); pcl::concatenateFields (*cloud, *normals, *cloud_with_normals); //* cloud_with_normals = cloud + normals //创建搜索树 pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>); tree2->setInputCloud (cloud_with_normals); //初始化 移动立方体算法 MarchingCubes对象,并设置参数 pcl::MarchingCubes<pcl::PointNormal> *mc; mc = new pcl::MarchingCubesHoppe<pcl::PointNormal> (); /* if (hoppe_or_rbf == 0) mc = new pcl::MarchingCubesHoppe<pcl::PointNormal> (); else { mc = new pcl::MarchingCubesRBF<pcl::PointNormal> (); (reinterpret_cast<pcl::MarchingCubesRBF<pcl::PointNormal>*> (mc))->setOffSurfaceDisplacement (off_surface_displacement); } */ //创建多变形网格,用于存储结果 pcl::PolygonMesh mesh; //设置MarchingCubes对象的参数 mc->setIsoLevel (0.0f); mc->setGridResolution (50, 50, 50); mc->setPercentageExtendGrid (0.0f); //设置搜索方法 mc->setInputCloud (cloud_with_normals); //执行重构,结果保存在mesh中 mc->reconstruct (mesh); //保存网格图 pcl::io::savePLYFile("result2.ply", mesh); // 显示结果图 boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer")); viewer->setBackgroundColor (0, 0, 0); //设置背景 viewer->addPolygonMesh(mesh,"my"); //设置显示的网格 //viewer->addCoordinateSystem (1.0); //设置坐标系 viewer->initCameraParameters (); while (!viewer->wasStopped ()){ viewer->spinOnce (100); boost::this_thread::sleep (boost::posix_time::microseconds (100000)); }//.........这里部分代码省略.........
开发者ID:dyz-zju,项目名称:MVision,代码行数:101,
示例7: main//.........这里部分代码省略......... clusterer.recognize (rototranslations, clustered_corrs); } else // Using GeometricConsistency { pcl::GeometricConsistencyGrouping<PointType, PointType> gc_clusterer; gc_clusterer.setGCSize (cg_size_); gc_clusterer.setGCThreshold (cg_thresh_); gc_clusterer.setInputCloud (model_keypoints); gc_clusterer.setSceneCloud (scene_keypoints); gc_clusterer.setModelSceneCorrespondences (model_scene_corrs); //gc_clusterer.cluster (clustered_corrs); gc_clusterer.recognize (rototranslations, clustered_corrs); } // // Output results // std::cout << "Model instances found: " << rototranslations.size () << std::endl; for (size_t i = 0; i < rototranslations.size (); ++i) { std::cout << "/n Instance " << i + 1 << ":" << std::endl; std::cout << " Correspondences belonging to this instance: " << clustered_corrs[i].size () << std::endl; // Print the rotation matrix and translation vector Eigen::Matrix3f rotation = rototranslations[i].block<3,3>(0, 0); Eigen::Vector3f translation = rototranslations[i].block<3,1>(0, 3); printf ("/n"); printf (" | %6.3f %6.3f %6.3f | /n", rotation (0,0), rotation (0,1), rotation (0,2)); printf (" R = | %6.3f %6.3f %6.3f | /n", rotation (1,0), rotation (1,1), rotation (1,2)); printf (" | %6.3f %6.3f %6.3f | /n", rotation (2,0), rotation (2,1), rotation (2,2)); printf ("/n"); printf (" t = < %0.3f, %0.3f, %0.3f >/n", translation (0), translation (1), translation (2)); } // // Visualization // pcl::visualization::PCLVisualizer viewer ("Correspondence Grouping"); viewer.addPointCloud (scene, "scene_cloud"); pcl::PointCloud<PointType>::Ptr off_scene_model (new pcl::PointCloud<PointType> ()); pcl::PointCloud<PointType>::Ptr off_scene_model_keypoints (new pcl::PointCloud<PointType> ()); if (show_correspondences_ || show_keypoints_) { // We are translating the model so that it doesn't end in the middle of the scene representation pcl::transformPointCloud (*model, *off_scene_model, Eigen::Vector3f (-1,0,0), Eigen::Quaternionf (1, 0, 0, 0)); pcl::transformPointCloud (*model_keypoints, *off_scene_model_keypoints, Eigen::Vector3f (-1,0,0), Eigen::Quaternionf (1, 0, 0, 0)); pcl::visualization::PointCloudColorHandlerCustom<PointType> off_scene_model_color_handler (off_scene_model, 255, 255, 128); viewer.addPointCloud (off_scene_model, off_scene_model_color_handler, "off_scene_model"); } if (show_keypoints_) { pcl::visualization::PointCloudColorHandlerCustom<PointType> scene_keypoints_color_handler (scene_keypoints, 0, 0, 255); viewer.addPointCloud (scene_keypoints, scene_keypoints_color_handler, "scene_keypoints"); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "scene_keypoints"); pcl::visualization::PointCloudColorHandlerCustom<PointType> off_scene_model_keypoints_color_handler (off_scene_model_keypoints, 0, 0, 255); viewer.addPointCloud (off_scene_model_keypoints, off_scene_model_keypoints_color_handler, "off_scene_model_keypoints"); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "off_scene_model_keypoints"); } for (size_t i = 0; i < rototranslations.size (); ++i) { pcl::PointCloud<PointType>::Ptr rotated_model (new pcl::PointCloud<PointType> ()); pcl::transformPointCloud (*model, *rotated_model, rototranslations[i]); std::stringstream ss_cloud; ss_cloud << "instance" << i; pcl::visualization::PointCloudColorHandlerCustom<PointType> rotated_model_color_handler (rotated_model, 255, 0, 0); viewer.addPointCloud (rotated_model, rotated_model_color_handler, ss_cloud.str ()); if (show_correspondences_) { for (size_t j = 0; j < clustered_corrs[i].size (); ++j) { std::stringstream ss_line; ss_line << "correspondence_line" << i << "_" << j; PointType& model_point = off_scene_model_keypoints->at (clustered_corrs[i][j].index_query); PointType& scene_point = scene_keypoints->at (clustered_corrs[i][j].index_match); // We are drawing a line for each pair of clustered correspondences found between the model and the scene viewer.addLine<PointType, PointType> (model_point, scene_point, 0, 255, 0, ss_line.str ()); } } } while (!viewer.wasStopped ()) { viewer.spinOnce (); } return (0);}
开发者ID:TuZZiX,项目名称:pcl_recognition,代码行数:101,
示例8: mainint main( int argc, char** argv ){ // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc, argv); // read the scene from the list of file specified command line arguments. osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default cow model instead. if (!loadedModel) { loadedModel = osgDB::readNodeFile("cow.osgt"); } // Still no loaded model, then exit if (!loadedModel) { osg::notify(osg::ALWAYS) << "No model could be loaded and didn't find cow.osgt, terminating.." << std::endl; return 0; } // Create Trackball manipulator osg::ref_ptr<osgGA::CameraManipulator> cameraManipulator = new osgGA::TrackballManipulator; const osg::BoundingSphere& bs = loadedModel->getBound(); if (bs.valid()) { // Adjust view to object view /* This caused a problem with the head tracking on the Vive osg::Vec3 modelCenter = bs.center(); osg::Vec3 eyePos = bs.center() + osg::Vec3(0, bs.radius(), 0); cameraManipulator->setHomePosition(eyePos, modelCenter, osg::Vec3(0, 0, 1)); */ } // Exit if we do not have an HMD present if (!OpenVRDevice::hmdPresent()) { osg::notify(osg::FATAL) << "Error: No valid HMD present!" << std::endl; return 1; } // Open the HMD float nearClip = 0.01f; float farClip = 10000.0f; float worldUnitsPerMetre = 1.0f; int samples = 4; osg::ref_ptr<OpenVRDevice> openvrDevice = new OpenVRDevice(nearClip, farClip, worldUnitsPerMetre, samples); // Exit if we fail to initialize the HMD device if (!openvrDevice->hmdInitialized()) { // The reason for failure was reported by the constructor. return 1; } // Get the suggested context traits osg::ref_ptr<osg::GraphicsContext::Traits> traits = openvrDevice->graphicsContextTraits(); traits->windowName = "OsgOpenVRViewerExample"; // Create a graphic context based on our desired traits osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits); if (!gc) { osg::notify(osg::NOTICE) << "Error, GraphicsWindow has not been created successfully" << std::endl; return 1; } if (gc.valid()) { gc->setClearColor(osg::Vec4(0.2f, 0.2f, 0.4f, 1.0f)); gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } GraphicsWindowViewer viewer(arguments, dynamic_cast<osgViewer::GraphicsWindow*>(gc.get())); // Force single threaded to make sure that no other thread can use the GL context viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); viewer.getCamera()->setGraphicsContext(gc); viewer.getCamera()->setViewport(0, 0, traits->width, traits->height); // Disable automatic computation of near and far plane viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); viewer.setCameraManipulator(cameraManipulator); // Things to do when viewer is realized osg::ref_ptr<OpenVRRealizeOperation> openvrRealizeOperation = new OpenVRRealizeOperation(openvrDevice); viewer.setRealizeOperation(openvrRealizeOperation.get()); osg::ref_ptr<OpenVRViewer> openvrViewer = new OpenVRViewer(&viewer, openvrDevice, openvrRealizeOperation); openvrViewer->addChild(loadedModel); viewer.setSceneData(openvrViewer); // Add statistics handler viewer.addEventHandler(new osgViewer::StatsHandler); viewer.addEventHandler(new OpenVREventHandler(openvrDevice)); viewer.run(); // Need to do this here to make it happen before destruction of the OSG Viewer, which destroys the OpenGL context. openvrDevice->shutdown(gc.get()); return 0;//.........这里部分代码省略.........
开发者ID:ChrisDenham,项目名称:osgopenvrviewer,代码行数:101,
示例9: semctl viewer_rt::viewer_rt (){ //Inicialization i = 0; key = 10; num_semaphore = 6; act = 0; run = true; turn_on = false; turn_view = 0; v1 = 0; v2 = 0; v3 = 0; v4 = 0; obj1 = 0; obj2 = 0; obj3 = 0; //Make semaphore if((semid = semget(key,num_semaphore,IPC_CREAT|0600)) == -1) std::cout << "[WIEWER_RT] ERROR CREATING SEMAPHORE" << std::endl; operation.sem_flg = 0; //Initialze semaphore semctl(semid,WRITE_PCD,SETVAL,1); semctl(semid,REQUEST_LOAD_CLOUD,SETVAL,0); semctl(semid,5,SETVAL,0); //Make and set pipes if (pipe(pipe_flags) == -1) std::cout << "[WIEWER_RT] ERROR CREATING THE PRINCIPAL PIPE" << std::endl; if (pipe(pipe_cloud) == -1) std::cout << "[WIEWER_RT] ERROR CREATING THE SECOND PIPE" << std::endl; //Fork the execcution pid = fork(); vector_pid.push_back(pid); name_process.push_back("VIEWER_RT"); if (pid == -1) std::cout << "[VIEWER_RT] ERROR MAKING FORK" << std::endl; //Child execution (paralel to the principal proccess) else if (pid == 0) { pcl::visualization::PCLVisualizer viewer ("vista 3D"); viewer.setSize(1360,768); //Configure viewer viewer.initCameraParameters (); /* //( xmin , ymin, xmax , ymax, viewport )// //two windows //viewer.createViewPort(0.0, 0.5, 1, 1, v1); //viewer.createViewPort(0.0, 0.0, 1, 0.5, v2); //three windows (A) //viewer.createViewPort(0.0, 0.66, 1, 1, v1); //viewer.createViewPort(0.0, 0.33, 1, 0.66, v2); //viewer.createViewPort(0.0, 0.0, 1, 0.33, v3); //three windows (B) //viewer.createViewPort(0, 0.5, 1, 1, v1); //viewer.createViewPort(0, 0, 0.5, 0.5, v2); //viewer.createViewPort(0.5, 0, 1, 0.5, v3); //viewer.setBackgroundColor (255, 255, 255); //viewer.createViewPort(0, 0, 1, 1, v1); //four windows //viewer.createViewPort(0.0, 0.5, 0.5, 1.0, v1); //viewer.createViewPort(0.5, 0.5, 1, 1, v2);//.........这里部分代码省略.........
开发者ID:jvgomez,项目名称:RoomReconstruction,代码行数:101,
示例10: mainint main( int argc, char** argv ){ float nearClip = 0.01f; float farClip = 10000.0f; float pixelsPerDisplayPixel = 1.0; bool useTimewarp = true; osg::ref_ptr<OculusDevice> oculusDevice = new OculusDevice(nearClip, farClip, pixelsPerDisplayPixel, useTimewarp); // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); // read the scene from the list of file specified command line arguments. osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default cow model instead. if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt"); // Still no loaded model, then exit if (!loadedModel) return 0; // Calculate the texture size const int textureWidth = oculusDevice->renderTargetWidth()/2; const int textureHeight = oculusDevice->renderTargetHeight(); // Setup textures for the RTT cameras osg::ref_ptr<osg::Texture2D> textureLeft = new osg::Texture2D; textureLeft->setTextureSize(textureWidth, textureHeight); textureLeft->setInternalFormat(GL_RGBA); osg::ref_ptr<osg::Texture2D> textureRight = new osg::Texture2D; textureRight->setTextureSize(textureWidth, textureHeight); textureRight->setInternalFormat(GL_RGBA); // Initialize RTT cameras for each eye osg::ref_ptr<osg::Camera> leftEyeRTTCamera = oculusDevice->createRTTCamera(textureLeft, OculusDevice::LEFT, osg::Camera::ABSOLUTE_RF); leftEyeRTTCamera->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR ); leftEyeRTTCamera->addChild( loadedModel ); osg::ref_ptr<osg::Camera> rightEyeRTTCamera = oculusDevice->createRTTCamera(textureRight, OculusDevice::RIGHT, osg::Camera::ABSOLUTE_RF); rightEyeRTTCamera->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR ); rightEyeRTTCamera->addChild( loadedModel ); // Create HUD cameras for each eye osg::ref_ptr<osg::Camera> leftCameraWarp = oculusDevice->createWarpOrthoCamera(0.0, 1.0, 0.0, 1.0); osg::ref_ptr<osg::Camera> rightCameraWarp = oculusDevice->createWarpOrthoCamera(0.0, 1.0, 0.0, 1.0); // Create shader program osg::ref_ptr<osg::Program> program = oculusDevice->createShaderProgram(); // Create distortionMesh for each camera osg::ref_ptr<osg::Geode> leftDistortionMesh = oculusDevice->distortionMesh(OculusDevice::LEFT, program, 0, 0, textureWidth, textureHeight, true); leftCameraWarp->addChild(leftDistortionMesh); osg::ref_ptr<osg::Geode> rightDistortionMesh = oculusDevice->distortionMesh(OculusDevice::RIGHT, program, 0, 0, textureWidth, textureHeight, true); rightCameraWarp->addChild(rightDistortionMesh); // Add pre draw camera to handle time warp leftCameraWarp->setPreDrawCallback(new WarpCameraPreDrawCallback(oculusDevice)); rightCameraWarp->setPreDrawCallback(new WarpCameraPreDrawCallback(oculusDevice)); // Attach shaders to each distortion mesh osg::ref_ptr<osg::StateSet> leftEyeStateSet = leftDistortionMesh->getOrCreateStateSet(); osg::ref_ptr<osg::StateSet> rightEyeStateSet = rightDistortionMesh->getOrCreateStateSet(); oculusDevice->applyShaderParameters(leftEyeStateSet, program, textureLeft, OculusDevice::LEFT); oculusDevice->applyShaderParameters(rightEyeStateSet, program, textureRight, OculusDevice::RIGHT); // Create Trackball manipulator osg::ref_ptr<osgGA::CameraManipulator> cameraManipulator = new osgGA::TrackballManipulator; const osg::BoundingSphere& bs = loadedModel->getBound(); if (bs.valid()) { // Adjust view to object view cameraManipulator->setHomePosition(osg::Vec3(0, bs.radius()*1.5, 0), osg::Vec3(0, 0, 0), osg::Vec3(0, 0, 1)); } // Add cameras to groups osg::ref_ptr<osg::Group> leftRoot = new osg::Group; osg::ref_ptr<osg::Group> rightRoot = new osg::Group; leftRoot->addChild(leftEyeRTTCamera); leftRoot->addChild(leftCameraWarp); rightRoot->addChild(rightEyeRTTCamera); rightRoot->addChild(rightCameraWarp); osg::ref_ptr<osg::GraphicsContext::Traits> traits = oculusDevice->graphicsContextTraits(); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits); // Attach to window, needed for direct mode oculusDevice->attachToWindow(gc); // Attach a callback to detect swap osg::ref_ptr<OculusSwapCallback> swapCallback = new OculusSwapCallback(oculusDevice); gc->setSwapCallback(swapCallback); // Create a composite viewer osgViewer::CompositeViewer viewer(arguments); // Create views and attach camera groups to them osg::ref_ptr<osgViewer::View> leftView = new osgViewer::View; leftView->setName("LeftEyeView"); viewer.addView(leftView); leftView->setSceneData(leftRoot); leftView->getCamera()->setName("LeftEyeCamera"); leftView->getCamera()->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f)); leftView->getCamera()->setViewport(new osg::Viewport(0, 0, oculusDevice->screenResolutionWidth() / 2, oculusDevice->screenResolutionHeight())); leftView->getCamera()->setGraphicsContext(gc); // Add statistics view to only one view leftView->addEventHandler(new osgViewer::StatsHandler);//.........这里部分代码省略.........
开发者ID:dsjolie,项目名称:osgoculusviewer,代码行数:101,
示例11: main_sparkint main_spark( int argc, char** argv ){ osg::ArgumentParser arguments( &argc, argv ); bool trackingModel = false; int effectType = 0; if ( arguments.read("--simple") ) effectType = 0; else if ( arguments.read("--explosion") ) effectType = 1; else if ( arguments.read("--fire") ) effectType = 2; else if ( arguments.read("--rain") ) effectType = 3; else if ( arguments.read("--smoke") ) effectType = 4; effectType = 3; spark::init(); osg::ref_ptr<SparkDrawable> spark = new SparkDrawable; osg::ref_ptr<osg::Geode> geode = new osg::Geode; switch ( effectType ) { case 1: // Explosion spark->setBaseSystemCreator( &createExplosion ); spark->addParticleSystem(); spark->setSortParticles( true ); spark->addImage( "explosion", osgDB::readImageFile("data/explosion.bmp"), GL_ALPHA ); spark->addImage( "flash", osgDB::readImageFile("data/flash.bmp"), GL_RGB ); spark->addImage( "spark1", osgDB::readImageFile("data/spark1.bmp"), GL_RGB ); spark->addImage( "spark2", osgDB::readImageFile("data/point.bmp"), GL_ALPHA ); spark->addImage( "wave", osgDB::readImageFile("data/wave.bmp"), GL_RGBA ); break; case 2: // Fire spark->setBaseSystemCreator( /*&createFire*/&fire_creator(2).createFire ); spark->addParticleSystem(); spark->addImage( "fire", osgDB::readImageFile("data/fire2.bmp"), GL_ALPHA ); spark->addImage( "explosion", osgDB::readImageFile("data/explosion.bmp"), GL_ALPHA ); break; case 3: // Rain spark->setBaseSystemCreator( &createRain, true ); // Must use the proto type directly spark->addImage( "waterdrops", osgDB::readImageFile("data/waterdrops.bmp"), GL_ALPHA ); geode = new osg::Geode; break; case 4: // Smoke spark->setBaseSystemCreator( &createSmoke ); spark->addParticleSystem(); spark->addImage( "smoke", osgDB::readImageFile("data/smoke.png"), GL_RGBA ); trackingModel = true; break; default: // Simple spark->setBaseSystemCreator( &createSimpleSystem ); spark->addParticleSystem(); spark->addImage( "flare", osgDB::readImageFile("data/flare.bmp"), GL_ALPHA ); break; } geode->addDrawable( spark.get() ); geode->getOrCreateStateSet()->setRenderingHint( osg::StateSet::TRANSPARENT_BIN ); geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); osg::ref_ptr<SparkUpdatingHandler> handler = new SparkUpdatingHandler; handler->addSpark( spark.get() ); osg::ref_ptr<osg::MatrixTransform> model = new osg::MatrixTransform; model->addChild( osgDB::readNodeFile("glider.osg") ); if ( trackingModel ) { handler->setTrackee( 0, model.get() ); osg::ref_ptr<osg::AnimationPathCallback> apcb = new osg::AnimationPathCallback; apcb->setAnimationPath( createAnimationPath(4.0f, 6.0f) ); model->setUpdateCallback( apcb.get() ); } osg::ref_ptr<osg::Group> root = new osg::Group; root->addChild( geode.get() ); root->addChild( model.get() ); osgViewer::Viewer viewer(arguments); viewer.getCamera()->setClearColor( osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f) ); viewer.setSceneData( root.get() ); viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler( new osgViewer::StatsHandler ); viewer.addEventHandler( new osgViewer::WindowSizeHandler ); viewer.addEventHandler( handler.get() ); return viewer.run();}
开发者ID:whztt07,项目名称:test_osg,代码行数:87,
示例12: mainint main(int argc, char **argv){ // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc, argv); // read the scene from the list of file specified commandline args. osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments); if (!scene) { std::cout << argv[0] << ": requires filename argument." << std::endl; return 1; } // construct the viewer. osgViewer::CompositeViewer viewer(arguments); if (arguments.read("-1")) { { osgViewer::View* view = new osgViewer::View; view->setName("Single view"); view->setSceneData(scene.get()); view->addEventHandler(new osgViewer::StatsHandler); view->setUpViewAcrossAllScreens(); view->setCameraManipulator(new osgGA::TrackballManipulator); viewer.addView(view); } } if (arguments.read("-2")) { // view one { osgViewer::View* view = new osgViewer::View; view->setName("View one"); viewer.addView(view); view->setUpViewOnSingleScreen(0); view->setSceneData(scene.get()); view->setCameraManipulator(new osgGA::TrackballManipulator); // add the state manipulator osg::ref_ptr<osgGA::StateSetManipulator> statesetManipulator = new osgGA::StateSetManipulator; statesetManipulator->setStateSet(view->getCamera()->getOrCreateStateSet()); view->addEventHandler(statesetManipulator.get()); } // view two { osgViewer::View* view = new osgViewer::View; view->setName("View two"); viewer.addView(view); view->setUpViewOnSingleScreen(1); view->setSceneData(scene.get()); view->setCameraManipulator(new osgGA::TrackballManipulator); view->addEventHandler(new osgViewer::StatsHandler); // add the handler for doing the picking view->addEventHandler(new PickHandler()); } } if (arguments.read("-3") || viewer.getNumViews() == 0) { osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); if (!wsi) { osg::notify(osg::NOTICE) << "Error, no WindowSystemInterface available, cannot create windows." << std::endl; return 1; } unsigned int width, height; wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; traits->x = 100; traits->y = 100; traits->width = 1000; traits->height = 800; traits->windowDecoration = true; traits->doubleBuffer = true; traits->sharedContext = 0; osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); if (gc.valid()) { osg::notify(osg::INFO) << " GraphicsWindow has been created successfully." << std::endl; // need to ensure that the window is cleared make sure that the complete window is set the correct colour//.........这里部分代码省略.........
开发者ID:wangfeilong321,项目名称:vdpm,代码行数:101,
示例13: rotated_modelvoid shot_detector::visualizeICP(){ std::cerr << "verifying" << std::endl; if (rototranslations.size () <= 0) { cerr << "*** No instances found! ***" << endl; return; } else { cerr << "Recognized Instances: " << rototranslations.size () << endl << endl; } /** * Generates clouds for each instances found */ std::vector<pcl::PointCloud<PointType>::ConstPtr> instances; for (size_t i = 0; i < rototranslations.size (); ++i) { pcl::PointCloud<PointType>::Ptr rotated_model (new pcl::PointCloud<PointType> ()); pcl::transformPointCloud (*model, *rotated_model, rototranslations[i]); instances.push_back (rotated_model); } std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > final_transforms; /** * ICP */ std::vector<pcl::PointCloud<PointType>::ConstPtr> registered_instances; if (true) { cerr << "--- ICP ---------" << endl; for (size_t i = 0; i < rototranslations.size (); ++i) { pcl::IterativeClosestPoint<PointType, PointType> icp; icp.setMaximumIterations (icp_max_iter_); icp.setMaxCorrespondenceDistance (icp_corr_distance_); icp.setInputTarget (scene); icp.setInputSource (instances[i]); pcl::PointCloud<PointType>::Ptr registered (new pcl::PointCloud<PointType>); icp.align (*registered); icp.setMaxCorrespondenceDistance (.01); icp.align (*registered); icp.setMaxCorrespondenceDistance (.005); icp.align (*registered); registered_instances.push_back (registered); std::cerr << rototranslations[i] << std::endl; final_transforms.push_back(icp.getFinalTransformation()); std::cerr << "answer" << icp.getFinalTransformation()* rototranslations[i] << std::endl; cerr << "Instance " << i << std::endl; if (icp.hasConverged ()) { cerr << "Aligned!" << endl; } else { cerr << "Not Aligned!" << endl; } } cerr << "-----------------" << endl << endl; } /** * Hypothesis Verification */ cerr << "--- Hypotheses Verification ---" << endl; std::vector<bool> hypotheses_mask; // Mask Vector to identify positive hypotheses pcl::GlobalHypothesesVerification<PointType, PointType> GoHv; GoHv.setSceneCloud (scene); // Scene Cloud GoHv.addModels (registered_instances, true); //Models to verify GoHv.setInlierThreshold (hv_inlier_th_); GoHv.setOcclusionThreshold (hv_occlusion_th_); GoHv.setRegularizer (hv_regularizer_); GoHv.setRadiusClutter (hv_rad_clutter_); GoHv.setClutterRegularizer (hv_clutter_reg_); GoHv.setDetectClutter (hv_detect_clutter_); GoHv.setRadiusNormals (hv_rad_normals_); GoHv.verify (); GoHv.getMask (hypotheses_mask); // i-element TRUE if hvModels[i] verifies hypotheses for (int i = 0; i < hypotheses_mask.size (); i++) { if (hypotheses_mask[i]) { cerr << "Instance " << i << " is GOOD! <---" << endl; } else { cerr << "Instance " << i << " is bad!" << endl; } } cerr << "-------------------------------" << endl; /** * Visualization */ pcl::visualization::PCLVisualizer viewer ("Hypotheses Verification"); viewer.addPointCloud (scene, "scene_cloud"); std::cerr << scene->points[1].x << scene->points[1].y << scene->points[1].z << std::endl; viewer.addCoordinateSystem (1.0); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "scene_cloud"); /* pcl::PointCloud<PointType>::Ptr off_scene_model (new pcl::PointCloud<PointType> ()); pcl::PointCloud<PointType>::Ptr off_scene_model_keypoints (new pcl::PointCloud<PointType> ()); pcl::PointCloud<PointType>::Ptr off_model_good_kp (new pcl::PointCloud<PointType> ()); pcl::transformPointCloud (*model, *off_scene_model, Eigen::Vector3f (-1, 0, 0), Eigen::Quaternionf (1, 0, 0, 0));//.........这里部分代码省略.........
开发者ID:ehuang3,项目名称:apc_ros,代码行数:101,
示例14: printfvoid shot_detector::visualizeCorrespondences(){ std::cerr << "Model instances found: " << rototranslations.size () << std::endl; for (size_t i = 0; i < rototranslations.size (); ++i) { std::cerr << "/n Instance " << i + 1 << ":" << std::endl; std::cerr << " Correspondences belonging to this instance: " << clustered_corrs[i].size () << std::endl; // Print the rotation matrix and translation vector Eigen::Matrix3f rotation = rototranslations[i].block<3, 3>(0, 0); Eigen::Vector3f translation = rototranslations[i].block<3, 1>(0, 3); printf ("/n"); printf (" | %6.3f %6.3f %6.3f | /n", rotation (0, 0), rotation (0, 1), rotation (0, 2)); printf (" R = | %6.3f %6.3f %6.3f | /n", rotation (1, 0), rotation (1, 1), rotation (1, 2)); printf (" | %6.3f %6.3f %6.3f | /n", rotation (2, 0), rotation (2, 1), rotation (2, 2)); printf ("/n"); printf (" t = < %0.3f, %0.3f, %0.3f >/n", translation (0), translation (1), translation (2)); } // // Visualization // pcl::visualization::PCLVisualizer viewer ("Correspondence Grouping"); viewer.addCoordinateSystem (1.0); viewer.addPointCloud (scene, "scene_cloud"); pcl::PointCloud<PointType>::Ptr off_scene_model (new pcl::PointCloud<PointType> ()); pcl::PointCloud<PointType>::Ptr off_scene_model_keypoints (new pcl::PointCloud<PointType> ()); // if (show_correspondences_ || show_keypoints_) // { // We are translating the model so that it doesn't end in the middle of the scene representation pcl::transformPointCloud (*model, *off_scene_model, Eigen::Vector3f (-1, 0, 0), Eigen::Quaternionf (1, 0, 0, 0)); pcl::transformPointCloud (*model_keypoints, *off_scene_model_keypoints, Eigen::Vector3f (-1, 0, 0), Eigen::Quaternionf (1, 0, 0, 0)); pcl::visualization::PointCloudColorHandlerCustom<PointType> off_scene_model_color_handler (off_scene_model, 255, 255, 128); viewer.addPointCloud (off_scene_model, "off_scene_model"); // } //if (show_keypoints_) // { /*pcl::visualization::PointCloudColorHandlerCustom<PointType> scene_keypoints_color_handler (scene_keypoints, 0, 0, 255); viewer.addPointCloud (scene_keypoints, scene_keypoints_color_handler, "scene_keypoints"); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "scene_keypoints");*/ /* pcl::visualization::PointCloudColorHandlerCustom<PointType> off_scene_model_keypoints_color_handler (off_scene_model_keypoints, 0, 0, 255); viewer.addPointCloud (off_scene_model_keypoints, "off_scene_model_keypoints"); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "off_scene_model_keypoints");*/ // } pcl::PointCloud<PointType>::Ptr scene_corr (new pcl::PointCloud<PointType> ()); for (int idx = 0; idx < model_scene_corrs->size(); ++idx) { PointType temp = scene_keypoints->at(model_scene_corrs->at(idx).index_match); scene_corr->push_back(temp); } pcl::visualization::PointCloudColorHandlerCustom<PointType> scene_corr_color_handler (scene_corr, 255, 0, 0); viewer.addPointCloud (scene_corr, scene_corr_color_handler, "scene_corr"); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "scene_corr"); for (size_t i = 0; i < rototranslations.size (); ++i) { pcl::PointCloud<PointType>::Ptr rotated_model (new pcl::PointCloud<PointType> ()); pcl::transformPointCloud (*model, *rotated_model, rototranslations[i]); std::stringstream ss_cloud; ss_cloud << "instance" << i; pcl::visualization::PointCloudColorHandlerCustom<PointType> rotated_model_color_handler (rotated_model, 255, 0, 0); viewer.addPointCloud (rotated_model, rotated_model_color_handler, ss_cloud.str ()); //if (show_correspondences_) //{ pcl::PointCloud<PointType>::Ptr scene_corr (new pcl::PointCloud<PointType> ()); for (size_t j = 0; j < clustered_corrs[i].size (); ++j) { std::stringstream ss_line; ss_line << "correspondence_line" << i << "_" << j; PointType& model_point = off_scene_model_keypoints->at (clustered_corrs[i][j].index_query); PointType& scene_point = scene_keypoints->at (clustered_corrs[i][j].index_match); // We are drawing a line for each pair of clustered correspondences found between the model and the scene viewer.addLine<PointType, PointType> (model_point, scene_point, 0, 255, 0, ss_line.str ()); } // } } while (!viewer.wasStopped ()) { viewer.spinOnce (); }}
开发者ID:ehuang3,项目名称:apc_ros,代码行数:86,
示例15: mainint main( int argc, char **argv ){ // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the application for presenting 3D interactive slide shows."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); arguments.getApplicationUsage()->addCommandLineOption("-a","Turn auto stepping on by default"); arguments.getApplicationUsage()->addCommandLineOption("-d <float>","Time duration in seconds between layers/slides"); arguments.getApplicationUsage()->addCommandLineOption("-s <float> <float> <float>","width, height, distance and of the screen away from the viewer"); arguments.getApplicationUsage()->addCommandLineOption("--viewer","Start Present3D as the viewer version."); arguments.getApplicationUsage()->addCommandLineOption("--authoring","Start Present3D as the authoring version, license required."); arguments.getApplicationUsage()->addCommandLineOption("--master","Start Present3D as the master version, license required."); arguments.getApplicationUsage()->addCommandLineOption("--slave","Start Present3D as the slave version, license required."); arguments.getApplicationUsage()->addCommandLineOption("--publishing","Start Present3D as the publishing version, license required."); arguments.getApplicationUsage()->addCommandLineOption("--timeDelayOnNewSlideWithMovies","Set the time delay on new slide with movies, done to allow movie threads to get in sync with rendering thread."); arguments.getApplicationUsage()->addCommandLineOption("--targetFrameRate","Set the target frame rate, defaults to 80Hz."); arguments.getApplicationUsage()->addCommandLineOption("--version","Report the Present3D version."); arguments.getApplicationUsage()->addCommandLineOption("--print <filename>","Print out slides to a series of image files."); arguments.getApplicationUsage()->addCommandLineOption("--html <filename>","Print out slides to a series of html & image files."); arguments.getApplicationUsage()->addCommandLineOption("--loop","Switch on looping of presentation."); arguments.getApplicationUsage()->addCommandLineOption("--devices","Print the Video input capability via QuickTime and exit."); // add alias from xml to p3d to provide backwards compatibility for old p3d files. osgDB::Registry::instance()->addFileExtensionAlias("xml","p3d"); // if user requests devices video capability. if (arguments.read("-devices") || arguments.read("--devices")) { // Force load QuickTime plugin, probe video capability, exit osgDB::readImageFile("devices.live"); return 1; } // read any env vars from presentations before we create viewer to make sure the viewer // utilises these env vars if (p3d::readEnvVars(arguments)) { osg::DisplaySettings::instance()->readEnvironmentalVariables(); } // set up any logins required for http access std::string url, username, password; while(arguments.read("--login",url, username, password)) { if (!osgDB::Registry::instance()->getAuthenticationMap()) { osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap); osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails( url, new osgDB::AuthenticationDetails(username, password) ); } }#ifdef USE_SDL SDLIntegration sdlIntegration; osg::notify(osg::INFO)<<"USE_SDL"<<std::endl;#endif bool doSetViewer = true; std::string configurationFile; // check env vars for configuration file const char* str = getenv("PRESENT3D_CONFIG_FILE"); if (!str) str = getenv("OSG_CONFIG_FILE"); if (str) configurationFile = str; // check command line parameters for configuration file. while (arguments.read("-c",configurationFile)) {} osg::Vec4 clearColor(0.0f,0.0f,0.0f,0.0f); while (arguments.read("--clear-color",clearColor[0],clearColor[1],clearColor[2],clearColor[3])) {} std::string filename; if (arguments.read("--spell-check",filename)) { p3d::SpellChecker spellChecker; spellChecker.checkP3dXml(filename); return 1; } if (arguments.read("--strip-text",filename)) { p3d::XmlPatcher patcher; // patcher.stripP3dXml(filename, osg::notify(osg::NOTICE)); osg::ref_ptr<osgDB::XmlNode> newNode = patcher.simplifyP3dXml(filename); if (newNode.valid()) { newNode->write(std::cout); }//.........这里部分代码省略.........
开发者ID:ChrisWC,项目名称:osg,代码行数:101,
示例16: mainint main( int argc, char **argv ){ // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the a modified version of standard OpenSceneGraph example which loads and visualises 3d models and sounds."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line paramters"); arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available"); arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available"); arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindigs."); arguments.getApplicationUsage()->addCommandLineOption("--maxsounds <n>","Sets the maximum number of sounds allowed."); arguments.getApplicationUsage()->addCommandLineOption("--gain <n>","Sets the global gain (volume)"); arguments.getApplicationUsage()->addCommandLineOption("--dopplerfactor <n>","Sets the doppler factor"); arguments.getApplicationUsage()->addCommandLineOption("--distancemodel <mode>", "NONE | INVERSE_DISTANCE |INVERSE_DISTANCE_CLAMPED"); // construct the viewer. osgViewer::Viewer viewer(arguments); // get details on keyboard and mouse bindings used by the viewer. viewer.getUsage(*arguments.getApplicationUsage()); // if user request help write it out to cout. bool helpAll = arguments.read("--help-all"); unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) | ((helpAll || arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) | ((helpAll || arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 ); if (helpType) { arguments.getApplicationUsage()->write(std::cout, helpType); return 1; } // Parsing the sound-related options unsigned int maxSounds = OSGAL_DEFAULT_MAX_SOUNDSOURCES_ALLOWED; arguments.read("--maxsounds", maxSounds); float gain = OSGAL_DEFAULT_GAIN; arguments.read("--gain", gain); float dopplerFactor = OSGAL_DEFAULT_DOPPLER_FACTOR; arguments.read("--dopplerfactor", dopplerFactor); openalpp::DistanceModel distanceModel = OSGAL_DEFAULT_DISTANCE_MODEL; std::string s_model;#undef None // Someone in Linux is defining it 8| if (arguments.read("--distancemodel", s_model)) { if (s_model == "NONE") distanceModel = openalpp::None; else if (s_model == "INVERSE_DISTANCE") distanceModel = openalpp::InverseDistance; else if (s_model == "INVERSE_DISTANCE_CLAMPED") distanceModel = openalpp::InverseDistanceClamped; else osg::notify(osg::WARN) << "WARNING: I do not understand that -distancemodel parameter" << std::endl; } // report any errors if they have occured when parsing the program aguments. if (arguments.errors()) { arguments.writeErrorMessages(std::cout); return 1; } if (arguments.argc()<=1) { arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); return 1; } try { // here we init the SoundManager osgAL::SoundManager::instance()->init(maxSounds); osgAL::SoundManager::instance()->getEnvironment()->setGain(gain); osgAL::SoundManager::instance()->getEnvironment()->setDopplerFactor(dopplerFactor); osgAL::SoundManager::instance()->getEnvironment()->setDistanceModel(distanceModel); osg::Timer_t start_tick = osg::Timer::instance()->tick(); // read the scene from the list of file specified commandline args. osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); // if no model has been successfully loaded report failure. if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; } // any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); // report any errors if they have occured when parsing the program aguments. if (arguments.errors()) { arguments.writeErrorMessages(std::cout);//.........这里部分代码省略.........
开发者ID:leloulight,项目名称:lbanet,代码行数:101,
示例17: mainint main(int argc, char *argv[]) { std::signal(SIGINT, sigHandler); std::string source; std::string file_name; std::string save_path; po::options_description visible_options("OPTIONS"); try { po::options_description options("INFO"); options.add_options() ("help", "Produce help message.") ("version,v", "Print version information.") ; po::options_description config("CONFIGURATION"); config.add_options() ("filename,n", po::value<std::string>(&file_name), "The base snapshot file name./n" "The timestamp of the snapshot will be prepended to this name." "If not provided, the SOURCE name will be used./n") ("folder,f", po::value<std::string>(&save_path), "The folder in which snapshots will be saved.") ; po::options_description hidden("HIDDEN OPTIONS"); hidden.add_options() ("source", po::value<std::string>(&source), "The name of the frame SOURCE that supplies frames to view./n") ; po::positional_options_description positional_options; positional_options.add("source", -1); po::options_description all_options("ALL OPTIONS"); all_options.add(options).add(hidden); visible_options.add(options).add(config); po::variables_map variable_map; po::store(po::command_line_parser(argc, argv) .options(all_options) .positional(positional_options) .run(), variable_map); po::notify(variable_map); // Use the parsed options if (variable_map.count("help")) { printUsage(visible_options); return 0; } if (variable_map.count("version")) { std::cout << "Oat Frame Viewer version " << Oat_VERSION_MAJOR << "." << Oat_VERSION_MINOR << "/n"; std::cout << "Written by Jonathan P. Newman in the [email C++ viewport函数代码示例 C++ viewModified函数代码示例
|