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