OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

stitchTriangles.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "triSurface.H"
00028 #include "mergePoints.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00036 
00037 bool triSurface::stitchTriangles
00038 (
00039     const pointField& rawPoints,
00040     const scalar tol,
00041     bool verbose
00042 )
00043 {
00044     // Merge points
00045     labelList pointMap;
00046     pointField newPoints;
00047     bool hasMerged = mergePoints(rawPoints, tol, verbose, pointMap, newPoints);
00048 
00049     if (hasMerged)
00050     {
00051         if (verbose)
00052         {
00053             Pout<< "stitchTriangles : Merged from " << rawPoints.size()
00054                 << " points down to " << newPoints.size() << endl;
00055         }
00056 
00057         pointField& ps = storedPoints();
00058 
00059         // Set the coordinates to the merged ones
00060         ps = newPoints;
00061 
00062         // Reset the triangle point labels to the unique points array
00063         label newTriangleI = 0;
00064         forAll(*this, i)
00065         {
00066             label newA = pointMap[operator[](i)[0]];
00067             label newB = pointMap[operator[](i)[1]];
00068             label newC = pointMap[operator[](i)[2]];
00069 
00070             if ((newA != newB) && (newA != newC) && (newB != newC))
00071             {
00072                 operator[](newTriangleI)[0] = newA;
00073                 operator[](newTriangleI)[1] = newB;
00074                 operator[](newTriangleI)[2] = newC;
00075                 operator[](newTriangleI).region() = operator[](i).region();
00076                 newTriangleI++;
00077             }
00078             else if (verbose)
00079             {
00080                 Pout<< "stitchTriangles : "
00081                     << "Removing triangle " << i << " with non-unique vertices."
00082                     << endl
00083                     << "    vertices   :" << newA << ' ' << newB << ' ' << newC
00084                     << endl
00085                     << "    coordinates:" << ps[newA] << ' ' << ps[newB]
00086                     << ' ' << ps[newC]  << endl;
00087             }
00088         }
00089 
00090         if (newTriangleI != size())
00091         {
00092             if (verbose)
00093             {
00094                 Pout<< "stitchTriangles : "
00095                     << "Removed " << size() - newTriangleI
00096                     << " triangles" << endl;
00097             }
00098             setSize(newTriangleI);
00099         }
00100     }
00101 
00102     return hasMerged;
00103 }
00104 
00105 
00106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00107 
00108 } // End namespace Foam
00109 
00110 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd