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
|
// This file is part of ff3d - http://www.freefem.org/ff3d
// Copyright (C) 2001, 2002, 2003 Stphane Del Pino
// 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: MeshDomainTetrahedrizor.cpp,v 1.5 2005/11/13 18:08:16 delpinux Exp $
#include <MeshOfTetrahedra.hpp>
#include <MeshDomainTetrahedrizor.hpp>
#include <set>
void
MeshDomainTetrahedrizor::
run(const bool& builtLocalizationTools)
{
// We don't need connectivity to be built
this->MeshTetrahedrizor::run(false);
const Domain& d = *__domain;
const MeshOfTetrahedra& fullMesh
= static_cast<const MeshOfTetrahedra&>(*__mesh);
// List of vertices that are inside the domain
Vector<bool> insideVertices(fullMesh.numberOfVertices());
for (size_t i=0; i<fullMesh.numberOfVertices(); ++i) {
insideVertices[i] = d.inside(fullMesh.vertex(i));
}
// Set of tetrahedra that will be kept
typedef std::set<const Tetrahedron*> KeptTetrahedra;
KeptTetrahedra keptTetrahedra;
for (MeshOfTetrahedra::const_iterator i(fullMesh);
not(i.end()); ++i) {
const Tetrahedron& t = *i;
for (int l=0; l<MeshOfTetrahedra::CellType::NumberOfVertices; ++l) {
if (insideVertices[fullMesh.vertexNumber(t(l))]) {
keptTetrahedra.insert(&t);
}
}
}
ffout(3) << "- keeping " << keptTetrahedra.size()
<< " tetrahedra over " << fullMesh.numberOfCells()
<< '\n';
// new create list of kept vertices
typedef std::map<size_t, size_t> KeptVerticesNumbers;
KeptVerticesNumbers keptVerticesNumbers;
size_t vertexNumber = 0;
for (KeptTetrahedra::const_iterator i = keptTetrahedra.begin();
i != keptTetrahedra.end(); ++i) {
const Tetrahedron& t = **i;
for (int l=0; l<MeshOfTetrahedra::CellType::NumberOfVertices; ++l) {
const size_t globalVertexNumber = fullMesh.vertexNumber(t(l));
if (keptVerticesNumbers.find(globalVertexNumber)
== keptVerticesNumbers.end()) {
keptVerticesNumbers[globalVertexNumber] = vertexNumber;
vertexNumber++;
}
}
}
VerticesSet* pVerticesSet = new VerticesSet(keptVerticesNumbers.size());
VerticesSet& verticesSet = *pVerticesSet;
VerticesCorrespondance* pCorrespondances
= new VerticesCorrespondance(keptVerticesNumbers.size());
VerticesCorrespondance& correspondances = *pCorrespondances;
// renumbers vertices correspondances
std::map<size_t, size_t> keptCorrespondances;
for (KeptVerticesNumbers::const_iterator i = keptVerticesNumbers.begin();
i != keptVerticesNumbers.end(); ++i) {
keptCorrespondances[fullMesh.correspondance(i->first)] = 0;
}
{
size_t n = 0;
for (std::map<size_t, size_t>::iterator i = keptCorrespondances.begin();
i != keptCorrespondances.end(); ++i) {
i->second = n;
n++;
}
}
// Copies usefull vertices
for (KeptVerticesNumbers::const_iterator i = keptVerticesNumbers.begin();
i != keptVerticesNumbers.end(); ++i) {
verticesSet[i->second] = fullMesh.vertex(i->first);
correspondances[i->second] = keptVerticesNumbers[fullMesh.correspondance(i->first)];
}
Vector<Tetrahedron>* pTetrahedra
= new Vector<Tetrahedron>(keptTetrahedra.size());
Vector<Tetrahedron>& tetrahedra = *pTetrahedra;
size_t tetrahedronNumber = 0;
for (KeptTetrahedra::const_iterator i = keptTetrahedra.begin();
i != keptTetrahedra.end(); ++i) {
const Tetrahedron& T = **i;
tetrahedra[tetrahedronNumber]
= Tetrahedron(verticesSet[keptVerticesNumbers[fullMesh.vertexNumber(T(0))]],
verticesSet[keptVerticesNumbers[fullMesh.vertexNumber(T(1))]],
verticesSet[keptVerticesNumbers[fullMesh.vertexNumber(T(2))]],
verticesSet[keptVerticesNumbers[fullMesh.vertexNumber(T(3))]],
T.reference());
tetrahedronNumber++;
}
MeshOfTetrahedra* meshOfTetrahedra
= new MeshOfTetrahedra(pVerticesSet,
pCorrespondances,
pTetrahedra,
0); // <= Border mesh of triangles
__mesh = meshOfTetrahedra;
}
|