00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef SMESH_Block_HeaderFile
00028 #define SMESH_Block_HeaderFile
00029
00030 #include "SMESH_SMESH.hxx"
00031
00032
00033
00034
00035
00036 #include <TopExp.hxx>
00037 #include <TopTools_IndexedMapOfOrientedShape.hxx>
00038 #include <TopoDS_Edge.hxx>
00039 #include <TopoDS_Face.hxx>
00040 #include <TopoDS_Shell.hxx>
00041 #include <TopoDS_Vertex.hxx>
00042 #include <gp_XY.hxx>
00043 #include <gp_XYZ.hxx>
00044 #include <math_FunctionSetWithDerivatives.hxx>
00045
00046 #include <ostream>
00047 #include <vector>
00048 #include <list>
00049
00050 class SMDS_MeshVolume;
00051 class SMDS_MeshNode;
00052 class Adaptor3d_Surface;
00053 class Adaptor2d_Curve2d;
00054 class Adaptor3d_Curve;
00055 class gp_Pnt;
00056
00057
00058
00059
00060
00061
00062 class SMESH_EXPORT SMESH_Block: public math_FunctionSetWithDerivatives
00063 {
00064 public:
00065 enum TShapeID {
00066
00067
00068
00069 ID_NONE = 0,
00070
00071 ID_V000 = 1, ID_V100, ID_V010, ID_V110, ID_V001, ID_V101, ID_V011, ID_V111,
00072
00073 ID_Ex00, ID_Ex10, ID_Ex01, ID_Ex11,
00074 ID_E0y0, ID_E1y0, ID_E0y1, ID_E1y1,
00075 ID_E00z, ID_E10z, ID_E01z, ID_E11z,
00076
00077 ID_Fxy0, ID_Fxy1, ID_Fx0z, ID_Fx1z, ID_F0yz, ID_F1yz,
00078
00079 ID_Shell
00080 };
00081 enum {
00082
00083 ID_FirstV = ID_V000, ID_FirstE = ID_Ex00, ID_FirstF = ID_Fxy0
00084
00085 };
00086
00087
00088 public:
00089
00090
00091
00092
00093 static int NbVertices() { return 8; }
00094 static int NbEdges() { return 12; }
00095 static int NbFaces() { return 6; }
00096 static int NbSubShapes() { return ID_Shell; }
00097
00098
00099 static inline bool IsVertexID( int theShapeID )
00100 { return ( theShapeID >= ID_V000 && theShapeID <= ID_V111 ); }
00101
00102 static inline bool IsEdgeID( int theShapeID )
00103 { return ( theShapeID >= ID_Ex00 && theShapeID <= ID_E11z ); }
00104
00105 static inline bool IsFaceID( int theShapeID )
00106 { return ( theShapeID >= ID_Fxy0 && theShapeID <= ID_F1yz ); }
00107
00108 static int ShapeIndex( int theShapeID )
00109 {
00110 if ( IsVertexID( theShapeID )) return theShapeID - ID_V000;
00111 if ( IsEdgeID( theShapeID )) return theShapeID - ID_Ex00;
00112 if ( IsFaceID( theShapeID )) return theShapeID - ID_Fxy0;
00113 return 0;
00114 }
00115
00116
00117
00118
00119
00120 static void GetFaceEdgesIDs (const int faceID, std::vector< int >& edgeVec );
00121
00122
00123 static void GetEdgeVertexIDs (const int edgeID, std::vector< int >& vertexVec );
00124
00125
00126 static int GetCoordIndOnEdge (const int theEdgeID)
00127 { return (theEdgeID < ID_E0y0) ? 1 : (theEdgeID < ID_E00z) ? 2 : 3; }
00128
00129
00130 static double* GetShapeCoef (const int theShapeID);
00131
00132
00133
00134
00135
00136
00137
00138 static int GetShapeIDByParams ( const gp_XYZ& theParams );
00139
00140
00141 static std::ostream& DumpShapeID (const int theBlockShapeID, std::ostream& stream);
00142
00143
00144
00145 public:
00146
00147
00148
00149
00150 SMESH_Block();
00151
00152 bool LoadBlockShapes(const TopoDS_Shell& theShell,
00153 const TopoDS_Vertex& theVertex000,
00154 const TopoDS_Vertex& theVertex001,
00155 TopTools_IndexedMapOfOrientedShape& theShapeIDMap );
00156
00157
00158
00159
00160 bool LoadBlockShapes(const TopTools_IndexedMapOfOrientedShape& theShapeIDMap);
00161
00162
00163 bool LoadMeshBlock(const SMDS_MeshVolume* theVolume,
00164 const int theNode000Index,
00165 const int theNode001Index,
00166 std::vector<const SMDS_MeshNode*>& theOrderedNodes);
00167
00168
00169
00170 bool LoadFace(const TopoDS_Face& theFace,
00171 const int theFaceID,
00172 const TopTools_IndexedMapOfOrientedShape& theShapeIDMap);
00173
00174
00175
00176
00177 static bool Insert(const TopoDS_Shape& theShape,
00178 const int theShapeID,
00179 TopTools_IndexedMapOfOrientedShape& theShapeIDMap);
00180
00181
00182
00183
00184 static bool FindBlockShapes(const TopoDS_Shell& theShell,
00185 const TopoDS_Vertex& theVertex000,
00186 const TopoDS_Vertex& theVertex001,
00187 TopTools_IndexedMapOfOrientedShape& theShapeIDMap );
00188
00189
00190
00191 public:
00192
00193
00194
00195
00196 bool VertexPoint( const int theVertexID, gp_XYZ& thePoint ) const {
00197 if ( !IsVertexID( theVertexID )) return false;
00198 thePoint = myPnt[ theVertexID - ID_FirstV ]; return true;
00199 }
00200
00201
00202 bool EdgePoint( const int theEdgeID, const gp_XYZ& theParams, gp_XYZ& thePoint ) const {
00203 if ( !IsEdgeID( theEdgeID )) return false;
00204 thePoint = myEdge[ theEdgeID - ID_FirstE ].Point( theParams ); return true;
00205 }
00206
00207
00208 bool EdgeU( const int theEdgeID, const gp_XYZ& theParams, double& theU ) const {
00209 if ( !IsEdgeID( theEdgeID )) return false;
00210 theU = myEdge[ theEdgeID - ID_FirstE ].GetU( theParams ); return true;
00211 }
00212
00213
00214 bool FacePoint( const int theFaceID, const gp_XYZ& theParams, gp_XYZ& thePoint ) const {
00215 if ( !IsFaceID ( theFaceID )) return false;
00216 thePoint = myFace[ theFaceID - ID_FirstF ].Point( theParams ); return true;
00217 }
00218
00219
00220 bool FaceUV( const int theFaceID, const gp_XYZ& theParams, gp_XY& theUV ) const {
00221 if ( !IsFaceID ( theFaceID )) return false;
00222 theUV = myFace[ theFaceID - ID_FirstF ].GetUV( theParams ); return true;
00223 }
00224
00225
00226 bool ShellPoint( const gp_XYZ& theParams, gp_XYZ& thePoint ) const;
00227
00228
00229 static bool ShellPoint(const gp_XYZ& theParams,
00230 const std::vector<gp_XYZ>& thePointOnShape,
00231 gp_XYZ& thePoint );
00232
00233
00234
00235
00236
00237
00238 public:
00239
00240
00241
00242
00243 bool ComputeParameters (const gp_Pnt& thePoint,
00244 gp_XYZ& theParams,
00245 const int theShapeID = ID_Shell,
00246 const gp_XYZ& theParamsHint = gp_XYZ(-1,-1,-1));
00247
00248
00249
00250 bool VertexParameters(const int theVertexID, gp_XYZ& theParams);
00251
00252
00253 bool EdgeParameters(const int theEdgeID, const double theU, gp_XYZ& theParams);
00254
00255
00256
00257 public:
00258
00259
00260
00261
00262
00263
00264 public:
00265
00266
00267
00268
00269 static bool IsForwardEdge (const TopoDS_Edge & theEdge,
00270 const TopTools_IndexedMapOfOrientedShape& theShapeIDMap) {
00271 int v1ID = theShapeIDMap.FindIndex( TopExp::FirstVertex( theEdge ).Oriented( TopAbs_FORWARD ));
00272 int v2ID = theShapeIDMap.FindIndex( TopExp::LastVertex( theEdge ).Oriented( TopAbs_FORWARD ));
00273 return ( v1ID < v2ID );
00274 }
00275
00276
00277 static int GetOrderedEdges (const TopoDS_Face& theFace,
00278 TopoDS_Vertex theFirstVertex,
00279 std::list< TopoDS_Edge >& theEdges,
00280 std::list< int > & theNbEdgesInWires,
00281 const bool theShapeAnalysisAlgo=false);
00282
00283
00284
00285
00286
00287
00288
00289 public:
00290
00291
00292
00293
00294 Standard_Integer NbVariables() const;
00295 Standard_Integer NbEquations() const;
00296 Standard_Boolean Value(const math_Vector& X,math_Vector& F) ;
00297 Standard_Boolean Derivatives(const math_Vector& X,math_Matrix& D) ;
00298 Standard_Boolean Values(const math_Vector& X,math_Vector& F,math_Matrix& D) ;
00299 Standard_Integer GetStateNumber ();
00300
00301 protected:
00302
00306 void init();
00307
00308
00309
00310
00311
00312
00313
00314 class SMESH_EXPORT TEdge {
00315 int myCoordInd;
00316 double myFirst;
00317 double myLast;
00318 Adaptor3d_Curve* myC3d;
00319
00320 gp_XYZ myNodes[2];
00321 public:
00322 void Set( const int edgeID, Adaptor3d_Curve* curve, const bool isForward );
00323 void Set( const int edgeID, const gp_XYZ& node1, const gp_XYZ& node2 );
00324 Adaptor3d_Curve* GetCurve() const { return myC3d; }
00325 double EndParam(int i) const { return i ? myLast : myFirst; }
00326 int CoordInd() const { return myCoordInd; }
00327 const gp_XYZ& NodeXYZ(int i) const { return i ? myNodes[1] : myNodes[0]; }
00328 gp_XYZ Point( const gp_XYZ& theParams ) const;
00329 double GetU( const gp_XYZ& theParams ) const;
00330 TEdge(): myC3d(0) {}
00331 ~TEdge();
00332 };
00333
00334 class SMESH_EXPORT TFace {
00335
00336 int myCoordInd[ 4 ];
00337 double myFirst [ 4 ];
00338 double myLast [ 4 ];
00339 Adaptor2d_Curve2d* myC2d [ 4 ];
00340
00341 gp_XY myCorner [ 4 ];
00342
00343 Adaptor3d_Surface* myS;
00344
00345 gp_XYZ myNodes[4];
00346 public:
00347 void Set( const int faceID, Adaptor3d_Surface* S,
00348 Adaptor2d_Curve2d* c2d[4], const bool isForward[4] );
00349 void Set( const int faceID, const TEdge& edgeU0, const TEdge& edgeU1 );
00350 gp_XY GetUV( const gp_XYZ& theParams ) const;
00351 gp_XYZ Point( const gp_XYZ& theParams ) const;
00352 int GetUInd() const { return myCoordInd[ 0 ]; }
00353 int GetVInd() const { return myCoordInd[ 2 ]; }
00354 void GetCoefs( int i, const gp_XYZ& theParams, double& eCoef, double& vCoef ) const;
00355 TFace(): myS(0) { myC2d[0]=myC2d[1]=myC2d[2]=myC2d[3]=0; }
00356 ~TFace();
00357 };
00358
00359
00360
00361 gp_XYZ myPnt[ 8 ];
00362
00363 TEdge myEdge[ 12 ];
00364
00365 TFace myFace[ 6 ];
00366
00367
00368
00369 enum { SQUARE_DIST = 0, DRV_1, DRV_2, DRV_3 };
00370 double distance () const { return sqrt( myValues[ SQUARE_DIST ]); }
00371 double funcValue(double sqDist) const { return mySquareFunc ? sqDist : sqrt(sqDist); }
00372 bool computeParameters(const gp_Pnt& thePoint, gp_XYZ& theParams, const gp_XYZ& theParamsHint);
00373
00374 int myFaceIndex;
00375 double myFaceParam;
00376 int myNbIterations;
00377 double mySumDist;
00378 double myTolerance;
00379 bool mySquareFunc;
00380
00381 gp_XYZ myPoint;
00382 gp_XYZ myParam;
00383 double myValues[ 4 ];
00384
00385 typedef std::pair<gp_XYZ,gp_XYZ> TxyzPair;
00386 TxyzPair my3x3x3GridNodes[ 27 ];
00387 bool myGridComputed;
00388 };
00389
00390
00391 #endif