27 #ifndef SMESH_Block_HeaderFile 
   28 #define SMESH_Block_HeaderFile 
   37 #include <TopTools_IndexedMapOfOrientedShape.hxx> 
   38 #include <TopoDS_Edge.hxx> 
   39 #include <TopoDS_Face.hxx> 
   40 #include <TopoDS_Shell.hxx> 
   41 #include <TopoDS_Vertex.hxx> 
   44 #include <math_FunctionSetWithDerivatives.hxx> 
   71     ID_V000 = 1, ID_V100, ID_V010, ID_V110, ID_V001, ID_V101, ID_V011, 
ID_V111, 
 
   77     ID_Fxy0, 
ID_Fxy1, ID_Fx0z, ID_Fx1z, ID_F0yz, ID_F1yz, 
 
   83     ID_FirstV = ID_V000, ID_FirstE = ID_Ex00, ID_FirstF = ID_Fxy0
 
   98   static inline bool IsVertexID( 
int theShapeID )
 
   99   { 
return ( theShapeID >= ID_V000 && theShapeID <= ID_V111 ); }
 
  101   static inline bool IsEdgeID( 
int theShapeID )
 
  102   { 
return ( theShapeID >= ID_Ex00 && theShapeID <= ID_E11z ); }
 
  104   static inline bool IsFaceID( 
int theShapeID )
 
  105   { 
return ( theShapeID >= ID_Fxy0 && theShapeID <= ID_F1yz ); }
 
  107   static int ShapeIndex( 
int theShapeID )
 
  109     if ( IsVertexID( theShapeID )) 
return theShapeID - ID_V000;
 
  110     if ( IsEdgeID( theShapeID ))   
return theShapeID - ID_Ex00;
 
  111     if ( IsFaceID( theShapeID ))   
