diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index 668d7781ce13478b9d3ead21f255824f881a129e..8d25990751d911fc07760cde580bba2a98db1e4b 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -128,13 +128,15 @@ class face public: - //- Return types for classify - enum proxType - { - NONE, - POINT, // Close to point - EDGE // Close to edge - }; + // Public Typedefs + + //- The proximity classifications + enum proxType + { + NONE = 0, //!< Unknown proximity + POINT, //!< Close to point + EDGE //!< Close to edge + }; // Static Data Members diff --git a/src/OpenFOAM/meshes/primitiveShapes/pyramid/pyramid.H b/src/OpenFOAM/meshes/primitiveShapes/pyramid/pyramid.H index 9f3ee46b412734d9fbba7e87a94f3c397fd09694..df27fd24443ea8832f155320a5cae314f109f6c4 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/pyramid/pyramid.H +++ b/src/OpenFOAM/meshes/primitiveShapes/pyramid/pyramid.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -80,13 +81,19 @@ class pyramid public: + // Public Typedefs + + //- The point type + typedef Point point_type; + + // Constructors //- Construct from base polygon and apex point inline pyramid(polygonRef base, const Point& apex); //- Construct from Istream - inline pyramid(Istream& is); + inline explicit pyramid(Istream& is); // Member Functions @@ -112,7 +119,7 @@ public: inline scalar mag(const UList<point>& points) const; - // IOstream operators + // IOstream Operators friend Istream& operator>> <Point, PointRef, polygonRef> ( diff --git a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H index 6e4acee3826eadf768632d3735a1188656584c9e..e4eb46dc06ffbfdcd9cea8232497f39ef90c3ac0 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H +++ b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H @@ -53,29 +53,24 @@ SourceFiles namespace Foam { -// Forward declarations - +// Forward Declarations class Istream; class Ostream; -class triPoints; class plane; +class triPoints; template<class Point, class PointRef> class triangle; template<class Point, class PointRef> -inline Istream& operator>> -( - Istream&, - triangle<Point, PointRef>& -); +inline Istream& operator>>(Istream&, triangle<Point, PointRef>&); template<class Point, class PointRef> -inline Ostream& operator<< -( - Ostream&, - const triangle<Point, PointRef>& -); +inline Ostream& operator<<(Ostream&, const triangle<Point, PointRef>&); + +// Common Typedefs + +//- A triangle using referred points typedef triangle<point, const point&> triPointRef; @@ -88,18 +83,21 @@ class triangle { public: - // Public typedefs + // Public Typedefs + + //- The point type + typedef Point point_type; //- Storage type for triangles originating from intersecting triangle - // with another triangle + //- with another triangle typedef FixedList<triPoints, 27> triIntersectionList; - //- Return types for classify + //- The proximity classifications enum proxType { - NONE, - POINT, // Close to point - EDGE // Close to edge + NONE = 0, //!< Unknown proximity + POINT, //!< Close to point + EDGE //!< Close to edge }; @@ -141,7 +139,7 @@ public: private: - // Private data + // Private Data PointRef a_, b_, c_; @@ -187,7 +185,7 @@ public: ); //- Construct from Istream - inline triangle(Istream& is); + inline explicit triangle(Istream& is); // Member Functions diff --git a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C index 4f0ade17faaf73601667636e2ea69ead13736ff2..71bd86367e104d3ec3a29963ab890994dc7bd6ec 100644 --- a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C +++ b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -321,7 +321,7 @@ bool Foam::treeBoundBox::contains(const vector& dir, const point& pt) const { // Compare all components against min and max of bb - for (direction cmpt=0; cmpt<3; ++cmpt) + for (direction cmpt=0; cmpt < point::nComponents; ++cmpt) { if (pt[cmpt] < min()[cmpt]) { @@ -357,68 +357,71 @@ bool Foam::treeBoundBox::contains(const vector& dir, const point& pt) const Foam::direction Foam::treeBoundBox::faceBits(const point& pt) const { - direction faceBits = 0; + direction octant = 0; + if (pt.x() == min().x()) { - faceBits |= LEFTBIT; + octant |= LEFTBIT; } else if (pt.x() == max().x()) { - faceBits |= RIGHTBIT; + octant |= RIGHTBIT; } if (pt.y() == min().y()) { - faceBits |= BOTTOMBIT; + octant |= BOTTOMBIT; } else if (pt.y() == max().y()) { - faceBits |= TOPBIT; + octant |= TOPBIT; } if (pt.z() == min().z()) { - faceBits |= BACKBIT; + octant |= BACKBIT; } else if (pt.z() == max().z()) { - faceBits |= FRONTBIT; + octant |= FRONTBIT; } - return faceBits; + + return octant; } Foam::direction Foam::treeBoundBox::posBits(const point& pt) const { - direction posBits = 0; + direction octant = 0; if (pt.x() < min().x()) { - posBits |= LEFTBIT; + octant |= LEFTBIT; } else if (pt.x() > max().x()) { - posBits |= RIGHTBIT; + octant |= RIGHTBIT; } if (pt.y() < min().y()) { - posBits |= BOTTOMBIT; + octant |= BOTTOMBIT; } else if (pt.y() > max().y()) { - posBits |= TOPBIT; + octant |= TOPBIT; } if (pt.z() < min().z()) { - posBits |= BACKBIT; + octant |= BACKBIT; } else if (pt.z() > max().z()) { - posBits |= FRONTBIT; + octant |= FRONTBIT; } - return posBits; + + return octant; } @@ -429,44 +432,23 @@ void Foam::treeBoundBox::calcExtremities point& furthest ) const { - scalar nearX, nearY, nearZ; - scalar farX, farY, farZ; - - if (Foam::mag(min().x() - pt.x()) < Foam::mag(max().x() - pt.x())) - { - nearX = min().x(); - farX = max().x(); - } - else - { - nearX = max().x(); - farX = min().x(); - } - - if (Foam::mag(min().y() - pt.y()) < Foam::mag(max().y() - pt.y())) - { - nearY = min().y(); - farY = max().y(); - } - else - { - nearY = max().y(); - farY = min().y(); - } - - if (Foam::mag(min().z() - pt.z()) < Foam::mag(max().z() - pt.z())) - { - nearZ = min().z(); - farZ = max().z(); - } - else + for (direction cmpt=0; cmpt < point::nComponents; ++cmpt) { - nearZ = max().z(); - farZ = min().z(); + if + ( + Foam::mag(min()[cmpt] - pt[cmpt]) + < Foam::mag(max()[cmpt] - pt[cmpt]) + ) + { + nearest[cmpt] = min()[cmpt]; + furthest[cmpt] = max()[cmpt]; + } + else + { + nearest[cmpt] = max()[cmpt]; + furthest[cmpt] = min()[cmpt]; + } } - - nearest = point(nearX, nearY, nearZ); - furthest = point(farX, farY, farZ); } diff --git a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H index 348bb2f95ee01ec63ea275e15fa87490059fd1b0..678202e1fe3bfff56507e70e5081e99f8053382f 100644 --- a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H +++ b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -80,7 +80,6 @@ class treeBoundBox; Istream& operator>>(Istream& is, treeBoundBox& bb); Ostream& operator<<(Ostream& os, const treeBoundBox& bb); - /*---------------------------------------------------------------------------*\ Class treeBoundBox Declaration \*---------------------------------------------------------------------------*/ @@ -89,18 +88,17 @@ class treeBoundBox : public boundBox { - public: - // Static Data Members + // Enumerations //- Bits used for octant/point encoding. - // Every octant/corner point is the combination of three faces. + // Every octant/corner point is the combination of three directions. enum octantBit : direction { - RIGHTHALF = 0x1, - TOPHALF = 0x2, - FRONTHALF = 0x4 + RIGHTHALF = 0x1, //!< 1: positive x-direction + TOPHALF = 0x2, //!< 2: positive y-direction + FRONTHALF = 0x4 //!< 4: positive z-direction }; //- Face codes. Identical order and meaning as per hex cellmodel @@ -147,6 +145,9 @@ public: E26 = 11 }; + + // Static Data Members + //- Face to point addressing static const faceList faces; diff --git a/src/meshTools/triSurface/triangleFuncs/triangleFuncs.C b/src/meshTools/triSurface/triangleFuncs/triangleFuncs.C index 09daf15878421d3b2dec431230db1afee95f8809..dc2ad74b0367b20d842facf85170d225516ba298 100644 --- a/src/meshTools/triSurface/triangleFuncs/triangleFuncs.C +++ b/src/meshTools/triSurface/triangleFuncs/triangleFuncs.C @@ -48,7 +48,7 @@ void Foam::triangleFuncs::setIntersection point& pt ) { - scalar denom = oppositeSign - thisSign; + const scalar denom = oppositeSign - thisSign; if (mag(denom) < tol) { @@ -62,29 +62,8 @@ void Foam::triangleFuncs::setIntersection } -void Foam::triangleFuncs::selectPt -( - const bool select0, - const point& p0, - const point& p1, - point& min -) -{ - if (select0) - { - min = p0; - } - else - { - min = p1; - } -} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -// Intersect triangle with parallel edges aligned with axis i0. -// Returns true (and intersection in pInter) if any of them intersects triangle. bool Foam::triangleFuncs::intersectAxesBundle ( const point& V0, @@ -169,9 +148,6 @@ bool Foam::triangleFuncs::intersectAxesBundle } -// Intersect triangle with bounding box. Return true if -// any of the faces of bb intersect triangle. -// Note: so returns false if triangle inside bb. bool Foam::triangleFuncs::intersectBb ( const point& p0, diff --git a/src/meshTools/triSurface/triangleFuncs/triangleFuncs.H b/src/meshTools/triSurface/triangleFuncs/triangleFuncs.H index 6a72d77e635645843bd9d1538f7fa83addcd8ce5..8d3068d33ac243b952dfdd7801acaf7b28233616 100644 --- a/src/meshTools/triSurface/triangleFuncs/triangleFuncs.H +++ b/src/meshTools/triSurface/triangleFuncs/triangleFuncs.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,7 +28,7 @@ Class Foam::triangleFuncs Description - Various triangle functions. + Contains various triangle static functions. SourceFiles triangleFuncs.C @@ -37,9 +38,6 @@ SourceFiles #ifndef triangleFuncs_H #define triangleFuncs_H -#include "point.H" -#include "label.H" -#include "scalar.H" #include "pointField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,7 +45,7 @@ SourceFiles namespace Foam { -// Forward declaration of classes +// Forward Declarations class treeBoundBox; /*---------------------------------------------------------------------------*\ @@ -56,26 +54,11 @@ class treeBoundBox; class triangleFuncs { - -public: - - // Public data types - - //- Enumeration defining nearness classification - enum proxType - { - NONE, - POINT, - EDGE - }; - - -private: - // Private Member Functions - //- Helper function for intersect. Sets pt to be anywhere on the edge - // between oppositeSidePt and thisSidePt depending on both signs. + //- Sets pt to be anywhere on the edge between oppositeSidePt + //- and thisSidePt depending on both signs. + // \note Helper function for intersect() static void setIntersection ( const point& oppositeSidePt, @@ -86,17 +69,10 @@ private: point& pt ); - //- Helper function. - static void selectPt - ( - const bool select0, - const point& p0, - const point& p1, - point& min - ); - public: + // Static Member Functions + //- Intersect triangle with parallel edges aligned with axis i0. // Returns true (and intersection in pInter) if any of them intersects // triangle. Used in intersectBb. @@ -111,7 +87,9 @@ public: point& pInter ); - //- Does triangle intersect bounding box. + //- Intersect triangle with bounding box. + // \return true if any bounding box faces intersect the triangle, + // returns false if the triangle is inside the bounding box static bool intersectBb ( const point& p0, @@ -120,7 +98,8 @@ public: const treeBoundBox& cubeBb ); - //- Does triangle intersect plane. Return bool and set intersection segment. + //- Intersect triangle with plane. + // \return bool and set intersection segment. static bool intersect ( const point& va0, @@ -134,7 +113,8 @@ public: point& pInter1 ); - //- Do triangles intersect. Return bool and set intersection segment. + //- Intersection of two triangles intersect. + // \return bool and set intersection segment. static bool intersect ( const point& va0,