7 #include "CurveConnectAs.h"
9 #include "EngaugeAssert.h"
10 #include "ExportFileRelations.h"
11 #include "ExportLayoutFunctions.h"
12 #include "ExportOrdinalsSmooth.h"
13 #include "ExportOrdinalsStraight.h"
14 #include "FormatCoordsUnits.h"
18 #include <QTextStream>
21 #include "SplinePair.h"
22 #include "Transformation.h"
27 const int COLUMNS_PER_CURVE = 2;
36 const QStringList &curvesIncluded,
37 const QString &delimiter,
39 QTextStream &str)
const
41 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportAllPerLineXThetaValuesMerged";
43 int curveCount = curvesIncluded.count();
44 int maxColumnSize = maxColumnSizeAllocation (modelExportOverride,
50 if (maxColumnSize > 0) {
52 QVector<QVector<QString*> > xThetaYRadiusValues (COLUMNS_PER_CURVE * curveCount, QVector<QString*> (maxColumnSize));
53 initializeXThetaYRadiusValues (curvesIncluded,
55 loadXThetaYRadiusValues (modelExportOverride,
61 outputXThetaYRadiusValues (modelExportOverride,
66 destroy2DArray (xThetaYRadiusValues);
73 const QStringList &curvesIncluded,
74 const QString &delimiter,
76 QTextStream &str)
const
78 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportOnePerLineXThetaValuesMerged";
80 QStringList::const_iterator itr;
81 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
83 QString curveIncluded = *itr;
85 exportAllPerLineXThetaValuesMerged (modelExportOverride,
88 QStringList (curveIncluded),
99 QTextStream &str)
const
101 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportToFile";
104 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
107 CONNECT_AS_RELATION_SMOOTH,
108 CONNECT_AS_RELATION_STRAIGHT);
111 const QString delimiter = exportDelimiterToText (modelExportOverride.
delimiter());
114 if (modelExportOverride.
layoutFunctions() == EXPORT_LAYOUT_ALL_PER_LINE) {
115 exportAllPerLineXThetaValuesMerged (modelExportOverride,
123 exportOnePerLineXThetaValuesMerged (modelExportOverride,
133 void ExportFileRelations::initializeXThetaYRadiusValues (
const QStringList &curvesIncluded,
134 QVector<QVector<QString*> > &xThetaYRadiusValues)
const
136 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::initializeXThetaYRadiusValues";
139 int curveCount = curvesIncluded.count();
140 int xThetaCount = xThetaYRadiusValues [0].count();
141 for (
int row = 0; row < xThetaCount; row++) {
142 for (
int col = 0; col < COLUMNS_PER_CURVE * curveCount; col++) {
143 xThetaYRadiusValues [col] [row] =
new QString;
148 QPointF ExportFileRelations::linearlyInterpolate (
const Points &points,
152 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::linearlyInterpolate";
154 double xTheta = 0, yRadius = 0;
155 double ordinalBefore = 0;
156 QPointF posGraphBefore;
157 bool foundIt =
false;
158 for (
int ip = 0; ip < points.count(); ip++) {
160 const Point &point = points.at (ip);
165 if (ordinal <= point.
ordinal()) {
171 xTheta = posGraph.x();
172 yRadius = posGraph.y();
178 double s = (ordinal - ordinalBefore) / (point.
ordinal() - ordinalBefore);
179 xTheta = (1.0 - s) * posGraphBefore.x() + s * posGraph.x();
180 yRadius = (1.0 - s) * posGraphBefore.y() + s * posGraph.y();
186 ordinalBefore = point.
ordinal();
187 posGraphBefore = posGraph;
193 xTheta = posGraphBefore.x();
194 yRadius = posGraphBefore.y();
198 return QPointF (xTheta,
205 const QStringList &curvesIncluded,
207 QVector<QVector<QString*> > &xThetaYRadiusValues)
const
209 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValues";
212 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
214 int colXTheta = 2 * ic;
215 int colYRadius = 2 * ic + 1;
217 const QString curveName = curvesIncluded.at (ic);
220 const Points points = curve->
points ();
225 loadXThetaYRadiusValuesForCurveRaw (document.
modelCoords(),
228 xThetaYRadiusValues [colXTheta],
229 xThetaYRadiusValues [colYRadius],
244 loadXThetaYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
248 xThetaYRadiusValues [colXTheta],
249 xThetaYRadiusValues [colYRadius],
254 loadXThetaYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
258 xThetaYRadiusValues [colXTheta],
259 xThetaYRadiusValues [colYRadius],
266 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
268 const Points &points,
269 const ExportValuesOrdinal &ordinals,
270 QVector<QString*> &xThetaValues,
271 QVector<QString*> &yRadiusValues,
274 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth";
277 vector<SplinePair> xy;
292 for (
int row = 0; row < ordinals.count(); row++) {
294 double ordinal = ordinals.at (row);
295 SplinePair splinePairFound = spline.interpolateCoeff(ordinal);
296 double xTheta = splinePairFound.
x ();
297 double yRadius = splinePairFound.
y ();
304 *(xThetaValues [row]),
305 *(yRadiusValues [row]),
310 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
312 const Points &points,
313 const ExportValuesOrdinal &ordinals,
314 QVector<QString*> &xThetaValues,
315 QVector<QString*> &yRadiusValues,
318 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight";
323 for (
int row = 0; row < ordinals.count(); row++) {
325 double ordinal = ordinals.at (row);
327 QPointF pointInterpolated = linearlyInterpolate (points,
333 pointInterpolated.y(),
336 *(xThetaValues [row]),
337 *(yRadiusValues [row]),
342 void ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
344 const Points &points,
345 QVector<QString*> &xThetaValues,
346 QVector<QString*> &yRadiusValues,
349 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw";
353 for (
int pt = 0; pt < points.count(); pt++) {
355 const Point &point = points.at (pt);
366 *(xThetaValues [pt]),
367 *(yRadiusValues [pt]),
375 const QStringList &curvesIncluded)
const
377 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::maxColumnSizeAllocation";
379 int maxColumnSize = 0;
382 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
384 const QString curveName = curvesIncluded.at (ic);
387 const Points points = curve->
points ();
392 maxColumnSize = qMax (maxColumnSize,
406 maxColumnSize = qMax (maxColumnSize,
411 return maxColumnSize;
414 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervals (
double pointsIntervalRelations,
415 ExportPointsIntervalUnits pointsIntervalUnits,
416 CurveConnectAs curveConnectAs,
418 const Points &points)
const
420 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervals";
422 if (pointsIntervalUnits == EXPORT_POINTS_INTERVAL_UNITS_GRAPH) {
423 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
425 return ordinalsAtIntervalsSmoothGraph (pointsIntervalRelations,
431 return ordinalsAtIntervalsStraightGraph (pointsIntervalRelations,
438 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
440 return ordinalsAtIntervalsSmoothScreen (pointsIntervalRelations,
445 return ordinalsAtIntervalsStraightScreen (pointsIntervalRelations,
452 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothGraph (
double pointsIntervalRelations,
454 const Points &points)
const
456 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothGraph";
458 ExportValuesOrdinal ordinals;
461 if ((pointsIntervalRelations > 0) &&
462 (points.count() > 0)) {
465 vector<SplinePair> xy;
475 pointsIntervalRelations);
481 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothScreen (
double pointsIntervalRelations,
482 const Points &points)
const
484 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothScreen"
485 <<
" pointCount=" << points.count();
488 ExportValuesOrdinal ordinals;
491 if ((pointsIntervalRelations > 0) &&
492 (points.count() > 0)) {
495 vector<SplinePair> xy;
504 pointsIntervalRelations);
510 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightGraph (
double pointsIntervalRelations,
512 const Points &points)
const
514 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightGraph";
516 ExportValuesOrdinal ordinals;
519 if ((pointsIntervalRelations > 0) &&
520 (points.count() > 0)) {
526 pointsIntervalRelations);
532 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightScreen (
double pointsIntervalRelations,
533 const Points &points)
const
535 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightScreen"
536 <<
" pointCount=" << points.count();
539 ExportValuesOrdinal ordinals;
542 if ((pointsIntervalRelations > 0) &&
543 (points.count() > 0)) {
548 pointsIntervalRelations);
555 const QStringList &curvesIncluded,
556 QVector<QVector<QString*> > &xThetaYRadiusValues,
557 const QString &delimiter,
558 QTextStream &str)
const
560 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::outputXThetaYRadiusValues";
563 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
564 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
565 str << curveSeparator(str.string());
566 str << gnuplotComment();
568 QString delimiterForRow;
569 QStringList::const_iterator itr;
570 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
571 QString curveName = *itr;
572 str << delimiterForRow << modelExportOverride.
xLabel();
573 delimiterForRow = delimiter;
574 str << delimiterForRow << curveName;
579 for (
int row = 0; row < xThetaYRadiusValues [0].count(); row++) {
581 QString delimiterForRow;
582 for (
int col = 0; col < xThetaYRadiusValues.count(); col++) {
584 str << delimiterForRow << *(xThetaYRadiusValues [col] [row]);
585 delimiterForRow = delimiter;
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.
LineStyle lineStyle() const
Get method for LineStyle.
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.
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.
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
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.
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.