1 #ifndef MEDUSA_BITS_DOMAINS_STLSHAPE_HPP_
2 #define MEDUSA_BITS_DOMAINS_STLSHAPE_HPP_
19 template <
typename vec_t>
21 assert_msg(!stl.empty(),
"Triangle list should not be empty.");
22 int num_triangles = stl.size();
23 std::map<vec_t, int> index;
25 faces_.resize(num_triangles);
26 normals_.resize(num_triangles);
27 bbox_.first = bbox_.second = v(stl[0].p1);
28 for (
int i = 0; i < num_triangles; ++i) {
29 const auto& t = stl[i];
32 if (index.count(p1) == 0) index[p1] = num_points++;
33 faces_[i][0] = index[p1];
34 bbox_.first = bbox_.first.cwiseMin(p1);
35 bbox_.second = bbox_.second.cwiseMax(p1);
38 if (index.count(p2) == 0) index[p2] = num_points++;
39 faces_[i][1] = index[p2];
40 bbox_.first = bbox_.first.cwiseMin(p2);
41 bbox_.second = bbox_.second.cwiseMax(p2);
44 if (index.count(p3) == 0) index[p3] = num_points++;
45 faces_[i][2] = index[p3];
46 bbox_.first = bbox_.first.cwiseMin(p3);
47 bbox_.second = bbox_.second.cwiseMax(p3);
49 normals_[i] = v(t.normal).normalized();
52 vertices_.resize(num_points);
53 for (
const auto& p : index) {
54 vertices_[p.second] = p.first;
58 template <
typename vec_t>
61 const std::function<
scalar_t(vec_t)>& dx,
int type)
const {
62 if (type == 0) type = -1;
66 int num_faces = faces_.
size();
67 for (
int i = 0; i < num_faces; ++i) {
68 auto p1 = vertices_[faces_[i][0]];
69 auto p2 = vertices_[faces_[i][1]];
70 auto p3 = vertices_[faces_[i][2]];
74 p1, p2, p3, n, dx,
false);
76 for (
const auto& p : points) {
88 #endif // MEDUSA_BITS_DOMAINS_STLSHAPE_HPP_