Salome HOME
aac128dc65b048d0d1e1c274de993cf7652330fa
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_EnforcedMesh1D.hxx
1 // Copyright (C) 2007-2021  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   // Return EDGEs resulted from division of FACE boundary by enforced segments
61   bool GetSplitsOfEdge( const TopoDS_Edge&           edge,
62                         std::vector< TopoDS_Edge > & splits,
63                         TopTools_IndexedMapOfShape & edgeTags );
64
65   // Return true if there are enforced segments on a FACE. Start iteration on segments
66   bool HasSegmentsOnFace( const TopoDS_Face& face );
67
68   // Data of an enforced segment to provide MG-CADSurf with
69   struct Segmemnt
70   {
71     int                  _tag;
72     Handle(Geom2d_Curve) _pcurve;
73
74     // data of two ends
75     double               _u   [2];
76     gp_XY                _uv  [2];
77     gp_XYZ               _xyz [2];
78     int                  _vTag[2];
79   };
80
81   // Return next segment on the FACE. Iteration starts upon calling HasSegmentsOnFace() 
82   bool NextSegment( Segmemnt & seg, TopTools_IndexedMapOfShape & vertexTags );
83
84   // Return enforced node by tag
85   const SMDS_MeshNode* GetNodeByTag( int tag, const TopTools_IndexedMapOfShape & vertexTags );
86
87   // Return true if a tad corresponds to an enforced segment
88   bool IsSegmentTag( int tag ) const;
89
90   // Return tag of EDGE by tags of its splits
91   int GetTagOfSplitEdge( int splitTag ) const;
92
93   typedef std::map< const SMDS_MeshElement* , std::vector< const SMDS_MeshNode* > > TNodesOnSeg;
94
95 private:
96
97   void copyEnforcedMesh( const BLSURFPlugin_Hypothesis::EnforcedMesh& theEnfMesh,
98                          const BLSURFPlugin_Hypothesis*               theHyp,
99                          const TopoDS_Shape&                          theShape);
100
101   const SMDS_MeshNode* copyEnforcedNode( const SMDS_MeshNode* enfNode );
102
103   void setupPredicates( const TopoDS_Shape& shape );
104
105   void splitSegmentOnSeveralShapes( const SMDS_MeshElement* segment );
106
107   void splitSelfIntersectingSegments( const TopoDS_Shape & face );
108
109   void findIntersectionWithSeamEdge( const TopoDS_Face & face, TNodesOnSeg & segInternalNodes );
110
111   bool intersectSegments( const SMDS_MeshElement* seg1, const SMDS_MeshElement* seg2,
112                           const TopoDS_Face& face, gp_Pnt& intPnt, gp_Pnt2d& inUV ) const;
113
114   gp_Pnt getEdgeIntersection( const TopoDS_Shape& faceOrEdge,
115                               const gp_XYZ& xyz0, const gp_XYZ& xyz1,
116                               TopoDS_Edge & edge, double & paramOnEdge );
117
118   void splitEdgeByNodes( TopoDS_Edge edge, const std::vector< const SMDS_MeshNode* >& nodes);
119
120   SMDS_MeshGroup* getGroup( const std::string& groupName );
121
122   const SMDS_MeshNode* findNodeOnEdge( const gp_Pnt& p, const TopoDS_Edge& edge );
123   void addNodeOnEdge( const SMDS_MeshNode*node , const TopoDS_Edge& edge, const double u = 0. );
124
125
126   SMESH_Mesh*                              _mesh;
127   TopoDS_Shape                             _shape;
128   SMESH_MesherHelper                       _helper;
129   bool                                     _isQuadratic;
130   std::map< std::string, SMDS_MeshGroup* > _name2Group;
131   double                                   _tol;
132   TopTools_IndexedMapOfShape               _faces;
133
134   // segments whose nodes are on different FACEs;
135   // such segments will be split into segments lying each on own FACE
136   std::vector< const SMDS_MeshElement* >   _segmentsOnSeveralShapes;
137
138   // nodes projected on EDGEs; EDGEs will be divided by them
139   typedef NCollection_DataMap< TopoDS_Edge,
140                                std::vector< const SMDS_MeshNode* >,
141                                TopTools_ShapeMapHasher>              TEdge2Nodes;
142   typedef NCollection_DataMap< TopoDS_Edge,
143                                std::vector< TopoDS_Edge >,
144                                TopTools_ShapeMapHasher>              TEdge2Edges;
145   TEdge2Nodes                               _nodesOnEdge;
146   TEdge2Edges                               _edgeSplitsOfEdge; // result of EDGE division by nodes
147   std::map< int, int >                      _splitTags2EdgeTag;
148   std::map< const SMDS_MeshNode* , TopoDS_Vertex > _nOnE2Vertex; // VERTEXes on _nodesOnEdge
149
150   typedef SMESH::Controls::ElementsOnShape    TPredicate;
151   typedef SMESH::Controls::ElementsOnShapePtr TPredicatePtr;
152   TPredicatePtr                             _onVertexPredicate;
153   TPredicatePtr                             _onEdgePredicate;
154
155   // for iteration of segments of FACE
156
157   SMDS_ElemIteratorPtr                      _segIterator;
158   TopoDS_Face                               _currentFace;
159   int                                       _segTag0;
160   int                                       _segTag;
161
162   typedef NCollection_IndexedMap< const SMDS_MeshNode* > TNodeIndMap;
163   TNodeIndMap                               _nodeTags;
164   int                                       _nodeTag0;
165
166   // nodes not projected to geometry; they are reused during next projection to geometry
167   std::vector< const SMDS_MeshNode* >       _freeNodes;
168
169 };
170
171
172 #endif