13 #ifndef BASIC_FUNCTIONS_H
14 #define BASIC_FUNCTIONS_H
41 inline T
clamp(T inf, T sup, T v)
43 return std::min(sup, std::max(inf, v));
59 inline T
wrap(T inf, T sup, T v)
63 T out = vtmp < 0 ? sup-((-vtmp-1)%len) : inf+(vtmp%len);
102 return sin(M_PI*x/a)/(M_PI*x/a);
119 return exp(-x*x*2*M_PI*M_PI*sd*sd);
134 const double alpha = .54;
135 const double beta = 1-alpha;
137 return alpha-beta*cos(M_PI*x/a+M_PI);
172 const double alpha = .50;
173 const double beta = 1-alpha;
175 return alpha-beta*cos(M_PI*x/a+M_PI);
194 double v = a*sin(M_PI*x)*sin(M_PI*x/a)/(M_PI*M_PI*x*x);
195 assert(v <= 1.001 && v >= -1.0001);
212 double v = (M_PI*x*((cos((M_PI*x)/a)*sin(M_PI*x)) +
213 (a*sin((M_PI*x)/a)*cos(M_PI*x))) -
214 (2*a*sin((M_PI*x)/a)*sin(M_PI*x)))/(M_PI*M_PI*x*x*x);
215 assert(v >= -2 && v <= 10);
224 return fabs(1-fmin(1,fabs(x/a)))/a;
253 switch((
int)floor(x)) {
255 return 4./3. + 2.*x + x*x + x*x*x/6.;
258 return 2./3. - x*x - x*x*x/2.;
261 return 2./3. - x*x + x*x*x/2.;
264 return 4./3. - 2*x + x*x - x*x*x/6.;
296 switch((
int)floor(x)) {
298 return (4+4*x+x*x)/2.;
300 return -(4*x + 3*x*x)/2.;
302 return (-4*x + 3*x*x)/2.;
304 return -(x*x - 4*x + 4)/2.;
335 switch((
int)floor(x)) {
407 return rad*M_PI/180.;
413 return rad*180./M_PI;
448 int64_t just_hob =
hob(in);
452 return (just_hob<<1);
465 std::list<int64_t> factors;
466 for(int64_t ii = 2; ii<=f; ii++) {
469 factors.push_back(ii);
491 bool acceptable =
false;
497 auto factors =
factor(in);
498 for(
auto f : factors) {
499 if(f != 3 && f != 5 && f != 7) {
531 template <
typename T =
int,
int MAXDIM=10>
550 for(
size_t dd=0; dd<
ndim; dd++)
566 for(
size_t dd=0; dd<dim; dd++) {
583 for(
int dd=0; dd<(int)ndim; dd++) {
585 if(pos[dd] == sz[dd])
591 for(
int dd=ndim-1; dd>= 0; dd--) {
593 if(pos[dd] == sz[dd])
606 #endif //BASIC_FUNCTIONS_H
#define INVALID_ARGUMENT(EXP)
Counter(size_t dim, const T *stop)
Initialize counter with the specified dimension and stop point.
bool advance(bool rorder=false)
Advance through ND-counter. 0,0,0 to 0,0,1 and so on. If roder is true then this will start at 0...
Very basic counter that iterates over an ND region.
double freqGaussian(double x, double sd)
Gaussian function in the frequency domain. Note that the standard deviation is in the time domain...
double hammingWindow(double x, double a)
double welchWindow(double x, double a)
double dLanczosKern(double x, double a)
Derivative of lanczos kernel with respect to x.
T clamp(T inf, T sup, T v)
Clamps value to range of [inf, sup]. Values outside will be pulled to either sup or inf...
int64_t round2(int64_t in)
Round up to the nearest power of 2.
std::list< int64_t > factor(int64_t f)
Provides a list of the prime-fractors of the input number.
double dB3kern(double x)
3rd order B-Spline derivative, radius 2 [-2,2]
double sincWindow(double x, double a)
Sinc function centered at 0, with radius a, range should be = 2a.
double hannWindow(double x, double a)
double radToDeg(double rad)
int64_t round357(int64_t in)
Rounds a number up to the nearest number that can be broken down into 3,5,7.
double degToRad(double rad)
double lanczosKern(double x, double a)
Derivative of lanczos kernel with respect to x.
double ddB3kern(double x)
3rd order B-Spline, 2nd derivative, radius 2 [-2,2]
double rectWindow(double x, double a)
Rectangle function centered at 0, with radius a, range should be = 2a.
double dLinKern(double x, double a)
const size_t MAXDIM
Defines the maximum supported dimension by image, used for stack-allocations.
double B3kern(double x)
3rd order B-Spline, radius 2 [-2,2]
int hob(int num)
Highest order bit.
double sec(double v)
Secand function.
Counter(size_t dim)
Default constructor. Just sizes pos to 0. dim is the number of dimensions to use/iterate over...
double cot(double v)
Cotangent function.
T wrap(T inf, T sup, T v)
Wraps and index based on the range [inf, sup] (when v is outside that) range. Thus inf = 1...
double csc(double v)
Cosecant function.