int main( int argc, char** argv ) { trace.info() << "exampleGridCurve3d: the type of data to be displayed " << "may be given as argument as follows: " << argv[0] << " scells" << endl; trace.info() << "Available types are: gridcurve (default), scells, points, midpoints, arrows" << endl; string type = (argc > 1) ? string(argv[1]) : "gridcurve"; trace.info() << "Chosen type: " << type << endl; //curve string sinus = examplesPath + "samples/sinus.dat"; // domain Point lowerBound = Point::diagonal( -100 ); Point upperBound = Point::diagonal( 100 ); //! [GridCurveDeclaration] K3 ks; ks.init( lowerBound, upperBound, true ); GridCurve<K3> gc( ks ); //! [GridCurveDeclaration] //! [GridCurveFromDataFile] fstream inputStream; inputStream.open (sinus.c_str(), ios::in); gc.initFromVectorStream(inputStream); inputStream.close(); //! [GridCurveFromDataFile] bool flag = false; #ifdef WITH_VISU3D_QGLVIEWER QApplication application(argc,argv); Viewer3D<Space,K3> viewer(ks); viewer.show(); if (type == "gridcurve") { viewer << gc; } else if (type == "scells") { viewer << gc.getSCellsRange(); } else if (type == "points") { viewer << gc.getPointsRange(); } else if (type == "midpoints") { viewer << gc.getMidPointsRange(); } else if (type == "arrows") { viewer << gc.getArrowsRange(); } else { trace.info() << "Display type not known." << std::endl; } viewer << Viewer3D<Space,K3>::updateDisplay; flag = application.exec(); #endif return flag; }
/** * Example of a test. To be completed. * */ bool testSCellsFunctors() { unsigned int nbok = 0; unsigned int nb = 0; trace.beginBlock ( "Testing block ..." ); //0-scell 2 point { typedef KhalimskySpaceND<3> K3; K3 theKSpace; SCellToPoint<K3> m(theKSpace); K3::SCell s = theKSpace.sPointel( K3::Point(3,3,4) ); K3::Point aPoint = m( s ); trace.info() << s << aPoint <<std::endl; nbok += ( aPoint == K3::Point(3,3,4) ) ? 1 : 0; nb++; } trace.info() << "(" << nbok << "/" << nb << ") " << std::endl; //1-scell 2 point { typedef KhalimskySpaceND<3> K3; K3 theKSpace; SCellToPoint<K3> m(theKSpace); K3::SCell s(K3::Point(0,0,0), true); //default point and orientation theKSpace.sSetKCoords( s, K3::Point(5,6,8) ); K3::Point aPoint = m( s ); trace.info() << s << aPoint <<std::endl; nbok += ( aPoint == K3::Point(3,3,4) ) ? 1 : 0; nb++; } trace.info() << "(" << nbok << "/" << nb << ") " << std::endl; //scell 2 midPoint { typedef KhalimskySpaceND<2> K2; K2 theKSpace; CanonicSCellEmbedder<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); K2::Space::RealPoint aPoint = m( s ); trace.info() << s << aPoint <<std::endl; nbok += ( aPoint == K2::Space::RealPoint(-0.5,0) ) ? 1 : 0; nb++; } trace.info() << "(" << nbok << "/" << nb << ") " << std::endl; //scell 2 arrow { typedef KhalimskySpaceND<2> K2; K2 theKSpace; SCellToArrow<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); std::pair<K2::Point, K2::Vector> aArrow = m( s ); trace.info() << s << aArrow.first << aArrow.second <<std::endl; K2::Point p(0,1); K2::Vector v(0,-1); nbok += ( ((aArrow.first == p) && (aArrow.second == v)) ) ? 1 : 0; nb++; } trace.info() << "(" << nbok << "/" << nb << ") " << std::endl; //scell 2 inner point { typedef KhalimskySpaceND<2> K2; K2 theKSpace; SCellToInnerPoint<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); K2::Point aPoint = m( s ); trace.info() << s << aPoint <<std::endl; nbok += ( aPoint == K2::Point(0,0) ) ? 1 : 0; nb++; } trace.info() << "(" << nbok << "/" << nb << ") " << std::endl; //scell 2 outer point { typedef KhalimskySpaceND<2> K2; K2 theKSpace; SCellToOuterPoint<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); K2::Point aPoint = m( s ); trace.info() << s << aPoint <<std::endl; nbok += ( aPoint == K2::Point(-1,0) ) ? 1 : 0; nb++; } trace.info() << "(" << nbok << "/" << nb << ") " << std::endl; //scell 2 incident pixels { typedef KhalimskySpaceND<2> K2; K2 theKSpace; SCellToIncidentPoints<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); std::pair<K2::Point, K2::Point> aPair = m( s ); trace.info() << s << aPair.first << aPair.second <<std::endl; K2::Point p1(0,0); K2::Point p2(-1,0); nbok += ( ((aPair.first == p1) && (aPair.second == p2)) ) ? 1 : 0; nb++; } trace.info() << "(" << nbok << "/" << nb << ") " << std::endl; //scell 2 code { typedef KhalimskySpaceND<2> K2; K2 theKSpace; SCellToCode<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); char aCode = m( s ); trace.info() << s << aCode <<std::endl; nbok += ( aCode == '3' ) ? 1 : 0; nb++; } trace.info() << "(" << nbok << "/" << nb << ") " << std::endl; trace.endBlock(); return nbok == nb; }
/** * Example of a test. To be completed. * */ bool testModifier() { unsigned int nbok = 0; unsigned int nb = 0; trace.beginBlock ( "Testing block ..." ); //scell 2 point { typedef KhalimskySpaceND<3> K3; K3 theKSpace; SCellToPoint<K3> m(theKSpace); K3::SCell s = theKSpace.sPointel( K3::Point(3,3,4) ); K3::Point aPoint = m.get( s ); trace.info() << s << aPoint <<std::endl; nbok += ( aPoint == K3::Point(3,3,4) ) ? 1 : 0; nb++; } //scell 2 midPoint { typedef KhalimskySpaceND<2> K2; K2 theKSpace; SCellToMidPoint<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); PointVector<K2::dimension,double> aPoint = m.get( s ); trace.info() << s << aPoint <<std::endl; nbok += ( aPoint == PointVector<K2::dimension,double>(0,0.5) ) ? 1 : 0; nb++; } //scell 2 arrow { typedef KhalimskySpaceND<2> K2; K2 theKSpace; SCellToArrow<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); std::pair<K2::Point, K2::Vector> aArrow = m.get( s ); trace.info() << s << aArrow.first << aArrow.second <<std::endl; K2::Point p(0,1); K2::Vector v(0,-1); nbok += ( ((aArrow.first == p) && (aArrow.second == v)) ) ? 1 : 0; nb++; } //scell 2 inner point { typedef KhalimskySpaceND<2> K2; K2 theKSpace; SCellToInnerPoint<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); K2::Point aPoint = m.get( s ); trace.info() << s << aPoint <<std::endl; nbok += ( aPoint == K2::Point(-1,0) ) ? 1 : 0; nb++; } //scell 2 outer point { typedef KhalimskySpaceND<2> K2; K2 theKSpace; SCellToOuterPoint<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); K2::Point aPoint = m.get( s ); trace.info() << s << aPoint <<std::endl; nbok += ( aPoint == K2::Point(0,0) ) ? 1 : 0; nb++; } //scell 2 incident pixels { typedef KhalimskySpaceND<2> K2; K2 theKSpace; SCellToIncidentPoints<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); std::pair<K2::Point, K2::Point> aPair = m.get( s ); trace.info() << s << aPair.first << aPair.second <<std::endl; K2::Point p1(-1,0); K2::Point p2(0,0); nbok += ( ((aPair.first == p1) && (aPair.second == p2)) ) ? 1 : 0; nb++; } //scell 2 code { typedef KhalimskySpaceND<2> K2; K2 theKSpace; SCellToCode<K2> m(theKSpace); K2::SCell s = theKSpace.sCell( K2::Point(0,1) ); char aCode = m.get( s ); trace.info() << s << aCode <<std::endl; nbok += ( aCode == '3' ) ? 1 : 0; nb++; } trace.info() << "(" << nbok << "/" << nb << ") " << std::endl; trace.endBlock(); return nbok == nb; }
/** Main function. @param argc the number of parameters given on the line command. @param argv an array of C-string, such that argv[0] is the name of the program, argv[1] the first parameter, etc. */ int main(int argc, char **argv) { typedef SpaceND<3,int> Z3; typedef KhalimskySpaceND<3,int> K3; typedef Z3::Point Point; typedef Z3::RealPoint RealPoint; // specify command line ---------------------------------------------- QApplication application(argc,argv); // remove Qt arguments. po::options_description general_opt("Specific allowed options (for Qt options, see Qt official site) are: "); general_opt.add_options() ("help,h", "display this message") ("input,i", po::value<std::string>(), "the name of the text file containing the list of 3D points (x y z per line)" ) ("box,b", po::value<int>()->default_value( 0 ), "specifies the the tightness of the bounding box around the curve with a given integer displacement <arg> to enlarge it (0 is tight)" ) ("viewBox,v", po::value<string>()->default_value( "WIRED" ), "displays the bounding box, <arg>=WIRED means that only edges are displayed, <arg>=COLORED adds colors for planes (XY is red, XZ green, YZ, blue)." ) ("curve3d,C", "displays the 3D curve") ("curve2d,c", "displays the 2D projections of the 3D curve on the bounding box") ("cover3d,3", "displays the 3D tangential cover of the curve" ) ("cover2d,2", "displays the 2D projections of the 3D tangential cover of the curve" ) ("nbColors,n", po::value<int>()->default_value( 3 ), "sets the number of successive colors used for displaying 2d and 3d maximal segments (default is 3: red, green, blue)" ) ("tangent,t", "displays the tangents to the curve" ) ; po::positional_options_description pos_opt; pos_opt.add("input", 1); // parse command line ---------------------------------------------- bool parseOK=true; po::variables_map vm; try { po::command_line_parser clp( argc, argv ); clp.options( general_opt ).positional( pos_opt ); po::store( clp.run(), vm ); } catch( const std::exception& ex ) { parseOK = false; trace.info() << "Error checking program options: "<< ex.what() << endl; } po::notify( vm ); if( !parseOK || vm.count("help")||argc<=1) { std::cout << "Usage: " << argv[0] << " [options] input\n" << "Display a 3D curve given as the <input> filename (with possibly projections and/or tangent information) by using QGLviewer.\n" << general_opt << "\n\n"; std::cout << "Example:\n" << "3dCurveViewer -C -b 1 -3 -2 -c ${DGtal}/examples/samples/sinus.dat\n"; return 0; } // process command line ---------------------------------------------- string input = vm["input"].as<std::string>(); int b = vm["box"].as<int>(); // Create curve 3D. vector<Point> sequence; fstream inputStream; inputStream.open ( input.c_str(), ios::in); try { sequence = PointListReader<Point>::getPointsFromInputStream( inputStream ); if ( sequence.size() == 0) throw IOException(); } catch (DGtal::IOException & ioe) { trace.error() << "Size is null." << std::endl; } inputStream.close(); // start viewer Viewer3D<> viewer; trace.beginBlock ( "Tool 3dCurveViewer" ); // ---------------------------------------------------------------------- // Create domain and curve. Point lowerBound = sequence[ 0 ]; Point upperBound = sequence[ 0 ]; for ( unsigned int j = 1; j < sequence.size(); ++j ) { lowerBound = lowerBound.inf( sequence[ j ] ); upperBound = upperBound.sup( sequence[ j ] ); } lowerBound -= Point::diagonal( b ); upperBound += Point::diagonal( b+1 ); K3 ks; ks.init( lowerBound, upperBound, true ); GridCurve<K3> gc( ks ); try { gc.initFromPointsVector( sequence ); } catch (DGtal::ConnectivityException& /*ce*/) { throw ConnectivityException(); return false; } // ---------------------------------------------------------------------- // Displays everything. viewer.show(); // Display axes. if ( vm.count( "viewBox" ) ) displayAxes<Point,RealPoint, Z3i::Space, Z3i::KSpace>( viewer, lowerBound, upperBound, vm[ "viewBox" ].as<std::string>() ); // Display 3D tangential cover. bool res = displayCover( viewer, ks, sequence.begin(), sequence.end(), vm.count( "cover3d" ), vm.count( "curve2d" ), vm.count( "cover2d" ), vm.count( "tangent" ), vm["nbColors"].as<int>() ); // Display 3D curve points. if ( vm.count( "curve3d" ) ) viewer << CustomColors3D( CURVE3D_COLOR, CURVE3D_COLOR ) << gc.getPointsRange() << sequence.back(); // curiously, last point is not displayed. // ---------------------------------------------------------------------- // User "interaction". viewer << Viewer3D<>::updateDisplay; application.exec(); trace.emphase() << ( res ? "Passed." : "Error." ) << endl; trace.endBlock(); return res ? 0 : 1; }