int main( int argc, char** argv ) { //! [frontierAndBoundary-LabelledImage] typedef Space::RealPoint RealPoint; typedef ImplicitBall<Space> EuclideanShape; typedef GaussDigitizer<Space,EuclideanShape> DigitalShape; typedef ImageContainerBySTLVector<Domain,DGtal::uint8_t> Image; Point c1( 2, 0, 0 ); int radius1 = 6; EuclideanShape ball1( c1, radius1 ); // ball r=6 DigitalShape shape1; shape1.attach( ball1 ); shape1.init( RealPoint( -10.0, -10.0, -10.0 ), RealPoint( 10.0, 10.0, 10.0 ), 1.0 ); Point c2( -2, 0, 0 ); int radius2 = 5; EuclideanShape ball2( c2, radius2 ); // ball r=6 DigitalShape shape2; shape2.attach( ball2 ); shape2.init( RealPoint( -10.0, -10.0, -10.0 ), RealPoint( 10.0, 10.0, 10.0 ), 1.0 ); Domain domain = shape1.getDomain(); Image image( domain ); // p1, p2 ); std::cerr << std::endl; for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end(); it != it_end; ++it ) { DGtal::uint8_t label = shape1( *it ) ? 1 : 0; label += shape2( *it ) ? 2 : 0; image.setValue( *it, label ); std::cerr << (int) image( *it ); } std::cerr << std::endl; //! [frontierAndBoundary-LabelledImage] //! [frontierAndBoundary-KSpace] trace.beginBlock( "Construct the Khalimsky space from the image domain." ); KSpace K; bool space_ok = K.init( domain.lowerBound(), domain.upperBound(), true ); if (!space_ok) { trace.error() << "Error in the Khamisky space construction."<<std::endl; return 2; } trace.endBlock(); //! [frontierAndBoundary-KSpace] //! [frontierAndBoundary-SetUpDigitalSurface] trace.beginBlock( "Set up digital surface." ); typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency; MySurfelAdjacency surfAdj( true ); // interior in all directions. typedef functors::FrontierPredicate<KSpace, Image> FSurfelPredicate; typedef ExplicitDigitalSurface<KSpace,FSurfelPredicate> FrontierContainer; typedef DigitalSurface<FrontierContainer> Frontier; typedef functors::BoundaryPredicate<KSpace, Image> BSurfelPredicate; typedef ExplicitDigitalSurface<KSpace,BSurfelPredicate> BoundaryContainer; typedef DigitalSurface<BoundaryContainer> Boundary; // frontier between label 1 and 0 (connected part containing bel10) SCell vox1 = K.sSpel( c1 + Point( radius1, 0, 0 ), K.POS ); SCell bel10 = K.sIncident( vox1, 0, true ); FSurfelPredicate surfPredicate10( K, image, 1, 0 ); Frontier frontier10 = new FrontierContainer( K, surfPredicate10, surfAdj, bel10 ); // frontier between label 2 and 0 (connected part containing bel20) SCell vox2 = K.sSpel( c2 - Point( radius2, 0, 0 ), K.POS ); SCell bel20 = K.sIncident( vox2, 0, false ); FSurfelPredicate surfPredicate20( K, image, 2, 0 ); Frontier frontier20 = new FrontierContainer( K, surfPredicate20, surfAdj, bel20 ); // boundary of label 3 (connected part containing bel32) SCell vox3 = K.sSpel( c1 - Point( radius1, 0, 0 ), K.POS ); SCell bel32 = K.sIncident( vox3, 0, false ); BSurfelPredicate surfPredicate3( K, image, 3 ); Boundary boundary3 = new BoundaryContainer( K, surfPredicate3, surfAdj, bel32 ); trace.endBlock(); //! [frontierAndBoundary-SetUpDigitalSurface] //! [volBreadthFirstTraversal-DisplayingSurface] trace.beginBlock( "Displaying surface in Viewer3D." ); QApplication application(argc,argv); Viewer3D<> viewer; viewer.show(); viewer << SetMode3D( domain.className(), "BoundingBox" ) << domain; Cell dummy; // Display frontier between 1 and 0. unsigned int nbSurfels10 = 0; viewer << CustomColors3D( Color::Red, Color::Red ); for ( Frontier::ConstIterator it = frontier10.begin(), it_end = frontier10.end(); it != it_end; ++it, ++nbSurfels10 ) viewer << *it; // Display frontier between 2 and 0. unsigned int nbSurfels20 = 0; viewer << CustomColors3D( Color::Yellow, Color::Yellow ); for ( Frontier::ConstIterator it = frontier20.begin(), it_end = frontier20.end(); it != it_end; ++it, ++nbSurfels20 ) viewer << *it; // Display boundary of 3. unsigned int nbSurfels3 = 0; viewer << CustomColors3D( Color( 255, 130, 15 ), Color( 255, 130, 15 ) ); for ( Boundary::ConstIterator it = boundary3.begin(), it_end = boundary3.end(); it != it_end; ++it, ++nbSurfels3 ) viewer << *it; trace.info() << "nbSurfels10 = " << nbSurfels10 << ", nbSurfels20 = " << nbSurfels20 << ", nbSurfels3 = " << nbSurfels3 << std::endl; viewer << Viewer3D<>::updateDisplay; trace.endBlock(); return application.exec(); //! [volBreadthFirstTraversal-DisplayingSurface] }
int main( int argc, char** argv ) { if ( argc < 9 ) { usage( argc, argv ); return 1; } double p1[ 3 ]; double p2[ 3 ]; for ( unsigned int i = 0; i < 3; ++i ) { p1[ i ] = atof( argv[ 2 + i ] ); p2[ i ] = atof( argv[ 5 + i ] ); } double step = atof( argv[ 8 ] ); Polynomial3 P; Polynomial3Reader reader; std::string poly_str = argv[ 1 ]; std::string::const_iterator iter = reader.read( P, poly_str.begin(), poly_str.end() ); if ( iter != poly_str.end() ) { std::cerr << "ERROR: I read only <" << poly_str.substr( 0, iter - poly_str.begin() ) << ">, and I built P=" << P << std::endl; return 1; } ImplicitShape ishape( P ); DigitalShape dshape; dshape.attach( ishape ); dshape.init( RealPointT( p1 ), RealPointT( p2 ), step ); Domain domain = dshape.getDomain(); KSpace K; bool space_ok = K.init( domain.lowerBound(), domain.upperBound(), true ); if ( !space_ok ) { trace.error() << "Error in the Khamisky space construction." << std::endl; return 2; } typedef SurfelAdjacency< KSpace::dimension > MySurfelAdjacency; MySurfelAdjacency surfAdj( true ); // interior in all directions. typedef KSpace::Surfel Surfel; typedef KSpace::SurfelSet SurfelSet; typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels; MySetOfSurfels theSetOfSurfels( K, surfAdj ); Surfel bel = Surfaces< KSpace >::findABel( K, dshape, 100000 ); Surfaces< KSpace >::trackBoundary( theSetOfSurfels.surfelSet(), K, surfAdj, dshape, bel ); QApplication application( argc, argv ); Viewer3D<> viewer; viewer.show(); viewer << SetMode3D( domain.className(), "BoundingBox" ) << domain; //----------------------------------------------------------------------- // Looking for the min and max values double minCurv = 1; double maxCurv = 0; CanonicSCellEmbedder< KSpace > midpoint( K ); for ( std::set< SCell >::iterator it = theSetOfSurfels.begin(), it_end = theSetOfSurfels.end(); it != it_end; ++it) { RealPointT A = midpoint( *it ) * step; A = ishape.nearestPoint (A,0.01,200,0.1*step); double a = ishape.meanCurvature( A ); // double a=ishape.gaussianCurvature(A); if ( !boost::math::isnan( a )) { if ( a > maxCurv ) { maxCurv = a; } else if ( a < minCurv ) { minCurv = a; } } } trace.info() << " Min = " << minCurv << std::endl; trace.info() << " Max = " << maxCurv << std::endl; //----------------------------------------------------------------------- //Specifing a color map GradientColorMap< double > cmap_grad( minCurv, maxCurv ); cmap_grad.addColor( Color( 50, 50, 255 ) ); cmap_grad.addColor( Color( 255, 0, 0 ) ); cmap_grad.addColor( Color( 255, 255, 10 ) ); //------------------------------------------------------------------------------------ //drawing unsigned int nbSurfels = 0; for ( std::set<SCell>::iterator it = theSetOfSurfels.begin(), it_end = theSetOfSurfels.end(); it != it_end; ++it, ++nbSurfels ) { RealPointT A = midpoint( *it ) * step; A = ishape.nearestPoint (A,0.01,200,0.1*step); // double a=ishape.gaussianCurvature(A); double a = ishape.meanCurvature( A ); if ( boost::math::isnan( a )) { a = 0; } viewer << CustomColors3D( Color::Black, cmap_grad( a )); viewer << *it; } viewer << Viewer3D<>::updateDisplay; return application.exec(); }
int main(int argc, char** argv) { // -------------------------------------------------------------------------- Type declaring typedef Space::RealPoint RealPoint; typedef Ellipsoid<Space> EuclideanShape; typedef GaussDigitizer<Space,EuclideanShape> DigitalShape; typedef ImageContainerBySTLVector<Domain,DGtal::uint8_t> Image; // -------------------------------------------------------------------------- Creating the shape RealPoint c1(0, 0, 0 ); RealPoint factors(6,6,12); EuclideanShape ball1( c1, factors ); // -------------------------------------------------------------------------- GaussDigitizing DigitalShape dshape; dshape.attach( ball1 ); RealPoint p1 =RealPoint( -15.0, -15.0, -15.0 ); RealPoint p2 =RealPoint( 15.0, 15.0, 15.0 ); dshape.init( RealPoint( p1 ), RealPoint( p2 ), 1.0); Domain domain = dshape.getDomain(); // -------------------------------------------------------------------------- Khalimskhy KSpace K; bool space_ok = K.init( domain.lowerBound(), domain.upperBound(), true ); if (!space_ok) { return 2; } // -------------------------------------------------------------------------- Other types typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency; typedef KSpace::Surfel Surfel; typedef KSpace::SurfelSet SurfelSet; typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels; typedef DigitalSurface< MySetOfSurfels > MyDigitalSurface; // -------------------------------------------------------------------------- Tracking the boudnadry MySurfelAdjacency surfAdj( true ); // interior in all directions. MySetOfSurfels theSetOfSurfels( K, surfAdj ); Surfel bel = Surfaces<KSpace>::findABel( K, dshape, 1000 ); Surfaces<KSpace>::trackBoundary( theSetOfSurfels.surfelSet(), K, surfAdj, dshape, bel ); QApplication application(argc,argv); Viewer3D viewer; viewer.show(); viewer << SetMode3D( domain.className(), "BoundingBox" ) << domain; //----------------------------------------------------------------------- Specifing a color map GradientColorMap<double> cmap_grad( 10, 20 ); cmap_grad.addColor( Color( 50, 50, 255 ) ); cmap_grad.addColor( Color( 255, 0, 0 ) ); cmap_grad.addColor( Color( 255, 255, 10 ) ); //----------------------------------------------------------------------- Drawing the ball && giving a color to the surfels( depending on the curvature) unsigned int nbSurfels = 0; SCellToMidPoint<KSpace> midpoint(K); for ( std::set<SCell>::iterator it = theSetOfSurfels.begin(), it_end = theSetOfSurfels.end(); it != it_end; ++it, ++nbSurfels ) { RealPoint A = midpoint( *it ); DGtal::StarShaped3D<Space>::AngularCoordinates Angles= ball1.parameter(A); double curvature =ball1.meanCurvature(Angles); viewer << CustomColors3D( Color::Black, cmap_grad( curvature)); viewer << *it; } viewer << Viewer3D::updateDisplay; return application.exec(); }