Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "triSurface.H"
00027 #include <OpenFOAM/mergePoints.H>
00028 #include <OpenFOAM/PackedBoolList.H>
00029
00030
00031
00032 namespace Foam
00033 {
00034
00035
00036
00037 bool triSurface::stitchTriangles
00038 (
00039 const pointField& rawPoints,
00040 const scalar tol,
00041 bool verbose
00042 )
00043 {
00044
00045 labelList pointMap;
00046 pointField newPoints;
00047 bool hasMerged = mergePoints(rawPoints, tol, verbose, pointMap, newPoints);
00048
00049 if (hasMerged)
00050 {
00051 pointField& ps = storedPoints();
00052
00053
00054 ps.transfer(newPoints);
00055
00056 if (verbose)
00057 {
00058 Pout<< "stitchTriangles : Merged from " << rawPoints.size()
00059 << " points down to " << ps.size() << endl;
00060 }
00061
00062
00063 label newTriangleI = 0;
00064 forAll(*this, i)
00065 {
00066 const labelledTri& tri = operator[](i);
00067 labelledTri newTri
00068 (
00069 pointMap[tri[0]],
00070 pointMap[tri[1]],
00071 pointMap[tri[2]],
00072 tri.region()
00073 );
00074
00075 if ((newTri[0] != newTri[1]) && (newTri[0] != newTri[2]) && (newTri[1] != newTri[2]))
00076 {
00077 operator[](newTriangleI++) = newTri;
00078 }
00079 else if (verbose)
00080 {
00081 Pout<< "stitchTriangles : "
00082 << "Removing triangle " << i
00083 << " with non-unique vertices." << endl
00084 << " vertices :" << newTri << endl
00085 << " coordinates:" << newTri.points(ps)
00086 << 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
00103
00104
00105 PackedBoolList pointIsUsed(ps.size());
00106
00107 label nPoints = 0;
00108
00109 forAll(*this, i)
00110 {
00111 const labelledTri& tri = operator[](i);
00112
00113 forAll(tri, fp)
00114 {
00115 label pointI = tri[fp];
00116 if (pointIsUsed.set(pointI, 1))
00117 {
00118 nPoints++;
00119 }
00120 }
00121 }
00122
00123 if (nPoints != ps.size())
00124 {
00125
00126 pointMap.setSize(ps.size());
00127 label newPointI = 0;
00128 forAll(pointIsUsed, pointI)
00129 {
00130 if (pointIsUsed[pointI])
00131 {
00132 ps[newPointI] = ps[pointI];
00133 pointMap[pointI] = newPointI++;
00134 }
00135 }
00136 ps.setSize(newPointI);
00137
00138 newTriangleI = 0;
00139 forAll(*this, i)
00140 {
00141 const labelledTri& tri = operator[](i);
00142 operator[](newTriangleI++) = labelledTri
00143 (
00144 pointMap[tri[0]],
00145 pointMap[tri[1]],
00146 pointMap[tri[2]],
00147 tri.region()
00148 );
00149 }
00150 }
00151 }
00152 }
00153
00154 return hasMerged;
00155 }
00156
00157
00158
00159
00160 }
00161
00162