Beispiel #1
0
/**
 * L1 test
 *
 */
bool testL1LengthEstimator(std::string &filename)
{

    trace.info() << "Reading GridCurve " << endl;

    ifstream instream; // input stream
    instream.open (filename.c_str(), ifstream::in);

    GridCurve<KhalimskySpaceND<2> > c; //grid curve
    c.initFromVectorStream(instream);

    //////////////////////// L1
    GridCurve<KhalimskySpaceND<2> >::ArrowsRange ra = c.getArrowsRange(); //range
    L1LengthEstimator<  GridCurve<KhalimskySpaceND<2> >::ArrowsRange::ConstIterator > l1length;
    TwoStepLocalLengthEstimator<  GridCurve<KhalimskySpaceND<2> >::ArrowsRange::ConstIterator > locallength(1.0,sqrt(2.0));

    l1length.init(1, ra.begin(), ra.end(), c.isClosed());
    trace.info() << "L1 length (h=1) = "<< l1length.eval()<<std::endl;

    l1length.init(10, ra.begin(), ra.end(), c.isClosed());
    trace.info() << "L1 length (h=10) = "<< l1length.eval()<<std::endl;

    ////////////////////// Local 2steps
    TwoStepLocalLengthEstimator<  GridCurve<KhalimskySpaceND<2> >::ArrowsRange::ConstIterator > locallength(1.0,sqrt(2.0));

    localength.init(1, ra.begin(), ra.end(), c.isClosed());
    trace.info() << "Local length (h=1) = "<< localength.eval()<<std::endl;


    //////////////////////// MLP
    GridCurve<KhalimskySpaceND<2> >::PointsRange rp = c.getPointsRange(); //range
    MLPLengthEstimator<  GridCurve<KhalimskySpaceND<2> >::PointsRange::ConstIterator > MLPlength;

    MLPlength.init(1, rp.begin(), rp.end(), c.isClosed());
    trace.info() << "MLP Length (h=1) = "<< MLPlength.eval()<<std::endl;

    MLPlength.init(10, rp.begin(), rp.end(), c.isClosed());
    trace.info() << "MLP Length (h=10) = "<< MLPlength.eval()<<std::endl;

    //////////////////////// FP
    FPLengthEstimator<  GridCurve<KhalimskySpaceND<2> >::PointsRange::ConstIterator > FPlength;

    FPlength.init(1, rp.begin(), rp.end(), c.isClosed());
    trace.info() << "FP Length (h=1) = "<< FPlength.eval()<<std::endl;

    FPlength.init(10, rp.begin(), rp.end(), c.isClosed());
    trace.info() << "FP Length (h=10) = "<< FPlength.eval()<<std::endl;

    //////////////////////// DSS
    DSSLengthEstimator<  GridCurve<KhalimskySpaceND<2> >::PointsRange::ConstIterator > DSSlength;

    DSSlength.init(1, rp.begin(), rp.end(), c.isClosed());
    trace.info() << "DSS Length (h=1) = "<< DSSlength.eval()<<std::endl;

    DSSlength.init(10, rp.begin(), rp.end(), c.isClosed());
    trace.info() << "DSS Length (h=10) = "<< DSSlength.eval()<<std::endl;

    return true;
}
bool
lengthEstimators( const std::string & /*name*/,
      Shape & aShape, 
      double h )
{
  // Types
  typedef typename Space::Point Point;
  typedef typename Space::Vector Vector;
  typedef typename Space::RealPoint RealPoint;
  typedef typename Space::Integer Integer;
  typedef HyperRectDomain<Space> Domain;
  typedef KhalimskySpaceND<Space::dimension,Integer> KSpace;
  typedef typename KSpace::SCell SCell;
  typedef typename GridCurve<KSpace>::PointsRange PointsRange;
  typedef typename GridCurve<KSpace>::ArrowsRange ArrowsRange;

  // Digitizer
  GaussDigitizer<Space,Shape> dig;  
  dig.attach( aShape ); // attaches the shape.
  Vector vlow(-1,-1); Vector vup(1,1);
  dig.init( aShape.getLowerBound()+vlow, aShape.getUpperBound()+vup, h ); 
  Domain domain = dig.getDomain();

  // Create cellular space
  KSpace K;
  bool ok = K.init( dig.getLowerBound(), dig.getUpperBound(), true );
  if ( ! ok )
    {
      std::cerr << "[lengthEstimators]"
    << " error in creating KSpace." << std::endl;
      return false;
    }
  try {
    // Extracts shape boundary
    SurfelAdjacency<KSpace::dimension> SAdj( true );
    SCell bel = Surfaces<KSpace>::findABel( K, dig, 10000 );
    // Getting the consecutive surfels of the 2D boundary
    std::vector<Point> points;
    Surfaces<KSpace>::track2DBoundaryPoints( points, K, SAdj, dig, bel );
    // Create GridCurve
    GridCurve<KSpace> gridcurve;
    gridcurve.initFromVector( points );
    // Ranges
    ArrowsRange ra = gridcurve.getArrowsRange(); 
    PointsRange rp = gridcurve.getPointsRange(); 


    // Estimations
    typedef typename PointsRange::ConstIterator ConstIteratorOnPoints; 
    typedef ParametricShapeArcLengthFunctor< Shape > Length;
    TrueGlobalEstimatorOnPoints< ConstIteratorOnPoints, Shape, Length  >  trueLengthEstimator;
    trueLengthEstimator.init( h, rp.begin(), rp.end(), &aShape, gridcurve.isClosed());

    L1LengthEstimator< typename ArrowsRange::ConstCirculator > l1length;
    DSSLengthEstimator< typename PointsRange::ConstCirculator > DSSlength;
    MLPLengthEstimator< typename PointsRange::ConstIterator > MLPlength;
    FPLengthEstimator< typename PointsRange::ConstIterator > FPlength;
    BLUELocalLengthEstimator< typename ArrowsRange::ConstIterator > BLUElength;
    RosenProffittLocalLengthEstimator< typename ArrowsRange::ConstIterator > RosenProffittlength;
  
    // Output
    double trueValue = trueLengthEstimator.eval();
    double l1, blue, rosen,dss,mlp,fp;
    double Tl1, Tblue, Trosen,Tdss,Tmlp,Tfp;
    
    Clock c;

    //Length evaluation & timing
    c.startClock();
    l1length.init(h, ra.c(), ra.c());
    l1 = l1length.eval();
    Tl1 = c.stopClock();
    
    c.startClock();
    BLUElength.init(h, ra.begin(), ra.end(), gridcurve.isClosed());
    blue = BLUElength.eval();
    Tblue = c.stopClock();
    
    c.startClock();
    RosenProffittlength.init(h, ra.begin(), ra.end(), gridcurve.isClosed());
    rosen = RosenProffittlength.eval();
    Trosen = c.stopClock();
    
    c.startClock();
    DSSlength.init(h, rp.c(), rp.c());
    dss = DSSlength.eval();
    Tdss = c.stopClock();
    
    c.startClock();
    MLPlength.init(h, rp.begin(), rp.end(), gridcurve.isClosed());
    mlp = MLPlength.eval();
    Tmlp = c.stopClock();

    c.startClock();
    FPlength.init(h, rp.begin(), rp.end(), gridcurve.isClosed());
    fp = FPlength.eval();
    Tfp = c.stopClock();

    std::cout << std::setprecision( 15 ) << h << " " << rp.size() << " " << trueValue 
   << " " << l1
   << " " << blue
   << " " << rosen
   << " " << dss
   << " " << mlp   
   << " " << fp
         << " " << Tl1
   << " " << Tblue
   << " " << Trosen
   << " " << Tdss
   << " " << Tmlp
   << " " << Tfp     
   << std::endl;
    return true;
  }    
  catch ( InputException e )
    {
      std::cerr << "[lengthEstimators]"
    << " error in finding a bel." << std::endl;
      return false;
    }
}