File: nspiralsolidtorus.cpp

package info (click to toggle)
regina-normal 4.5-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 16,824 kB
  • ctags: 7,862
  • sloc: cpp: 63,296; ansic: 12,913; sh: 10,556; perl: 3,294; makefile: 947; python: 188
file content (202 lines) | stat: -rw-r--r-- 6,614 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

/**************************************************************************
 *                                                                        *
 *  Regina - A Normal Surface Theory Calculator                           *
 *  Computational Engine                                                  *
 *                                                                        *
 *  Copyright (c) 1999-2008, 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.                       *
 *                                                                        *
 *  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, write to the Free            *
 *  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,       *
 *  MA 02110-1301, USA.                                                   *
 *                                                                        *
 **************************************************************************/

/* end stub */

#include <vector>
#include "algebra/nabeliangroup.h"
#include "manifold/nhandlebody.h"
#include "subcomplex/nspiralsolidtorus.h"
#include "triangulation/ntriangulation.h"

namespace regina {

NSpiralSolidTorus* NSpiralSolidTorus::clone() const {
    NSpiralSolidTorus* ans = new NSpiralSolidTorus(nTet);
    for (unsigned long i = 0; i < nTet; i++) {
        ans->tet[i] = tet[i];
        ans->vertexRoles[i] = vertexRoles[i];
    }
    return ans;
}

void NSpiralSolidTorus::reverse() {
    NTetrahedron** newTet = new NTetrahedron*[nTet];
    NPerm* newRoles = new NPerm[nTet];

    NPerm switchPerm(3, 2, 1, 0);
    for (unsigned long i = 0; i < nTet; i++) {
        newTet[i] = tet[nTet - 1 - i];
        newRoles[i] = vertexRoles[nTet - 1 - i] * switchPerm;
    }

    delete[] tet;
    delete[] vertexRoles;
    tet = newTet;
    vertexRoles = newRoles;
}

void NSpiralSolidTorus::cycle(unsigned long k) {
    NTetrahedron** newTet = new NTetrahedron*[nTet];
    NPerm* newRoles = new NPerm[nTet];

    for (unsigned long i = 0; i < nTet; i++) {
        newTet[i] = tet[(i + k) % nTet];
        newRoles[i] = vertexRoles[(i + k) % nTet];
    }

    delete[] tet;
    delete[] vertexRoles;
    tet = newTet;
    vertexRoles = newRoles;
}

bool NSpiralSolidTorus::makeCanonical(const NTriangulation* tri) {
    unsigned long i, index;

    unsigned long baseTet = 0;
    unsigned long baseIndex = tri->tetrahedronIndex(tet[0]);
    for (i = 1; i < nTet; i++) {
        index = tri->tetrahedronIndex(tet[i]);
        if (index < baseIndex) {
            baseIndex = index;
            baseTet = i;
        }
    }

    bool reverseAlso = (vertexRoles[baseTet][0] > vertexRoles[baseTet][3]);

    if (baseTet == 0 && (! reverseAlso))
        return false;

    NTetrahedron** newTet = new NTetrahedron*[nTet];
    NPerm* newRoles = new NPerm[nTet];

    if (reverseAlso) {
        // Make baseTet into tetrahedron 0 and reverse.
        NPerm switchPerm(3, 2, 1, 0);
        for (unsigned long i = 0; i < nTet; i++) {
            newTet[i] = tet[(baseTet + nTet - i) % nTet];
            newRoles[i] = vertexRoles[(baseTet + nTet - i) % nTet] *
                switchPerm;
        }
    } else {
        // Make baseTet into tetrahedron 0 but don't reverse.
        for (unsigned long i = 0; i < nTet; i++) {
            newTet[i] = tet[(i + baseTet) % nTet];
            newRoles[i] = vertexRoles[(i + baseTet) % nTet];
        }
    }

    delete[] tet;
    delete[] vertexRoles;
    tet = newTet;
    vertexRoles = newRoles;

    return true;
}

bool NSpiralSolidTorus::isCanonical(const NTriangulation* tri) const {
    if (vertexRoles[0][0] > vertexRoles[0][3])
        return false;

    long baseIndex = tri->tetrahedronIndex(tet[0]);
    for (unsigned long i = 1; i < nTet; i++)
        if (tri->tetrahedronIndex(tet[i]) < baseIndex)
            return false;

    return true;
}

NSpiralSolidTorus* NSpiralSolidTorus::formsSpiralSolidTorus(NTetrahedron* tet,
        NPerm useVertexRoles) {
    NPerm invRoleMap(1, 2, 3, 0);  // Maps upper roles to lower roles.

    NTetrahedron* base = tet;
    NPerm baseRoles(useVertexRoles);

    std::vector<NTetrahedron*> tets;
    std::vector<NPerm> roles;
    stdhash::hash_set<NTetrahedron*, HashPointer> usedTets;

    tets.push_back(tet);
    roles.push_back(useVertexRoles);
    usedTets.insert(tet);

    NTetrahedron* adjTet;
    NPerm adjRoles;

    while (1) {
        // Examine the tetrahedron beyond tet.
        adjTet = tet->getAdjacentTetrahedron(useVertexRoles[0]);
        adjRoles = tet->getAdjacentTetrahedronGluing(useVertexRoles[0]) *
            useVertexRoles * invRoleMap;

        // Check that we haven't hit the boundary.
        if (adjTet == 0)
            return 0;

        if (adjTet == base) {
            // We're back at the beginning of the loop.
            // Check that everything is glued up correctly.
            if (adjRoles != baseRoles)
                return 0;

            // Success!
            break;
        }

        if (usedTets.count(adjTet))
            return 0;

        // Move on to the next tetrahedron.
        tet = adjTet;
        useVertexRoles = adjRoles;

        tets.push_back(tet);
        roles.push_back(useVertexRoles);
        usedTets.insert(tet);
    }

    // We've found a spiralled solid torus.
    NSpiralSolidTorus* ans = new NSpiralSolidTorus(tets.size());
    copy(tets.begin(), tets.end(), ans->tet);
    copy(roles.begin(), roles.end(), ans->vertexRoles);
    return ans;
}

NManifold* NSpiralSolidTorus::getManifold() const {
    return new NHandlebody(1, true);
}

NAbelianGroup* NSpiralSolidTorus::getHomologyH1() const {
    NAbelianGroup* ans = new NAbelianGroup();
    ans->addRank();
    return ans;
}

} // namespace regina