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"
18 #include <QTextStream>
21 #include "SplinePair.h"
22 #include "Transformation.h"
34 const QStringList &curvesIncluded,
35 const ExportValuesXOrY &xThetaValues,
36 const QString &delimiter,
38 QTextStream &str)
const
40 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportAllPerLineXThetaValuesMerged";
42 int curveCount = curvesIncluded.count();
43 int xThetaCount = xThetaValues.count();
44 QVector<QVector<QString*> > yRadiusValues (curveCount, QVector<QString*> (xThetaCount));
45 initializeYRadiusValues (curvesIncluded,
48 loadYRadiusValues (modelExportOverride,
56 outputXThetaYRadiusValues (modelExportOverride,
66 destroy2DArray (yRadiusValues);
72 const QStringList &curvesIncluded,
73 const ExportValuesXOrY &xThetaValues,
74 const QString &delimiter,
76 QTextStream &str)
const
78 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportOnePerLineXThetaValuesMerged";
82 QStringList::const_iterator itr;
83 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
85 insertLineSeparator (isFirst,
86 modelExportOverride.
header(),
90 const int CURVE_COUNT = 1;
91 QString curveIncluded = *itr;
92 QStringList curvesIncluded (curveIncluded);
94 int xThetaCount = xThetaValues.count();
95 QVector<QVector<QString*> > yRadiusValues (CURVE_COUNT, QVector<QString*> (xThetaCount));
96 initializeYRadiusValues (curvesIncluded,
99 loadYRadiusValues (modelExportOverride,
106 outputXThetaYRadiusValues (modelExportOverride,
116 destroy2DArray (yRadiusValues);
124 QTextStream &str)
const
126 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportToFile";
129 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
132 CONNECT_AS_FUNCTION_SMOOTH,
133 CONNECT_AS_FUNCTION_STRAIGHT);
136 const QString delimiter = exportDelimiterToText (modelExportOverride.
delimiter(),
137 modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT);
143 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
148 ftor.xThetaValuesRaw(),
150 ExportValuesXOrY xThetaValuesMerged = exportXTheta.
xThetaValues ();
153 if (xThetaValuesMerged.count() > 0) {
156 if (modelExportOverride.
layoutFunctions() == EXPORT_LAYOUT_ALL_PER_LINE) {
157 exportAllPerLineXThetaValuesMerged (modelExportOverride,
166 exportOnePerLineXThetaValuesMerged (modelExportOverride,
178 void ExportFileFunctions::initializeYRadiusValues (
const QStringList &curvesIncluded,
179 const ExportValuesXOrY &xThetaValuesMerged,
180 QVector<QVector<QString*> > &yRadiusValues)
const
182 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::initializeYRadiusValues";
185 int curveCount = curvesIncluded.count();
186 int xThetaCount = xThetaValuesMerged.count();
187 for (
int row = 0; row < xThetaCount; row++) {
188 for (
int col = 0; col < curveCount; col++) {
189 yRadiusValues [col] [row] =
new QString;
194 double ExportFileFunctions::linearlyInterpolate (
const Points &points,
203 QPointF posGraphBefore;
204 bool foundIt =
false;
205 for (
int ip = 0; !foundIt && (ip < points.count()); ip++) {
207 const Point &point = points.at (ip);
216 if (xThetaValue <= posGraph.x() && (ip > 0)) {
223 double s = (xThetaValue - posGraphBefore.x()) / (posGraph.x() - posGraphBefore.x());
224 yRadius = (1.0 -s) * posGraphBefore.y() + s * posGraph.y();
229 posGraphBefore = posGraph;
234 if (points.count() > 1) {
238 int N = points.count();
239 const Point &pointLast = points.at (N - 1);
240 const Point &pointBefore = points.at (N - 2);
241 QPointF posGraphLast;
246 double s = (xThetaValue - posGraphBefore.x()) / (posGraphLast.x() - posGraphBefore.x());
247 yRadius = (1.0 - s) * posGraphBefore.y() + s * posGraphLast.y();
249 }
else if (points.count() == 1) {
252 yRadius = posGraphBefore.y();
256 ENGAUGE_ASSERT (
false);
267 const QStringList &curvesIncluded,
269 const ExportValuesXOrY &xThetaValues,
270 QVector<QVector<QString*> > &yRadiusValues)
const
272 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValues";
275 int curveCount = curvesIncluded.count();
276 for (
int col = 0; col < curveCount; col++) {
278 const QString curveName = curvesIncluded.at (col);
281 const Points points = curve->
points ();
286 loadYRadiusValuesForCurveRaw (document.
modelCoords(),
292 yRadiusValues [col]);
298 loadYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
304 yRadiusValues [col]);
308 loadYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
314 yRadiusValues [col]);
320 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
323 const Points &points,
324 const ExportValuesXOrY &xThetaValues,
326 QVector<QString*> &yRadiusValues)
const
328 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth";
332 vector<SplinePair> xy;
342 QString dummyXThetaOut;
344 if (points.count() == 0) {
347 for (
int row = 0; row < xThetaValues.count(); row++) {
348 *(yRadiusValues [row]) =
"";
351 }
else if (points.count() == 1 ||
352 points.count() == 2) {
355 for (
int row = 0; row < xThetaValues.count(); row++) {
357 double xTheta = xThetaValues.at (row);
359 if (points.count() == 1) {
360 yRadius = xy.at (0).y ();
362 double x0 = xy.at (0).x ();
363 double x1 = xy.at (1).x ();
364 double y0 = xy.at (0).y ();
365 double y1 = xy.at (1).y ();
368 yRadius = xy.at (0).y ();
370 double s = (xTheta - x0) / (x1 - x0);
371 yRadius = (1.0 - s) * y0 + s * y1;
380 *(yRadiusValues [row]),
390 const int MAX_ITERATIONS = 32;
400 for (
int row = 0; row < xThetaValues.count(); row++) {
402 double xTheta = xThetaValues.at (row);
403 SplinePair splinePairFound = spline.findSplinePairForFunctionX (xTheta,
405 double yRadius = splinePairFound.
y ();
408 QString dummyXThetaOut;
415 *(yRadiusValues [row]),
422 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
425 const Points &points,
426 const ExportValuesXOrY &xThetaValues,
428 QVector<QString*> &yRadiusValues)
const
430 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight";
435 for (
int row = 0; row < xThetaValues.count(); row++) {
437 double xThetaValue = xThetaValues.at (row);
439 double yRadius = linearlyInterpolate (points,
444 QString dummyXThetaOut;
451 *(yRadiusValues [row]),
456 void ExportFileFunctions::loadYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
459 const Points &points,
460 const ExportValuesXOrY &xThetaValues,
462 QVector<QString*> &yRadiusValues)
const
464 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveRaw";
470 for (
int pt = 0; pt < points.count(); pt++) {
472 const Point &point = points.at (pt);
480 double closestSeparation = 0.0;
482 for (
int row = 0; row < xThetaValues.count(); row++) {
484 double xThetaValue = xThetaValues.at (row);
486 double separation = qAbs (posGraph.x() - xThetaValue);
489 (separation < closestSeparation)) {
491 closestSeparation = separation;
498 QString dummyXThetaOut;
505 *(yRadiusValues [rowClosest]),
514 const QStringList &curvesIncluded,
515 const ExportValuesXOrY &xThetaValuesMerged,
517 QVector<QVector<QString*> > &yRadiusValues,
518 const QString &delimiter,
519 QTextStream &str)
const
521 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::outputXThetaYRadiusValues";
524 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
525 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
526 str << curveSeparator (str.string());
527 str << gnuplotComment();
529 str << modelExportOverride.
xLabel();
530 QStringList::const_iterator itrHeader;
531 for (itrHeader = curvesIncluded.begin(); itrHeader != curvesIncluded.end(); itrHeader++) {
532 QString curveName = *itrHeader;
533 str << delimiter << curveName;
539 const double DUMMY_Y_RADIUS = 1.0;
541 for (
int row = 0; row < xThetaValuesMerged.count(); row++) {
543 if (rowHasAtLeastOneYRadiusEntry (yRadiusValues,
546 double xTheta = xThetaValuesMerged.at (row);
549 QString xThetaString, yRadiusString;
560 for (
int col = 0; col < yRadiusValues.count(); col++) {
562 str << delimiter << *(yRadiusValues [col] [row]);
570 bool ExportFileFunctions::rowHasAtLeastOneYRadiusEntry (
const QVector<QVector<QString*> > &yRadiusValues,
573 bool hasEntry =
false;
575 for (
int col = 0; col < yRadiusValues.count(); col++) {
577 QString entry = *(yRadiusValues [col] [row]);
578 if (!entry.isEmpty()) {
Model for DlgSettingsGeneral and CmdSettingsGeneral.
Creates the set of merged x/theta values for exporting functions, using interpolation.
Cubic interpolation given independent and dependent value vectors.
const Points points() const
Return a shallow copy of the Points.
ExportValuesXOrY xThetaValues() const
Resulting x/theta values for all included functions.
LineStyle lineStyle() const
Get method for LineStyle.
ExportFileFunctions()
Single constructor.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
double y() const
Get method for y.
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.
void loadSplinePairsWithTransformation(const Points &points, const Transformation &transformation, std::vector< double > &t, std::vector< SplinePair > &xy) const
Load t (=ordinal) and xy (=screen position) spline pairs, converting screen coordinates to graph coor...
Model for DlgSettingsMainWindow.
Utility class to interpolate points spaced evenly along a piecewise defined curve with fitted spline...
Model for DlgSettingsCoords and CmdSettingsCoords.
Storage of one imported image and the data attached to that image.
Container for one set of digitized Points.
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
CurveStyle curveStyle() const
Return the curve style.
void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
CurveConnectAs curveConnectAs() const
Get method for connect type.
Callback for collecting X/Theta independent variables, for functions, in preparation for exporting...
Single X/Y pair for cubic spline interpolation initialization and calculations.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
void exportToFile(const DocumentModelExportFormat &modelExportOverride, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, QTextStream &str) const
Export Document points according to the settings.