Пример #1
0
/**
 * 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;
}
Пример #2
0
/**
 * Example of a test. To be completed.
 *
 */
bool testFitting()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;
  trace.beginBlock ( "Testing init ..." );

  using namespace Z3i;

  trace.beginBlock("Creating Surface");
  Point p1( -20, -20, -20 );
  Point p2( 20, 20, 20 );
   
  ImplicitBall<Z3i::Space> shape( RealPoint(6.0,0,0), 4);
  typedef GaussDigitizer<Z3i::Space, ImplicitBall<Z3i::Space> > Gauss;
  Gauss gauss;
  gauss.attach(shape);
  gauss.init(p1, p2, 1);
  
  typedef LightImplicitDigitalSurface<KSpace,  Gauss > SurfaceContainer;
  typedef DigitalSurface<SurfaceContainer> Surface;
  typedef Surface::Surfel Surfel;


  KSpace K;
  nbok += K.init( p1, p2, true ) ? 1 : 0;
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
               << "K.init() is ok" << std::endl;
  Surfel bel = Surfaces<KSpace>::findABel( K, gauss, 10000 );
  SurfaceContainer* surfaceContainer = new SurfaceContainer
    ( K, gauss, SurfelAdjacency<KSpace::dimension>( true ), bel );
  Surface surface( surfaceContainer ); // acquired
  CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
  trace.endBlock();

  trace.beginBlock("Normal vector field computation");
  typedef functors::ElementaryConvolutionNormalVectorEstimator<Surfel, CanonicSCellEmbedder<KSpace> > FunctorNormal;
  typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, Z3i::L2Metric,
                                                 FunctorNormal,
                                                 DGtal::functors::GaussianKernel> ReporterNormal;
  typedef EstimatorCache<ReporterNormal> NormalCache;

  //estimator
  DGtal::functors::GaussianKernel gaussKernelFunc(5.0);
  FunctorNormal functorNormal(embedder, 1.0);
  ReporterNormal reporterNormal;
  reporterNormal.attach(surface);
  reporterNormal.setParams(l2Metric, functorNormal, gaussKernelFunc, 5.0);

  //caching normal field
  NormalCache normalCache(reporterNormal);
  normalCache.init( 1, surface.begin(), surface.end());
  trace.info() << "Normal vector field cached... "<< normalCache << std::endl;
  trace.endBlock();

  trace.beginBlock("Creating  sphere fitting adapter from normal vector field");
  typedef functors::SphereFittingEstimator<Surfel, CanonicSCellEmbedder<KSpace> , NormalCache> Functor;
  typedef functors::ConstValue< double > ConvFunctor;
  typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, Z3i::L2Metric, Functor, ConvFunctor> Reporter;

  Functor fitter(embedder,1.0, 5.0, normalCache);
  ConvFunctor convFunc(1.0);
  Reporter reporter;
  reporter.attach(surface);
  reporter.setParams(l2Metric, fitter , convFunc, 15.0);
  
  reporter.init(1, surface.begin(), surface.end());
  for(Surface::ConstIterator it = surface.begin(), ite=surface.end(); it!=ite; ++it)
    {
      Functor::Quantity val = reporter.eval( it );
      trace.info() << "Fitting = "<<val.center <<" rad="<<val.radius<<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;
}