MeVisLab Toolbox Reference
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 
25 ML_START_NAMESPACE
26 
27 
29 #define ML_DEBUG_ENV_NAME "ML_KERNELLINEAPPLICATORBASE"
30 
31  //---------------------------------------------------------------------------------------------
61  //---------------------------------------------------------------------------------------------
62  template <typename DATATYPE, typename KDATATYPE>
63  class KernelLineApplicatorBase : public LineApplicator<DATATYPE> {
64 
65  //-------------------------------------------------------------------------------------------
66  //----------------------- CONSTRUCTORS AND DESTRUCTOR ---------------------------------------
67  //-------------------------------------------------------------------------------------------
68 
69 public:
70  //-------------------------------------------------------------------------------------------
73  //-------------------------------------------------------------------------------------------
75 
76  //-------------------------------------------------------------------------------------------
78  //-------------------------------------------------------------------------------------------
80 
81  //-------------------------------------------------------------------------------------------
84  //-------------------------------------------------------------------------------------------
86 
87  //-------------------------------------------------------------------------------------------
89  //-------------------------------------------------------------------------------------------
90  ~KernelLineApplicatorBase() override{ _clearIndices(); }
91 
92  //-------------------------------------------------------------------------------------------
94  //-------------------------------------------------------------------------------------------
96 
97  //-------------------------------------------------------------------------------------------
100  //-------------------------------------------------------------------------------------------
101  ImageVector getNegativeExtent() const override { return _kernel ? _kernel->getNegativeExtent() : ImageVector(0); }
102  ImageVector getPositiveExtent() const override { return _kernel ? _kernel->getPositiveExtent() : ImageVector(0); }
104 
105 
106  //-------------------------------------------------------------------------------------------
109  //-------------------------------------------------------------------------------------------
110  inline void setKernel(const TKernel<KDATATYPE> &kernel) { _kernel = &kernel; }
111  inline const TKernel<KDATATYPE> &getKernel() const { return *_kernel; }
113 
114  //-------------------------------------------------------------------------------------------
119  //-------------------------------------------------------------------------------------------
121  TSubImageWithCursor<DATATYPE> * /*outSubImg*/,
122  size_t /*numVox*/) override { _defineIndices(*inSubImg); };
123 
124  protected:
125 
126  //-------------------------------------------------------------------------------------------
128  //-------------------------------------------------------------------------------------------
129  void _init();
130 
131 
132  //-------------------------------------------------------------------------------------------
133  // --------------------- CREATE/CLEAR OF THE KERNEL INDEX TABLE -----------------------------
134  //-------------------------------------------------------------------------------------------
135 
136  //-------------------------------------------------------------------------------------------
141  //-------------------------------------------------------------------------------------------
142  virtual void _defineIndices(const SubImage &inSubImg);
143 
144  //-------------------------------------------------------------------------------------------
146  //-------------------------------------------------------------------------------------------
147  virtual void _clearIndices();
148 
149 
150  //-------------------------------------------------------------------------------------------
151  // --------------------- Protected members.--------------------------------------------------
152  //-------------------------------------------------------------------------------------------
153 
154  //-------------------------------------------------------------------------------------------
156  //-------------------------------------------------------------------------------------------
158 
159  //-------------------------------------------------------------------------------------------
162  //-------------------------------------------------------------------------------------------
168 
171 
176  };
177 
178 
179 
180 
181 
182 
183 
184 
185  //-------------------------------------------------------------------------------------------
186  // --------------------- IMPLEMENTATION PART ------------------------------------------------
187  //-------------------------------------------------------------------------------------------
188 
189 
190  //-------------------------------------------------------------------------------------------
192  //-------------------------------------------------------------------------------------------
193  template <typename DATATYPE, typename KDATATYPE>
195  {
196  _init();
197  *this=kernLineAppBase;
198  }
199 
200 
201  //-------------------------------------------------------------------------------------------
204  //-------------------------------------------------------------------------------------------
205  template <typename DATATYPE, typename KDATATYPE>
207  {
208  // Initialize this instance.
209  _init();
210 
211  // Specify the kernel.
212  setKernel(kernel);
213  }
214 
215  //-------------------------------------------------------------------------------------------
217  //-------------------------------------------------------------------------------------------
218  template <typename DATATYPE, typename KDATATYPE>
220  {
221  // Initialize pointer to the kernel used for filtering.
222  _kernel = nullptr;
223 
224  // Table of offsets from the voxel covered by the kernel origin to other image voxels
225  // covered by the kernel.
226  _indexTab = nullptr;
227  _indexTabSize = 0;
228  _srcVoxOffset = 0;
229  }
230 
231  //-------------------------------------------------------------------------------------------
233  //-------------------------------------------------------------------------------------------
234  template <typename DATATYPE, typename KDATATYPE>
238  {
239  // Assign only if objects differ.
240  if (this != &kernLineAppBase){
241  // Copy member settings.
242  _kernel = kernLineAppBase._kernel;
243  _srcVoxOffset = kernLineAppBase._srcVoxOffset;
244 
245  // Create new index table for filtering.
246  _clearIndices();
247  _indexTabSize = kernLineAppBase._indexTabSize;
248  _indexTab = new MLsoffset[_indexTabSize];
249  if (!_indexTab){
250  ML_PRINT_FATAL_ERROR("KernelLineApplicatorBase.h: KernelLineApplicatorBase::operator=(...):",
251  ML_NO_MEMORY, "Not enough memory. Cannot complete assignment operator correctly!");
252  }
253 
254  // Copy contents of table.
255  if (_indexTab){ memcpy(_indexTab, kernLineAppBase._indexTab, sizeof(MLsoffset)*_indexTabSize); }
256 
257  // Copy the offset from kernel origin to replaced voxel.
258  _srcVoxOffset = kernLineAppBase._srcVoxOffset;
259  }
260  return *this;
261  }
262 
263  //-------------------------------------------------------------------------------------------
268  //-------------------------------------------------------------------------------------------
269  template <typename DATATYPE, typename KDATATYPE>
271  {
272  // Destroy previous index table.
273  _clearIndices();
274 
275  // Create new index table.
276  _indexTab = KernelTools::createIndexTab(inSubImg.getStride(), *_kernel);
277 
278  // Calculate the offset to the source voxel to be copied if input is copied normally to output.
279  _srcVoxOffset = KernelTools::calcSrcVoxelOffset(inSubImg.getStride(), _kernel->getNegativeExtent());
280 
281  // Store the number of elements _indexTabSize.
282  _indexTabSize = _kernel->getTabSize();
283 
284  }
285 
286  //-------------------------------------------------------------------------------------------
288  //-------------------------------------------------------------------------------------------
289  template <typename DATATYPE, typename KDATATYPE>
291  {
292  // Compute offset index from voxel in output image to voxel in input image which can be
293  // returned as original voxel, e.g. if filter operation fails or if it does nothing.
294  _srcVoxOffset = 0;
295 
296  // Remove previous indexTab.
297  if (_indexTab){
298  delete []_indexTab;
299  _indexTab = nullptr;
300  _indexTabSize = 0;
301  }
302  }
303 
304 
305 // Forget ML_DEBUG_ENV_NAME, because it probably will be used by other operators, too.
306 #undef ML_DEBUG_ENV_NAME
307 
308 ML_END_NAMESPACE
309 
310 #endif // __mlKernelLineApplicatorBase_H
311 
312 
The KernelLineApplicatorBase class is designed to implement new kernel based filters to be applied to...
const TKernel< KDATATYPE > & getKernel() const
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)
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 which is organized linearly in memory.
Definition: mlSubImage.h:75
ImageVector getStride() const
Returns a stride vector to address the memory efficiently.
Definition: mlSubImage.h:264
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
#define ML_NO_MEMORY
The system does not have enough memory to perform the desired operation; try to reduce application da...
Definition: mlTypeDefs.h:837
#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...
MLint MLsoffset
Signed ML offset type which is a 32 bit signed integer on 32 bit platforms and a 64 bit integer on 64...
Definition: mlTypeDefs.h:650
TImageVector< MLint > ImageVector
Defines the standard ImageVector type which is used by the ML for indexing and coordinates.