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,
40 QTextStream &str)
const
42 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportAllPerLineXThetaValuesMerged";
44 int curveCount = curvesIncluded.count();
45 int maxColumnSize = maxColumnSizeAllocation (modelExportOverride,
51 if (maxColumnSize > 0) {
53 QVector<QVector<QString*> > xThetaYRadiusValues (COLUMNS_PER_CURVE * curveCount, QVector<QString*> (maxColumnSize));
54 initializeXThetaYRadiusValues (curvesIncluded,
56 loadXThetaYRadiusValues (modelExportOverride,
62 outputXThetaYRadiusValues (modelExportOverride,
67 destroy2DArray (xThetaYRadiusValues);
74 const QStringList &curvesIncluded,
75 const QString &delimiter,
77 QTextStream &str)
const
79 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportOnePerLineXThetaValuesMerged";
81 QStringList::const_iterator itr;
82 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
84 QString curveIncluded = *itr;
86 exportAllPerLineXThetaValuesMerged (modelExportOverride,
89 QStringList (curveIncluded),
100 QTextStream &str)
const
102 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportToFile";
105 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
108 CONNECT_AS_RELATION_SMOOTH,
109 CONNECT_AS_RELATION_STRAIGHT);
112 const QString delimiter = exportDelimiterToText (modelExportOverride.
delimiter(),
113 modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT);
116 if (modelExportOverride.
layoutFunctions() == EXPORT_LAYOUT_ALL_PER_LINE) {
117 exportAllPerLineXThetaValuesMerged (modelExportOverride,
125 exportOnePerLineXThetaValuesMerged (modelExportOverride,
135 void ExportFileRelations::initializeXThetaYRadiusValues (
const QStringList &curvesIncluded,
136 QVector<QVector<QString*> > &xThetaYRadiusValues)
const
138 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::initializeXThetaYRadiusValues";
141 int curveCount = curvesIncluded.count();
142 int xThetaCount = xThetaYRadiusValues [0].count();
143 for (
int row = 0; row < xThetaCount; row++) {
144 for (
int col = 0; col < COLUMNS_PER_CURVE * curveCount; col++) {
145 xThetaYRadiusValues [col] [row] =
new QString;
150 QPointF ExportFileRelations::linearlyInterpolate (
const Points &points,
156 double xTheta = 0, yRadius = 0;
157 double ordinalBefore = 0;
158 QPointF posGraphBefore;
159 bool foundIt =
false;
160 for (
int ip = 0; ip < points.count(); ip++) {
162 const Point &point = points.at (ip);
167 if (ordinal <= point.
ordinal()) {
173 xTheta = posGraph.x();
174 yRadius = posGraph.y();
180 double s = (ordinal - ordinalBefore) / (point.
ordinal() - ordinalBefore);
181 xTheta = (1.0 - s) * posGraphBefore.x() + s * posGraph.x();
182 yRadius = (1.0 - s) * posGraphBefore.y() + s * posGraph.y();
188 ordinalBefore = point.
ordinal();
189 posGraphBefore = posGraph;
195 xTheta = posGraphBefore.x();
196 yRadius = posGraphBefore.y();
200 return QPointF (xTheta,
207 const QStringList &curvesIncluded,
209 QVector<QVector<QString*> > &xThetaYRadiusValues)
const
211 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValues";
214 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
216 int colXTheta = 2 * ic;
217 int colYRadius = 2 * ic + 1;
219 const QString curveName = curvesIncluded.at (ic);
222 const Points points = curve->
points ();
227 loadXThetaYRadiusValuesForCurveRaw (document.
modelCoords(),
231 xThetaYRadiusValues [colXTheta],
232 xThetaYRadiusValues [colYRadius],
247 loadXThetaYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
252 xThetaYRadiusValues [colXTheta],
253 xThetaYRadiusValues [colYRadius],
258 loadXThetaYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
263 xThetaYRadiusValues [colXTheta],
264 xThetaYRadiusValues [colYRadius],
271 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
274 const Points &points,
275 const ExportValuesOrdinal &ordinals,
276 QVector<QString*> &xThetaValues,
277 QVector<QString*> &yRadiusValues,
280 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth";
283 vector<SplinePair> xy;
301 for (
int row = 0; row < ordinals.count(); row++) {
303 double ordinal = ordinals.at (row);
304 SplinePair splinePairFound = spline.interpolateCoeff(ordinal);
305 double xTheta = splinePairFound.
x ();
306 double yRadius = splinePairFound.
y ();
314 *(xThetaValues [row]),
315 *(yRadiusValues [row]),
321 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
324 const Points &points,
325 const ExportValuesOrdinal &ordinals,
326 QVector<QString*> &xThetaValues,
327 QVector<QString*> &yRadiusValues,
330 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight";
335 for (
int row = 0; row < ordinals.count(); row++) {
337 double ordinal = ordinals.at (row);
339 QPointF pointInterpolated = linearlyInterpolate (points,
345 pointInterpolated.y(),
349 *(xThetaValues [row]),
350 *(yRadiusValues [row]),
355 void ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
358 const Points &points,
359 QVector<QString*> &xThetaValues,
360 QVector<QString*> &yRadiusValues,
363 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw";
367 for (
int pt = 0; pt < points.count(); pt++) {
369 const Point &point = points.at (pt);
381 *(xThetaValues [pt]),
382 *(yRadiusValues [pt]),
390 const QStringList &curvesIncluded)
const
392 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::maxColumnSizeAllocation";
394 int maxColumnSize = 0;
397 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
399 const QString curveName = curvesIncluded.at (ic);
402 const Points points = curve->
points ();
407 maxColumnSize = qMax (maxColumnSize,
421 maxColumnSize = qMax (maxColumnSize,
426 return maxColumnSize;
429 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervals (
double pointsIntervalRelations,
430 ExportPointsIntervalUnits pointsIntervalUnits,
431 CurveConnectAs curveConnectAs,
433 const Points &points)
const
435 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervals";
437 if (pointsIntervalUnits == EXPORT_POINTS_INTERVAL_UNITS_GRAPH) {
438 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
440 return ordinalsAtIntervalsSmoothGraph (pointsIntervalRelations,
446 return ordinalsAtIntervalsStraightGraph (pointsIntervalRelations,
453 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
455 return ordinalsAtIntervalsSmoothScreen (pointsIntervalRelations,
460 return ordinalsAtIntervalsStraightScreen (pointsIntervalRelations,
467 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothGraph (
double pointsIntervalRelations,
469 const Points &points)
const
471 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothGraph";
473 ExportValuesOrdinal ordinals;
476 if ((pointsIntervalRelations > 0) &&
477 (points.count() > 0)) {
480 vector<SplinePair> xy;
490 pointsIntervalRelations);
496 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothScreen (
double pointsIntervalRelations,
497 const Points &points)
const
499 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothScreen"
500 <<
" pointCount=" << points.count();
503 ExportValuesOrdinal ordinals;
506 if ((pointsIntervalRelations > 0) &&
507 (points.count() > 0)) {
510 vector<SplinePair> xy;
519 pointsIntervalRelations);
525 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightGraph (
double pointsIntervalRelations,
527 const Points &points)
const
529 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightGraph";
531 ExportValuesOrdinal ordinals;
534 if ((pointsIntervalRelations > 0) &&
535 (points.count() > 0)) {
541 pointsIntervalRelations);
547 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightScreen (
double pointsIntervalRelations,
548 const Points &points)
const
550 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightScreen"
551 <<
" pointCount=" << points.count();
554 ExportValuesOrdinal ordinals;
557 if ((pointsIntervalRelations > 0) &&
558 (points.count() > 0)) {
563 pointsIntervalRelations);
570 const QStringList &curvesIncluded,
571 QVector<QVector<QString*> > &xThetaYRadiusValues,
572 const QString &delimiter,
573 QTextStream &str)
const
575 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::outputXThetaYRadiusValues";
578 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
579 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
580 str << curveSeparator(str.string());
581 str << gnuplotComment();
583 QString delimiterForRow;
584 QStringList::const_iterator itr;
585 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
586 QString curveName = *itr;
587 str << delimiterForRow << modelExportOverride.
xLabel();
588 delimiterForRow = delimiter;
589 str << delimiterForRow << curveName;
594 for (
int row = 0; row < xThetaYRadiusValues [0].count(); row++) {
596 QString delimiterForRow;
597 for (
int col = 0; col < xThetaYRadiusValues.count(); col++) {
599 str << delimiterForRow << *(xThetaYRadiusValues [col] [row]);
600 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.
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.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.