ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkFFTWGlobalConfiguration.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkFFTWGlobalConfiguration_h
19 #define itkFFTWGlobalConfiguration_h
20 
21 #include "itkObject.h"
22 //NOTE: Need to have at least one itk include before
23 // the next defines in order to have ITK_USE_FFTWF,ITK_USE_FFTWD defined
24 #if defined(ITK_USE_FFTWF) || defined(ITK_USE_FFTWD)
25 
26 #include "ITKFFTExport.h"
27 #include "itkSimpleFastMutexLock.h"
28 
29 #include "itksys/SystemTools.hxx"
30 #include "itksys/SystemInformation.hxx"
31 #include "fftw3.h"
32 #include <algorithm>
33 #include <cctype>
34 
35 //* The fftw utilities help control the various strategies
36 //available for controlling optimizations for the FFTW library.
37 //
38 //Environmental variables:
39 //ITK_FFTW_PLAN_RIGOR - Defines how aggressive the generation of
40 // wisdom should be.
41 //ITK_FFTW_READ_WISDOM_CACHE - Defines if a wisdom file cache should
42 // be read if found. (it is "On" by default)
43 //ITK_FFTW_WRITE_WISDOM_CACHE - Defines if generated wisdom file cache
44 // should be written (it is "Off" by default)
45 //ITK_FFTW_WISDOM_CACHE_BASE - Defines the base directory where the
46 // fftw wisdom cache will be placed,
47 // this is intended to be used with auto-
48 // generated cache file names
49 //ITK_FFTW_WISDOM_CACHE_FILE - Defines the full name of the cache
50 // file to be generated. If this is
51 // set, then ITK_FFTW_WISDOM_CACHE_BASE
52 // is ignored.
53 //
54 // The above behaviors can also be controlled by the application.
55 //
56 
57 namespace itk
58 {
63 #ifdef _WIN32
64 #define FFTWPathSep "\\"
65 #else
66 #define FFTWPathSep "/"
67 #endif
68 
69 class ITKFFT_EXPORT WisdomFilenameGeneratorBase
70 {
71  public:
72  //The baseCacheDirectory from which to build the cache hierarchy
73  virtual std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const = 0;
75  virtual ~WisdomFilenameGeneratorBase();
76  private:
77 };
78 
79 class ITKFFT_EXPORT ManualWisdomFilenameGenerator:
81 {
82  public:
83  ManualWisdomFilenameGenerator(const std::string &wfn);
84  void SetWisdomFilename(const std::string &wfn);
85  virtual std::string GenerateWisdomFilename(const std::string &baseCacheDirectory ) const ITK_OVERRIDE;
86  private:
87  std::string m_WisdomFilename;
88 };
89 
91 {
92  public:
93  virtual std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const ITK_OVERRIDE;
94 };
95 
97 {
98  public:
99  virtual std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const ITK_OVERRIDE;
100 };
101 
103 {
104 public:
106 
107  virtual std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const ITK_OVERRIDE;
108 
109  void SetUseOSName(const bool flag);
110  void SetUseOSRelease(const bool flag);
111  void SetUseOSVersion(const bool flag);
112  void SetUseOSPlatform(const bool flag);
113  void SetUseOSBitSize(const bool flag);
114  void SetUseNumberOfProcessors(const bool flag);
115  void SetUseVendorString(const bool flag);
116  void SetUseTypeID(const bool flag);
117  void SetUseFamilyID(const bool flag);
118  void SetUseModelID(const bool flag);
119  void SetUseSteppingCode(const bool flag);
120 
121  bool GetUseOSName() const;
122  bool GetUseOSRelease() const;
123  bool GetUseOSVersion() const;
124  bool GetUseOSPlatform() const;
125  bool GetUseOSBitSize() const;
126  bool GetUseNumberOfProcessors() const;
127  bool GetUseVendorString() const;
128  bool GetUseTypeID() const;
129  bool GetUseFamilyID() const;
130  bool GetUseModelID() const;
131  bool GetUseSteppingCode() const;
132 
133 private:
146 };
147 
166 class ITKFFT_EXPORT FFTWGlobalConfiguration
167  : public Object
168 {
169 public:
170 
177 
179  itkTypeMacro(FFTWGlobalConfiguration, Object);
180 
182  static SimpleFastMutexLock & GetLockMutex();
183 
188  static void SetNewWisdomAvailable( const bool & v );
189  static bool GetNewWisdomAvailable();
191 
200  static void SetPlanRigor( const int & v );
201 
202  static int GetPlanRigor();
203  static void SetPlanRigor( const std::string & name );
204 
206  static int GetPlanRigorValue( const std::string & name );
207 
209  static std::string GetPlanRigorName( const int & value );
210 
218  static void SetReadWisdomCache( const bool & v );
219  static bool GetReadWisdomCache();
221 
229  static void SetWriteWisdomCache( const bool & v );
230  static bool GetWriteWisdomCache();
232 
239  static void SetWisdomCacheBase( const std::string & v );
240  static std::string GetWisdomCacheBase();
242 
255  static void SetWisdomFilenameGenerator( WisdomFilenameGeneratorBase *wfg);
256 
270  static std::string GetWisdomFileDefaultBaseName();
271 
273  static bool ImportWisdomFileDouble( const std::string &fname );
274  static bool ExportWisdomFileDouble( const std::string &fname );
276 
278  static bool ImportWisdomFileFloat( const std::string &fname );
279  static bool ExportWisdomFileFloat( const std::string &fname );
281 
283  static bool ImportDefaultWisdomFileDouble();
284  static bool ExportDefaultWisdomFileDouble();
286 
288  static bool ImportDefaultWisdomFileFloat();
289  static bool ExportDefaultWisdomFileFloat();
291 
292 private:
293  FFTWGlobalConfiguration(); //This will process env variables
294  ~FFTWGlobalConfiguration(); //This will write cache file if requested.
295 
297  static Pointer GetInstance();
298 
303  itkFactorylessNewMacro(Self);
304 
305  FFTWGlobalConfiguration(const Self &) ITK_DELETE_FUNCTION;
306  void operator=(const Self &) ITK_DELETE_FUNCTION;
307 
308  static Pointer m_Instance;
309  static SimpleFastMutexLock m_CreationLock;
310 
312  bool m_NewWisdomAvailable;
313  int m_PlanRigor;
314  bool m_WriteWisdomCache;
315  bool m_ReadWisdomCache;
316  std::string m_WisdomCacheBase;
317  //m_WriteWisdomCache Controls the behavior of default
318  //wisdom file creation policies.
319  WisdomFilenameGeneratorBase * m_WisdomFilenameGenerator;
320 };
321 }
322 #endif
323 #endif
Critical section locking class that can be allocated on the stack.
Light weight base class for most itk classes.
SmartPointer< const Self > ConstPointer
Base class for most ITK classes.
Definition: itkObject.h:57