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;
29 const QStringList &curvesIncluded,
30 const QString &delimiter,
32 QTextStream &str)
const
34 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportAllPerLineXThetaValuesMerged";
36 int curveCount = curvesIncluded.count();
37 int maxColumnSize = maxColumnSizeAllocation (modelExportOverride,
43 if (maxColumnSize > 0) {
45 QVector<QVector<QString*> > xThetaYRadiusValues (COLUMNS_PER_CURVE * curveCount, QVector<QString*> (maxColumnSize));
46 initializeXThetaYRadiusValues (curvesIncluded,
48 loadXThetaYRadiusValues (modelExportOverride,
53 outputXThetaYRadiusValues (modelExportOverride,
58 destroy2DArray (xThetaYRadiusValues);
64 const QStringList &curvesIncluded,
65 const QString &delimiter,
67 QTextStream &str)
const
69 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportOnePerLineXThetaValuesMerged";
71 QStringList::const_iterator itr;
72 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
74 QString curveIncluded = *itr;
76 exportAllPerLineXThetaValuesMerged (modelExportOverride,
78 QStringList (curveIncluded),
88 QTextStream &str)
const
90 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::exportToFile";
93 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
96 CONNECT_AS_RELATION_SMOOTH,
97 CONNECT_AS_RELATION_STRAIGHT);
100 const QString delimiter = exportDelimiterToText (modelExportOverride.
delimiter());
103 if (modelExportOverride.
layoutFunctions() == EXPORT_LAYOUT_ALL_PER_LINE) {
104 exportAllPerLineXThetaValuesMerged (modelExportOverride,
111 exportOnePerLineXThetaValuesMerged (modelExportOverride,
120 void ExportFileRelations::initializeXThetaYRadiusValues (
const QStringList &curvesIncluded,
121 QVector<QVector<QString*> > &xThetaYRadiusValues)
const
123 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::initializeXThetaYRadiusValues";
126 int curveCount = curvesIncluded.count();
127 int xThetaCount = xThetaYRadiusValues [0].count();
128 for (
int row = 0; row < xThetaCount; row++) {
129 for (
int col = 0; col < COLUMNS_PER_CURVE * curveCount; col++) {
130 xThetaYRadiusValues [col] [row] =
new QString;
135 QPointF ExportFileRelations::linearlyInterpolate (
const Points &points,
139 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::linearlyInterpolate";
141 double xTheta = 0, yRadius = 0;
142 double ordinalBefore = 0;
143 QPointF posGraphBefore;
144 bool foundIt =
false;
145 for (
int ip = 0; ip < points.count(); ip++) {
147 const Point &point = points.at (ip);
152 if (ordinal <= point.
ordinal()) {
158 xTheta = posGraph.x();
159 yRadius = posGraph.y();
165 double s = (ordinal - ordinalBefore) / (point.
ordinal() - ordinalBefore);
166 xTheta = (1.0 - s) * posGraphBefore.x() + s * posGraph.x();
167 yRadius = (1.0 - s) * posGraphBefore.y() + s * posGraph.y();
173 ordinalBefore = point.
ordinal();
174 posGraphBefore = posGraph;
180 xTheta = posGraphBefore.x();
181 yRadius = posGraphBefore.y();
185 return QPointF (xTheta,
191 const QStringList &curvesIncluded,
193 QVector<QVector<QString*> > &xThetaYRadiusValues)
const
195 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValues";
198 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
200 int colXTheta = 2 * ic;
201 int colYRadius = 2 * ic + 1;
203 const QString curveName = curvesIncluded.at (ic);
206 const Points points = curve->
points ();
211 loadXThetaYRadiusValuesForCurveRaw (document.
modelCoords(),
213 xThetaYRadiusValues [colXTheta],
214 xThetaYRadiusValues [colYRadius],
229 loadXThetaYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
232 xThetaYRadiusValues [colXTheta],
233 xThetaYRadiusValues [colYRadius],
238 loadXThetaYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
241 xThetaYRadiusValues [colXTheta],
242 xThetaYRadiusValues [colYRadius],
249 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
250 const Points &points,
251 const ExportValuesOrdinal &ordinals,
252 QVector<QString*> &xThetaValues,
253 QVector<QString*> &yRadiusValues,
256 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedSmooth";
259 vector<SplinePair> xy;
274 for (
int row = 0; row < ordinals.count(); row++) {
276 double ordinal = ordinals.at (row);
277 SplinePair splinePairFound = spline.interpolateCoeff(ordinal);
278 double xTheta = splinePairFound.
x ();
279 double yRadius = splinePairFound.
y ();
285 *(xThetaValues [row]),
286 *(yRadiusValues [row]),
291 void ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
292 const Points &points,
293 const ExportValuesOrdinal &ordinals,
294 QVector<QString*> &xThetaValues,
295 QVector<QString*> &yRadiusValues,
298 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveInterpolatedStraight";
303 for (
int row = 0; row < ordinals.count(); row++) {
305 double ordinal = ordinals.at (row);
307 QPointF pointInterpolated = linearlyInterpolate (points,
313 pointInterpolated.y(),
315 *(xThetaValues [row]),
316 *(yRadiusValues [row]),
321 void ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
322 const Points &points,
323 QVector<QString*> &xThetaValues,
324 QVector<QString*> &yRadiusValues,
327 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::loadXThetaYRadiusValuesForCurveRaw";
331 for (
int pt = 0; pt < points.count(); pt++) {
333 const Point &point = points.at (pt);
343 *(xThetaValues [pt]),
344 *(yRadiusValues [pt]),
352 const QStringList &curvesIncluded)
const
354 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::maxColumnSizeAllocation";
356 int maxColumnSize = 0;
359 for (
int ic = 0; ic < curvesIncluded.count(); ic++) {
361 const QString curveName = curvesIncluded.at (ic);
364 const Points points = curve->
points ();
369 maxColumnSize = qMax (maxColumnSize,
383 maxColumnSize = qMax (maxColumnSize,
388 return maxColumnSize;
391 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervals (
double pointsIntervalRelations,
392 ExportPointsIntervalUnits pointsIntervalUnits,
393 CurveConnectAs curveConnectAs,
395 const Points &points)
const
397 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervals";
399 if (pointsIntervalUnits == EXPORT_POINTS_INTERVAL_UNITS_GRAPH) {
400 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
402 return ordinalsAtIntervalsSmoothGraph (pointsIntervalRelations,
408 return ordinalsAtIntervalsStraightGraph (pointsIntervalRelations,
415 if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH) {
417 return ordinalsAtIntervalsSmoothScreen (pointsIntervalRelations,
422 return ordinalsAtIntervalsStraightScreen (pointsIntervalRelations,
429 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothGraph (
double pointsIntervalRelations,
431 const Points &points)
const
433 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothGraph";
435 ExportValuesOrdinal ordinals;
438 if ((pointsIntervalRelations > 0) &&
439 (points.count() > 0)) {
442 vector<SplinePair> xy;
452 pointsIntervalRelations);
458 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsSmoothScreen (
double pointsIntervalRelations,
459 const Points &points)
const
461 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsSmoothScreen"
462 <<
" pointCount=" << points.count();
465 ExportValuesOrdinal ordinals;
468 if ((pointsIntervalRelations > 0) &&
469 (points.count() > 0)) {
472 vector<SplinePair> xy;
481 pointsIntervalRelations);
487 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightGraph (
double pointsIntervalRelations,
489 const Points &points)
const
491 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightGraph";
493 ExportValuesOrdinal ordinals;
496 if ((pointsIntervalRelations > 0) &&
497 (points.count() > 0)) {
503 pointsIntervalRelations);
509 ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightScreen (
double pointsIntervalRelations,
510 const Points &points)
const
512 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::ordinalsAtIntervalsStraightScreen"
513 <<
" pointCount=" << points.count();
516 ExportValuesOrdinal ordinals;
519 if ((pointsIntervalRelations > 0) &&
520 (points.count() > 0)) {
525 pointsIntervalRelations);
532 const QStringList &curvesIncluded,
533 QVector<QVector<QString*> > &xThetaYRadiusValues,
534 const QString &delimiter,
535 QTextStream &str)
const
537 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileRelations::outputXThetaYRadiusValues";
540 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
541 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
542 str << curveSeparator(str.string());
543 str << gnuplotComment();
545 QString delimiterForRow;
546 QStringList::const_iterator itr;
547 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
548 QString curveName = *itr;
549 str << delimiterForRow << modelExportOverride.
xLabel();
550 delimiterForRow = delimiter;
551 str << delimiterForRow << curveName;
556 for (
int row = 0; row < xThetaYRadiusValues [0].count(); row++) {
558 QString delimiterForRow;
559 for (
int col = 0; col < xThetaYRadiusValues.count(); col++) {
561 str << delimiterForRow << *(xThetaYRadiusValues [col] [row]);
562 delimiterForRow = delimiter;
Cubic interpolation given independent and dependent value vectors.
void exportToFile(const DocumentModelExportFormat &modelExportOverride, const Document &document, const Transformation &transformation, QTextStream &str) const
Export Document points according to the settings.
const Points points() const
Return a shallow copy of the Points.
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...
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.