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