1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "triSurface.H"
28 #include "mergePoints.H"
29 #include "PackedBoolList.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38 bool triSurface::stitchTriangles
40 const pointField& rawPoints,
48 bool hasMerged = mergePoints(rawPoints, tol, verbose, pointMap, newPoints);
50 pointField& ps = storedPoints();
52 // Set the coordinates to the merged ones
53 ps.transfer(newPoints);
59 Pout<< "stitchTriangles : Merged from " << rawPoints.size()
60 << " points down to " << ps.size() << endl;
63 // Reset the triangle point labels to the unique points array
64 label newTriangleI = 0;
67 const labelledTri& tri = operator[](i);
76 if ((newTri[0] != newTri[1]) && (newTri[0] != newTri[2]) && (newTri[1] != newTri[2]))
78 operator[](newTriangleI++) = newTri;
82 Pout<< "stitchTriangles : "
83 << "Removing triangle " << i
84 << " with non-unique vertices." << endl
85 << " vertices :" << newTri << endl
86 << " coordinates:" << newTri.points(ps)
91 if (newTriangleI != size())
95 Pout<< "stitchTriangles : "
96 << "Removed " << size() - newTriangleI
97 << " triangles" << endl;
99 setSize(newTriangleI);
101 // And possibly compact out any unused points (since used only
102 // by triangles that have just been deleted)
103 // Done in two passes to save memory (pointField)
106 PackedBoolList pointIsUsed(ps.size());
112 const labelledTri& tri = operator[](i);
116 label pointI = tri[fp];
117 if (pointIsUsed.set(pointI, 1))
124 if (nPoints != ps.size())
127 pointMap.setSize(ps.size());
129 forAll(pointIsUsed, pointI)
131 if (pointIsUsed[pointI])
133 ps[newPointI] = ps[pointI];
134 pointMap[pointI] = newPointI++;
137 ps.setSize(newPointI);
142 const labelledTri& tri = operator[](i);
143 operator[](newTriangleI++) = labelledTri
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 } // End namespace Foam
163 // ************************************************************************* //