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
|
/**************************************************************************
* *
* 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 <list>
#include "enumerate/ndoubledescriptor.h"
#include "file/nfile.h"
#include "maths/nmatrixint.h"
#include "progress/nprogressmanager.h"
#include "progress/nprogresstypes.h"
#include "surfaces/nnormalsurfacelist.h"
#include "surfaces/flavourregistry.h"
#include "triangulation/ntriangulation.h"
#include "utilities/xmlutils.h"
namespace regina {
#define __FLAVOUR_REGISTRY_BODY
const int NNormalSurfaceList::STANDARD = 0;
const int NNormalSurfaceList::AN_STANDARD = 100;
const int NNormalSurfaceList::QUAD = 1;
const int NNormalSurfaceList::EDGE_WEIGHT = 200;
const int NNormalSurfaceList::FACE_ARCS = 201;
#define REGISTER_FLAVOUR(id_name, class, n, a, t) \
case NNormalSurfaceList::id_name: \
return class::makeMatchingEquations(triangulation);
NMatrixInt* makeMatchingEquations(NTriangulation* triangulation,
int flavour) {
switch(flavour) {
// Import cases from the flavour registry.
#include "surfaces/flavourregistry.h"
}
return 0;
}
#undef REGISTER_FLAVOUR
#define REGISTER_FLAVOUR(id_name, cls, n, a, test) \
case NNormalSurfaceList::id_name: \
if (! (test)) \
noSurfaces = true; \
else if (list->embedded) \
constraints = cls::makeEmbeddedConstraints(triang); \
break;
void* NNormalSurfaceList::Enumerator::run(void*) {
NProgressNumber* progress = 0;
if (manager) {
progress = new NProgressNumber(0, 3);
manager->setProgress(progress);
}
// Perform any pre-enumeration tests and fetch any necessary
// compatibility constraints.
NCompConstraintSet* constraints = 0;
bool noSurfaces = false;
switch(list->flavour) {
// Import cases from the flavour registry.
#include "surfaces/flavourregistry.h"
}
if (noSurfaces) {
// There are no normal surfaces at all.
triang->insertChildLast(list);
if (progress) {
progress->setOutOf(1);
progress->setCompleted(1);
progress->setFinished();
}
return 0;
}
if (progress)
progress->incCompleted();
// Form the matching equations and starting cone.
NMatrixInt* eqns = makeMatchingEquations(triang, list->flavour);
std::list<NNormalSurfaceVector*> originalCone;
std::list<NVector<NLargeInteger>*> faces;
createNonNegativeCone(triang, list->flavour, back_inserter(originalCone),
back_inserter(faces));
if (progress)
progress->incCompleted();
// Find the normal surfaces.
NDoubleDescriptor::enumerateVertices(SurfaceInserter(*list, triang),
originalCone.begin(), originalCone.end(), faces.begin(), faces.end(),
*eqns, constraints, progress);
for_each(originalCone.begin(), originalCone.end(),
FuncDelete<NNormalSurfaceVector>());
for_each(faces.begin(), faces.end(),
FuncDelete<NVector<NLargeInteger> >());
delete eqns;
delete constraints;
// All done!
triang->insertChildLast(list);
if (progress) {
progress->incCompleted();
progress->setFinished();
}
return 0;
}
NNormalSurfaceList* NNormalSurfaceList::enumerate(NTriangulation* owner,
int newFlavour, bool embeddedOnly, NProgressManager* manager) {
NNormalSurfaceList* ans = new NNormalSurfaceList(newFlavour, embeddedOnly);
Enumerator* e = new Enumerator(ans, owner, manager);
if (manager) {
if (! e->start(0, true)) {
delete ans;
return 0;
}
return ans;
} else {
e->run(0);
delete e;
return ans;
}
}
NTriangulation* NNormalSurfaceList::getTriangulation() const {
return dynamic_cast<NTriangulation*>(getTreeParent());
}
#undef REGISTER_FLAVOUR
#define REGISTER_FLAVOUR(id_name, c, n, almost_normal, t) \
case id_name: return almost_normal;
bool NNormalSurfaceList::allowsAlmostNormal() const {
switch(flavour) {
// Import cases from the flavour registry.
#include "surfaces/flavourregistry.h"
}
return false;
}
#undef REGISTER_FLAVOUR
#define REGISTER_FLAVOUR(id_name, c, name, a, t) \
case id_name: o << name; break;
void NNormalSurfaceList::writeTextShort(std::ostream& o) const {
o << surfaces.size() << " vertex normal surface";
if (surfaces.size() != 1)
o << 's';
o << " (";
switch(flavour) {
// Import cases from the flavour registry.
#include "surfaces/flavourregistry.h"
default: o << "Unknown"; break;
}
o << ')';
}
#undef REGISTER_FLAVOUR
#define REGISTER_FLAVOUR(id_name, c, name, a, t) \
case id_name: o << name << '\n'; break;
void NNormalSurfaceList::writeTextLong(std::ostream& o) const {
if (embedded)
o << "Embedded ";
else
o << "Embedded, immersed & singular ";
o << "vertex normal surfaces\n";
o << "Coordinates: ";
switch(flavour) {
// Import cases from the flavour registry.
#include "surfaces/flavourregistry.h"
default: o << "Unknown\n"; break;
}
writeAllSurfaces(o);
}
void NNormalSurfaceList::writePacket(NFile& out) const {
out.writeInt(flavour);
out.writeBool(embedded);
out.writeULong(surfaces.size());
std::vector<NNormalSurface*>::const_iterator it;
for (it = surfaces.begin(); it != surfaces.end(); it++)
(*it)->writeToFile(out);
// Write the properties.
// At the moment there are no properties!
out.writeAllPropertiesFooter();
}
#undef REGISTER_FLAVOUR
#define REGISTER_FLAVOUR(id_name, c, name, a, t) \
case id_name: out << regina::xml::xmlEncodeSpecialChars(name); break;
void NNormalSurfaceList::writeXMLPacketData(std::ostream& out) const {
// Write the surface list parameters.
out << " <params embedded=\"" << (embedded ? 'T' : 'F')
<< "\" flavourid=\"" << flavour << "\"\n";
out << "\tflavour=\"";
switch(flavour) {
// Import cases from the flavour registry.
#include "surfaces/flavourregistry.h"
default: out << "Unknown"; break;
}
out << "\"/>\n";
// Write the individual surfaces.
std::vector<NNormalSurface*>::const_iterator it;
for (it = surfaces.begin(); it != surfaces.end(); it++)
(*it)->writeXMLData(out);
}
#undef REGISTER_FLAVOUR
#define REGISTER_FLAVOUR(id_name, c, n, a, t) \
case id_name: break;
NNormalSurfaceList* NNormalSurfaceList::readPacket(NFile& in,
NPacket* parent) {
// Check that we recognise the flavour of coordinate system being
// used.
int flavour = in.readInt();
switch(flavour) {
// Import cases from the flavour registry.
#include "surfaces/flavourregistry.h"
default: return 0;
}
NNormalSurfaceList* ans = new NNormalSurfaceList();
ans->flavour = flavour;
ans->embedded = in.readBool();
unsigned long nSurfaces = in.readULong();
for (unsigned long i=0; i<nSurfaces; i++)
ans->surfaces.push_back(NNormalSurface::readFromFile(in, ans->flavour,
dynamic_cast<NTriangulation*>(parent)));
// Read the properties.
in.readProperties(0);
return ans;
}
NPacket* NNormalSurfaceList::internalClonePacket(NPacket* /* parent */) const {
NNormalSurfaceList* ans = new NNormalSurfaceList();
ans->flavour = flavour;
ans->embedded = embedded;
transform(surfaces.begin(), surfaces.end(), back_inserter(ans->surfaces),
FuncNewClonePtr<NNormalSurface>());
return ans;
}
// Tidy up.
#undef REGISTER_FLAVOUR
#undef __FLAVOUR_REGISTRY_BODY
} // namespace regina
|