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

« back to all changes in this revision

Viewing changes to engine/triangulation/ntriangle.h

  • Committer: Package Import Robot
  • Author(s): Ben Burton
  • Date: 2013-11-02 11:44:32 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20131102114432-acgci6b1pb2hjl8q
Tags: 4.95-1
* New upstream release.
* The python module is now installed in a standard location beneath
  /usr/lib/python2.7/dist-packages.
* Switched python packaging from python-support to dh_python2.

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
/*! \file triangulation/ntriangle.h
 
36
 *  \brief Deals with triangles in a triangulation.
 
37
 */
 
38
 
 
39
#ifndef __NFACE_H
 
40
#ifndef __DOXYGEN
 
41
#define __NFACE_H
 
42
#endif
 
43
 
 
44
#include "regina-core.h"
 
45
#include "shareableobject.h"
 
46
#include "maths/nperm4.h"
 
47
#include "utilities/nmarkedvector.h"
 
48
// NOTE: More #includes follow after the class declarations.
 
49
 
 
50
namespace regina {
 
51
 
 
52
class NBoundaryComponent;
 
53
class NComponent;
 
54
class NEdge;
 
55
class NTetrahedron;
 
56
class NTriangulation;
 
57
class NVertex;
 
58
 
 
59
/**
 
60
 * \weakgroup triangulation
 
61
 * @{
 
62
 */
 
63
 
 
64
/**
 
65
 * Details how a triangle in the skeleton forms part of an individual
 
66
 * tetrahedron.
 
67
 */
 
68
class REGINA_API NTriangleEmbedding {
 
69
    private:
 
70
        NTetrahedron* tetrahedron_;
 
71
            /**< The tetrahedron in which this triangle is contained. */
 
72
        int tri_;
 
73
            /**< The face number of the tetrahedron that is this triangle. */
 
74
 
 
75
    public:
 
76
        /**
 
77
         * Creates an embedding descriptor containing the given data.
 
78
         *
 
79
         * @param tet the tetrahedron in which this triangle is contained.
 
80
         * @param tri the face number of \a tet that is this triangle.
 
81
         */
 
82
        NTriangleEmbedding(NTetrahedron* tet, int tri);
 
83
 
 
84
        /**
 
85
         * Creates an embedding descriptor containing the same data as
 
86
         * the given embedding descriptor.
 
87
         *
 
88
         * @param cloneMe the embedding descriptor to clone.
 
89
         */
 
90
        NTriangleEmbedding(const NTriangleEmbedding& cloneMe);
 
91
 
 
92
        /**
 
93
         * Returns the tetrahedron in which this triangle is contained.
 
94
         *
 
95
         * @return the tetrahedron.
 
96
         */
 
97
        NTetrahedron* getTetrahedron() const;
 
98
 
 
99
        /**
 
100
         * Returns the triangle number within getTetrahedron() that is
 
101
         * this triangle.
 
102
         *
 
103
         * @return the triangle number that is this triangle.
 
104
         */
 
105
        int getTriangle() const;
 
106
        /**
 
107
         * A deprecated alias for getTriangle().
 
108
         *
 
109
         * This routine returns the triangle number within getTetrahedron()
 
110
         * that is this triangle.  See getTriangle() for further details.
 
111
         *
 
112
         * \deprecated This routine will be removed in a future version
 
113
         * of Regina.  Please use getTriangle() instead.
 
114
         *
 
115
         * @return the triangle number that is this triangle.
 
116
         */
 
117
        int getFace() const;
 
118
 
 
119
        /**
 
120
         * Returns a mapping from vertices (0,1,2) of this triangle to the
 
121
         * corresponding vertex numbers in getTetrahedron(), as described
 
122
         * in NTetrahedron::getTriangleMapping().
 
123
         *
 
124
         * @return a mapping from the vertices of this triangle to the
 
125
         * vertices of getTetrahedron().
 
126
         */
 
127
        NPerm4 getVertices() const;
 
128
};
 
129
 
 
130
/**
 
131
 * Represents a triangle in the skeleton of a triangulation.
 
132
 * Triangles are highly temporary; once a triangulation changes, all its
 
133
 * triangle objects will be deleted and new ones will be created.
 
134
 */
 
135
class REGINA_API NTriangle : public ShareableObject, public NMarkedElement {
 
136
    public:
 
137
        static const int TRIANGLE;
 
138
            /**< Specifies a triangle with no identified vertices or edges. */
 
139
        static const int SCARF;
 
140
            /**< Specifies a triangle with two identified vertices. */
 
141
        static const int PARACHUTE;
 
142
            /**< Specifies a triangle with three identified vertices. */
 
143
        static const int CONE;
 
144
            /**< Specifies a triangle with two edges identified to form a
 
145
                 cone. */
 
146
        static const int MOBIUS;
 
147
            /**< Specifies a triangle with two edges identified to form a
 
148
                 mobius band. */
 
149
        static const int HORN;
 
150
            /**< Specifies a triangle with two edges identified to form a
 
151
                 cone with all three vertices identified. */
 
152
        static const int DUNCEHAT;
 
153
            /**< Specifies a triangle with all three edges identified, some
 
154
                 via orientable and some via non-orientable gluings. */
 
155
        static const int L31;
 
156
            /**< Specifies a triangle with all three edges identified using
 
157
                 non-orientable gluings.  Note that this forms a spine for
 
158
                 the Lens space L(3,1). */
 
159
 
 
160
        /**
 
161
         * An array that maps triangle numbers within a tetrahedron
 
162
         * (i.e., face numbers) to the canonical ordering of the individual
 
163
         * tetrahedron vertices that form each triangle.
 
164
         *
 
165
         * This means that the vertices of triangle \a i in a tetrahedron
 
166
         * are, in canonical order, <tt>ordering[i][0..2]</tt>.  As an
 
167
         * immediate consequence, we obtain <tt>ordering[i][3] == i</tt>.
 
168
         *
 
169
         * Regina defines canonical order to be \e increasing order.
 
170
         * That is, <tt>ordering[i][0] &lt; ... &lt; ordering[i][2]</tt>.
 
171
         *
 
172
         * This table does \e not describe the mapping from specific
 
173
         * triangles within a triangulation into individual tetrahedra (for
 
174
         * that, see NTetrahedron::getTriangleMapping() instead).  This table
 
175
         * merely provides a neat and consistent way of listing the
 
176
         * vertices of any given tetrahedron face.
 
177
         *
 
178
         * This lookup table replaces the deprecated routine
 
179
         * regina::faceOrdering().
 
180
         */
 
181
        static const NPerm4 ordering[4];
 
182
 
 
183
    private:
 
184
        NTriangleEmbedding* embeddings[2];
 
185
            /**< An array of descriptors telling how this triangle forms a
 
186
                 part of each individual tetrahedron that it belongs to.
 
187
                 These embeddings will be automatically deleted when the
 
188
                 triangle itself is deleted. */
 
189
        int nEmbeddings;
 
190
            /**< The number of embedding descriptors stored in
 
191
                 the embeddings array. */
 
192
        NComponent* component;
 
193
            /**< The component that this triangle is a part of. */
 
194
        NBoundaryComponent* boundaryComponent;
 
195
            /**< The boundary component that this triangle is a part of,
 
196
                 or 0 if this triangle is internal. */
 
197
        int type;
 
198
            /**< Specifies the triangle type according to one of the
 
199
                 predefined triangle type constants in NTriangle, or 0 if
 
200
                 type has not yet been determined. */
 
201
        int subtype;
 
202
            /**< Specifies the vertex or edge that plays a special role
 
203
                 for the triangle type specified by \a type.  This is only
 
204
                 relevant for some triangle types. */
 
205
 
 
206
    public:
 
207
        /**
 
208
         * Default destructor.
 
209
         * All embedding descriptors stored in this triangle will be
 
210
         * automatically deleted.
 
211
         */
 
212
        virtual ~NTriangle();
 
213
 
 
214
        /**
 
215
         * Determines if this triangle lies entirely on the boundary of the
 
216
         * triangulation.
 
217
         *
 
218
         * @return \c true if and only if this triangle lies on the boundary.
 
219
         */
 
220
        bool isBoundary() const;
 
221
 
 
222
        /**
 
223
         * Returns a description of the triangle type.
 
224
         * The triangle type describes how the edges and vertices of the
 
225
         * triangle are identified.
 
226
         *
 
227
         * @return one of the predefined triangle type constants in NTriangle.
 
228
         */
 
229
        int getType();
 
230
 
 
231
        /**
 
232
         * Return the triangle vertex or triangle edge that plays a special role
 
233
         * for the triangle type of this triangle.  Note that this routine is
 
234
         * only relevant for some triangle types.  The triangle type is
 
235
         * returned by getType().
 
236
         *
 
237
         * @return The vertex or edge that plays a special role (this
 
238
         * will be 0, 1 or 2), or -1 if this triangle type has no special
 
239
         * vertex or edge.
 
240
         */
 
241
        int getSubtype();
 
242
 
 
243
        /**
 
244
         * Determines whether this triangle is wrapped up to form a Mobius band.
 
245
         *
 
246
         * Note that several different triangle types (as returned by
 
247
         * getType()) can produce this result.
 
248
         * Note also that a triangle can be both a Mobius band \a and a cone.
 
249
         *
 
250
         * @return \c true if and only if this triangle is a Mobius band.
 
251
         */
 
252
        bool isMobiusBand();
 
253
 
 
254
        /**
 
255
         * Determines whether this triangle is wrapped up to form a cone.
 
256
         *
 
257
         * Note that several different triangle types (as returned by
 
258
         * getType()) can produce this result.
 
259
         * Note also that a triangle can be both a Mobius band \a and a cone.
 
260
         *
 
261
         * @return \c true if and only if this triangle is a cone.
 
262
         */
 
263
        bool isCone();
 
264
 
 
265
        /**
 
266
         * Returns the number of descriptors available through getEmbedding().
 
267
         * Note that this number will never be greater than two.
 
268
         *
 
269
         * @return the number of embedding descriptors.
 
270
         */
 
271
        unsigned getNumberOfEmbeddings() const;
 
272
 
 
273
        /**
 
274
         * Returns the requested descriptor detailing how this triangle forms a
 
275
         * part of a particular tetrahedron in the triangulation.
 
276
         * Note that if this triangle represents multiple faces of a
 
277
         * particular tetrahedron, then there will be multiple embedding
 
278
         * descriptors available regarding that tetrahedron.
 
279
         *
 
280
         * @param index the index of the requested descriptor.  This
 
281
         * should be between 0 and getNumberOfEmbeddings()-1 inclusive.
 
282
         * @return the requested embedding descriptor.
 
283
         */
 
284
        const NTriangleEmbedding& getEmbedding(unsigned index) const;
 
285
 
 
286
        /**
 
287
         * Returns the triangulation to which this triangle belongs.
 
288
         *
 
289
         * @return the triangulation containing this triangle.
 
290
         */
 
291
        NTriangulation* getTriangulation() const;
 
292
 
 
293
        /**
 
294
         * Returns the component of the triangulation to which this
 
295
         * triangle belongs.
 
296
         *
 
297
         * @return the component containing this triangle.
 
298
         */
 
299
        NComponent* getComponent() const;
 
300
 
 
301
        /**
 
302
         * Returns the boundary component of the triangulation to which
 
303
         * this triangle belongs.
 
304
         *
 
305
         * @return the boundary component containing this triangle, or 0 if this
 
306
         * triangle does not lie entirely within the boundary of the
 
307
         * triangulation.
 
308
         */
 
309
        NBoundaryComponent* getBoundaryComponent() const;
 
310
 
 
311
        /**
 
312
         * Returns the vertex of the triangulation that corresponds
 
313
         * to the given vertex of this triangle.
 
314
         *
 
315
         * Note that vertex \a i of a triangle is opposite edge \a i of the
 
316
         * triangle.
 
317
         *
 
318
         * @param vertex the vertex of this triangle to examine.  This should
 
319
         * be 0, 1 or 2.
 
320
         * @return the corresponding vertex of the triangulation.
 
321
         */
 
322
        NVertex* getVertex(int vertex) const;
 
323
        /**
 
324
         * Returns the edge of the triangulation that corresponds
 
325
         * to the given edge of this triangle.
 
326
         *
 
327
         * Note that edge \a i of a triangle is opposite vertex \a i of the
 
328
         * triangle.
 
329
         *
 
330
         * @param edge the edge of this triangle to examine.  This should be
 
331
         * 0, 1 or 2.
 
332
         * @return the corresponding edge of the triangulation.
 
333
         */
 
334
        NEdge* getEdge(int edge) const;
 
335
        /**
 
336
         * Examines the given edge of this triangle, and returns a mapping
 
337
         * from the "canonical" vertices of the corresponding edge of
 
338
         * the triangulation to the vertices of this triangle.
 
339
         *
 
340
         * This routine behaves much the same as
 
341
         * NTetrahedron::getEdgeMapping(), except that it maps the edge
 
342
         * vertices into a triangle, not into a tetrahedron.  See
 
343
         * NTetrahedron::getEdgeMapping() for a more detailed
 
344
         * explanation of precisely what this mapping means.
 
345
         *
 
346
         * This routine differs from NTetrahedron::getEdgeMapping() in
 
347
         * how it handles the images of 2 and 3.  This routine will
 
348
         * always map 2 to the remaining vertex of this triangle (which is
 
349
         * equal to the argument \a edge), and will always map 3 to itself.
 
350
         *
 
351
         * @param edge the edge of this triangle to examine.  This should be
 
352
         * 0, 1 or 2.
 
353
         * @return a mapping from vertices (0,1) of the requested edge to
 
354
         * the vertices of this triangle.
 
355
         */
 
356
        NPerm4 getEdgeMapping(int edge) const;
 
357
 
 
358
        void writeTextShort(std::ostream& out) const;
 
359
        void writeTextLong(std::ostream& out) const;
 
360
 
 
361
    private:
 
362
        /**
 
363
         * Creates a new triangle and marks it as belonging to the
 
364
         * given triangulation component.
 
365
         *
 
366
         * @param myComponent the triangulation component to which this
 
367
         * triangle belongs.
 
368
         */
 
369
        NTriangle(NComponent* myComponent);
 
370
 
 
371
    friend class NTriangulation;
 
372
        /**< Allow access to private members. */
 
373
};
 
374
 
 
375
/*@}*/
 
376
 
 
377
} // namespace regina
 
