File: skeleton.cpp

package info (click to toggle)
regina-normal 7.4.1-1.1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 154,244 kB
  • sloc: cpp: 295,026; xml: 9,992; sh: 1,344; python: 1,225; perl: 616; ansic: 138; makefile: 26
file content (245 lines) | stat: -rw-r--r-- 9,527 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245

/**************************************************************************
 *                                                                        *
 *  Regina - A Normal Surface Theory Calculator                           *
 *  Computational Engine                                                  *
 *                                                                        *
 *  Copyright (c) 1999-2025, Ben Burton                                   *
 *  For further details contact Ben Burton (bab@debian.org).              *
 *                                                                        *
 *  This program is free software; you can redistribute it and/or         *
 *  modify it under the terms of the GNU General Public License as        *
 *  published by the Free Software Foundation; either version 2 of the    *
 *  License, or (at your option) any later version.                       *
 *                                                                        *
 *  As an exception, when this program is distributed through (i) the     *
 *  App Store by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or     *
 *  (iii) Google Play by Google Inc., then that store may impose any      *
 *  digital rights management, device limits and/or redistribution        *
 *  restrictions that are required by its terms of service.               *
 *                                                                        *
 *  This program is distributed in the hope that it will be useful, but   *
 *  WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *  General Public License for more details.                              *
 *                                                                        *
 *  You should have received a copy of the GNU General Public License     *
 *  along with this program. If not, see <https://www.gnu.org/licenses/>. *
 *                                                                        *
 **************************************************************************/

#include <queue>
#include "maths/rational.h"
#include "triangulation/dim3.h"

#include <iostream>

