From: eap Date: Wed, 24 Feb 2010 12:43:56 +0000 (+0000) Subject: + static bool FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized... X-Git-Tag: V5_1_4a1~70 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a34eac927668ea3508bfb03a7e4f3d8a0f9665d9;p=modules%2Fsmesh.git + static bool FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized=true); --- diff --git a/src/SMESH/SMESH_Algo.cxx b/src/SMESH/SMESH_Algo.cxx index da8647c40..20b3056f1 100644 --- a/src/SMESH/SMESH_Algo.cxx +++ b/src/SMESH/SMESH_Algo.cxx @@ -175,6 +175,37 @@ double SMESH_Algo::EdgeLength(const TopoDS_Edge & E) return length; } +//================================================================================ +/*! + * \brief Calculate normal of a mesh face + */ +//================================================================================ + +bool SMESH_Algo::FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized) +{ + if ( !F || F->GetType() != SMDSAbs_Face ) + return false; + + normal.SetCoord(0,0,0); + int nbNodes = F->IsQuadratic() ? F->NbNodes()/2 : F->NbNodes(); + for ( int i = 0; i < nbNodes-2; ++i ) + { + gp_XYZ p[3]; + for ( int n = 0; n < 3; ++n ) + { + const SMDS_MeshNode* node = F->GetNode( n ); + p[n].SetCoord( node->X(), node->Y(), node->Z() ); + } + normal += ( p[0] - p[1] ) ^ ( p[2] - p[1] ); + } + double size2 = normal.SquareModulus(); + bool ok = ( size2 > numeric_limits::min() * numeric_limits::min()); + if ( normalized && ok ) + normal /= sqrt( size2 ); + + return ok; +} + //================================================================================ /*! * \brief Find out elements orientation on a geometrical face diff --git a/src/SMESH/SMESH_Algo.hxx b/src/SMESH/SMESH_Algo.hxx index da108fbf6..2caa5ddf6 100644 --- a/src/SMESH/SMESH_Algo.hxx +++ b/src/SMESH/SMESH_Algo.hxx @@ -53,11 +53,20 @@ class SMESHDS_Mesh; class SMDS_MeshNode; class SMESH_subMesh; class SMESH_MesherHelper; +class gp_XYZ; -typedef std::map< SMESH_subMesh*, std::vector > MapShapeNbElems; -// vector must have size corresponding to EntityType_Last from SMDSAbs: +typedef std::map< SMESH_subMesh*, std::vector > MapShapeNbElems; typedef std::map< SMESH_subMesh*, std::vector >::iterator MapShapeNbElemsItr; +/*! + * \brief Root of all algorithms + * + * Methods of the class are grouped into several parts: + * - main lifecycle methods, like Compute() + * - methods describing features of the algorithm, like NeedShape() + * - methods related to dependencies between sub-meshes imposed by the algorith + * - static utilities, like EdgeLength() + */ class SMESH_EXPORT SMESH_Algo:public SMESH_Hypothesis { public: @@ -281,6 +290,11 @@ public: */ static double EdgeLength(const TopoDS_Edge & E); + /*! + * \brief Calculate normal of a mesh face + */ + static bool FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized=true); + /*! * \brief Return continuity of two edges * \param E1 - the 1st edge