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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
|
/**************************************************************************
* *
* 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 <iostream>
#include <iomanip>
#include <sstream>
#include "file/nfile.h"
#include "triangulation/ntriangulation.h"
#include "utilities/xmlutils.h"
// Property IDs:
// #define PROPID_EXTRA_TOPOLOGY 1 -- Do not use!
#define PROPID_H1 10
#define PROPID_H1REL 11
#define PROPID_H1BDRY 12
#define PROPID_H2 13
#define PROPID_FUNDAMENTALGROUP 14
// Property IDs for properties relating to normal surfaces:
#define PROPID_ZEROEFFICIENT 201
#define PROPID_SPLITTINGSURFACE 202
namespace regina {
void NTriangulation::clearAllProperties() {
if (calculatedSkeleton) {
deleteSkeleton();
calculatedSkeleton = false;
}
fundamentalGroup.clear();
H1.clear();
H1Rel.clear();
H1Bdry.clear();
H2.clear();
zeroEfficient.clear();
splittingSurface.clear();
twoSphereBoundaryComponents.clear();
negativeIdealBoundaryComponents.clear();
threeSphere.clear();
turaevViroCache.clear();
}
void NTriangulation::writeTextLong(std::ostream& out) const {
if (! calculatedSkeleton)
calculateSkeleton();
out << "Size of the skeleton:\n";
out << " Tetrahedra: " << tetrahedra.size() << '\n';
out << " Faces: " << faces.size() << '\n';
out << " Edges: " << edges.size() << '\n';
out << " Vertices: " << vertices.size() << '\n';
out << '\n';
NTetrahedron* tet;
NTetrahedron* adjTet;
unsigned tetPos;
int face, vertex, start, end;
NPerm adjPerm;
out << "Tetrahedron gluing:\n";
out << " Tet | glued to: (012) (013) (023) (123)\n";
out << " -----+-------------------------------------------------------\n";
for (tetPos=0; tetPos<tetrahedra.size(); tetPos++) {
tet = tetrahedra[tetPos];
out << " " << std::setw(3) << tetPos << " | ";
for (face=3; face>=0; face--) {
out << " ";
adjTet = tet->getAdjacentTetrahedron(face);
if (! adjTet)
out << " boundary";
else {
adjPerm = tet->getAdjacentTetrahedronGluing(face);
out << std::setw(3) << tetrahedronIndex(adjTet) << " (";
for (vertex=0; vertex<4; vertex++) {
if (vertex == face) continue;
out << adjPerm[vertex];
}
out << ")";
}
}
out << '\n';
}
out << '\n';
out << "Vertices:\n";
out << " Tet | vertex: 0 1 2 3\n";
out << " -----+--------------------------\n";
for (tetPos=0; tetPos<tetrahedra.size(); tetPos++) {
tet = tetrahedra[tetPos];
out << " " << std::setw(3) << tetPos << " | ";
for (vertex=0; vertex<4; vertex++)
out << ' ' << std::setw(3) <<
vertexIndex(tet->getVertex(vertex));
out << '\n';
}
out << '\n';
out << "Edges:\n";
out << " Tet | edge: 01 02 03 12 13 23\n";
out << " -----+--------------------------------\n";
for (tetPos=0; tetPos<tetrahedra.size(); tetPos++) {
tet = tetrahedra[tetPos];
out << " " << std::setw(3) << tetPos << " | ";
for (start=0; start<4; start++)
for (end=start+1; end<4; end++)
out << ' ' << std::setw(3)
<< edgeIndex(tet->getEdge(edgeNumber[start][end]));
out << '\n';
}
out << '\n';
out << "Faces:\n";
out << " Tet | face: 012 013 023 123\n";
out << " -----+------------------------\n";
for (tetPos=0; tetPos<tetrahedra.size(); tetPos++) {
tet = tetrahedra[tetPos];
out << " " << std::setw(3) << tetPos << " | ";
for (face=3; face>=0; face--)
out << ' ' << std::setw(3) << faceIndex(tet->getFace(face));
out << '\n';
}
out << '\n';
}
void NTriangulation::writePacket(NFile& out) const {
NTetrahedron* tet;
NTetrahedron* adjTet;
NPerm adjPerm;
int face;
long tetPos, adjPos;
// Write the number of tetrahedra.
out.writeULong(tetrahedra.size());
// Write the name of each tetrahedron.
TetrahedronIterator it;
for (it = tetrahedra.begin(); it != tetrahedra.end(); it++)
out.writeString((*it)->getDescription());
// Write the joins to take place.
tetPos = 0;
for (it = tetrahedra.begin(); it != tetrahedra.end(); it++) {
tet = *it;
for (face=0; face<4; face++) {
adjTet = tet->getAdjacentTetrahedron(face);
if (adjTet) {
adjPos = tetrahedronIndex(adjTet);
adjPerm = tet->getAdjacentTetrahedronGluing(face);
if (adjPos > tetPos ||
(adjPos == tetPos && adjPerm[face] > face)) {
// Write this gluing to file.
out.writeLong(tetPos);
out.writeInt(face);
out.writeLong(adjPos);
out.writeChar(adjPerm.getPermCode());
}
}
}
tetPos++;
}
// Signify no more joins to take place.
out.writeLong(-1);
// Write the properties.
std::streampos bookmark(0);
if (fundamentalGroup.known()) {
bookmark = out.writePropertyHeader(PROPID_FUNDAMENTALGROUP);
fundamentalGroup.value()->writeToFile(out);
out.writePropertyFooter(bookmark);
}
if (H1.known()) {
bookmark = out.writePropertyHeader(PROPID_H1);
H1.value()->writeToFile(out);
out.writePropertyFooter(bookmark);
}
if (H1Rel.known()) {
bookmark = out.writePropertyHeader(PROPID_H1REL);
H1Rel.value()->writeToFile(out);
out.writePropertyFooter(bookmark);
}
if (H1Bdry.known()) {
bookmark = out.writePropertyHeader(PROPID_H1BDRY);
H1Bdry.value()->writeToFile(out);
out.writePropertyFooter(bookmark);
}
if (H2.known()) {
bookmark = out.writePropertyHeader(PROPID_H2);
H2.value()->writeToFile(out);
out.writePropertyFooter(bookmark);
}
if (zeroEfficient.known()) {
bookmark = out.writePropertyHeader(PROPID_ZEROEFFICIENT);
out.writeBool(zeroEfficient.value());
out.writePropertyFooter(bookmark);
}
if (splittingSurface.known()) {
bookmark = out.writePropertyHeader(PROPID_SPLITTINGSURFACE);
out.writeBool(splittingSurface.value());
out.writePropertyFooter(bookmark);
}
out.writeAllPropertiesFooter();
}
NTriangulation* NTriangulation::readPacket(NFile& in, NPacket* /* parent */) {
NTriangulation* triang = new NTriangulation();
NTetrahedron* tet;
// Create new tetrahedra.
unsigned long nTet = in.readULong();
for (unsigned long i=0; i<nTet; i++) {
tet = new NTetrahedron();
tet->setDescription(in.readString());
triang->addTetrahedron(tet);
}
// Read in the joins.
long tetPos, altPos;
int face;
NPerm adjPerm;
tetPos = in.readLong();
while (tetPos >= 0) {
face = in.readInt();
altPos = in.readLong();
adjPerm = in.readChar();
triang->tetrahedra[tetPos]->joinTo(face,
triang->tetrahedra[altPos], NPerm(adjPerm));
tetPos = in.readLong();
}
// Read in properties.
in.readProperties(triang);
// Return the completed triangulation.
return triang;
}
void NTriangulation::readIndividualProperty(NFile& infile, unsigned propType) {
if (propType == PROPID_FUNDAMENTALGROUP)
fundamentalGroup = NGroupPresentation::readFromFile(infile);
if (propType == PROPID_H1)
H1 = NAbelianGroup::readFromFile(infile);
if (propType == PROPID_H1REL)
H1Rel = NAbelianGroup::readFromFile(infile);
if (propType == PROPID_H1BDRY)
H1Bdry = NAbelianGroup::readFromFile(infile);
if (propType == PROPID_H2)
H2 = NAbelianGroup::readFromFile(infile);
if (propType == PROPID_ZEROEFFICIENT)
zeroEfficient = infile.readBool();
if (propType == PROPID_SPLITTINGSURFACE)
splittingSurface = infile.readBool();
}
void NTriangulation::writeXMLPacketData(std::ostream& out) const {
using regina::xml::xmlEncodeSpecialChars;
using regina::xml::xmlValueTag;
// Write the tetrahedron gluings.
TetrahedronIterator it;
NTetrahedron* adjTet;
int face;
out << " <tetrahedra ntet=\"" << tetrahedra.size() << "\">\n";
for (it = tetrahedra.begin(); it != tetrahedra.end(); it++) {
out << " <tet desc=\"" <<
xmlEncodeSpecialChars((*it)->getDescription()) << "\"> ";
for (face = 0; face < 4; face++) {
adjTet = (*it)->getAdjacentTetrahedron(face);
if (adjTet) {
out << tetrahedronIndex(adjTet) << ' '
<< static_cast<int>((*it)->
getAdjacentTetrahedronGluing(face).getPermCode())
<< ' ';
} else
out << "-1 -1 ";
}
out << "</tet>\n";
}
out << " </tetrahedra>\n";
if (fundamentalGroup.known()) {
out << " <fundgroup>\n";
fundamentalGroup.value()->writeXMLData(out);
out << " </fundgroup>\n";
}
if (H1.known()) {
out << " <H1>";
H1.value()->writeXMLData(out);
out << "</H1>\n";
}
if (H1Rel.known()) {
out << " <H1Rel>";
H1Rel.value()->writeXMLData(out);
out << "</H1Rel>\n";
}
if (H1Bdry.known()) {
out << " <H1Bdry>";
H1Bdry.value()->writeXMLData(out);
out << "</H1Bdry>\n";
}
if (H2.known()) {
out << " <H2>";
H2.value()->writeXMLData(out);
out << "</H2>\n";
}
if (twoSphereBoundaryComponents.known())
out << " " << xmlValueTag("twosphereboundarycomponents",
twoSphereBoundaryComponents.value()) << '\n';
if (negativeIdealBoundaryComponents.known())
out << " " << xmlValueTag("negativeidealboundarycomponents",
negativeIdealBoundaryComponents.value()) << '\n';
if (zeroEfficient.known())
out << " " << xmlValueTag("zeroeff", zeroEfficient.value())
<< '\n';
if (splittingSurface.known())
out << " " << xmlValueTag("splitsfce", splittingSurface.value())
<< '\n';
if (threeSphere.known())
out << " " << xmlValueTag("threesphere", threeSphere.value()) << '\n';
if (! turaevViroCache.empty()) {
for (TuraevViroSet::const_iterator it = turaevViroCache.begin();
it != turaevViroCache.end(); it++)
out << " <turaevviro r=\"" << (*it).first.first
<< "\" root=\"" << (*it).first.second
<< "\" value=\"" << (*it).second << "\"/>\n";
}
}
NTriangulation* NTriangulation::enterTextTriangulation(std::istream& in,
std::ostream& out) {
NTriangulation* triang = new NTriangulation();
NTetrahedron* tet;
long nTet;
// Create new tetrahedra.
out << "Number of tetrahedra: ";
in >> nTet;
while (nTet < 0) {
out << "The number of tetrahedra must be non-negative.\n";
out << "Number of tetrahedra: ";
in >> nTet;
}
out << '\n';
for (long i=0; i<nTet; i++)
triang->addTetrahedron(new NTetrahedron());
// Read in the joins.
long tetPos, altPos;
int face, altFace;
NTetrahedron* altTet;
int vertices[6];
out << "Tetrahedra are numbered from 0 to " << nTet-1 << ".\n";
out << "Vertices are numbered from 0 to 3.\n";
out << "Enter in the face gluings one at a time.\n";
out << '\n';
while(1) {
out << "Enter two tetrahedra to glue, separated by a space, or ";
out << "-1 if finished: ";
in >> tetPos;
if (tetPos < 0) break;
in >> altPos;
if (altPos < 0) break;
if (tetPos >= nTet || altPos >= nTet) {
out << "Tetrahedron identifiers must be between 0 and "
<< nTet-1 << " inclusive.\n";
continue;
}
tet = triang->tetrahedra[tetPos];
altTet = triang->tetrahedra[altPos];
out << "Enter the three vertices of the first tetrahedron ("
<< tetPos << "), separated by spaces,\n";
out << " that will form one face of the gluing: ";
in >> vertices[0] >> vertices[1] >> vertices[2];
out << "Enter the corresponding three vertices of the second tetrahedron ("
<< altPos << "): ";
in >> vertices[3] >> vertices[4] >> vertices[5];
if (vertices[3] < 0 || vertices[3] > 3 || vertices[4] < 0
|| vertices[4] > 3 || vertices[5] < 0 || vertices[5] > 3
|| vertices[0] < 0 || vertices[0] > 3 || vertices[1] < 0
|| vertices[1] > 3 || vertices[2] < 0 || vertices[2] > 3) {
out << "Vertices must be between 0 and 3 inclusive.\n";
continue;
}
if (vertices[0] == vertices[1] || vertices[1] == vertices[2]
|| vertices[2] == vertices[0]) {
out << "The three vertices for tetrahedron " << tetPos
<< " must be different.\n";
continue;
}
if (vertices[3] == vertices[4] || vertices[4] == vertices[5]
|| vertices[5] == vertices[3]) {
out << "The three vertices for tetrahedron " << altPos
<< " must be different.\n";
continue;
}
face = 6 - vertices[0] - vertices[1] - vertices[2];
altFace = 6 - vertices[3] - vertices[4] - vertices[5];
if (face == altFace && tetPos == altPos) {
out << "You cannot glue a face to itself.\n";
continue;
}
if (tet->getAdjacentTetrahedron(face) ||
altTet->getAdjacentTetrahedron(altFace)) {
out << "One of these faces is already glued to something else.\n";
continue;
}
tet->joinTo(face, altTet,
NPerm(vertices[0], vertices[3], vertices[1], vertices[4],
vertices[2], vertices[5], face, altFace));
out << '\n';
}
triang->gluingsHaveChanged();
out << "Finished reading gluings.\n";
out << "The triangulation has been successfully created.\n";
out << '\n';
// Return the completed triangulation.
return triang;
}
long NTriangulation::getEulerCharManifold() const {
// Begin with V - E + F - T.
// This call to getEulerCharTri() also ensures that the skeleton has
// been calculated.
long ans = getEulerCharTri();
// Truncate any ideal vertices.
for (BoundaryComponentIterator it = boundaryComponents.begin();
it != boundaryComponents.end(); ++it)
if ((*it)->isIdeal())
ans += (*it)->getEulerCharacteristic() - 1;
// If we have an invalid triangulation, we need to locate non-standard
// boundary vertices and invalid edges, and truncate those unwanted bits
// also.
if (! valid) {
for (VertexIterator it = vertices.begin(); it != vertices.end(); ++it)
if ((*it)->getLink() == NVertex::NON_STANDARD_BDRY)
ans += (*it)->getLinkEulerCharacteristic() - 1;
for (EdgeIterator it = edges.begin(); it != edges.end(); ++it)
if (! (*it)->isValid())
++ans;
}
return ans;
}
void NTriangulation::deleteTetrahedra() {
for_each(tetrahedra.begin(), tetrahedra.end(), FuncDelete<NTetrahedron>());
tetrahedra.clear();
}
void NTriangulation::deleteSkeleton() {
for_each(vertices.begin(), vertices.end(), FuncDelete<NVertex>());
for_each(edges.begin(), edges.end(), FuncDelete<NEdge>());
for_each(faces.begin(), faces.end(), FuncDelete<NFace>());
for_each(components.begin(), components.end(), FuncDelete<NComponent>());
for_each(boundaryComponents.begin(), boundaryComponents.end(),
FuncDelete<NBoundaryComponent>());
vertices.clear();
edges.clear();
faces.clear();
components.clear();
boundaryComponents.clear();
}
void NTriangulation::cloneFrom(const NTriangulation& X) {
ChangeEventBlock(this);
removeAllTetrahedra();
TetrahedronIterator it;
for (it = X.tetrahedra.begin(); it != X.tetrahedra.end(); it++)
addTetrahedron(new NTetrahedron((*it)->getDescription()));
// Make the gluings.
long tetPos, adjPos;
NTetrahedron* tet;
NTetrahedron* adjTet;
NPerm adjPerm;
int face;
tetPos = 0;
for (it = X.tetrahedra.begin(); it != X.tetrahedra.end(); it++) {
tet = *it;
for (face=0; face<4; face++) {
adjTet = tet->getAdjacentTetrahedron(face);
if (adjTet) {
adjPos = X.tetrahedronIndex(adjTet);
adjPerm = tet->getAdjacentTetrahedronGluing(face);
if (adjPos > tetPos ||
(adjPos == tetPos && adjPerm[face] > face)) {
tetrahedra[tetPos]->joinTo(face,
tetrahedra[adjPos], adjPerm);
}
}
}
tetPos++;
}
gluingsHaveChanged();
// Properties:
if (X.fundamentalGroup.known())
fundamentalGroup= new NGroupPresentation(*X.fundamentalGroup.value());
if (X.H1.known())
H1 = new NAbelianGroup(*(X.H1.value()));
if (X.H1Rel.known())
H1Rel = new NAbelianGroup(*(X.H1Rel.value()));
if (X.H1Bdry.known())
H1Bdry = new NAbelianGroup(*(X.H1Bdry.value()));
if (X.H2.known())
H2 = new NAbelianGroup(*(X.H2.value()));
twoSphereBoundaryComponents = X.twoSphereBoundaryComponents;
negativeIdealBoundaryComponents = X.negativeIdealBoundaryComponents;
zeroEfficient = X.zeroEfficient;
splittingSurface = X.splittingSurface;
threeSphere = X.threeSphere;
turaevViroCache = X.turaevViroCache;
}
void NTriangulation::insertTriangulation(const NTriangulation& X) {
ChangeEventBlock(this);
unsigned long norig = getNumberOfTetrahedra();
TetrahedronIterator it;
for (it = X.tetrahedra.begin(); it != X.tetrahedra.end(); it++)
addTetrahedron(new NTetrahedron((*it)->getDescription()));
// Make the gluings.
long tetPos, adjPos;
NTetrahedron* tet;
NTetrahedron* adjTet;
NPerm adjPerm;
int face;
tetPos = 0;
for (it = X.tetrahedra.begin(); it != X.tetrahedra.end(); it++) {
tet = *it;
for (face=0; face<4; face++) {
adjTet = tet->getAdjacentTetrahedron(face);
if (adjTet) {
adjPos = X.tetrahedronIndex(adjTet);
adjPerm = tet->getAdjacentTetrahedronGluing(face);
if (adjPos > tetPos ||
(adjPos == tetPos && adjPerm[face] > face)) {
tetrahedra[norig + tetPos]->joinTo(face,
tetrahedra[norig + adjPos], adjPerm);
}
}
}
tetPos++;
}
gluingsHaveChanged();
}
void NTriangulation::insertConstruction(unsigned long nTetrahedra,
const int adjacencies[][4], const int gluings[][4][4]) {
if (nTetrahedra == 0)
return;
NTetrahedron** tet = new NTetrahedron*[nTetrahedra];
unsigned i, j;
NPerm p;
for (i = 0; i < nTetrahedra; i++)
tet[i] = new NTetrahedron();
for (i = 0; i < nTetrahedra; i++)
for (j = 0; j < 4; j++)
if (adjacencies[i][j] >= 0 &&
! tet[i]->getAdjacentTetrahedron(j)) {
p = NPerm(gluings[i][j][0], gluings[i][j][1],
gluings[i][j][2], gluings[i][j][3]);
tet[i]->joinTo(j, tet[adjacencies[i][j]], p);
}
// It's not until here that we actually modify this triangulation.
ChangeEventBlock(this);
for (i = 0; i < nTetrahedra; i++)
addTetrahedron(tet[i]);
delete[] tet;
}
std::string NTriangulation::dumpConstruction() const {
std::ostringstream ans;
ans <<
"/**\n";
if (! getPacketLabel().empty())
ans <<
" * Triangulation: " << getPacketLabel() << "\n";
ans <<
" * Code automatically generated by dumpConstruction().\n"
" */\n"
"\n";
if (tetrahedra.empty()) {
ans <<
"/* This triangulation is empty. No code is being generated. */\n";
return ans.str();
}
ans <<
"/**\n"
" * The following arrays describe the individual gluings of\n"
" * tetrahedron faces.\n"
" */\n"
"\n";
unsigned long nTetrahedra = tetrahedra.size();
NTetrahedron* tet;
NPerm p;
unsigned long t;
int f, i;
ans << "const int adjacencies[" << nTetrahedra << "][4] = {\n";
for (t = 0; t < nTetrahedra; t++) {
tet = tetrahedra[t];
ans << " { ";
for (f = 0; f < 4; f++) {
if (tet->getAdjacentTetrahedron(f)) {
ans << tetrahedronIndex(tet->getAdjacentTetrahedron(f));
} else
ans << "-1";
if (f < 3)
ans << ", ";
else if (t != nTetrahedra - 1)
ans << "},\n";
else
ans << "}\n";
}
}
ans << "};\n\n";
ans << "const int gluings[" << nTetrahedra << "][4][4] = {\n";
for (t = 0; t < nTetrahedra; t++) {
tet = tetrahedra[t];
ans << " { ";
for (f = 0; f < 4; f++) {
if (tet->getAdjacentTetrahedron(f)) {
p = tet->getAdjacentTetrahedronGluing(f);
ans << "{ ";
for (i = 0; i < 4; i++) {
ans << p[i];
if (i < 3)
ans << ", ";
else
ans << " }";
}
} else
ans << "{ 0, 0, 0, 0 }";
if (f < 3)
ans << ", ";
else if (t != nTetrahedra - 1)
ans << " },\n";
else
ans << " }\n";
}
}
ans << "};\n\n";
ans <<
"/**\n"
" * The following code actually constructs a triangulation based on\n"
" * the information stored in the arrays above.\n"
" */\n"
"\n"
"NTriangulation tri;\n"
"tri.insertConstruction(" << nTetrahedra << ", adjacencies, gluings);\n"
"\n";
return ans.str();
}
} // namespace regina
|