QXRD  0.11.16
Public Member Functions | Private Member Functions | Static Private Member Functions | List of all members
QxrdFitterRingPoint Class Reference

#include <qxrdfitterringpoint.h>

Inheritance diagram for QxrdFitterRingPoint:
Inheritance graph
[legend]
Collaboration diagram for QxrdFitterRingPoint:
Collaboration graph
[legend]

Public Member Functions

 QxrdFitterRingPoint (QxrdCenterFinder *cf, int index, double x0, double y0, double pkht, double bkgd)
 
 QxrdFitterRingPoint ()
 
int fit ()
 
- Public Member Functions inherited from QxrdFitterPeakOrRing
 QxrdFitterPeakOrRing (QxrdCenterFinder *cf, int index, double x0, double y0, double pkht, double bkgd)
 
 QxrdFitterPeakOrRing ()
 
int index () const
 
double x0 () const
 
double y0 () const
 
double pkht () const
 
double bkgd () const
 
double fittedX () const
 
double fittedY () const
 
double fittedWidth () const
 
double fittedHeight () const
 
double fittedBkgd () const
 
double fittedBkgdX () const
 
double fittedBkgdY () const
 
double fittedR () const
 
double fittedAz () const
 
- Public Member Functions inherited from QxrdFitter
 QxrdFitter (QxrdCenterFinder *cf)
 
 QxrdFitter ()
 
QxrdCenterFindercf () const
 
FitResult reason () const
 
QString reasonString () const
 

Private Member Functions

void evaluate (double *parm, double *xv, int np, int nx)
 

Static Private Member Functions

static void staticEvaluate (double *parm, double *xv, int np, int nx, void *adata)
 

Additional Inherited Members

- Public Types inherited from QxrdFitter
enum  FitResult {
  Successful, NoResult, OutsideData, BadWidth,
  BadPosition, BadHeight, LastReason
}
 
- Static Public Member Functions inherited from QxrdFitter
static QString reasonString (FitResult i)
 
- Protected Attributes inherited from QxrdFitterPeakOrRing
int m_Index
 
double m_X0
 
double m_Y0
 
double m_Pkht
 
double m_Bkgd
 
double m_FittedX
 
double m_FittedY
 
double m_FittedWidth
 
double m_FittedHeight
 
double m_FittedBkgd
 
double m_FittedBkgdX
 
double m_FittedBkgdY
 
double m_FittedR
 
double m_FittedAz
 
- Protected Attributes inherited from QxrdFitter
QxrdCenterFinderm_CenterFinder
 
FitResult m_Reason
 

Detailed Description

Definition at line 6 of file qxrdfitterringpoint.h.

Constructor & Destructor Documentation

QxrdFitterRingPoint::QxrdFitterRingPoint ( QxrdCenterFinder cf,
int  index,
double  x0,
double  y0,
double  pkht,
double  bkgd 
)

Definition at line 14 of file qxrdfitterringpoint.cpp.

QxrdFitterRingPoint::QxrdFitterRingPoint ( )

Definition at line 19 of file qxrdfitterringpoint.cpp.

19  :
21 {
22 }

Member Function Documentation

void QxrdFitterRingPoint::evaluate ( double *  parm,
double *  xv,
int  np,
int  nx 
)
private

Definition at line 33 of file qxrdfitterringpoint.cpp.

References QxrdCenterFinder::imageValue(), QxrdFitter::m_CenterFinder, QxrdFitterPeakOrRing::m_X0, QxrdFitterPeakOrRing::m_Y0, QxrdCenterFinder::printMessage(), QxrdFitterPeakOrRing::x0(), and QxrdFitterPeakOrRing::y0().

Referenced by staticEvaluate().

34 {
35  if (m_CenterFinder) {
36 // m_CenterFinder->printMessage("Fitting");
37 
38  if (np!=6) {
39  m_CenterFinder->printMessage("Wrong number of parameters");
40  } else {
41  double pr = parm[0];
42  double wd = parm[1];
43  double ht = parm[2];
44  double bg = parm[3];
45  double bx = parm[4];
46  double by = parm[5];
47 
48  double dr = m_CenterFinder->get_PeakFitRadius();
49  double xc = m_CenterFinder->get_CenterX();
50  double yc = m_CenterFinder->get_CenterY();
51  double cx0 = m_X0;
52  double cy0 = m_Y0;
53  double az = atan2(cy0-yc, cx0-xc);
54 
55  int n = dr*2+1;
56  int x0 = cx0 - dr;
57  int y0 = cy0 - dr;
58 // int nn = n*n;
59  int i=0;
60 
61  double cx = xc + pr*cos(az);
62  double cy = yc + pr*sin(az);
63 
64  double dx0 = cx - xc;
65  double dy0 = cy - yc;
66  double r0 = sqrt(dx0*dx0+dy0*dy0);
67 
68  for (int y=y0; y<y0+n; y++) {
69  for (int x=x0; x<x0+n; x++) {
70  double d = m_CenterFinder->imageValue(x,y);
71 
72  double dx = x-cx;
73  double dy = y-cy;
74  double dx1 = x - xc;
75  double dy1 = y - yc;
76  double r1 = sqrt(dx1*dx1+dy1*dy1);
77  double dr = r1-r0;
78  double pk = bg + dx*bx + dy*by + ht*exp(-((dr*dr)/(2.0*wd*wd)));
79 
80  xv[i++] = pk - d;
81  }
82  }
83  }
84  }
85 }
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QxrdCenterFinder * m_CenterFinder
Definition: qxrdfitter.h:31
double imageValue(double x, double y)

