Newer
Older
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include <iostream>
#include <cmath>
#include <stdexcept>
#include "MantidAPI/LogarithmScale.h"
//#include "MantidAPI/TransformScaleFactory.h"
namespace Mantid
{
namespace API
{
//DECLARE_TRANSFORMSCALE(LogarithmScale);
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
void LogarithmScale::setBase( double &base)
{
if( base <=0 )
{
g_log.error("Error: logarithm base must be a positive number");
}
m_base = base;
}
/* Transform the grid to adopt a logarithm scale.
* @param gd a grid object
*/
void LogarithmScale::transform( std::vector<double> &gd )
{
double a = 1.0/log(m_base);
size_t n = gd.size();
if(n==0) return; //no need to process
if( gd.front() <=0 )
{
g_log.error("LogarithmScale::transform Error: negative values");
return;
}
if(n<3) return; //no need to process
double startX = a * log( gd.front() );
double endX = a * log( gd.back() );
double spacing = (endX-startX)/double(n);
double x = startX + spacing;
for(auto it=gd.begin()+1; it!=gd.end()-1; it++)
{
*it = pow(m_base,x);
x += spacing;
}
}
} // namespace API
} // namespace Mantid