7 #include "CallbackGatherXThetaValuesFunctions.h" 8 #include "CurveConnectAs.h" 10 #include "DocumentModelGeneral.h" 11 #include "EngaugeAssert.h" 12 #include "ExportFileFunctions.h" 13 #include "ExportLayoutFunctions.h" 14 #include "ExportOrdinalsSmooth.h" 15 #include "ExportXThetaValuesMergedFunctions.h" 16 #include "FormatCoordsUnits.h" 17 #include "LinearToLog.h" 20 #include <QTextStream> 23 #include "SplinePair.h" 24 #include "Transformation.h" 36 const QStringList &curvesIncluded,
37 const ExportValuesXOrY &xThetaValues,
38 const QString &delimiter,
43 unsigned int &numWritesSoFar)
const 45 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportAllPerLineXThetaValuesMerged";
47 int curveCount = curvesIncluded.count();
48 int xThetaCount = xThetaValues.count();
49 QVector<QVector<QString*> > yRadiusValues (curveCount, QVector<QString*> (xThetaCount));
50 initializeYRadiusValues (curvesIncluded,
53 loadYRadiusValues (modelExportOverride,
63 outputXThetaYRadiusValues (modelExportOverride,
74 destroy2DArray (yRadiusValues);
80 const QStringList &curvesIncluded,
81 const ExportValuesXOrY &xThetaValues,
82 const QString &delimiter,
87 unsigned int &numWritesSoFar)
const 89 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportOnePerLineXThetaValuesMerged";
91 QStringList::const_iterator itr;
92 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
95 const int CURVE_COUNT = 1;
96 QString curveIncluded = *itr;
97 QStringList curvesIncludedIter (curveIncluded);
99 int xThetaCount = xThetaValues.count();
100 QVector<QVector<QString*> > yRadiusValues (CURVE_COUNT, QVector<QString*> (xThetaCount));
101 initializeYRadiusValues (curvesIncludedIter,
104 loadYRadiusValues (modelExportOverride,
113 outputXThetaYRadiusValues (modelExportOverride,
124 destroy2DArray (yRadiusValues);
133 unsigned int &numWritesSoFar)
const 135 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportToFile";
142 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
145 CONNECT_AS_FUNCTION_SMOOTH,
146 CONNECT_AS_FUNCTION_STRAIGHT);
149 const QString delimiter = exportDelimiterToText (modelExportOverride.
delimiter(),
150 modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT);
156 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
161 ftor.xThetaValuesRaw(),
163 ExportValuesXOrY xThetaValuesMerged = exportXTheta.
xThetaValues ();
166 if (xThetaValuesMerged.count() > 0) {
169 if (modelExportOverride.
layoutFunctions() == EXPORT_LAYOUT_ALL_PER_LINE) {
170 exportAllPerLineXThetaValuesMerged (modelExportOverride,
182 exportOnePerLineXThetaValuesMerged (modelExportOverride,
197 void ExportFileFunctions::initializeYRadiusValues (
const QStringList &curvesIncluded,
198 const ExportValuesXOrY &xThetaValuesMerged,
199 QVector<QVector<QString*> > &yRadiusValues)
const 201 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::initializeYRadiusValues";
204 int curveCount = curvesIncluded.count();
205 int xThetaCount = xThetaValuesMerged.count();
206 for (
int row = 0; row < xThetaCount; row++) {
207 for (
int col = 0; col < curveCount; col++) {
208 yRadiusValues [col] [row] =
new QString;
213 double ExportFileFunctions::linearlyInterpolate (
const Points &points,
222 QPointF posGraphBefore, posScreenBefore;
223 bool foundIt =
false;
224 for (
int ip = 0; !foundIt && (ip < points.count()); ip++) {
226 const Point &point = points.at (ip);
235 if (xThetaValue <= posGraph.x() && (ip > 0)) {
242 yRadius = linearlyInterpolateYRadiusFromTwoPoints (xThetaValue,
250 posGraphBefore = posGraph;
255 if (points.count() > 1) {
259 int N = points.count();
260 const Point &pointLast = points.at (N - 1);
261 const Point &pointBefore = points.at (N - 2);
262 QPointF posGraphLast;
267 yRadius = linearlyInterpolateYRadiusFromTwoPoints (xThetaValue,
272 }
else if (points.count() == 1) {
275 yRadius = posGraphBefore.y();
279 ENGAUGE_ASSERT (
false);
290 const QStringList &curvesIncluded,
294 const ExportValuesXOrY &xThetaValues,
295 QVector<QVector<QString*> > &yRadiusValues)
const 297 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValues";
300 int curveCount = curvesIncluded.count();
301 for (
int col = 0; col < curveCount; col++) {
303 const QString curveName = curvesIncluded.at (col);
306 Points points = curve->
points ();
311 loadYRadiusValuesForCurveRaw (document.
modelCoords(),
317 yRadiusValues [col]);
323 loadYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
331 yRadiusValues [col]);
335 loadYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
341 yRadiusValues [col]);
347 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
350 const Points &points,
351 const ExportValuesXOrY &xThetaValues,
355 QVector<QString*> &yRadiusValues)
const 357 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth";
361 vector<SplinePair> xy;
373 QString dummyXThetaOut;
375 if (points.count() == 0) {
378 for (
int row = 0; row < xThetaValues.count(); row++) {
379 *(yRadiusValues [row]) =
"";
382 }
else if (points.count() == 1 ||
383 points.count() == 2) {
386 for (
int row = 0; row < xThetaValues.count(); row++) {
388 double xTheta = xThetaValues.at (row);
390 if (points.count() == 1) {
391 yRadius = xy.at (0).y ();
393 double x0 = xy.at (0).x ();
394 double x1 = xy.at (1).x ();
395 double y0 = xy.at (0).y ();
396 double y1 = xy.at (1).y ();
399 yRadius = xy.at (0).y ();
401 double s = (xTheta - x0) / (x1 - x0);
402 yRadius = (1.0 - s) * y0 + s * y1;
411 *(yRadiusValues [row]),
421 const int MAX_ITERATIONS = 32;
431 for (
int row = 0; row < xThetaValues.count(); row++) {
433 double xTheta = xThetaValues.at (row);
437 SplinePair splinePairFound = spline.findSplinePairForFunctionX (linearToLog.
linearize (xTheta, isLogXTheta),
439 double yRadius = linearToLog.
delinearize (splinePairFound.
y (),
443 QString dummyXThetaOut;
450 *(yRadiusValues [row]),
457 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
460 const Points &points,
461 const ExportValuesXOrY &xThetaValues,
463 QVector<QString*> &yRadiusValues)
const 465 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight";
470 for (
int row = 0; row < xThetaValues.count(); row++) {
472 double xThetaValue = xThetaValues.at (row);
474 double yRadius = linearlyInterpolate (points,
479 QString dummyXThetaOut;
486 *(yRadiusValues [row]),
491 void ExportFileFunctions::loadYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
494 const Points &points,
495 const ExportValuesXOrY &xThetaValues,
497 QVector<QString*> &yRadiusValues)
const 499 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveRaw";
505 for (
int pt = 0; pt < points.count(); pt++) {
507 const Point &point = points.at (pt);
515 double closestSeparation = 0.0;
517 for (
int row = 0; row < xThetaValues.count(); row++) {
519 double xThetaValue = xThetaValues.at (row);
521 double separation = qAbs (posGraph.x() - xThetaValue);
524 (separation < closestSeparation)) {
526 closestSeparation = separation;
533 QString dummyXThetaOut;
540 *(yRadiusValues [rowClosest]),
549 const QStringList &curvesIncluded,
550 const ExportValuesXOrY &xThetaValuesMerged,
552 QVector<QVector<QString*> > &yRadiusValues,
553 const QString &delimiter,
555 unsigned int &numWritesSoFar)
const 557 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::outputXThetaYRadiusValues";
560 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
561 insertLineSeparator (numWritesSoFar == 0,
562 modelExportOverride.
header (),
564 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
565 str << gnuplotComment();
567 str << modelExportOverride.
xLabel();
568 QStringList::const_iterator itrHeader;
569 for (itrHeader = curvesIncluded.begin(); itrHeader != curvesIncluded.end(); itrHeader++) {
570 QString curveName = *itrHeader;
571 str << delimiter << curveName;
578 const double DUMMY_Y_RADIUS = 1.0;
580 for (
int row = 0; row < xThetaValuesMerged.count(); row++) {
582 if (rowHasAtLeastOneYRadiusEntry (yRadiusValues,
585 double xTheta = xThetaValuesMerged.at (row);
588 QString xThetaString, yRadiusString;
597 str << wrapInDoubleQuotesIfNeeded (modelExportOverride,
600 for (
int col = 0; col < yRadiusValues.count(); col++) {
602 QString yRadiusString = *(yRadiusValues [col] [row]);
603 str << delimiter << wrapInDoubleQuotesIfNeeded (modelExportOverride,
614 bool ExportFileFunctions::rowHasAtLeastOneYRadiusEntry (
const QVector<QVector<QString*> > &yRadiusValues,
617 bool hasEntry =
false;
619 for (
int col = 0; col < yRadiusValues.count(); col++) {
621 QString entry = *(yRadiusValues [col] [row]);
622 if (!entry.isEmpty()) {
Model for DlgSettingsGeneral and CmdSettingsGeneral.
CurveConnectAs curveConnectAs() const
Get method for connect type.
Creates the set of merged x/theta values for exporting functions, using interpolation.
Cubic interpolation given independent and dependent value vectors.
ExportValuesXOrY xThetaValues() const
Resulting x/theta values for all included functions.
double y() const
Get method for y.
double linearize(double value, bool isLog) const
Convert log coordinates to linear. This is a noop if the input is already linear. ...
double delinearize(double value, bool isLog) const
Convert linear coordinates to log. This is a noop if the output is supposed to be linear...
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
ExportFileFunctions()
Single constructor.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
QPointF posScreen() const
Accessor for screen position.
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
const Points points() const
Return a shallow copy of the Points.
Model for DlgSettingsMainWindow.
LineStyle lineStyle() const
Get method for LineStyle.
Utility class to interpolate points spaced evenly along a piecewise defined curve with fitted spline...
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
Model for DlgSettingsCoords and CmdSettingsCoords.
Storage of one imported image and the data attached to that image.
Container for one set of digitized Points.
void loadSplinePairsWithTransformation(const Points &points, const Transformation &transformation, bool isLogXTheta, bool isLogYRadius, std::vector< double > &t, std::vector< SplinePair > &xy) const
Load t (=ordinal) and xy (=screen position) spline pairs, converting screen coordinates to graph coor...
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
CurveStyle curveStyle() const
Return the curve style.
Callback for collecting X/Theta independent variables, for functions, in preparation for exporting...
Warps log coordinates to make them linear before passing them to code that accepts only linear coordi...
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
Single X/Y pair for cubic spline interpolation initialization and calculations.
void exportToFile(const DocumentModelExportFormat &modelExportOverride, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, QTextStream &str, unsigned int &numWritesSoFar) const
Export Document points according to the settings.