ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothGraph (double pointsIntervalRelations, const Transformation &transformation, const Points &points) const { LOG4CPP_INFO_S ((*mainCat)) << "ExportFileRelations::ordinalsAtIntervalsSmoothGraph"; ExportValuesOrdinal ordinals; // Prevent infinite loop when there are no points or will be too many points if ((pointsIntervalRelations > 0) && (points.count() > 0)) { vector<double> t; vector<SplinePair> xy; ExportOrdinalsSmooth ordinalsSmooth; ordinalsSmooth.loadSplinePairsWithTransformation (points, transformation, t, xy); ordinals = ordinalsSmooth.ordinalsAtIntervalsGraph (t, xy, pointsIntervalRelations); } return ordinals; }
void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth (const DocumentModelCoords &modelCoords, const DocumentModelGeneral &modelGeneral, const MainWindowModel &modelMainWindow, const Points &points, const ExportValuesOrdinal &ordinals, QVector<QString*> &xThetaValues, QVector<QString*> &yRadiusValues, const Transformation &transformation) const { LOG4CPP_INFO_S ((*mainCat)) << "ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth"; vector<double> t; vector<SplinePair> xy; ExportOrdinalsSmooth ordinalsSmooth; ordinalsSmooth.loadSplinePairsWithTransformation (points, transformation, t, xy); // Spline class requires at least one point if (xy.size() > 0) { // Fit a spline Spline spline (t, xy); FormatCoordsUnits format; // Extract the points for (int row = 0; row < ordinals.count(); row++) { double ordinal = ordinals.at (row); SplinePair splinePairFound = spline.interpolateCoeff(ordinal); double xTheta = splinePairFound.x (); double yRadius = splinePairFound.y (); // Save values for this row into xThetaValues and yRadiusValues, after appropriate formatting format.unformattedToFormatted (xTheta, yRadius, modelCoords, modelGeneral, modelMainWindow, *(xThetaValues [row]), *(yRadiusValues [row]), transformation); } } }
void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth (const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const Points &points, const ExportValuesXOrY &xThetaValues, const Transformation &transformation, QVector<QString*> &yRadiusValues) const { LOG4CPP_INFO_S ((*mainCat)) << "ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth"; // Convert screen coordinates to graph coordinates, in vectors suitable for spline fitting vector<double> t; vector<SplinePair> xy; ExportOrdinalsSmooth ordinalsSmooth; ordinalsSmooth.loadSplinePairsWithTransformation (points, transformation, t, xy); // Formatting FormatCoordsUnits format; QString dummyXThetaOut; if (points.count() == 0) { // Since there are no values, leave the field empty for (int row = 0; row < xThetaValues.count(); row++) { *(yRadiusValues [row]) = ""; } } else if (points.count() == 1 || points.count() == 2) { // Apply the single value everywhere (N=1) or do linear interpolation (N=2) for (int row = 0; row < xThetaValues.count(); row++) { double xTheta = xThetaValues.at (row); double yRadius; if (points.count() == 1) { yRadius = xy.at (0).y (); } else { double x0 = xy.at (0).x (); double x1 = xy.at (1).x (); double y0 = xy.at (0).y (); double y1 = xy.at (1).y (); if (x0 == x1) { // Cannot do linear interpolation using two points at the same x value yRadius = xy.at (0).y (); } else { double s = (xTheta - x0) / (x1 - x0); yRadius = (1.0 - s) * y0 + s * y1; } } format.unformattedToFormatted (xTheta, yRadius, modelCoords, modelMainWindow, dummyXThetaOut, *(yRadiusValues [row]), transformation); } } else { // Iteration accuracy versus number of iterations 8->256, 10->1024, 12->4096. Single pixel accuracy out of // typical image size of 1024x1024 means around 10 iterations gives decent accuracy for numbers much bigger // than 1. A value of 12 gave some differences in the least significant figures of numbers like 10^-3 in // the regression tests. Toggling between 30 and 32 made no difference in the regression tests. const int MAX_ITERATIONS = 32; // Spline class requires at least one point if (xy.size() > 0) { // Fit a spline Spline spline (t, xy); // Get value at desired points for (int row = 0; row < xThetaValues.count(); row++) { double xTheta = xThetaValues.at (row); SplinePair splinePairFound = spline.findSplinePairForFunctionX (xTheta, MAX_ITERATIONS); double yRadius = splinePairFound.y (); // Save y/radius value for this row into yRadiusValues, after appropriate formatting QString dummyXThetaOut; format.unformattedToFormatted (xTheta, yRadius, modelCoords, modelMainWindow, dummyXThetaOut, *(yRadiusValues [row]), transformation); } } } }