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 using sample_type = sphere<T>;
25
26 // the start node
27 node_type n0;
28 // the end node
29 node_type n1;
30
31 template<typename ParamT = float>
32 sample_type evaluate(ParamT t) const {
34 n.pos = interpolate_cubic_hermite(n0.pos.val, n0.pos.tan, n1.pos.val, n1.pos.tan, t);
35 n.rad = interpolate_cubic_hermite(n0.rad.val, n0.rad.tan, n1.rad.val, n1.rad.tan, t);
36 return n;
37 }
38
39 template<typename ParamT = float>
40 std::vector<sample_type> sample(size_t num_segments) const {
41 std::vector<sample_type> points;
42 points.reserve(num_segments + 1);
43 sequence_transform<ParamT>(std::back_inserter(points), [this](ParamT t) { return evaluate(t); }, num_segments + 1);
44 return points;
45 }
46
47 std::pair<vec_type, vec_type> approximate_axis_aligned_bounding_box() const {
48 std::pair<vec_type, vec_type> box;
49 std::array<quadratic_bezier_tube<T>, 2> qtubes = split_to_quadratic_bezier_tubes();
50
51 std::pair<vec_type, vec_type> qbox = qtubes[0].axis_aligned_bounding_box();
52 box.first = qbox.first;
53 box.second = qbox.second;
54
55 qbox = qtubes[1].axis_aligned_bounding_box();
56 box.first = min(box.first, qbox.first);
57 box.second = max(box.second, qbox.second);
58
59 return box;
60 }
61
62 std::array<quadratic_bezier_tube<T>, 2> split_to_quadratic_bezier_tubes() const {
63 std::array<vec_type, 5> ps = split_hermite_to_quadratic_beziers(n0.pos, n1.pos);
64 std::array<T, 5> rs = split_hermite_to_quadratic_beziers(n0.rad, n1.rad);
65
66 std::array<quadratic_bezier_tube<T>, 2> qtubes;
67 qtubes[0].n0 = { ps[0], rs[0] };
68 qtubes[0].n1 = { ps[1], rs[1] };
69 qtubes[0].n2 = { ps[2], rs[2] };
70 qtubes[1].n0 = { ps[2], rs[2] };
71 qtubes[1].n1 = { ps[3], rs[3] };
72 qtubes[1].n2 = { ps[4], rs[4] };
73 return qtubes;
74 }
75};
76
77
78} // namespace math
79} // namespace cgv
matrix of fixed size dimensions
Definition fmat.h:23
this header is dependency free
Definition print.h:11