Salome HOME
PAL9391
[modules/smesh.git] / src / SMESH / SMESH_Block.cxx
index 016805fd352932cf648f277e504521b8d1c68777..431208fcf1d4ed2689cdea1206052afbff7aa1b0 100644 (file)
@@ -26,6 +26,9 @@
 #include <BRepTools.hxx>
 #include <BRepTools_WireExplorer.hxx>
 #include <BRep_Tool.hxx>
+#include <Extrema_ExtPC.hxx>
+#include <Extrema_POnCurv.hxx>
+#include <GeomAdaptor_Curve.hxx>
 #include <TopAbs_ShapeEnum.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopLoc_Location.hxx>
@@ -236,6 +239,42 @@ bool SMESH_Block::ShellPoint( const gp_XYZ& theParams, gp_XYZ& thePoint ) const
   return true;
 }
 
+//=======================================================================
+//function : ShellPoint
+//purpose  : computes coordinates of a point in shell by points on sub-shapes;
+//           thePointOnShape[ subShapeID ] must be a point on a subShape
+//=======================================================================
+
+bool SMESH_Block::ShellPoint(const gp_XYZ&         theParams,
+                             const vector<gp_XYZ>& thePointOnShape,
+                             gp_XYZ&               thePoint )
+{
+  if ( thePointOnShape.size() < ID_F1yz )
+    return false;
+
+  double x = theParams.X(), y = theParams.Y(), z = theParams.Z();
+  double x1 = 1. - x,       y1 = 1. - y,       z1 = 1. - z;
+  const vector<gp_XYZ>& p = thePointOnShape;
+
+  thePoint = 
+    x1 * p[ID_F0yz] + x * p[ID_F1yz]
+      + y1 * p[ID_Fx0z] + y * p[ID_Fx1z]
+        + z1 * p[ID_Fxy0] + z * p[ID_Fxy1]
+          + x1 * (y1 * (z1 * p[ID_V000] + z * p[ID_V001])
+                  + y * (z1 * p[ID_V010] + z * p[ID_V011]))
+            + x * (y1 * (z1 * p[ID_V100] + z * p[ID_V101])
+                   + y * (z1 * p[ID_V110] + z * p[ID_V111]));
+  thePoint -=
+    x1 * (y1 * p[ID_E00z] + y * p[ID_E01z])
+      + x * (y1 * p[ID_E10z] + y * p[ID_E11z])
+        + y1 * (z1 * p[ID_Ex00] + z * p[ID_Ex01])
+          + y * (z1 * p[ID_Ex10] + z * p[ID_Ex11])
+            + z1 * (x1 * p[ID_E0y0] + x * p[ID_E1y0])
+              + z * (x1 * p[ID_E0y1] + x * p[ID_E1y1]);
+
+  return true;
+}
+
 //=======================================================================
 //function : NbVariables
 //purpose  : 
@@ -381,9 +420,24 @@ bool SMESH_Block::ComputeParameters(const gp_Pnt& thePoint,
                                     gp_XYZ&       theParams,
                                     const int     theShapeID)
 {
+  if ( VertexParameters( theShapeID, theParams ))
+    return true;
+
+  if ( IsEdgeID( theShapeID )) {
+    TEdge& e = myEdge[ theShapeID - ID_Ex00 ];
+    GeomAdaptor_Curve curve( e.myC3d );
+    double f = Min( e.myFirst, e.myLast ), l = Max( e.myFirst, e.myLast );
+    Extrema_ExtPC anExtPC( thePoint, curve, f, l );
+    int i, nb = anExtPC.IsDone() ? anExtPC.NbExt() : 0;
+    for ( i = 1; i <= nb; i++ ) {
+      if ( anExtPC.IsMin( i ))
+        return EdgeParameters( theShapeID, anExtPC.Point( i ).Parameter(), theParams );
+    }
+    return false;
+  }
+
 //   MESSAGE( endl<<"SMESH_Block::ComputeParameters( "
 //           <<thePoint.X()<<", "<<thePoint.Y()<<", "<<thePoint.Z()<<")");
-
   myPoint = thePoint.XYZ();
 
   myParam.SetCoord( -1,-1,-1 );
@@ -493,6 +547,42 @@ bool SMESH_Block::ComputeParameters(const gp_Pnt& thePoint,
   return true;
 }
 
+//=======================================================================
+//function : VertexParameters
+//purpose  : return parameters of a vertex given by TShapeID
+//=======================================================================
+
+bool SMESH_Block::VertexParameters(const int theVertexID, gp_XYZ& theParams)
+{
+  switch ( theVertexID ) {
+  case ID_V000: theParams.SetCoord(0., 0., 0.); return true;
+  case ID_V100: theParams.SetCoord(1., 0., 0.); return true;
+  case ID_V110: theParams.SetCoord(1., 1., 0.); return true;
+  case ID_V010: theParams.SetCoord(0., 1., 0.); return true;
+  default:;
+  }
+  return false;
+}
+
+//=======================================================================
+//function : EdgeParameters
+//purpose  : return parameters of a point given by theU on edge
+//=======================================================================
+
+bool SMESH_Block::EdgeParameters(const int theEdgeID, const double theU, gp_XYZ& theParams)
+{
+  if ( IsEdgeID( theEdgeID )) {
+    vector< int > vertexVec;
+    GetEdgeVertexIDs( theEdgeID, vertexVec );
+    VertexParameters( vertexVec[0], theParams );
+    TEdge& e = myEdge[ theEdgeID - ID_Ex00 ];
+    double param = ( theU - e.myFirst ) / ( e.myLast - e.myFirst );
+    theParams.SetCoord( e.myCoordInd, param );
+    return true;
+  }
+  return false;
+}
+
 //=======================================================================
 //function : GetStateNumber
 //purpose  :