return theShapeID - ID_Fxy0;
 
  119   static void GetFaceEdgesIDs (
const int faceID, std::vector< int >& edgeVec );
 
  122   static void GetEdgeVertexIDs (
const int edgeID, std::vector< int >& vertexVec );
 
  125   static int GetCoordIndOnEdge (
const int theEdgeID)
 
  126   { 
return (theEdgeID < ID_E0y0) ? 1 : (theEdgeID < ID_E00z) ? 2 : 3; }
 
  129   static double* GetShapeCoef (
const int theShapeID);
 
  137   static int GetShapeIDByParams ( 
const gp_XYZ& theParams );
 
  140   static std::ostream& DumpShapeID (
const int theBlockShapeID, std::ostream& stream);
 
  151   bool LoadBlockShapes(
const TopoDS_Shell&         theShell,
 
  152                        const TopoDS_Vertex&        theVertex000,
 
  153                        const TopoDS_Vertex&        theVertex001,
 
  154                        TopTools_IndexedMapOfOrientedShape& theShapeIDMap );
 
  159   bool LoadBlockShapes(
const TopTools_IndexedMapOfOrientedShape& theShapeIDMap);
 
  163                      const int                     theNode000Index,
 
  164                      const int                     theNode001Index,
 
  165                      std::vector<const SMDS_MeshNode*>& theOrderedNodes);
 
  169   bool LoadFace(
const TopoDS_Face& theFace,
 
  171                 const TopTools_IndexedMapOfOrientedShape& theShapeIDMap);
 
  176   static bool Insert(
const TopoDS_Shape& theShape,
 
  177                      const int           theShapeID,
 
  178                      TopTools_IndexedMapOfOrientedShape& theShapeIDMap);
 
  183   static bool FindBlockShapes(
const TopoDS_Shell&         theShell,
 
  184                               const TopoDS_Vertex&        theVertex000,
 
  185                               const TopoDS_Vertex&        theVertex001,
 
  186                               TopTools_IndexedMapOfOrientedShape& theShapeIDMap );
 
  195   bool VertexPoint( 
const int theVertexID, gp_XYZ& thePoint )
 const {
 
  196     if ( !IsVertexID( theVertexID ))           
return false;
 
  197     thePoint = myPnt[ theVertexID - ID_FirstV ]; 
return true;
 
  201   bool EdgePoint( 
const int theEdgeID, 
const gp_XYZ& theParams, gp_XYZ& thePoint )
 const {
 
  202     if ( !IsEdgeID( theEdgeID ))                                 
return false;
 
  203     thePoint = myEdge[ theEdgeID - ID_FirstE ].Point( theParams ); 
return true;
 
  207   bool EdgeU( 
const int theEdgeID, 
const gp_XYZ& theParams, 
double& theU )
 const {
 
  208     if ( !IsEdgeID( theEdgeID ))                              
return false;
 
  209     theU = myEdge[ theEdgeID - ID_FirstE ].GetU( theParams ); 
return true;
 
  213   bool FacePoint( 
const int theFaceID, 
const gp_XYZ& theParams, gp_XYZ& thePoint )
 const {
 
  214     if ( !IsFaceID ( theFaceID ))                                
return false;
 
  215     thePoint = myFace[ theFaceID - ID_FirstF ].Point( theParams ); 
return true;
 
  219   bool FaceUV( 
const int theFaceID, 
const gp_XYZ& theParams, gp_XY& theUV )
 const {
 
  220     if ( !IsFaceID ( theFaceID ))                               
return false;
 
  221     theUV = myFace[ theFaceID - ID_FirstF ].GetUV( theParams ); 
return true;
 
  225   bool ShellPoint( 
const gp_XYZ& theParams, gp_XYZ& thePoint ) 
const;
 
  228   static bool ShellPoint(
const gp_XYZ&         theParams,
 
  229                          const std::vector<gp_XYZ>& thePointOnShape,
 
  242   bool ComputeParameters (
const gp_Pnt& thePoint,
 
  244                           const int     theShapeID    = ID_Shell,
 
  245                           const gp_XYZ& theParamsHint = gp_XYZ(-1,-1,-1));
 
  251   bool VertexParameters(
const int theVertexID, gp_XYZ& theParams);
 
  254   bool EdgeParameters(
const int theEdgeID, 
const double theU, gp_XYZ& theParams);
 
  257   void SetTolerance(
const double tol);
 
  263   bool IsToleranceReached() 
const;
 
  274   static bool IsForwardEdge (
const TopoDS_Edge &                       theEdge,
 
  275                              const TopTools_IndexedMapOfOrientedShape& theShapeIDMap) {
 
  276     int v1ID = theShapeIDMap.FindIndex( TopExp::FirstVertex( theEdge ).Oriented( TopAbs_FORWARD ));
 
  277     int v2ID = theShapeIDMap.FindIndex( TopExp::LastVertex( theEdge ).Oriented( TopAbs_FORWARD ));
 
  278     return ( v1ID < v2ID );
 
  282   static int GetOrderedEdges (
const TopoDS_Face&        theFace,
 
  283                               std::list< TopoDS_Edge >& theEdges,
 
  284                               std::list< int >  &       theNbEdgesInWires,
 
  285                               TopoDS_Vertex             theFirstVertex=TopoDS_Vertex(),
 
  286                               const bool                theShapeAnalysisAlgo=
false);
 
  299   Standard_Integer NbVariables() 
const;
 
  300   Standard_Integer NbEquations() 
const;
 
  301   Standard_Boolean Value(
const math_Vector& X,math_Vector& F) ;
 
  302   Standard_Boolean Derivatives(
const math_Vector& X,math_Matrix& D) ;
 
  303   Standard_Boolean Values(
const math_Vector& X,math_Vector& F,math_Matrix& D) ;
 
  304   Standard_Integer GetStateNumber ();
 
  327     void Set( 
const int edgeID, 
Adaptor3d_Curve* curve, 
const bool isForward );
 
  328     void Set( 
const int edgeID, 
const gp_XYZ& node1, 
const gp_XYZ& node2 );
 
  330     double EndParam(
int i)
 const { 
return i ? myLast : myFirst; }
 
  332     const gp_XYZ& 
NodeXYZ(
int i)
 const { 
return i ? myNodes[1] : myNodes[0]; }
 
  333     gp_XYZ Point( 
const gp_XYZ& theParams ) 
const; 
 
  334     double GetU( 
const gp_XYZ& theParams ) 
const;  
 
  342     double               myFirst   [ 4 ];
 
  346     gp_XY                myCorner  [ 4 ];
 
  355     gp_XY  GetUV( 
const gp_XYZ& theParams ) 
const;
 
  356     gp_XYZ Point( 
const gp_XYZ& theParams ) 
const;
 
  357     int GetUInd()
 const { 
return myCoordInd[ 0 ]; }
 
  358     int GetVInd()
 const { 
return myCoordInd[ 2 ]; }
 
  359     void GetCoefs( 
int i, 
const gp_XYZ& theParams, 
double& eCoef, 
double& vCoef ) 
const;
 
  361     bool IsUVInQuad( 
const gp_XY& uv,
 
  362                      const gp_XYZ& param0, 
const gp_XYZ& param1,
 
  363                      const gp_XYZ& param2, 
const gp_XYZ& param3 ) 
const;
 
  364     gp_XY GetUVRange() 
const;
 
  365     TFace(): myS(0) { myC2d[0]=myC2d[1]=myC2d[2]=myC2d[3]=0; }
 
  379   enum { SQUARE_DIST = 0, DRV_1, DRV_2, DRV_3 };
 
  380   double distance ()
 const { 
return sqrt( myValues[ SQUARE_DIST ]); }
 
  381   double funcValue(
double sqDist)
 const { 
return mySquareFunc ? sqDist : sqrt(sqDist); }
 
  382   bool computeParameters(
const gp_Pnt& thePoint, gp_XYZ& theParams, 
const gp_XYZ& theParamsHint, 
int);
 
  383   void refineParametersOnFace( 
const gp_Pnt& thePoint, gp_XYZ& theParams, 
int theFaceID );
 
  384   bool findUVByHalfDivision( 
const gp_Pnt& thePoint, 
const gp_XY& theUV,
 
  385                              const TFace& tface, gp_XYZ& theParams);
 
  386   bool findUVAround( 
const gp_Pnt& thePoint, 
const gp_XY& theUV,
 
  387                      const TFace& tface, gp_XYZ& theParams, 
int nbGetWorstLimit );
 
  388   bool saveBetterSolution( 
const gp_XYZ& theNewParams, gp_XYZ& theParams, 
double sqDistance );
 
  399   double   myValues[ 4 ];