Commit 0d662c74 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: use triSurface::FaceType where triangle or region information

not required
parent 6d73c32b
......@@ -47,19 +47,16 @@ bool validTri
const labelledTri& f = surf[faceI];
if
(
(f[0] < 0) || (f[0] >= surf.points().size())
|| (f[1] < 0) || (f[1] >= surf.points().size())
|| (f[2] < 0) || (f[2] >= surf.points().size())
)
forAll(f, fp)
{
WarningIn("validTri(const triSurface&, const label)")
<< "triangle " << faceI << " vertices " << f
<< " uses point indices outside point range 0.."
<< surf.points().size()-1 << endl;
return false;
if (f[fp] < 0 || f[fp] >= surf.points().size())
{
WarningIn("validTri(const triSurface&, const label)")
<< "triangle " << faceI << " vertices " << f
<< " uses point indices outside point range 0.."
<< surf.points().size()-1 << endl;
return false;
}
}
if ((f[0] == f[1]) || (f[0] == f[2]) || (f[1] == f[2]))
......
......@@ -100,8 +100,8 @@ static void splitTri
label oldNTris = tris.size();
label fp = findIndex(f, e[0]);
label fp1 = (fp+1)%3;
label fp2 = (fp1+1)%3;
label fp1 = f.fcIndex(fp);
label fp2 = f.fcIndex(fp1);
if (f[fp1] == e[1])
{
......
......@@ -34,7 +34,7 @@ static void markPointNbrs
boolList& okToCollapse
)
{
const labelledTri& f = surf.localFaces()[faceI];
const triSurface::FaceType& f = surf.localFaces()[faceI];
forAll(f, fp)
{
......@@ -108,12 +108,12 @@ label collapseEdge(triSurface& surf, const scalar minLen)
if (okToCollapse[faceI])
{
// Check edge lengths.
const labelledTri& f = localFaces[faceI];
const triSurface::FaceType& f = localFaces[faceI];
forAll(f, fp)
{
label v = f[fp];
label v1 = f[(fp+1) % 3];
label v1 = f[f.fcIndex(fp)];
if (mag(localPoints[v1] - localPoints[v]) < minLen)
{
......
......@@ -128,9 +128,7 @@ void dumpFaces
forAllConstIter(Map<label>, connectedFaces, iter)
{
const labelledTri& f = surf.localFaces()[iter.key()];
point ctr(f.centre(surf.localPoints()));
point ctr = surf.localFaces()[iter.key()].centre(surf.localPoints());
os << "v " << ctr.x() << ' ' << ctr.y() << ' ' << ctr.z() << endl;
}
......@@ -453,7 +451,7 @@ label sharedFace
const edge& e = surf.edges()[sharedEdgeI];
const labelledTri& f = surf.localFaces()[firstFaceI];
const triSurface::FaceType& f = surf.localFaces()[firstFaceI];
label startIndex = findIndex(f, e.start());
......@@ -597,13 +595,13 @@ void renumberFaces
const triSurface& surf,
const labelList& pointMap,
const Map<label>& faceToEdge,
List<labelledTri>& newTris
List<triSurface::FaceType>& newTris
)
{
forAllConstIter(Map<label>, faceToEdge, iter)
{
const label faceI = iter.key();
const labelledTri& f = surf.localFaces()[faceI];
const triSurface::FaceType& f = surf.localFaces()[faceI];
forAll(f, fp)
{
......@@ -911,7 +909,6 @@ int main(int argc, char *argv[])
forAll(surf, faceI)
{
newTris[faceI] = surf.localFaces()[faceI];
newTris[faceI].region() = surf[faceI].region();
}
......@@ -924,7 +921,7 @@ int main(int argc, char *argv[])
// Check if faces use unmoved points.
forAll(newTris, faceI)
{
const labelledTri& f = newTris[faceI];
const triSurface::FaceType& f = newTris[faceI];
forAll(f, fp)
{
......
......@@ -196,8 +196,7 @@ int main(int argc, char *argv[])
forAll(surf1, faceI)
{
const labelledTri& f = surf1[faceI];
const point centre = f.centre(surf1.points());
const point centre = surf1[faceI].centre(surf1.points());
if
(
......
......@@ -324,13 +324,7 @@ void Foam::treeDataTriSurface::findNearest
forAll(indices, i)
{
label index = indices[i];
const labelledTri& f = surface_[index];
// Triangle points
const point& p0 = points[f[0]];
const point& p1 = points[f[1]];
const point& p2 = points[f[2]];
const triSurface::FaceType& f = surface_[index];
////- Possible optimization: do quick rejection of triangle if bounding
//// sphere does not intersect triangle bounding box. From simplistic
......@@ -379,7 +373,7 @@ void Foam::treeDataTriSurface::findNearest
// t
// );
pointHit pHit = triPointRef(p0, p1, p2).nearestPoint(sample);
pointHit pHit = f.nearestPoint(sample, points);
scalar distSqr = sqr(pHit.distance());
......@@ -425,14 +419,16 @@ bool Foam::treeDataTriSurface::intersects
{
const pointField& points = surface_.points();
const labelledTri& f = surface_[index];
const triSurface::FaceType& f = surface_[index];
// Do quick rejection test
treeBoundBox triBb(points[f[0]], points[f[0]]);
triBb.min() = min(triBb.min(), points[f[1]]);
triBb.max() = max(triBb.max(), points[f[1]]);
triBb.min() = min(triBb.min(), points[f[2]]);
triBb.max() = max(triBb.max(), points[f[2]]);
for (label ptI=1; ptI < f.size(); ++ptI)
{
triBb.min() = ::Foam::min(triBb.min(), points[f[ptI]]);
triBb.max() = ::Foam::max(triBb.max(), points[f[ptI]]);
}
const direction startBits(triBb.posBits(start));
const direction endBits(triBb.posBits(end));
......@@ -443,16 +439,14 @@ bool Foam::treeDataTriSurface::intersects
return false;
}
const triPointRef tri(points[f[0]], points[f[1]], points[f[2]]);
const vector dir(end - start);
// Use relative tolerance (from octree) to determine intersection.
pointHit inter = tri.intersection
pointHit inter = f.intersection
(
start,
dir,
points,
intersection::HALF_RAY,
indexedOctree<treeDataTriSurface>::perturbTol()
);
......
......@@ -162,7 +162,7 @@ bool Foam::triSurfaceMesh::isSurfaceClosed() const
facesPerEdge.clear();
forAll(pFaces, i)
{
const labelledTri& f = triSurface::operator[](pFaces[i]);
const triSurface::FaceType& f = triSurface::operator[](pFaces[i]);
label fp = findIndex(f, pointI);
// Something weird: if I expand the code of addFaceToEdge in both
......@@ -293,9 +293,9 @@ void Foam::triSurfaceMesh::calcBounds(boundBox& bb, label& nPoints) const
nPoints = 0;
bb = boundBox::invertedBox;
forAll(s, triI)
forAll(s, faceI)
{
const labelledTri& f = s[triI];
const triSurface::FaceType& f = s[faceI];
forAll(f, fp)
{
......@@ -475,9 +475,9 @@ void Foam::triSurfaceMesh::clearOut()
Foam::pointField Foam::triSurfaceMesh::coordinates() const
{
// Use copy to calculate face centres so they don't get stored
return PrimitivePatch<labelledTri, SubList, const pointField&>
return PrimitivePatch<triSurface::FaceType, SubList, const pointField&>
(
SubList<labelledTri>(*this, triSurface::size()),
SubList<triSurface::FaceType>(*this, triSurface::size()),
triSurface::points()
).faceCentres();
}
......@@ -804,12 +804,12 @@ void Foam::triSurfaceMesh::getNormal
{
if (info[i].hit())
{
label triI = info[i].index();
label faceI = info[i].index();
//- Cached:
//normal[i] = faceNormals()[triI];
//normal[i] = faceNormals()[faceI];
//- Uncached
normal[i] = triSurface::operator[](triI).normal(points());
normal[i] = triSurface::operator[](faceI).normal(points());
normal[i] /= mag(normal[i]) + VSMALL;
}
else
......
......@@ -489,7 +489,7 @@ Foam::booleanSurface::booleanSurface
}
labelList faceZone1;
(void)cutSurf1.markZones(isIntersectionEdge1, faceZone1);
cutSurf1.markZones(isIntersectionEdge1, faceZone1);
// Check whether at least one of sides of intersection has been marked.
......@@ -537,7 +537,7 @@ Foam::booleanSurface::booleanSurface
}
labelList faceZone2;
(void)cutSurf2.markZones(isIntersectionEdge2, faceZone2);
cutSurf2.markZones(isIntersectionEdge2, faceZone2);
// Check whether at least one of sides of intersection has been marked.
......@@ -960,20 +960,11 @@ Foam::booleanSurface::booleanSurface
forAll(combinedSurf, faceI)
{
const labelledTri& f = combinedSurf[faceI];
pointHit curHit =
triPointRef
(
pts[f[0]],
pts[f[1]],
pts[f[2]]
).nearestPoint(outsidePoint);
pointHit curHit = combinedSurf[faceI].nearestPoint(outsidePoint, pts);
if (curHit.distance() < minHit.distance())
{
minHit = curHit;
minFaceI = faceI;
}
}
......
......@@ -219,12 +219,12 @@ bool Foam::intersectedSurface::sameEdgeOrder
if (fpB != -1)
{
// Get prev/next vertex on fA
label vA1 = fA[(fpA + 1) % 3];
label vAMin1 = fA[fpA ? fpA-1 : 2];
label vA1 = fA[fA.fcIndex(fpA)];
label vAMin1 = fA[fA.rcIndex(fpA)];
// Get prev/next vertex on fB
label vB1 = fB[(fpB + 1) % 3];
label vBMin1 = fB[fpB ? fpB-1 : 2];
label vB1 = fB[fB.fcIndex(fpB)];
label vBMin1 = fB[fB.rcIndex(fpB)];
if (vA1 == vB1 || vAMin1 == vBMin1)
{
......
......@@ -414,23 +414,14 @@ bool Foam::edgeIntersections::offsetPerturb
// Classify point on face of surface2
label surf2FaceI = pHit.index();
const labelledTri& f2 = surf2.localFaces()[surf2FaceI];
const triSurface::FaceType& f2 = surf2.localFaces()[surf2FaceI];
const pointField& surf2Pts = surf2.localPoints();
label nearType;
label nearLabel;
triPointRef tri
(
surf2Pts[f2[0]],
surf2Pts[f2[1]],
surf2Pts[f2[2]]
);
const point ctr = f2.centre(surf2Pts);
point ctr = tri.centre();
label nearType, nearLabel;
tri.classify(pHit.hitPoint(), nearType, nearLabel);
f2.nearestPointClassify(pHit.hitPoint(), surf2Pts, nearType, nearLabel);
if (nearType == triPointRef::POINT || nearType == triPointRef::EDGE)
{
......
......@@ -53,22 +53,18 @@ bool Foam::surfaceIntersection::excludeEdgeHit
const scalar
)
{
const labelledTri& f = surf.localFaces()[faceI];
const triSurface::FaceType& f = surf.localFaces()[faceI];
const edge& e = surf.edges()[edgeI];
if
(
(f[0] == e.start())
|| (f[0] == e.end())
|| (f[1] == e.start())
|| (f[1] == e.end())
|| (f[2] == e.start())
|| (f[2] == e.end())
)
forAll(f, fp)
{
return true;
if (f[0] == e.start() || f[0] == e.end())
{
return true;
}
}
// {
// // Get edge vector
// vector eVec = e.vec(surf.localPoints());
// eVec /= mag(eVec) + VSMALL;
......@@ -112,11 +108,9 @@ bool Foam::surfaceIntersection::excludeEdgeHit
// {
// return false;
// }
}
else
{
return false;
}
// }
return false;
}
......@@ -137,14 +131,14 @@ bool Foam::surfaceIntersection::excludeEdgeHit
//
// const pointField& points = surf.points();
//
// const labelledTri& f = surf.localFaces()[hitFaceI];
// const triSurface::FaceType& f = surf.localFaces()[hitFaceI];
//
// // Plane for intersect test.
// plane pl(eStart, n);
//
// forAll(f, fp)
// {
// label fp1 = (fp + 1) % 3;
// label fp1 = f.fcIndex(fp);
//
// const point& start = points[f[fp]];
// const point& end = points[f[fp1]];
......@@ -303,19 +297,12 @@ void Foam::surfaceIntersection::classifyHit
// Classify point on surface2
const labelledTri& f2 = surf2.localFaces()[surf2FaceI];
const triSurface::FaceType& f2 = surf2.localFaces()[surf2FaceI];
const pointField& surf2Pts = surf2.localPoints();
label nearType;
label nearLabel;
label nearType, nearLabel;
(void)triPointRef
(
surf2Pts[f2[0]],
surf2Pts[f2[1]],
surf2Pts[f2[2]]
).classify(pHit.hitPoint(), nearType, nearLabel);
f2.nearestPointClassify(pHit.hitPoint(), surf2Pts, nearType, nearLabel);
// Classify points on edge of surface1
label edgeEnd =
......@@ -333,7 +320,7 @@ void Foam::surfaceIntersection::classifyHit
if (edgeEnd >= 0)
{
// 1. Point hits point. Do nothing.
if (debug&2)
if (debug & 2)
{
Pout<< pHit.hitPoint() << " is surf1:"
<< " end point of edge " << e
......@@ -344,7 +331,7 @@ void Foam::surfaceIntersection::classifyHit
else
{
// 2. Edge hits point. Cut edge with new point.
if (debug&2)
if (debug & 2)
{
Pout<< pHit.hitPoint() << " is surf1:"
<< " somewhere on edge " << e
......
......@@ -90,9 +90,7 @@ Foam::label Foam::surfaceIntersection::getEdge
const label fp
)
{
const labelledTri& f = surf.localFaces()[faceI];
edge faceEdge(f[fp], f[(fp+1) % 3]);
const edge faceEdge = surf.localFaces()[faceI].faceEdge(fp);
const labelList& eLabels = surf.faceEdges()[faceI];
......
......@@ -340,15 +340,7 @@ Foam::label Foam::octreeDataTriSurface::getSampleType
<< abort(FatalError);
}
const pointField& pts = surface_.points();
const labelledTri& f = surface_[faceI];
pointHit curHit = triPointRef
(
pts[f[0]],
pts[f[1]],
pts[f[2]]
).nearestPoint(sample);
pointHit curHit = surface_[faceI].nearestPoint(sample, surface_.points());
// Get normal according to position on face. On point -> pointNormal,
// on edge-> edge normal, face normal on interior.
......@@ -433,18 +425,18 @@ bool Foam::octreeDataTriSurface::intersects
return false;
}
const pointField& points = surface_.points();
const labelledTri& f = surface_[index];
triPointRef tri(points[f[0]], points[f[1]], points[f[2]]);
const vector dir(end - start);
// Disable picking up intersections behind us.
scalar oldTol = intersection::setPlanarTol(0.0);
pointHit inter = tri.ray(start, dir, intersection::HALF_RAY);
pointHit inter = surface_[index].ray
(
start,
dir,
surface_.points(),
intersection::HALF_RAY
);
intersection::setPlanarTol(oldTol);
......@@ -512,10 +504,8 @@ Foam::scalar Foam::octreeDataTriSurface::calcSign
{
n = surface_.faceNormals()[index];
const labelledTri& tri = surface_[index];
// take vector from sample to any point on triangle (we use vertex 0)
vector vec = sample - surface_.points()[tri[0]];
// take vector from sample to any point on face (we use vertex 0)
vector vec = sample - surface_.points()[surface_[index][0]];
vec /= mag(vec) + VSMALL;
......
......@@ -34,38 +34,15 @@ defineTypeNameAndDebug(Foam::orientedSurface, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Return true if face uses edge from start to end.
bool Foam::orientedSurface::edgeOrder
(
const labelledTri& f,
const edge& e
)
{
if
(
(f[0] == e[0] && f[1] == e[1])
|| (f[1] == e[0] && f[2] == e[1])
|| (f[2] == e[0] && f[0] == e[1])
)
{
return true;
}
else
{
return false;
}
}
// Return true if edge is used in opposite order in faces
bool Foam::orientedSurface::consistentEdge
(
const edge& e,
const labelledTri& f0,
const labelledTri& f1
const triSurface::FaceType& f0,
const triSurface::FaceType& f1
)
{
return edgeOrder(f0, e) ^ edgeOrder(f1, e);
return (f0.edgeDirection(e) > 0) ^ (f1.edgeDirection(e) > 0);
}
......@@ -118,8 +95,8 @@ Foam::labelList Foam::orientedSurface::edgeToFace
label face0 = eFaces[0];
label face1 = eFaces[1];
const labelledTri& f0 = s.localFaces()[face0];
const labelledTri& f1 = s.localFaces()[face1];
const triSurface::FaceType& f0 = s.localFaces()[face0];
const triSurface::FaceType& f1 = s.localFaces()[face1];
if (flip[face0] == UNVISITED)
{
......@@ -401,15 +378,8 @@ bool Foam::orientedSurface::orient
{
if (flipState[faceI] == UNVISITED)
{
const labelledTri& f = s[faceI];
pointHit curHit =
triPointRef
(
s.points()[f[0]],
s.points()[f[1]],
s.points()[f[2]]
).nearestPoint(samplePoint);
s[faceI].nearestPoint(samplePoint, s.points());
if (curHit.distance() < minDist)
{
......
......@@ -66,15 +66,12 @@ class orientedSurface
// Private Member Functions
//- Return true if face uses edge from start to end.
static bool edgeOrder(const labelledTri&, const edge&);
//- Return true if edge is used in opposite order in faces
static bool consistentEdge
(
const edge& e,
const labelledTri& f0,
const labelledTri& f1
const triSurface::FaceType& f0,
const triSurface::FaceType& f1
);