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
|
/**************************************************************************
* *
* Regina - A Normal Surface Theory Calculator *
* Computational Engine *
* *
* Copyright (c) 1999-2025, 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. *
* *
* As an exception, when this program is distributed through (i) the *
* App Store by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or *
* (iii) Google Play by Google Inc., then that store may impose any *
* digital rights management, device limits and/or redistribution *
* restrictions that are required by its terms of service. *
* *
* 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, see <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#include <vector>
#include "surface/normalsurfaces.h"
#include "surface/surfacefilter.h"
#include "triangulation/dim3.h"
namespace regina {
namespace {
inline constexpr NormalCoords transformCoords(NormalCoords src,
NormalTransform t) {
switch (t) {
case NormalTransform::ConvertReducedToStandard:
switch (src) {
case NormalCoords::Quad: return NormalCoords::Standard;
case NormalCoords::QuadOct:
return NormalCoords::AlmostNormal;
default:
throw FailedPrecondition("Reduced-to-standard "
"conversion is only available from coordinate "
"systems NormalCoords::Quad and "
"NormalCoords::QuadOct");
}
case NormalTransform::ConvertStandardToReduced:
switch (src) {
case NormalCoords::Standard: return NormalCoords::Quad;
case NormalCoords::AlmostNormal:
return NormalCoords::QuadOct;
default:
throw FailedPrecondition("Standard-to-reduced "
"conversion is only available from coordinate "
"systems NormalCoords::Standard and "
"NormalCoords::AlmostNormal");
}
default:
return src;
}
}
inline Flags<NormalList> transformList(Flags<NormalList> src,
NormalTransform t) {
switch (t) {
case NormalTransform::ConvertReducedToStandard:
case NormalTransform::ConvertStandardToReduced:
if (src != (NormalList::EmbeddedOnly | NormalList::Vertex))
throw FailedPrecondition("Conversion between "
"standard and reduced coordinate systems requires "
"the source list to contain exactly all "
"embedded vertex surfaces");
return src;
case NormalTransform::FilterCompatible:
case NormalTransform::FilterDisjoint:
case NormalTransform::FilterIncompressible:
if (! src.has(NormalList::EmbeddedOnly))
throw FailedPrecondition("This filter requires "
"the input list to contain only embedded surfaces");
return NormalList::Custom | NormalList::EmbeddedOnly;
default:
return NormalList::Custom;
}
}
inline Flags<NormalAlg> transformAlg(Flags<NormalAlg> src,
NormalTransform t) {
switch (t) {
case NormalTransform::ConvertReducedToStandard:
return src | NormalAlg::VertexViaReduced;
default:
return NormalAlg::Custom;
}
}
}
NormalSurfaces::NormalSurfaces(const NormalSurfaces& src,
NormalTransform transform) :
NormalSurfaces(transformCoords(src.coords_, transform),
transformList(src.which_, transform),
transformAlg(src.algorithm_, transform), src.triangulation_) {
switch (transform) {
case NormalTransform::ConvertReducedToStandard:
if (src.triangulation_->isIdeal() ||
! src.triangulation_->isValid())
throw FailedPrecondition("Conversion from reduced to "
"standard coordinate systems requires a "
"valid, non-ideal triangulation");
buildStandardFromReduced(src.surfaces_);
break;
case NormalTransform::ConvertStandardToReduced:
if (src.triangulation_->isIdeal() ||
! src.triangulation_->isValid())
throw FailedPrecondition("Conversion from standard to "
"reduced coordinate systems requires a "
"valid, non-ideal triangulation");
buildReducedFromStandard(src.surfaces_);
break;
case NormalTransform::FilterCompatible:
for (const auto& a : src.surfaces_)
for (const auto& b : src.surfaces_)
if (&a != &b && a.locallyCompatible(b)) {
surfaces_.push_back(a);
break;
}
break;
case NormalTransform::FilterDisjoint:
{
std::vector<const NormalSurface*> interesting;
for (const NormalSurface& s : src.surfaces_)
if ((! s.isEmpty()) && s.isCompact() && s.isConnected())
interesting.push_back(&s);
for (const auto* a : interesting)
for (const auto* b : interesting)
if (a != b && a->disjoint(*b)) {
surfaces_.push_back(*a);
break;
}
}
break;
case NormalTransform::FilterIncompressible:
for (const NormalSurface& s : src.surfaces_) {
if (s.isVertexLinking() || s.isThinEdgeLink().first)
continue;
// If we have a one-sided surface, don't worry about taking the
// two-sided double cover. If the complement of the one-sided
// surface has a compressing disc, then the complement of the
// double cover has the same compressing disc, and this surface
// can happily be tossed away.
if (! s.cutAlong().hasSimpleCompressingDisc())
surfaces_.push_back(s);
}
break;
default:
throw FailedPrecondition(
"The transformation type was not recognised");
}
}
NormalSurfaces::NormalSurfaces(const NormalSurfaces& src,
const SurfaceFilter& filter) :
NormalSurfaces(
src.coords_,
(src.which_ &
(NormalList::EmbeddedOnly | NormalList::ImmersedSingular)) |
NormalList::Custom,
src.algorithm_ | NormalAlg::Custom,
src.triangulation_) {
for (const NormalSurface& s : src.surfaces_)
if (filter.accept(s))
surfaces_.push_back(s);
}
} // namespace regina
|