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