1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
20 // File : SMESH_Block.hxx
21 // Created : Tue Nov 30 12:42:18 2004
22 // Author : Edward AGAPOV (eap)
25 #ifndef SMESH_Block_HeaderFile
26 #define SMESH_Block_HeaderFile
28 #include <Geom2d_Curve.hxx>
29 #include <Geom_Curve.hxx>
30 #include <Geom_Surface.hxx>
32 #include <TopTools_IndexedMapOfOrientedShape.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Shell.hxx>
35 #include <TopoDS_Vertex.hxx>
37 #include <gp_Trsf.hxx>
40 #include <math_FunctionSetWithDerivatives.hxx>
41 #include <math_Matrix.hxx>
42 #include <math_Vector.hxx>
47 // =========================================================
48 // class calculating coordinates of 3D points by normalized
49 // parameters inside the block and vice versa
50 // =========================================================
52 class SMESH_Block: public math_FunctionSetWithDerivatives
55 enum TShapeID { // ids of the block sub-shapes
58 ID_V000 = 1, ID_V100, ID_V010, ID_V110, ID_V001, ID_V101, ID_V011, ID_V111,
60 ID_Ex00, ID_Ex10, ID_Ex01, ID_Ex11,
61 ID_E0y0, ID_E1y0, ID_E0y1, ID_E1y1,
62 ID_E00z, ID_E10z, ID_E01z, ID_E11z,
64 ID_Fxy0, ID_Fxy1, ID_Fx0z, ID_Fx1z, ID_F0yz, ID_F1yz,
68 static inline bool IsVertexID( int theShapeID )
69 { return ( theShapeID >= ID_V000 && theShapeID <= ID_V111 ); }
71 static inline bool IsEdgeID( int theShapeID )
72 { return ( theShapeID >= ID_Ex00 && theShapeID <= ID_E11z ); }
74 static inline bool IsFaceID( int theShapeID )
75 { return ( theShapeID >= ID_Fxy0 && theShapeID <= ID_F1yz ); }
78 SMESH_Block (): myNbIterations(0), mySumDist(0.) {}
80 bool LoadBlockShapes(const TopoDS_Shell& theShell,
81 const TopoDS_Vertex& theVertex000,
82 const TopoDS_Vertex& theVertex001,
83 // TopTools_IndexedMapOfShape& theShapeIDMap
84 TopTools_IndexedMapOfOrientedShape& theShapeIDMap );
85 // add sub-shapes of theBlock to theShapeIDMap so that they get
86 // IDs acoording to enum TShapeID
88 static int GetShapeIDByParams ( const gp_XYZ& theParams );
89 // define an id of the block sub-shape by point parameters
91 bool VertexPoint( const int theVertexID, gp_XYZ& thePoint ) const {
92 if ( !IsVertexID( theVertexID )) return false;
93 thePoint = myPnt[ theVertexID - ID_V000 ]; return true;
95 // return vertex coordinates
97 bool EdgePoint( const int theEdgeID, const gp_XYZ& theParams, gp_XYZ& thePoint ) const {
98 if ( !IsEdgeID( theEdgeID )) return false;
99 thePoint = myEdge[ theEdgeID - ID_Ex00 ].Point( theParams ); return true;
101 // return coordinates of a point on edge
103 bool FacePoint( const int theFaceID, const gp_XYZ& theParams, gp_XYZ& thePoint ) const {
104 if ( !IsFaceID ( theFaceID )) return false;
105 thePoint = myFace[ theFaceID - ID_Fxy0 ].Point( theParams ); return true;
107 // return coordinates of a point on face
109 bool ShellPoint( const gp_XYZ& theParams, gp_XYZ& thePoint ) const;
110 // return coordinates of a point in shell
112 bool ComputeParameters (const gp_Pnt& thePoint,
114 const int theShapeID = ID_Shell);
115 // compute point parameters in the block
117 static void GetFaceEdgesIDs (const int faceID, vector< int >& edgeVec );
118 // return edges IDs of a face in the order u0, u1, 0v, 1v
120 static int GetCoordIndOnEdge (const int theEdgeID)
121 { return (theEdgeID < ID_E0y0) ? 1 : (theEdgeID < ID_E00z) ? 2 : 3; }
122 // return an index of a coordinate which varies along the edge
124 static double* GetShapeCoef (const int theShapeID);
125 // for theShapeID( TShapeID ), returns 3 coefficients used
126 // to compute an addition of an on-theShape point to coordinates
127 // of an in-shell point. If an in-shell point has parameters (Px,Py,Pz),
128 // then the addition of a point P is computed as P*kx*ky*kz and ki is
129 // defined by the returned coef like this:
130 // ki = (coef[i] == 0) ? 1 : (coef[i] < 0) ? 1 - Pi : Pi
132 static bool IsForwardEdge (const TopoDS_Edge & theEdge,
133 //TopTools_IndexedMapOfShape& theShapeIDMap
134 TopTools_IndexedMapOfOrientedShape& theShapeIDMap) {
135 int v1ID = theShapeIDMap.FindIndex( TopExp::FirstVertex( theEdge ).Oriented( TopAbs_FORWARD ));
136 int v2ID = theShapeIDMap.FindIndex( TopExp::LastVertex( theEdge ).Oriented( TopAbs_FORWARD ));
137 return ( v1ID < v2ID );
139 // Return true if an in-block parameter increases along theEdge curve
141 static void Swap(double& a, double& b) { double tmp = a; a = b; b = tmp; }
143 // methods of math_FunctionSetWithDerivatives
144 Standard_Integer NbVariables() const;
145 Standard_Integer NbEquations() const;
146 Standard_Boolean Value(const math_Vector& X,math_Vector& F) ;
147 Standard_Boolean Derivatives(const math_Vector& X,math_Matrix& D) ;
148 Standard_Boolean Values(const math_Vector& X,math_Vector& F,math_Matrix& D) ;
149 Standard_Integer GetStateNumber ();
151 static ostream& DumpShapeID (const int theBlockShapeID, ostream& stream);
152 // DEBUG: dump an id of a block sub-shape
160 Handle(Geom_Curve) myC3d;
162 double GetU( const gp_XYZ& theParams ) const;
163 gp_XYZ Point( const gp_XYZ& theParams ) const;
167 // 4 edges in the order u0, u1, 0v, 1v
169 double myFirst [ 4 ];
171 Handle(Geom2d_Curve) myC2d [ 4 ];
172 // 4 corner points in the order 00, 10, 11, 01
173 gp_XY myCorner [ 4 ];
175 Handle(Geom_Surface) myS;
177 gp_XY GetUV( const gp_XYZ& theParams ) const;
178 gp_XYZ Point( const gp_XYZ& theParams ) const;
179 int GetUInd() const { return myCoordInd[ 0 ]; }
180 int GetVInd() const { return myCoordInd[ 2 ]; }
183 TopoDS_Shell myShell;
192 // for param computation
199 gp_XYZ myPoint; // the given point
200 gp_XYZ myParam; // the best parameters guess
201 double myValues[ 4 ]; // values computed at myParam
203 typedef pair<gp_XYZ,gp_XYZ> TxyzPair;
204 TxyzPair my3x3x3GridNodes[ 27 ];