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 "sortEdgesIntoChains.H"
29 #include "helperFunctions.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 void sortEdgesIntoChains::createNodeLabels()
46 const edge& e = bEdges_[eI];
47 if( !newNodeLabel_.found(e.start()) )
48 newNodeLabel_.insert(e.start(), nPoints++);
49 if( !newNodeLabel_.found(e.end()) )
50 newNodeLabel_.insert(e.end(), nPoints++);
53 edgesAtPoint_.setSize(nPoints, DynList<label>());
56 const edge& e = bEdges_[eI];
57 label l = newNodeLabel_[e.start()];
58 edgesAtPoint_[l].append(eI);
60 l = newNodeLabel_[e.end()];
61 edgesAtPoint_[l].append(eI);
64 forAll(edgesAtPoint_, pI)
65 if( edgesAtPoint_[pI].size() % 2 )
69 bool sortEdgesIntoChains::findPointsBelongingToTheChain
76 Info << "Finding point belonging to a chain" << endl;
79 chainEdges.setSize(bEdges_.size());
82 if( edgesAtPoint_[currPos].size() != 2 )
85 const label commonVrt =
86 bEdges_[edgesAtPoint_[currPos][0]].commonVertex
88 bEdges_[edgesAtPoint_[currPos][1]]
90 label prevVrt = bEdges_[edgesAtPoint_[currPos][0]].otherVertex(commonVrt);
91 label nextVrt = bEdges_[edgesAtPoint_[currPos][1]].otherVertex(commonVrt);
92 forAll(edgesAtPoint_[currPos], posI)
93 chainEdges[edgesAtPoint_[currPos][posI]] = true;
96 Info << "commonVrt " << commonVrt << endl;
97 Info << "prevVrt " << prevVrt << endl;
98 Info << "nextVrt " << nextVrt << endl;
106 const DynList<label>& vEdges = edgesAtPoint_[newNodeLabel_[prevVrt]];
107 if( vEdges.size() == 2 )
110 if( !chainEdges[vEdges[eI]] )
113 chainEdges[vEdges[eI]] = true;
114 prevVrt = bEdges_[vEdges[eI]].otherVertex(prevVrt);
123 const DynList<label>& vEdges = edgesAtPoint_[newNodeLabel_[nextVrt]];
124 if( vEdges.size() == 2 )
127 if( !chainEdges[vEdges[eI]] )
130 chainEdges[vEdges[eI]] = true;
131 nextVrt = bEdges_[vEdges[eI]].otherVertex(nextVrt);
137 (edgesAtPoint_[newNodeLabel_[nextVrt]].size() != 2) &&
138 (edgesAtPoint_[newNodeLabel_[prevVrt]].size() != 2) &&
147 Info << "Chain edges " << chainEdges << endl;
153 void sortEdgesIntoChains::shrinkEdges(const boolList& chainEdges)
155 forAll(chainEdges, eI)
158 const edge& e = bEdges_[eI];
159 edgesAtPoint_[newNodeLabel_[e.start()]].removeElement
161 edgesAtPoint_[newNodeLabel_[e.start()]].containsAtPosition(eI)
164 edgesAtPoint_[newNodeLabel_[e.end()]].removeElement
166 edgesAtPoint_[newNodeLabel_[e.end()]].containsAtPosition(eI)
171 void sortEdgesIntoChains::createChainFromEdges(const boolList& chainEdges)
174 forAll(chainEdges, eI)
178 labelList chainPoints(i);
181 forAll(chainEdges, eI)
184 chainPoints[i++] = bEdges_[eI].start();
185 chainPoints[i++] = bEdges_[eI].end();
188 Info << "Init chainPoints " << chainPoints << endl;
195 Info << "Iteration " << label(i-1) << endl;
199 const DynList<label>& pEdges =
200 edgesAtPoint_[newNodeLabel_[chainPoints[i-1]]];
203 if( chainEdges[pEdges[peI]] )
205 const label otherPoint =
206 bEdges_[pEdges[peI]].otherVertex(chainPoints[i-1]);
209 Info << "Other point " << otherPoint << endl;
211 if( otherPoint == -1 )
213 if( chainPoints[i-2] == otherPoint )
215 if( chainPoints[0] == otherPoint )
219 chainPoints[i++] = otherPoint;
223 createdChains_.append(chainPoints);
229 void sortEdgesIntoChains::sortEdges()
235 boolList chainEdges(bEdges_.size());
236 forAll(edgesAtPoint_, pI)
237 if( findPointsBelongingToTheChain(pI, chainEdges) )
239 createChainFromEdges(chainEdges);
241 shrinkEdges(chainEdges);
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
248 sortEdgesIntoChains::sortEdgesIntoChains(const DynList<edge>& bEdges)
259 sortEdgesIntoChains::~sortEdgesIntoChains()
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
265 const DynList<labelList>& sortEdgesIntoChains::sortedChains() const
267 return createdChains_;
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
272 } // End namespace Foam
274 // ************************************************************************* //