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_Pattern_HeaderFile
00028 #define SMESH_Pattern_HeaderFile
00029
00030 #include "SMESH_SMESH.hxx"
00031
00032 #include <vector>
00033 #include <list>
00034 #include <map>
00035 #include <set>
00036 #include <iostream>
00037
00038 #include <TopoDS_Shape.hxx>
00039 #include <TopTools_IndexedMapOfOrientedShape.hxx>
00040 #include <gp_XYZ.hxx>
00041 #include <gp_XY.hxx>
00042 #include <gp_Pnt.hxx>
00043
00044 class SMDS_MeshElement;
00045 class SMDS_MeshFace;
00046 class SMDS_MeshVolume;
00047 class SMDS_MeshNode;
00048 class SMESH_Mesh;
00049 class SMESHDS_SubMesh;
00050 class TopoDS_Shell;
00051 class TopoDS_Vertex;
00052 class TopoDS_Face;
00053 class TopoDS_Edge;
00054
00055
00056
00057
00058
00059
00060
00061 class SMESH_EXPORT SMESH_Pattern {
00062 public:
00063
00064 SMESH_Pattern ();
00065
00066 void Clear();
00067
00068
00069 bool Load (const char* theFileContents);
00070
00071
00072 bool Load (SMESH_Mesh* theMesh,
00073 const TopoDS_Face& theFace,
00074 bool theProject = false);
00075
00076
00077
00078
00079 bool Load (SMESH_Mesh* theMesh,
00080 const TopoDS_Shell& theBlock);
00081
00082
00083 bool Save (std::ostream& theFile);
00084
00085
00086 bool Apply (const TopoDS_Face& theFace,
00087 const TopoDS_Vertex& theVertexOnKeyPoint1,
00088 const bool theReverse);
00089
00090
00091
00092
00093
00094 bool Apply (const TopoDS_Shell& theBlock,
00095 const TopoDS_Vertex& theVertex000,
00096 const TopoDS_Vertex& theVertex001);
00097
00098
00099
00100
00101
00102 bool Apply (const SMDS_MeshFace* theFace,
00103 const int theNodeIndexOnKeyPoint1,
00104 const bool theReverse);
00105
00106
00107
00108
00109 bool Apply (SMESH_Mesh* theMesh,
00110 const SMDS_MeshFace* theFace,
00111 const TopoDS_Shape& theSurface,
00112 const int theNodeIndexOnKeyPoint1,
00113 const bool theReverse);
00114
00115
00116
00117
00118 bool Apply (SMESH_Mesh* theMesh,
00119 std::set<const SMDS_MeshFace*>& theFaces,
00120 const int theNodeIndexOnKeyPoint1,
00121 const bool theReverse);
00122
00123
00124
00125
00126 bool Apply (const SMDS_MeshVolume* theVolume,
00127 const int theNode000Index,
00128 const int theNode001Index);
00129
00130
00131
00132
00133
00134
00135 bool Apply (std::set<const SMDS_MeshVolume*>& theVolumes,
00136 const int theNode000Index,
00137 const int theNode001Index);
00138
00139
00140
00141
00142
00143
00144 bool GetMappedPoints ( std::list<const gp_XYZ *> & thePoints ) const;
00145
00146
00147 bool MakeMesh(SMESH_Mesh* theMesh,
00148 const bool toCreatePolygons = false,
00149 const bool toCreatePolyedrs = false);
00150
00151
00152
00153
00154
00155
00156
00157 enum ErrorCode {
00158 ERR_OK,
00159
00160 ERR_READ_NB_POINTS,
00161 ERR_READ_POINT_COORDS,
00162 ERR_READ_TOO_FEW_POINTS,
00163 ERR_READ_3D_COORD,
00164 ERR_READ_NO_KEYPOINT,
00165 ERR_READ_BAD_INDEX,
00166 ERR_READ_ELEM_POINTS,
00167 ERR_READ_NO_ELEMS,
00168 ERR_READ_BAD_KEY_POINT,
00169
00170 ERR_SAVE_NOT_LOADED,
00171
00172 ERR_LOAD_EMPTY_SUBMESH,
00173
00174 ERR_LOADF_NARROW_FACE,
00175 ERR_LOADF_CLOSED_FACE,
00176 ERR_LOADF_CANT_PROJECT,
00177
00178 ERR_LOADV_BAD_SHAPE,
00179 ERR_LOADV_COMPUTE_PARAMS,
00180
00181 ERR_APPL_NOT_COMPUTED,
00182 ERR_APPL_NOT_LOADED,
00183 ERR_APPL_BAD_DIMENTION,
00184 ERR_APPL_BAD_NB_VERTICES,
00185
00186 ERR_APPLF_BAD_TOPOLOGY,
00187 ERR_APPLF_BAD_VERTEX,
00188 ERR_APPLF_INTERNAL_EEROR,
00189
00190 ERR_APPLV_BAD_SHAPE,
00191
00192 ERR_APPLF_BAD_FACE_GEOM,
00193
00194 ERR_MAKEM_NOT_COMPUTED,
00195
00196 ERR_UNEXPECTED
00197 };
00198
00199 ErrorCode GetErrorCode() const { return myErrorCode; }
00200
00201
00202 bool IsLoaded() const { return !myPoints.empty() && !myElemPointIDs.empty(); }
00203
00204
00205 bool Is2D() const { return myIs2D; }
00206
00207
00208 bool GetPoints ( std::list<const gp_XYZ *> & thePoints ) const;
00209
00210
00211 const std::list< int > & GetKeyPointIDs () const { return myKeyPointIDs; }
00212
00213
00214
00215 const std::list< std::list< int > >& GetElementPointIDs (bool applied) const
00216 { return myElemXYZIDs.empty() || !applied ? myElemPointIDs : myElemXYZIDs; }
00217
00218
00219 void DumpPoints() const;
00220
00221
00222
00223
00224
00225
00226 TopoDS_Shape GetSubShape( const int i ) const {
00227 if ( i < 1 || i > myShapeIDMap.Extent() ) return TopoDS_Shape();
00228 return myShapeIDMap( i );
00229 }
00230
00231
00232
00233 private:
00234
00235
00236 struct TPoint {
00237 gp_XYZ myInitXYZ;
00238 gp_XY myInitUV;
00239 double myInitU;
00240 gp_Pnt myXYZ;
00241 gp_XY myUV;
00242 double myU;
00243 TPoint();
00244 };
00245 friend std::ostream & operator <<(std::ostream & OS, const TPoint& p);
00246
00247 bool setErrorCode( const ErrorCode theErrorCode );
00248
00249
00250 bool setShapeToMesh(const TopoDS_Shape& theShape);
00251
00252
00253 std::list< TPoint* > & getShapePoints(const TopoDS_Shape& theShape);
00254
00255
00256
00257
00258
00259 std::list< TPoint* > & getShapePoints(const int theShapeID);
00260
00261
00262 bool findBoundaryPoints();
00263
00264
00265
00266 void arrangeBoundaries (std::list< std::list< TPoint* > >& boundaryPoints);
00267
00268
00269
00270
00271
00272 void computeUVOnEdge( const TopoDS_Edge& theEdge, const std::list< TPoint* > & ePoints );
00273
00274
00275 bool compUVByIsoIntersection (const std::list< std::list< TPoint* > >& boundaryPoints,
00276 const gp_XY& theInitUV,
00277 gp_XY& theUV,
00278 bool & theIsDeformed);
00279
00280
00281 bool compUVByElasticIsolines(const std::list< std::list< TPoint* > >& boundaryPoints,
00282 const std::list< TPoint* >& pointsToCompute);
00283
00284
00285
00286 double setFirstEdge (std::list< TopoDS_Edge > & theWire, int theFirstEdgeID);
00287
00288
00289
00290
00291 typedef std::list< std::list< TopoDS_Edge > > TListOfEdgesList;
00292
00293 bool sortSameSizeWires (TListOfEdgesList & theWireList,
00294 const TListOfEdgesList::iterator& theFromWire,
00295 const TListOfEdgesList::iterator& theToWire,
00296 const int theFirstEdgeID,
00297 std::list< std::list< TPoint* > >& theEdgesPointsList );
00298
00299
00300
00301
00302
00303
00304 typedef std::set<const SMDS_MeshNode*> TNodeSet;
00305
00306 void mergePoints (const bool uniteGroups);
00307
00308
00309 void makePolyElements(const std::vector< const SMDS_MeshNode* >& theNodes,
00310 const bool toCreatePolygons,
00311 const bool toCreatePolyedrs);
00312
00313
00314 void createElements(SMESH_Mesh* theMesh,
00315 const std::vector<const SMDS_MeshNode* >& theNodesVector,
00316 const std::list< std::list< int > > & theElemNodeIDs,
00317 const std::vector<const SMDS_MeshElement*>& theElements);
00318
00319
00320 bool getFacesDefinition(const SMDS_MeshNode** theBndNodes,
00321 const int theNbBndNodes,
00322 const std::vector< const SMDS_MeshNode* >& theNodes,
00323 std::list< int >& theFaceDefs,
00324 std::vector<int>& theQuantity);
00325
00326
00327
00328
00329 bool isReversed(const SMDS_MeshNode* theFirstNode,
00330 const std::list< int >& theIdsList) const;
00331
00332
00333
00334 void clearMesh(SMESH_Mesh* theMesh) const;
00335
00336
00337 static SMESHDS_SubMesh * getSubmeshWithElements(SMESH_Mesh* theMesh,
00338 const TopoDS_Shape& theShape);
00339
00340
00341 private:
00342
00343
00344 typedef std::list< int > TElemDef;
00345
00346 bool myIs2D;
00347 std::vector< TPoint > myPoints;
00348 std::list< int > myKeyPointIDs;
00349 std::list< TElemDef > myElemPointIDs;
00350
00351 ErrorCode myErrorCode;
00352 bool myIsComputed;
00353 bool myIsBoundaryPointsFound;
00354
00355 TopoDS_Shape myShape;
00356
00357
00358 TopTools_IndexedMapOfOrientedShape myShapeIDMap;
00359 std::map< int, std::list< TPoint* > > myShapeIDToPointsMap;
00360
00361
00362
00363 std::list< int > myNbKeyPntInBoundary;
00364
00365
00366
00367
00368 std::vector<gp_XYZ> myXYZ;
00369 std::list< TElemDef > myElemXYZIDs;
00370 std::map< int, const SMDS_MeshNode*> myXYZIdToNodeMap;
00371 std::vector<const SMDS_MeshElement*> myElements;
00372 std::vector<const SMDS_MeshNode*> myOrderedNodes;
00373
00374
00375 std::vector<const SMDS_MeshElement*> myPolyElems;
00376
00377 std::list< TElemDef > myPolyElemXYZIDs;
00378 std::list< std::vector<int> > myPolyhedronQuantities;
00379
00380
00381
00382
00383 std::map<TNodeSet,std::list<std::list<int> > > myIdsOnBoundary;
00384
00385 std::map< int, std::list< TElemDef* > > myReverseConnectivity;
00386 };
00387
00388
00389 #endif