comac_desk_app/PostProcessing/CommonFunction.h

49 lines
1.5 KiB
C++

#ifndef PST_COMMONFUNCTION_H
#define PST_COMMONFUNCTION_H
//#include "PostProcessingModuleConfig.h"
#include <iostream>
#include <vector>
namespace pst
{
class CommonFunction
{
public:
CommonFunction();
public:
// 字符串分割
static void Stringsplit(const std::string& str, const std::string& splits,
std::vector<std::string>& res);
//去除字符串首尾空格
static std::string trim(const std::string& s);
//球坐标(角度制)转直角坐标-->点
static void SphereToRectangularCoorSys(const double theta,
const double phi, const double r, double& x, double& y, double& z);
static void PolarToRectangularCoorSys(const double theta, const double r, double& x, double& y);
//判断两个浮点数是否相等
// ulp: units in the last place.
template <typename T>
typename std::enable_if<!std::numeric_limits<T>::is_integer, bool>::type
IsAlmostEqual(T x, T y, int ulp = 2)
{
// the machine epsilon has to be scaled to the magnitude of the values used
// and multiplied by the desired precision in ULPs (units in the last place)
return std::fabs(x - y) <
std::numeric_limits<T>::epsilon() * std::fabs(x + y) * ulp
// unless the result is subnormal
|| std::fabs(x - y) < std::numeric_limits<T>::min();
}
};
}
#endif // QVTK_COMMONFUNCTION_H