MeVisLab Toolbox Reference
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 
27 ML_START_NAMESPACE
28 
29 
31 #define ML_DEBUG_ENV_NAME "ML_KERNELLINEAPPLICATOR"
32 
33  //---------------------------------------------------------------------------------------------
65  //---------------------------------------------------------------------------------------------
66  template <typename DATATYPE, typename KDATATYPE>
67  class MLKERNELEXPORT KernelLineApplicator : public KernelLineApplicatorBase<DATATYPE, KDATATYPE> {
68 
69  //-------------------------------------------------------------------------------------------
70  //----------------------- CONSTRUCTORS AND DESTRUCTOR ---------------------------------------
71  //-------------------------------------------------------------------------------------------
72 
73 public:
74  //--------------------------------------------------------------------------------------------------------
100  //--------------------------------------------------------------------------------------------------------
101  enum ApplyMode {
102  APPLY_COPY = 0,
108 
109  NUM_APPLY_MODES
110  };
111 
112  //-------------------------------------------------------------------------------------------
114  //-------------------------------------------------------------------------------------------
115  static const char* const ApplyModeNames[];
116 
117  //-------------------------------------------------------------------------------------------
120  //-------------------------------------------------------------------------------------------
122  {
123  _init();
124  }
125 
126  //-------------------------------------------------------------------------------------------
128  //-------------------------------------------------------------------------------------------
130  KernelLineApplicatorBase<DATATYPE, KDATATYPE>(kernLineApp)
131  {
132  _init();
133  *this=kernLineApp;
134  }
135 
136  //-------------------------------------------------------------------------------------------
141  //-------------------------------------------------------------------------------------------
143  ApplyMode applyMode,
144  MLdouble iIntMin=-DBL_MIN, MLdouble iIntMax=DBL_MAX,
145  MLdouble kIntMin=-DBL_MIN, MLdouble kIntMax=DBL_MAX) :
146  KernelLineApplicatorBase<DATATYPE, KDATATYPE>(kernel)
147  {
148  // Initialize this instance.
149  _init();
150 
151  // Specify the kernel.
152  setKernel(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  //-------------------------------------------------------------------------------------------
166  {
168  }
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) { _applyMode = mode; }
199  inline ApplyMode getApplyMode() const { return _applyMode; }
201 
202 
203  //-------------------------------------------------------------------------------------------
206  //-------------------------------------------------------------------------------------------
207  inline DATATYPE getImageIntervalMin() const { return _origIMinDT; }
208  inline DATATYPE getImageIntervalMax() const { return _origIMaxDT; }
209  inline DATATYPE getKernelIntervalMin() const { return _kernIMinDT; }
210  inline DATATYPE getKernelIntervalMax() const { return _kernIMaxDT; }
212 
213  //-------------------------------------------------------------------------------------------
218  //-------------------------------------------------------------------------------------------
219  void setImageInterval(MLdouble min=-DBL_MAX, MLdouble max=DBL_MAX)
220  {
221  // Store MLdouble and casted values to DATATYPE. So we don't need to cast so much later.
222  _origIMin = min;
223  _origIMax = max;
224  _origIMinDT = static_cast<DATATYPE>(min);
225  _origIMaxDT = static_cast<DATATYPE>(max);
226  _normOrigI = _origIMin <= _origIMax;
227  }
228 
229  //-------------------------------------------------------------------------------------------
235  //-------------------------------------------------------------------------------------------
236  void setKernelInterval(MLdouble min=-DBL_MAX, MLdouble max=DBL_MAX)
237  {
238  // Store MLdouble and casted values to DATATYPE. So we don't need to cast so much later.
239  _kernIMin = min;
240  _kernIMax = max;
241  _kernIMinDT = static_cast<DATATYPE>(min);
242  _kernIMaxDT = static_cast<DATATYPE>(max);
243  _normKernI = _kernIMin <= _kernIMax;
244  }
245 
246  //-------------------------------------------------------------------------------------------
251  //-------------------------------------------------------------------------------------------
252  bool isInImageInterval(DATATYPE v) const
253  {
254  // Look whether v is in current interval. Normally v is implicitly converted to
255  // _origMin/_origMax type for comparison, i.e. 3 <= 3.5 results to false.
256  // For user defined data types, however,
257  // we want to use the user defined comparison. So we must look for the data type and
258  // use different casts.
260 
261  // Use MLdouble for comparison
262  (( _normOrigI && ((static_cast<MLdouble>(v) >=_origIMin) && (static_cast<MLdouble>(v) <= _origIMax))) ||
263  (!_normOrigI && ((static_cast<MLdouble>(v) < _origIMax) || (static_cast<MLdouble>(v) > _origIMin))) ) :
264 
265  // Use DATATYPE for comparison.
266  (( _normOrigI && ((v >=_origIMinDT) && (v <= _origIMaxDT))) ||
267  (!_normOrigI && ((v < _origIMaxDT) || (v > _origIMinDT))) )
268  );
269  }
270 
271  //-------------------------------------------------------------------------------------------
276  //-------------------------------------------------------------------------------------------
277  bool isInKernelInterval(DATATYPE v) const
278  {
279  // See \c isInImageInterval for documentation.
281 
282  // Use MLdouble for comparison
283  (( _normKernI && ((static_cast<MLdouble>(v) >=_kernIMin) && (static_cast<MLdouble>(v) <= _kernIMax))) ||
284  (!_normKernI && ((static_cast<MLdouble>(v) < _kernIMax) || (static_cast<MLdouble>(v) > _kernIMin))) ) :
285 
286  // Use DATATYPE for comparison.
287  (( _normKernI && ((v >=_kernIMinDT) && (v <= _kernIMaxDT))) ||
288  (!_normKernI && ((v < _kernIMaxDT) || (v > _kernIMinDT))) )
289  );
290  }
291 
292 
293  //-------------------------------------------------------------------------------------------
298  //-------------------------------------------------------------------------------------------
301  size_t numVox)
302  {
303  // Update the index table for this page. It contains an offset to get from the kernel origin
304  // to any other kernel voxel. It's needed for fast access to values covered by kernel elements.
305  _defineIndices(*inSubImg);
306 
307  // Kernel empty or invalid kernel?
311  outSubImg->getCursorPos(),
312  numVox,
314  }
315  else{
316  switch (_applyMode){
317 
318  default:
319  case APPLY_COPY:
321  outSubImg->getCursorPos(),
322  numVox,
324  break;
325 
326  case APPLY_USER_FILTER:
327  applyUserFilterToLine(inSubImg, outSubImg, numVox);
328  break;
329 
330  case APPLY_NORMALLY:
332  (inSubImg->getCursorPos(), outSubImg->getCursorPos(), numVox,
336  break;
337 
338  case APPLY_IMAGE_INTERVAL_FILTER:
340  (inSubImg->getCursorPos(), outSubImg->getCursorPos(), numVox,
345  _origIMin,
346  _origIMax);
347  break;
348 
349  case APPLY_KERNEL_INTERVAL_FILTER:
351  (inSubImg->getCursorPos(), outSubImg->getCursorPos(), numVox,
356  _kernIMin,
357  _kernIMax);
358  break;
359 
360  case APPLY_IMAGE_AND_KERNEL_INTERVAL_FILTER:
362  (inSubImg->getCursorPos(), outSubImg->getCursorPos(), numVox,
367  _origIMin,
368  _origIMax,
369  _kernIMin,
370  _kernIMax);
371  break;
372  }
373  }
374  }
375 
376  //-------------------------------------------------------------------------------------------
381  //-------------------------------------------------------------------------------------------
384  long numVox) const
385  {
386  // Use convenience routine from helper class when not overloaded.
388  outSubImg->getCursorPos(),
389  numVox,
391  }
392 
393  protected:
394 
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  //-------------------------------------------------------------------------------------------
414  // Protected members.
415  //-------------------------------------------------------------------------------------------
416 
417  //-------------------------------------------------------------------------------------------
419  //-------------------------------------------------------------------------------------------
421 
422  //-------------------------------------------------------------------------------------------
423  // ---------------------- KERNEL INTERVALS AND THEIR PROPERTIES -----------------------------
424  //-------------------------------------------------------------------------------------------
429  DATATYPE _origIMinDT;
430  DATATYPE _origIMaxDT;
432 
435 
436 
437 
442  DATATYPE _kernIMinDT;
443  DATATYPE _kernIMaxDT;
445 
448  };
449 
450 //-------------------------------------------------------------------
452 //-------------------------------------------------------------------
453 template <typename DATATYPE, typename KDATATYPE> const char * const
455  "ApplyCopy",
456  "ApplyNormally",
457  "ApplyUserFilter",
458  "ApplyImageIntervalFilter",
459  "ApplyKernelIntervalFilter",
460  "ApplyImageAndKernelInterval"
461  };
462 
463 
464 
465 // Forget ML_DEBUG_ENV_NAME, because it probably will be used by other operators, too.
466 #undef ML_DEBUG_ENV_NAME
467 
468 ML_END_NAMESPACE
469 
470 #endif // __mlKernelLineApplicator_H
471 
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.
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.
const KernelLineApplicator & operator=(const KernelLineApplicator &kernLineApp)
Assignment operator. Assures that dynamic and normal members are copied correctly.
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:73
A class that offers a TSubImage with a TSubImageCursor.
Definition: mlTSubImage.h:1277
DATATYPE * getCursorPos() const
Definition: mlTSubImage.h:1466
#define MLKERNELEXPORT
Includes files used in many parts of the dll, defined dll-specific macros and controls any system dep...
double MLdouble
Definition: mlTypeDefs.h:223
TypeTraits for scalar ML Datatypes.
Definition: mlTypeTraits.h:51