/** * Example of a test. To be completed. * */ bool testLocalEstimatorFromFunctorAdapter() { unsigned int nbok = 0; unsigned int nb = 0; trace.beginBlock ( "Testing init ..." ); using namespace Z3i; typedef ImplicitDigitalEllipse3<Point> ImplicitDigitalEllipse; typedef LightImplicitDigitalSurface<KSpace,ImplicitDigitalEllipse> SurfaceContainer; typedef DigitalSurface<SurfaceContainer> Surface; //typedef Surface::SurfelConstIterator ConstIterator; //typedef Surface::Tracker Tracker; typedef Surface::Surfel Surfel; trace.beginBlock("Creating Surface"); Point p1( -10, -10, -10 ); Point p2( 10, 10, 10 ); KSpace K; nbok += K.init( p1, p2, true ) ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "K.init() is ok" << std::endl; ImplicitDigitalEllipse ellipse( 6.0, 4.5, 3.4 ); Surfel bel = Surfaces<KSpace>::findABel( K, ellipse, 10000 ); SurfaceContainer* surfaceContainer = new SurfaceContainer ( K, ellipse, SurfelAdjacency<KSpace::dimension>( true ), bel ); Surface surface( surfaceContainer ); // acquired trace.endBlock(); trace.beginBlock("Creating adapters"); typedef functors::MongeJetFittingGaussianCurvatureEstimator<Surfel, CanonicSCellEmbedder<KSpace> > FunctorGaussian; typedef functors::MongeJetFittingPrincipalCurvaturesEstimator<Surfel, CanonicSCellEmbedder<KSpace> > FunctorPrincipalCurvatures; typedef functors::MongeJetFittingMeanCurvatureEstimator<Surfel, CanonicSCellEmbedder<KSpace> > FunctorMean; typedef functors::MongeJetFittingNormalVectorEstimator<Surfel, CanonicSCellEmbedder<KSpace> > FunctorNormal; typedef functors::LinearLeastSquareFittingNormalVectorEstimator<Surfel, CanonicSCellEmbedder<KSpace> > FunctorNormalLeast; typedef functors::ConstValue< double > ConvFunctor; typedef LpMetric<Space> L2Metric; typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, L2Metric, FunctorGaussian, ConvFunctor> ReporterK; typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, L2Metric, FunctorPrincipalCurvatures, ConvFunctor> Reporterk1k2; typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, L2Metric, FunctorMean, ConvFunctor> ReporterH; typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, L2Metric, FunctorNormal, ConvFunctor> ReporterNormal; typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, L2Metric, FunctorNormalLeast, ConvFunctor> ReporterNormalLeast; CanonicSCellEmbedder<KSpace> embedder(surface.container().space()); FunctorGaussian estimatorK(embedder,1); FunctorPrincipalCurvatures estimatork1k2(embedder,1); FunctorMean estimatorH(embedder, 1); FunctorNormal estimatorN(embedder,1); FunctorNormalLeast estimatorL(embedder,1); ConvFunctor convFunc(1.0); ReporterK reporterK; Reporterk1k2 reporterk1k2; ReporterH reporterH; ReporterNormal reporterN; ReporterNormalLeast reporterL; reporterK.attach(surface); reporterk1k2.attach(surface); reporterH.attach(surface); reporterN.attach(surface); reporterL.attach(surface); reporterK.init(1, surface.begin(), surface.end()); reporterk1k2.init(1, surface.begin(), surface.end()); reporterH.init(1, surface.begin(), surface.end()); reporterN.init(1, surface.begin(), surface.end()); reporterL.init(1, surface.begin(), surface.end()); L2Metric l2(2.0); reporterK.setParams(l2, estimatorK, convFunc, 5.0); reporterk1k2.setParams(l2, estimatork1k2, convFunc, 5.0); reporterH.setParams(l2, estimatorH, convFunc, 5.0); reporterN.setParams(l2, estimatorN, convFunc, 5.0); reporterL.setParams(l2, estimatorL, convFunc, 5.0); FunctorGaussian::Quantity valK = reporterK.eval( surface.begin()); FunctorPrincipalCurvatures::Quantity valk1k2 = reporterk1k2.eval( surface.begin()); FunctorMean::Quantity valH = reporterH.eval( surface.begin()); FunctorNormal::Quantity valN = reporterN.eval( surface.begin()); FunctorNormalLeast::Quantity valL = reporterL.eval( surface.begin()); trace.info() << "Gaussian = "<<valK <<std::endl; trace.info() << "k1 = " << valk1k2.first << " , k2 = " << valk1k2.second <<std::endl; trace.info() << "Mean = "<<valH<< std::endl; trace.info() << "Normal Vector (from Monge form) = "<<valN<< std::endl; trace.info() << "Normal Vector (linear least square) = "<<valL<< std::endl; trace.endBlock(); trace.endBlock(); nbok += true ? 1 : 0; nb++; trace.info() << "(" << nbok << "/" << nb << ") " << "true == true" << std::endl; return nbok == nb; }
int main( ) { //! [SurfelFunctorsInit] using namespace Z3i; typedef ImplicitDigitalEllipse3<Point> ImplicitDigitalEllipse; typedef LightImplicitDigitalSurface<KSpace,ImplicitDigitalEllipse> SurfaceContainer; typedef DigitalSurface< SurfaceContainer > Surface; typedef SurfaceContainer::Surfel Surfel; Point p1( -10, -10, -10 ); Point p2( 10, 10, 10 ); KSpace K; K.init( p1, p2, true ); ImplicitDigitalEllipse ellipse( 6.0, 4.5, 3.4 ); Surfel bel = Surfaces<KSpace>::findABel( K, ellipse, 10000 ); SurfaceContainer* surfaceContainer = new SurfaceContainer ( K, ellipse, SurfelAdjacency<KSpace::dimension>( true ), bel ); Surface surface( surfaceContainer ); // acquired //! [SurfelFunctorsInit] //! [SurfelFunctorsType] #ifdef WITH_CGAL typedef DGtal::functors::MongeJetFittingGaussianCurvatureEstimator<Surfel, CanonicSCellEmbedder<KSpace> > FunctorGaussian; typedef functors::MongeJetFittingMeanCurvatureEstimator<Surfel, CanonicSCellEmbedder<KSpace> > FunctorMean; typedef functors::MongeJetFittingNormalVectorEstimator<Surfel, CanonicSCellEmbedder<KSpace> > FunctorNormal; typedef functors::LinearLeastSquareFittingNormalVectorEstimator<Surfel, CanonicSCellEmbedder<KSpace> > FunctorNormalLeast; //constant convolution functor typedef functors::ConstValue<double> ConstFunctor; typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, Z3i::L2Metric, FunctorGaussian, ConstFunctor> ReporterK; typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, Z3i::L2Metric, FunctorMean, ConstFunctor> ReporterH; typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, Z3i::L2Metric, FunctorNormal, ConstFunctor> ReporterNormal; typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, Z3i::L2Metric, FunctorNormalLeast, ConstFunctor> ReporterNormalLeast; #endif ///For Elmentary convolution, we specify a Gaussian convolution ///kernel from the BasicFunctors.h file typedef functors::ElementaryConvolutionNormalVectorEstimator<Surfel, CanonicSCellEmbedder<KSpace> > FunctorNormalElem; typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, Z3i::L2Metric, FunctorNormalElem, DGtal::functors::GaussianKernel> ReporterNormalElem; //! [SurfelFunctorsType] //! [SurfelFunctorsInstances] CanonicSCellEmbedder<KSpace> embedder(surface.container().space()); #ifdef WITH_CGAL ///Creating functors for h=1.0 FunctorGaussian estimatorK(embedder,1.0); FunctorMean estimatorH(embedder, 1.0); FunctorNormal estimatorN(embedder,1.0); FunctorNormalLeast estimatorL(embedder,1.0); ConstFunctor constFunctor(1.0); ReporterK reporterK; ReporterH reporterH; ReporterNormal reporterN; ReporterNormalLeast reporterL; #endif FunctorNormalElem estimatorNormalElem(embedder,1.0); ///sigma = 2.0 for the gaussian smoothing DGtal::functors::GaussianKernel gaussian(2.0); ReporterNormalElem reporterElem(surface, l2Metric, estimatorNormalElem, gaussian); //! [SurfelFunctorsInstances] //! [SurfelFunctorsEstim] #ifdef WITH_CGAL reporterK.attach(surface); reporterH.attach(surface); reporterN.attach(surface); reporterL.attach(surface); reporterK.init(1, surface.begin(), surface.end()); reporterH.init(1, surface.begin(), surface.end()); reporterN.init(1, surface.begin(), surface.end()); reporterL.init(1, surface.begin(), surface.end()); reporterK.setParams(l2Metric, estimatorK, constFunctor, 5.0); reporterH.setParams(l2Metric, estimatorH, constFunctor, 5.0); reporterN.setParams(l2Metric, estimatorN, constFunctor, 5.0); reporterL.setParams(l2Metric, estimatorL, constFunctor, 5.0); FunctorGaussian::Quantity valK = reporterK.eval( surface.begin()); FunctorMean::Quantity valH = reporterH.eval( surface.begin()); FunctorNormal::Quantity valN = reporterN.eval( surface.begin()); FunctorNormalLeast::Quantity valL = reporterL.eval( surface.begin()); #endif reporterElem.attach(surface); reporterElem.setParams(l2Metric, estimatorNormalElem, gaussian, 5.0); reporterElem.init(1.0, surface.begin(), surface.end()); FunctorNormalElem::Quantity valElem = reporterElem.eval( surface.begin()); #ifdef WITH_CGAL trace.info() << "Gaussian = "<<valK <<std::endl; trace.info() << "Mean = "<<valH<< std::endl; trace.info() << "Normal Vector (from Monge form) = "<<valN<< std::endl; trace.info() << "Normal Vector (linear least square) = "<<valL<< std::endl; #endif trace.info() << "Normal Vector (Elementary conv) = "<<valElem<< std::endl; //! [SurfelFunctorsEstim] return 0; }