7 #include "CurveConnectAs.h"
9 #include "DocumentModelGeneral.h"
10 #include "EngaugeAssert.h"
11 #include "ExportFileRelations.h"
12 #include "ExportLayoutFunctions.h"
13 #include "ExportOrdinalsSmooth.h"
14 #include "ExportOrdinalsStraight.h"
15 #include "FormatCoordsUnits.h"
19 #include <QTextStream>
22 #include "SplinePair.h"
23 #include "Transformation.h"
28 const int COLUMNS_PER_CURVE = 2;
37 const QStringList &curvesIncluded,
38 const QString &delimiter,
42 QTextStream &str)
const
44 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportAllPerLineXThetaValuesMerged";
46 int maxColumnSize = maxColumnSizeAllocation (modelExportOverride,
54 if (maxColumnSize > 0) {
58 exportAllPerLineXThetaValuesMergedMultiplePass (maxColumnSize,
71 exportAllPerLineXThetaValuesMergedOnePass (maxColumnSize,
85 void ExportFileRelations::exportAllPerLineXThetaValuesMergedMultiplePass (
int maxColumnSize,
89 const QStringList &curvesIncluded,
90 const QString &delimiter,
94 QTextStream &str)
const
102 const int CURVE_COUNT_PER_PASS = 1;
104 int curveCount = curvesIncluded.count ();
106 QVector<QVector<QString*> > xThetaYRadiusValuesAll (COLUMNS_PER_CURVE * curveCount, QVector<QString*> (maxColumnSize));
108 initializeXThetaYRadiusValues (curvesIncluded,
109 xThetaYRadiusValuesAll);
112 int colX = 0, colY = colX + 1;
113 for (
int c = 0; c < curvesIncluded.count (); c++) {
114 QString curve = curvesIncluded [c];
116 QStringList curvesIncludedInPass;
117 curvesIncludedInPass << curve;
118 ENGAUGE_ASSERT (curvesIncludedInPass.count () == CURVE_COUNT_PER_PASS);
120 QVector<QVector<QString*> > xThetaYRadiusValuesOne (COLUMNS_PER_CURVE * CURVE_COUNT_PER_PASS, QVector<QString*> (maxColumnSize));
122 initializeXThetaYRadiusValues (curvesIncludedInPass,
123 xThetaYRadiusValuesOne);
124 loadXThetaYRadiusValues (modelExportOverride,
127 curvesIncludedInPass,
131 xThetaYRadiusValuesOne);
134 for (
int row = 0; row < maxColumnSize; row++) {
135 *(xThetaYRadiusValuesAll [colX] [row]) = *(xThetaYRadiusValuesOne [0] [row]);
136 *(xThetaYRadiusValuesAll [colY] [row]) = *(xThetaYRadiusValuesOne [1] [row]);
139 destroy2DArray (xThetaYRadiusValuesOne);
145 outputXThetaYRadiusValues (modelExportOverride,
147 xThetaYRadiusValuesAll,
150 destroy2DArray (xThetaYRadiusValuesAll);
153 void ExportFileRelations::exportAllPerLineXThetaValuesMergedOnePass (
int maxColumnSize,
157 const QStringList &curvesIncluded,
158 const QString &delimiter,
162 QTextStream &str)
const
164 int curveCount = curvesIncluded.count ();
166 QVector<QVector<QString*> > xThetaYRadiusValues (COLUMNS_PER_CURVE * curveCount, QVector<QString*> (maxColumnSize));
167 initializeXThetaYRadiusValues (curvesIncluded,
168 xThetaYRadiusValues);
169 loadXThetaYRadiusValues (modelExportOverride,
176 xThetaYRadiusValues);
177 outputXThetaYRadiusValues (modelExportOverride,
182 destroy2DArray (xThetaYRadiusValues);
188 const QStringList &curvesIncluded,
189 const QString &delimiter,
193 QTextStream &str)
const
195 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportOnePerLineXThetaValuesMerged";
197 QStringList::const_iterator itr;
198 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
200 QString curveIncluded = *itr;
202 exportAllPerLineXThetaValuesMerged (modelExportOverride,
205 QStringList (curveIncluded),
218 QTextStream &str)
const
220 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportToFile";
227 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
230 CONNECT_AS_RELATION_SMOOTH,
231 CONNECT_AS_RELATION_STRAIGHT);
234 const QString delimiter = exportDelimiterToText (modelExportOverride.
delimiter(),
235 modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT);
238 if (modelExportOverride.
layoutFunctions() == EXPORT_LAYOUT_ALL_PER_LINE) {
239 exportAllPerLineXThetaValuesMerged (modelExportOverride,
249 exportOnePerLineXThetaValuesMerged (modelExportOverride,
261 void ExportFileRelations::initializeXThetaYRadiusValues (
const QStringList &curvesIncluded,
262 QVector<QVector<QString*> > &xThetaYRadiusValues)
const
264 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::initializeXThetaYRadiusValues";
267 int curveCount = curvesIncluded.count();
268 int xThetaCount = xThetaYRadiusValues [0].count();
269 for (
int row = 0; row < xThetaCount; row++) {
270 for (
int col = 0; col < COLUMNS_PER_CURVE * curveCount; col++) {
271 xThetaYRadiusValues [col] [row] =
new QString;
276 QPointF ExportFileRelations::linearlyInterpolate (
const Points &points,
282 double xTheta = 0, yRadius = 0;
283 double ordinalBefore = 0;
284 QPointF posGraphBefore;
285 bool foundIt =
false;
286 for (
int ip = 0; ip < points.count(); ip++) {
288 const Point &point = points.at (ip);
293 if (ordinal <= point.
ordinal()) {
299 xTheta = posGraph.x();
300 yRadius = posGraph.y();
306 double s = (ordinal - ordinalBefore) / (point.
ordinal() - ordinalBefore);
307 xTheta = (1.0 - s) * posGraphBefore.x() + s * posGraph.x();
308 yRadius = (1.0 - s) * posGraphBefore.y() + s * posGraph.y();
314 ordinalBefore = point.
ordinal();
315 posGraphBefore = posGraph;
321 xTheta = posGraphBefore.x();
322 yRadius = posGraphBefore.y();
326 return QPointF (xTheta,
333 const QStringList &curvesIncluded,
337 QVector<QVector<QString*> > &xThetaYRadiusValues)
const
339 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValues";
342 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
344 int colXTheta = 2 * ic;
345 int colYRadius = 2 * ic + 1;
347 const QString curveName = curvesIncluded.at (ic);
350 const Points points = curve->
points ();
355 loadXThetaYRadiusValuesForCurveRaw (document.
modelCoords(),
359 xThetaYRadiusValues [colXTheta],
360 xThetaYRadiusValues [colYRadius],
377 loadXThetaYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
382 xThetaYRadiusValues [colXTheta],
383 xThetaYRadiusValues [colYRadius],
390 loadXThetaYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
395 xThetaYRadiusValues [colXTheta],
396 xThetaYRadiusValues [colYRadius],
403 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
406 const Points &points,
407 const ExportValuesOrdinal &ordinals,
408 QVector<QString*> &xThetaValues,
409 QVector<QString*> &yRadiusValues,
412 bool isLogYRadius)
const
414 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth";
417 vector<SplinePair> xy;
437 for (
int row = 0; row < ordinals.count(); row++) {
439 double ordinal = ordinals.at (row);
440 SplinePair splinePairFound = spline.interpolateCoeff(ordinal);
441 double xTheta = splinePairFound.
x ();
442 double yRadius = splinePairFound.
y ();
450 *(xThetaValues [row]),
451 *(yRadiusValues [row]),
457 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
460 const Points &points,
461 const ExportValuesOrdinal &ordinals,
462 QVector<QString*> &xThetaValues,
463 QVector<QString*> &yRadiusValues,
466 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight";
471 for (
int row = 0; row < ordinals.count(); row++) {
473 double ordinal = ordinals.at (row);
475 QPointF pointInterpolated = linearlyInterpolate (points,
481 pointInterpolated.y(),
485 *(xThetaValues [row]),
486 *(yRadiusValues [row]),
491 void ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
494 const Points &points,
495 QVector<QString*> &xThetaValues,
496 QVector<QString*> &yRadiusValues,
499 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw";
503 for (
int pt = 0; pt < points.count(); pt++) {
505 const Point &point = points.at (pt);
517 *(xThetaValues [pt]),
518 *(yRadiusValues [pt]),
528 const QStringList &curvesIncluded)
const
530 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::maxColumnSizeAllocation";
532 int maxColumnSize = 0;
535 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
537 const QString curveName = curvesIncluded.at (ic);
540 const Points points = curve->
points ();
545 maxColumnSize = qMax (maxColumnSize,
562 maxColumnSize = qMax (maxColumnSize,
567 return maxColumnSize;
570 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervals (
double pointsIntervalRelations,
571 ExportPointsIntervalUnits pointsIntervalUnits,
572 CurveConnectAs curveConnectAs,
576 const Points &points)
const
578 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervals";
580 if (pointsIntervalUnits == EXPORT_POINTS_INTERVAL_UNITS_GRAPH) {
581 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
583 return ordinalsAtIntervalsSmoothGraph (pointsIntervalRelations,
591 return ordinalsAtIntervalsStraightGraph (pointsIntervalRelations,
598 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
600 return ordinalsAtIntervalsSmoothScreen (pointsIntervalRelations,
605 return ordinalsAtIntervalsStraightScreen (pointsIntervalRelations,
612 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothGraph (
double pointsIntervalRelations,
616 const Points &points)
const
618 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothGraph";
620 ExportValuesOrdinal ordinals;
623 if ((pointsIntervalRelations > 0) &&
624 (points.count() > 0)) {
627 vector<SplinePair> xy;
639 pointsIntervalRelations);
645 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothScreen (
double pointsIntervalRelations,
646 const Points &points)
const
648 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothScreen"
649 <<
" pointCount=" << points.count();
652 ExportValuesOrdinal ordinals;
655 if ((pointsIntervalRelations > 0) &&
656 (points.count() > 0)) {
659 vector<SplinePair> xy;
668 pointsIntervalRelations);
674 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightGraph (
double pointsIntervalRelations,
676 const Points &points)
const
678 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightGraph";
680 ExportValuesOrdinal ordinals;
683 if ((pointsIntervalRelations > 0) &&
684 (points.count() > 0)) {
690 pointsIntervalRelations);
696 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightScreen (
double pointsIntervalRelations,
697 const Points &points)
const
699 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightScreen"
700 <<
" pointCount=" << points.count();
703 ExportValuesOrdinal ordinals;
706 if ((pointsIntervalRelations > 0) &&
707 (points.count() > 0)) {
712 pointsIntervalRelations);
719 const QStringList &curvesIncluded,
720 QVector<QVector<QString*> > &xThetaYRadiusValues,
721 const QString &delimiter,
722 QTextStream &str)
const
724 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::outputXThetaYRadiusValues";
727 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
728 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
729 str << curveSeparator(str.string());
730 str << gnuplotComment();
732 QString delimiterForRow;
733 QStringList::const_iterator itr;
734 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
735 QString curveName = *itr;
736 str << delimiterForRow << modelExportOverride.
xLabel();
737 delimiterForRow = delimiter;
738 str << delimiterForRow << curveName;
743 for (
int row = 0; row < xThetaYRadiusValues [0].count(); row++) {
745 QString delimiterForRow;
746 for (
int col = 0; col < xThetaYRadiusValues.count(); col++) {
748 str << delimiterForRow << *(xThetaYRadiusValues [col] [row]);
749 delimiterForRow = delimiter;
Model for DlgSettingsGeneral and CmdSettingsGeneral.
Cubic interpolation given independent and dependent value vectors.
const Points points() const
Return a shallow copy of the Points.
void exportToFile(const DocumentModelExportFormat &modelExportOverride, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, QTextStream &str) const
Export Document points according to the settings.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
LineStyle lineStyle() const
Get method for LineStyle.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
double y() const
Get method for y.
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...
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
QPointF posScreen() const
Accessor for screen position.
const LineStyle lineStyle(const QString &curveName) const
Get method for copying one line style in one step.
ExportValuesOrdinal ordinalsAtIntervalsGraphWithoutTransformation(const Points &points, double pointsInterval) const
Compute ordinals, without any conversion to graph coordinates.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
Model for DlgSettingsMainWindow.
void loadSplinePairsWithoutTransformation(const Points &points, std::vector< double > &t, std::vector< SplinePair > &xy) const
Load t (=ordinal) and xy (=screen position) spline pairs, without any conversion to graph coordinates...
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.
ExportValuesOrdinal ordinalsAtIntervalsGraph(const std::vector< double > &t, const std::vector< SplinePair > &xy, double pointsInterval) const
Perform the interpolation on the arrays loaded by the other methods.
Details for a specific Line.
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
Utility class to interpolate points spaced evenly along a piecewise defined curve with line segments ...
double x() const
Get method for x.
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.
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
ExportFileRelations()
Single constructor.
CurveConnectAs curveConnectAs() const
Get method for connect type.
ExportValuesOrdinal ordinalsAtIntervalsGraphWithTransformation(const Points &points, const Transformation &transformation, double pointsInterval) const
Compute ordinals, converting screen coordinates to graph coordinates.
Single X/Y pair for cubic spline interpolation initialization and calculations.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.