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 #ifndef SMESH_MeshEditor_HeaderFile
00029 #define SMESH_MeshEditor_HeaderFile
00030
00031 #include "SMESH_SMESH.hxx"
00032
00033 #include "SMDS_MeshElement.hxx"
00034 #include "SMESH_Controls.hxx"
00035 #include "SMESH_Mesh.hxx"
00036 #include "SMESH_SequenceOfElemPtr.hxx"
00037 #include "SMESH_SequenceOfNode.hxx"
00038
00039 #include <TColStd_HSequenceOfReal.hxx>
00040 #include <gp_Dir.hxx>
00041
00042 #include <list>
00043 #include <map>
00044 #include <set>
00045
00046 class SMDS_MeshFace;
00047 class SMDS_MeshNode;
00048 class gp_Ax1;
00049 class gp_Vec;
00050 class gp_Pnt;
00051 class SMESH_MesherHelper;
00052
00053
00054 typedef std::map<const SMDS_MeshElement*,
00055 std::list<const SMDS_MeshElement*> > TElemOfElemListMap;
00056 typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*> TNodeNodeMap;
00057
00059 typedef std::set< const SMDS_MeshElement*, TIDCompare > TIDSortedElemSet;
00060
00061 typedef pair< const SMDS_MeshNode*, const SMDS_MeshNode* > NLink;
00062
00063
00064
00068
00069 struct SMESH_NodeSearcher
00070 {
00071 virtual const SMDS_MeshNode* FindClosestTo( const gp_Pnt& pnt ) = 0;
00072 virtual void MoveNode( const SMDS_MeshNode* node, const gp_Pnt& toPnt ) = 0;
00073 };
00074
00075
00081
00082
00083 struct SMESH_ElementSearcher
00084 {
00085 virtual void FindElementsByPoint(const gp_Pnt& point,
00086 SMDSAbs_ElementType type,
00087 std::vector< const SMDS_MeshElement* >& foundElems)=0;
00088 };
00089
00090
00094
00095
00096 struct SMESH_TLink: public NLink
00097 {
00098 SMESH_TLink(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2 ):NLink( n1, n2 )
00099 { if ( n1->GetID() < n2->GetID() ) std::swap( first, second ); }
00100 SMESH_TLink(const NLink& link ):NLink( link )
00101 { if ( first->GetID() < second->GetID() ) std::swap( first, second ); }
00102 const SMDS_MeshNode* node1() const { return first; }
00103 const SMDS_MeshNode* node2() const { return second; }
00104 };
00105
00106
00110
00111 class SMESH_MeshEditor_PathPoint {
00112 public:
00113 SMESH_MeshEditor_PathPoint() {
00114 myPnt.SetCoord(99., 99., 99.);
00115 myTgt.SetCoord(1.,0.,0.);
00116 myAngle=0.;
00117 myPrm=0.;
00118 }
00119 void SetPnt(const gp_Pnt& aP3D){
00120 myPnt=aP3D;
00121 }
00122 void SetTangent(const gp_Dir& aTgt){
00123 myTgt=aTgt;
00124 }
00125 void SetAngle(const double& aBeta){
00126 myAngle=aBeta;
00127 }
00128 void SetParameter(const double& aPrm){
00129 myPrm=aPrm;
00130 }
00131 const gp_Pnt& Pnt()const{
00132 return myPnt;
00133 }
00134 const gp_Dir& Tangent()const{
00135 return myTgt;
00136 }
00137 double Angle()const{
00138 return myAngle;
00139 }
00140 double Parameter()const{
00141 return myPrm;
00142 }
00143
00144 protected:
00145 gp_Pnt myPnt;
00146 gp_Dir myTgt;
00147 double myAngle;
00148 double myPrm;
00149 };
00150
00151
00152
00156
00157
00158 class SMESH_EXPORT SMESH_MeshEditor {
00159
00160 public:
00161
00162 SMESH_MeshEditor( SMESH_Mesh* theMesh );
00163
00167 SMDS_MeshElement* AddElement(const std::vector<const SMDS_MeshNode*> & nodes,
00168 const SMDSAbs_ElementType type,
00169 const bool isPoly,
00170 const int ID = 0);
00174 SMDS_MeshElement* AddElement(const std::vector<int> & nodeIDs,
00175 const SMDSAbs_ElementType type,
00176 const bool isPoly,
00177 const int ID = 0);
00178
00179 bool Remove (const std::list< int >& theElemIDs, const bool isNodes);
00180
00181
00182
00183 bool InverseDiag (const SMDS_MeshElement * theTria1,
00184 const SMDS_MeshElement * theTria2 );
00185
00186
00187
00188
00189 bool InverseDiag (const SMDS_MeshNode * theNode1,
00190 const SMDS_MeshNode * theNode2 );
00191
00192
00193
00194
00195 bool DeleteDiag (const SMDS_MeshNode * theNode1,
00196 const SMDS_MeshNode * theNode2 );
00197
00198
00199
00200
00201 bool Reorient (const SMDS_MeshElement * theElement);
00202
00203
00204
00213 bool TriToQuad (TIDSortedElemSet & theElems,
00214 SMESH::Controls::NumericalFunctorPtr theCriterion,
00215 const double theMaxAngle);
00216
00223 bool QuadToTri (TIDSortedElemSet & theElems,
00224 SMESH::Controls::NumericalFunctorPtr theCriterion);
00225
00232 bool QuadToTri (TIDSortedElemSet & theElems,
00233 const bool the13Diag);
00234
00241 int BestSplit (const SMDS_MeshElement* theQuad,
00242 SMESH::Controls::NumericalFunctorPtr theCriterion);
00243
00244
00245 enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
00246
00247 void Smooth (TIDSortedElemSet & theElements,
00248 std::set<const SMDS_MeshNode*> & theFixedNodes,
00249 const SmoothMethod theSmoothMethod,
00250 const int theNbIterations,
00251 double theTgtAspectRatio = 1.0,
00252 const bool the2D = true);
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 typedef std::auto_ptr< std::list<int> > PGroupIDs;
00263
00264 PGroupIDs RotationSweep (TIDSortedElemSet & theElements,
00265 const gp_Ax1& theAxis,
00266 const double theAngle,
00267 const int theNbSteps,
00268 const double theToler,
00269 const bool theMakeGroups,
00270 const bool theMakeWalls=true);
00271
00272
00273
00279 enum ExtrusionFlags {
00280 EXTRUSION_FLAG_BOUNDARY = 0x01,
00281 EXTRUSION_FLAG_SEW = 0x02
00282 };
00283
00287 struct ExtrusParam {
00288 gp_Dir myDir;
00289 Handle(TColStd_HSequenceOfReal) mySteps;
00290 SMESH_SequenceOfNode myNodes;
00291 };
00292
00297 const SMDS_MeshNode* CreateNode(const double x,
00298 const double y,
00299 const double z,
00300 const double tolnode,
00301 SMESH_SequenceOfNode& aNodes);
00302
00315 PGroupIDs ExtrusionSweep (TIDSortedElemSet & theElems,
00316 const gp_Vec& theStep,
00317 const int theNbSteps,
00318 TElemOfElemListMap& newElemsMap,
00319 const bool theMakeGroups,
00320 const int theFlags = EXTRUSION_FLAG_BOUNDARY,
00321 const double theTolerance = 1.e-6);
00322
00333 PGroupIDs ExtrusionSweep (TIDSortedElemSet & theElems,
00334 ExtrusParam& theParams,
00335 TElemOfElemListMap& newElemsMap,
00336 const bool theMakeGroups,
00337 const int theFlags,
00338 const double theTolerance);
00339
00340
00341
00342
00343
00344 enum Extrusion_Error {
00345 EXTR_OK,
00346 EXTR_NO_ELEMENTS,
00347 EXTR_PATH_NOT_EDGE,
00348 EXTR_BAD_PATH_SHAPE,
00349 EXTR_BAD_STARTING_NODE,
00350 EXTR_BAD_ANGLES_NUMBER,
00351 EXTR_CANT_GET_TANGENT
00352 };
00353
00354 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet & theElements,
00355 SMESH_subMesh* theTrackPattern,
00356 const SMDS_MeshNode* theNodeStart,
00357 const bool theHasAngles,
00358 std::list<double>& theAngles,
00359 const bool theLinearVariation,
00360 const bool theHasRefPoint,
00361 const gp_Pnt& theRefPoint,
00362 const bool theMakeGroups);
00363 Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet & theElements,
00364 SMESH_Mesh* theTrackPattern,
00365 const SMDS_MeshNode* theNodeStart,
00366 const bool theHasAngles,
00367 std::list<double>& theAngles,
00368 const bool theLinearVariation,
00369 const bool theHasRefPoint,
00370 const gp_Pnt& theRefPoint,
00371 const bool theMakeGroups);
00372
00373
00374
00375 PGroupIDs Transform (TIDSortedElemSet & theElements,
00376 const gp_Trsf& theTrsf,
00377 const bool theCopy,
00378 const bool theMakeGroups,
00379 SMESH_Mesh* theTargetMesh=0);
00380
00381
00382
00383 typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
00384
00385 void FindCoincidentNodes (std::set<const SMDS_MeshNode*> & theNodes,
00386 const double theTolerance,
00387 TListOfListOfNodes & theGroupsOfNodes);
00388
00389
00390
00394 SMESH_NodeSearcher* GetNodeSearcher();
00395
00399 SMESH_ElementSearcher* GetElementSearcher();
00403 static bool isOut( const SMDS_MeshElement* element, const gp_Pnt& point, double tol );
00404
00405
00406 int SimplifyFace (const std::vector<const SMDS_MeshNode *> faceNodes,
00407 std::vector<const SMDS_MeshNode *>& poly_nodes,
00408 std::vector<int>& quantities) const;
00409
00410
00411
00412 void MergeNodes (TListOfListOfNodes & theNodeGroups);
00413
00414
00415
00416 typedef std::list< std::list< int > > TListOfListOfElementsID;
00417
00418 void FindEqualElements(std::set<const SMDS_MeshElement*> & theElements,
00419 TListOfListOfElementsID & theGroupsOfElementsID);
00420
00421
00422
00423 void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
00424
00425
00426 void MergeEqualElements();
00427
00428
00429
00430 static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
00431 const SMDS_MeshNode* theNode2,
00432 const SMDS_MeshNode* theNode3 = 0);
00433
00434
00435 static bool FindFreeBorder (const SMDS_MeshNode* theFirstNode,
00436 const SMDS_MeshNode* theSecondNode,
00437 const SMDS_MeshNode* theLastNode,
00438 std::list< const SMDS_MeshNode* > & theNodes,
00439 std::list< const SMDS_MeshElement* >& theFaces);
00440
00441
00442 enum Sew_Error {
00443 SEW_OK,
00444
00445 SEW_BORDER1_NOT_FOUND,
00446 SEW_BORDER2_NOT_FOUND,
00447 SEW_BOTH_BORDERS_NOT_FOUND,
00448 SEW_BAD_SIDE_NODES,
00449 SEW_VOLUMES_TO_SPLIT,
00450
00451 SEW_DIFF_NB_OF_ELEMENTS,
00452 SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
00453 SEW_BAD_SIDE1_NODES,
00454 SEW_BAD_SIDE2_NODES,
00455 SEW_INTERNAL_ERROR
00456 };
00457
00458
00459 Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
00460 const SMDS_MeshNode* theBorderSecondNode,
00461 const SMDS_MeshNode* theBorderLastNode,
00462 const SMDS_MeshNode* theSide2FirstNode,
00463 const SMDS_MeshNode* theSide2SecondNode,
00464 const SMDS_MeshNode* theSide2ThirdNode = 0,
00465 const bool theSide2IsFreeBorder = true,
00466 const bool toCreatePolygons = false,
00467 const bool toCreatePolyedrs = false);
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488 Sew_Error SewSideElements (TIDSortedElemSet& theSide1,
00489 TIDSortedElemSet& theSide2,
00490 const SMDS_MeshNode* theFirstNode1ToMerge,
00491 const SMDS_MeshNode* theFirstNode2ToMerge,
00492 const SMDS_MeshNode* theSecondNode1ToMerge,
00493 const SMDS_MeshNode* theSecondNode2ToMerge);
00494
00495
00496
00497
00498
00499
00500
00501 void InsertNodesIntoLink(const SMDS_MeshElement* theFace,
00502 const SMDS_MeshNode* theBetweenNode1,
00503 const SMDS_MeshNode* theBetweenNode2,
00504 std::list<const SMDS_MeshNode*>& theNodesToInsert,
00505 const bool toCreatePoly = false);
00506
00507
00508
00509 void UpdateVolumes (const SMDS_MeshNode* theBetweenNode1,
00510 const SMDS_MeshNode* theBetweenNode2,
00511 std::list<const SMDS_MeshNode*>& theNodesToInsert);
00512
00513
00514
00515 void ConvertToQuadratic(const bool theForce3d);
00516
00517
00518
00519 bool ConvertFromQuadratic();
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535 static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
00536 const SMDS_MeshElement* elemInGroups,
00537 SMESHDS_Mesh * aMesh);
00538
00539
00540 static void RemoveElemFromGroups (const SMDS_MeshElement* element,
00541 SMESHDS_Mesh * aMesh);
00542
00543
00544 static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
00545 const SMDS_MeshElement* elemToAdd,
00546 SMESHDS_Mesh * aMesh);
00547
00548
00552 static void GetLinkedNodes( const SMDS_MeshNode* node,
00553 TIDSortedElemSet & linkedNodes,
00554 SMDSAbs_ElementType type = SMDSAbs_All );
00555
00556 static const SMDS_MeshElement*
00557 FindFaceInSet(const SMDS_MeshNode* n1,
00558 const SMDS_MeshNode* n2,
00559 const TIDSortedElemSet& elemSet,
00560 const TIDSortedElemSet& avoidSet);
00561
00562
00563
00564
00576 static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
00577 std::set<const SMDS_MeshElement*>& theSide2,
00578 const SMDS_MeshNode* theFirstNode1,
00579 const SMDS_MeshNode* theFirstNode2,
00580 const SMDS_MeshNode* theSecondNode1,
00581 const SMDS_MeshNode* theSecondNode2,
00582 TNodeNodeMap & nReplaceMap);
00583
00590 static bool IsMedium(const SMDS_MeshNode* node,
00591 const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
00592
00593 int FindShape (const SMDS_MeshElement * theElem);
00594
00595
00596
00597 SMESH_Mesh * GetMesh() { return myMesh; }
00598
00599 SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }
00600
00601 const SMESH_SequenceOfElemPtr& GetLastCreatedNodes() const { return myLastCreatedNodes; }
00602
00603 const SMESH_SequenceOfElemPtr& GetLastCreatedElems() const { return myLastCreatedElems; }
00604
00605 bool DoubleNodes( const std::list< int >& theListOfNodes,
00606 const std::list< int >& theListOfModifiedElems );
00607
00608 bool DoubleNodes( const TIDSortedElemSet& theElems,
00609 const TIDSortedElemSet& theNodesNot,
00610 const TIDSortedElemSet& theAffectedElems );
00611
00612 bool DoubleNodesInRegion( const TIDSortedElemSet& theElems,
00613 const TIDSortedElemSet& theNodesNot,
00614 const TopoDS_Shape& theShape );
00615
00621 bool Make2DMeshFrom3D();
00622
00623 private:
00624
00629 int convertElemToQuadratic(SMESHDS_SubMesh * theSm,
00630 SMESH_MesherHelper& theHelper,
00631 const bool theForce3d);
00632
00637 int removeQuadElem( SMESHDS_SubMesh * theSm,
00638 SMDS_ElemIteratorPtr theItr,
00639 const int theShapeID);
00646 PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
00647 const SMESH_SequenceOfElemPtr& elemGens,
00648 const std::string& postfix,
00649 SMESH_Mesh* targetMesh=0);
00650
00651
00652 typedef std::map<const SMDS_MeshNode*, std::list<const SMDS_MeshNode*> > TNodeOfNodeListMap;
00653 typedef TNodeOfNodeListMap::iterator TNodeOfNodeListMapItr;
00654 typedef std::vector<TNodeOfNodeListMapItr> TVecOfNnlmiMap;
00655 typedef std::map<const SMDS_MeshElement*, TVecOfNnlmiMap > TElemOfVecOfNnlmiMap;
00656
00665 void sweepElement(const SMDS_MeshElement* elem,
00666 const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
00667 std::list<const SMDS_MeshElement*>& newElems,
00668 const int nbSteps,
00669 SMESH_SequenceOfElemPtr& srcElements);
00670
00680 void makeWalls (TNodeOfNodeListMap & mapNewNodes,
00681 TElemOfElemListMap & newElemsMap,
00682 TElemOfVecOfNnlmiMap & elemNewNodesMap,
00683 TIDSortedElemSet& elemSet,
00684 const int nbSteps,
00685 SMESH_SequenceOfElemPtr& srcElements);
00686
00690 Extrusion_Error MakeEdgePathPoints(std::list<double>& aPrms,
00691 const TopoDS_Edge& aTrackEdge,
00692 bool FirstIsStart,
00693 list<SMESH_MeshEditor_PathPoint>& LPP);
00694 Extrusion_Error MakeExtrElements(TIDSortedElemSet& theElements,
00695 list<SMESH_MeshEditor_PathPoint>& fullList,
00696 const bool theHasAngles,
00697 list<double>& theAngles,
00698 const bool theLinearVariation,
00699 const bool theHasRefPoint,
00700 const gp_Pnt& theRefPoint,
00701 const bool theMakeGroups);
00702 void LinearAngleVariation(const int NbSteps,
00703 list<double>& theAngles);
00704
00705 bool doubleNodes( SMESHDS_Mesh* theMeshDS,
00706 const TIDSortedElemSet& theElems,
00707 const TIDSortedElemSet& theNodesNot,
00708 std::map< const SMDS_MeshNode*,
00709 const SMDS_MeshNode* >& theNodeNodeMap,
00710 const bool theIsDoubleElem );
00711
00712 private:
00713
00714 SMESH_Mesh * myMesh;
00715
00719 SMESH_SequenceOfElemPtr myLastCreatedNodes;
00720
00724 SMESH_SequenceOfElemPtr myLastCreatedElems;
00725
00726 };
00727
00728 #endif