Here is the call graph for this function:

Here is the caller graph for this function:

int QxrdFitterRingPoint::fit ( )
virtual

Implements QxrdFitter.

Definition at line 87 of file qxrdfitterringpoint.cpp.

References QxrdFitter::BadHeight, QxrdFitter::BadPosition, QxrdFitter::BadWidth, QxrdFitterPeakOrRing::bkgd(), QxrdCenterFinder::data(), QxrdCenterFinder::imageValue(), QxrdFitter::m_CenterFinder, QxrdFitterPeakOrRing::m_FittedBkgd, QxrdFitterPeakOrRing::m_FittedBkgdX, QxrdFitterPeakOrRing::m_FittedBkgdY, QxrdFitterPeakOrRing::m_FittedHeight, QxrdFitterPeakOrRing::m_FittedWidth, QxrdFitterPeakOrRing::m_FittedX, QxrdFitterPeakOrRing::m_FittedY, QxrdFitterPeakOrRing::m_Pkht, QxrdFitter::m_Reason, QxrdFitterPeakOrRing::m_X0, QxrdFitterPeakOrRing::m_Y0, QxrdFitter::OutsideData, QxrdFitterPeakOrRing::pkht(), staticEvaluate(), and QxrdFitter::Successful.

Referenced by QxrdCenterFinder::fitRingNear(), and QxrdCenterFinder::traceRingNear().

88 {
89  int niter = -1;
90 
91  if (m_CenterFinder) {
92 
93  double x = m_X0, y = m_Y0;
94 
95 // if (qcepDebug(DEBUG_FITTING) || m_CenterFinder->get_PeakFitDebug()) {
96 // m_CenterFinder -> printMessage(QObject::tr("Fitting i: %1, x0: %2, y0: %3")
97 // .arg(index()).arg(m_X0).arg(m_Y0));
98 // }
99 
100  int width = 0, height = 0;
101 
103 
104  if (data) {
105  width = data -> get_Width()+1;
106  height = data -> get_Height()+1;
107 
108  if (x<0 || x>width || y<0 || y>height) {
110  } else {
111  double xc = m_CenterFinder->get_CenterX();
112  double yc = m_CenterFinder->get_CenterY();
113  double dx = x - xc;
114  double dy = y - yc;
115  double r = sqrt(dx*dx + dy*dy);
116  double chi = atan2(dy, dx);
117  double dr = m_CenterFinder->get_PeakFitRadius();
118  double bkgd = ( m_CenterFinder->imageValue(xc+(r+dr)*cos(chi), yc+(r+dr)*sin(chi))
119  +m_CenterFinder->imageValue(xc+(r-dr)*cos(chi), yc+(r-dr)*sin(chi)))/2.0;
120  double pkht = m_CenterFinder->imageValue(x,y) - bkgd;
121 
122  double parms[6];
123 
124  parms[0] = r;
125  parms[1] = 2.0;
126  parms[2] = pkht;
127  parms[3] = bkgd;
128  parms[4] = 0;
129  parms[5] = 0;
130 
131  double info[LM_INFO_SZ];
132 
133  int n = m_CenterFinder->get_PeakFitRadius()*2+1;
134 
135  niter = dlevmar_dif(QxrdFitterRingPoint::staticEvaluate,
136  parms, NULL, 6, n*n,
137  m_CenterFinder->get_PeakFitIterations(),
138  NULL, info, NULL, NULL, this);
139 
140  if (niter > 0) {
142  m_FittedX = xc + parms[0]*cos(chi);
143  m_FittedY = yc + parms[0]*sin(chi);
144  m_FittedWidth = parms[1];
145  m_FittedHeight = parms[2];
146  m_FittedBkgd = parms[3];
147  m_FittedBkgdX = parms[4];
148  m_FittedBkgdY = parms[5];
149 
150  double dx = m_FittedX - m_X0;
151  double dy = m_FittedY - m_Y0;
152  double dr = sqrt(dx*dx + dy*dy);
153 
154  if ((fabs(m_FittedWidth)<m_CenterFinder->get_FittedWidthMin()) ||
155  (fabs(m_FittedWidth)>m_CenterFinder->get_FittedWidthMax())) {
156  m_Reason = BadWidth;
157  } else if ((m_FittedHeight/m_Pkht)<m_CenterFinder->get_FittedHeightMinRatio()) {
159  } else if (dr>m_CenterFinder->get_FittedPositionMaxDistance()) {
161  }
162  }
163  }
164  }
165  }
166 
167  return niter;
168 }
FitResult m_Reason
Definition: qxrdfitter.h:32
QcepDoubleImageDataPtr data() const
QxrdCenterFinder * m_CenterFinder
Definition: qxrdfitter.h:31
static void staticEvaluate(double *parm, double *xv, int np, int nx, void *adata)
double imageValue(double x, double y)
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdFitterRingPoint::staticEvaluate ( double *  parm,
double *  xv,
int  np,
int  nx,
void *  adata 
)
staticprivate

Definition at line 24 of file qxrdfitterringpoint.cpp.

References evaluate().

Referenced by fit().

25 {
27 
28  if (rf) {
29  rf->evaluate(p,hx,m,n);
30  }
31 }
void evaluate(double *parm, double *xv, int np, int nx)

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: