MeVisLabToolboxReference
|
00001 // **InsertLicense** code 00002 //------------------------------------------------------------------------- 00004 00009 //------------------------------------------------------------------------- 00010 // Prevent multiple including of this file. 00011 #if !defined(__mlKernelLineApplicatorBase_H) 00012 #define __mlKernelLineApplicatorBase_H 00013 00014 // ML-includes 00015 #ifndef __mlInitSystemKernel_H 00016 #include "mlInitSystemKernel.h" 00017 #endif 00018 #ifndef __mlKernel_H 00019 #include "mlKernel.h" 00020 #endif 00021 #ifndef __mlLineApplicator_H 00022 #include "mlLineApplicator.h" 00023 #endif 00024 #ifndef __mlKernelTools_H 00025 #include "mlKernelTools.h" 00026 #endif 00027 00028 ML_START_NAMESPACE 00029 00030 00032 #define ML_DEBUG_ENV_NAME "ML_KERNELLINEAPPLICATORBASE" 00033 00034 //--------------------------------------------------------------------------------------------- 00064 //--------------------------------------------------------------------------------------------- 00065 template <typename DATATYPE, typename KDATATYPE> 00066 class KernelLineApplicatorBase : public LineApplicator<DATATYPE> { 00067 00068 //------------------------------------------------------------------------------------------- 00069 //----------------------- CONSTRUCTORS AND DESTRUCTOR --------------------------------------- 00070 //------------------------------------------------------------------------------------------- 00071 00072 public: 00073 //------------------------------------------------------------------------------------------- 00076 //------------------------------------------------------------------------------------------- 00077 KernelLineApplicatorBase(){ _init(); } 00078 00079 //------------------------------------------------------------------------------------------- 00081 //------------------------------------------------------------------------------------------- 00082 KernelLineApplicatorBase(const KernelLineApplicatorBase<DATATYPE, KDATATYPE> &kernLineAppBase); 00083 00084 //------------------------------------------------------------------------------------------- 00087 //------------------------------------------------------------------------------------------- 00088 KernelLineApplicatorBase(const TKernel<KDATATYPE> &kernel); 00089 00090 //------------------------------------------------------------------------------------------- 00092 //------------------------------------------------------------------------------------------- 00093 virtual ~KernelLineApplicatorBase(){ _clearIndices(); } 00094 00095 //------------------------------------------------------------------------------------------- 00097 //------------------------------------------------------------------------------------------- 00098 const KernelLineApplicatorBase<DATATYPE, KDATATYPE> &operator=(const KernelLineApplicatorBase<DATATYPE, KDATATYPE> &kernLineAppBase); 00099 00100 //------------------------------------------------------------------------------------------- 00102 00103 //------------------------------------------------------------------------------------------- 00104 virtual ImageVector getNegativeExtent() const { return _kernel ? _kernel->getNegativeExtent() : ImageVector(0); } 00105 virtual ImageVector getPositiveExtent() const { return _kernel ? _kernel->getPositiveExtent() : ImageVector(0); } 00107 00108 00109 //------------------------------------------------------------------------------------------- 00111 00112 //------------------------------------------------------------------------------------------- 00113 inline void setKernel(const TKernel<KDATATYPE> &kernel) { _kernel = &kernel; } 00114 inline const TKernel<KDATATYPE> &getKernel() const { return *_kernel; } 00116 00117 //------------------------------------------------------------------------------------------- 00122 //------------------------------------------------------------------------------------------- 00123 virtual void applyToLine(TSubImageWithCursor<DATATYPE> *inSubImg, 00124 TSubImageWithCursor<DATATYPE> * /*outSubImg*/, 00125 size_t /*numVox*/) { _defineIndices(*inSubImg); }; 00126 00127 protected: 00128 00129 //------------------------------------------------------------------------------------------- 00131 //------------------------------------------------------------------------------------------- 00132 void _init(); 00133 00134 00135 //------------------------------------------------------------------------------------------- 00136 // --------------------- CREATE/CLEAR OF THE KERNEL INDEX TABLE ----------------------------- 00137 //------------------------------------------------------------------------------------------- 00138 00139 //------------------------------------------------------------------------------------------- 00144 //------------------------------------------------------------------------------------------- 00145 virtual void _defineIndices(const SubImage &inSubImg); 00146 00147 //------------------------------------------------------------------------------------------- 00149 //------------------------------------------------------------------------------------------- 00150 virtual void _clearIndices(); 00151 00152 00153 //------------------------------------------------------------------------------------------- 00154 // --------------------- Protected members.-------------------------------------------------- 00155 //------------------------------------------------------------------------------------------- 00156 00157 //------------------------------------------------------------------------------------------- 00159 //------------------------------------------------------------------------------------------- 00160 const TKernel<KDATATYPE> *_kernel; 00161 00162 //------------------------------------------------------------------------------------------- 00164 00165 //------------------------------------------------------------------------------------------- 00170 MLsoffset *_indexTab; 00171 00173 size_t _indexTabSize; 00174 00177 MLsoffset _srcVoxOffset; 00179 }; 00180 00181 00182 00183 00184 00185 00186 00187 00188 //------------------------------------------------------------------------------------------- 00189 // --------------------- IMPLEMENTATION PART ------------------------------------------------ 00190 //------------------------------------------------------------------------------------------- 00191 00192 00193 //------------------------------------------------------------------------------------------- 00195 //------------------------------------------------------------------------------------------- 00196 template <typename DATATYPE, typename KDATATYPE> 00197 KernelLineApplicatorBase<DATATYPE, KDATATYPE>::KernelLineApplicatorBase(const KernelLineApplicatorBase<DATATYPE, KDATATYPE> &kernLineAppBase) 00198 { 00199 _init(); 00200 *this=kernLineAppBase; 00201 } 00202 00203 00204 //------------------------------------------------------------------------------------------- 00207 //------------------------------------------------------------------------------------------- 00208 template <typename DATATYPE, typename KDATATYPE> 00209 KernelLineApplicatorBase<DATATYPE, KDATATYPE>::KernelLineApplicatorBase(const TKernel<KDATATYPE> &kernel) 00210 { 00211 //mlDebugPrint("Entering constructor..."); 00212 00213 // Initialize this instance. 00214 _init(); 00215 00216 // Specify the kernel. 00217 setKernel(kernel); 00218 00219 //mlDebugPrint("Leaving constructor."); 00220 } 00221 00222 //------------------------------------------------------------------------------------------- 00224 //------------------------------------------------------------------------------------------- 00225 template <typename DATATYPE, typename KDATATYPE> 00226 void KernelLineApplicatorBase<DATATYPE, KDATATYPE>::_init() 00227 { 00228 // Initialize pointer to the kernel used for filtering. 00229 _kernel = NULL; 00230 00231 // Table of offsets from the voxel covered by the kernel origin to other image voxels 00232 // covered by the kernel. 00233 _indexTab = NULL; 00234 _indexTabSize = 0; 00235 _srcVoxOffset = 0; 00236 } 00237 00238 //------------------------------------------------------------------------------------------- 00240 //------------------------------------------------------------------------------------------- 00241 template <typename DATATYPE, typename KDATATYPE> 00242 const KernelLineApplicatorBase<DATATYPE, KDATATYPE> 00243 &KernelLineApplicatorBase<DATATYPE, KDATATYPE>:: 00244 operator=(const KernelLineApplicatorBase<DATATYPE, KDATATYPE> &kernLineAppBase) 00245 { 00246 //mlDebugPrint("Entering operator=..."); 00247 00248 // Assign only if objects differ. 00249 if (this != &kernLineAppBase){ 00250 // Copy member settings. 00251 _kernel = kernLineAppBase._kernel; 00252 _srcVoxOffset = kernLineAppBase._srcVoxOffset; 00253 00254 // Create new index table for filtering. 00255 _clearIndices(); 00256 _indexTabSize = kernLineAppBase._indexTabSize; 00257 _indexTab = new MLsoffset[_indexTabSize]; 00258 if (!_indexTab){ 00259 ML_PRINT_FATAL_ERROR("KernelLineApplicatorBase.h: KernelLineApplicatorBase::operator=(...):", 00260 ML_NO_MEMORY, "Not enough memory. Cannot complete assignment operator correctly!"); 00261 } 00262 00263 // Copy contents of table. 00264 if (_indexTab){ memcpy(_indexTab, kernLineAppBase._indexTab, sizeof(MLsoffset)*_indexTabSize); } 00265 00266 // Copy the offset from kernel origin to replaced voxel. 00267 _srcVoxOffset = kernLineAppBase._srcVoxOffset; 00268 } 00269 00270 //mlDebugPrint("Leaving operator=."); 00271 00272 return *this; 00273 } 00274 00275 //------------------------------------------------------------------------------------------- 00280 //------------------------------------------------------------------------------------------- 00281 template <typename DATATYPE, typename KDATATYPE> 00282 void KernelLineApplicatorBase<DATATYPE, KDATATYPE>::_defineIndices(const SubImage &inSubImg) 00283 { 00284 // Destroy previous index table. 00285 _clearIndices(); 00286 00287 // Create new index table. 00288 _indexTab = KernelTools::createIndexTab(inSubImg.getStride(), *_kernel); 00289 00290 // Calculate the offset to the source voxel to be copied if input is copied normally to output. 00291 _srcVoxOffset = KernelTools::calcSrcVoxelOffset(inSubImg.getStride(), _kernel->getNegativeExtent()); 00292 00293 // Store the number of elements _indexTabSize. 00294 _indexTabSize = _kernel->getTabSize(); 00295 00296 } 00297 00298 //------------------------------------------------------------------------------------------- 00300 //------------------------------------------------------------------------------------------- 00301 template <typename DATATYPE, typename KDATATYPE> 00302 void KernelLineApplicatorBase<DATATYPE, KDATATYPE>::_clearIndices() 00303 { 00304 //mlDebugPrint("Entering _clearIndexTab..."); 00305 00306 // Compute offset index from voxel in output image to voxel in input image which can be 00307 // returned as original voxel, e.g. if filter operation fails or if it does nothing. 00308 _srcVoxOffset = 0; 00309 00310 // Remove previous indexTab. 00311 if (_indexTab){ 00312 delete []_indexTab; 00313 _indexTab = NULL; 00314 _indexTabSize = 0; 00315 } 00316 00317 //mlDebugPrint("Leaving _clearIndexTab."); 00318 } 00319 00320 00321 // Forget ML_DEBUG_ENV_NAME, because it probably will be used by other operators, too. 00322 #undef ML_DEBUG_ENV_NAME 00323 00324 ML_END_NAMESPACE 00325 00326 #endif // __mlKernelLineApplicatorBase_H 00327 00328