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
00028
00029 #ifndef SMESH_MeshEditor_HeaderFile
00030 #define SMESH_MeshEditor_HeaderFile
00031
00032 #include "SMESH_SMESH.hxx"
00033
00034 #include "SMDS_MeshElement.hxx"
00035 #include "SMESH_Controls.hxx"
00036 #include "SMESH_Mesh.hxx"
00037 #include "SMESH_TypeDefs.hxx"
00038
00039 #include <utilities.h>
00040
00041 #include <TColStd_HSequenceOfReal.hxx>
00042 #include <gp_Dir.hxx>
00043
00044 #include <list>
00045 #include <map>
00046 #include <set>
00047
00048 class SMDS_MeshFace;
00049 class SMDS_MeshNode;
00050 class gp_Ax1;
00051 class gp_Vec;
00052 class gp_Pnt;
00053 class SMESH_MesherHelper;
00054
00055
00056
00060
00061 struct SMESH_NodeSearcher
00062 {
00063 virtual const SMDS_MeshNode* FindClosestTo( const gp_Pnt& pnt ) = 0;
00064 virtual void MoveNode( const SMDS_MeshNode* node, const gp_Pnt& toPnt ) = 0;
00065 };
00066
00067
00075
00076
00077 struct SMESH_ElementSearcher
00078 {
00079 virtual int FindElementsByPoint(const gp_Pnt& point,
00080 SMDSAbs_ElementType type,
00081 std::vector< const SMDS_MeshElement* >& foundElems)=0;
00082
00083 virtual TopAbs_State GetPointState(const gp_Pnt& point) = 0;
00084
00088 virtual void GetElementsNearLine( const gp_Ax1& line,
00089 SMDSAbs_ElementType type,
00090 std::vector< const SMDS_MeshElement* >& foundElems)=0;
00091 };
00092
00093
00097
00098
00099 class SMESH_EXPORT SMESH_MeshEditor
00100 {
00101 public:
00102
00103 SMESH_MeshEditor( SMESH_Mesh* theMesh );
00104
00108 SMDS_MeshElement* AddElement(const std::vector<const SMDS_MeshNode*> & nodes,
00109 const SMDSAbs_ElementType type,
00110 const bool isPoly,
00111 const int ID = -1);
00115 SMDS_MeshElement* AddElement(const std::vector<int> & nodeIDs,
00116 const SMDSAbs_ElementType type,
00117 const bool isPoly,
00118 const int ID = -1);
00119
00120 int Remove (const std::list< int >& theElemIDs, const bool isNodes);
00121
00122
00123
00124 bool InverseDiag (const SMDS_MeshElement * theTria1,
00125 const SMDS_MeshElement * theTria2 );
00126
00127
00128
00129
00130 bool InverseDiag (const SMDS_MeshNode * theNode1,
00131 const SMDS_MeshNode * theNode2 );
00132
00133
00134
00135
00136 bool DeleteDiag (const SMDS_MeshNode * theNode1,
00137 const SMDS_MeshNode * theNode2 );
00138
00139
00140
00141
00142 bool Reorient (const SMDS_MeshElement * theElement);
00143
00144
00145
00154 bool TriToQuad (TIDSortedElemSet & theElems,
00155 SMESH::Controls::NumericalFunctorPtr theCriterion,
00156 const double theMaxAngle);
00157
00164 bool QuadToTri (TIDSortedElemSet & theElems,
00165 SMESH::Controls::NumericalFunctorPtr theCriterion);
00166
00173 bool QuadToTri (TIDSortedElemSet & theElems,
00174 const bool the13Diag);
00175
00182 int BestSplit (const SMDS_MeshElement* theQuad,
00183 SMESH::Controls::NumericalFunctorPtr theCriterion);
00184
00185
00186 enum SplitVolumToTetraFlags { HEXA_TO_5 = 1, HEXA_TO_6 = 2, HEXA_TO_24 = 3 };
00187
00190 void SplitVolumesIntoTetra (const TIDSortedElemSet & theElems, const int theMethodFlags);
00191
00192
00193 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
00194
00195 void Smooth (TIDSortedElemSet & theElements,
00196 std::set<const SMDS_MeshNode*> & theFixedNodes,
00197 const SmoothMethod theSmoothMethod,
00198 const int theNbIterations,
00199 double theTgtAspectRatio = 1.0,
00200 const bool the2D = true);
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 typedef std::auto_ptr< std::list<int> > PGroupIDs;
00211
00212 PGroupIDs RotationSweep (TIDSortedElemSet & theElements,
00213 const gp_Ax1& theAxis,
00214 const double theAngle,
00215 const int theNbSteps,
00216 const double theToler,
00217 const bool theMakeGroups,
00218 const bool theMakeWalls=true);
00219
00220
00221
00227 enum ExtrusionFlags {
00228 EXTRUSION_FLAG_BOUNDARY = 0x01,
00229 EXTRUSION_FLAG_SEW = 0x02
00230 };
00231
00235 struct ExtrusParam {
00236 gp_Dir myDir;
00237 Handle(TColStd_HSequenceOfReal) mySteps;
00238 SMESH_SequenceOfNode myNodes;
00239 };
00240
00245 const SMDS_MeshNode* CreateNode(const double x,
00246 const double y,
00247 const double z,
00248 const double tolnode,
00249 SMESH_SequenceOfNode& aNodes);
00250
00263 PGroupIDs ExtrusionSweep (TIDSortedElemSet & theElems,
00264 const gp_Vec& theStep,
00265 const int theNbSteps,
00266 TElemOfElemListMap& newElemsMap,
00267 const bool theMakeGroups,
00268 const int theFlags = EXTRUSION_FLAG_BOUNDARY,
00269 const double theTolerance = 1.e-6);
00270
00281 PGroupIDs ExtrusionSweep (TIDSortedElemSet & theElems,
00282 ExtrusParam& theParams,
00283 TElemOfElemListMap& newElemsMap,
00284 const bool theMakeGroups,
00285 const int theFlags,
00286 const double theTolerance);
00287
00288
00289
00290
00291
00292 enum Extrusion_Error {
00293 EXTR_OK,
00294 EXTR_NO_ELEMENTS,
00295 EXTR_PATH_NOT_EDGE,
00296 EXTR_BAD_PATH_SHAPE,
00297 EXTR_BAD_STARTING_NODE,
00298 EXTR_BAD_ANGLES_NUMBER,
00299 EXTR_CANT_GET_TANGENT
00300 };
00301
00302 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet & theElements,
00303 SMESH_subMesh* theTrackPattern,
00304 const SMDS_MeshNode* theNodeStart,
00305 const bool theHasAngles,
00306 std::list<double>& theAngles,
00307 const bool theLinearVariation,
00308 const bool theHasRefPoint,
00309 const gp_Pnt& theRefPoint,
00310 const bool theMakeGroups);
00311 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet & theElements,
00312 SMESH_Mesh* theTrackPattern,
00313 const SMDS_MeshNode* theNodeStart,
00314 const bool theHasAngles,
00315 std::list<double>& theAngles,
00316 const bool theLinearVariation,
00317 const bool theHasRefPoint,
00318 const gp_Pnt& theRefPoint,
00319 const bool theMakeGroups);
00320
00321
00322
00323 PGroupIDs Transform (TIDSortedElemSet & theElements,
00324 const gp_Trsf& theTrsf,
00325 const bool theCopy,
00326 const bool theMakeGroups,
00327 SMESH_Mesh* theTargetMesh=0);
00328
00329
00330
00331 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
00332
00333 void FindCoincidentNodes (TIDSortedNodeSet & theNodes,
00334 const double theTolerance,
00335 TListOfListOfNodes & theGroupsOfNodes);
00336
00337
00338
00342 SMESH_NodeSearcher* GetNodeSearcher();
00343
00347 SMESH_ElementSearcher* GetElementSearcher();
00348 SMESH_ElementSearcher* GetElementSearcher( SMDS_ElemIteratorPtr elemIt );
00352 static bool isOut( const SMDS_MeshElement* element, const gp_Pnt& point, double tol );
00353
00354
00355 int SimplifyFace (const std::vector<const SMDS_MeshNode *> faceNodes,
00356 std::vector<const SMDS_MeshNode *>& poly_nodes,
00357 std::vector<int>& quantities) const;
00358
00359
00360
00361 void MergeNodes (TListOfListOfNodes & theNodeGroups);
00362
00363
00364
00365 typedef std::list< std::list< int > > TListOfListOfElementsID;
00366
00367 void FindEqualElements(std::set<const SMDS_MeshElement*> & theElements,
00368 TListOfListOfElementsID & theGroupsOfElementsID);
00369
00370
00371
00372 void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
00373
00374
00375 void MergeEqualElements();
00376
00377
00378
00379 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
00380 const SMDS_MeshNode* theNode2,
00381 const SMDS_MeshNode* theNode3 = 0);
00382
00383
00384 static bool FindFreeBorder (const SMDS_MeshNode* theFirstNode,
00385 const SMDS_MeshNode* theSecondNode,
00386 const SMDS_MeshNode* theLastNode,
00387 std::list< const SMDS_MeshNode* > & theNodes,
00388 std::list< const SMDS_MeshElement* >& theFaces);
00389
00390
00391 enum Sew_Error {
00392 SEW_OK,
00393
00394 SEW_BORDER1_NOT_FOUND,
00395 SEW_BORDER2_NOT_FOUND,
00396 SEW_BOTH_BORDERS_NOT_FOUND,
00397 SEW_BAD_SIDE_NODES,
00398 SEW_VOLUMES_TO_SPLIT,
00399
00400 SEW_DIFF_NB_OF_ELEMENTS,
00401 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
00402 SEW_BAD_SIDE1_NODES,
00403 SEW_BAD_SIDE2_NODES,
00404 SEW_INTERNAL_ERROR
00405 };
00406
00407
00408 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
00409 const SMDS_MeshNode* theBorderSecondNode,
00410 const SMDS_MeshNode* theBorderLastNode,
00411 const SMDS_MeshNode* theSide2FirstNode,
00412 const SMDS_MeshNode* theSide2SecondNode,
00413 const SMDS_MeshNode* theSide2ThirdNode = 0,
00414 const bool theSide2IsFreeBorder = true,
00415 const bool toCreatePolygons = false,
00416 const bool toCreatePolyedrs = false);
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437 Sew_Error SewSideElements (TIDSortedElemSet& theSide1,
00438 TIDSortedElemSet& theSide2,
00439 const SMDS_MeshNode* theFirstNode1ToMerge,
00440 const SMDS_MeshNode* theFirstNode2ToMerge,
00441 const SMDS_MeshNode* theSecondNode1ToMerge,
00442 const SMDS_MeshNode* theSecondNode2ToMerge);
00443
00444
00445
00446
00447
00448
00449
00450 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
00451 const SMDS_MeshNode* theBetweenNode1,
00452 const SMDS_MeshNode* theBetweenNode2,
00453 std::list<const SMDS_MeshNode*>& theNodesToInsert,
00454 const bool toCreatePoly = false);
00455
00456
00457
00458 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
00459 const SMDS_MeshNode* theBetweenNode2,
00460 std::list<const SMDS_MeshNode*>& theNodesToInsert);
00461
00462
00463
00464 void ConvertToQuadratic(const bool theForce3d);
00465 void ConvertToQuadratic(const bool theForce3d, TIDSortedElemSet& theElements);
00466
00467
00468
00469
00470
00471
00472
00473
00474 bool ConvertFromQuadratic();
00475 void ConvertFromQuadratic(TIDSortedElemSet& theElements);
00476
00477
00478
00479
00480 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
00481 const SMDS_MeshElement* elemInGroups,
00482 SMESHDS_Mesh * aMesh);
00483
00484
00485 static void RemoveElemFromGroups (const SMDS_MeshElement* element,
00486 SMESHDS_Mesh * aMesh);
00487
00488
00489 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
00490 const SMDS_MeshElement* elemToAdd,
00491 SMESHDS_Mesh * aMesh);
00492
00493
00494 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
00495 const std::vector<const SMDS_MeshElement*>& elemToAdd,
00496 SMESHDS_Mesh * aMesh);
00497
00498
00502 static void GetLinkedNodes( const SMDS_MeshNode* node,
00503 TIDSortedElemSet & linkedNodes,
00504 SMDSAbs_ElementType type = SMDSAbs_All );
00505
00506 static const SMDS_MeshElement* FindFaceInSet(const SMDS_MeshNode* n1,
00507 const SMDS_MeshNode* n2,
00508 const TIDSortedElemSet& elemSet,
00509 const TIDSortedElemSet& avoidSet,
00510 int* i1=0,
00511 int* i2=0);
00512
00513
00514
00515
00516
00528 static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
00529 std::set<const SMDS_MeshElement*>& theSide2,
00530 const SMDS_MeshNode* theFirstNode1,
00531 const SMDS_MeshNode* theFirstNode2,
00532 const SMDS_MeshNode* theSecondNode1,
00533 const SMDS_MeshNode* theSecondNode2,
00534 TNodeNodeMap & theNodeReplaceMap);
00535
00542 static bool IsMedium(const SMDS_MeshNode* node,
00543 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
00544
00545 int FindShape (const SMDS_MeshElement * theElem);
00546
00547
00548
00549 SMESH_Mesh * GetMesh() { return myMesh; }
00550
00551 SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }
00552
00553 const SMESH_SequenceOfElemPtr& GetLastCreatedNodes() const { return myLastCreatedNodes; }
00554
00555 const SMESH_SequenceOfElemPtr& GetLastCreatedElems() const { return myLastCreatedElems; }
00556
00557 bool DoubleNodes( const std::list< int >& theListOfNodes,
00558 const std::list< int >& theListOfModifiedElems );
00559
00560 bool DoubleNodes( const TIDSortedElemSet& theElems,
00561 const TIDSortedElemSet& theNodesNot,
00562 const TIDSortedElemSet& theAffectedElems );
00563
00564 bool DoubleNodesInRegion( const TIDSortedElemSet& theElems,
00565 const TIDSortedElemSet& theNodesNot,
00566 const TopoDS_Shape& theShape );
00567
00568 double OrientedAngle(const gp_Pnt& p0, const gp_Pnt& p1, const gp_Pnt& g1, const gp_Pnt& g2);
00569
00570 bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
00571 bool createJointElems);
00572
00573 bool CreateFlatElementsOnFacesGroups( const std::vector<TIDSortedElemSet>& theElems );
00574
00580 bool Make2DMeshFrom3D();
00581
00582 enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
00583
00584 int MakeBoundaryMesh(const TIDSortedElemSet& elements,
00585 Bnd_Dimension dimension,
00586 SMESH_Group* group = 0,
00587 SMESH_Mesh* targetMesh = 0,
00588 bool toCopyElements = false,
00589 bool toCopyExistingBondary = false,
00590 bool toAddExistingBondary = false,
00591 bool aroundElements = false);
00592
00593
00594 private:
00595
00600 int convertElemToQuadratic(SMESHDS_SubMesh * theSm,
00601 SMESH_MesherHelper& theHelper,
00602 const bool theForce3d);
00603
00608 int removeQuadElem( SMESHDS_SubMesh * theSm,
00609 SMDS_ElemIteratorPtr theItr,
00610 const int theShapeID);
00617 PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
00618 const SMESH_SequenceOfElemPtr& elemGens,
00619 const std::string& postfix,
00620 SMESH_Mesh* targetMesh=0);
00621
00622
00623 typedef std::map<const SMDS_MeshNode*, std::list<const SMDS_MeshNode*> > TNodeOfNodeListMap;
00624 typedef TNodeOfNodeListMap::iterator TNodeOfNodeListMapItr;
00625 typedef std::vector<TNodeOfNodeListMapItr> TVecOfNnlmiMap;
00626 typedef std::map<const SMDS_MeshElement*, TVecOfNnlmiMap > TElemOfVecOfNnlmiMap;
00627
00636 void sweepElement(const SMDS_MeshElement* elem,
00637 const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
00638 std::list<const SMDS_MeshElement*>& newElems,
00639 const int nbSteps,
00640 SMESH_SequenceOfElemPtr& srcElements);
00641
00651 void makeWalls (TNodeOfNodeListMap & mapNewNodes,
00652 TElemOfElemListMap & newElemsMap,
00653 TElemOfVecOfNnlmiMap & elemNewNodesMap,
00654 TIDSortedElemSet& elemSet,
00655 const int nbSteps,
00656 SMESH_SequenceOfElemPtr& srcElements);
00657
00658 struct SMESH_MeshEditor_PathPoint
00659 {
00660 gp_Pnt myPnt;
00661 gp_Dir myTgt;
00662 double myAngle, myPrm;
00663
00664 SMESH_MeshEditor_PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myPrm(0) {}
00665 void SetPnt (const gp_Pnt& aP3D) { myPnt =aP3D; }
00666 void SetTangent (const gp_Dir& aTgt) { myTgt =aTgt; }
00667 void SetAngle (const double& aBeta) { myAngle=aBeta; }
00668 void SetParameter(const double& aPrm) { myPrm =aPrm; }
00669 const gp_Pnt& Pnt ()const { return myPnt; }
00670 const gp_Dir& Tangent ()const { return myTgt; }
00671 double Angle ()const { return myAngle; }
00672 double Parameter ()const { return myPrm; }
00673 };
00674 Extrusion_Error MakeEdgePathPoints(std::list<double>& aPrms,
00675 const TopoDS_Edge& aTrackEdge,
00676 bool aFirstIsStart,
00677 std::list<SMESH_MeshEditor_PathPoint>& aLPP);
00678 Extrusion_Error MakeExtrElements(TIDSortedElemSet& theElements,
00679 std::list<SMESH_MeshEditor_PathPoint>& theFullList,
00680 const bool theHasAngles,
00681 std::list<double>& theAngles,
00682 const bool theLinearVariation,
00683 const bool theHasRefPoint,
00684 const gp_Pnt& theRefPoint,
00685 const bool theMakeGroups);
00686 void LinearAngleVariation(const int NbSteps,
00687 list<double>& theAngles);
00688
00689 bool doubleNodes( SMESHDS_Mesh* theMeshDS,
00690 const TIDSortedElemSet& theElems,
00691 const TIDSortedElemSet& theNodesNot,
00692 std::map< const SMDS_MeshNode*, const SMDS_MeshNode* >& theNodeNodeMap,
00693 const bool theIsDoubleElem );
00694
00695 private:
00696
00697 SMESH_Mesh * myMesh;
00698
00702 SMESH_SequenceOfElemPtr myLastCreatedNodes;
00703
00707 SMESH_SequenceOfElemPtr myLastCreatedElems;
00708
00709 };
00710
00711 #endif