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
17
18// Include most ML specific things.
19#include "mlModuleIncludes.h"
20#include "mlITKSupport.h"
22#include "mlKernel.h"
23
24#include <itkNeighborhood.h>
25#include <itkFlatStructuringElement.h>
26#include <itkNumericTraits.h>
27
28namespace itk {
29
30//----------------------------------------------------------------------------------
33//----------------------------------------------------------------------------------
34template<class TPixel, unsigned int VDimension = 2, class TAllocator = NeighborhoodAllocator<TPixel>, class SuperClss = Neighborhood<TPixel, VDimension, TAllocator > >
36{
37public:
40
42 typedef Neighborhood<TPixel, VDimension, TAllocator> Superclass;
43
46
49
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
78
81
83 MLITKStructuringElementBase(const ML_NAMESPACE::Kernel &kernel)
84 {
85 // Initialize structure element from ML kernel.
87 }
88
91
97
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.
114 }
115
117 virtual void CreateStructuringElement(const ML_NAMESPACE::Kernel &kernel)
118 {
119 // Reset size to be sure that previous settings are cleared.
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.
135 ML_NAMESPACE::ImageVector pos(0);
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//----------------------------------------------------------------------------------
157template<class TPixel, unsigned int VDimension = 2, class TAllocator = NeighborhoodAllocator<TPixel> >
158class MLITKStructuringElement : public MLITKStructuringElementBase<TPixel, VDimension, TAllocator, Neighborhood<TPixel, VDimension, TAllocator > >
159{
160public:
163
165 typedef Neighborhood<TPixel, VDimension, TAllocator > NeighbourHoodClass;
166
169
172
175
178
182
183 typedef typename AllocatorType::iterator Iterator;
184 typedef typename AllocatorType::const_iterator ConstIterator;
186
188
192
194
196 typedef typename OffsetType::OffsetValueType OffsetValueType;
198
201
204
207
209 MLITKStructuringElement(const ML_NAMESPACE::Kernel &kernel) : Superclass(kernel){ }
210
213
216 {
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_KERNEL_WRAPPER_TYPEDEFS_2(CLASS_NAME, NAMESPACE) \
264 \
265 /*--------------------------------------------------------------------*/ \
266 \
267 /*--------------------------------------------------------------------*/ \
268 typedef itk::MLITKStructuringElement<ITK_INDATATYPE,DIM> MLITKKernelType; \
269 \
270 /*--------------------------------------------------------------------*/ \
271 \
272 /*--------------------------------------------------------------------*/ \
273 typedef NAMESPACE::CLASS_NAME<_TEMPLATE_INPUTS2, MLITKKernelType> FilterType; \
274
275
276
277//--------------------------------------------------------------------------------
280//--------------------------------------------------------------------------------
281#define ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_0(CLASS_NAME, NAMESPACE) \
282 \
283 /*--------------------------------------------------------------------*/ \
284 \
285 /*--------------------------------------------------------------------*/ \
286 typedef itk::FlatStructuringElement<DIM> MLITKFLATKernelType; \
287 \
288 /*--------------------------------------------------------------------*/ \
289 \
290 /*--------------------------------------------------------------------*/ \
291 typedef NAMESPACE::CLASS_NAME<_TEMPLATE_INPUTS0, MLITKFLATKernelType > FilterType; \
292
293
294//--------------------------------------------------------------------------------
297//--------------------------------------------------------------------------------
298#define ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_1(CLASS_NAME, NAMESPACE) \
299 \
300 /*--------------------------------------------------------------------*/ \
301 \
302 /*--------------------------------------------------------------------*/ \
303 typedef itk::FlatStructuringElement<DIM> MLITKFLATKernelType; \
304 \
305 /*--------------------------------------------------------------------*/ \
306 \
307 /*--------------------------------------------------------------------*/ \
308 typedef NAMESPACE::CLASS_NAME<_TEMPLATE_INPUTS1, MLITKFLATKernelType > FilterType; \
309
310
311
312//--------------------------------------------------------------------------------
316//--------------------------------------------------------------------------------
317#define ML_ITK_KERNEL_WRAPPER_0_2D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
318 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
319 ML_ITK_KERNEL_WRAPPER_TYPEDEFS_0, \
320 ML_IMPLEMENT_ALL_ITK_2D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
321
322//--------------------------------------------------------------------------------
326//--------------------------------------------------------------------------------
327#define ML_ITK_KERNEL_WRAPPER_0_3D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
328 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
329 ML_ITK_KERNEL_WRAPPER_TYPEDEFS_0, \
330 ML_IMPLEMENT_ALL_ITK_3D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
331
332//--------------------------------------------------------------------------------
335//--------------------------------------------------------------------------------
336#define ML_ITK_KERNEL_WRAPPER_0_6D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
337 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
338 ML_ITK_KERNEL_WRAPPER_TYPEDEFS_0, \
339 ML_IMPLEMENT_ALL_ITK_6D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
340
341
342//--------------------------------------------------------------------------------
346//--------------------------------------------------------------------------------
347#define ML_ITK_KERNEL_WRAPPER_1_2D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
348 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
349 ML_ITK_KERNEL_WRAPPER_TYPEDEFS_1, \
350 ML_IMPLEMENT_ALL_ITK_2D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
351
352//--------------------------------------------------------------------------------
356//--------------------------------------------------------------------------------
357#define ML_ITK_KERNEL_WRAPPER_1_3D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
358 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
359 ML_ITK_KERNEL_WRAPPER_TYPEDEFS_1, \
360 ML_IMPLEMENT_ALL_ITK_3D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
361
362//--------------------------------------------------------------------------------
365//--------------------------------------------------------------------------------
366#define ML_ITK_KERNEL_WRAPPER_1_6D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
367 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
368 ML_ITK_KERNEL_WRAPPER_TYPEDEFS_1, \
369 ML_IMPLEMENT_ALL_ITK_6D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
370
371
372//--------------------------------------------------------------------------------
375//--------------------------------------------------------------------------------
376#define ML_ITK_KERNEL_WRAPPER_2_6D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
377 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
378 ML_ITK_KERNEL_WRAPPER_TYPEDEFS_2, \
379 ML_IMPLEMENT_ALL_ITK_6D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
380
381
382// For flat kernels:
383
384//--------------------------------------------------------------------------------
388//--------------------------------------------------------------------------------
389#define ML_ITK_FLAT_KERNEL_WRAPPER_0_2D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
390 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
391 ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_0, \
392 ML_IMPLEMENT_ALL_ITK_2D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
393
394//--------------------------------------------------------------------------------
398//--------------------------------------------------------------------------------
399#define ML_ITK_FLAT_KERNEL_WRAPPER_0_3D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
400 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
401 ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_0, \
402 ML_IMPLEMENT_ALL_ITK_3D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
403
404//--------------------------------------------------------------------------------
407//--------------------------------------------------------------------------------
408#define ML_ITK_FLAT_KERNEL_WRAPPER_0_6D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
409 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
410 ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_0, \
411 ML_IMPLEMENT_ALL_ITK_6D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
412
413
414//--------------------------------------------------------------------------------
418//--------------------------------------------------------------------------------
419#define ML_ITK_FLAT_KERNEL_WRAPPER_1_2D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
420 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
421 ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_1, \
422 ML_IMPLEMENT_ALL_ITK_2D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
423
424//--------------------------------------------------------------------------------
428//--------------------------------------------------------------------------------
429#define ML_ITK_FLAT_KERNEL_WRAPPER_1_3D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
430 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
431 ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_1, \
432 ML_IMPLEMENT_ALL_ITK_3D_CASES, _ML_ITK_DETERMINE_OUT_REGION_N)
433
434//--------------------------------------------------------------------------------
437//--------------------------------------------------------------------------------
438#define ML_ITK_FLAT_KERNEL_WRAPPER_1_6D(PROJECT_PREFIX, CLASS_NAME, NAMESPACE) \
439 _ML_ITK_WRAPPER(PROJECT_PREFIX, CLASS_NAME, NAMESPACE, _ML_ITK_DETERMINE_IN_REGION_N, \
440 ML_ITK_FLAT_KERNEL_WRAPPER_TYPEDEFS_1, \
441 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.
Self & operator=(const Self &other)
Assignment operator. Only superclass stuff is done.
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.
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.
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.
Self & operator=(const Self &other)
Assignment operator. Only superclass stuff is done.
AllocatorType::const_iterator ConstIterator
MLITKStructuringElement()
Default constructor.
Superclass::SizeValueType SizeValueType
Neighborhood< TPixel, VDimension, TAllocator > NeighbourHoodClass
Used neighborhood.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
Include dll-specific settings.