Salome HOME
64ccf0e15503a53ae00ab568b752c884a747d845
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_EnforcedMesh1D.hxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File      : BLSURFPlugin_EnforcedMesh1D.hxx
20 // Author    : Edward AGAPOV (OCC)
21
22 #ifndef __BLSURFPlugin_EnforcedMesh1D_HXX__
23 #define __BLSURFPlugin_EnforcedMesh1D_HXX__
24
25 #include "BLSURFPlugin_Hypothesis.hxx"
26
27 #include <SMESH_ControlsDef.hxx>
28 #include <SMESH_MesherHelper.hxx>
29
30 #include <Geom2d_Curve.hxx>
31 #include <NCollection_DataMap.hxx>
32 #include <NCollection_IndexedMap.hxx>
33 #include <TopTools_IndexedMapOfShape.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Vertex.hxx>
37 #include <gp_Pnt.hxx>
38 #include <gp_Pnt2d.hxx>
39
40 #include <vector>
41 #include <map>
42
43 class SMDS_MeshElement;
44 class SMDS_MeshGroup;
45 class SMDS_MeshNode;
46 class SMESH_Mesh;
47
48 /*!
49  * \brief Implement 1D mesh into the mesh made by MG-CADSurf
50  */
51 class BLSURFPlugin_EnforcedMesh1D
52 {
53 public:
54
55   BLSURFPlugin_EnforcedMesh1D( SMESH_MesherHelper&            helper,
56                                const BLSURFPlugin_Hypothesis* hyp );
57
58   ~BLSURFPlugin_EnforcedMesh1D();
59
60   // Add a vertex on EDGE
61   void AddVertexOnEdge( const double* xyz );
62
63   // Return EDGEs resulted from division of FACE boundary by enforced segments
64   bool GetSplitsOfEdge( const TopoDS_Edge&           edge,
65                         std::vector< TopoDS_Edge > & splits,
66                         TopTools_IndexedMapOfShape & edgeTags );
67
68   // Return true if there are enforced segments on a FACE. Start iteration on segments
69   bool HasSegmentsOnFace( const TopoDS_Face& face );
70
71   // Data of an enforced segment to provide MG-CADSurf with
72   struct Segmemnt
73   {
74     int                  _tag;
75     Handle(Geom2d_Curve) _pcurve;
76
77     // data of two ends
78     double               _u   [2];
79     gp_XY                _uv  [2];
80     gp_XYZ               _xyz [2];
81     int                  _vTag[2];
82   };
83
84   // Return next segment on the FACE. Iteration starts upon calling HasSegmentsOnFace() 
85   bool NextSegment( Segmemnt & seg, TopTools_IndexedMapOfShape & vertexTags );
86
87   // Return enforced node by tag
88   const SMDS_MeshNode* GetNodeByTag( int tag, const TopTools_IndexedMapOfShape & vertexTags );
89
90   // Return true if a tad corresponds to an enforced segment
91   bool IsSegmentTag( int tag ) const;
92
93   // Return tag of EDGE by tags of its splits
94   int GetTagOfSplitEdge( int splitTag ) const;
95
96   typedef std::map< const SMDS_MeshElement* , std::vector< const SMDS_MeshNode* > > TNodesOnSeg;
97
98 private:
99
100   void copyEnforcedMesh( const BLSURFPlugin_Hypothesis::EnforcedMesh& theEnfMesh,
101                          const BLSURFPlugin_Hypothesis*               theHyp,
102                          const TopoDS_Shape&                          theShape);
103
104   const SMDS_MeshNode* copyEnforcedNode( const SMDS_MeshNode* enfNode );
105
106   void setupPredicates( const TopoDS_Shape& shape );
107
108   void splitSegmentOnSeveralShapes( const SMDS_MeshElement* segment );
109
110   void splitSelfIntersectingSegments( const TopoDS_Shape & face );
111
112   void findIntersectionWithSeamEdge( const TopoDS_Face & face, TNodesOnSeg & segInternalNodes );
113
114   bool intersectSegments( const SMDS_MeshElement* seg1, const SMDS_MeshElement* seg2,
115                           const TopoDS_Face& face, gp_Pnt& intPnt, gp_Pnt2d& inUV ) const;
116
117   gp_Pnt getEdgeIntersection( const TopoDS_Shape& faceOrEdge,
118                               const gp_XYZ& xyz0, const gp_XYZ& xyz1,
119                               TopoDS_Edge & edge, double & paramOnEdge );
120
121   void splitEdgeByNodes( TopoDS_Edge edge, const std::vector< const SMDS_MeshNode* >& nodes);
122
123   SMDS_MeshGroup* getGroup( const std::string& groupName );
124
125   const SMDS_MeshNode* findNodeOnEdge( const gp_Pnt& p, const TopoDS_Edge& edge );
126   void addNodeOnEdge( const SMDS_MeshNode*node , const TopoDS_Edge& edge, const double u = 0. );
127
128
129   SMESH_Mesh*                              _mesh;
130   TopoDS_Shape                             _shape;
131   SMESH_MesherHelper                       _helper;
132   bool                                     _isQuadratic;
133   std::map< std::string, SMDS_MeshGroup* > _name2Group;
134   double                                   _tol;
135   TopTools_IndexedMapOfShape               _faces;
136
137   // segments whose nodes are on different FACEs;
138   // such segments will be split into segments lying each on own FACE
139   std::vector< const SMDS_MeshElement* >   _segmentsOnSeveralShapes;
140
141   // nodes projected on EDGEs; EDGEs will be divided by them
142   typedef NCollection_DataMap< TopoDS_Edge,
143                                std::vector< const SMDS_MeshNode* >,
144                                TopTools_ShapeMapHasher>              TEdge2Nodes;
145   typedef NCollection_DataMap< TopoDS_Edge,
146                                std::vector< TopoDS_Edge >,
147                                TopTools_ShapeMapHasher>              TEdge2Edges;
148   TEdge2Nodes                               _nodesOnEdge;
149   TEdge2Edges                               _edgeSplitsOfEdge; // result of EDGE division by nodes
150   std::map< int, int >                      _splitTags2EdgeTag;
151   std::map< const SMDS_MeshNode* , TopoDS_Vertex > _nOnE2Vertex; // VERTEXes on _nodesOnEdge
152
153   typedef SMESH::Controls::ElementsOnShape    TPredicate;
154   typedef SMESH::Controls::ElementsOnShapePtr TPredicatePtr;
155   TPredicatePtr                             _onVertexPredicate;
156   TPredicatePtr                             _onEdgePredicate;
157
158   // for iteration of segments of FACE
159
160   SMDS_ElemIteratorPtr                      _segIterator;
161   TopoDS_Face                               _currentFace;
162   int                                       _segTag0;
163   int                                       _segTag;
164
165   typedef NCollection_IndexedMap< const SMDS_MeshNode* > TNodeIndMap;
166   TNodeIndMap                               _nodeTags;
167   int                                       _nodeTag0;
168
169   // nodes not projected to geometry; they are reused during next projection to geometry
170   std::vector< const SMDS_MeshNode* >       _freeNodes;
171
172 };
173
174
175 #endif