-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #5827 classes for the scaling transformation
- Loading branch information
Showing
8 changed files
with
433 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#ifndef MANTID_API_ITRANSFORMSCALE_H_ | ||
#define MANTID_API_ITRANSFORMSCALE_H_ | ||
|
||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include <boost/shared_ptr.hpp> | ||
|
||
#include "MantidAPI/DllConfig.h" | ||
#include "MantidKernel/Logger.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
/*Base class representing a scaling transformation acting on a one-dimensional grid domain | ||
@author Jose Borreguero | ||
@date Aug/28/2012 | ||
Copyright © 2009 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid>. | ||
Code Documentation is available at: <http://doxygen.mantidproject.org>. | ||
*/ | ||
|
||
class MANTID_API_DLL ITransformScale | ||
{ | ||
public: | ||
/// Virtual destructor | ||
virtual ~ITransformScale() {} | ||
virtual void initialize(); | ||
virtual const std::string name() const { return "ITransformScale"; } | ||
/// The scaling transformation. Override with method of derived classes | ||
virtual void transform( std::vector<double> &gd ); | ||
|
||
protected: | ||
static Kernel::Logger& g_log; | ||
}; // class ITransformScale | ||
|
||
/// typedef for a shared pointer | ||
typedef boost::shared_ptr<ITransformScale> ITransformScale_sptr; | ||
|
||
} // namespace API | ||
} // namespace Mantid | ||
|
||
#define DECLARE_TRANSFORMSCALE(classname) \ | ||
namespace { \ | ||
Mantid::Kernel::RegistrationHelper register_trs_##classname( \ | ||
((Mantid::API::TransformScaleFactory::Instance().subscribe<classname>(#classname)) \ | ||
, 0)); \ | ||
} | ||
|
||
|
||
#endif /*MANTID_API_ITRANSFORMSCALE_H_*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef MANTID_API_LINEARSCALE_H_ | ||
#define MANTID_API_LINEARSCALE_H_ | ||
|
||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAPI/DllConfig.h" | ||
#include "MantidAPI/ITransformScale.h" | ||
|
||
#include <boost/shared_ptr.hpp> | ||
|
||
#include <stdexcept> | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
/*Base class representing a linear scaling transformation acting on a one-dimensional grid domain | ||
@author Jose Borreguero | ||
@date Aug/28/2012 | ||
Copyright © 2009 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid>. | ||
Code Documentation is available at: <http://doxygen.mantidproject.org>. | ||
*/ | ||
|
||
class MANTID_API_DLL LinearScale : public ITransformScale | ||
{ | ||
public: | ||
LinearScale(); | ||
~LinearScale(); | ||
/// The scaling transformation. First and last elements of the grid remain unchanged | ||
const std::string name() const { return "LinearScale"; } | ||
void transform( std::vector<double> &gd ); | ||
}; // class LinearScale | ||
|
||
|
||
} // namespace API | ||
} // namespace Mantid | ||
|
||
#endif /*MANTID_API_LINEARSCALE_H_*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#ifndef MANTID_API_LOGARITHMSCALE_H_ | ||
#define MANTID_API_LOGARITHMSCALE_H_ | ||
|
||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include <boost/shared_ptr.hpp> | ||
#include <cmath> | ||
|
||
#include "MantidAPI/DllConfig.h" | ||
#include "MantidAPI/ITransformScale.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
/*Base class representing a logarithm scaling transformation acting on a one-dimensional grid domain | ||
@author Jose Borreguero | ||
@date Aug/28/2012 | ||
Copyright © 2009 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid>. | ||
Code Documentation is available at: <http://doxygen.mantidproject.org>. | ||
*/ | ||
|
||
class MANTID_API_DLL LogarithmScale : public ITransformScale | ||
{ | ||
public: | ||
LogarithmScale() : m_base(M_E) {}; | ||
~LogarithmScale(); | ||
void setBase( double &base); | ||
/// The scaling transformation. First and last elements of the grid remain unchanged | ||
void transform( std::vector<double> &gd ); | ||
const std::string name() const { return "LogarithmScale"; } | ||
|
||
private: | ||
double m_base; //base of the logarithm | ||
|
||
}; // class LogarithmScale | ||
|
||
|
||
} // namespace API | ||
} // namespace Mantid | ||
|
||
#endif /*MANTID_API_LOGARITHMSCALE_H_*/ |
84 changes: 84 additions & 0 deletions
84
Code/Mantid/Framework/API/inc/MantidAPI/TransformScaleFactory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#ifndef MANTID_API_TRANSFORMSCALEFACTORY_H_ | ||
#define MANTID_API_TRANSFORMSCALEFACTORY_H_ | ||
|
||
#include "MantidAPI/DllConfig.h" | ||
#include "MantidKernel/ClassMacros.h" | ||
#include "MantidKernel/DynamicFactory.h" | ||
#include "MantidKernel/SingletonHolder.h" | ||
|
||
namespace Mantid | ||
{ | ||
// | ||
// Forward declarations | ||
// | ||
namespace Kernel | ||
{ | ||
class IPropertyManager; | ||
} | ||
namespace API | ||
{ | ||
// | ||
// Forward declarations | ||
// | ||
class ITransformScale; | ||
|
||
/** | ||
Constructs a scaling transform object from a string | ||
Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid>. | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class MANTID_API_DLL TransformScaleFactoryImpl : public Kernel::DynamicFactory<ITransformScale> | ||
{ | ||
public: | ||
/// Returns scaling transform | ||
boost::shared_ptr<ITransformScale> create(const std::string &type ) const; | ||
|
||
private: | ||
friend struct Mantid::Kernel::CreateUsingNew<TransformScaleFactoryImpl>; | ||
|
||
/// Private Constructor for singleton class | ||
TransformScaleFactoryImpl(); | ||
///Private Destructor for singleton | ||
virtual ~TransformScaleFactoryImpl(); | ||
/// Override the DynamicFactory::createUnwrapped() method. We don't want it used here. | ||
ITransformScale* createUnwrapped(const std::string& className) const; | ||
/// Private copy constructor - NO COPY ALLOWED | ||
TransformScaleFactoryImpl(const TransformScaleFactoryImpl&); | ||
/// Private assignment operator - NO ASSIGNMENT ALLOWED | ||
TransformScaleFactoryImpl& operator = (const TransformScaleFactoryImpl&); | ||
///reference to the logger class | ||
Kernel::Logger& g_log; | ||
// Do not use default methods | ||
}; | ||
|
||
///Forward declaration of a specialisation of SingletonHolder for TransformScaleFactoryImpl (needed for dllexport/dllimport) and a typedef for it. | ||
#ifdef _WIN32 | ||
// this breaks new namespace declaraion rules; need to find a better fix | ||
template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<TransformScaleFactoryImpl>; | ||
#endif /* _WIN32 */ | ||
typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<TransformScaleFactoryImpl> TransformScaleFactory; | ||
|
||
|
||
} // namespace API | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_API_TRANSFORMSCALEFACTORY_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include <iostream> | ||
|
||
#include "MantidAPI/LinearScale.h" | ||
#include "MantidAPI/GridDomain1D.h" | ||
#include "MantidAPI/TransformScaleFactory.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
|
||
DECLARE_TRANSFORMSCALE(LinearScale); | ||
|
||
/* Transform the grid to adopt a linear scale | ||
* @param gd a grid object | ||
*/ | ||
void LinearScale::transform( std::vector<double> &gd ) | ||
{ | ||
size_t n = gd.size(); | ||
if(n<3) return; //no need to process | ||
double startX = gd.front(); | ||
double endX = gd.back(); | ||
double spacing = (endX-startX)/double(n); | ||
double x = startX + spacing; | ||
for(auto it=gd.begin()+1; it!=gd.end()-1; it++) | ||
{ | ||
*it = x; | ||
x += spacing; | ||
} | ||
} | ||
|
||
|
||
|
||
} // namespace API | ||
} // namespace Mantid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include <iostream> | ||
#include <cmath> | ||
#include <stdexcept> | ||
|
||
#include "MantidAPI/LogarithmScale.h" | ||
#include "MantidAPI/GridDomain1D.h" | ||
#include "MantidAPI/TransformScaleFactory.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
|
||
DECLARE_TRANSFORMSCALE(LogarithmScale); | ||
|
||
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 |
Oops, something went wrong.