22 #include <QTextStream>
38 const QStringList &curvesIncluded,
40 const QString &delimiter,
47 unsigned int &numWritesSoFar)
const
51 int curveCount = curvesIncluded.count();
52 int xThetaCount = xThetaValues.count();
53 QVector<QVector<QString*> > yRadiusValues (curveCount, QVector<QString*> (xThetaCount));
54 initializeYRadiusValues (curvesIncluded,
57 loadYRadiusValues (modelExportOverride,
69 outputXThetaYRadiusValues (modelExportOverride,
80 destroy2DArray (yRadiusValues);
86 const QStringList &curvesIncluded,
88 const QString &delimiter,
95 unsigned int &numWritesSoFar)
const
99 QStringList::const_iterator itr;
100 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
103 const int CURVE_COUNT = 1;
104 QString curveIncluded = *itr;
105 QStringList curvesIncludedIter (curveIncluded);
107 int xThetaCount = xThetaValues.count();
108 QVector<QVector<QString*> > yRadiusValues (CURVE_COUNT, QVector<QString*> (xThetaCount));
109 initializeYRadiusValues (curvesIncludedIter,
112 loadYRadiusValues (modelExportOverride,
123 outputXThetaYRadiusValues (modelExportOverride,
134 destroy2DArray (yRadiusValues);
143 unsigned int &numWritesSoFar)
const
152 QStringList curvesIncluded = curvesToInclude (modelExportOverride,
171 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
181 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
196 if (xThetaValuesMerged.count() > 0) {
200 exportAllPerLineXThetaValuesMerged (modelExportOverride,
214 exportOnePerLineXThetaValuesMerged (modelExportOverride,
231 void ExportFileFunctions::initializeYRadiusValues (
const QStringList &curvesIncluded,
233 QVector<QVector<QString*> > &yRadiusValues)
const
238 int curveCount = curvesIncluded.count();
239 int xThetaCount = xThetaValuesMerged.count();
240 for (
int row = 0; row < xThetaCount; row++) {
241 for (
int col = 0; col < curveCount; col++) {
242 yRadiusValues [col] [row] =
new QString;
247 double ExportFileFunctions::linearlyInterpolate (
const Points &points,
256 QPointF posGraphBefore;
257 bool foundIt =
false;
258 for (
int ip = 0; !foundIt && (ip < points.count()); ip++) {
260 const Point &point = points.at (ip);
269 if (xThetaValue <= posGraph.x() && (ip > 0)) {
276 yRadius = linearlyInterpolateYRadiusFromTwoPoints (xThetaValue,
284 posGraphBefore = posGraph;
289 if (points.count() > 1) {
293 int N = points.count();
294 const Point &pointLast = points.at (N - 1);
295 const Point &pointBefore = points.at (N - 2);
296 QPointF posGraphLast;
301 yRadius = linearlyInterpolateYRadiusFromTwoPoints (xThetaValue,
306 }
else if (points.count() == 1) {
309 yRadius = posGraphBefore.y();
324 const QStringList &curvesIncluded,
331 QVector<QVector<QString*> > &yRadiusValues)
const
336 int curveCount = curvesIncluded.count();
337 for (
int col = 0; col < curveCount; col++) {
339 const QString curveName = curvesIncluded.at (col);
347 loadYRadiusValuesForCurveRaw (document.
modelCoords(),
356 yRadiusValues [col]);
362 loadYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
373 yRadiusValues [col]);
377 loadYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
386 yRadiusValues [col]);
392 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
400 const QString &curveName,
403 QVector<QString*> &yRadiusValues)
const
409 vector<SplinePair> xy;
421 QString dummyXThetaOut;
423 if (points.count() == 0) {
426 for (
int row = 0; row < xThetaValues.count(); row++) {
427 *(yRadiusValues [row]) =
"";
430 }
else if (points.count() == 1 ||
431 points.count() == 2) {
434 for (
int row = 0; row < xThetaValues.count(); row++) {
436 double xTheta = xThetaValues.at (row);
438 if (points.count() == 1) {
439 yRadius = xy.at (0).y ();
441 double x0 = xy.at (0).x ();
442 double x1 = xy.at (1).x ();
443 double y0 = xy.at (0).y ();
444 double y1 = xy.at (1).y ();
445 double numerator = (xTheta - x0);
446 double denominator = (x1 - x0);
447 if (qAbs (denominator) < qAbs (numerator) / 1.0e6) {
449 yRadius = xy.at (0).y ();
451 double s = numerator / denominator;
452 yRadius = (1.0 - s) * y0 + s * y1;
455 if (xThetaIsNotOutOfBounds (xTheta,
465 *(yRadiusValues [row]),
468 *(yRadiusValues [row]) =
"";
478 const int MAX_ITERATIONS = 32;
488 for (
int row = 0; row < xThetaValues.count(); row++) {
490 double xTheta = xThetaValues.at (row);
494 SplinePair splinePairFound = spline.findSplinePairForFunctionX (linearToLog.
linearize (xTheta, isLogXTheta),
496 double yRadius = linearToLog.
delinearize (splinePairFound.
y (),
500 if (xThetaIsNotOutOfBounds (xTheta,
510 *(yRadiusValues [row]),
513 *(yRadiusValues [row]) =
"";
520 void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
526 const QString &curveName,
529 QVector<QString*> &yRadiusValues)
const
536 QString dummyXThetaOut;
537 for (
int row = 0; row < xThetaValues.count(); row++) {
539 double xTheta = xThetaValues.at (row);
542 *(yRadiusValues [row]) =
"";
543 if (points.count () > 0) {
545 double yRadius = linearlyInterpolate (points,
550 if (xThetaIsNotOutOfBounds (xTheta,
560 *(yRadiusValues [row]),
567 void ExportFileFunctions::loadYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
573 const QString &curveName,
576 QVector<QString*> &yRadiusValues)
const
584 for (
int pt = 0; pt < points.count(); pt++) {
586 const Point &point = points.at (pt);
594 double closestSeparation = 0.0;
596 for (
int row = 0; row < xThetaValues.count(); row++) {
598 double xTheta = xThetaValues.at (row);
600 double separation = qAbs (posGraph.x() - xTheta);
603 (separation < closestSeparation)) {
605 closestSeparation = separation;
612 if (xThetaIsNotOutOfBounds (posGraph.x(),
616 QString dummyXThetaOut;
623 *(yRadiusValues [rowClosest]),
626 *(yRadiusValues [rowClosest]) =
"";
635 const QStringList &curvesIncluded,
638 QVector<QVector<QString*> > &yRadiusValues,
639 const QString &delimiter,
641 unsigned int &numWritesSoFar)
const
647 insertLineSeparator (numWritesSoFar == 0,
648 modelExportOverride.
header (),
651 str << gnuplotComment();
653 str << modelExportOverride.
xLabel();
654 QStringList::const_iterator itrHeader;
655 for (itrHeader = curvesIncluded.begin(); itrHeader != curvesIncluded.end(); itrHeader++) {
656 QString curveName = *itrHeader;
657 str << delimiter << curveName;
664 const double DUMMY_Y_RADIUS = 1.0;
666 for (
int row = 0; row < xThetaValuesMerged.count(); row++) {
668 if (rowHasAtLeastOneYRadiusEntry (yRadiusValues,
671 double xTheta = xThetaValuesMerged.at (row);
674 QString xThetaString, yRadiusString;
683 str << wrapInDoubleQuotesIfNeeded (modelExportOverride,
686 for (
int col = 0; col < yRadiusValues.count(); col++) {
688 QString yRadiusString = *(yRadiusValues [col] [row]);
689 str << delimiter << wrapInDoubleQuotesIfNeeded (modelExportOverride,
700 bool ExportFileFunctions::rowHasAtLeastOneYRadiusEntry (
const QVector<QVector<QString*> > &yRadiusValues,
703 bool hasEntry =
false;
705 for (
int col = 0; col < yRadiusValues.count(); col++) {
707 QString entry = *(yRadiusValues [col] [row]);
708 if (!entry.isEmpty()) {
719 bool ExportFileFunctions::xThetaIsNotOutOfBounds (
double xTheta,
720 const QString &curveName,
726 if (curveLimitsMin.contains (curveName)) {
727 ok = ok && (curveLimitsMin [curveName] <= xTheta);
730 if (curveLimitsMax.contains (curveName)) {
731 ok = ok && (xTheta <= curveLimitsMax [curveName]);
CurveLimits curveLimitsMin() const
Endpoint minima for each curve, if extrapolation has been disabled.
Model for DlgSettingsGeneral and CmdSettingsGeneral.
virtual CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
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.
Callback for collecting X/Theta independent variables, for functions, in preparation for exporting...
ExportValuesXOrY xThetaValues() const
Resulting x/theta values for all included functions.
ValuesVectorXOrY xThetaValuesRaw() const
Resulting x/theta values for all included functions.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
double delinearize(double value, bool isLog) const
Convert linear coordinates to log. This is a noop if the output is supposed to be linear...
LineStyle lineStyle() const
Get method for LineStyle.
ExportFileFunctions()
Single constructor.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
double y() const
Get method for y.
#define LOG4CPP_INFO_S(logger)
void loadSplinePairsWithTransformation(const Points &points, const Transformation &transformation, bool isLogXTheta, bool isLogYRadius, std::vector< double > &t, std::vector< SplinePair > &xy) const
Load t (=ordinal) and xy (=screen position) spline pairs, converting screen coordinates to graph coor...
QHash< QString, double > CurveLimits
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
QPointF posScreen() const
Accessor for screen position.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
Model for DlgSettingsMainWindow.
QList< double > ExportValuesXOrY
Utility class to interpolate points spaced evenly along a piecewise defined curve with fitted spline...
double linearize(double value, bool isLog) const
Convert log coordinates to linear. This is a noop if the input is already linear. ...
Model for DlgSettingsCoords and CmdSettingsCoords.
Storage of one imported image and the data attached to that image.
Container for one set of digitized Points.
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
virtual CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
log4cpp::Category * mainCat
QString exportDelimiterToText(ExportDelimiter exportDelimiter, bool isGnuplotDelimiter)
Callback for collecting X/Theta independent variables, for functions, in preparation for exporting...
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.
CurveLimits curveLimitsMax() const
Endpoint maxima for each curve, if extrapolation has been disabled.
Warps log coordinates to make them linear before passing them to code that accepts only linear coordi...
void exportToFile(const DocumentModelExportFormat &modelExportOverride, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, QTextStream &str, unsigned int &numWritesSoFar) const
Export Document points according to the settings.
Single X/Y pair for cubic spline interpolation initialization and calculations.
QMap< double, bool > ValuesVectorXOrY
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...