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