1#ifndef TATOOINE_STREAMSURFACE_H
2#define TATOOINE_STREAMSURFACE_H
16#include <boost/functional.hpp>
17#include <boost/range/algorithm.hpp>
18#include <boost/range/numeric.hpp>
26template <
typename Streamsurface>
27struct hultquist_discretization;
29template <
typename Flowmap,
30 template <
typename>
typename SeedcurveInterpolationKernel>
34 return flowmap_type::num_dimensions();
40 typename seedcurve_type::template vertex_property_sampler_type<
62 seedcurve.template sampler<SeedcurveInterpolationKernel>()},
75 seedcurve.template sampler<SeedcurveInterpolationKernel>()},
88 seedcurve.template sampler<SeedcurveInterpolationKernel>()},
114 if (u < m_min_u || u >
m_max_u) {
122 }
catch (std::exception&) {
131 std::size_t num_samples)
const {
132 auto step = (uv1 - uv0) / (num_samples - 1);
134 for (std::size_t i = 0; i < num_samples - 1; ++i) {
136 sample(uv0 + step * (i + 1)));
144 template <
template <
typename>
148 return Discretization<this_type>(
this, std::forward<Args>(args)...);
155template <
typename Flowmap>
157 line<
typename Flowmap::real_type,
158 Flowmap::num_dimensions()>
const& seedcurve)
161template <
typename Flowmap>
163 line<
typename Flowmap::real_type,
164 Flowmap::num_dimensions()>
const& seedcurve)
167template <
typename Flowmap>
170 line<
typename Flowmap::real_type, Flowmap::num_dimensions()>
const&)
173template <
typename Flowmap>
175 line<
typename Flowmap::real_type,
176 Flowmap::num_dimensions()>
const& seedcurve)
179template <
typename Flowmap>
181 line<
typename Flowmap::real_type,
182 Flowmap::num_dimensions()>
const& seedcurve)
185template <
typename Flowmap>
188 line<
typename Flowmap::real_type, Flowmap::num_dimensions()>
const&)
191template <
typename Streamsurface>
194 Streamsurface::num_dimensions()> {
199 return Streamsurface::num_dimensions();
206 using parent_type::operator[];
219 std::pair<vertex_list_iterator_type, vertex_list_iterator_type>;
271 return this->
template vertex_property<uv_type>(
"uv");
273 auto&
find_uv_prop() {
return this->
template vertex_property<uv_type>(
"uv"); }
289 auto new_face_indices = std::vector<triangle_handle>{};
290 auto left0 =
begin(front0);
291 auto const end0 =
end(front0);
292 auto left1 =
begin(front1);
293 auto const end1 =
end(front1);
296 while (
next(left0) != end0 ||
next(left1) != end1) {
297 assert(left0 != end0);
298 assert(left1 != end1);
299 auto lower_edge_len = std::numeric_limits<real_type>::max();
300 auto upper_edge_len = std::numeric_limits<real_type>::max();
301 auto const right0 =
next(left0);
302 auto const right1 =
next(left1);
304 if (
next(left0) != end0) {
305 lower_edge_len = std::abs(
uv(*left1)(0) -
uv(*right0)(0));
308 if (
next(left1) != end1) {
309 upper_edge_len = std::abs(
uv(*right1)(0) -
uv(*left0)(0));
312 if (lower_edge_len < upper_edge_len) {
313 new_face_indices.push_back(
315 if (
next(left0) != end0) {
320 new_face_indices.push_back(
323 if (
next(left1) != end1) {
341 seedline_resolution}) {
342 auto const t0u =
t0(u);
355 }
catch (std::exception&) {
360 while (d > desired_spatial_dist * 1.5) {
362 auto new_uv = (
uv(*v) +
uv(*
next(v))) * 0.5;
369 }
catch (std::exception&) {
372 }
catch (std::exception&) {
384 if (
front.size() >= 3) {
389 }
catch (std::exception&) {
395 d() < desired_spatial_dist * 1.25) {
400 if (
front.size() > 2 &&
402 desired_spatial_dist * 0.5) {
408template <
typename Streamsurface>
411 Streamsurface::num_dimensions()> {
416 return Streamsurface::num_dimensions();
423 using parent_type::operator[];
436 std::pair<vertex_list_iterator_type, vertex_list_iterator_type>;
460 : m_streamsurface{
streamsurface}, m_uv_property{&insert_uv_prop()} {}
464 m_streamsurface{other.m_streamsurface},
465 m_uv_property{&find_uv_prop()} {}
469 m_streamsurface{other.m_streamsurface},
470 m_uv_property{&find_uv_prop()} {}
473 parent_type::operator=(other);
475 m_uv_property = &find_uv_prop();
480 parent_type::operator=(std::move(other));
481 m_streamsurface = other.m_streamsurface;
482 m_uv_property = &find_uv_prop();
490 return this->
template vertex_property<uv_type>(
"uv");
492 auto&
find_uv_prop() {
return this->
template vertex_property<uv_type>(
"uv"); }
501 auto v = parent_type::insert_vertex(p);
507 auto v = parent_type::insert_vertex(std::move(p));
513 auto v = parent_type::insert_vertex(p);
514 uv(v) = std::move(p_uv);
519 auto v = parent_type::insert_vertex(std::move(p));
520 uv(v) = std::move(p_uv);
525 for (
auto const& subfront :
front) {
526 auto new_face_indices = std::vector<triangle_handle>{};
527 auto const& vs = subfront.first;
528 auto [left0, end0] = subfront.second;
529 auto left1 =
begin(vs);
537 while (
next(left0) != end0 ||
next(left1) != end1) {
538 assert(left0 != end0);
539 assert(left1 != end1);
540 real_type lower_edge_len = std::numeric_limits<real_type>::max();
541 real_type upper_edge_len = std::numeric_limits<real_type>::max();
542 auto const right0 =
next(left0);
543 auto const right1 =
next(left1);
545 if (
next(left0) != end0) {
546 lower_edge_len = std::abs(uv(*left1)(0) - uv(*right0)(0));
549 if (
next(left1) != end1) {
550 upper_edge_len = std::abs(uv(*right1)(0) - uv(*left0)(0));
553 if (lower_edge_len < upper_edge_len) {
554 new_face_indices.push_back(
555 this->insert_triangle(*left0, *right0, *left1));
556 if (
next(left0) != end0) {
561 new_face_indices.push_back(
562 this->insert_triangle(*left0, *right1, *left1));
564 if (
next(left1) != end1) {
573 auto vs = std::vector<vertex_list_type>{};
576 seedline_resolution}) {
577 auto const t0u = t0(u);
582 auto const v = insert_vertex(std::move(new_pos),
uv_type{u, t0u});
583 vs.back().push_back(v);
590 if (vs.back().size() <= 1) {
594 for (
auto&& vs : vs) {
595 front.emplace_back(std::move(vs), std::pair{
begin(vs),
end(vs)});
601 return average_segment_length(subfront.first);
607 dist_acc +=
norm(at(*v) - at(*
next(v)));
610 return dist_acc / (vs.size() - 1);
614 auto find_best_predecessor = [
this](
auto const v,
auto const& pred_range) {
615 real_type min_u_dist = std::numeric_limits<real_type>::max();
616 auto best_it = pred_range.second;
617 for (
auto it = pred_range.first; it != pred_range.second; ++it) {
618 if (
real_type u_dist = std::abs(uv(*v)(0) - uv(*it)(0));
619 u_dist < min_u_dist) {
622 if (min_u_dist == 0) {
631 if (subfront->first.size() > 1) {
632 auto& vs = subfront->first;
633 auto& pred_range = subfront->second;
639 }
catch (std::exception&) {
644 while (d > desired_spatial_dist * 1.5) {
648 auto const best_predecessor = find_best_predecessor(v, pred_range);
652 pred_range.second =
next(best_predecessor);
658 auto new_uv = (uv(*v) + uv(*
next(v))) * 0.5;
662 insert_vertex(new_pnt,
uv_type{new_uv(0), new_uv(1)});
663 vs.insert(
next(v), new_v);
666 }
catch (std::exception&) {
669 }
catch (std::exception&) {
671 auto const best_predecessor = find_best_predecessor(v, pred_range);
676 pred_range.second =
next(best_predecessor);
692 for (
auto& subfront :
front) {
693 auto& vs = subfront.first;
694 if (vs.size() >= 3) {
702 }
catch (std::exception&) {
708 d() < desired_spatial_dist * 1.25) {
714 desired_spatial_dist * 0.5) {
721template <
typename Streamsurface>
726 return Streamsurface::num_dimensions();
754 std::size_t seedline_resolution,
real_type stepsize,
757 assert(forward_tau >= 0);
758 assert(backward_tau <= 0);
761 if (seed_front.empty()) {
765 if (backward_tau < 0) {
766 auto cur_stepsize = stepsize;
767 auto cur_front = seed_front;
769 while (advected_time > backward_tau) {
770 if (advected_time - cur_stepsize < backward_tau) {
771 cur_stepsize = std::abs(backward_tau - advected_time);
773 cur_front =
evolve(cur_front, -cur_stepsize);
774 advected_time -= cur_stepsize;
778 if (forward_tau > 0) {
779 auto cur_stepsize = stepsize;
780 auto cur_front = seed_front;
782 while (advected_time < forward_tau) {
783 if (advected_time + cur_stepsize > forward_tau) {
784 cur_stepsize = forward_tau - advected_time;
786 cur_front =
evolve(cur_front, cur_stepsize);
787 advected_time += cur_stepsize;
794 auto advected_front =
front;
801 vec const new_uv{
uv(0),
uv(1) + step};
808 return advected_front;
812template <
typename Streamsurface>
835 std::size_t seedline_resolution,
real_type stepsize,
838 assert(forward_tau >= 0);
839 assert(backward_tau <= 0);
842 if (seed_front.size() <= 1) {
847 if (backward_tau < 0) {
848 auto cur_stepsize = stepsize;
849 auto cur_front = seed_front;
851 while (advected_time > backward_tau) {
852 if (advected_time - cur_stepsize < backward_tau) {
853 cur_stepsize = std::abs(backward_tau - advected_time);
855 cur_front =
evolve(cur_front, -cur_stepsize, desired_spatial_dist);
856 advected_time -= cur_stepsize;
860 if (forward_tau > 0) {
861 auto cur_stepsize = stepsize;
862 auto cur_front = seed_front;
864 while (advected_time < forward_tau) {
865 if (advected_time + cur_stepsize > forward_tau) {
866 cur_stepsize = forward_tau - advected_time;
868 cur_front =
evolve(cur_front, cur_stepsize, desired_spatial_dist);
869 advected_time += cur_stepsize;
883 for (
auto& v :
front) {
885 auto const new_uv =
vec{
uv(0),
uv(1) + step};
904 return advected_front;
auto & operator=(const cache &other)
Definition: cache.h:48
Definition: concepts.h:33
Definition: concepts.h:39
Definition: concepts.h:84
Definition: algorithm.h:6
auto begin(Range &&range)
Definition: iterator_facade.h:318
auto end(Range &&range)
Definition: iterator_facade.h:322
Vec< 2 > vec2
Definition: vec_typedefs.h:28
constexpr auto norm(base_tensor< Tensor, T, N > const &t, unsigned p=2) -> T
Definition: norm.h:23
constexpr auto max(A &&a, B &&b)
Definition: math.h:20
auto size(vec< ValueType, N > const &v)
Definition: vec.h:148
auto next(Iter iter)
Definition: iterator_facade.h:325
constexpr auto min(A &&a, B &&b)
Definition: math.h:15
auto back(linspace< Real > const &l)
Definition: linspace.h:136
auto front(linspace< Real > const &l)
Definition: linspace.h:126
static constexpr forward_tag forward
Definition: tags.h:9
constexpr auto euclidean_distance(base_tensor< Tensor0, T0, N > const &lhs, base_tensor< Tensor1, T1, N > const &rhs)
Definition: distance.h:19
auto prev(Iter iter)
Definition: iterator_facade.h:343
vec_type pos_type
Definition: axis_aligned_bounding_box.h:109
Definition: vertex_handle.h:10
Definition: streamsurface.h:194
typename vertex_list_type::const_iterator vertex_list_iterator_type
Definition: streamsurface.h:217
streamsurface_type const * m_streamsurface
Definition: streamsurface.h:230
uv_property_type * m_uv_property
Definition: streamsurface.h:231
auto subdivide(front_type &front, real_type desired_spatial_dist) -> void
Definition: streamsurface.h:350
vec< real_type, 2 > vec2
Definition: streamsurface.h:210
auto seedcurve_to_front(std::size_t const seedline_resolution)
Definition: streamsurface.h:338
front_evolving_streamsurface_discretization(this_type &&other) noexcept
Definition: streamsurface.h:248
typename Streamsurface::real_type real_type
Definition: streamsurface.h:201
auto streamsurface() const -> auto const &
Definition: streamsurface.h:234
typename parent_type::template typed_vertex_property_type< uv_type > uv_property_type
Definition: streamsurface.h:213
Streamsurface streamsurface_type
Definition: streamsurface.h:220
auto uv(vertex_handle v) const -> auto const &
Definition: streamsurface.h:277
auto average_segment_length(vertex_list_type const &vertices) const
Definition: streamsurface.h:330
auto & insert_uv_prop()
Definition: streamsurface.h:270
auto & find_uv_prop()
Definition: streamsurface.h:273
typename parent_type::simplex_handle triangle_handle
Definition: unstructured_triangular_grid.h:15
front_evolving_streamsurface_discretization(this_type const &other)
Definition: streamsurface.h:243
auto t0(real_type u) const
Definition: streamsurface.h:279
void reduce(front_type &front, real_type desired_spatial_dist)
Definition: streamsurface.h:383
std::pair< vertex_list_iterator_type, vertex_list_iterator_type > vertex_range_type
Definition: streamsurface.h:219
auto & operator=(this_type &&other) noexcept
Definition: streamsurface.h:260
auto & operator=(this_type const &other)
Definition: streamsurface.h:253
std::list< vertex_handle > vertex_list_type
Definition: streamsurface.h:216
static constexpr auto num_dimensions() -> std::size_t
Definition: streamsurface.h:198
vec2 uv_type
Definition: streamsurface.h:211
std::vector< vertex_handle > vertex_vec_type
Definition: streamsurface.h:215
front_evolving_streamsurface_discretization(streamsurface_type const *streamsurface)
Definition: streamsurface.h:239
auto uv(vertex_handle v) -> auto &
Definition: streamsurface.h:276
auto triangulate_timeline(front_type const &front0, front_type const &front1)
Definition: streamsurface.h:287
auto insert_vertex(pos_type const &p, uv_type const &p_uv)
Definition: streamsurface.h:281
vertex_list_type front_type
Definition: streamsurface.h:224
Definition: streamsurface.h:814
auto operator=(this_type &&other) noexcept -> hultquist_discretization &=default
hultquist_discretization(streamsurface_type *streamsurface, std::size_t seedline_resolution, real_type stepsize, real_type backward_tau, real_type forward_tau)
Definition: streamsurface.h:834
typename Streamsurface::real_type real_type
Definition: streamsurface.h:815
hultquist_discretization(this_type &&other) noexcept=default
auto streamsurface() const -> auto const &
Definition: streamsurface.h:234
auto operator=(this_type const &other) -> hultquist_discretization &=default
Streamsurface streamsurface_type
Definition: streamsurface.h:220
hultquist_discretization(this_type const &other)=default
auto evolve(front_type const &front, real_type step, real_type)
Definition: streamsurface.h:893
~hultquist_discretization()=default
auto uv(vertex_handle v) -> auto &
Definition: streamsurface.h:276
auto insert_vertex(pos_type const &p, uv_type const &p_uv)
Definition: streamsurface.h:281
vertex_list_type front_type
Definition: streamsurface.h:224
auto advect(front_type front, real_type step)
Definition: streamsurface.h:881
Definition: interpolation.h:16
auto parameterization() -> auto &
Definition: line.h:502
Definition: linspace.h:26
Definition: streamsurface.h:411
auto & operator=(this_type &&other) noexcept
Definition: streamsurface.h:479
typename Streamsurface::real_type real_type
Definition: streamsurface.h:418
std::list< vertex_handle > vertex_list_type
Definition: streamsurface.h:433
void triangulate_timeline(front_type const &front)
Definition: streamsurface.h:524
auto t0(real_type u) const
Definition: streamsurface.h:498
std::pair< vertex_list_type, vertex_range_type > subfront_type
Definition: streamsurface.h:437
std::list< subfront_type > front_type
Definition: streamsurface.h:442
auto seedcurve_to_front(std::size_t seedline_resolution)
Definition: streamsurface.h:572
auto uv(vertex_handle v) const -> auto const &
Definition: streamsurface.h:496
typename parent_type::template typed_vertex_property_type< uv_type > uv_property_type
Definition: streamsurface.h:430
auto insert_vertex(pos_type const &p, uv_type &&p_uv)
Definition: streamsurface.h:512
void reduce(front_type &front, real_type desired_spatial_dist)
Definition: streamsurface.h:691
typename vertex_list_type::const_iterator vertex_list_iterator_type
Definition: streamsurface.h:434
auto & operator=(this_type const &other)
Definition: streamsurface.h:472
Streamsurface streamsurface_type
Definition: streamsurface.h:438
multi_front_evolving_streamsurface_discretization(this_type &&other) noexcept
Definition: streamsurface.h:467
real_type average_segment_length(vertex_list_type const &vs) const
Definition: streamsurface.h:604
void subdivide(front_type &front, real_type desired_spatial_dist)
Definition: streamsurface.h:613
auto insert_vertex(pos_type &&p, uv_type const &p_uv)
Definition: streamsurface.h:506
multi_front_evolving_streamsurface_discretization(streamsurface_type const *streamsurface)
Definition: streamsurface.h:458
auto & find_uv_prop()
Definition: streamsurface.h:492
auto insert_vertex(pos_type &&p, uv_type &&p_uv)
Definition: streamsurface.h:518
uv_property_type * m_uv_property
Definition: streamsurface.h:450
auto & uv(vertex_handle v)
Definition: streamsurface.h:495
auto insert_vertex(pos_type const &p, uv_type const &p_uv)
Definition: streamsurface.h:500
std::vector< vertex_handle > vertex_vec_type
Definition: streamsurface.h:432
multi_front_evolving_streamsurface_discretization(this_type const &other)
Definition: streamsurface.h:462
std::pair< vertex_list_iterator_type, vertex_list_iterator_type > vertex_range_type
Definition: streamsurface.h:436
auto & insert_uv_prop()
Definition: streamsurface.h:489
real_type average_segment_length(subfront_type const &subfront) const
Definition: streamsurface.h:600
streamsurface_type const * m_streamsurface
Definition: streamsurface.h:448
auto streamsurface() const -> auto const &
Definition: streamsurface.h:453
static constexpr auto num_dimensions() -> std::size_t
Definition: streamsurface.h:415
std::set< vertex_handle > m_on_border
Definition: streamsurface.h:449
Definition: streamsurface.h:723
typename parent_type::streamsurface_type streamsurface_type
Definition: streamsurface.h:732
typename Streamsurface::real_type real_type
Definition: streamsurface.h:724
typename parent_type::vertex_list_iterator_type vertex_list_iterator_type
Definition: streamsurface.h:738
naive_discretization(naive_discretization const &other)=default
static constexpr auto num_dimensions() -> std::size_t
Definition: streamsurface.h:725
typename parent_type::vertex_vec_type vertex_vec_type
Definition: streamsurface.h:733
auto streamsurface() const -> auto const &
Definition: streamsurface.h:234
typename parent_type::vertex_range_type vertex_range_type
Definition: streamsurface.h:739
naive_discretization(streamsurface_type *streamsurface, std::size_t seedline_resolution, real_type stepsize, real_type backward_tau, real_type forward_tau)
Definition: streamsurface.h:753
naive_discretization & operator=(naive_discretization &&other) noexcept=default
typename parent_type::vertex_list_type vertex_list_type
Definition: streamsurface.h:734
~naive_discretization()=default
typename parent_type::subfront_type subfront_type
Definition: streamsurface.h:731
naive_discretization(naive_discretization &&other) noexcept=default
auto evolve(front_type const &front, real_type const step)
Definition: streamsurface.h:793
typename parent_type::vertex_handle vertex_handle
Definition: streamsurface.h:735
naive_discretization & operator=(naive_discretization const &other)=default
typename parent_type::triangle_handle triangle_handle
Definition: streamsurface.h:736
auto uv(vertex_handle v) -> auto &
Definition: streamsurface.h:276
typename parent_type::front_type front_type
Definition: streamsurface.h:730
auto insert_vertex(pos_type const &p, uv_type const &p_uv)
Definition: streamsurface.h:281
Definition: exceptions.h:8
Definition: pointset.h:83
auto insert_vertex(arithmetic auto const ... ts)
Definition: pointset.h:243
auto vertices() const
Definition: pointset.h:226
Definition: streamsurface.h:31
constexpr auto min_u() const
Definition: streamsurface.h:151
streamsurface(convertible_to< Flowmap > auto &&flowmap, seedcurve_type const &seedcurve)
Definition: streamsurface.h:81
real_type m_t0_u0
Definition: streamsurface.h:48
typename seedcurve_type::template vertex_property_sampler_type< seedcurve_type, SeedcurveInterpolationKernel > seedcurve_interpolator_type
Definition: streamsurface.h:41
streamsurface(convertible_to< Flowmap > auto &&flowmap, arithmetic auto t0u0, arithmetic auto t0u1, seedcurve_type const &seedcurve)
Definition: streamsurface.h:55
auto operator()(real_type u, real_type v) const
Definition: streamsurface.h:141
streamsurface(convertible_to< Flowmap > auto &&flowmap, arithmetic auto t0, seedcurve_type const &seedcurve)
Definition: streamsurface.h:68
auto sample(real_type const u, real_type const v) const -> vec_type
calculates position of streamsurface
Definition: streamsurface.h:113
Flowmap m_flowmap
Definition: streamsurface.h:47
auto operator()(vec2 const &uv) const
Definition: streamsurface.h:142
auto flowmap() const -> auto const &
Definition: streamsurface.h:108
real_type m_t0_u1
Definition: streamsurface.h:48
auto seedcurve() const -> auto const &
Definition: streamsurface.h:110
real_type m_max_u
Definition: streamsurface.h:51
auto t0(real_type const u) const
Definition: streamsurface.h:99
std::decay_t< Flowmap > flowmap_type
Definition: streamsurface.h:32
seedcurve_type m_seedcurve
Definition: streamsurface.h:49
constexpr auto max_u() const
Definition: streamsurface.h:152
seedcurve_interpolator_type m_seedcurve_interpolator
Definition: streamsurface.h:50
real_type m_min_u
Definition: streamsurface.h:51
auto flowmap() -> auto &
Definition: streamsurface.h:107
line< real_type, num_dimensions()> seedcurve_type
Definition: streamsurface.h:38
auto discretize(Args &&... args)
Definition: streamsurface.h:147
auto distance(vec2 const &uv0, vec2 const &uv1, std::size_t num_samples) const
Definition: streamsurface.h:130
auto sample(vec2 const &uv) const -> vec_type
calculates position of streamsurface
Definition: streamsurface.h:128
typename flowmap_type::real_type real_type
Definition: streamsurface.h:36
static constexpr auto num_dimensions() -> std::size_t
Definition: streamsurface.h:33
type_list_at< this_type, I > at
Definition: type_list.h:269
typename parent_type::template typed_vertex_property_type< T > typed_vertex_property_type
Definition: unstructured_simplicial_grid.h:82
auto at(simplex_handle t) const -> auto
Definition: unstructured_simplicial_grid.h:300
Definition: unstructured_triangular_grid.h:10
auto insert_triangle(Handles const ... handles)
Definition: unstructured_triangular_grid.h:18
typename parent_type::simplex_handle triangle_handle
Definition: unstructured_triangular_grid.h:15