1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 cfMesh is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
28 #include "triSurfaceCopyParts.H"
29 #include "triSurfModifier.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 void triSurfaceCopyParts::markFacetsForCopying
40 const wordList& parts,
44 copyFacets.setSize(surf_.size());
47 const geometricSurfacePatchList& patches = surf_.patches();
49 //- mark patches which will be copied
50 boolList copyPatch(patches.size(), false);
52 forAll(patches, patchI)
54 const word name = patches[patchI].name();
58 if( parts[partI] == name )
60 copyPatch[patchI] = true;
66 //- select facets affected by the deletion of a patch
69 if( copyPatch[surf_[triI].region()] )
70 copyFacets[triI] = true;
73 //- mark facets contained in selected subsets
74 DynList<label> facetSubsetsIDs;
75 surf_.facetSubsetIndices(facetSubsetsIDs);
77 forAll(facetSubsetsIDs, i)
79 const word fsName = surf_.facetSubsetName(facetSubsetsIDs[i]);
83 if( parts[partI] == fsName )
85 labelLongList containedFacets;
86 surf_.facetsInSubset(facetSubsetsIDs[i], containedFacets);
88 forAll(containedFacets, cfI)
89 copyFacets[containedFacets[cfI]] = true;
97 void triSurfaceCopyParts::copySurfaceMesh
99 const boolList& copyFacets,
103 Info << "Starting copying surface parts" << endl;
105 const pointField& pts = surf_.points();
107 labelLongList newPointLabel(pts.size(), -1);
111 //- create the modifier and delete data if there is any
112 triSurfModifier sm(s);
113 sm.facetsAccess().clear();
114 sm.featureEdgesAccess().clear();
115 sm.patchesAccess().setSize(surf_.patches().size());
116 forAll(surf_.patches(), patchI)
117 sm.patchesAccess()[patchI] = surf_.patches()[patchI];
119 //- copy selected patches
120 labelLongList newTriangleLabel(surf_.size(), -1);
121 forAll(copyFacets, triI)
123 if( !copyFacets[triI] )
126 const labelledTri& tri = surf_[triI];
129 newTri.region() = tri.region();
133 if( newPointLabel[tri[pI]] == -1 )
135 newPointLabel[tri[pI]] = nPoints;
139 newTri[pI] = newPointLabel[tri[pI]];
142 newTriangleLabel[triI] = s.size();
143 s.appendTriangle(newTri);
146 Info << "Copied triangles " << s.size() << endl;
147 Info << "Number of vertices " << nPoints << endl;
150 pointField& newPts = sm.pointsAccess();
151 newPts.setSize(nPoints);
153 forAll(newPointLabel, i)
155 if( newPointLabel[i] < 0 )
158 newPts[newPointLabel[i]] = pts[i];
161 //- copy point subsets
162 DynList<label> subsetIds;
163 surf_.pointSubsetIndices(subsetIds);
164 forAll(subsetIds, subsetI)
166 const label origId = subsetIds[subsetI];
167 const word sName = surf_.pointSubsetName(origId);
169 labelLongList pointsInSubset;
170 surf_.pointsInSubset(origId, pointsInSubset);
172 const label newId = s.addPointSubset(sName);
173 forAll(pointsInSubset, i)
175 const label newPointI = newPointLabel[pointsInSubset[i]];
180 s.addPointToSubset(newId, newPointI);
184 //- copy facet subsets
185 surf_.facetSubsetIndices(subsetIds);
186 forAll(subsetIds, subsetI)
188 const label origId = subsetIds[subsetI];
189 const word sName = surf_.facetSubsetName(origId);
191 labelLongList trianglesInSubset;
192 surf_.facetsInSubset(origId, trianglesInSubset);
194 const label newId = s.addFacetSubset(sName);
195 forAll(trianglesInSubset, i)
197 const label newTriI = newTriangleLabel[trianglesInSubset[i]];
202 s.addFacetToSubset(newId, newTriI);
206 //- copy feature edges
207 labelLongList newEdgeLabel(surf_.nFeatureEdges(), -1);
208 const VRWGraph& pointEdges = surf_.pointEdges();
209 const edgeLongList& edges = surf_.edges();
210 const VRWGraph& edgeFacets = surf_.edgeFacets();
211 forAll(newEdgeLabel, edgeI)
213 const edge& e = surf_.featureEdges()[edgeI];
215 forAllRow(pointEdges, e.start(), peI)
217 const label eJ = pointEdges(e.start(), peI);
225 if( newPointLabel[e.start()] < 0 )
227 if( newPointLabel[e.end()] < 0 )
229 bool foundTriangle(false);
230 forAllRow(edgeFacets, eI, efI)
232 if( newTriangleLabel[edgeFacets(eI, efI)] >= 0 )
234 foundTriangle = true;
241 newEdgeLabel[edgeI] = sm.featureEdgesAccess().size();
242 sm.featureEdgesAccess().append
244 edge(newPointLabel[e.start()], newPointLabel[e.end()])
248 //- copy subsets of feature edges
249 surf_.edgeSubsetIndices(subsetIds);
250 forAll(subsetIds, subsetI)
252 const label origId = subsetIds[subsetI];
253 const word sName = surf_.edgeSubsetName(origId);
255 labelLongList edgesInSubset;
256 surf_.edgesInSubset(origId, edgesInSubset);
258 const label newId = s.addEdgeSubset(sName);
259 forAll(edgesInSubset, i)
261 const label newEdgeI = newEdgeLabel[edgesInSubset[i]];
266 s.addEdgeToSubset(newId, newEdgeI);
270 Info << "Finished copying surface parts" << endl;
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 triSurfaceCopyParts::triSurfaceCopyParts(const triSurf& surface)
280 triSurfaceCopyParts::~triSurfaceCopyParts()
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 void triSurfaceCopyParts::copySurface(const wordList& patches, triSurf& s) const
287 boolList copyFacets(surf_.size(), false);
289 markFacetsForCopying(patches, copyFacets);
291 copySurfaceMesh(copyFacets, s);
294 triSurf* triSurfaceCopyParts::copySurface(const wordList& patches) const
296 boolList copyFacets(surf_.size(), false);
298 markFacetsForCopying(patches, copyFacets);
300 triSurf* sPtr = new triSurf();
302 copySurfaceMesh(copyFacets, *sPtr);
307 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
309 } // End namespace Foam
311 // ************************************************************************* //