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,
43 unsigned int &numWritesSoFar)
const 45 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportAllPerLineXThetaValuesMerged";
47 int maxColumnSize = maxColumnSizeAllocation (modelExportOverride,
55 if (maxColumnSize > 0) {
59 exportAllPerLineXThetaValuesMergedMultiplePass (maxColumnSize,
73 exportAllPerLineXThetaValuesMergedOnePass (maxColumnSize,
88 void ExportFileRelations::exportAllPerLineXThetaValuesMergedMultiplePass (
int maxColumnSize,
92 const QStringList &curvesIncluded,
93 const QString &delimiter,
98 unsigned int &numWritesSoFar)
const 106 const int CURVE_COUNT_PER_PASS = 1;
108 int curveCount = curvesIncluded.count ();
110 QVector<QVector<QString*> > xThetaYRadiusValuesAll (COLUMNS_PER_CURVE * curveCount, QVector<QString*> (maxColumnSize));
112 initializeXThetaYRadiusValues (curvesIncluded,
113 xThetaYRadiusValuesAll);
116 int colX = 0, colY = colX + 1;
117 for (
int c = 0; c < curvesIncluded.count (); c++) {
118 QString curve = curvesIncluded [c];
120 QStringList curvesIncludedInPass;
121 curvesIncludedInPass << curve;
122 ENGAUGE_ASSERT (curvesIncludedInPass.count () == CURVE_COUNT_PER_PASS);
124 QVector<QVector<QString*> > xThetaYRadiusValuesOne (COLUMNS_PER_CURVE * CURVE_COUNT_PER_PASS, QVector<QString*> (maxColumnSize));
126 initializeXThetaYRadiusValues (curvesIncludedInPass,
127 xThetaYRadiusValuesOne);
128 loadXThetaYRadiusValues (modelExportOverride,
131 curvesIncludedInPass,
135 xThetaYRadiusValuesOne);
138 for (
int row = 0; row < maxColumnSize; row++) {
139 *(xThetaYRadiusValuesAll [colX] [row]) = *(xThetaYRadiusValuesOne [0] [row]);
140 *(xThetaYRadiusValuesAll [colY] [row]) = *(xThetaYRadiusValuesOne [1] [row]);
143 destroy2DArray (xThetaYRadiusValuesOne);
149 outputXThetaYRadiusValues (modelExportOverride,
151 xThetaYRadiusValuesAll,
155 destroy2DArray (xThetaYRadiusValuesAll);
158 void ExportFileRelations::exportAllPerLineXThetaValuesMergedOnePass (
int maxColumnSize,
162 const QStringList &curvesIncluded,
163 const QString &delimiter,
168 unsigned int &numWritesSoFar)
const 170 int curveCount = curvesIncluded.count ();
172 QVector<QVector<QString*> > xThetaYRadiusValues (COLUMNS_PER_CURVE * curveCount, QVector<QString*> (maxColumnSize));
173 initializeXThetaYRadiusValues (curvesIncluded,
174 xThetaYRadiusValues);
175 loadXThetaYRadiusValues (modelExportOverride,
182 xThetaYRadiusValues);
183 outputXThetaYRadiusValues (modelExportOverride,
189 destroy2DArray (xThetaYRadiusValues);
195 const QStringList &curvesIncluded,
196 const QString &delimiter,
201 unsigned int &numWritesSoFar)
const 203 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportOnePerLineXThetaValuesMerged";
205 QStringList::const_iterator itr;
206 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
208 QString curveIncluded = *itr;
210 exportAllPerLineXThetaValuesMerged (modelExportOverride,
213 QStringList (curveIncluded),
228 unsigned int &numWritesSoFar)
const 230 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportToFile";
237 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
240 CONNECT_AS_RELATION_SMOOTH,
241 CONNECT_AS_RELATION_STRAIGHT);
244 const QString delimiter = exportDelimiterToText (modelExportOverride.
delimiter(),
245 modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT);
248 if (modelExportOverride.
layoutFunctions() == EXPORT_LAYOUT_ALL_PER_LINE) {
249 exportAllPerLineXThetaValuesMerged (modelExportOverride,
260 exportOnePerLineXThetaValuesMerged (modelExportOverride,
273 void ExportFileRelations::initializeXThetaYRadiusValues (
const QStringList &curvesIncluded,
274 QVector<QVector<QString*> > &xThetaYRadiusValues)
const 276 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::initializeXThetaYRadiusValues";
279 int curveCount = curvesIncluded.count();
280 int xThetaCount = xThetaYRadiusValues [0].count();
281 for (
int row = 0; row < xThetaCount; row++) {
282 for (
int col = 0; col < COLUMNS_PER_CURVE * curveCount; col++) {
283 xThetaYRadiusValues [col] [row] =
new QString;
288 QPointF ExportFileRelations::linearlyInterpolate (
const Points &points,
294 double xTheta = 0, yRadius = 0;
295 double ordinalBefore = 0;
296 QPointF posGraphBefore;
297 bool foundIt =
false;
298 for (
int ip = 0; ip < points.count(); ip++) {
300 const Point &point = points.at (ip);
305 if (ordinal <= point.
ordinal()) {
311 xTheta = posGraph.x();
312 yRadius = posGraph.y();
318 double s = (ordinal - ordinalBefore) / (point.
ordinal() - ordinalBefore);
319 xTheta = (1.0 - s) * posGraphBefore.x() + s * posGraph.x();
320 yRadius = (1.0 - s) * posGraphBefore.y() + s * posGraph.y();
326 ordinalBefore = point.
ordinal();
327 posGraphBefore = posGraph;
333 xTheta = posGraphBefore.x();
334 yRadius = posGraphBefore.y();
338 return QPointF (xTheta,
345 const QStringList &curvesIncluded,
349 QVector<QVector<QString*> > &xThetaYRadiusValues)
const 351 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValues";
354 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
356 int colXTheta = 2 * ic;
357 int colYRadius = 2 * ic + 1;
359 const QString curveName = curvesIncluded.at (ic);
362 const Points points = curve->
points ();
367 loadXThetaYRadiusValuesForCurveRaw (document.
modelCoords(),
371 xThetaYRadiusValues [colXTheta],
372 xThetaYRadiusValues [colYRadius],
389 loadXThetaYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
394 xThetaYRadiusValues [colXTheta],
395 xThetaYRadiusValues [colYRadius],
402 loadXThetaYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
407 xThetaYRadiusValues [colXTheta],
408 xThetaYRadiusValues [colYRadius],
415 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
418 const Points &points,
419 const ExportValuesOrdinal &ordinals,
420 QVector<QString*> &xThetaValues,
421 QVector<QString*> &yRadiusValues,
424 bool isLogYRadius)
const 426 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth";
429 vector<SplinePair> xy;
449 for (
int row = 0; row < ordinals.count(); row++) {
451 double ordinal = ordinals.at (row);
453 double xTheta = splinePairFound.
x ();
454 double yRadius = splinePairFound.
y ();
462 *(xThetaValues [row]),
463 *(yRadiusValues [row]),
469 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
472 const Points &points,
473 const ExportValuesOrdinal &ordinals,
474 QVector<QString*> &xThetaValues,
475 QVector<QString*> &yRadiusValues,
478 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight";
483 for (
int row = 0; row < ordinals.count(); row++) {
485 double ordinal = ordinals.at (row);
487 QPointF pointInterpolated = linearlyInterpolate (points,
493 pointInterpolated.y(),
497 *(xThetaValues [row]),
498 *(yRadiusValues [row]),
503 void ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
506 const Points &points,
507 QVector<QString*> &xThetaValues,
508 QVector<QString*> &yRadiusValues,
511 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw";
515 for (
int pt = 0; pt < points.count(); pt++) {
517 const Point &point = points.at (pt);
529 *(xThetaValues [pt]),
530 *(yRadiusValues [pt]),
540 const QStringList &curvesIncluded)
const 542 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::maxColumnSizeAllocation";
544 int maxColumnSize = 0;
547 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
549 const QString curveName = curvesIncluded.at (ic);
552 const Points points = curve->
points ();
557 maxColumnSize = qMax (maxColumnSize,
574 maxColumnSize = qMax (maxColumnSize,
579 return maxColumnSize;
582 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervals (
double pointsIntervalRelations,
583 ExportPointsIntervalUnits pointsIntervalUnits,
584 CurveConnectAs curveConnectAs,
588 const Points &points)
const 590 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervals";
592 if (pointsIntervalUnits == EXPORT_POINTS_INTERVAL_UNITS_GRAPH) {
593 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
595 return ordinalsAtIntervalsSmoothGraph (pointsIntervalRelations,
603 return ordinalsAtIntervalsStraightGraph (pointsIntervalRelations,
610 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
612 return ordinalsAtIntervalsSmoothScreen (pointsIntervalRelations,
617 return ordinalsAtIntervalsStraightScreen (pointsIntervalRelations,
624 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothGraph (
double pointsIntervalRelations,
628 const Points &points)
const 630 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothGraph";
632 ExportValuesOrdinal ordinals;
635 if ((pointsIntervalRelations > 0) &&
636 (points.count() > 0)) {
639 vector<SplinePair> xy;
651 pointsIntervalRelations);
657 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothScreen (
double pointsIntervalRelations,
658 const Points &points)
const 660 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothScreen" 661 <<
" pointCount=" << points.count();
664 ExportValuesOrdinal ordinals;
667 if ((pointsIntervalRelations > 0) &&
668 (points.count() > 0)) {
671 vector<SplinePair> xy;
680 pointsIntervalRelations);
686 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightGraph (
double pointsIntervalRelations,
688 const Points &points)
const 690 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightGraph";
692 ExportValuesOrdinal ordinals;
695 if ((pointsIntervalRelations > 0) &&
696 (points.count() > 0)) {
702 pointsIntervalRelations);
708 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightScreen (
double pointsIntervalRelations,
709 const Points &points)
const 711 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightScreen" 712 <<
" pointCount=" << points.count();
715 ExportValuesOrdinal ordinals;
718 if ((pointsIntervalRelations > 0) &&
719 (points.count() > 0)) {
724 pointsIntervalRelations);
731 const QStringList &curvesIncluded,
732 QVector<QVector<QString*> > &xThetaYRadiusValues,
733 const QString &delimiter,
735 unsigned int &numWritesSoFar)
const 737 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::outputXThetaYRadiusValues";
740 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
741 insertLineSeparator (numWritesSoFar == 0,
742 modelExportOverride.
header (),
744 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
745 str << gnuplotComment();
747 QString delimiterForRow;
748 QStringList::const_iterator itr;
749 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
750 QString curveName = *itr;
751 str << delimiterForRow << modelExportOverride.
xLabel();
752 delimiterForRow = delimiter;
753 str << delimiterForRow << curveName;
759 for (
int row = 0; row < xThetaYRadiusValues [0].count(); row++) {
761 QString delimiterForRow;
762 for (
int col = 0; col < xThetaYRadiusValues.count(); col++) {
764 QString xThetaString = *(xThetaYRadiusValues [col] [row]);
765 str << delimiterForRow << wrapInDoubleQuotesIfNeeded (modelExportOverride,
767 delimiterForRow = delimiter;
Model for DlgSettingsGeneral and CmdSettingsGeneral.
CurveConnectAs curveConnectAs() const
Get method for connect type.
Cubic interpolation given independent and dependent value vectors.
ExportValuesOrdinal ordinalsAtIntervalsGraphWithTransformation(const Points &points, const Transformation &transformation, double pointsInterval) const
Compute ordinals, converting screen coordinates to graph coordinates.
SplinePair interpolateCoeff(double t) const
Return interpolated y for specified x.
double y() const
Get method for y.
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
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.
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.
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
const Points points() const
Return a shallow copy of the Points.
Model for DlgSettingsMainWindow.
const LineStyle lineStyle(const QString &curveName) const
Get method for copying one line style in one step.
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.
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.
Storage of one imported image and the data attached to that image.
Container for one set of digitized Points.
Details for a specific Line.
Utility class to interpolate points spaced evenly along a piecewise defined curve with line segments ...
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.
CurveStyle curveStyle() const
Return the curve style.
ExportFileRelations()
Single constructor.
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
double x() const
Get method for x.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
Single X/Y pair for cubic spline interpolation initialization and calculations.
ExportValuesOrdinal ordinalsAtIntervalsGraphWithoutTransformation(const Points &points, double pointsInterval) const
Compute ordinals, without any conversion to graph coordinates.
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...