All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Protected Attributes
QGpCoreTools::GridSearch Class Reference

Search a grid for maxima (global or local) More...

#include <GridSearch.h>

Inheritance diagram for QGpCoreTools::GridSearch:
QGpCoreTools::Function2Search ArrayCore::FKGridSearch T0GridSearch ArrayCore::HRFKGridSearch

List of all members.

Public Member Functions

double globalMax ()
 GridSearch ()
Function2MaximaIterator localMax (int nMax, double absThres=0.0, double relThres=0.0)
int nx () const
int ny () const
void setAbsolutePrecision (double p)
void setGrid (double minX, double maxX, double dX, double minY, double maxY, double dY)
void setRelativePrecision (double p)
double x (int i) const
double y (int i) const
 ~GridSearch ()

Protected Attributes

int _nx
int _ny
double _precisionX
double _precisionY
double * _x
double * _y

Detailed Description

Search a grid for maxima (global or local)


Constructor & Destructor Documentation

References _nx, _ny, _precisionX, _precisionY, _x, _y, and TRACE.

{
  TRACE;
  _precisionX=0.001;
  _precisionY=0.001;
  _nx=0;
  _ny=0;
  _x=0;
  _y=0;
}

Description of destructor still missing

References _x, _y, and TRACE.

{
  TRACE;
  delete [] _x;
  delete [] _y;
}

Member Function Documentation

Search all grid for its maximum and refine it

References QGpCoreTools::Function2Search::_function, _nx, _ny, QGpCoreTools::Function2Search::_pos, _x, _y, QGpCoreTools::Function2Search::highLimit(), QGpCoreTools::Function2Search::lowLimit(), QGpCoreTools::Point2D::setY(), TRACE, and QGpCoreTools::AbstractFunction2::value().

Referenced by ToolNR::t0Apply().

{
  TRACE;
  int maxix=0, maxiy=0;
  double val,maxVal=-1e99;
  int k=0;
  for(int iy=0;iy<_ny;iy++) {
    for(int ix=0;ix<_nx;ix++, k++) {
      val=_function->value(_x[ix], _y[iy], k);
      if(val>maxVal) {
        maxVal=val;
        maxix=ix;
        maxiy=iy;
      }
    }
  }
  // Refine search by recursion and re-regridding
  if(_ny==1) {
    _pos.setY(_y[0]);
    return refineMax(lowLimit(maxix, _x),highLimit(maxix, _x, _nx));
  }
  else return refineMax(lowLimit(maxix, _x), highLimit(maxix, _x, _nx),
                        lowLimit(maxiy, _y), highLimit(maxiy, _y, _ny));
}
Function2MaximaIterator QGpCoreTools::GridSearch::localMax ( int  nMax,
double  absThres = 0.0,
double  relThres = 0.0 
)

Reimplemented from QGpCoreTools::Function2Search.

References QGpCoreTools::Function2Search::_function, QGpCoreTools::Function2Search::_localMaxima, _nx, _ny, QGpCoreTools::Function2Search::_pos, _x, _y, TRACE, and QGpCoreTools::AbstractFunction2::value().

Referenced by FKLoopTask::exportMax().

{
  TRACE;
  double * map=new double [_nx*_ny];
  int k=0;
  int iy;
  for(iy=0;iy<_ny;iy++) {
    for(int ix=0;ix<_nx;ix++,k++) {
      map[k]=_function->value(_x[ix], _y[iy], k);
    }
  }
  _localMaxima.clear();
  int nxm=_nx-1;
  int nym=_ny-1;
  k=_nx+1;
  for(iy=1;iy<nym;iy++) {
    for(int ix=1;ix<nxm;ix++,k++) {
      if(map[k-1]>0 && map[k]>map[k-1] &&
          map[k+1]>0 && map[k]>map[k+1] &&
          map[k-_nx-1]>0 && map[k]>map[k-_nx-1] &&
          map[k-_nx]>0 && map[k]>map[k-_nx] &&
          map[k-_nx+1]>0 && map[k]>map[k-_nx+1] &&
          map[k+_nx-1]>0 && map[k]>map[k+_nx-1] &&
          map[k+_nx]>0 && map[k]>map[k+_nx] &&
          map[k+_nx+1]>0 && map[k]>map[k+_nx+1]) {
        double val=refineMax(_x[ix-1],_x[ix+1], _y[iy-1],_y[iy+1]);
        _localMaxima.append(Function2SearchMaximum(val, _pos));
      }
    }
    k+=2;
  }
  delete [] map;
  return Function2Search::localMax(nMax, absThres, relThres);
}
int QGpCoreTools::GridSearch::nx ( ) const [inline]
int QGpCoreTools::GridSearch::ny ( ) const [inline]
void QGpCoreTools::GridSearch::setGrid ( double  minX,
double  maxX,
double  dX,
double  minY,
double  maxY,
double  dY 
)

References QGpCoreTools::Function2Search::_function, _nx, _ny, _x, _y, QGpCoreTools::AbstractFunction2::initGrid(), nx(), ny(), and TRACE.

Referenced by RealTimeArrayProcess::setWavenumberRange().

{
  TRACE;
  ASSERT(_function);

  int nx=(int)round((maxX-minX)/dX)+1;
  int ny=(int)round((maxY-minY)/dY)+1;
  if (nx!=_nx) {
    delete [] _x;
    _x=new double [nx];
    _nx=nx;
  }
  if(ny!=_ny) {
    delete [] _y;
    _y=new double [ny];
    _ny=ny;
  }
  for(int i=0;i<_nx;i++) _x[i]=minX+dX*(double)i;
  for(int i=0;i<_ny;i++) _y[i]=minY+dY*(double)i;

  _function->initGrid(_nx * _ny);
  int k=0;
  for(int iy=0;iy<_ny;iy++) {
    for(int ix=0;ix<_nx;ix++, k++) {
      _function->initGrid(_x[ix], _y[iy], k);
    }
  }
}
double QGpCoreTools::GridSearch::x ( int  i) const [inline]
double QGpCoreTools::GridSearch::y ( int  i) const [inline]

Member Data Documentation

Referenced by GridSearch().

Referenced by GridSearch().

double* QGpCoreTools::GridSearch::_x [protected]
double * QGpCoreTools::GridSearch::_y [protected]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines