util.cpp 3.73 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#include "test_Mesh.hpp"

bool edges_are_optimal(Mesh &m) {
    for (size_t i = 0;i != m.size_edges();++i) {
        EXPECT_TRUE(m.is_locally_optimal(i));
    }

    return true;
}

bool edges_are_valid(Mesh &m) {
12
    // TODO: Test for self-encroachment of triangle edges/verticies
13
    for (size_t i = 0;i != m.size_edges();++i) {
14
15
16
17
18
19
20
21
        const Edge e = m.edge(i);

        EXPECT_TRUE(e.self() == m.edge(e.next()).prev());
        EXPECT_TRUE(e.self() == m.edge(e.prev()).next());
        EXPECT_TRUE(e.self() == m.edge(e.twin()).twin());

        if ((e.twin() != e.self())) {
            EXPECT_TRUE(e.node() == m.edge(m.edge(e.twin()).next()).node());
22
23
            EXPECT_TRUE(m.curve_from_edge(e.self()) == m.curve_from_edge(e.twin()));
            if (m.curve_from_edge(e.self()) != nullptr) {
24
25
26
27
28
29
                EXPECT_TRUE(e.orientation() != m.edge(e.twin()).orientation());
            }

            EXPECT_FALSE(e.node() == m.edge(e.twin()).node());
        }

30
        if (m.curve_from_edge(i) != nullptr) {
31
32
33
            double tol = m.length(i) * FLT_EPSILON;
            if (e.orientation()) {
                Point p0 = m.base(e);
34
                Point p1 = m.curve_from_edge(e.self())->point(m.dart_constraint_from_edge(e.self()).S0);
35
36
37
                EXPECT_NEAR(dist(p0,p1), 0.0, tol);

                p0 = m.tip(e);
38
                p1 = m.curve_from_edge(e.self())->point(m.dart_constraint_from_edge(e.self()).S1);
39
40
41
42
                EXPECT_NEAR(dist(p0,p1), 0.0, tol);
            }
            else {
                Point p0 = m.base(e);
43
                Point p1 = m.curve_from_edge(e.self())->point(m.dart_constraint_from_edge(e.self()).S1);
44
45
46
                EXPECT_NEAR(dist(p0,p1), 0.0, tol);

                p0 = m.tip(e);
47
                p1 = m.curve_from_edge(e.self())->point(m.dart_constraint_from_edge(e.self()).S0);
48
49
50
51
52
                EXPECT_NEAR(dist(p0,p1), 0.0, tol);
            }
        }
    }

53
54
55
56
    for (size_t i = 0; i != m.size_dart_constraints(); ++i) {
        DartConstraint const &d = m.dart_constraint(i);
        EXPECT_EQ(i, d.self());

57
58
        EXPECT_TRUE(d.forward_dart() != SIZE_MAX || d.reverse_dart() != SIZE_MAX || d.self() == 0);

59
60
61
62
63
64
65
66
67
68
69
70
71
        if (d.forward_dart() != SIZE_MAX) {
            Edge const &e = m.edge(d.forward_dart());
            EXPECT_TRUE(e.orientation());
            EXPECT_EQ(i, e.constraint());
        }

        if (d.reverse_dart() != SIZE_MAX) {
            Edge const &e = m.edge(d.reverse_dart());
            EXPECT_FALSE(e.orientation());
            EXPECT_EQ(i, e.constraint());
        }
    }

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    return true;
}

void forced_refinement(Mesh &m, std::string file_name, size_t num_refines) {
    double minq = m.MinimumElementQuality;
    double mine = m.MinimumElementSize;
    double maxe = m.MaximumElementSize;

    m.MinimumElementQuality = DBL_MAX;
    m.MinimumElementSize = 0.0;
    m.MaximumElementSize = DBL_MAX;

    for (size_t i = 0;i < num_refines;++i) {
        bool success = false;
        try {
            success = m.refine_once();
        }
        catch (const std::exception except) {
            throw;
        }
        m.save_as(SAVE_DIR, file_name + "_" + std::to_string(i));

        edges_are_valid(m);
        edges_are_optimal(m);
    }

    m.MinimumElementQuality = minq;
    m.MaximumElementSize = mine;
    m.MaximumElementSize = maxe;
}

std::vector<size_t> map_verticies_to_points(std::vector<std::shared_ptr<Vertex const>> verts, Mesh &m) {
    std::vector<size_t> index;
    index.reserve(verts.size());

    for (size_t i = 0;i != verts.size();++i) {
        for (size_t j = 0;j != m.size_points();++j) {
            if (verts[i]->x() == m.point(j).X && verts[i]->y() == m.point(j).Y) {
                index.push_back(j);
                break;
            }
        }
    }

    return std::move(index);
}