1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "edgeSurface.H"
27 #include "triSurface.H"
28 #include "surfaceIntersection.H"
29 #include "meshTools.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(Foam::edgeSurface, 0);
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 // Write whole pointField and edges to stream
40 void Foam::edgeSurface::writeOBJ
42 const pointField& points,
43 const edgeList& edges,
47 forAll(points, pointI)
49 const point& pt = points[pointI];
51 os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
55 const edge& e = edges[edgeI];
57 os << "l " << e.start()+1 << ' ' << e.end()+1 << endl;
62 // Write whole pointField and selected edges to stream
63 void Foam::edgeSurface::writeOBJ
65 const pointField& points,
66 const edgeList& edges,
67 const labelList& edgeLabels,
71 forAll(points, pointI)
73 const point& pt = points[pointI];
75 os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
79 const edge& e = edges[edgeLabels[i]];
81 os << "l " << e.start()+1 << ' ' << e.end()+1 << endl;
86 // Pointedges in edgeSurface indices only.
87 void Foam::edgeSurface::calcPointEdges()
89 pointEdges_.setSize(points_.size());
91 labelList pointNEdges(points_.size(), 0);
95 const edge& e = edges_[edgeI];
101 forAll(pointEdges_, pointI)
103 pointEdges_[pointI].setSize(pointNEdges[pointI]);
108 forAll(edges_, edgeI)
110 const edge& e = edges_[edgeI];
112 labelList& pEdges0 = pointEdges_[e[0]];
113 pEdges0[pointNEdges[e[0]]++] = edgeI;
115 labelList& pEdges1 = pointEdges_[e[1]];
116 pEdges1[pointNEdges[e[1]]++] = edgeI;
121 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
123 // Construct from surface and intersection description
124 Foam::edgeSurface::edgeSurface
126 const triSurface& surf,
127 const bool isFirstSurface,
128 const surfaceIntersection& inter
131 points_(surf.nPoints() + inter.cutPoints().size()),
132 nSurfacePoints_(surf.nPoints()),
134 nSurfaceEdges_(surf.nEdges()),
136 faceEdges_(surf.size()),
137 pointEdges_(points_.size())
139 // Copy points (surface ones first)
140 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144 const pointField& surfPoints = surf.localPoints();
146 forAll(surfPoints, i)
148 points_[pointI++] = surfPoints[i];
151 const pointField& cutPoints = inter.cutPoints();
155 points_[pointI++] = cutPoints[i];
159 // Copy edges (surface ones first)
160 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162 DynamicList<edge> allEdges(surf.nEdges() + inter.cutEdges().size());
163 DynamicList<label> allParentEdges(surf.nEdges());
164 List<DynamicList<label> > allFaceEdges(surf.size());
167 // Copy surface edges (can be split!)
169 const edgeList& surfEdges = surf.edges();
171 forAll(surfEdges, edgeI)
173 const edge& e = surfEdges[edgeI];
175 // Get additional vertices for this edge.
176 const labelList& extraVerts = inter.edgeCuts(isFirstSurface)[edgeI];
178 // Store current top of allEdges.
179 label freeNewEdgeI = allEdges.size();
181 if (extraVerts.empty())
183 // No cuts across this edge. Note that vertices do not need to be
189 // Edge is cut. From e.start() to extraVerts[0],
190 // from extraVerts[i] to i+1 and finally to e.end().
196 extraVerts[0] + nSurfacePoints_
200 for (label extraI = 1; extraI < extraVerts.size(); extraI++)
206 extraVerts[extraI-1] + nSurfacePoints_,
207 extraVerts[extraI] + nSurfacePoints_
215 extraVerts.last() + nSurfacePoints_,
221 // Update allFaceEdges, parentEdges_ for the newly added edges.
223 // Add each edge label to all face neighbours of edgeI
224 const labelList& myFaces = surf.edgeFaces()[edgeI];
226 for (label eI = freeNewEdgeI; eI < allEdges.size(); eI++)
228 allParentEdges.append(edgeI);
230 forAll(myFaces, myFaceI)
232 allFaceEdges[myFaces[myFaceI]].append(eI);
237 // Done all (possibly split) surface edges by now.
238 nSurfaceEdges_ = allEdges.size();
241 // Copy intersection edges
242 // (note no parentEdges)
243 const edgeList& cutEdges = inter.cutEdges();
247 const edge& e = cutEdges[i];
249 allEdges.append(edge(e[0] + nSurfacePoints_, e[1] + nSurfacePoints_));
255 // Add intersection edges to faceEdges
256 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
258 forAllConstIter(labelPairLookup, inter.facePairToEdge(), iter)
260 // Edge label in intersection
261 const label edgeI = iter();
263 // Get the face from the correct surface
264 const FixedList<label, 2>& twoFaces = iter.key();
277 // Store on face-edge addressing. (note: offset edge)
278 allFaceEdges[faceI].append(edgeI + nSurfaceEdges_);
282 edges_.transfer(allEdges);
283 parentEdges_.transfer(allParentEdges);
285 forAll(allFaceEdges, faceI)
287 faceEdges_[faceI].transfer(allFaceEdges[faceI]);
291 // Additional addressing
292 // ~~~~~~~~~~~~~~~~~~~~~
299 Pout<< "edgeSurface : Dumping faceEdges to files" << endl;
301 forAll(faceEdges_, faceI)
303 const labelList& fEdges = faceEdges_[faceI];
305 if (fEdges.size() != 3)
307 fileName faceFName("face_" + name(faceI) + ".obj");
308 Pout<< "edgeSurface : Dumping faceEdges for face " << faceI
309 << " to " << faceFName << endl;
311 OFstream fStream(faceFName);
312 writeOBJ(points_, edges_, fEdges, fStream);
316 Pout<< "edgeSurface : Dumping edges to edges.obj" << endl;
317 OFstream eStream("edges.obj");
318 writeOBJ(points_, edges_, eStream);
320 Pout<< "edgeSurface : Dumping intersectionEdges to"
321 << " intersectionEdges.obj" << endl;
322 OFstream intEdgesStream("intersectionEdges.obj");
324 labelList edgeLabels(edges_.size() - nSurfaceEdges_);
327 for (label edgeI = nSurfaceEdges_; edgeI < edges_.size(); edgeI++)
329 edgeLabels[i++] = edgeI;
332 writeOBJ(points_, edges_, edgeLabels, intEdgesStream);
337 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
339 void Foam::edgeSurface::addIntersectionEdges
342 const edgeList& additionalEdges
347 Pout<< "Old face consisted of edges:" << endl;
349 const labelList& fEdges = faceEdges_[faceI];
352 const edge& e = edges_[fEdges[i]];
354 Pout<< " " << fEdges[i] << ' ' << e
355 << points_[e.start()] << ' ' << points_[e.end()] << endl;
359 // Make space for additional intersection edges (copies old ones)
360 const label oldNEdges = edges_.size();
362 edges_.setSize(oldNEdges + additionalEdges.size());
364 // Append new intersection edges
365 label newEdgeI = oldNEdges;
367 forAll(additionalEdges, i)
369 edges_[newEdgeI] = additionalEdges[i]; // Vertices already in eSurf
374 // Append to faceEdges.
375 labelList& fEdges = faceEdges_[faceI];
377 label nFEdges = fEdges.size();
379 fEdges.setSize(nFEdges + additionalEdges.size());
381 forAll(additionalEdges, i)
383 fEdges[nFEdges++] = oldNEdges + i;
387 // Update pointEdge addressing
393 const labelList& fEdges = faceEdges_[faceI];
395 Pout<< "New face consists of edges:" << endl;
398 const edge& e = edges_[fEdges[i]];
400 Pout<< " " << fEdges[i] << ' ' << e
401 << points_[e.start()] << ' ' << points_[e.end()] << endl;
407 // ************************************************************************* //