MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlKernelLineApplicator.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
16
17#if !defined(__mlKernelLineApplicator_H)
18#define __mlKernelLineApplicator_H
19
20// ML-includes
21#include "mlInitSystemKernel.h"
22#include "mlKernel.h"
23#include "mlLineApplicator.h"
24#include "mlKernelTools.h"
26
28
29
31#define ML_DEBUG_ENV_NAME "ML_KERNELLINEAPPLICATOR"
32
33//---------------------------------------------------------------------------------------------
65//---------------------------------------------------------------------------------------------
66template <typename DATATYPE, typename KDATATYPE> class MLKERNELEXPORT KernelLineApplicator
67 : public KernelLineApplicatorBase<DATATYPE, KDATATYPE>
68{
69
70 //-------------------------------------------------------------------------------------------
71 //----------------------- CONSTRUCTORS AND DESTRUCTOR ---------------------------------------
72 //-------------------------------------------------------------------------------------------
73
74public:
75 //--------------------------------------------------------------------------------------------------------
101 //--------------------------------------------------------------------------------------------------------
112
113 //-------------------------------------------------------------------------------------------
115 //-------------------------------------------------------------------------------------------
116 static const char* const ApplyModeNames[];
117
118 //-------------------------------------------------------------------------------------------
121 //-------------------------------------------------------------------------------------------
127
128 //-------------------------------------------------------------------------------------------
130 //-------------------------------------------------------------------------------------------
137
138 //-------------------------------------------------------------------------------------------
143 //-------------------------------------------------------------------------------------------
147 {
148 // Initialize this instance.
149 _init();
150
151 // Specify the kernel.
153
154 // Set the mode how the kernel is applied to the image.
155 setApplyMode(applyMode);
156
157 // Initialize image and kernel interval.
158 setImageInterval(iIntMin, iIntMax);
159 setKernelInterval(kIntMin, kIntMax);
160 }
161
162 //-------------------------------------------------------------------------------------------
164 //-------------------------------------------------------------------------------------------
169
170 //-------------------------------------------------------------------------------------------
172 //-------------------------------------------------------------------------------------------
174 {
175 // Execute superclass functionality.
177
178 // Assign only if objects differ.
179 if (this != &kernLineApp) {
180 // Copy member settings.
181 setApplyMode(kernLineApp._applyMode);
182 setImageInterval(kernLineApp._origIMin, kernLineApp._origIMax);
183 setKernelInterval(kernLineApp._kernIMin, kernLineApp._kernIMax);
184 }
185
186 return *this;
187 }
188
189
190 //-------------------------------------------------------------------------------------------
191 //------------------------- PARAMETER CONTROL -----------------------------------------------
192 //-------------------------------------------------------------------------------------------
193
194 //-------------------------------------------------------------------------------------------
197 //-------------------------------------------------------------------------------------------
198 inline void setApplyMode(ApplyMode mode)
199 {
200 _applyMode = mode;
201 }
202 inline ApplyMode getApplyMode() const
203 {
204 return _applyMode;
205 }
207
208
209 //-------------------------------------------------------------------------------------------
212 //-------------------------------------------------------------------------------------------
214 {
215 return _origIMinDT;
216 }
218 {
219 return _origIMaxDT;
220 }
222 {
223 return _kernIMinDT;
224 }
226 {
227 return _kernIMaxDT;
228 }
230
231 //-------------------------------------------------------------------------------------------
236 //-------------------------------------------------------------------------------------------
238 {
239 // Store MLdouble and cast values to DATATYPE. So we don't need to cast so much later.
240 _origIMin = min;
241 _origIMax = max;
242 _origIMinDT = static_cast<DATATYPE>(min);
243 _origIMaxDT = static_cast<DATATYPE>(max);
244 _normOrigI = _origIMin <= _origIMax;
245 }
246
247 //-------------------------------------------------------------------------------------------
253 //-------------------------------------------------------------------------------------------
255 {
256 // Store MLdouble and cast values to DATATYPE. So we don't need to cast so much later.
257 _kernIMin = min;
258 _kernIMax = max;
259 _kernIMinDT = static_cast<DATATYPE>(min);
260 _kernIMaxDT = static_cast<DATATYPE>(max);
261 _normKernI = _kernIMin <= _kernIMax;
262 }
263
264 //-------------------------------------------------------------------------------------------
269 //-------------------------------------------------------------------------------------------
271 {
272 // Look whether v is in current interval. Normally v is implicitly converted to
273 // _origMin/_origMax type for comparison, i.e. 3 <= 3.5 results to false.
274 // For user defined data types, however,
275 // we want to use the user defined comparison. So we must look for the data type and
276 // use different casts.
278
279 // Use MLdouble for comparison
280 ((_normOrigI && ((static_cast<MLdouble>(v) >= _origIMin) && (static_cast<MLdouble>(v) <= _origIMax))) ||
281 (!_normOrigI && ((static_cast<MLdouble>(v) < _origIMax) || (static_cast<MLdouble>(v) > _origIMin))))
282 :
283
284 // Use DATATYPE for comparison.
285 ((_normOrigI && ((v >= _origIMinDT) && (v <= _origIMaxDT))) ||
286 (!_normOrigI && ((v < _origIMaxDT) || (v > _origIMinDT)))));
287 }
288
289 //-------------------------------------------------------------------------------------------
294 //-------------------------------------------------------------------------------------------
296 {
297 // See \c isInImageInterval for documentation.
299
300 // Use MLdouble for comparison
301 ((_normKernI && ((static_cast<MLdouble>(v) >= _kernIMin) && (static_cast<MLdouble>(v) <= _kernIMax))) ||
302 (!_normKernI && ((static_cast<MLdouble>(v) < _kernIMax) || (static_cast<MLdouble>(v) > _kernIMin))))
303 :
304
305 // Use DATATYPE for comparison.
306 ((_normKernI && ((v >= _kernIMinDT) && (v <= _kernIMaxDT))) ||
307 (!_normKernI && ((v < _kernIMaxDT) || (v > _kernIMinDT)))));
308 }
309
310
311 //-------------------------------------------------------------------------------------------
316 //-------------------------------------------------------------------------------------------
318 {
319 // Update the index table for this page. It contains an offset to get from the kernel origin
320 // to any other kernel voxel. It's needed for fast access to values covered by kernel elements.
322
323 // Kernel empty or invalid kernel?
326 {
327 KernelTools::copyLine(inSubImg->getCursorPos(), outSubImg->getCursorPos(), numVox,
329 }
330 else {
331 switch (_applyMode) {
332
333 default:
334 case APPLY_COPY:
335 KernelTools::copyLine(inSubImg->getCursorPos(), outSubImg->getCursorPos(), numVox,
337 break;
338
339 case APPLY_USER_FILTER:
340 applyUserFilterToLine(inSubImg, outSubImg, numVox);
341 break;
342
343 case APPLY_NORMALLY:
344 KernelTools::correlateLine(inSubImg->getCursorPos(), outSubImg->getCursorPos(), numVox,
348 break;
349
350 case APPLY_IMAGE_INTERVAL_FILTER:
352 inSubImg->getCursorPos(), outSubImg->getCursorPos(), numVox,
357 break;
358
359 case APPLY_KERNEL_INTERVAL_FILTER:
361 inSubImg->getCursorPos(), outSubImg->getCursorPos(), numVox,
366 break;
367
368 case APPLY_IMAGE_AND_KERNEL_INTERVAL_FILTER:
370 inSubImg->getCursorPos(), outSubImg->getCursorPos(), numVox,
374 KernelLineApplicatorBase<DATATYPE, KDATATYPE>::_srcVoxOffset, _origIMin, _origIMax, _kernIMin, _kernIMax);
375 break;
376 }
377 }
378 }
379
380 //-------------------------------------------------------------------------------------------
385 //-------------------------------------------------------------------------------------------
387 long numVox) const
388 {
389 // Use convenience routine from helper class when not overloaded.
390 KernelTools::copyLine(inSubImg->getCursorPos(), outSubImg->getCursorPos(), numVox,
392 }
393
394protected:
395 //-------------------------------------------------------------------------------------------
397 //-------------------------------------------------------------------------------------------
398 void _init()
399 {
400 // Execute superclass functionality.
402
403 // mode how the kernel is applied to the image.
404 _applyMode = APPLY_NORMALLY;
405
406 // Intervals to exclude input image voxels from filtering or from usage in kernels.
407 setImageInterval(-DBL_MAX, DBL_MAX);
408 setKernelInterval(-DBL_MAX, DBL_MAX);
409 }
410
411
412 //-------------------------------------------------------------------------------------------
413 // Protected members.
414 //-------------------------------------------------------------------------------------------
415
416 //-------------------------------------------------------------------------------------------
418 //-------------------------------------------------------------------------------------------
420
421 //-------------------------------------------------------------------------------------------
422 // ---------------------- KERNEL INTERVALS AND THEIR PROPERTIES -----------------------------
423 //-------------------------------------------------------------------------------------------
431
434
435
443
446};
447
448//-------------------------------------------------------------------
450//-------------------------------------------------------------------
451template <typename DATATYPE, typename KDATATYPE>
452const char* const KernelLineApplicator<DATATYPE, KDATATYPE>::ApplyModeNames[] = {"ApplyCopy",
453 "ApplyNormally",
454 "ApplyUserFilter",
455 "ApplyImageIntervalFilter",
456 "ApplyKernelIntervalFilter",
457 "ApplyImageAndKernelInterval"};
458
459
460// Forget ML_DEBUG_ENV_NAME, because it probably will be used by other operators, too.
461#undef ML_DEBUG_ENV_NAME
462
464
465#endif // __mlKernelLineApplicator_H
The KernelLineApplicatorBase class is designed to implement new kernel based filters to be applied to...
const KernelLineApplicatorBase< DATATYPE, KDATATYPE > & operator=(const KernelLineApplicatorBase< DATATYPE, KDATATYPE > &kernLineAppBase)
Assignment operator. Assures that dynamic and normal members are copied correctly.
virtual void _clearIndices()
Removes the current _indexTab.
void _init()
Initialization the current instance of mlKernelApplicatorBase. To be called by constructors.
virtual void _defineIndices(const SubImage &inSubImg)
Create the table of offsets from the voxel (0,0,0,0,0,0) of the kernel to any other voxel of the kern...
void setKernel(const TKernel< KDATATYPE > &kernel)
The KernelLineApplicator class takes a Kernel instance and filters one line of an mlSubImage and writ...
ApplyMode
The ApplyModes decide about the way how the kernel is used to filter the input image and which parts ...
ApplyMode _applyMode
The mode how the kernel is applied to the image.
KernelLineApplicator()
Default constructor.
KernelLineApplicator(const TKernel< KDATATYPE > &kernel, ApplyMode applyMode, MLdouble iIntMin=-DBL_MIN, MLdouble iIntMax=DBL_MAX, MLdouble kIntMin=-DBL_MIN, MLdouble kIntMax=DBL_MAX)
Convenience constructor to create a complete line applicator with all important parameters set.
void setApplyMode(ApplyMode mode)
bool _normOrigI
_normOrigI==true indicates that the interval is used exclusively.
void applyToLine(TSubImageWithCursor< DATATYPE > *inSubImg, TSubImageWithCursor< DATATYPE > *outSubImg, size_t numVox)
Selects the correct line filter mode and filters a row with the currently specified kernel.
void setImageInterval(MLdouble min=-DBL_MAX, MLdouble max=DBL_MAX)
Correlations can be applied to a subset of voxels by setting a threshold interval which includes the ...
bool isInImageInterval(DATATYPE v) const
Test whether the value v is within image interval.
const KernelLineApplicator & operator=(const KernelLineApplicator &kernLineApp)
Assignment operator. Assures that dynamic and normal members are copied correctly.
bool isInKernelInterval(DATATYPE v) const
Test whether the value v is within kernel interval.
virtual void applyUserFilterToLine(TSubImageWithCursor< DATATYPE > *inSubImg, TSubImageWithCursor< DATATYPE > *outSubImg, long numVox) const
Filter a row with the current kernel with a user defined algorithm.
void _init()
Initialization the current instance of mlKernelApplicator. To be called by constructors.
KernelLineApplicator(const KernelLineApplicator &kernLineApp)
Copy constructor.
bool _normKernI
_normKernI==true indicates that the interval is used exclusively.
void setKernelInterval(MLdouble min=-DBL_MAX, MLdouble max=DBL_MAX)
When filtering an image then voxels covered by the kernel elements outside a certain grey level inter...
virtual ~KernelLineApplicator()
Destructor. Frees dynamic members.
static void correlateLine(const IN_DATATYPE *inCursor, OUT_DATATYPE *outCursor, size_t numVox, const K_DATATYPE *valTab, const MLsoffset *indexTab, size_t indexTabSize)
See MLKernelToolsCorrelateLine.
static void correlateLineWithKernelInterval(const IN_DATATYPE *inCursor, OUT_DATATYPE *outCursor, size_t numVox, const K_DATATYPE *valTab, const MLsoffset *indexTab, size_t indexTabSize, MLsoffset srcVoxelOffset, MLdouble minVal, MLdouble maxVal)
See MLKernelToolsCorrelateLineWithKernelInterval.
static void correlateLineWithImageInterval(const IN_DATATYPE *inCursor, OUT_DATATYPE *outCursor, size_t numVox, const K_DATATYPE *valTab, const MLsoffset *indexTab, size_t indexTabSize, MLsoffset srcVoxelOffset, MLdouble minVal, MLdouble maxVal)
See MLKernelToolsCorrelateLineWithImageInterval.
static void correlateLineWithImageAndKernelInterval(const IN_DATATYPE *inCursor, OUT_DATATYPE *outCursor, size_t numVox, const K_DATATYPE *valTab, const MLsoffset *indexTab, size_t indexTabSize, MLsoffset srcVoxelOffset, MLdouble imgIntMinVal, MLdouble imgIntMaxVal, MLdouble kernIntMinVal, MLdouble kernIntMaxVal)
See MLKernelToolsCorrelateLineWithImageAndKernelInterval.
static void copyLine(const IN_DATATYPE *inCursor, OUT_DATATYPE *outCursor, size_t numVox, MLsoffset srcVoxelOffset)
Wrapping of functions globally available in ML_NAMESPACE for backward compatibility.
Class to manage a filtering kernel for images.
Definition mlKernel.h:74
A class that offers a TSubImage with a TSubImageCursor.
#define MLKERNELEXPORT
Includes files used in many parts of the dll, defined dll-specific macros and controls any system dep...
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
double MLdouble
Definition mlTypeDefs.h:217
TypeTraits for scalar ML datatypes.