1#ifndef TATOOINE_CURVE_TO_STREAMLINE_H
2#define TATOOINE_CURVE_TO_STREAMLINE_H
10template <
typename Real>
23 template <
typename V,
typename Line>
25 Real initial_stepsize, Real delta,
size_t num_its) {
30 Real cur_stepsize = initial_stepsize;
31 for (
unsigned int i = 0; i < num_its; i++) {
37 cur_stepsize *= delta;
43 template <
typename Line>
45 for (
size_t i = 0; i <
line.size(); i++) {
52 template <
typename Line>
54 for (
unsigned int i = 0; i <
line.size(); i++) {
61 for (
size_t i = 0; i <
tangents.size(); i++) {
63 vec3 aux_vec{1, 0, 0};
65 if (
approx_equal(aux_vec, tn, 1e-10)) { aux_vec = {0, 1, 0}; }
66 if (
approx_equal(aux_vec, tn, 1e-10)) { aux_vec = {0, 0, 1}; }
76 template <
typename Line>
82 for (
size_t i = start_idx; i < end_idx; ++i) {
90 redistributed_points[i] += correction;
96 template <
typename V,
typename Line>
98 for (
size_t i = 0; i <
line.size(); ++i) {
101 const Real offset = 1e-6;
103 const auto v_x_pos =
normalize(v(x +
bases[i].col(0) * offset, t0));
104 const auto v_x_neg =
normalize(v(x -
bases[i].col(0) * offset, t0));
105 const auto v_y_pos =
normalize(v(x +
bases[i].col(1) * offset, t0));
106 const auto v_y_neg =
normalize(v(x -
bases[i].col(1) * offset, t0));
109 auto alpha_x_pos =
min_angle(tn, v_x_pos);
110 auto alpha_x_neg =
min_angle(tn, v_x_neg);
111 auto alpha_y_pos =
min_angle(tn, v_y_pos);
112 auto alpha_y_neg =
min_angle(tn, v_y_neg);
114 if (std::isnan(alpha_x_pos)) { alpha_x_pos = 0; }
115 if (std::isnan(alpha_x_neg)) { alpha_x_neg = 0; }
116 if (std::isnan(alpha_y_pos)) { alpha_y_pos = 0; }
117 if (std::isnan(alpha_y_neg)) { alpha_y_neg = 0; }
119 grad_alpha[i] = {(alpha_x_pos - alpha_x_neg) / (offset * 2),
120 (alpha_y_pos - alpha_y_neg) / (offset * 2)};
Definition: algorithm.h:6
constexpr auto min_angle(base_tensor< Tensor0, T0, N > const &v0, base_tensor< Tensor1, T1, N > const &v1)
Returns the angle of two normalized vectors.
Definition: tensor_operations.h:54
constexpr auto approx_equal(T0 const &lhs, T1 const &rhs, common_type< tatooine::value_type< T0 >, tatooine::value_type< T1 > > eps=1e-6)
for comparison
Definition: tensor_utility.h:11
constexpr auto normalize(base_tensor< Tensor, T, N > const &t_in) -> vec< T, N >
Definition: tensor_operations.h:100
constexpr auto dot(base_tensor< Tensor0, T0, N > const &lhs, base_tensor< Tensor1, T1, N > const &rhs)
Definition: tensor_operations.h:120
constexpr auto cross(base_tensor< Tensor0, T0, 3 > const &lhs, base_tensor< Tensor1, T1, 3 > const &rhs)
Definition: cross.h:9
Definition: curve_to_streamline.h:11
void calc_tangents(const Line &line)
Definition: curve_to_streamline.h:53
std::vector< vec3 > tangents
Definition: curve_to_streamline.h:20
void calc_gradient_alpha(const V &v, Real t0, const Line &line)
Definition: curve_to_streamline.h:97
void step(Line &line, Real stepsize)
Definition: curve_to_streamline.h:44
void calc_plane_basis()
Definition: curve_to_streamline.h:60
void redistribute_points(Line &line) const
Definition: curve_to_streamline.h:77
std::vector< mat32 > bases
Definition: curve_to_streamline.h:18
auto operator()(const field< V, Real, 3, 3 > &v, Real t0, Line line, Real initial_stepsize, Real delta, size_t num_its)
Definition: curve_to_streamline.h:24
std::vector< vec2 > grad_alpha
Definition: curve_to_streamline.h:19
auto vertices() const
Definition: line.h:250
auto vertex_at(std::size_t const i) const -> auto const &
Definition: line.h:146
auto front_vertex() const -> auto const &
Definition: line.h:170
auto is_closed() const
Definition: line.h:305
auto back_vertex() const -> auto const &
Definition: line.h:173
static auto constexpr randu(ValueType min=0, ValueType max=1, RandEng &&eng=RandEng{std::random_device{}()})
Definition: vec.h:35