From b8f19ad031d6deb672d239666d2fee1da7d808d2 Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 17 Dec 2013 08:15:16 +0000 Subject: [PATCH] 0022362: EDF SMESH: Quadrangle (mapping) algorithm: enforced vertices + void GetBarycentricCoords( const gp_XY& point, + const gp_XY& t0, const gp_XY& t1, const gp_XY& t2, + double & bc0, double & bc1); --- src/SMESHUtils/SMESH_Block.cxx | 27 +++++++------------ src/SMESHUtils/SMESH_MeshAlgos.cxx | 33 +++++++++++++++++++++++ src/SMESHUtils/SMESH_MeshAlgos.hxx | 42 +++++++++++++++++++----------- 3 files changed, 70 insertions(+), 32 deletions(-) diff --git a/src/SMESHUtils/SMESH_Block.cxx b/src/SMESHUtils/SMESH_Block.cxx index 7d2ed2a71..fd40175d8 100644 --- a/src/SMESHUtils/SMESH_Block.cxx +++ b/src/SMESHUtils/SMESH_Block.cxx @@ -26,6 +26,11 @@ // #include "SMESH_Block.hxx" +#include "SMDS_MeshNode.hxx" +#include "SMDS_MeshVolume.hxx" +#include "SMDS_VolumeTool.hxx" +#include "SMESH_MeshAlgos.hxx" + #include #include #include @@ -56,10 +61,7 @@ #include #include -#include "SMDS_MeshNode.hxx" -#include "SMDS_MeshVolume.hxx" -#include "SMDS_VolumeTool.hxx" -#include "utilities.h" +#include #include #include @@ -309,24 +311,15 @@ gp_XYZ SMESH_Block::TFace::Point( const gp_XYZ& theParams ) const namespace { + inline bool isPntInTria( const gp_XY& p, const gp_XY& t0, const gp_XY& t1, const gp_XY& t2 ) { - const double // matrix 2x2 - T11 = t0.X()-t2.X(), T12 = t1.X()-t2.X(), - T21 = t0.Y()-t2.Y(), T22 = t1.Y()-t2.Y(); - const double Tdet = T11*T22 - T12*T21; // matrix determinant - if ( Abs( Tdet ) < std::numeric_limits::min() ) - return false; - // matrix inverse - const double t11 = T22, t12 = -T12, t21 = -T21, t22 = T11; - // vector - const double r11 = p.X()-t2.X(), r12 = p.Y()-t2.Y(); - // barycentric coordinates: mutiply matrix by vector - const double bc0 = (t11 * r11 + t12 * r12)/Tdet; - const double bc1 = (t21 * r11 + t22 * r12)/Tdet; + double bc0, bc1; + SMESH_MeshAlgos::GetBarycentricCoords( p, t0, t1, t2, bc0, bc1 ); return ( bc0 >= 0. && bc1 >= 0. && bc0 + bc1 <= 1. ); } + inline bool isPntInQuad( const gp_XY& p, const gp_XY& q0, const gp_XY& q1, const gp_XY& q2, const gp_XY& q3 ) { diff --git a/src/SMESHUtils/SMESH_MeshAlgos.cxx b/src/SMESHUtils/SMESH_MeshAlgos.cxx index 45acf33b1..2ecd29a90 100644 --- a/src/SMESHUtils/SMESH_MeshAlgos.cxx +++ b/src/SMESHUtils/SMESH_MeshAlgos.cxx @@ -1386,6 +1386,39 @@ double SMESH_MeshAlgos::GetDistance( const SMDS_MeshFace* face, return badDistance; } +//================================================================================ +/*! + * \brief Returns barycentric coordinates of a point within a triangle. + * A not returned bc2 = 1. - bc0 - bc1. + * The point lies within the triangle if ( bc0 >= 0 && bc1 >= 0 && bc0+bc1 <= 1 ) + */ +//================================================================================ + +void SMESH_MeshAlgos::GetBarycentricCoords( const gp_XY& p, + const gp_XY& t0, + const gp_XY& t1, + const gp_XY& t2, + double & bc0, + double & bc1) +{ + const double // matrix 2x2 + T11 = t0.X()-t2.X(), T12 = t1.X()-t2.X(), + T21 = t0.Y()-t2.Y(), T22 = t1.Y()-t2.Y(); + const double Tdet = T11*T22 - T12*T21; // matrix determinant + if ( Abs( Tdet ) < std::numeric_limits::min() ) + { + bc0 = bc1 = 2.; + return; + } + // matrix inverse + const double t11 = T22, t12 = -T12, t21 = -T21, t22 = T11; + // vector + const double r11 = p.X()-t2.X(), r12 = p.Y()-t2.Y(); + // barycentric coordinates: mutiply matrix by vector + bc0 = (t11 * r11 + t12 * r12)/Tdet; + bc1 = (t21 * r11 + t22 * r12)/Tdet; +} + //======================================================================= //function : FindFaceInSet //purpose : Return a face having linked nodes n1 and n2 and which is diff --git a/src/SMESHUtils/SMESH_MeshAlgos.hxx b/src/SMESHUtils/SMESH_MeshAlgos.hxx index a02ba10dd..dc4d8fcb4 100644 --- a/src/SMESHUtils/SMESH_MeshAlgos.hxx +++ b/src/SMESHUtils/SMESH_MeshAlgos.hxx @@ -97,9 +97,16 @@ namespace SMESH_MeshAlgos /*! * \brief Return true if the point is IN or ON of the element */ - SMESHUtils_EXPORT bool IsOut( const SMDS_MeshElement* element, const gp_Pnt& point, double tol ); + SMESHUtils_EXPORT + bool IsOut( const SMDS_MeshElement* element, const gp_Pnt& point, double tol ); - SMESHUtils_EXPORT double GetDistance( const SMDS_MeshFace* face, const gp_Pnt& point ); + SMESHUtils_EXPORT + double GetDistance( const SMDS_MeshFace* face, const gp_Pnt& point ); + + SMESHUtils_EXPORT + void GetBarycentricCoords( const gp_XY& point, + const gp_XY& t0, const gp_XY& t1, const gp_XY& t2, + double & bc0, double & bc1); /*! * Return a face having linked nodes n1 and n2 and which is @@ -107,35 +114,40 @@ namespace SMESH_MeshAlgos * - in elemSet provided that !elemSet.empty() * i1 and i2 optionally returns indices of n1 and n2 */ - SMESHUtils_EXPORT const SMDS_MeshElement* - FindFaceInSet(const SMDS_MeshNode* n1, - const SMDS_MeshNode* n2, - const TIDSortedElemSet& elemSet, - const TIDSortedElemSet& avoidSet, - int* i1=0, - int* i2=0); + SMESHUtils_EXPORT + const SMDS_MeshElement* FindFaceInSet(const SMDS_MeshNode* n1, + const SMDS_MeshNode* n2, + const TIDSortedElemSet& elemSet, + const TIDSortedElemSet& avoidSet, + int* i1=0, + int* i2=0); /*! * \brief Calculate normal of a mesh face */ - SMESHUtils_EXPORT bool FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized=true); + SMESHUtils_EXPORT + bool FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized=true); /*! * \brief Return nodes common to two elements */ - SMESHUtils_EXPORT std::vector< const SMDS_MeshNode*> GetCommonNodes(const SMDS_MeshElement* e1, + SMESHUtils_EXPORT + std::vector< const SMDS_MeshNode*> GetCommonNodes(const SMDS_MeshElement* e1, const SMDS_MeshElement* e2); /*! * \brief Return SMESH_NodeSearcher. The caller is responsible for deleteing it */ - SMESHUtils_EXPORT SMESH_NodeSearcher* GetNodeSearcher( SMDS_Mesh& mesh ); + SMESHUtils_EXPORT + SMESH_NodeSearcher* GetNodeSearcher( SMDS_Mesh& mesh ); /*! * \brief Return SMESH_ElementSearcher. The caller is responsible for deleting it */ - SMESHUtils_EXPORT SMESH_ElementSearcher* GetElementSearcher( SMDS_Mesh& mesh ); - SMESHUtils_EXPORT SMESH_ElementSearcher* GetElementSearcher( SMDS_Mesh& mesh, - SMDS_ElemIteratorPtr elemIt ); + SMESHUtils_EXPORT + SMESH_ElementSearcher* GetElementSearcher( SMDS_Mesh& mesh ); + SMESHUtils_EXPORT + SMESH_ElementSearcher* GetElementSearcher( SMDS_Mesh& mesh, + SMDS_ElemIteratorPtr elemIt ); } #endif -- 2.39.2