Skip to content

Commit

Permalink
Re #11422 Implement functions for scaling transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew D Jones authored and Matthew D Jones committed Aug 6, 2015
1 parent c267193 commit 225eb1b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
#include "qwt_math.h"
#include "qwt_scale_map.h"

/*!
\brief Operations for power (X^n) transformations
*/
/*
* Operations for power (X^n) transformations
*/
class QWT_EXPORT MantidQwtScaleTransformation: public QwtScaleTransformation
{
public:
Expand All @@ -43,6 +43,15 @@ class QWT_EXPORT MantidQwtScaleTransformation: public QwtScaleTransformation
Other
};

private:
// TODO this should be user input from GUI
int nth_power = 2;

MantidQwtScaleTransformation();
MantidQwtScaleTransformation &operator=( const MantidQwtScaleTransformation);

const Type d_type;

};

#endif
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/API/src/MantidQwtPowerScaleEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MantidQwtScaleTransformation *MantidQwtPowerScaleEngine::transformation() const
void MantidQwtPowerScaleEngine::autoScale(int maxNumSteps,
double &x1, double &x2, double &stepSize) const
{
const double one_over_n = 1.0/nth_power
const double one_over_n = 1.0/nth_power;

if ( x1 > x2 )
qSwap(x1, x2);
Expand Down
35 changes: 35 additions & 0 deletions Code/Mantid/MantidQt/API/src/MantidQwtScaleTransformation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "MantidQwtScaleTransformation.h"

double MantidQwtScaleTransformation::xForm(
double s, double s1, double s2, double p1, double p2) const
{
if (d_type == Log10)
return p1 + (p2 - p1) / log(s2 / s1) * log(s / s1);
else if (d_type == Power)
return p1 + (p2 - p1) / pow(s2, nth_power) - pow(s1, nth_power)) * (pow(s, nth_power) - pow(s1, nth_power));
else
return p1 + (p2 - p1) / (s2 - s1) * (s - s1);
}

/*
Transform a value from a linear to a logarithmic interval
@param p value related to the linear interval [p1, p2]
@param p1 first border of linear interval
@param p2 second border of linear interval
@param s1 first border of logarithmic interval
@param s2 second border of logarithmic interval
@return logarithmic or power interval
*/
double QwtScaleTransformation::invXForm(double p, double p1, double p2,
double s1, double s2) const
{
if (d_type == Log10)
return exp((p - p1) / (p2 - p1) * log(s2 / s1)) * s1;
else if (d_type == Power){
const double one_over_n = 1.0/nth_power;
return pow((p - p1) / (p2 - p1) * pow(s2, nth_power) - pow(s1, nth_power)), one_over_n) * s1;
}
else
return s1 + (s2 - s1) / (p2 - p1) * (p - p1);
}

0 comments on commit 225eb1b

Please sign in to comment.