Line data Source code
1 : #include "HardThresholding.h" 2 : #include "Error.h" 3 : #include "TypeCasts.hpp" 4 : 5 : namespace elsa 6 : { 7 : template <typename data_t> 8 0 : HardThresholding<data_t>::HardThresholding(const DataDescriptor& descriptor) 9 0 : : ProximityOperator<data_t>(descriptor) 10 : { 11 0 : } 12 : 13 : template <typename data_t> 14 0 : void HardThresholding<data_t>::applyImpl(const DataContainer<data_t>& v, 15 : geometry::Threshold<data_t> t, 16 : DataContainer<data_t>& prox) const 17 : { 18 0 : if (v.getSize() != prox.getSize()) { 19 0 : throw LogicError("HardThresholding: sizes of v and prox must match"); 20 : } 21 : 22 0 : auto vIter = v.begin(); 23 0 : auto proxIter = prox.begin(); 24 : 25 0 : for (; vIter != v.end() && proxIter != prox.end(); vIter++, proxIter++) { 26 0 : if ((*vIter > t) || (*vIter < -t)) { 27 0 : *proxIter = *vIter; 28 : } else { 29 0 : *proxIter = 0; 30 : } 31 : } 32 0 : } 33 : 34 : template <typename data_t> 35 0 : auto HardThresholding<data_t>::cloneImpl() const -> HardThresholding<data_t>* 36 : { 37 0 : return new HardThresholding<data_t>(this->getRangeDescriptor()); 38 : } 39 : 40 : template <typename data_t> 41 0 : auto HardThresholding<data_t>::isEqual(const ProximityOperator<data_t>& other) const -> bool 42 : { 43 0 : if (!ProximityOperator<data_t>::isEqual(other)) { 44 0 : return false; 45 : } 46 : 47 0 : auto otherDerived = downcast_safe<HardThresholding<data_t>>(&other); 48 : 49 0 : return static_cast<bool>(otherDerived); 50 : } 51 : 52 : // ------------------------------------------ 53 : // explicit template instantiation 54 : template class HardThresholding<float>; 55 : template class HardThresholding<double>; 56 : } // namespace elsa