Salome HOME
Copyrights update 2015.
[modules/smesh.git] / src / StdMeshers / StdMeshers_FaceSide.hxx
1 // Copyright (C) 2007-2015  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
102   // static "consrtuctors"
103   static StdMeshers_FaceSidePtr New(const TopoDS_Face&   Face,
104                                     const TopoDS_Edge&   Edge,
105                                     SMESH_Mesh*          Mesh,
106                                     const bool           IsForward,
107                                     const bool           IgnoreMediumNodes,
108                                     SMESH_ProxyMesh::Ptr ProxyMesh = SMESH_ProxyMesh::Ptr())
109   { return StdMeshers_FaceSidePtr
110       ( new StdMeshers_FaceSide( Face,Edge,Mesh,IsForward,IgnoreMediumNodes,ProxyMesh ));
111   }
112   static StdMeshers_FaceSidePtr New (const TopoDS_Face&      Face,
113                                      std::list<TopoDS_Edge>& Edges,
114                                      SMESH_Mesh*             Mesh,
115                                      const bool              IsForward,
116                                      const bool              IgnoreMediumNodes,
117                                      SMESH_ProxyMesh::Ptr    ProxyMesh = SMESH_ProxyMesh::Ptr())
118   { return StdMeshers_FaceSidePtr
119       ( new StdMeshers_FaceSide( Face,Edges,Mesh,IsForward,IgnoreMediumNodes,ProxyMesh ));
120   }
121   static StdMeshers_FaceSidePtr New (const StdMeshers_FaceSide*  Side,
122                                      const SMDS_MeshNode*        Node,
123                                      const gp_Pnt2d*             Pnt2d1,
124                                      const gp_Pnt2d*             Pnt2d2=NULL,
125                                      const Handle(Geom2d_Curve)& C2d=NULL,
126                                      const double                UFirst=0.,
127                                      const double                ULast=1.)
128   { return StdMeshers_FaceSidePtr
129       ( new StdMeshers_FaceSide( Side,Node,Pnt2d1,Pnt2d2,C2d,UFirst,ULast ));
130   }
131   static StdMeshers_FaceSidePtr New (UVPtStructVec&     theSideNodes,
132                                      const TopoDS_Face& theFace = TopoDS_Face())
133   {
134     return StdMeshers_FaceSidePtr( new StdMeshers_FaceSide( theSideNodes, theFace ));
135   }
136
137   /*!
138    * \brief Return wires of a face as StdMeshers_FaceSide's
139    */
140   static TSideVector GetFaceWires(const TopoDS_Face&   theFace,
141                                   SMESH_Mesh &         theMesh,
142                                   const bool           theIgnoreMediumNodes,
143                                   TError &             theError,
144                                   SMESH_ProxyMesh::Ptr theProxyMesh = SMESH_ProxyMesh::Ptr(),
145                                   const bool           theCheckVertexNodes=true);
146   /*!
147    * \brief Change orientation of side geometry
148    */
149   void Reverse();
150   /*!
151    * \brief Make ignore medium nodes
152    */
153   void SetIgnoreMediumNodes(bool toIgnore);
154
155   /*!
156    * \brief Return nb nodes on edges and vertices (+1 to be == GetUVPtStruct().size() ).
157    *        Call it with update == true if mesh of this side can be recomputed
158    *        since creation of this side
159    */
160   int NbPoints(const bool update = false) const;
161   /*!
162    * \brief Return nb edges
163    *        Call it with update == true if mesh of this side can be recomputed
164    *        since creation of this side
165    */
166   int NbSegments(const bool update = false) const;
167   /*!
168    * \brief Return mesh
169    */
170   SMESH_Mesh* GetMesh() const { return myProxyMesh->GetMesh(); }
171   /*!
172    * \brief Return true if there are vertices without nodes
173    */
174   bool MissVertexNode() const { return myMissingVertexNodes; }
175
176   /*!
177    * \brief Return detailed data on nodes
178     * \param isXConst - true if normalized parameter X is constant
179     * \param constValue - constant parameter value
180     *
181     * Missing nodes are allowed only on internal vertices.
182     * For a closed side, the 1st point repeats at end
183    */
184   const UVPtStructVec& GetUVPtStruct(bool isXConst =0, double constValue =0) const;
185   /*!
186    * \brief Simulates detailed data on nodes
187     * \param isXConst - true if normalized parameter X is constant
188     * \param constValue - constant parameter value
189    */
190   const UVPtStructVec& SimulateUVPtStruct(int    nbSeg,
191                                           bool   isXConst   = 0,
192                                           double constValue = 0) const;
193   /*!
194    * \brief Return nodes in the order they encounter while walking along the side.
195     * For a closed side, the 1st point repeats at end
196    */
197   std::vector<const SMDS_MeshNode*> GetOrderedNodes() const;
198
199   /*!
200    * \brief Return edge and parameter on edge by normalized parameter
201    */
202   inline double Parameter(double U, TopoDS_Edge & edge) const;
203   /*!
204    * \brief Return UV by normalized parameter
205    */
206   gp_Pnt2d Value2d(double U) const;
207   /*!
208    * \brief Return XYZ by normalized parameter
209    */
210   gp_Pnt   Value3d(double U) const;
211   /*!
212    * \brief Creates a Adaptor2d_Curve2d to be used in SMESH_Block
213    */
214   Adaptor2d_Curve2d* GetCurve2d() const;
215   /*!
216    * \brief Creates a fully functional Adaptor_Curve
217    */
218   BRepAdaptor_CompCurve* GetCurve3d() const;
219   /*!
220    * \brief Return nb of wrapped edges
221    */
222   int NbEdges() const { return myEdge.size(); }
223   /*!
224    * \brief Return i-th edge (count starts from zero)
225    */
226   const TopoDS_Edge& Edge(int i) const { return myEdge[i]; }
227   /*!
228    * \brief Return all edges
229    */
230   const std::vector<TopoDS_Edge>& Edges() const { return myEdge; }
231   /*!
232    * \brief Return 1st vertex of the i-the edge (count starts from zero)
233    */
234   TopoDS_Vertex FirstVertex(int i=0) const;
235   /*!
236    * \brief Return last vertex of the i-the edge (count starts from zero)
237    */
238   TopoDS_Vertex LastVertex(int i=-1) const;
239   /*!
240    * \brief Return side length
241    */
242   double Length() const { return myLength; }
243   /*!
244    * \brief Return edge index corresponding to normalized parameter
245    */
246   inline int EdgeIndex( double U ) const;
247
248   //virtual gp_Pnt Value(double U) const;
249   
250   void dump(const char* msg=0) const;
251   
252   /*!
253    * \brief Return ID of i-th wrapped edge (count starts from zero)
254    */
255   inline int EdgeID(int i) const;
256   /*!
257    * \brief Return p-curve of i-th wrapped edge (count starts from zero)
258    */
259   inline Handle(Geom2d_Curve) Curve2d(int i) const;
260   /*!
261    * \brief Return first normalized parameter of the i-the edge (count starts from zero)
262    */
263   inline double FirstParameter(int i) const;
264   /*!
265    * \brief Return last normalized parameter of the i-the edge (count starts from zero)
266    */
267   inline double LastParameter(int i) const;
268   /*!
269    * \brief Return first parameter of the i-the edge (count starts from zero).
270    *        EDGE orientation is taken into account
271    */
272   inline double FirstU(int i) const;
273   /*!
274    * \brief Return last parameter of the i-the edge (count starts from zero).
275    *        EDGE orientation is taken into account
276    */
277   inline double LastU(int i) const;
278   /*!
279    * \brief Return length of i-th wrapped edge (count starts from zero)
280    */
281   inline double EdgeLength(int i) const;
282   /*!
283    * \brief Return orientation of i-th wrapped edge (count starts from zero)
284    */
285   inline bool IsReversed(int i) const;
286
287 protected:
288
289   void reverseProxySubmesh( const TopoDS_Edge& E );
290
291   // DON't FORGET to update Reverse() when adding one more vector!
292   std::vector<uvPtStruct>           myPoints, myFalsePoints;
293   std::vector<TopoDS_Edge>          myEdge;
294   std::vector<int>                  myEdgeID;
295   std::vector<Handle(Geom2d_Curve)> myC2d;
296   std::vector<GeomAdaptor_Curve>    myC3dAdaptor;
297   std::vector<double>               myFirst, myLast;
298   std::vector<double>               myNormPar;
299   std::vector<double>               myEdgeLength;
300   std::vector<int>                  myIsUniform;
301   double                            myLength;
302   int                               myNbPonits, myNbSegments;
303   SMESH_ProxyMesh::Ptr              myProxyMesh;
304   bool                              myMissingVertexNodes, myIgnoreMediumNodes;
305   gp_Pnt2d                          myDefaultPnt2d;
306 };
307
308
309 //================================================================================
310 /*!
311  * \brief Return edge index corresponding to normalized parameter
312   * \param U - the parameter
313   * \retval int - index
314  */
315 //================================================================================
316
317 inline int StdMeshers_FaceSide::EdgeIndex( double U ) const
318 {
319   int i = myNormPar.size() - 1;
320   while ( i > 0 && U < myNormPar[ i-1 ] ) --i;
321   return i;
322 }
323
324 //================================================================================
325 /*!
326  * \brief Return edge and parameter on edge by normalized parameter
327   * \param U - the parameter
328   * \retval double - pameter on a curve
329  */
330 //================================================================================
331
332 inline double StdMeshers_FaceSide::Parameter(double U, TopoDS_Edge & edge) const
333 {
334   int i = EdgeIndex( U );
335   edge = myEdge[ i ];
336   double prevU = i ? myNormPar[ i-1 ] : 0;
337   double r = ( U - prevU )/ ( myNormPar[ i ] - prevU );
338   return myFirst[i] * ( 1 - r ) + myLast[i] * r;
339 }
340
341 //================================================================================
342 /*!
343  * \brief Return first normalized parameter of the i-the edge
344  */
345 //================================================================================
346
347 inline double StdMeshers_FaceSide::FirstParameter(int i) const
348 {
349   return i==0 ? 0. : i<(int)myNormPar.size() ? myNormPar[i-1] : 1.;
350 }
351
352 //================================================================================
353 /*!
354  * \brief Return ast normalized parameter of the i-the edge
355  */
356 //================================================================================
357
358 inline double StdMeshers_FaceSide::LastParameter(int i) const
359 {
360   return i < (int)myNormPar.size() ? myNormPar[i] : 1;
361 }
362
363 //================================================================================
364 /*!
365  * \brief Return first parameter of the i-the edge
366  */
367 //================================================================================
368
369 inline double StdMeshers_FaceSide::FirstU(int i) const
370 {
371   return myFirst[ i % myFirst.size() ];
372 }
373
374 //================================================================================
375 /*!
376  * \brief Return last parameter of the i-the edge
377  */
378 //================================================================================
379
380 inline double StdMeshers_FaceSide::LastU(int i) const
381 {
382   return myLast[ i % myLast.size() ];
383 }
384
385 //================================================================================
386   /*!
387    * \brief Return ID of i-th wrapped edge (count starts from zero)
388    */
389 //================================================================================
390
391 inline int StdMeshers_FaceSide::EdgeID(int i) const
392 {
393   return myEdgeID[ i % myEdgeID.size() ];
394 }
395
396 //================================================================================
397 /*!
398    * \brief Return p-curve of i-th wrapped edge (count starts from zero)
399    */
400 //================================================================================
401
402 inline Handle(Geom2d_Curve) StdMeshers_FaceSide::Curve2d(int i) const
403 {
404   return myC2d[ i % myC2d.size() ];
405 }
406
407 //================================================================================
408 /*!
409  * \brief Return length of i-th wrapped edge (count starts from zero)
410  */
411  //================================================================================
412
413 inline double StdMeshers_FaceSide::EdgeLength(int i) const
414 {
415   return myEdgeLength[ i % myEdgeLength.size() ];
416 }
417
418 //================================================================================
419 /*!
420  * \brief Return orientation of i-th wrapped edge (count starts from zero)
421  */
422  //================================================================================
423
424 inline bool StdMeshers_FaceSide::IsReversed(int i) const
425 {
426   return myFirst[i] > myLast[i];
427 }
428
429 #endif