7 #include "CallbackGatherXThetaValuesFunctions.h"
8 #include "CurveConnectAs.h"
10 #include "EngaugeAssert.h"
11 #include "ExportFileFunctions.h"
12 #include "ExportLayoutFunctions.h"
13 #include "ExportOrdinalsSmooth.h"
14 #include "ExportXThetaValuesMergedFunctions.h"
15 #include "FormatCoordsUnits.h"
17 #include <QTextStream>
20 #include "SplinePair.h"
21 #include "Transformation.h"
33 const QStringList &curvesIncluded,
34 const ExportValuesXOrY &xThetaValues,
35 const QString &delimiter,
37 QTextStream &str)
const
39 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportAllPerLineXThetaValuesMerged";
41 int curveCount = curvesIncluded.count();
42 int xThetaCount = xThetaValues.count();
43 QVector<QVector<QString*> > yRadiusValues (curveCount, QVector<QString*> (xThetaCount));
44 initializeYRadiusValues (curvesIncluded,
47 loadYRadiusValues (modelExportOverride,
55 outputXThetaYRadiusValues (modelExportOverride,
64 destroy2DArray (yRadiusValues);
70 const QStringList &curvesIncluded,
71 const ExportValuesXOrY &xThetaValues,
72 const QString &delimiter,
74 QTextStream &str)
const
76 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportOnePerLineXThetaValuesMerged";
80 QStringList::const_iterator itr;
81 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
83 insertLineSeparator (isFirst,
84 modelExportOverride.
header(),
88 const int CURVE_COUNT = 1;
89 QString curveIncluded = *itr;
90 QStringList curvesIncluded (curveIncluded);
92 int xThetaCount = xThetaValues.count();
93 QVector<QVector<QString*> > yRadiusValues (CURVE_COUNT, QVector<QString*> (xThetaCount));
94 initializeYRadiusValues (curvesIncluded,
97 loadYRadiusValues (modelExportOverride,
104 outputXThetaYRadiusValues (modelExportOverride,
113 destroy2DArray (yRadiusValues);
121 QTextStream &str)
const
123 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportToFile";
126 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
129 CONNECT_AS_FUNCTION_SMOOTH,
130 CONNECT_AS_FUNCTION_STRAIGHT);
133 const QString delimiter = exportDelimiterToText (modelExportOverride.
delimiter(),
134 modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT);
140 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
145 ftor.xThetaValuesRaw(),
147 ExportValuesXOrY xThetaValuesMerged = exportXTheta.
xThetaValues ();
150 if (xThetaValuesMerged.count() > 0) {
153 if (modelExportOverride.
layoutFunctions() == EXPORT_LAYOUT_ALL_PER_LINE) {
154 exportAllPerLineXThetaValuesMerged (modelExportOverride,
163 exportOnePerLineXThetaValuesMerged (modelExportOverride,
175 void ExportFileFunctions::initializeYRadiusValues (
const QStringList &curvesIncluded,
176 const ExportValuesXOrY &xThetaValuesMerged,
177 QVector<QVector<QString*> > &yRadiusValues)
const
179 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::initializeYRadiusValues";
182 int curveCount = curvesIncluded.count();
183 int xThetaCount = xThetaValuesMerged.count();
184 for (
int row = 0; row < xThetaCount; row++) {
185 for (
int col = 0; col < curveCount; col++) {
186 yRadiusValues [col] [row] =
new QString;
191 double ExportFileFunctions::linearlyInterpolate (
const Points &points,
198 QPointF posGraphBefore;
199 bool foundIt =
false;
200 for (
int ip = 0; ip < points.count(); ip++) {
202 const Point &point = points.at (ip);
207 if (xThetaValue <= posGraph.x()) {
213 yRadius = posGraph.y();
219 double s = (xThetaValue - posGraphBefore.x()) / (posGraph.x() - posGraphBefore.x());
220 yRadius = (1.0 -s) * posGraphBefore.y() + s * posGraph.y();
226 posGraphBefore = posGraph;
232 yRadius = posGraphBefore.y();
242 const QStringList &curvesIncluded,
244 const ExportValuesXOrY &xThetaValues,
245 QVector<QVector<QString*> > &yRadiusValues)
const
247 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValues";
250 int curveCount = curvesIncluded.count();
251 for (
int col = 0; col < curveCount; col++) {
253 const QString curveName = curvesIncluded.at (col);
256 const Points points = curve->
points ();
261 loadYRadiusValuesForCurveRaw (document.
modelCoords(),
266 yRadiusValues [col]);
272 loadYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
277 yRadiusValues [col]);
281 loadYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
286 yRadiusValues [col]);
292 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
294 const Points &points,
295 const ExportValuesXOrY &xThetaValues,
297 QVector<QString*> &yRadiusValues)
const
299 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth";
303 vector<SplinePair> xy;
313 QString dummyXThetaOut;
315 if (points.count() == 0) {
318 for (
int row = 0; row < xThetaValues.count(); row++) {
319 *(yRadiusValues [row]) =
"";
322 }
else if (points.count() == 1 ||
323 points.count() == 2) {
326 for (
int row = 0; row < xThetaValues.count(); row++) {
328 double xTheta = xThetaValues.at (row);
330 if (points.count() == 1) {
331 yRadius = xy.at (0).y ();
333 double x0 = xy.at (0).x ();
334 double x1 = xy.at (1).x ();
335 double y0 = xy.at (0).y ();
336 double y1 = xy.at (1).y ();
339 yRadius = xy.at (0).y ();
341 double s = (xTheta - x0) / (x1 - x0);
342 yRadius = (1.0 - s) * y0 + s * y1;
350 *(yRadiusValues [row]),
360 const int MAX_ITERATIONS = 32;
370 for (
int row = 0; row < xThetaValues.count(); row++) {
372 double xTheta = xThetaValues.at (row);
373 SplinePair splinePairFound = spline.findSplinePairForFunctionX (xTheta,
375 double yRadius = splinePairFound.
y ();
378 QString dummyXThetaOut;
384 *(yRadiusValues [row]),
391 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
393 const Points &points,
394 const ExportValuesXOrY &xThetaValues,
396 QVector<QString*> &yRadiusValues)
const
398 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight";
403 for (
int row = 0; row < xThetaValues.count(); row++) {
405 double xThetaValue = xThetaValues.at (row);
407 double yRadius = linearlyInterpolate (points,
412 QString dummyXThetaOut;
418 *(yRadiusValues [row]),
423 void ExportFileFunctions::loadYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
425 const Points &points,
426 const ExportValuesXOrY &xThetaValues,
428 QVector<QString*> &yRadiusValues)
const
430 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveRaw";
436 for (
int pt = 0; pt < points.count(); pt++) {
438 const Point &point = points.at (pt);
446 double closestSeparation = 0.0;
448 for (
int row = 0; row < xThetaValues.count(); row++) {
450 double xThetaValue = xThetaValues.at (row);
452 double separation = qAbs (posGraph.x() - xThetaValue);
455 (separation < closestSeparation)) {
457 closestSeparation = separation;
464 QString dummyXThetaOut;
470 *(yRadiusValues [rowClosest]),
478 const QStringList &curvesIncluded,
479 const ExportValuesXOrY &xThetaValuesMerged,
481 QVector<QVector<QString*> > &yRadiusValues,
482 const QString &delimiter,
483 QTextStream &str)
const
485 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::outputXThetaYRadiusValues";
488 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
489 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
490 str << curveSeparator (str.string());
491 str << gnuplotComment();
493 str << modelExportOverride.
xLabel();
494 QStringList::const_iterator itrHeader;
495 for (itrHeader = curvesIncluded.begin(); itrHeader != curvesIncluded.end(); itrHeader++) {
496 QString curveName = *itrHeader;
497 str << delimiter << curveName;
503 const double DUMMY_Y_RADIUS = 1.0;
505 for (
int row = 0; row < xThetaValuesMerged.count(); row++) {
507 if (rowHasAtLeastOneYRadiusEntry (yRadiusValues,
510 double xTheta = xThetaValuesMerged.at (row);
513 QString xThetaString, yRadiusString;
523 for (
int col = 0; col < yRadiusValues.count(); col++) {
525 str << delimiter << *(yRadiusValues [col] [row]);
533 bool ExportFileFunctions::rowHasAtLeastOneYRadiusEntry (
const QVector<QVector<QString*> > &yRadiusValues,
536 bool hasEntry =
false;
538 for (
int col = 0; col < yRadiusValues.count(); col++) {
540 QString entry = *(yRadiusValues [col] [row]);
541 if (!entry.isEmpty()) {
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.
void exportToFile(const DocumentModelExportFormat &modelExportOverride, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, QTextStream &str) const
Export Document points according to the settings.