Salome HOME
NPAL17873: SMESH add a triangle instead of make quadrangles only.
[modules/smesh.git] / src / StdMeshers / StdMeshers_ProjectionUtils.hxx
1 //  SMESH SMESH : idl implementation based on 'SMESH' unit's calsses
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 // File      : StdMeshers_ProjectionUtils.hxx
25 // Created   : Thu Oct 26 15:37:24 2006
26 // Author    : Edward AGAPOV (eap)
27
28
29 #ifndef StdMeshers_ProjectionUtils_HeaderFile
30 #define StdMeshers_ProjectionUtils_HeaderFile
31
32 #include "SMESH_StdMeshers.hxx"
33
34 #include <TopTools_DataMapOfShapeShape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Vertex.hxx>
37 #include <TopoDS_Face.hxx>
38
39 #include <list>
40 #include <map>
41
42 class TopoDS_Shape;
43 class SMDS_MeshNode;
44 class SMESH_Mesh;
45 class SMESH_Hypothesis;
46 class SMESH_subMesh;
47 class TopTools_IndexedDataMapOfShapeListOfShape;
48
49 /*!
50  * \brief Class encapsulating methods common to Projection algorithms
51  */
52 class StdMeshers_ProjectionUtils
53 {
54  public:
55
56   typedef TopTools_DataMapOfShapeShape                         TShapeShapeMap;
57   typedef TopTools_IndexedDataMapOfShapeListOfShape            TAncestorMap;
58   typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*> TNodeNodeMap;
59
60   /*!
61    * \brief Looks for association of all subshapes of two shapes
62     * \param theShape1 - shape 1
63     * \param theMesh1 - mesh built on shape 1
64     * \param theShape2 - shape 2
65     * \param theMesh2 - mesh built on shape 2
66     * \param theAssociation - association map to be filled that may
67     *                         contain association of one or two pairs of vertices
68     * \retval bool - true if association found
69    */
70   static bool FindSubShapeAssociation(const TopoDS_Shape& theShape1,
71                                       SMESH_Mesh*         theMesh1,
72                                       const TopoDS_Shape& theShape2,
73                                       SMESH_Mesh*         theMesh2,
74                                       TShapeShapeMap &    theAssociationMap);
75
76   /*!
77    * \brief Find association of edges of faces
78     * \param face1 - face 1
79     * \param VV1 - vertices of face 1
80     * \param face2 - face 2
81     * \param VV2 - vertices of face 2 associated with oned of face 1
82     * \param edges1 - out list of edges of face 1
83     * \param edges2 - out list of edges of face 2
84     * \retval int - nb of edges in an outer wire in a success case, else zero
85    */
86   static int FindFaceAssociation(const TopoDS_Face&    face1,
87                                  TopoDS_Vertex         VV1[2],
88                                  const TopoDS_Face&    face2,
89                                  TopoDS_Vertex         VV2[2],
90                                  list< TopoDS_Edge > & edges1,
91                                  list< TopoDS_Edge > & edges2);
92
93   /*!
94    * \brief Insert vertex association defined by a hypothesis into a map
95     * \param theHyp - hypothesis
96     * \param theAssociationMap - association map
97     * \param theTargetShape - the shape theHyp assigned to
98    */
99   static void InitVertexAssociation( const SMESH_Hypothesis* theHyp,
100                                      TShapeShapeMap &        theAssociationMap,
101                                      const TopoDS_Shape&     theTargetShape);
102
103   /*!
104    * \brief Inserts association theShape1 <-> theShape2 to TShapeShapeMap
105     * \param theShape1 - shape 1
106     * \param theShape2 - shape 2
107     * \param theAssociationMap - association map 
108     * \param theBidirectional - if false, inserts theShape1 -> theShape2 association
109     * \retval bool - true if there was no association for these shapes before
110    */
111   static bool InsertAssociation( const TopoDS_Shape& theShape1,
112                                  const TopoDS_Shape& theShape2,
113                                  TShapeShapeMap &    theAssociationMap,
114                                  const bool          theBidirectional=true);
115
116   static bool IsSubShape( const TopoDS_Shape& shape, SMESH_Mesh* aMesh );
117
118   static bool IsSubShape( const TopoDS_Shape& shape, const TopoDS_Shape& mainShape );
119
120   /*!
121    * \brief Finds an edge by its vertices in a main shape of the mesh
122    */
123   static TopoDS_Edge GetEdgeByVertices( SMESH_Mesh*          aMesh,
124                                         const TopoDS_Vertex& V1,
125                                         const TopoDS_Vertex& V2);
126                                         
127   /*!
128    * \brief Return another face sharing an edge
129    * \param edgeToFaces - data map of descendants to ancestors
130    */
131   static TopoDS_Face GetNextFace( const TAncestorMap& edgeToFaces,
132                                   const TopoDS_Edge&  edge,
133                                   const TopoDS_Face&  face);
134   /*!
135    * \brief Return other vertex of an edge
136    */
137   static TopoDS_Vertex GetNextVertex(const TopoDS_Edge&   edge,
138                                      const TopoDS_Vertex& vertex);
139
140   /*!
141    * \brief Return an oriented propagation edge
142     * \param aMesh - mesh
143     * \param fromEdge - start edge for propagation
144     * \retval pair<int,TopoDS_Edge> - propagation step and found edge
145    */
146   static std::pair<int,TopoDS_Edge> GetPropagationEdge( SMESH_Mesh*        aMesh,
147                                                         const TopoDS_Edge& anEdge,
148                                                         const TopoDS_Edge& fromEdge);
149
150   /*!
151    * \brief Find corresponding nodes on two faces
152     * \param face1 - the first face
153     * \param mesh1 - mesh containing elements on the first face
154     * \param face2 - the second face
155     * \param mesh2 - mesh containing elements on the second face
156     * \param assocMap - map associating subshapes of the faces
157     * \param nodeIn2OutMap - map containing found matching nodes
158     * \retval bool - is a success
159    */
160   static bool FindMatchingNodesOnFaces( const TopoDS_Face&     face1,
161                                         SMESH_Mesh*            mesh1,
162                                         const TopoDS_Face&     face2,
163                                         SMESH_Mesh*            mesh2,
164                                         const TShapeShapeMap & assocMap,
165                                         TNodeNodeMap &         nodeIn2OutMap);
166   /*!
167    * \brief Check if the first and last vertices of an edge are the same
168     * \param anEdge - the edge to check
169     * \retval bool - true if same
170    */
171   static bool IsClosedEdge( const TopoDS_Edge& anEdge );
172
173   /*!
174    * \brief Return any subshape of a face belonging to the outer wire
175     * \param face - the face
176     * \param type - type of subshape to return
177     * \retval TopoDS_Shape - the found subshape
178    */
179   static TopoDS_Shape OuterShape( const TopoDS_Face& face,
180                                   TopAbs_ShapeEnum   type);
181
182   /*!
183    * \brief Check that submeshis is computed and try to compute it if is not
184     * \param sm - submesh to compute
185     * \param iterationNb - int used to stop infinite recursive call
186     * \retval bool - true if computed
187    */
188   static bool MakeComputed(SMESH_subMesh * sm, const int iterationNb = 0);
189
190   /*!
191    * \brief Count nb of subshapes
192     * \param shape - the shape
193     * \param type - the type of subshapes to count
194     * \param ignoreSame - if true, use map not to count same shapes, esle use explorer
195     * \retval int - the calculated number
196    */
197   static int Count(const TopoDS_Shape&    shape,
198                    const TopAbs_ShapeEnum type,
199                    const bool             ignoreSame);
200
201   /*!
202    * \brief Set event listeners to submesh with projection algo
203     * \param subMesh - submesh with projection algo
204     * \param srcShape - source shape
205     * \param srcMesh - source mesh
206    */
207   static void SetEventListener(SMESH_subMesh* subMesh,
208                                TopoDS_Shape   srcShape,
209                                SMESH_Mesh*    srcMesh);
210
211 };
212
213 #endif