diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-03-02 21:10:46 +0100 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-03-02 21:10:46 +0100 |
| commit | 971250070e7b27590d215de54116f3990ab8ff5a (patch) | |
| tree | b4c4ccf1986251263425993b0fb879ddd829b3d5 /lib/core | |
| parent | 0b475ddb7d1557fad9f9455d189ec87d434f7670 (diff) | |
| download | libs-lbm-971250070e7b27590d215de54116f3990ab8ff5a.tar.gz | |
Adding bluring for masks
Diffstat (limited to 'lib/core')
| -rw-r--r-- | lib/core/c++/math/n_linear.hpp | 29 | ||||
| -rw-r--r-- | lib/core/c++/particle/blur.hpp | 37 |
2 files changed, 66 insertions, 0 deletions
diff --git a/lib/core/c++/math/n_linear.hpp b/lib/core/c++/math/n_linear.hpp new file mode 100644 index 0000000..62906cd --- /dev/null +++ b/lib/core/c++/math/n_linear.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include "../common.hpp" + +namespace kel { +namespace lbm { + +template<typename FieldSchema, typename T, uint64_t D> +void n_linear_interpolate(const saw::data<FieldSchema>& field, const saw::data<sch::FixedArray<T,D>>& pos){ + + auto pos_bound = pos; + auto meta = field.dims(); + saw::data<sch::UInt64> ind; + for(saw::data<sch::UInt64> i{0u}; i < saw::data<sch::UInt64>{D}; ++i){ + pos_bound.at(i).set( + std::max( + std::min( + meta.at(i).template cast_to<T>().get(), + pos.at(i).get() + 1.5 + ), + 1, + ) + -1 + ); + ind.at(i) = pos_bound.at(i).template cast_to<sch::UInt64>(); + } +} +} +} diff --git a/lib/core/c++/particle/blur.hpp b/lib/core/c++/particle/blur.hpp new file mode 100644 index 0000000..a304e8d --- /dev/null +++ b/lib/core/c++/particle/blur.hpp @@ -0,0 +1,37 @@ +#pragma once + +namespace kel { +namespace lbm { +template<typename T, uint64_t D> +void blur_mask(saw::data<sch::Array<T,D>>& p_mask){ + + saw::data<T> mid{2.0/3.0}; + saw::data<T> edge{1.0/6.0}; + + // saw::data<sch::FixedArray<sch::UInt64>,2u> blur_weights{{2.0/3.0},{1.0/6.0}}; + + auto meta = p_mask.dims(); + saw::data<sch::Array<T,D>> blurred_mask{meta}; + + for(saw::data<sch::UInt64> i{0u}; i < saw::data<sch::UInt64>{D}; ++i){ + iterator<D>::apply([&](const auto& index){ + blurred_mask.at(index) = p_mask.at(index) * mid; + + if(index.at({i}).get() > 0u){ + auto l_ind = index; + l_ind.at({i}) = ind.at({i}) - 1u; + blurred_mask.at(index) = blurred_mask.at(index) + p_mask.at(l_ind) * edge; + } + if((index.at({i}).get() + 1u) < meta.at({i})){ + auto r_ind = index; + r_ind.at({i}) = ind.at({i}) + 1u; + blurred_mask.at(index) = blurred_mask.at(index) + p_mask.at(r_ind) * edge; + } + },{},meta); + + p_mask = blurred_mask; + } + +} +} +} |
