1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH : idl implementation based on 'SMESH' unit's calsses
24 // File : StdMeshers_ProjectionUtils.hxx
25 // Created : Thu Oct 26 15:37:24 2006
26 // Author : Edward AGAPOV (eap)
28 #ifndef StdMeshers_ProjectionUtils_HeaderFile
29 #define StdMeshers_ProjectionUtils_HeaderFile
31 #include "SMESH_StdMeshers.hxx"
33 #include "SMDS_MeshElement.hxx"
35 #include <TopTools_DataMapOfShapeShape.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <gp_Trsf.hxx>
40 #include <gp_Trsf2d.hxx>
47 class SMESH_Hypothesis;
50 class TopTools_IndexedDataMapOfShapeListOfShape;
51 class TopTools_IndexedMapOfShape;
55 * \brief Struct used instead of a sole TopTools_DataMapOfShapeShape to avoid
56 * problems with bidirectional bindings
58 struct StdMeshers_ShapeShapeBiDirectionMap
60 TopTools_DataMapOfShapeShape _map1to2, _map2to1;
62 // convention: s1 - target, s2 - source
63 bool Bind( const TopoDS_Shape& s1, const TopoDS_Shape& s2 )
64 { _map1to2.Bind( s1, s2 ); return _map2to1.Bind( s2, s1 ); }
65 bool IsBound( const TopoDS_Shape& s, const bool isShape2=false ) const
66 { return (isShape2 ? _map2to1 : _map1to2).IsBound( s ); }
67 bool IsEmpty() const { return _map1to2.IsEmpty(); }
68 int Extent() const { return _map1to2.Extent(); }
69 void Clear() { _map1to2.Clear(); _map2to1.Clear(); }
70 const TopoDS_Shape& operator()( const TopoDS_Shape& s, const bool isShape2=false ) const
71 { // if we get a Standard_NoSuchObject here, it means that the calling code
72 // passes incorrect isShape2
73 return (isShape2 ? _map2to1 : _map1to2)( s );
78 * \brief Methods common to Projection algorithms
80 namespace StdMeshers_ProjectionUtils
82 typedef StdMeshers_ShapeShapeBiDirectionMap TShapeShapeMap;
83 typedef TopTools_IndexedDataMapOfShapeListOfShape TAncestorMap;
84 typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*,
85 TIDCompare> TNodeNodeMap;
89 * \brief Finds transformation beween two sets of 2D points using
90 * a least square approximation
97 TrsfFinder2D(): _srcOrig(0,0) {}
99 void Set( const gp_Trsf2d& t ) { _trsf = t; } // it's an alternative to Solve()
101 bool Solve( const std::vector< gp_XY >& srcPnts,
102 const std::vector< gp_XY >& tgtPnts );
104 gp_XY Transform( const gp_Pnt2d& srcUV ) const;
106 bool IsIdentity() const { return ( _trsf.Form() == gp_Identity ); }
109 * \brief Finds transformation beween two sets of 3D points using
110 * a least square approximation
117 TrsfFinder3D(): _srcOrig(0,0,0) {}
119 void Set( const gp_Trsf& t ) { _trsf = t; } // it's an alternative to Solve()
121 bool Solve( const std::vector< gp_XYZ > & srcPnts,
122 const std::vector< gp_XYZ > & tgtPnts );
124 gp_XYZ Transform( const gp_Pnt& srcP ) const;
126 gp_XYZ TransformVec( const gp_Vec& v ) const;
128 bool IsIdentity() const { return ( _trsf.Form() == gp_Identity ); }
134 * \brief Looks for association of all sub-shapes of two shapes
135 * \param theShape1 - shape 1
136 * \param theMesh1 - mesh built on shape 1
137 * \param theShape2 - shape 2
138 * \param theMesh2 - mesh built on shape 2
139 * \param theAssociation - association map to be filled that may
140 * contain association of one or two pairs of vertices
141 * \retval bool - true if association found
143 bool FindSubShapeAssociation(const TopoDS_Shape& theShape1,
144 SMESH_Mesh* theMesh1,
145 const TopoDS_Shape& theShape2,
146 SMESH_Mesh* theMesh2,
147 TShapeShapeMap & theAssociationMap);
150 * \brief Find association of edges of faces
151 * \param face1 - face 1
152 * \param VV1 - vertices of face 1
153 * \param face2 - face 2
154 * \param VV2 - vertices of face 2 associated with oned of face 1
155 * \param edges1 - out list of edges of face 1
156 * \param edges2 - out list of edges of face 2
157 * \retval int - nb of edges in an outer wire in a success case, else zero
159 int FindFaceAssociation(const TopoDS_Face& face1,
160 TopoDS_Vertex VV1[2],
161 const TopoDS_Face& face2,
162 TopoDS_Vertex VV2[2],
163 std::list< TopoDS_Edge > & edges1,
164 std::list< TopoDS_Edge > & edges2);
167 * \brief Insert vertex association defined by a hypothesis into a map
168 * \param theHyp - hypothesis
169 * \param theAssociationMap - association map
170 * \param theTargetShape - the shape theHyp assigned to
172 void InitVertexAssociation( const SMESH_Hypothesis* theHyp,
173 TShapeShapeMap & theAssociationMap);
176 * \brief Inserts association theShape1 <-> theShape2 to TShapeShapeMap
177 * \param theShape1 - target shape
178 * \param theShape2 - source shape
179 * \param theAssociationMap - association map
180 * \param theBidirectional - if false, inserts theShape1 -> theShape2 association
181 * \retval bool - true if there was no association for these shapes before
183 bool InsertAssociation( const TopoDS_Shape& theShape1, // target
184 const TopoDS_Shape& theShape2, // source
185 TShapeShapeMap & theAssociationMap);
188 * \brief Finds an edge by its vertices in a main shape of the mesh
190 TopoDS_Edge GetEdgeByVertices( SMESH_Mesh* aMesh,
191 const TopoDS_Vertex& V1,
192 const TopoDS_Vertex& V2);
195 * \brief Return another face sharing an edge
196 * \param edgeToFaces - data map of descendants to ancestors
198 TopoDS_Face GetNextFace( const TAncestorMap& edgeToFaces,
199 const TopoDS_Edge& edge,
200 const TopoDS_Face& face);
202 * \brief Return other vertex of an edge
204 TopoDS_Vertex GetNextVertex(const TopoDS_Edge& edge,
205 const TopoDS_Vertex& vertex);
208 * \brief Return an oriented propagation edge
209 * \param aMesh - mesh
210 * \param fromEdge - start edge for propagation
211 * \param chain - return, if provided, a propagation chain passed till
212 * anEdge; if anEdge.IsNull() then a full propagation chain is returned
213 * \retval pair<int,TopoDS_Edge> - propagation step and found edge
215 std::pair<int,TopoDS_Edge> GetPropagationEdge( SMESH_Mesh* aMesh,
216 const TopoDS_Edge& anEdge,
217 const TopoDS_Edge& fromEdge,
218 TopTools_IndexedMapOfShape* chain=0);
221 * \brief Find corresponding nodes on two faces
222 * \param face1 - the first face
223 * \param mesh1 - mesh containing elements on the first face
224 * \param face2 - the second face
225 * \param mesh2 - mesh containing elements on the second face
226 * \param assocMap - map associating sub-shapes of the faces
227 * \param nodeIn2OutMap - map containing found matching nodes
228 * \retval bool - is a success
230 bool FindMatchingNodesOnFaces( const TopoDS_Face& face1,
232 const TopoDS_Face& face2,
234 const TShapeShapeMap & assocMap,
235 TNodeNodeMap & nodeIn2OutMap);
237 * \brief Return any sub-shape of a face belonging to the outer wire
238 * \param face - the face
239 * \param type - type of sub-shape to return
240 * \retval TopoDS_Shape - the found sub-shape
242 TopoDS_Shape OuterShape( const TopoDS_Face& face,
243 TopAbs_ShapeEnum type);
246 * \brief Check that submeshis is computed and try to compute it if is not
247 * \param sm - submesh to compute
248 * \param iterationNb - int used to stop infinite recursive call
249 * \retval bool - true if computed
251 bool MakeComputed(SMESH_subMesh * sm, const int iterationNb = 0);
254 * \brief Returns an error message to show in case if MakeComputed( sm ) fails.
256 std::string SourceNotComputedError( SMESH_subMesh * sm = 0,
257 SMESH_Algo* projAlgo=0);
260 * \brief Set event listeners to submesh with projection algo
261 * \param subMesh - submesh with projection algo
262 * \param srcShape - source shape
263 * \param srcMesh - source mesh
265 void SetEventListener(SMESH_subMesh* subMesh,
266 TopoDS_Shape srcShape,
267 SMESH_Mesh* srcMesh);
270 * \brief Return a boundary EDGE (or all boundary EDGEs) of edgeContainer
272 TopoDS_Edge GetBoundaryEdge(const TopoDS_Shape& edgeContainer,
273 const SMESH_Mesh& mesh,
274 std::list< TopoDS_Edge >* allBndEdges = 0 );