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
|
/**************************************************************************
* *
* 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 <set>
#include <vector>
#include "algebra/abeliangroup.h"
#include "manifold/handlebody.h"
#include "subcomplex/spiralsolidtorus.h"
#include "triangulation/dim3.h"
namespace regina {
SpiralSolidTorus& SpiralSolidTorus::operator = (const SpiralSolidTorus& src) {
// std::copy() exhibits undefined behaviour in the case of self-assignment.
if (std::addressof(src) == this)
return *this;
if (nTet_ != src.nTet_) {
delete[] tet_;
delete[] vertexRoles_;
nTet_ = src.nTet_;
tet_ = new Tetrahedron<3>*[nTet_];
vertexRoles_ = new Perm<4>[nTet_];
}
std::copy(src.tet_, src.tet_ + nTet_, tet_);
std::copy(src.vertexRoles_, src.vertexRoles_ + nTet_, vertexRoles_);
return *this;
}
void SpiralSolidTorus::reverse() {
auto* newTet = new Tetrahedron<3>*[nTet_];
auto* newRoles = new Perm<4>[nTet_];
Perm<4> switchPerm(3, 2, 1, 0);
for (size_t 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 SpiralSolidTorus::cycle(size_t k) {
auto* newTet = new Tetrahedron<3>*[nTet_];
auto* newRoles = new Perm<4>[nTet_];
for (size_t 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 SpiralSolidTorus::makeCanonical() {
size_t i, index;
size_t baseTet = 0;
size_t baseIndex = tet_[0]->index();
for (i = 1; i < nTet_; i++) {
index = tet_[i]->index();
if (index < baseIndex) {
baseIndex = index;
baseTet = i;
}
}
bool reverseAlso = (vertexRoles_[baseTet][0] > vertexRoles_[baseTet][3]);
if (baseTet == 0 && (! reverseAlso))
return false;
auto* newTet = new Tetrahedron<3>*[nTet_];
auto* newRoles = new Perm<4>[nTet_];
if (reverseAlso) {
// Make baseTet into tetrahedron 0 and reverse.
Perm<4> switchPerm(3, 2, 1, 0);
for (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 (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 SpiralSolidTorus::isCanonical() const {
if (vertexRoles_[0][0] > vertexRoles_[0][3])
return false;
size_t baseIndex = tet_[0]->index();
for (size_t i = 1; i < nTet_; i++)
if (tet_[i]->index() < baseIndex)
return false;
return true;
}
std::unique_ptr<SpiralSolidTorus> SpiralSolidTorus::recognise(
Tetrahedron<3>* tet, Perm<4> useVertexRoles) {
Perm<4> invRoleMap(1, 2, 3, 0); // Maps upper roles to lower roles.
Tetrahedron<3>* base = tet;
Perm<4> baseRoles(useVertexRoles);
std::vector<Tetrahedron<3>*> tets;
std::vector<Perm<4>> roles;
std::set<Tetrahedron<3>*> usedTets;
tets.push_back(tet);
roles.push_back(useVertexRoles);
usedTets.insert(tet);
Tetrahedron<3>* adjTet;
Perm<4> adjRoles;
while (true) {
// Examine the tetrahedron beyond tet.
adjTet = tet->adjacentTetrahedron(useVertexRoles[0]);
adjRoles = tet->adjacentGluing(useVertexRoles[0]) *
useVertexRoles * invRoleMap;
// Check that we haven't hit the boundary.
if (! adjTet)
return nullptr;
if (adjTet == base) {
// We're back at the beginning of the loop.
// Check that everything is glued up correctly.
if (adjRoles != baseRoles)
return nullptr;
// Success!
break;
}
if (usedTets.count(adjTet))
return nullptr;
// 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.
std::unique_ptr<SpiralSolidTorus> ans(new SpiralSolidTorus(tets.size()));
std::copy(tets.begin(), tets.end(), ans->tet_);
std::copy(roles.begin(), roles.end(), ans->vertexRoles_);
return ans;
}
std::unique_ptr<Manifold> SpiralSolidTorus::manifold() const {
return std::make_unique<Handlebody>(1);
}
AbelianGroup SpiralSolidTorus::homology() const {
return AbelianGroup(1);
}
void SpiralSolidTorus::writeTextShort(std::ostream& out) const {
out << nTet_ << "-tetrahedron spiralled solid torus, tetrahedra ";
for (size_t i = 0; i < nTet_; ++i) {
if (i > 0)
out << ", ";
out << tet_[i]->index() << " (" << vertexRoles_[i] << ')';
}
}
} // namespace regina
|