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