/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "surfaceIntersection.H"
#include "triSurfaceSearch.H"
#include "OFstream.H"
#include "labelPairHashes.H"
#include "triSurface.H"
#include "pointIndexHit.H"
#include "mergePoints.H"
#include "plane.H"
#include "edgeIntersections.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(surfaceIntersection, 0);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Checks if there exists a special topological situation that causes
// edge and the face it hit not to be recognized.
//
// For now if the face shares a point with the edge
bool Foam::surfaceIntersection::excludeEdgeHit
(
const triSurface& surf,
const label edgeI,
const label facei,
const scalar
)
{
const triSurface::FaceType& f = surf.localFaces()[facei];
const edge& e = surf.edges()[edgeI];
forAll(f, fp)
{
if (f[0] == e.start() || f[0] == e.end())
{
return true;
}
}
// {
// // Get edge vector
// vector eVec = e.vec(surf.localPoints());
// eVec /= mag(eVec) + VSMALL;
//
// const labelList& eLabels = surf.faceEdges()[facei];
//
// // Get edge vector of 0th edge of face
// vector e0Vec = surf.edges()[eLabels[0]].vec(surf.localPoints());
// e0Vec /= mag(e0Vec) + VSMALL;
//
// vector n = e0Vec ^ eVec;
//
// if (mag(n) < SMALL)
// {
// // e0 is aligned with e. Choose next edge of face.
// vector e1Vec = surf.edges()[eLabels[1]].vec(surf.localPoints());
// e1Vec /= mag(e1Vec) + VSMALL;
//
// n = e1Vec ^ eVec;
//
// if (mag(n) < SMALL)
// {
// // Problematic triangle. Two edges aligned with edgeI. Give
// // up.
// return true;
// }
// }
//
// // Check if same as faceNormal
// if (mag(n & surf.faceNormals()[facei]) > 1-tol)
// {
//
// Pout<< "edge:" << e << " face:" << facei
// << " e0Vec:" << e0Vec << " n:" << n
// << " normalComponent:" << (n & surf.faceNormals()[facei])
// << " tol:" << tol << endl;
//
// return true;
// }
// else
// {
// return false;
// }
// }
return false;
}
//// Find intersection of plane with edges of hitFacei. Returns
//// - edgeI
//// - intersection point
//Foam::pointIndexHit Foam::surfaceIntersection::faceEdgeIntersection
//(
// const triSurface& surf,
// const label hitFacei,
//
// const vector& n,
// const point& eStart,
// const point& eEnd
//)
//{
// pointIndexHit pInter;
//
// const pointField& points = surf.points();
//
// const triSurface::FaceType& f = surf.localFaces()[hitFacei];
//
// // Plane for intersect test.
// plane pl(eStart, n);
//
// forAll(f, fp)
// {
// label fp1 = f.fcIndex(fp);
//
// const point& start = points[f[fp]];
// const point& end = points[f[fp1]];
//
// vector eVec(end - start);
//
// scalar s = pl.normalIntersect(start, eVec);
//
// if (s < 0 || s > 1)
// {
// pInter.setPoint(start + s*eVec);
//
// // Check if is correct one: orientation walking
// // eStart - eEnd - hitPoint should be opposite n
// vector n2(triPointRef(start, end, pInter.hitPoint()).normal());
//
// Pout<< "plane normal:" << n
// << " start:" << start << " end:" << end
// << " hit at:" << pInter.hitPoint()
// << " resulting normal:" << n2 << endl;
//
// if ((n2 & n) < 0)
// {
// pInter.setHit();
//
// // Find corresponding edge between f[fp] f[fp1]
// label edgeI =
// meshTools::findEdge
// (
// surf.edges(),
// surf.faceEdges()[hitFacei],
// f[fp],
// f[fp1]
// );
//
// pInter.setIndex(edgeI);
//
// return pInter;
// }
// }
// }
//
// FatalErrorInFunction
// << "Did not find intersection of plane " << pl
// << " with edges of face " << hitFacei << " verts:" << f
// << abort(FatalError);
//
// return pInter;
//}
void Foam::surfaceIntersection::storeIntersection
(
const bool isFirstSurf,
const labelList& facesA,
const label faceB,
DynamicList& allCutEdges,
DynamicList& allCutPoints
)
{
forAll(facesA, facesAI)
{
label faceA = facesA[facesAI];
// Combine two faces. Always make sure the face from the first surface
// is element 0.
FixedList