Salome HOME
+ static bool FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized...
authoreap <eap@opencascade.com>
Wed, 24 Feb 2010 12:43:56 +0000 (12:43 +0000)
committereap <eap@opencascade.com>
Wed, 24 Feb 2010 12:43:56 +0000 (12:43 +0000)
src/SMESH/SMESH_Algo.cxx
src/SMESH/SMESH_Algo.hxx

index da8647c400dcebc6595f7bba4b856c867f45e305..20b3056f1896a40271b5e455e3238a3a41f3b69d 100644 (file)
@@ -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<double>::min() * numeric_limits<double>::min());
+  if ( normalized && ok )
+    normal /= sqrt( size2 );
+
+  return ok;
+}
+
 //================================================================================
 /*!
  * \brief Find out elements orientation on a geometrical face
index da108fbf6602be183ebe3e8ae128f88b52565d5c..2caa5ddf6dc0fb949162c56561cd980f74fb19ec 100644 (file)
@@ -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<int> > MapShapeNbElems;
-// vector must have size corresponding to EntityType_Last from SMDSAbs:
+typedef std::map< SMESH_subMesh*, std::vector<int> >           MapShapeNbElems;
 typedef std::map< SMESH_subMesh*, std::vector<int> >::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