Salome HOME
PAL7358. Add VertexParameters() and EdgeParameters()
authoreap <eap@opencascade.com>
Wed, 26 Jan 2005 08:32:21 +0000 (08:32 +0000)
committereap <eap@opencascade.com>
Wed, 26 Jan 2005 08:32:21 +0000 (08:32 +0000)
src/SMESH/SMESH_Block.cxx
src/SMESH/SMESH_Block.hxx

index 016805fd352932cf648f277e504521b8d1c68777..4c55ca8e40886ab0538d3580e75a988405a94438 100644 (file)
@@ -26,6 +26,9 @@
 #include <BRepTools.hxx>
 #include <BRepTools_WireExplorer.hxx>
 #include <BRep_Tool.hxx>
 #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>
 #include <TopAbs_ShapeEnum.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopLoc_Location.hxx>
@@ -381,9 +384,24 @@ bool SMESH_Block::ComputeParameters(const gp_Pnt& thePoint,
                                     gp_XYZ&       theParams,
                                     const int     theShapeID)
 {
                                     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()<<")");
 //   MESSAGE( endl<<"SMESH_Block::ComputeParameters( "
 //           <<thePoint.X()<<", "<<thePoint.Y()<<", "<<thePoint.Z()<<")");
-
   myPoint = thePoint.XYZ();
 
   myParam.SetCoord( -1,-1,-1 );
   myPoint = thePoint.XYZ();
 
   myParam.SetCoord( -1,-1,-1 );
@@ -493,6 +511,42 @@ bool SMESH_Block::ComputeParameters(const gp_Pnt& thePoint,
   return true;
 }
 
   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  : 
 //=======================================================================
 //function : GetStateNumber
 //purpose  : 
index 7ab38891a2ed1b53c143ea26ec5243c7728553bc..7258fdeff7d656cc7f50d7dcf43ddd0b472fcfa4 100644 (file)
@@ -122,7 +122,14 @@ class SMESH_Block: public math_FunctionSetWithDerivatives
   bool ComputeParameters (const gp_Pnt& thePoint,
                           gp_XYZ&       theParams,
                           const int     theShapeID = ID_Shell);
   bool ComputeParameters (const gp_Pnt& thePoint,
                           gp_XYZ&       theParams,
                           const int     theShapeID = ID_Shell);
-  // compute point parameters in the block
+  // compute point parameters in the block.
+  // Note: for edges, it is better to use EdgeParameters()
+
+  bool VertexParameters(const int theVertexID, gp_XYZ& theParams);
+  // return parameters of a vertex given by TShapeID
+
+  bool EdgeParameters(const int theEdgeID, const double theU, gp_XYZ& theParams);
+  // return parameters of a point given by theU on edge
 
   static void GetFaceEdgesIDs (const int faceID, vector< int >& edgeVec );
   // return edges IDs of a face in the order u0, u1, 0v, 1v
 
   static void GetFaceEdgesIDs (const int faceID, vector< int >& edgeVec );
   // return edges IDs of a face in the order u0, u1, 0v, 1v