~ubuntu-branches/ubuntu/vivid/regina-normal/vivid

« back to all changes in this revision

Viewing changes to engine/foreign/recogniser.cpp

  • Committer: Package Import Robot
  • Author(s): Ben Burton
  • Date: 2014-08-29 17:37:46 UTC
  • mfrom: (19.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140829173746-igmqc9b67y366a7u
Tags: 4.96-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/**************************************************************************
3
 
 *                                                                        *
4
 
 *  Regina - A Normal Surface Theory Calculator                           *
5
 
 *  Computational Engine                                                  *
6
 
 *                                                                        *
7
 
 *  Copyright (c) 1999-2013, Ben Burton                                   *
8
 
 *  For further details contact Ben Burton (bab@debian.org).              *
9
 
 *                                                                        *
10
 
 *  This program is free software; you can redistribute it and/or         *
11
 
 *  modify it under the terms of the GNU General Public License as        *
12
 
 *  published by the Free Software Foundation; either version 2 of the    *
13
 
 *  License, or (at your option) any later version.                       *
14
 
 *                                                                        *
15
 
 *  As an exception, when this program is distributed through (i) the     *
16
 
 *  App Store by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or     *
17
 
 *  (iii) Google Play by Google Inc., then that store may impose any      *
18
 
 *  digital rights management, device limits and/or redistribution        *
19
 
 *  restrictions that are required by its terms of service.               *
20
 
 *                                                                        *
21
 
 *  This program is distributed in the hope that it will be useful, but   *
22
 
 *  WITHOUT ANY WARRANTY; without even the implied warranty of            *
23
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
24
 
 *  General Public License for more details.                              *
25
 
 *                                                                        *
26
 
 *  You should have received a copy of the GNU General Public             *
27
 
 *  License along with this program; if not, write to the Free            *
28
 
 *  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,       *
29
 
 *  MA 02110-1301, USA.                                                   *
30
 
 *                                                                        *
31
 
 **************************************************************************/
32
 
 
33
 
/* end stub */
34
 
 
35
 
#include <fstream>
36
 
 
37
 
#include "foreign/recogniser.h"
38
 
#include "triangulation/ntriangulation.h"
39
 
 
40
 
namespace regina {
41
 
 
42
 
namespace {
43
 
    // Anonymous routine to write to the given output stream.
44
 
    //
45
 
    // PRE: All preconditions for writeRecogniser() have already been
46
 
    // tested, and are known to be met.
47
 
    bool writeRecogniser(std::ostream& out, NTriangulation& tri) {
48
 
        // Write the header.
49
 
        out << "triangulation" << std::endl;
50
 
 
51
 
        // Write face gluings.
52
 
        NTriangle* f;
53
 
        NTetrahedron* tet;
54
 
        NPerm4 vert;
55
 
        for (unsigned i = 0; i < tri.getNumberOfTriangles(); ++i) {
56
 
            f = tri.getTriangle(i);
57
 
 
58
 
            tet = f->getEmbedding(0).getTetrahedron();
59
 
            vert = f->getEmbedding(0).getVertices();
60
 
            out << 't' << (tri.tetrahedronIndex(tet) + 1)
61
 
                << '(' << (vert[0] + 1)
62
 
                << ',' << (vert[1] + 1)
63
 
                << ',' << (vert[2] + 1) << ") - ";
64
 
 
65
 
            tet = f->getEmbedding(1).getTetrahedron();
66
 
            vert = f->getEmbedding(1).getVertices();
67
 
            out << 't' << (tri.tetrahedronIndex(tet) + 1)
68
 
                << '(' << (vert[0] + 1)
69
 
                << ',' << (vert[1] + 1)
70
 
                << ',' << (vert[2] + 1) << ')';
71
 
 
72
 
            if (i != tri.getNumberOfTriangles() - 1)
73
 
                out << ',';
74
 
            out << std::endl;
75
 
        }
76
 
 
77
 
        // Write the footer.
78
 
        out << "end" << std::endl;
79
 
 
80
 
        return true;
81
 
    }
82
 
}
83
 
 
84
 
bool writeRecogniser(const char* filename, NTriangulation& tri) {
85
 
    // Sanity checks.
86
 
    if (! tri.isValid())
87
 
        return false;
88
 
    if (tri.hasBoundaryTriangles())
89
 
        return false;
90
 
 
91
 
    // Write to file or stdout as appropriate.
92
 
    if (filename && *filename) {
93
 
        std::ofstream out(filename);
94
 
        if (! out)
95
 
            return 0;
96
 
        return writeRecogniser(out, tri);
97
 
    } else {
98
 
        return writeRecogniser(std::cout, tri);
99
 
    }
100
 
}
101
 
 
102
 
} // namespace regina