MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlKernelLineApplicatorBase.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
15
16#if !defined(__mlKernelLineApplicatorBase_H)
17#define __mlKernelLineApplicatorBase_H
18
19// ML-includes
20#include "mlInitSystemKernel.h"
21#include "mlKernel.h"
22#include "mlLineApplicator.h"
23#include "mlKernelTools.h"
24
26
27
29#define ML_DEBUG_ENV_NAME "ML_KERNELLINEAPPLICATORBASE"
30
31//---------------------------------------------------------------------------------------------
61//---------------------------------------------------------------------------------------------
62template <typename DATATYPE, typename KDATATYPE> class KernelLineApplicatorBase : public LineApplicator<DATATYPE>
63{
64
65 //-------------------------------------------------------------------------------------------
66 //----------------------- CONSTRUCTORS AND DESTRUCTOR ---------------------------------------
67 //-------------------------------------------------------------------------------------------
68
69public:
70 //-------------------------------------------------------------------------------------------
73 //-------------------------------------------------------------------------------------------
75 {
76 _init();
77 }
78
79 //-------------------------------------------------------------------------------------------
81 //-------------------------------------------------------------------------------------------
83
84 //-------------------------------------------------------------------------------------------
87 //-------------------------------------------------------------------------------------------
89
90 //-------------------------------------------------------------------------------------------
92 //-------------------------------------------------------------------------------------------
94 {
95 _clearIndices();
96 }
97
98 //-------------------------------------------------------------------------------------------
100 //-------------------------------------------------------------------------------------------
103
104 //-------------------------------------------------------------------------------------------
107 //-------------------------------------------------------------------------------------------
109 {
110 return _kernel ? _kernel->getNegativeExtent() : ImageVector(0);
111 }
113 {
114 return _kernel ? _kernel->getPositiveExtent() : ImageVector(0);
115 }
117
118
119 //-------------------------------------------------------------------------------------------
122 //-------------------------------------------------------------------------------------------
124 {
125 _kernel = &kernel;
126 }
127 inline const TKernel<KDATATYPE>& getKernel() const
128 {
129 return *_kernel;
130 }
132
133 //-------------------------------------------------------------------------------------------
138 //-------------------------------------------------------------------------------------------
140 size_t /*numVox*/) override
141 {
142 _defineIndices(*inSubImg);
143 };
144
145protected:
146 //-------------------------------------------------------------------------------------------
148 //-------------------------------------------------------------------------------------------
149 void _init();
150
151
152 //-------------------------------------------------------------------------------------------
153 // --------------------- CREATE/CLEAR OF THE KERNEL INDEX TABLE -----------------------------
154 //-------------------------------------------------------------------------------------------
155
156 //-------------------------------------------------------------------------------------------
161 //-------------------------------------------------------------------------------------------
162 virtual void _defineIndices(const SubImage& inSubImg);
163
164 //-------------------------------------------------------------------------------------------
166 //-------------------------------------------------------------------------------------------
167 virtual void _clearIndices();
168
169
170 //-------------------------------------------------------------------------------------------
171 // --------------------- Protected members.--------------------------------------------------
172 //-------------------------------------------------------------------------------------------
173
174 //-------------------------------------------------------------------------------------------
176 //-------------------------------------------------------------------------------------------
178
179 //-------------------------------------------------------------------------------------------
182 //-------------------------------------------------------------------------------------------
188
191
196};
197
198
199//-------------------------------------------------------------------------------------------
200// --------------------- IMPLEMENTATION PART ------------------------------------------------
201//-------------------------------------------------------------------------------------------
202
203
204//-------------------------------------------------------------------------------------------
206//-------------------------------------------------------------------------------------------
207template <typename DATATYPE, typename KDATATYPE>
214
215
216//-------------------------------------------------------------------------------------------
219//-------------------------------------------------------------------------------------------
220template <typename DATATYPE, typename KDATATYPE>
222{
223 // Initialize this instance.
224 _init();
225
226 // Specify the kernel.
227 setKernel(kernel);
228}
229
230//-------------------------------------------------------------------------------------------
232//-------------------------------------------------------------------------------------------
233template <typename DATATYPE, typename KDATATYPE> void KernelLineApplicatorBase<DATATYPE, KDATATYPE>::_init()
234{
235 // Initialize pointer to the kernel used for filtering.
236 _kernel = nullptr;
237
238 // Table of offsets from the voxel covered by the kernel origin to other image voxels
239 // covered by the kernel.
240 _indexTab = nullptr;
241 _indexTabSize = 0;
242 _srcVoxOffset = 0;
243}
244
245//-------------------------------------------------------------------------------------------
247//-------------------------------------------------------------------------------------------
248template <typename DATATYPE, typename KDATATYPE>
251{
252 // Assign only if objects differ.
253 if (this != &kernLineAppBase) {
254 // Copy member settings.
255 _kernel = kernLineAppBase._kernel;
256 _srcVoxOffset = kernLineAppBase._srcVoxOffset;
257
258 // Create new index table for filtering.
259 _clearIndices();
260 _indexTabSize = kernLineAppBase._indexTabSize;
261 _indexTab = new MLsoffset[_indexTabSize];
262 if (!_indexTab) {
263 ML_PRINT_FATAL_ERROR("KernelLineApplicatorBase.h: KernelLineApplicatorBase::operator=(...):", ML_NO_MEMORY,
264 "Not enough memory. Cannot complete assignment operator correctly!");
265 }
266
267 // Copy contents of table.
268 if (_indexTab) {
269 memcpy(_indexTab, kernLineAppBase._indexTab, sizeof(MLsoffset) * _indexTabSize);
270 }
271
272 // Copy the offset from kernel origin to replaced voxel.
273 _srcVoxOffset = kernLineAppBase._srcVoxOffset;
274 }
275 return *this;
276}
277
278//-------------------------------------------------------------------------------------------
283//-------------------------------------------------------------------------------------------
284template <typename DATATYPE, typename KDATATYPE>
286{
287 // Destroy previous index table.
288 _clearIndices();
289
290 // Create new index table.
291 _indexTab = KernelTools::createIndexTab(inSubImg.getStride(), *_kernel);
292
293 // Calculate the offset to the source voxel to be copied if input is copied normally to output.
294 _srcVoxOffset = KernelTools::calcSrcVoxelOffset(inSubImg.getStride(), _kernel->getNegativeExtent());
295
296 // Store the number of elements _indexTabSize.
297 _indexTabSize = _kernel->getTabSize();
298}
299
300//-------------------------------------------------------------------------------------------
302//-------------------------------------------------------------------------------------------
303template <typename DATATYPE, typename KDATATYPE> void KernelLineApplicatorBase<DATATYPE, KDATATYPE>::_clearIndices()
304{
305 // Compute offset index from voxel in output image to voxel in input image which can be
306 // returned as original voxel, e.g. if filter operation fails or if it does nothing.
307 _srcVoxOffset = 0;
308
309 // Remove previous indexTab.
310 if (_indexTab) {
311 delete[] _indexTab;
312 _indexTab = nullptr;
313 _indexTabSize = 0;
314 }
315}
316
317
318// Forget ML_DEBUG_ENV_NAME, because it probably will be used by other operators, too.
319#undef ML_DEBUG_ENV_NAME
320
322
323#endif // __mlKernelLineApplicatorBase_H
The KernelLineApplicatorBase class is designed to implement new kernel based filters to be applied to...
void applyToLine(TSubImageWithCursor< DATATYPE > *inSubImg, TSubImageWithCursor< DATATYPE > *, size_t) override
Applies the kernel to a row of the input subimage.
~KernelLineApplicatorBase() override
Destructor. Frees dynamic members.
ImageVector getNegativeExtent() const override
Returns the negative extent of a kernel used for filtering.
KernelLineApplicatorBase()
Default constructor.
MLsoffset _srcVoxOffset
Offset from origin of kernel in input image to the voxel under the replaced voxel in output image.
size_t _indexTabSize
Size of _indexTab. Default is 0.
const TKernel< KDATATYPE > * _kernel
Pointer to the kernel used to filter an input page.
ImageVector getPositiveExtent() const override
Returns the positive extent of a kernel used for filtering.
void setKernel(const TKernel< KDATATYPE > &kernel)
const TKernel< KDATATYPE > & getKernel() const
MLsoffset * _indexTab
Table and variables defined temporarily while filtering a page.
The LineApplicator class provides pure virtual functions used by the old applyFiltering functions fro...
This class manages/represents a rectangular 6D image region that is organized linearly in memory.
Definition mlSubImage.h:75
Class to manage a filtering kernel for images.
Definition mlKernel.h:74
A class that offers a TSubImage with a TSubImageCursor.
#define ML_NO_MEMORY
The system does not have enough memory to perform the desired operation; try to reduce application da...
Definition mlTypeDefs.h:791
#define ML_PRINT_FATAL_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_FATAL_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be du...
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
MLint MLsoffset
Signed ML offset type that is a 32-bit signed integer on 32-bit platforms and a 64-bit integer on 64-...
Definition mlTypeDefs.h:559