cgv
Loading...
Searching...
No Matches
hermite_tube.h
1#pragma once
2
3#include <array>
4
5#include "bezier_tube.h"
6#include "convert_curve.h"
7#include "hermite.h"
8
9namespace cgv {
10namespace math {
11
12template<typename T>
17
18template<typename T>
20public:
21 using vec_type = fvec<T, 3>;
24
25 // the start node
26 node_type n0;
27 // the end node
28 node_type n1;
29
30 template<typename ParamT = float>
31 node_type evaluate(ParamT t) const {
32 node_type n;
33 n.pos = interpolate_cubic_hermite(n0.val, n0.tan, n1.val, n1.tan, t);
34 n.rad = interpolate_cubic_hermite(n0.val, n0.tan, n1.val, n1.tan, t);
35 return n;
36 }
37
38 template<typename ParamT = float>
39 std::vector<node_type> sample(size_t num_segments) const {
40 std::vector<node_type> points;
41 points.reserve(num_segments + 1);
42 sample_steps_transform<ParamT>(std::back_inserter(points), [this](ParamT t) { return evaluate(t); }, num_segments);
43 return points;
44 }
45
46 std::pair<vec_type, vec_type> approximate_axis_aligned_bounding_box() const {
47 std::pair<vec_type, vec_type> box;
48 std::array<quadratic_bezier_tube<T>, 2> qtubes = split_to_quadratic_bezier_tubes();
49
50 std::pair<vec_type, vec_type> qbox = qtubes[0].axis_aligned_bounding_box();
51 box.first = qbox.first;
52 box.second = qbox.second;
53
54 qbox = qtubes[1].axis_aligned_bounding_box();
55 box.first = min(box.first, qbox.first);
56 box.second = max(box.second, qbox.second);
57
58 return box;
59 }
60
61 std::array<quadratic_bezier_tube<T>, 2> split_to_quadratic_bezier_tubes() const {
62 std::array<vec_type, 5> ps = split_hermite_to_quadratic_beziers(n0.pos, n1.pos);
63 std::array<T, 5> rs = split_hermite_to_quadratic_beziers(n0.rad, n1.rad);
64
65 std::array<quadratic_bezier_tube<T>, 2> qtubes;
66 qtubes[0].n0 = { ps[0], rs[0] };
67 qtubes[0].n1 = { ps[1], rs[1] };
68 qtubes[0].n2 = { ps[2], rs[2] };
69 qtubes[1].n0 = { ps[2], rs[2] };
70 qtubes[1].n1 = { ps[3], rs[3] };
71 qtubes[1].n2 = { ps[4], rs[4] };
72 return qtubes;
73 }
74};
75
76
77} // namespace math
78} // namespace cgv
matrix of fixed size dimensions
Definition fmat.h:23
the cgv namespace
Definition print.h:11