MeVisLab Toolbox Reference
mlITKKernelSupport.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #pragma once
14 
16 #include "mlInitSystemITKSupport.h"
17 
18 // Include most ML specific things.
19 #include "mlModuleIncludes.h"
20 #include "mlITKSupport.h"
21 #include "mlITKFlatStructElement.h"
22 #include "mlKernel.h"
23 
24 #include <itkNeighborhood.h>
25 #include <itkFlatStructuringElement.h>
26 #include <itkNumericTraits.h>
27 
28 namespace itk {
29 
30 //----------------------------------------------------------------------------------
33 //----------------------------------------------------------------------------------
34 template<class TPixel, unsigned int VDimension = 2, class TAllocator = NeighborhoodAllocator<TPixel>, class SuperClss = Neighborhood<TPixel, VDimension, TAllocator > >
35 class MLITKStructuringElementBase : public SuperClss
36 {
37 public:
40 
42  typedef Neighborhood<TPixel, VDimension, TAllocator> Superclass;
43 
45  typedef TAllocator AllocatorType;
46 
48  itkStaticConstMacro(NeighborhoodDimension, unsigned int, VDimension);
49 
51  typedef TPixel PixelType;
52 
56 
57  typedef typename AllocatorType::iterator Iterator;
58  typedef typename AllocatorType::const_iterator ConstIterator;
60 
62 
63  typedef typename Superclass::SizeType SizeType;
64  typedef typename Superclass::SizeValueType SizeValueType;
66 
68 
69  typedef typename Superclass::OffsetType OffsetType;
70  typedef typename OffsetType::OffsetValueType OffsetValueType;
72 
74  typedef typename Superclass::RadiusType RadiusType;
75 
77  typedef SliceIterator<TPixel, Self> SliceIteratorType;
78 
81 
84  {
85  // Initialize structure element from ML kernel.
87  }
88 
91 
94  : SuperClss(other)
95  {
96  }
97 
99  Self &operator=(const Self& other)
100  {
101  Superclass::operator=(other);
102  return *this;
103  }
104 
106  virtual void setKernelFromString(const std::string &kernelStr)
107  {
108  // Create an ML kernel from from the passed string.
109  ML_NAMESPACE::Kernel kernelFromStr;
110  kernelFromStr.setKernel(kernelStr);
111 
112  // Initialize structure element from ML kernel.
113  CreateStructuringElement(kernelFromStr);
114  }
115 
117  virtual void CreateStructuringElement(const ML_NAMESPACE::Kernel &kernel)
118  {
119  // Reset size to be sure that previous settings are cleared.
120  SizeType itkKExt;
121  itkKExt.Fill(0);
122  this->SetRadius(itkKExt);
123 
124  // Get extents of MK kernel.
125  ML_NAMESPACE::ImageVector kExt = kernel.getExtent();
126 
127  // Get maximum extents of MK kernel.
128  itkKExt = ML_NAMESPACE::ITKSizeFromMLVector<SizeType>(kExt);
129  this->SetRadius(itkKExt);
130 
131  // Get half kernel extent. Note that we rely on odd kernel extents.
132  ML_NAMESPACE::ImageVector shiftHalf(kernel.getNegativeExtent());
133 
134  // Scan all values of the ML kernel and set them in the itk kernel.
136  OffsetType offset;
137  offset.Fill(0);
138  for (size_t n=0; n < kernel.getTabSize(); n++){
139  pos.set(kernel.getCoordTab()[n]);
140  for (unsigned int i=0; i<offset.GetOffsetDimension(); i++){
141  // ITK structure elements are symmetric to the origin. So shift
142  // ML kernel element from (always positive) position half kernel left.
143  offset[i] = pos[i]-shiftHalf[i];
144  }
145 
146  // Set itk kernel element.
147  (*this)[offset] = static_cast<TPixel>(kernel.getValueTab()[n]);
148  }
149  }
150 };
151 
152 //----------------------------------------------------------------------------------
156 //----------------------------------------------------------------------------------
157 template<class TPixel, unsigned int VDimension = 2, class TAllocator = NeighborhoodAllocator<TPixel> >
158 class MLITKStructuringElement : public MLITKStructuringElementBase<TPixel, VDimension, TAllocator, Neighborhood<TPixel, VDimension, TAllocator > >
159 {
160 public:
163 
165  typedef Neighborhood<TPixel, VDimension, TAllocator > NeighbourHoodClass;
166 
169 
171  typedef TAllocator AllocatorType;
172 
174  itkStaticConstMacro(NeighborhoodDimension, unsigned int, VDimension);
175 
177  typedef TPixel PixelType;
178 
182 
183  typedef typename AllocatorType::iterator Iterator;
184  typedef typename AllocatorType::const_iterator ConstIterator;
186 
188 
189  typedef typename Superclass::SizeType SizeType;
192 
194 
196  typedef typename OffsetType::OffsetValueType OffsetValueType;
198 
201 
203  typedef SliceIterator<TPixel, Self> SliceIteratorType;
204 
207 
210 
212  MLITKStructuringElement(const Self& other): Superclass(other){ }
213 
215  Self &operator=(const Self& other)
216  {
217  Superclass::operator=(other);
218  return *this;
219  }
220 };
221 
222 } // namespace itk
223 
224 //--------------------------------------------------------------------------------
227 //--------------------------------------------------------------------------------
228 #define ML_ITK_KERNEL_WRAPPER_TYPEDEFS_0(CLASS_NAME, NAMESPACE) \
229  \
230  /*--------------------------------------------------------------------*/ \
231  \
232  /*--------------------------------------------------------------------*/ \
233  typedef itk::MLITKStructuringElement<ITK_INDATATYPE,DIM> MLITKKernelType; \
234  \
235  /*--------------------------------------------------------------------*/ \
236  \
237  /*--------------------------------------------------------------------*/ \
238  typedef NAMESPACE::CLASS_NAME<_TEMPLATE_INPUTS0, MLITKKernelType> FilterType; \
239 
240 
241 //--------------------------------------------------------------------------------
244 //--------------------------------------------------------------------------------
245 #define ML_ITK_KERNEL_WRAPPER_TYPEDEFS_1(CLASS_NAME, NAMESPACE) \
246  \
247  /*--------------------------------------------------------------------*/ \
248  \
249  /*--------------------------------------------------------------------*/ \
250  typedef itk::MLITKStructuringElement<ITK_INDATATYPE,DIM> MLITKKernelType; \
251  \
252  /*--------------------------------------------------------------------*/ \
253  \
254  /*--------------------------------------------------------------------*/ \
255  typedef NAMESPACE::CLASS_NAME<_TEMPLATE_INPUTS1, MLITKKernelType> FilterType; \
256 
257 
258 
259 //--------------------------------------------------------------------------------
262 //--------------------------------------------------------------------------------
263 #define ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_0(CLASS_NAME, NAMESPACE) \
264  \
265  /*--------------------------------------------------------------------*/ \
266  \
267  /*--------------------------------------------------------------------*/ \
268  typedef itk::FlatStructuringElement<DIM> MLITKFLATKernelType; \
269  \
270  /*--------------------------------------------------------------------*/ \
271  \
272  /*--------------------------------------------------------------------*/ \
273  typedef NAMESPACE::CLASS_NAME<_TEMPLATE_INPUTS0, MLITKFLATKernelType > FilterType; \
274 
275 
276 //--------------------------------------------------------------------------------
279 //--------------------------------------------------------------------------------
280 #define ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_1(CLASS_NAME, NAMESPACE) \
281  \
282  /*--------------------------------------------------------------------*/ \
283  \
284  /*--------------------------------------------------------------------*/ \
285  typedef itk::FlatStructuringElement<DIM> MLITKFLATKernelType; \
286  \
287  /*--------------------------------------------------------------------*/ \
288  \
289  /*--------------------------------------------------------------------*/ \
290  typedef NAMESPACE::CLASS_NAME<_TEMPLATE_INPUTS1, MLITKFLATKernelType > FilterType; \
291 
292 
293 
294 //--------------------------------------------------------------------------------
298 //--------------------------------------------------------------------------------
299 #define ML_ITK_KERNEL_WRAPPER_0_2D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
300  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
301  ML_ITK_KERNEL_WRAPPER_TYPEDEFS_0, \
302  ML_IMPLEMENT_ALL_ITK_2D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
303 
304 //--------------------------------------------------------------------------------
308 //--------------------------------------------------------------------------------
309 #define ML_ITK_KERNEL_WRAPPER_0_3D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
310  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
311  ML_ITK_KERNEL_WRAPPER_TYPEDEFS_0, \
312  ML_IMPLEMENT_ALL_ITK_3D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
313 
314 //--------------------------------------------------------------------------------
317 //--------------------------------------------------------------------------------
318 #define ML_ITK_KERNEL_WRAPPER_0_6D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
319  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
320  ML_ITK_KERNEL_WRAPPER_TYPEDEFS_0, \
321  ML_IMPLEMENT_ALL_ITK_6D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
322 
323 
324 //--------------------------------------------------------------------------------
328 //--------------------------------------------------------------------------------
329 #define ML_ITK_KERNEL_WRAPPER_1_2D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
330  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
331  ML_ITK_KERNEL_WRAPPER_TYPEDEFS_1, \
332  ML_IMPLEMENT_ALL_ITK_2D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
333 
334 //--------------------------------------------------------------------------------
338 //--------------------------------------------------------------------------------
339 #define ML_ITK_KERNEL_WRAPPER_1_3D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
340  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
341  ML_ITK_KERNEL_WRAPPER_TYPEDEFS_1, \
342  ML_IMPLEMENT_ALL_ITK_3D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
343 
344 //--------------------------------------------------------------------------------
347 //--------------------------------------------------------------------------------
348 #define ML_ITK_KERNEL_WRAPPER_1_6D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
349  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
350  ML_ITK_KERNEL_WRAPPER_TYPEDEFS_1, \
351  ML_IMPLEMENT_ALL_ITK_6D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
352 
353 
354 // For flat kernels:
355 
356 //--------------------------------------------------------------------------------
360 //--------------------------------------------------------------------------------
361 #define ML_ITK_FLAT_KERNEL_WRAPPER_0_2D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
362  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
363  ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_0, \
364  ML_IMPLEMENT_ALL_ITK_2D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
365 
366 //--------------------------------------------------------------------------------
370 //--------------------------------------------------------------------------------
371 #define ML_ITK_FLAT_KERNEL_WRAPPER_0_3D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
372  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
373  ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_0, \
374  ML_IMPLEMENT_ALL_ITK_3D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
375 
376 //--------------------------------------------------------------------------------
379 //--------------------------------------------------------------------------------
380 #define ML_ITK_FLAT_KERNEL_WRAPPER_0_6D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
381  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
382  ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_0, \
383  ML_IMPLEMENT_ALL_ITK_6D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
384 
385 
386 //--------------------------------------------------------------------------------
390 //--------------------------------------------------------------------------------
391 #define ML_ITK_FLAT_KERNEL_WRAPPER_1_2D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
392  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
393  ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_1, \
394  ML_IMPLEMENT_ALL_ITK_2D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
395 
396 //--------------------------------------------------------------------------------
400 //--------------------------------------------------------------------------------
401 #define ML_ITK_FLAT_KERNEL_WRAPPER_1_3D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
402  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
403  ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_1, \
404  ML_IMPLEMENT_ALL_ITK_3D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
405 
406 //--------------------------------------------------------------------------------
409 //--------------------------------------------------------------------------------
410 #define ML_ITK_FLAT_KERNEL_WRAPPER_1_6D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
411  _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
412  ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_1, \
413  ML_IMPLEMENT_ALL_ITK_6D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
Template class to create an itk structured element from an ML kernel.
Superclass::SizeType SizeType
Size and value typedef support.
virtual void CreateStructuringElement(const ml::Kernel &kernel)
Create the structuring element.
virtual ~MLITKStructuringElementBase()
Default destructor. Only superclass stuff is done.
Superclass::RadiusType RadiusType
Radius typedef support.
MLITKStructuringElementBase()
Default constructor.
virtual void setKernelFromString(const std::string &kernelStr)
Convenience constructor from a string description of an ML kernel.
itkStaticConstMacro(NeighborhoodDimension, unsigned int, VDimension)
External support for dimensionality.
TPixel PixelType
External support for pixel type.
Superclass::SizeValueType SizeValueType
TAllocator AllocatorType
External support for allocator type.
MLITKStructuringElementBase(const ml::Kernel &kernel)
Convenience constructor directly from the ML kernel.
Superclass::OffsetType OffsetType
Offset and value typedef support.
OffsetType::OffsetValueType OffsetValueType
AllocatorType::iterator Iterator
Iterator typedef support.
MLITKStructuringElementBase(const Self &other)
Copy constructor. Only superclass stuff is done.
AllocatorType::const_iterator ConstIterator
SliceIterator< TPixel, Self > SliceIteratorType
External slice iterator type typedef support.
MLITKStructuringElementBase Self
Standard self typedef.
Self & operator=(const Self &other)
Assignment operator. Only superclass stuff is done.
Neighborhood< TPixel, VDimension, TAllocator > Superclass
Standard super class typedef.
Specialized class for generated toolkit modules using normal kernels.
MLITKStructuringElement(const ml::Kernel &kernel)
Convenience constructor directly from the ML kernel.
Superclass::RadiusType RadiusType
Radius typedef support.
SliceIterator< TPixel, Self > SliceIteratorType
External slice iterator type typedef support.
TAllocator AllocatorType
External support for allocator type.
Self & operator=(const Self &other)
Assignment operator. Only superclass stuff is done.
AllocatorType::iterator Iterator
Iterator typedef support.
Superclass::OffsetType OffsetType
Offset and value typedef support.
itkStaticConstMacro(NeighborhoodDimension, unsigned int, VDimension)
External support for dimensionality.
MLITKStructuringElement(const Self &other)
Copy constructor. Only superclass stuff is done.
MLITKStructuringElement Self
Standard self typedef.
TPixel PixelType
External support for pixel type.
OffsetType::OffsetValueType OffsetValueType
MLITKStructuringElementBase< TPixel, VDimension, TAllocator, NeighbourHoodClass > Superclass
Standard super class typedef.
Superclass::SizeType SizeType
Size and value typedef support.
AllocatorType::const_iterator ConstIterator
MLITKStructuringElement()
Default constructor.
Superclass::SizeValueType SizeValueType
Neighborhood< TPixel, VDimension, TAllocator > NeighbourHoodClass
Used neighborhood.
std::string setKernel(const std::string &kernString)
Defines elements and values of the kernel matrix by a string.
Definition: mlKernel.h:1255
Include dll-specific settings.
TKernel< KernelDataType > Kernel
Standard kernel type to be used in this kernel library.
Definition: mlKernel.h:2211
TImageVector< MLint > ImageVector
Defines the standard ImageVector type which is used by the ML for indexing and coordinates.