7 #include "CallbackGatherXThetaValuesFunctions.h" 8 #include "CurveConnectAs.h" 10 #include "EngaugeAssert.h" 11 #include "ExportFileFunctions.h" 12 #include "ExportLayoutFunctions.h" 13 #include "ExportOrdinalsSmooth.h" 14 #include "ExportXThetaValuesMergedFunctions.h" 15 #include "FormatCoordsUnits.h" 17 #include <QTextStream> 20 #include "SplinePair.h" 21 #include "Transformation.h" 33 const QStringList &curvesIncluded,
34 const ExportValuesXOrY &xThetaValues,
35 const QString &delimiter,
37 QTextStream &str)
const 39 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportAllPerLineXThetaValuesMerged";
41 int curveCount = curvesIncluded.count();
42 int xThetaCount = xThetaValues.count();
43 QVector<QVector<QString*> > yRadiusValues (curveCount, QVector<QString*> (xThetaCount));
44 initializeYRadiusValues (curvesIncluded,
47 loadYRadiusValues (modelExportOverride,
55 outputXThetaYRadiusValues (modelExportOverride,
64 destroy2DArray (yRadiusValues);
70 const QStringList &curvesIncluded,
71 const ExportValuesXOrY &xThetaValues,
72 const QString &delimiter,
74 QTextStream &str)
const 76 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportOnePerLineXThetaValuesMerged";
80 QStringList::const_iterator itr;
81 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
83 insertLineSeparator (isFirst,
84 modelExportOverride.
header(),
88 const int CURVE_COUNT = 1;
89 QString curveIncluded = *itr;
90 QStringList curvesIncluded (curveIncluded);
92 int xThetaCount = xThetaValues.count();
93 QVector<QVector<QString*> > yRadiusValues (CURVE_COUNT, QVector<QString*> (xThetaCount));
94 initializeYRadiusValues (curvesIncluded,
97 loadYRadiusValues (modelExportOverride,
104 outputXThetaYRadiusValues (modelExportOverride,
113 destroy2DArray (yRadiusValues);
121 QTextStream &str)
const 123 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::exportToFile";
126 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
129 CONNECT_AS_FUNCTION_SMOOTH,
130 CONNECT_AS_FUNCTION_STRAIGHT);
133 const QString delimiter = exportDelimiterToText (modelExportOverride.
delimiter(),
134 modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT);
140 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
145 ftor.xThetaValuesRaw(),
147 ExportValuesXOrY xThetaValuesMerged = exportXTheta.
xThetaValues ();
150 if (xThetaValuesMerged.count() > 0) {
153 if (modelExportOverride.
layoutFunctions() == EXPORT_LAYOUT_ALL_PER_LINE) {
154 exportAllPerLineXThetaValuesMerged (modelExportOverride,
163 exportOnePerLineXThetaValuesMerged (modelExportOverride,
175 void ExportFileFunctions::initializeYRadiusValues (
const QStringList &curvesIncluded,
176 const ExportValuesXOrY &xThetaValuesMerged,
177 QVector<QVector<QString*> > &yRadiusValues)
const 179 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::initializeYRadiusValues";
182 int curveCount = curvesIncluded.count();
183 int xThetaCount = xThetaValuesMerged.count();
184 for (
int row = 0; row < xThetaCount; row++) {
185 for (
int col = 0; col < curveCount; col++) {
186 yRadiusValues [col] [row] =
new QString;
191 double ExportFileFunctions::linearlyInterpolate (
const Points &points,
200 QPointF posGraphBefore;
201 bool foundIt =
false;
202 for (
int ip = 0; !foundIt && (ip < points.count()); ip++) {
204 const Point &point = points.at (ip);
213 if (xThetaValue <= posGraph.x() && (ip > 0)) {
220 double s = (xThetaValue - posGraphBefore.x()) / (posGraph.x() - posGraphBefore.x());
221 yRadius = (1.0 -s) * posGraphBefore.y() + s * posGraph.y();
226 posGraphBefore = posGraph;
231 if (points.count() > 1) {
235 int N = points.count();
236 const Point &pointLast = points.at (N - 1);
237 const Point &pointBefore = points.at (N - 2);
238 QPointF posGraphLast;
243 double s = (xThetaValue - posGraphBefore.x()) / (posGraphLast.x() - posGraphBefore.x());
244 yRadius = (1.0 - s) * posGraphBefore.y() + s * posGraphLast.y();
246 }
else if (points.count() == 1) {
249 yRadius = posGraphBefore.y();
253 ENGAUGE_ASSERT (
false);
264 const QStringList &curvesIncluded,
266 const ExportValuesXOrY &xThetaValues,
267 QVector<QVector<QString*> > &yRadiusValues)
const 269 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValues";
272 int curveCount = curvesIncluded.count();
273 for (
int col = 0; col < curveCount; col++) {
275 const QString curveName = curvesIncluded.at (col);
278 const Points points = curve->
points ();
283 loadYRadiusValuesForCurveRaw (document.
modelCoords(),
288 yRadiusValues [col]);
294 loadYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
299 yRadiusValues [col]);
303 loadYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
308 yRadiusValues [col]);
314 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
316 const Points &points,
317 const ExportValuesXOrY &xThetaValues,
319 QVector<QString*> &yRadiusValues)
const 321 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth";
325 vector<SplinePair> xy;
335 QString dummyXThetaOut;
337 if (points.count() == 0) {
340 for (
int row = 0; row < xThetaValues.count(); row++) {
341 *(yRadiusValues [row]) =
"";
344 }
else if (points.count() == 1 ||
345 points.count() == 2) {
348 for (
int row = 0; row < xThetaValues.count(); row++) {
350 double xTheta = xThetaValues.at (row);
352 if (points.count() == 1) {
353 yRadius = xy.at (0).y ();
355 double x0 = xy.at (0).x ();
356 double x1 = xy.at (1).x ();
357 double y0 = xy.at (0).y ();
358 double y1 = xy.at (1).y ();
361 yRadius = xy.at (0).y ();
363 double s = (xTheta - x0) / (x1 - x0);
364 yRadius = (1.0 - s) * y0 + s * y1;
372 *(yRadiusValues [row]),
382 const int MAX_ITERATIONS = 32;
392 for (
int row = 0; row < xThetaValues.count(); row++) {
394 double xTheta = xThetaValues.at (row);
397 double yRadius = splinePairFound.
y ();
400 QString dummyXThetaOut;
406 *(yRadiusValues [row]),
413 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
415 const Points &points,
416 const ExportValuesXOrY &xThetaValues,
418 QVector<QString*> &yRadiusValues)
const 420 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight";
425 for (
int row = 0; row < xThetaValues.count(); row++) {
427 double xThetaValue = xThetaValues.at (row);
429 double yRadius = linearlyInterpolate (points,
434 QString dummyXThetaOut;
440 *(yRadiusValues [row]),
445 void ExportFileFunctions::loadYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
447 const Points &points,
448 const ExportValuesXOrY &xThetaValues,
450 QVector<QString*> &yRadiusValues)
const 452 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::loadYRadiusValuesForCurveRaw";
458 for (
int pt = 0; pt < points.count(); pt++) {
460 const Point &point = points.at (pt);
468 double closestSeparation = 0.0;
470 for (
int row = 0; row < xThetaValues.count(); row++) {
472 double xThetaValue = xThetaValues.at (row);
474 double separation = qAbs (posGraph.x() - xThetaValue);
477 (separation < closestSeparation)) {
479 closestSeparation = separation;
486 QString dummyXThetaOut;
492 *(yRadiusValues [rowClosest]),
500 const QStringList &curvesIncluded,
501 const ExportValuesXOrY &xThetaValuesMerged,
503 QVector<QVector<QString*> > &yRadiusValues,
504 const QString &delimiter,
505 QTextStream &str)
const 507 LOG4CPP_INFO_S ((*mainCat)) <<
"ExportFileFunctions::outputXThetaYRadiusValues";
510 if (modelExportOverride.
header() != EXPORT_HEADER_NONE) {
511 if (modelExportOverride.
header() == EXPORT_HEADER_GNUPLOT) {
512 str << curveSeparator (str.string());
513 str << gnuplotComment();
515 str << modelExportOverride.
xLabel();
516 QStringList::const_iterator itrHeader;
517 for (itrHeader = curvesIncluded.begin(); itrHeader != curvesIncluded.end(); itrHeader++) {
518 QString curveName = *itrHeader;
519 str << delimiter << curveName;
525 const double DUMMY_Y_RADIUS = 1.0;
527 for (
int row = 0; row < xThetaValuesMerged.count(); row++) {
529 if (rowHasAtLeastOneYRadiusEntry (yRadiusValues,
532 double xTheta = xThetaValuesMerged.at (row);
535 QString xThetaString, yRadiusString;
545 for (
int col = 0; col < yRadiusValues.count(); col++) {
547 str << delimiter << *(yRadiusValues [col] [row]);
555 bool ExportFileFunctions::rowHasAtLeastOneYRadiusEntry (
const QVector<QVector<QString*> > &yRadiusValues,
558 bool hasEntry =
false;
560 for (
int col = 0; col < yRadiusValues.count(); col++) {
562 QString entry = *(yRadiusValues [col] [row]);
563 if (!entry.isEmpty()) {
Creates the set of merged x/theta values for exporting functions, using interpolation.
Cubic interpolation given independent and dependent value vectors.
const Points points() const
Return a shallow copy of the Points.
ExportValuesXOrY xThetaValues() const
Resulting x/theta values for all included functions.
LineStyle lineStyle() const
Get method for LineStyle.
ExportFileFunctions()
Single constructor.
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.
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
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.
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.
SplinePair findSplinePairForFunctionX(double x, int numIterations) const
Use bisection algorithm to iteratively find the SplinePair interpolated to best match the specified x...
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
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.
void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
CurveConnectAs curveConnectAs() const
Get method for connect type.
Callback for collecting X/Theta independent variables, for functions, in preparation for exporting...
Single X/Y pair for cubic spline interpolation initialization and calculations.
void exportToFile(const DocumentModelExportFormat &modelExportOverride, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, QTextStream &str) const
Export Document points according to the settings.