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,
41 QTextStream &str)
const 43 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportAllPerLineXThetaValuesMerged";
45 int curveCount = curvesIncluded.count();
46 int xThetaCount = xThetaValues.count();
47 QVector<QVector<QString*> > yRadiusValues (curveCount, QVector<QString*> (xThetaCount));
48 initializeYRadiusValues (curvesIncluded,
51 loadYRadiusValues (modelExportOverride,
61 outputXThetaYRadiusValues (modelExportOverride,
71 destroy2DArray (yRadiusValues);
77 const QStringList &curvesIncluded,
78 const ExportValuesXOrY &xThetaValues,
79 const QString &delimiter,
83 QTextStream &str)
const 85 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportOnePerLineXThetaValuesMerged";
89 QStringList::const_iterator itr;
90 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
92 insertLineSeparator (isFirst,
93 modelExportOverride.
header(),
97 const int CURVE_COUNT = 1;
98 QString curveIncluded = *itr;
99 QStringList curvesIncluded (curveIncluded);
101 int xThetaCount = xThetaValues.count();
102 QVector<QVector<QString*> > yRadiusValues (CURVE_COUNT, QVector<QString*> (xThetaCount));
103 initializeYRadiusValues (curvesIncluded,
106 loadYRadiusValues (modelExportOverride,
115 outputXThetaYRadiusValues (modelExportOverride,
125 destroy2DArray (yRadiusValues);
133 QTextStream &str)
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,
181 exportOnePerLineXThetaValuesMerged (modelExportOverride,
195 void ExportFileFunctions::initializeYRadiusValues (
const QStringList &curvesIncluded,
196 const ExportValuesXOrY &xThetaValuesMerged,
197 QVector<QVector<QString*> > &yRadiusValues)
const 199 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::initializeYRadiusValues";
202 int curveCount = curvesIncluded.count();
203 int xThetaCount = xThetaValuesMerged.count();
204 for (
int row = 0; row < xThetaCount; row++) {
205 for (
int col = 0; col < curveCount; col++) {
206 yRadiusValues [col] [row] =
new QString;
211 double ExportFileFunctions::linearlyInterpolate (
const Points &points,
220 QPointF posGraphBefore;
221 bool foundIt =
false;
222 for (
int ip = 0; !foundIt && (ip < points.count()); ip++) {
224 const Point &point = points.at (ip);
233 if (xThetaValue <= posGraph.x() && (ip > 0)) {
240 double s = (xThetaValue - posGraphBefore.x()) / (posGraph.x() - posGraphBefore.x());
241 yRadius = (1.0 -s) * posGraphBefore.y() + s * posGraph.y();
246 posGraphBefore = posGraph;
251 if (points.count() > 1) {
255 int N = points.count();
256 const Point &pointLast = points.at (N - 1);
257 const Point &pointBefore = points.at (N - 2);
258 QPointF posGraphLast;
263 double s = (xThetaValue - posGraphBefore.x()) / (posGraphLast.x() - posGraphBefore.x());
264 yRadius = (1.0 - s) * posGraphBefore.y() + s * posGraphLast.y();
266 }
else if (points.count() == 1) {
269 yRadius = posGraphBefore.y();
273 ENGAUGE_ASSERT (
false);
284 const QStringList &curvesIncluded,
288 const ExportValuesXOrY &xThetaValues,
289 QVector<QVector<QString*> > &yRadiusValues)
const 291 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValues";
294 int curveCount = curvesIncluded.count();
295 for (
int col = 0; col < curveCount; col++) {
297 const QString curveName = curvesIncluded.at (col);
300 Points points = curve->
points ();
305 loadYRadiusValuesForCurveRaw (document.
modelCoords(),
311 yRadiusValues [col]);
317 loadYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
325 yRadiusValues [col]);
329 loadYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
335 yRadiusValues [col]);
341 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
344 const Points &points,
345 const ExportValuesXOrY &xThetaValues,
349 QVector<QString*> &yRadiusValues)
const 351 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth";
355 vector<SplinePair> xy;
367 QString dummyXThetaOut;
369 if (points.count() == 0) {
372 for (
int row = 0; row < xThetaValues.count(); row++) {
373 *(yRadiusValues [row]) =
"";
376 }
else if (points.count() == 1 ||
377 points.count() == 2) {
380 for (
int row = 0; row < xThetaValues.count(); row++) {
382 double xTheta = xThetaValues.at (row);
384 if (points.count() == 1) {
385 yRadius = xy.at (0).y ();
387 double x0 = xy.at (0).x ();
388 double x1 = xy.at (1).x ();
389 double y0 = xy.at (0).y ();
390 double y1 = xy.at (1).y ();
393 yRadius = xy.at (0).y ();
395 double s = (xTheta - x0) / (x1 - x0);
396 yRadius = (1.0 - s) * y0 + s * y1;
405 *(yRadiusValues [row]),
415 const int MAX_ITERATIONS = 32;
425 for (
int row = 0; row < xThetaValues.count(); row++) {
427 double xTheta = xThetaValues.at (row);
433 double yRadius = linearToLog.
delinearize (splinePairFound.
y (),
437 QString dummyXThetaOut;
444 *(yRadiusValues [row]),
451 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
454 const Points &points,
455 const ExportValuesXOrY &xThetaValues,
457 QVector<QString*> &yRadiusValues)
const 459 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight";
464 for (
int row = 0; row < xThetaValues.count(); row++) {
466 double xThetaValue = xThetaValues.at (row);
468 double yRadius = linearlyInterpolate (points,
473 QString dummyXThetaOut;
480 *(yRadiusValues [row]),
485 void ExportFileFunctions::loadYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
488 const Points &points,
489 const ExportValuesXOrY &xThetaValues,
491 QVector<QString*> &yRadiusValues)
const 493 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveRaw";
499 for (
int pt = 0; pt < points.count(); pt++) {
501 const Point &point = points.at (pt);
509 double closestSeparation = 0.0;
511 for (
int row = 0; row < xThetaValues.count(); row++) {
513 double xThetaValue = xThetaValues.at (row);
515 double separation = qAbs (posGraph.x() - xThetaValue);
518 (separation < closestSeparation)) {
520 closestSeparation = separation;
527 QString dummyXThetaOut;
534 *(yRadiusValues [rowClosest]),
543 const QStringList &curvesIncluded,
544 const ExportValuesXOrY &xThetaValuesMerged,
546 QVector<QVector<QString*> > &yRadiusValues,
547 const QString &delimiter,
548 QTextStream &str)
const 550 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::outputXThetaYRadiusValues";
553 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
554 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
555 str << curveSeparator (str.string());
556 str << gnuplotComment();
558 str << modelExportOverride.
xLabel();
559 QStringList::const_iterator itrHeader;
560 for (itrHeader = curvesIncluded.begin(); itrHeader != curvesIncluded.end(); itrHeader++) {
561 QString curveName = *itrHeader;
562 str << delimiter << curveName;
568 const double DUMMY_Y_RADIUS = 1.0;
570 for (
int row = 0; row < xThetaValuesMerged.count(); row++) {
572 if (rowHasAtLeastOneYRadiusEntry (yRadiusValues,
575 double xTheta = xThetaValuesMerged.at (row);
578 QString xThetaString, yRadiusString;
589 for (
int col = 0; col < yRadiusValues.count(); col++) {
591 str << delimiter << *(yRadiusValues [col] [row]);
599 bool ExportFileFunctions::rowHasAtLeastOneYRadiusEntry (
const QVector<QVector<QString*> > &yRadiusValues,
602 bool hasEntry =
false;
604 for (
int col = 0; col < yRadiusValues.count(); col++) {
606 QString entry = *(yRadiusValues [col] [row]);
607 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...
void exportToFile(const DocumentModelExportFormat &modelExportOverride, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, QTextStream &str) const
Export Document points according to the settings.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
Single X/Y pair for cubic spline interpolation initialization and calculations.