File: nlayering.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-- 7,867 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 "triangulation/ntetrahedron.h"
#include "subcomplex/nlayering.h"

namespace regina {

NLayering::NLayering(NTetrahedron* bdry0, NPerm roles0, NTetrahedron* bdry1,
        NPerm roles1) : size(0), reln(1, 0, 0, 1) {
    oldBdryTet[0] = newBdryTet[0] = bdry0;
    oldBdryTet[1] = newBdryTet[1] = bdry1;

    oldBdryRoles[0] = newBdryRoles[0] = roles0;
    oldBdryRoles[1] = newBdryRoles[1] = roles1;
}

bool NLayering::extendOne() {
    // See if we move to a common new tetrahedron.
    // Also make sure this really is a new tetrahedron, so we don't get
    // stuck in a loop.
    NTetrahedron* next = newBdryTet[0]->getAdjacentTetrahedron(
        newBdryRoles[0][3]);

    if (next == 0 || next == newBdryTet[0] || next == newBdryTet[1] ||
            next == oldBdryTet[0] || next == oldBdryTet[1])
        return false;
    if (next != newBdryTet[1]->getAdjacentTetrahedron(newBdryRoles[1][3]))
        return false;

    // Get the mappings from the boundary vertex roles to the new tetrahedron
    // vertices.
    NPerm cross0 = newBdryTet[0]->getAdjacentTetrahedronGluing(
        newBdryRoles[0][3]) * newBdryRoles[0];
    NPerm cross1 = newBdryTet[1]->getAdjacentTetrahedronGluing(
        newBdryRoles[1][3]) * newBdryRoles[1];

    // Is it actually a layering?
    if (cross1 == cross0 * NPerm(3, 2, 1, 0)) {
        // We're layering over the edge joining vertex roles 1 and 2.
        size++;

        newBdryRoles[0] = cross0 * NPerm(0, 1, 3, 2);
        newBdryRoles[1] = cross0 * NPerm(3, 2, 0, 1);

        newBdryTet[0] = newBdryTet[1] = next;

        // new a = old a         = reln00 p + reln01 q
        // new b = old a + old b = (reln00 + reln10) p + (reln01 + reln11) q
        reln[1][0] += reln[0][0];
        reln[1][1] += reln[0][1];

        return true;
    } else if (cross1 == cross0 * NPerm(2, 3, 0, 1)) {
        // We're layering over the edge joining vertex roles 0 and 2.
        size++;

        newBdryRoles[0] = cross0 * NPerm(0, 1, 3, 2);
        newBdryRoles[1] = cross0 * NPerm(2, 3, 1, 0);

        newBdryTet[0] = newBdryTet[1] = next;

        // new a = old a         = reln00 p + reln01 q
        // new b = old b - old a = (reln10 - reln00) p + (reln11 - reln01) q
        reln[1][0] -= reln[0][0];
        reln[1][1] -= reln[0][1];

        return true;
    } else if (cross1 == cross0 * NPerm(1, 0, 3, 2)) {
        // We're layering over the edge joining vertex roles 0 and 1.
        size++;

        newBdryRoles[0] = cross0 * NPerm(0, 3, 2, 1);
        newBdryRoles[1] = cross0 * NPerm(1, 2, 3, 0);

        newBdryTet[0] = newBdryTet[1] = next;

        // new a = old a - old b = (reln00 - reln10) p + (reln01 - reln11) q
        // new b = old b         = reln10 p + reln11 q
        reln[0][0] -= reln[1][0];
        reln[0][1] -= reln[1][1];

        return true;
    }

    // It's not a layering at all.
    return false;
}

unsigned long NLayering::extend() {
    unsigned long added = 0;

    while (extendOne())
        added++;

    return added;
}

bool NLayering::matchesTop(NTetrahedron* upperBdry0, NPerm upperRoles0,
        NTetrahedron* upperBdry1, NPerm upperRoles1, NMatrix2& upperReln)
        const {
    // We can cut half our cases by assuming that upperBdry0 meets with
    // newBdryTet[0] and that upperBdry1 meets with newBdryTet[1].
    bool rot180;
    if (upperBdry0->getAdjacentTetrahedron(upperRoles0[3]) == newBdryTet[1] &&
            upperBdry0->getAdjacentFace(upperRoles0[3]) == newBdryRoles[1][3]) {
        // If it does match, it's the opposite matching (upperBdry0 with
        // newBdryTet[1] and vice versa).  Switch them and remember what
        // we did.
        NTetrahedron* tmpTet = upperBdry0;
        upperBdry0 = upperBdry1;
        upperBdry1 = tmpTet;

        NPerm tmpPerm = upperRoles0;
        upperRoles0 = upperRoles1;
        upperRoles1 = tmpPerm;

        rot180 = true;
    } else {
        // If it does match, it's what we'd like.
        rot180 = false;
    }

    // Do we meet the right tetrahedra and faces?
    if (upperBdry0->getAdjacentTetrahedron(upperRoles0[3]) != newBdryTet[0])
        return false;
    if (upperBdry0->getAdjacentFace(upperRoles0[3]) != newBdryRoles[0][3])
        return false;
    if (upperBdry1->getAdjacentTetrahedron(upperRoles1[3]) != newBdryTet[1])
        return false;
    if (upperBdry1->getAdjacentFace(upperRoles1[3]) != newBdryRoles[1][3])
        return false;

    // Find the mapping from the upper vertex roles to the boundary
    // vertex roles.  Verify that this mapping is consistent for both faces.
    NPerm cross = newBdryRoles[0].inverse() * upperBdry0->
        getAdjacentTetrahedronGluing(upperRoles0[3]) * upperRoles0;
    if (cross != newBdryRoles[1].inverse() * upperBdry1->
            getAdjacentTetrahedronGluing(upperRoles1[3]) * upperRoles1)
        return false;

    // It's a match!  Run through the six possible mappings to get the
    // relationship matrix correct.
    if (cross == NPerm(0, 1, 2, 3)) {
        // It's the identity.
        upperReln = reln;
    } else if (cross == NPerm(0, 2, 1, 3)) {
        // new a = + old b
        // new b = + old a
        upperReln = NMatrix2(0, 1, 1, 0) * reln;
    } else if (cross == NPerm(1, 0, 2, 3)) {
        // new a = - old a
        // new b = - old a + old b
        upperReln = NMatrix2(-1, 0, -1, 1) * reln;
    } else if (cross == NPerm(1, 2, 0, 3)) {
        // new a = - old a + old b
        // new b = - old a
        upperReln = NMatrix2(-1, 1, -1, 0) * reln;
    } else if (cross == NPerm(2, 0, 1, 3)) {
        // new a = - old b
        // new b = + old a - old b
        upperReln = NMatrix2(0, -1, 1, -1) * reln;
    } else if (cross == NPerm(2, 1, 0, 3)) {
        // new a = + old a - old b
        // new b = - old b
        upperReln = NMatrix2(1, -1, 0, -1) * reln;
    }

    // Don't forget to account for the 180 degree rotation if it
    // happened.
    if (rot180)
        upperReln.negate();

    return true;
}

} // namespace regina