Sinc.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2018 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_Sinc_H
21 #define MIRTK_Sinc_H
22 
23 #include "mirtk/Config.h"
24 #include "mirtk/Math.h"
25 
26 #include "mirtk/NumericsExport.h"
27 
28 
29 namespace mirtk {
30 
31 
32 /**
33  * Sinc function
34  */
35 template <class TReal>
36 class Sinc
37 {
38 public:
39 
40  /// Floating point precision type
41  typedef TReal Real;
42 
43  /// Radius of Sinc kernel
44  /// (for use as Kernel::Radius, where Kernel is a typedef of Sinc<T>)
45  MIRTKCU_API static const int Radius = 6;
46 
47  /// Size of Sinc kernel
48  MIRTKCU_API static const int KernelSize = 2 * Radius + 1;
49 
50  /// Size of Sinc function lookup table
51  /// Note that the actual array size is: LookupTableSize * (Radius + 0.5)
52  MIRTKCU_API static const int LookupTableSize = 1000000;
53 
54  /// Lookup table of Sinc function values
55  MIRTK_Numerics_EXPORT MIRTKCU_API static Real *LookupTable;
56 
57  /// Initialize lookup table of Sinc function values
58  MIRTKCU_API static void Initialize();
59 
60  /// Lookup Sinc function value
61  MIRTKCU_API static Real Lookup(TReal);
62 
63 };
64 
65 // -----------------------------------------------------------------------------
66 // Fix Clang warning regarding missing definition of static template member
67 #ifdef __clang__
68 template <class TReal> TReal *Sinc<TReal>::LookupTable = nullptr;
69 #endif // defined(__clang__)
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 // Inline definitions
73 ////////////////////////////////////////////////////////////////////////////////
74 
75 // -----------------------------------------------------------------------------
76 template <class TReal>
77 inline TReal Sinc<TReal>::Lookup(TReal x)
78 {
79  return LookupTable[iround(abs(x) * LookupTableSize)];
80 }
81 
82 
83 } // namespace mirtk
84 
85 #endif // MIRTK_Sinc_H
TReal Real
Floating point precision type.
Definition: Sinc.h:41
static MIRTKCU_API Real Lookup(TReal)
Lookup Sinc function value.
Definition: Sinc.h:77
static MIRTKCU_API const int LookupTableSize
Definition: Sinc.h:52
static MIRTKCU_API const int Radius
Definition: Sinc.h:45
Definition: IOConfig.h:41
static MIRTKCU_API void Initialize()
Initialize lookup table of Sinc function values.
static MIRTKCU_API const int KernelSize
Size of Sinc kernel.
Definition: Sinc.h:48
MIRTKCU_API int iround(T x)
Round floating-point value and cast to int.
Definition: Math.h:170
MIRTK_Numerics_EXPORT static MIRTKCU_API Real * LookupTable
Lookup table of Sinc function values.
Definition: Sinc.h:55