378
// Some more headers that are required for inline functions:
 
379
#include "triangulation/ntetrahedron.h"
 
380
namespace regina {
 
381
 
 
382
// Inline functions for NTriangle
 
383
 
 
384
inline NTriangle::NTriangle(NComponent* myComponent) : nEmbeddings(0),
 
385
        component(myComponent), boundaryComponent(0), type(0) {
 
386
}
 
387
 
 
388
inline NTriangle::~NTriangle() {
 
389
    if (nEmbeddings > 0)
 
390
        delete embeddings[0];
 
391
    if (nEmbeddings > 1)
 
392
        delete embeddings[1];
 
393
}
 
394
 
 
395
inline NTriangulation* NTriangle::getTriangulation() const {
 
396
    return embeddings[0]->getTetrahedron()->getTriangulation();
 
397
}
 
398
 
 
399
inline NComponent* NTriangle::getComponent() const {
 
400
    return component;
 
401
}
 
402
 
 
403
inline NBoundaryComponent* NTriangle::getBoundaryComponent() const {
 
404
    return boundaryComponent;
 
405
}
 
406
 
 
407
inline NVertex* NTriangle::getVertex(int vertex) const {
 
408
    return embeddings[0]->getTetrahedron()->getVertex(
 
409
        embeddings[0]->getVertices()[vertex]);
 
410
}
 
411
 
 
412
inline bool NTriangle::isBoundary() const {
 
413
    return (boundaryComponent != 0);
 
414
}
 
415
 
 
416
inline int NTriangle::getSubtype() {
 
417
    getType();
 
418
    return subtype;
 
419
}
 
420
 
 
421
inline bool NTriangle::isMobiusBand() {
 
422
    getType();
 
423
    return (type == L31 || type == DUNCEHAT || type == MOBIUS);
 
424
}
 
425
 
 
426
inline bool NTriangle::isCone() {
 
427
    getType();
 
428
    return (type == DUNCEHAT || type == CONE || type == HORN);
 
429
}
 
430
 
 
431
inline unsigned NTriangle::getNumberOfEmbeddings() const {
 
432
    return nEmbeddings;
 
433
}
 
434
 
 
435
inline const NTriangleEmbedding& NTriangle::getEmbedding(unsigned index) const {
 
436
    return *(embeddings[index]);
 
437
}
 
438
 
 
439
inline void NTriangle::writeTextShort(std::ostream& out) const {
 
440
    out << (isBoundary() ? "Boundary " : "Internal ") << "triangle";
 
441
}
 
442
 
 
443
inline NTriangleEmbedding::NTriangleEmbedding(NTetrahedron* tet, int tri) :
 
444
        tetrahedron_(tet), tri_(tri) {
 
445
}
 
446
 
 
447
inline NTriangleEmbedding::NTriangleEmbedding(
 
448
        const NTriangleEmbedding& cloneMe) :
 
449
        tetrahedron_(cloneMe.tetrahedron_), tri_(cloneMe.tri_) {
 
450
}
 
451
 
 
452
inline NTetrahedron* NTriangleEmbedding::getTetrahedron() const {
 
453
    return tetrahedron_;
 
454
}
 
455
 
 
456
inline int NTriangleEmbedding::getTriangle() const {
 
457
    return tri_;
 
458
}
 
459
 
 
460
inline int NTriangleEmbedding::getFace() const {
 
461
    return tri_;
 
462
}
 
463
 
 
464
inline NPerm4 NTriangleEmbedding::getVertices() const {
 
465
    return tetrahedron_->getTriangleMapping(tri_);
 
466
}
 
467
 
 
468
} // namespace regina
 
469
 
 
470
#endif
 
471