191                                            double play, 
int patience_limit)
 
  199    std::vector< std::vector<int> > pts;      
 
  200    std::vector< std::vector<double> >  cen_pts;    
 
  202    std::vector<double> pt(2);  
 
  211    gsl_rng *randGen = gsl_rng_alloc(gsl_rng_taus);
 
  212    gsl_rng_set(randGen, time(NULL));  
 
  214    samples = selectionChip->
Samples();
 
  215    lines   = selectionChip->
Lines();
 
  219    k = int(ceil(
double(samples) - a));
 
  220    l = int(ceil(
double(lines  ) - b));
 
  232    double aSearch,centerSample,centerLine,delta,cSearch;
 
  233    cSearch = searchStep/5.0;
 
  234    centerSample = double((k+i)/2.0);
 
  235    centerLine   = double((l+j)/2.0);
 
  236    delta = (centerSample-double(i))*(centerSample-
double(i)) + (centerLine  -double(l))*(centerLine  -
double(l));  
 
  238    aSearch = (searchStep-cSearch)/delta;
 
  240    for (pt[0]=floor(a+1.0); pt[0]<k; pt[0]+=searchStep) {
 
  241      for (pt[1]=floor(b+1.0); pt[1]<l; pt[1]+=searchStep) {
 
  242        cen_pts.push_back(pt);
 
  243        delta = (centerSample-double(pt[0]))*(centerSample-
double(pt[0])) + (centerLine-double(pt[1]))*(centerLine-
double(pt[1]));  
 
  244        searchStep = aSearch*delta + cSearch;
 
  245        if (searchStep > l - pt[1] && l - pt[1] > 1e-4)  
 
  246          searchStep = l - pt[1];
 
  248      if (searchStep > k - pt[0] && k - pt[0] > 1e-4)  
 
  249        searchStep = k - pt[0];
 
  253    selectionEdge(selectionChip,&pts);
 
  256    if (pts.size() ==0) 
return 0;
 
  261    while (emptySets < patience_limit && cen_pts.size()>0) {
 
  264      randPt = gsl_rng_uniform_int( randGen  ,cen_pts.size() );
 
  265      dpt[0] = cen_pts[randPt][0];
 
  266      dpt[1] = cen_pts[randPt][1];
 
  268      cen_pts.erase( cen_pts.begin() + randPt);  
 
  271      ellipseFromCenterAxesAngle(&ellNew, dpt[0], dpt[1], a, b, 0.0);
 
  275      if (!bestFitEllipse(&ellNew, &pts, play, 50)) {
 
  281      if (ellNew.area < ellBest.area) {
 
  286      if (!ellipseInChip(&ellNew,selectionChip)) {  
 
  292      if (elipsePercentSelected(selectionChip,&ellNew) < percent_selected) {
 
  300      ellBest.area = ellNew.area;
 
  301      ellBest.A[0] = ellNew.A[0];
 
  302      ellBest.A[1] = ellNew.A[1];
 
  303      ellBest.A[2] = ellNew.A[2];
 
  305      ellBest.cen[0] = ellNew.cen[0];
 
  306      ellBest.cen[1] = ellNew.cen[1];
 
  308      ellBest.semiMajor = ellNew.semiMajor;
 
  309      ellBest.semiMinor = ellNew.semiMinor;
 
  310      ellBest.majorAxis[0] = ellNew.majorAxis[0];
 
  311      ellBest.majorAxis[1] = ellNew.majorAxis[1];
 
  312      ellBest.minorAxis[0] = ellNew.minorAxis[0];
 
  313      ellBest.minorAxis[1] = ellNew.minorAxis[1];
 
  316    if( ellBest.area == 0)
 
  322    for (i=1;i<=samples;i++) {
 
  323      for (j=1;j<=lines;j++) {
 
  327        if (!pointInEllipse(&ellBest,dpt,play)) {  
 
  328          if( selectionChip->
GetValue(i,j) == 1)