Salome HOME
Merge remote branch 'origin/V7_dev'
[modules/smesh.git] / src / StdMeshers / StdMeshers_FaceSide.hxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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 // File      : StdMeshers_FaceSide.hxx
24 // Created   : Wed Jan 31 18:41:25 2007
25 // Author    : Edward AGAPOV (eap)
26 // Module    : SMESH
27 //
28 #ifndef StdMeshers_FaceSide_HeaderFile
29 #define StdMeshers_FaceSide_HeaderFile
30
31 #include "SMESH_StdMeshers.hxx"
32
33 #include "SMESH_ProxyMesh.hxx"
34
35 #include <Geom2d_Curve.hxx>
36 #include <GeomAdaptor_Curve.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <gp_Pnt2d.hxx>
41
42 #include <vector>
43 #include <list>
44 #include <boost/shared_ptr.hpp>
45
46 class SMDS_MeshNode;
47 class SMESH_Mesh;
48 class Adaptor2d_Curve2d;
49 class Adaptor3d_Curve;
50 class BRepAdaptor_CompCurve;
51 struct SMESH_ComputeError;
52 class StdMeshers_FaceSide;
53
54 typedef boost::shared_ptr< SMESH_ComputeError >  TError;
55 typedef boost::shared_ptr< StdMeshers_FaceSide > StdMeshers_FaceSidePtr;
56 typedef std::vector< StdMeshers_FaceSidePtr >    TSideVector;
57
58 //================================================================================
59 /*!
60  * \brief Represents a side of a quasi quadrilateral face.
61  * It can be composed of several edges. Gives access to geometry and 1D mesh of a side.
62  */
63 //================================================================================
64
65 class STDMESHERS_EXPORT StdMeshers_FaceSide
66 {
67 public:
68   /*!
69    * \brief Wrap one edge
70    */
71   StdMeshers_FaceSide(const TopoDS_Face&   theFace,
72                       const TopoDS_Edge&   theEdge,
73                       SMESH_Mesh*          theMesh,
74                       const bool           theIsForward,
75                       const bool           theIgnoreMediumNodes,
76                       SMESH_ProxyMesh::Ptr theProxyMesh = SMESH_ProxyMesh::Ptr());
77   /*!
78    * \brief Wrap several edges. Edges must be properly ordered and oriented.
79    */
80   StdMeshers_FaceSide(const TopoDS_Face&      theFace,
81                       std::list<TopoDS_Edge>& theEdges,
82                       SMESH_Mesh*             theMesh,
83                       const bool              theIsForward,
84                       const bool              theIgnoreMediumNodes,
85                       SMESH_ProxyMesh::Ptr    theProxyMesh = SMESH_ProxyMesh::Ptr());
86   /*!
87    * \brief Simulate a side from a vertex using data from other FaceSide
88    */
89   StdMeshers_FaceSide(const StdMeshers_FaceSide*  theSide,
90                       const SMDS_MeshNode*        theNode,
91                       const gp_Pnt2d*             thePnt2d1,
92                       const gp_Pnt2d*             thePnt2d2=NULL,
93                       const Handle(Geom2d_Curve)& theC2d=NULL,
94                       const double                theUFirst=0.,
95                       const double                theULast=1.);
96   /*!
97    * \brief Create a side from an UVPtStructVec
98    */
99   StdMeshers_FaceSide(UVPtStructVec&     theSideNodes,
100                       const TopoDS_Face& theFace = TopoDS_Face(),
101                       const TopoDS_Edge& theEdge = TopoDS_Edge(),
102                       SMESH_Mesh*        theMesh = 0);
103
104   // static "consrtuctors"
105   static StdMeshers_FaceSidePtr New(const TopoDS_Face&   Face,
106                                     const TopoDS_Edge&   Edge,
107                                     SMESH_Mesh*          Mesh,
108                                     const bool           IsForward,
109                                     const bool           IgnoreMediumNodes,
110                                     SMESH_ProxyMesh::Ptr ProxyMesh = SMESH_ProxyMesh::Ptr())
111   { return StdMeshers_FaceSidePtr
112       ( new StdMeshers_FaceSide( Face,Edge,Mesh,IsForward,IgnoreMediumNodes,ProxyMesh ));
113   }
114   static StdMeshers_FaceSidePtr New (const TopoDS_Face&      Face,
115                                      std::list<TopoDS_Edge>& Edges,
116                                      SMESH_Mesh*             Mesh,
117                                      const bool              IsForward,
118                                      const bool              IgnoreMediumNodes,
119                                      SMESH_ProxyMesh::Ptr    ProxyMesh = SMESH_ProxyMesh::Ptr())
120   { return StdMeshers_FaceSidePtr
121       ( new StdMeshers_FaceSide( Face,Edges,Mesh,IsForward,IgnoreMediumNodes,ProxyMesh ));
122   }
123   static StdMeshers_FaceSidePtr New (const StdMeshers_FaceSide*  Side,
124                                      const SMDS_MeshNode*        Node,
125                                      const gp_Pnt2d*             Pnt2d1,
126                                      const gp_Pnt2d*             Pnt2d2=NULL,
127                                      const Handle(Geom2d_Curve)& C2d=NULL,
128                                      const double                UFirst=0.,
129                                      const double                ULast=1.)
130   { return StdMeshers_FaceSidePtr
131       ( new StdMeshers_FaceSide( Side,Node,Pnt2d1,Pnt2d2,C2d,UFirst,ULast ));
132   }
133   static StdMeshers_FaceSidePtr New (UVPtStructVec&     theSideNodes,
134                                      const TopoDS_Face& theFace = TopoDS_Face())
135   {
136     return StdMeshers_FaceSidePtr( new StdMeshers_FaceSide( theSideNodes, theFace ));
137   }
138
139   /*!
140    * \brief Return wires of a face as StdMeshers_FaceSide's
141    */
142   static TSideVector GetFaceWires(const TopoDS_Face&   theFace,
143                                   SMESH_Mesh &         theMesh,
144                                   const bool           theIgnoreMediumNodes,
145                                   TError &             theError,
146                                   SMESH_ProxyMesh::Ptr theProxyMesh = SMESH_ProxyMesh::Ptr(),
147                                   const bool           theCheckVertexNodes=true);
148   /*!
149    * \brief Change orientation of side geometry
150    */
151   void Reverse();
152   /*!
153    * \brief Make ignore medium nodes
154    */
155   void SetIgnoreMediumNodes(bool toIgnore);
156
157   /*!
158    * \brief Return nb nodes on edges and vertices (+1 to be == GetUVPtStruct().size() ).
159    *        Call it with update == true if mesh of this side can be recomputed
160    *        since creation of this side
161    */
162   int NbPoints(const bool update = false) const;
163   /*!
164    * \brief Return nb edges
165    *        Call it with update == true if mesh of this side can be recomputed
166    *        since creation of this side
167    */
168   int NbSegments(const bool update = false) const;
169   /*!
170    * \brief Return mesh
171    */
172   SMESH_Mesh* GetMesh() const { return myProxyMesh->GetMesh(); }
173   /*!
174    * \brief Return true if there are vertices without nodes
175    */
176   bool MissVertexNode() const { return myMissingVertexNodes; }
177
178   /*!
179    * \brief Return detailed data on nodes
180     * \param isXConst - true if normalized parameter X is constant
181     * \param constValue - constant parameter value
182     *
183     * Missing nodes are allowed only on internal vertices.
184     * For a closed side, the 1st point repeats at end
185    */
186   const UVPtStructVec& GetUVPtStruct(bool isXConst =0, double constValue =0) const;
187   /*!
188    * \brief Simulates detailed data on nodes
189     * \param isXConst - true if normalized parameter X is constant
190     * \param constValue - constant parameter value
191    */
192   const UVPtStructVec& SimulateUVPtStruct(int    nbSeg,
193                                           bool   isXConst   = 0,
194                                           double constValue = 0) const;
195   /*!
196    * \brief Return nodes in the order they encounter while walking along
197    *  the while side or a specified EDGE.
198     * For a closed side, the 1st point repeats at end
199    */
200   std::vector<const SMDS_MeshNode*> GetOrderedNodes(int iE=-1) const;
201
202   /*!
203    * \brief Return nodes of the i-th EDGE.
204    *        Nodes moved to other geometry by MergeNodes() are also returned.
205    * \retval bool - is OK
206    */
207   bool GetEdgeNodes(const size_t                       i,
208                     std::vector<const SMDS_MeshNode*>& nodes,
209                     bool                               inlude1stVertex=true,
210                     bool                               inludeLastVertex=true) const;
211
212   /*!
213    * \brief Return a node from the i-th VERTEX (count starts from zero)
214    *        Nodes moved to other geometry by MergeNodes() are also returned.
215    */
216   const SMDS_MeshNode* VertexNode(std::size_t i, bool* isMoved = 0) const;
217
218   /*!
219    * \brief Return edge and parameter on edge by normalized parameter
220    */
221   inline double Parameter(double U, TopoDS_Edge & edge) const;
222   /*!
223    * \brief Return UV by normalized parameter
224    */
225   gp_Pnt2d Value2d(double U) const;
226   /*!
227    * \brief Return XYZ by normalized parameter
228    */
229   gp_Pnt   Value3d(double U) const;
230   /*!
231    * \brief Creates a Adaptor2d_Curve2d to be used in SMESH_Block
232    */
233   Adaptor2d_Curve2d* GetCurve2d() const;
234   /*!
235    * \brief Creates a fully functional Adaptor_Curve
236    */
237   BRepAdaptor_CompCurve* GetCurve3d() const;
238   /*!
239    * \brief Return nb of wrapped edges
240    */
241   int NbEdges() const { return myEdge.size(); }
242   /*!
243    * \brief Return i-th edge (count starts from zero)
244    */
245   const TopoDS_Edge& Edge(int i) const { return myEdge[i]; }
246   /*!
247    * \brief Return all edges
248    */
249   const std::vector<TopoDS_Edge>& Edges() const { return myEdge; }
250   /*!
251    * \brief Return the FACE
252    */
253   const TopoDS_Face& Face() const { return myFace; }
254   /*!
255    * \brief Return 1st vertex of the i-th edge (count starts from zero)
256    */
257   TopoDS_Vertex FirstVertex(int i=0) const;
258   /*!
259    * \brief Return last vertex of the i-th edge (count starts from zero)
260    */
261   TopoDS_Vertex LastVertex(int i=-1) const;
262   /*!
263    * \brief Return \c true if the chain of EDGEs is closed
264    */
265   bool IsClosed() const;
266   /*!
267    * \brief Return side length
268    */
269   double Length() const { return myLength; }
270   /*!
271    * \brief Return edge index corresponding to normalized parameter
272    */
273   inline int EdgeIndex( double U ) const;
274
275   //virtual gp_Pnt Value(double U) const;
276   
277   void dump(const char* msg=0) const;
278   
279   /*!
280    * \brief Return ID of i-th wrapped edge (count starts from zero)
281    */
282   inline int EdgeID(int i) const;
283   /*!
284    * \brief Return p-curve of i-th wrapped edge (count starts from zero)
285    */
286   inline Handle(Geom2d_Curve) Curve2d(int i) const;
287   /*!
288    * \brief Return first normalized parameter of the i-th edge (count starts from zero)
289    */
290   inline double FirstParameter(int i) const;
291   /*!
292    * \brief Return last normalized parameter of the i-th edge (count starts from zero)
293    */
294   inline double LastParameter(int i) const;
295   /*!
296    * \brief Return first parameter of the i-th edge (count starts from zero).
297    *        EDGE orientation is taken into account
298    */
299   inline double FirstU(int i) const;
300   /*!
301    * \brief Return last parameter of the i-th edge (count starts from zero).
302    *        EDGE orientation is taken into account
303    */
304   inline double LastU(int i) const;
305   /*!
306    * \brief Return length of i-th wrapped edge (count starts from zero)
307    */
308   inline double EdgeLength(int i) const;
309   /*!
310    * \brief Return orientation of i-th wrapped edge (count starts from zero)
311    */
312   inline bool IsReversed(int i) const;
313
314 protected:
315
316   void reverseProxySubmesh( const TopoDS_Edge& E );
317
318   // DON't FORGET to update Reverse() when adding one more vector!
319   TopoDS_Face                       myFace;
320   std::vector<uvPtStruct>           myPoints, myFalsePoints;
321   std::vector<TopoDS_Edge>          myEdge;
322   std::vector<int>                  myEdgeID;
323   std::vector<Handle(Geom2d_Curve)> myC2d;
324   std::vector<GeomAdaptor_Curve>    myC3dAdaptor;
325   std::vector<double>               myFirst, myLast;
326   std::vector<double>               myNormPar;
327   std::vector<double>               myEdgeLength;
328   std::vector<int>                  myIsUniform;
329   double                            myLength;
330   int                               myNbPonits, myNbSegments;
331   SMESH_ProxyMesh::Ptr              myProxyMesh;
332   bool                              myMissingVertexNodes, myIgnoreMediumNodes;
333   gp_Pnt2d                          myDefaultPnt2d;
334 };
335
336
337 //================================================================================
338 /*!
339  * \brief Return edge index corresponding to normalized parameter
340   * \param U - the parameter
341   * \retval int - index
342  */
343 //================================================================================
344
345 inline int StdMeshers_FaceSide::EdgeIndex( double U ) const
346 {
347   int i = myNormPar.size() - 1;
348   while ( i > 0 && U < myNormPar[ i-1 ] ) --i;
349   return i;
350 }
351
352 //================================================================================
353 /*!
354  * \brief Return edge and parameter on edge by normalized parameter
355   * \param U - the parameter
356   * \retval double - pameter on a curve
357  */
358 //================================================================================
359
360 inline double StdMeshers_FaceSide::Parameter(double U, TopoDS_Edge & edge) const
361 {
362   int i = EdgeIndex( U );
363   edge = myEdge[ i ];
364   double prevU = i ? myNormPar[ i-1 ] : 0;
365   double r = ( U - prevU )/ ( myNormPar[ i ] - prevU );
366   return myFirst[i] * ( 1 - r ) + myLast[i] * r;
367 }
368
369 //================================================================================
370 /*!
371  * \brief Return first normalized parameter of the i-th edge
372  */
373 //================================================================================
374
375 inline double StdMeshers_FaceSide::FirstParameter(int i) const
376 {
377   return i==0 ? 0. : i<(int)myNormPar.size() ? myNormPar[i-1] : 1.;
378 }
379
380 //================================================================================
381 /*!
382  * \brief Return ast normalized parameter of the i-th edge
383  */
384 //================================================================================
385
386 inline double StdMeshers_FaceSide::LastParameter(int i) const
387 {
388   return i < (int)myNormPar.size() ? myNormPar[i] : 1;
389 }
390
391 //================================================================================
392 /*!
393  * \brief Return first parameter of the i-th edge
394  */
395 //================================================================================
396
397 inline double StdMeshers_FaceSide::FirstU(int i) const
398 {
399   return myFirst[ i % myFirst.size() ];
400 }
401
402 //================================================================================
403 /*!
404  * \brief Return last parameter of the i-th edge
405  */
406 //================================================================================
407
408 inline double StdMeshers_FaceSide::LastU(int i) const
409 {
410   return myLast[ i % myLast.size() ];
411 }
412
413 //================================================================================
414   /*!
415    * \brief Return ID of i-th wrapped edge (count starts from zero)
416    */
417 //================================================================================
418
419 inline int StdMeshers_FaceSide::EdgeID(int i) const
420 {
421   return myEdgeID[ i % myEdgeID.size() ];
422 }
423
424 //================================================================================
425 /*!
426    * \brief Return p-curve of i-th wrapped edge (count starts from zero)
427    */
428 //================================================================================
429
430 inline Handle(Geom2d_Curve) StdMeshers_FaceSide::Curve2d(int i) const
431 {
432   return myC2d[ i % myC2d.size() ];
433 }
434
435 //================================================================================
436 /*!
437  * \brief Return length of i-th wrapped edge (count starts from zero)
438  */
439  //================================================================================
440
441 inline double StdMeshers_FaceSide::EdgeLength(int i) const
442 {
443   return myEdgeLength[ i % myEdgeLength.size() ];
444 }
445
446 //================================================================================
447 /*!
448  * \brief Return orientation of i-th wrapped edge (count starts from zero)
449  */
450  //================================================================================
451
452 inline bool StdMeshers_FaceSide::IsReversed(int i) const
453 {
454   return myFirst[i] > myLast[i];
455 }
456
457 #endif