namespace regina {

void Triangulation<3>::calculateSkeleton() {
    TriangulationBase<3>::calculateSkeleton();

    ideal_ = false;
    standard_ = true;

#if 0
    checkPermutations();
        // Sets valid to false if gluings are mismatched (which should
        // never happen if the Tetrahedron<3> gluing routines have been
        // used correctly)
#endif

    calculateVertexLinks();
        // Sets valid, ideal, Vertex<3>.link,
        //     Vertex<3>.linkEulerChar, Component<3>.ideal,
        //     boundaryComponents, Vertex<3>.boundaryComponent

    // Flesh out the details of each component.
    for (auto v : vertices())
        v->component()->vertices_.push_back(v);
    for (auto e : edges())
        e->component()->edges_.push_back(e);
    for (auto t : triangles())
        t->component()->triangles_.push_back(t);
}

void Triangulation<3>::checkPermutations() {
    for (Tetrahedron<3>* tet : simplices_)
        for (int face = 0; face < 4; face++) {
            Tetrahedron<3> * adjacent = tet->adjacentTetrahedron(face);

            if (adjacent) {
                Perm<4> perm = tet->adjacentGluing(face);

                Perm<4> adj_perm = adjacent->adjacentGluing(perm[face]);

                if (!(perm*adj_perm).isIdentity()) {
                    valid_ = false;

                    // This printing statement is temporary code 
                    // to be removed once enough people have tested it
                    std::cerr << "ERROR: Permutations of adjacent faces "
                                 "do not match in skeleton.cpp" << std::endl;
                }

                if (tet != adjacent->adjacentTetrahedron(perm[face])) {
                    valid_ = false;

                    // This printing statement is temporary code 
                    // to be removed once enough people have tested it
                    std::cerr << "ERROR: Adjacency relations do not match"
                                 " in skeleton.cpp" << std::endl;
                }
            }
        }
}

void Triangulation<3>::calculateVertexLinks() {
    // Begin by calculating Euler characteristics.
    // Here we use the formula:  chi = (2 v_int + v_bdry - f) / 2, which
    // is easily proven with a little arithmetic.

    // Note that Vertex<3>::linkEulerChar is initialised to 0 in
    // the Vertex<3> constructor.

    // Begin by calculating (2 v_int + v_bdry) for each vertex link.
    Vertex<3>* end0;
    Vertex<3>* end1;
    Tetrahedron<3>* tet;
    for (Edge<3>* e : edges()) {
        // Try to compute e->vertex(0) and e->vertex(1), but
        // without calling e->vertex() which will recursively try to
        // recompute the skeleton.
        const EdgeEmbedding<3>& emb = e->front();
        tet = emb.tetrahedron();

        end0 = std::get<0>(tet->faces_)[
            std::get<1>(tet->mappings_)[emb.edge()][0]];
        end1 = std::get<0>(tet->faces_)[
            std::get<1>(tet->mappings_)[emb.edge()][1]];

        if (e->isBoundary()) {
            // Contribute to v_bdry.
            end0->linkEulerChar_++;
            if (e->isValid())
                end1->linkEulerChar_++;
        } else {
            // Contribute to 2 v_int.
            end0->linkEulerChar_ += 2;
            if (e->isValid())
                end1->linkEulerChar_ += 2;
        }
    }

    // Run through each vertex and finalise Euler characteristic, link
    // and more.

    for (Vertex<3>* vertex : vertices()) {
        // Fix the Euler characteristic (subtract f, divide by two).
        vertex->linkEulerChar_ = (vertex->linkEulerChar_
            - static_cast<long>(vertex->degree())) / 2;

        if (vertex->isBoundary()) {
            // We haven't added ideal vertices to the boundary list yet,
            // so this must be real boundary.
            if (vertex->linkEulerChar_ == 1)
                vertex->link_ = Vertex<3>::Link::Disc;
            else {
                vertex->link_ = Vertex<3>::Link::Invalid;
                vertex->whyInvalid_.value |= Vertex<3>::INVALID_LINK;
                valid_ = vertex->component_->valid_ = false;
                standard_ = false;
            }
        } else {
            if (vertex->linkEulerChar_ == 2)
                vertex->link_ = Vertex<3>::Link::Sphere;
            else {
                if (vertex->linkEulerChar_ == 0)
                    vertex->link_ = (vertex->isLinkOrientable() ?
                        Vertex<3>::Link::Torus : Vertex<3>::Link::KleinBottle);
                else {
                    vertex->link_ = Vertex<3>::Link::NonStandardCusp;
                    standard_ = false;
                }

                ideal_ = true;
                vertex->component()->ideal_ = true;

                auto* bc = new BoundaryComponent<3>();
                bc->push_back(vertex);
                bc->orientable_ = vertex->isLinkOrientable();
                vertex->boundaryComponent_ = bc;
                ++nBoundaryFaces_[0];
                boundaryComponents_.push_back(bc);
                vertex->component()->boundaryComponents_.push_back(bc);
            }
        }
    }
}

void Triangulation<3>::calculateBoundaryProperties() const {
    // Make sure the skeleton has been calculated!
    ensureSkeleton();

    bool localTwoSphereBoundaryComponents = false;
    bool localNegativeIdealBoundaryComponents = false;

    for (BoundaryComponent<3>* bc : boundaryComponents_) {
        if (bc->eulerChar() == 2)
            localTwoSphereBoundaryComponents = true;
        else if (bc->isIdeal() && bc->eulerChar() < 0)
            localNegativeIdealBoundaryComponents = true;

        // Stop the search if we've found everything we're looking for.
        if (localTwoSphereBoundaryComponents &&
                localNegativeIdealBoundaryComponents)
            break;
    }

    prop_.twoSphereBoundaryComponents_ = localTwoSphereBoundaryComponents;
    prop_.negativeIdealBoundaryComponents_ =
        localNegativeIdealBoundaryComponents;
}

void Triangulation<3>::cloneSkeleton(const Triangulation& src) {
    TriangulationBase<3>::cloneSkeleton(src);

    ideal_ = src.ideal_;
    standard_ = src.standard_;

    {
        auto me = vertices().begin();
        auto you = src.vertices().begin();
        for ( ; me != vertices().end(); ++me, ++you) {
            (*me)->link_ = (*you)->link_;
            (*me)->linkEulerChar_ = (*you)->linkEulerChar_;
            // Leave linkTri_ as built-on-demand for now.
        }
    }

    {
        auto me = triangles().begin();
        auto you = src.triangles().begin();
        for ( ; me != triangles().end(); ++me, ++you) {
            (*me)->type_ = (*you)->type_;
            (*me)->subtype_ = (*you)->subtype_;
        }
    }

    {
        auto me = components_.begin();
        auto you = src.components_.begin();
        for ( ; me != components_.end(); ++me, ++you) {
            (*me)->ideal_ = (*you)->ideal_;

            for (auto f : (*you)->vertices_)
                (*me)->vertices_.push_back(vertex(f->index()));
            for (auto f : (*you)->edges_)
                (*me)->edges_.push_back(edge(f->index()));
            for (auto f : (*you)->triangles_)
                (*me)->triangles_.push_back(triangle(f->index()));
        }
    }
}

} // namespace regina