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" 19 #include <QTextStream> 22 #include "SplinePair.h" 23 #include "Transformation.h" 35 const QStringList &curvesIncluded,
36 const ExportValuesXOrY &xThetaValues,
37 const QString &delimiter,
42 unsigned int &numWritesSoFar)
const 44 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportAllPerLineXThetaValuesMerged";
46 int curveCount = curvesIncluded.count();
47 int xThetaCount = xThetaValues.count();
48 QVector<QVector<QString*> > yRadiusValues (curveCount, QVector<QString*> (xThetaCount));
49 initializeYRadiusValues (curvesIncluded,
52 loadYRadiusValues (modelExportOverride,
62 outputXThetaYRadiusValues (modelExportOverride,
73 destroy2DArray (yRadiusValues);
79 const QStringList &curvesIncluded,
80 const ExportValuesXOrY &xThetaValues,
81 const QString &delimiter,
86 unsigned int &numWritesSoFar)
const 88 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportOnePerLineXThetaValuesMerged";
90 QStringList::const_iterator itr;
91 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
94 const int CURVE_COUNT = 1;
95 QString curveIncluded = *itr;
96 QStringList curvesIncluded (curveIncluded);
98 int xThetaCount = xThetaValues.count();
99 QVector<QVector<QString*> > yRadiusValues (CURVE_COUNT, QVector<QString*> (xThetaCount));
100 initializeYRadiusValues (curvesIncluded,
103 loadYRadiusValues (modelExportOverride,
112 outputXThetaYRadiusValues (modelExportOverride,
123 destroy2DArray (yRadiusValues);
132 unsigned int &numWritesSoFar)
const 134 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportToFile";
141 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
144 CONNECT_AS_FUNCTION_SMOOTH,
145 CONNECT_AS_FUNCTION_STRAIGHT);
148 const QString delimiter = exportDelimiterToText (modelExportOverride.
delimiter(),
149 modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT);
155 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
160 ftor.xThetaValuesRaw(),
162 ExportValuesXOrY xThetaValuesMerged = exportXTheta.
xThetaValues ();
165 if (xThetaValuesMerged.count() > 0) {
168 if (modelExportOverride.
layoutFunctions() == EXPORT_LAYOUT_ALL_PER_LINE) {
169 exportAllPerLineXThetaValuesMerged (modelExportOverride,
181 exportOnePerLineXThetaValuesMerged (modelExportOverride,
196 void ExportFileFunctions::initializeYRadiusValues (
const QStringList &curvesIncluded,
197 const ExportValuesXOrY &xThetaValuesMerged,
198 QVector<QVector<QString*> > &yRadiusValues)
const 200 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::initializeYRadiusValues";
203 int curveCount = curvesIncluded.count();
204 int xThetaCount = xThetaValuesMerged.count();
205 for (
int row = 0; row < xThetaCount; row++) {
206 for (
int col = 0; col < curveCount; col++) {
207 yRadiusValues [col] [row] =
new QString;
212 double ExportFileFunctions::linearlyInterpolate (
const Points &points,
221 QPointF posGraphBefore;
222 bool foundIt =
false;
223 for (
int ip = 0; !foundIt && (ip < points.count()); ip++) {
225 const Point &point = points.at (ip);
234 if (xThetaValue <= posGraph.x() && (ip > 0)) {
241 double s = (xThetaValue - posGraphBefore.x()) / (posGraph.x() - posGraphBefore.x());
242 yRadius = (1.0 -s) * posGraphBefore.y() + s * posGraph.y();
247 posGraphBefore = posGraph;
252 if (points.count() > 1) {
256 int N = points.count();
257 const Point &pointLast = points.at (N - 1);
258 const Point &pointBefore = points.at (N - 2);
259 QPointF posGraphLast;
264 double s = (xThetaValue - posGraphBefore.x()) / (posGraphLast.x() - posGraphBefore.x());
265 yRadius = (1.0 - s) * posGraphBefore.y() + s * posGraphLast.y();
267 }
else if (points.count() == 1) {
270 yRadius = posGraphBefore.y();
274 ENGAUGE_ASSERT (
false);
285 const QStringList &curvesIncluded,
289 const ExportValuesXOrY &xThetaValues,
290 QVector<QVector<QString*> > &yRadiusValues)
const 292 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValues";
295 int curveCount = curvesIncluded.count();
296 for (
int col = 0; col < curveCount; col++) {
298 const QString curveName = curvesIncluded.at (col);
301 Points points = curve->
points ();
306 loadYRadiusValuesForCurveRaw (document.
modelCoords(),
312 yRadiusValues [col]);
318 loadYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
326 yRadiusValues [col]);
330 loadYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
336 yRadiusValues [col]);
342 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
345 const Points &points,
346 const ExportValuesXOrY &xThetaValues,
350 QVector<QString*> &yRadiusValues)
const 352 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth";
356 vector<SplinePair> xy;
368 QString dummyXThetaOut;
370 if (points.count() == 0) {
373 for (
int row = 0; row < xThetaValues.count(); row++) {
374 *(yRadiusValues [row]) =
"";
377 }
else if (points.count() == 1 ||
378 points.count() == 2) {
381 for (
int row = 0; row < xThetaValues.count(); row++) {
383 double xTheta = xThetaValues.at (row);
385 if (points.count() == 1) {
386 yRadius = xy.at (0).y ();
388 double x0 = xy.at (0).x ();
389 double x1 = xy.at (1).x ();
390 double y0 = xy.at (0).y ();
391 double y1 = xy.at (1).y ();
394 yRadius = xy.at (0).y ();
396 double s = (xTheta - x0) / (x1 - x0);
397 yRadius = (1.0 - s) * y0 + s * y1;
406 *(yRadiusValues [row]),
416 const int MAX_ITERATIONS = 32;
426 for (
int row = 0; row < xThetaValues.count(); row++) {
428 double xTheta = xThetaValues.at (row);
434 double yRadius = linearToLog.
delinearize (splinePairFound.
y (),
438 QString dummyXThetaOut;
445 *(yRadiusValues [row]),
452 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
455 const Points &points,
456 const ExportValuesXOrY &xThetaValues,
458 QVector<QString*> &yRadiusValues)
const 460 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight";
465 for (
int row = 0; row < xThetaValues.count(); row++) {
467 double xThetaValue = xThetaValues.at (row);
469 double yRadius = linearlyInterpolate (points,
474 QString dummyXThetaOut;
481 *(yRadiusValues [row]),
486 void ExportFileFunctions::loadYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
489 const Points &points,
490 const ExportValuesXOrY &xThetaValues,
492 QVector<QString*> &yRadiusValues)
const 494 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveRaw";
500 for (
int pt = 0; pt < points.count(); pt++) {
502 const Point &point = points.at (pt);
510 double closestSeparation = 0.0;
512 for (
int row = 0; row < xThetaValues.count(); row++) {
514 double xThetaValue = xThetaValues.at (row);
516 double separation = qAbs (posGraph.x() - xThetaValue);
519 (separation < closestSeparation)) {
521 closestSeparation = separation;
528 QString dummyXThetaOut;
535 *(yRadiusValues [rowClosest]),
544 const QStringList &curvesIncluded,
545 const ExportValuesXOrY &xThetaValuesMerged,
547 QVector<QVector<QString*> > &yRadiusValues,
548 const QString &delimiter,
550 unsigned int &numWritesSoFar)
const 552 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::outputXThetaYRadiusValues";
555 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
556 insertLineSeparator (numWritesSoFar == 0,
557 modelExportOverride.
header (),
559 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
560 str << gnuplotComment();
562 str << modelExportOverride.
xLabel();
563 QStringList::const_iterator itrHeader;
564 for (itrHeader = curvesIncluded.begin(); itrHeader != curvesIncluded.end(); itrHeader++) {
565 QString curveName = *itrHeader;
566 str << delimiter << curveName;
573 const double DUMMY_Y_RADIUS = 1.0;
575 for (
int row = 0; row < xThetaValuesMerged.count(); row++) {
577 if (rowHasAtLeastOneYRadiusEntry (yRadiusValues,
580 double xTheta = xThetaValuesMerged.at (row);
583 QString xThetaString, yRadiusString;
592 str << wrapInDoubleQuotesIfNeeded (modelExportOverride,
595 for (
int col = 0; col < yRadiusValues.count(); col++) {
597 QString yRadiusString = *(yRadiusValues [col] [row]);
598 str << delimiter << wrapInDoubleQuotesIfNeeded (modelExportOverride,
609 bool ExportFileFunctions::rowHasAtLeastOneYRadiusEntry (
const QVector<QVector<QString*> > &yRadiusValues,
612 bool hasEntry =
false;
614 for (
int col = 0; col < yRadiusValues.count(); col++) {
616 QString entry = *(yRadiusValues [col] [row]);
617 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.
SplinePair findSplinePairForFunctionX(double x, int numIterations) const
Use bisection algorithm to iteratively find the SplinePair interpolated to best match the specified x...
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.