size_t PawleyFunction::calculateFunctionValues( const API::IPeakFunction_sptr &peak, const API::FunctionDomain1D &domain, API::FunctionValues &localValues) const { size_t domainSize = domain.size(); const double *domainBegin = domain.getPointerAt(0); const double *domainEnd = domain.getPointerAt(domainSize); double centre = peak->centre(); double dx = m_peakRadius * peak->fwhm(); auto lb = std::lower_bound(domainBegin, domainEnd, centre - dx); auto ub = std::upper_bound(lb, domainEnd, centre + dx); size_t n = std::distance(lb, ub); if (n == 0) { throw std::invalid_argument("Null-domain"); } FunctionDomain1DView localDomain(lb, n); localValues.reset(localDomain); peak->functionLocal(localValues.getPointerToCalculated(0), localDomain.getPointerAt(0), n); return std::distance(domainBegin, lb); }
//---------------------------------------------------------------------------------------------- /// Extract values from domain and values objects to vectors. /// @param domain :: A domain with fitting data arguments. /// @param values :: A FunctionValues object with the fitting data. /// @param x :: A vector to store the domain values /// @param y :: A vector to store the fitting data values. void extractValues(const API::FunctionDomain1D &domain, const API::FunctionValues &values, std::vector<double> &x, std::vector<double> &y) { size_t n = domain.size(); double start = domain[0]; double end = domain[n - 1]; auto dBegin = domain.getPointerAt(0); auto startIter = std::lower_bound(dBegin, dBegin + n, start); auto istart = static_cast<size_t>(std::distance(dBegin, startIter)); if (istart == n) { x.clear(); y.clear(); return; } auto endIter = std::lower_bound(startIter, dBegin + n, end); auto iend = static_cast<size_t>(std::distance(dBegin, endIter)); if (iend <= istart) { x.clear(); y.clear(); return; } n = iend - istart; x.resize(n); y.resize(n); for (size_t i = istart; i < iend; ++i) { auto j = i - istart; x[j] = domain[i]; y[j] = values.getFitData(i); } }