1 #include "CurveConnectAs.h"
3 #include "EngaugeAssert.h"
4 #include "ExportFileRelations.h"
5 #include "ExportLayoutFunctions.h"
6 #include "ExportOrdinalsSmooth.h"
7 #include "ExportOrdinalsStraight.h"
8 #include "FormatCoordsUnits.h"
12 #include <QTextStream>
15 #include "SplinePair.h"
16 #include "Transformation.h"
21 const int COLUMNS_PER_CURVE = 2;
30 const QStringList &curvesIncluded,
31 const QString &delimiter,
33 QTextStream &str)
const
35 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportAllPerLineXThetaValuesMerged";
37 int curveCount = curvesIncluded.count();
38 int maxColumnSize = maxColumnSizeAllocation (modelExportOverride,
44 if (maxColumnSize > 0) {
46 QVector<QVector<QString*> > xThetaYRadiusValues (COLUMNS_PER_CURVE * curveCount, QVector<QString*> (maxColumnSize));
47 initializeXThetaYRadiusValues (curvesIncluded,
49 loadXThetaYRadiusValues (modelExportOverride,
55 outputXThetaYRadiusValues (modelExportOverride,
60 destroy2DArray (xThetaYRadiusValues);
67 const QStringList &curvesIncluded,
68 const QString &delimiter,
70 QTextStream &str)
const
72 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportOnePerLineXThetaValuesMerged";
74 QStringList::const_iterator itr;
75 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
77 QString curveIncluded = *itr;
79 exportAllPerLineXThetaValuesMerged (modelExportOverride,
82 QStringList (curveIncluded),
93 QTextStream &str)
const
95 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportToFile";
98 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
101 CONNECT_AS_RELATION_SMOOTH,
102 CONNECT_AS_RELATION_STRAIGHT);
105 const QString delimiter = exportDelimiterToText (modelExportOverride.
delimiter());
108 if (modelExportOverride.
layoutFunctions() == EXPORT_LAYOUT_ALL_PER_LINE) {
109 exportAllPerLineXThetaValuesMerged (modelExportOverride,
117 exportOnePerLineXThetaValuesMerged (modelExportOverride,
127 void ExportFileRelations::initializeXThetaYRadiusValues (
const QStringList &curvesIncluded,
128 QVector<QVector<QString*> > &xThetaYRadiusValues)
const
130 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::initializeXThetaYRadiusValues";
133 int curveCount = curvesIncluded.count();
134 int xThetaCount = xThetaYRadiusValues [0].count();
135 for (
int row = 0; row < xThetaCount; row++) {
136 for (
int col = 0; col < COLUMNS_PER_CURVE * curveCount; col++) {
137 xThetaYRadiusValues [col] [row] =
new QString;
142 QPointF ExportFileRelations::linearlyInterpolate (
const Points &points,
146 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::linearlyInterpolate";
148 double xTheta = 0, yRadius = 0;
149 double ordinalBefore = 0;
150 QPointF posGraphBefore;
151 bool foundIt =
false;
152 for (
int ip = 0; ip < points.count(); ip++) {
154 const Point &point = points.at (ip);
159 if (ordinal <= point.
ordinal()) {
165 xTheta = posGraph.x();
166 yRadius = posGraph.y();
172 double s = (ordinal - ordinalBefore) / (point.
ordinal() - ordinalBefore);
173 xTheta = (1.0 - s) * posGraphBefore.x() + s * posGraph.x();
174 yRadius = (1.0 - s) * posGraphBefore.y() + s * posGraph.y();
180 ordinalBefore = point.
ordinal();
181 posGraphBefore = posGraph;
187 xTheta = posGraphBefore.x();
188 yRadius = posGraphBefore.y();
192 return QPointF (xTheta,
199 const QStringList &curvesIncluded,
201 QVector<QVector<QString*> > &xThetaYRadiusValues)
const
203 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValues";
206 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
208 int colXTheta = 2 * ic;
209 int colYRadius = 2 * ic + 1;
211 const QString curveName = curvesIncluded.at (ic);
214 const Points points = curve->
points ();
219 loadXThetaYRadiusValuesForCurveRaw (document.
modelCoords(),
222 xThetaYRadiusValues [colXTheta],
223 xThetaYRadiusValues [colYRadius],
238 loadXThetaYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
242 xThetaYRadiusValues [colXTheta],
243 xThetaYRadiusValues [colYRadius],
248 loadXThetaYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
252 xThetaYRadiusValues [colXTheta],
253 xThetaYRadiusValues [colYRadius],
260 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
262 const Points &points,
263 const ExportValuesOrdinal &ordinals,
264 QVector<QString*> &xThetaValues,
265 QVector<QString*> &yRadiusValues,
268 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth";
271 vector<SplinePair> xy;
286 for (
int row = 0; row < ordinals.count(); row++) {
288 double ordinal = ordinals.at (row);
289 SplinePair splinePairFound = spline.interpolateCoeff(ordinal);
290 double xTheta = splinePairFound.
x ();
291 double yRadius = splinePairFound.
y ();
298 *(xThetaValues [row]),
299 *(yRadiusValues [row]),
304 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
306 const Points &points,
307 const ExportValuesOrdinal &ordinals,
308 QVector<QString*> &xThetaValues,
309 QVector<QString*> &yRadiusValues,
312 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight";
317 for (
int row = 0; row < ordinals.count(); row++) {
319 double ordinal = ordinals.at (row);
321 QPointF pointInterpolated = linearlyInterpolate (points,
327 pointInterpolated.y(),
330 *(xThetaValues [row]),
331 *(yRadiusValues [row]),
336 void ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
338 const Points &points,
339 QVector<QString*> &xThetaValues,
340 QVector<QString*> &yRadiusValues,
343 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw";
347 for (
int pt = 0; pt < points.count(); pt++) {
349 const Point &point = points.at (pt);
360 *(xThetaValues [pt]),
361 *(yRadiusValues [pt]),
369 const QStringList &curvesIncluded)
const
371 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::maxColumnSizeAllocation";
373 int maxColumnSize = 0;
376 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
378 const QString curveName = curvesIncluded.at (ic);
381 const Points points = curve->
points ();
386 maxColumnSize = qMax (maxColumnSize,
400 maxColumnSize = qMax (maxColumnSize,
405 return maxColumnSize;
408 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervals (
double pointsIntervalRelations,
409 ExportPointsIntervalUnits pointsIntervalUnits,
410 CurveConnectAs curveConnectAs,
412 const Points &points)
const
414 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervals";
416 if (pointsIntervalUnits == EXPORT_POINTS_INTERVAL_UNITS_GRAPH) {
417 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
419 return ordinalsAtIntervalsSmoothGraph (pointsIntervalRelations,
425 return ordinalsAtIntervalsStraightGraph (pointsIntervalRelations,
432 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
434 return ordinalsAtIntervalsSmoothScreen (pointsIntervalRelations,
439 return ordinalsAtIntervalsStraightScreen (pointsIntervalRelations,
446 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothGraph (
double pointsIntervalRelations,
448 const Points &points)
const
450 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothGraph";
452 ExportValuesOrdinal ordinals;
455 if ((pointsIntervalRelations > 0) &&
456 (points.count() > 0)) {
459 vector<SplinePair> xy;
469 pointsIntervalRelations);
475 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothScreen (
double pointsIntervalRelations,
476 const Points &points)
const
478 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothScreen"
479 <<
" pointCount=" << points.count();
482 ExportValuesOrdinal ordinals;
485 if ((pointsIntervalRelations > 0) &&
486 (points.count() > 0)) {
489 vector<SplinePair> xy;
498 pointsIntervalRelations);
504 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightGraph (
double pointsIntervalRelations,
506 const Points &points)
const
508 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightGraph";
510 ExportValuesOrdinal ordinals;
513 if ((pointsIntervalRelations > 0) &&
514 (points.count() > 0)) {
520 pointsIntervalRelations);
526 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightScreen (
double pointsIntervalRelations,
527 const Points &points)
const
529 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightScreen"
530 <<
" pointCount=" << points.count();
533 ExportValuesOrdinal ordinals;
536 if ((pointsIntervalRelations > 0) &&
537 (points.count() > 0)) {
542 pointsIntervalRelations);
549 const QStringList &curvesIncluded,
550 QVector<QVector<QString*> > &xThetaYRadiusValues,
551 const QString &delimiter,
552 QTextStream &str)
const
554 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::outputXThetaYRadiusValues";
557 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
558 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
559 str << curveSeparator(str.string());
560 str << gnuplotComment();
562 QString delimiterForRow;
563 QStringList::const_iterator itr;
564 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
565 QString curveName = *itr;
566 str << delimiterForRow << modelExportOverride.
xLabel();
567 delimiterForRow = delimiter;
568 str << delimiterForRow << curveName;
573 for (
int row = 0; row < xThetaYRadiusValues [0].count(); row++) {
575 QString delimiterForRow;
576 for (
int col = 0; col < xThetaYRadiusValues.count(); col++) {
578 str << delimiterForRow << *(xThetaYRadiusValues [col] [row]);
579 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 and CmdSettingsMainWindow.
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.