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
|
/**************************************************************************
* *
* Regina - A Normal Surface Theory Calculator *
* Computational Engine *
* *
* Copyright (c) 1999-2011, 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 "surfaces/normalspec.tcc"
#include "surfaces/nnormalsurface.h"
#include "surfaces/nnormalsurfacelist.h"
#include "surfaces/nsquad.h"
#include "surfaces/nsquadoct.h"
#include "triangulation/ntriangulation.h"
namespace regina {
// Although internalStandardToReduced() is a template routine, we implement
// it here in this C++ file to avoid dragging it into the headers.
//
// The following definitions should ensure that the template is fully
// instantiated where it needs to be.
NNormalSurfaceList* NNormalSurfaceList::standardToQuad() const {
return internalStandardToReduced<NormalSpec>();
}
NNormalSurfaceList* NNormalSurfaceList::standardANToQuadOct() const {
return internalStandardToReduced<AlmostNormalSpec>();
}
template <class Variant>
NNormalSurfaceList* NNormalSurfaceList::internalStandardToReduced() const {
// And off we go!
NTriangulation* owner = getTriangulation();
// Basic sanity checks:
if (flavour != Variant::standardFlavour() || ! embedded)
return 0;
if (owner->isIdeal() || ! owner->isValid())
return 0;
// Prepare a final surface list.
NNormalSurfaceList* ans = new NNormalSurfaceList(
Variant::reducedFlavour(), true);
// Get the empty triangulation out of the way now.
unsigned n = owner->getNumberOfTetrahedra();
if (n == 0) {
owner->insertChildLast(ans);
return ans;
}
// We need to get rid of vertex links entirely before we start.
typedef const NNormalSurfaceVector* VectorPtr;
VectorPtr* use = new VectorPtr[surfaces.size()];
unsigned long nUse = 0;
std::vector<NNormalSurface*>::const_iterator it;
for (it = surfaces.begin(); it != surfaces.end(); ++it)
if (! (*it)->isVertexLinking())
use[nUse++] = (*it)->rawVector();
// We want to take all surfaces with maximal zero sets in quad space.
// That is, we want surface S if and only if there is no other surface T
// where, for every quadrilateral coordinate where S is zero, T is
// zero also.
// For almost normal surfaces, simply replace "quadrilateral" with
// "quadrilateral or octagonal".
bool dominates, strict;
unsigned tet, quad, pos;
typename Variant::ReducedVector* v;
unsigned long i, j;
for (i = 0; i < nUse; ++i) {
if (use[i] == 0)
continue;
dominates = strict = false;
for (j = 0; j < nUse; ++j) {
if (j == i || use[j] == 0)
continue;
dominates = true;
strict = false;
for (tet = 0; tet < n && dominates; ++tet)
for (quad = 0; quad < Variant::reducedCoords; ++quad)
if ((*use[i])[Variant::stdPos(tet, 4 + quad)] ==
NLargeInteger::zero &&
(*use[j])[Variant::stdPos(tet, 4 + quad)] !=
NLargeInteger::zero) {
dominates = false;
break;
} else if ((*use[i])[Variant::stdPos(tet, 4 + quad)] !=
NLargeInteger::zero &&
(*use[j])[Variant::stdPos(tet, 4 + quad)] ==
NLargeInteger::zero) {
// If this *does* turn out to be a domination of
// zero sets, we know it's strict.
strict = true;
}
if (dominates)
break;
}
if (! dominates) {
// We want this surface.
v = new typename Variant::ReducedVector(Variant::redLen(n));
pos = 0;
for (tet = 0; tet < n; ++tet)
for (quad = 0; quad < Variant::reducedCoords; ++quad)
v->setElement(pos++,
(*use[i])[Variant::stdPos(tet, 4 + quad)]);
ans->surfaces.push_back(new NNormalSurface(owner, v));
} else if (strict) {
// We can drop this surface entirely from our list.
// We don't want it for our final solution set, and if
// use[i] is going to rule out some *other* surface then
// use[j] will rule out that same other surface also.
//
// The domination need to be strict because otherwise we
// might want use[i] to rule out use[j] (i.e., they both
// rule out each other).
use[i] = 0;
}
}
delete[] use;
// All done!
owner->insertChildLast(ans);
return ans;
}
} // namespace regina
|