Salome HOME
PAL13615 (EDF PAL 315/31 GEOM SMESH : meshing of a "5 edges quadrangle")
[modules/smesh.git] / src / StdMeshers / StdMeshers_FaceSide.hxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  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 //
24 // File      : StdMeshers_FaceSide.hxx
25 // Created   : Wed Jan 31 18:41:25 2007
26 // Author    : Edward AGAPOV (eap)
27 // Module    : SMESH
28
29 #ifndef StdMeshers_FaceSide_HeaderFile
30 #define StdMeshers_FaceSide_HeaderFile
31
32 #include <gp_Pnt2d.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <Geom2d_Curve.hxx>
36 #include <TopExp.hxx>
37
38 #include <vector>
39 #include <list>
40 #include <boost/shared_ptr.hpp>
41
42 class SMDS_MeshNode;
43 class SMESH_Mesh;
44 class Adaptor2d_Curve2d;
45 class Adaptor3d_Curve;
46 class BRepAdaptor_CompCurve;
47 class TopoDS_Face;
48
49 typedef struct uvPtStruct
50 {
51   double param;
52   //int    curvIndex;
53   double normParam;
54   double u; // original 2d parameter
55   double v;
56   double x; // 2d parameter, normalized [0,1]
57   double y;
58   const SMDS_MeshNode * node;
59 } UVPtStruct;
60
61 class StdMeshers_FaceSide;
62 typedef boost::shared_ptr< StdMeshers_FaceSide > StdMeshers_FaceSidePtr;
63 typedef boost::shared_ptr< uvPtStruct > UVPtStructPtr;
64
65 //================================================================================
66 /*!
67  * \brief Represents a side of a quasi quadrilateral face.
68  * It can be composed of several edges. Gives access to geometry and 1D mesh of a side.
69  */
70 //================================================================================
71
72 class StdMeshers_FaceSide
73 {
74 public:
75   /*!
76    * \brief Wrap one edge
77    */
78   StdMeshers_FaceSide(const TopoDS_Face& theFace,
79                       const TopoDS_Edge& theEdge,
80                       SMESH_Mesh*        theMesh,
81                       const bool         theIsForward,
82                       const bool         theIgnoreMediumNodes);
83   /*!
84    * \brief Wrap several edges. Edges must be properly ordered and oriented.
85    */
86   StdMeshers_FaceSide(const TopoDS_Face& theFace,
87                       list<TopoDS_Edge>& theEdges,
88                       SMESH_Mesh*        theMesh,
89                       const bool         theIsForward,
90                       const bool         theIgnoreMediumNodes);
91   /*!
92    * \brief Change orientation of side geometry
93    */
94   void Reverse();
95   /*!
96    * \brief Return nb nodes on edges including ones on vertices
97    */
98   int NbPoints() const { return myNbPonits; }
99   /*!
100    * \brief Return nb nodes on edges including ones on vertices
101    */
102   int NbSegments() const { return myNbSegments; }
103   /*!
104    * \brief Return mesh
105    */
106   SMESH_Mesh* GetMesh() const { return myMesh; }
107   /*!
108    * \brief Return true if there vertices without nodes
109    */
110   bool MissVertexNode() const { return myMissingVertexNodes; }
111   /*!
112    * \brief Return detailed data on nodes
113     * \param isXConst - true if normalized parameter X is constant
114     * \param constValue - constant parameter value
115     *
116     * Missing nodes are allowed only on internal vertices
117    */
118   const vector<UVPtStruct>& GetUVPtStruct(bool isXConst, double constValue) const;
119   /*!
120    * \brief Simulates detailed data on nodes
121     * \param isXConst - true if normalized parameter X is constant
122     * \param constValue - constant parameter value
123    */
124   const vector<UVPtStruct>& SimulateUVPtStruct(int    nbSeg,
125                                                bool   isXConst,
126                                                double constValue) const;
127   /*!
128    * \brief Return edge and parameter on edge by normalized parameter
129    */
130   inline double Parameter(double U, TopoDS_Edge & edge) const;
131   /*!
132    * \brief Return UV by normalized parameter
133    */
134   gp_Pnt2d Value2d(double U) const;
135   /*!
136    * \brief Creates a Adaptor2d_Curve2d to be used in SMESH_Block
137    */
138   Adaptor2d_Curve2d* GetCurve2d() const;
139   /*!
140    * \brief Creates a fully functional Adaptor_Curve
141    */
142   BRepAdaptor_CompCurve* GetCurve3d() const;
143   /*!
144    * \brief Return nb of wrapped edges
145    */
146   int NbEdges() const { return myEdge.size(); }
147   /*!
148    * \brief Return i-th wrapped edge (count starts from zero)
149    */
150   const TopoDS_Edge& Edge(int i) const { return myEdge[i]; }
151   /*!
152    * \brief Return 1st vertex of the i-the edge (count starts from zero)
153    */
154   inline TopoDS_Vertex FirstVertex(int i=0) const;
155   /*!
156    * \brief Return last vertex of the i-the edge (count starts from zero)
157    */
158   inline TopoDS_Vertex LastVertex(int i=-1) const;
159   /*!
160    * \brief Return first normalized parameter of the i-the edge (count starts from zero)
161    */
162   inline double FirstParameter(int i) const;
163   /*!
164    * \brief Return ast normalized parameter of the i-the edge (count starts from zero)
165    */
166   inline double LastParameter(int i) const;
167   /*!
168    * \brief Return side length
169    */
170   double Length() const { return myLength; }
171   /*!
172    * \brief Return edge index corresponding to normalized parameter
173    */
174   inline int EdgeIndex( double U ) const;
175
176   //virtual gp_Pnt Value(double U) const;
177   
178   void dump(const char* msg=0) const;
179   
180
181 protected:
182   vector<uvPtStruct>           myPoints, myFalsePoints;
183   vector<TopoDS_Edge>          myEdge;
184   vector<Handle(Geom2d_Curve)> myC2d;
185   vector<double>               myFirst, myLast;
186   vector<double>               myNormPar;
187   double                       myLength;
188   int                          myNbPonits, myNbSegments;
189   SMESH_Mesh*                  myMesh;
190   bool                         myMissingVertexNodes, myIgnoreMediumNodes;
191 };
192
193
194 //================================================================================
195 /*!
196  * \brief Return edge index corresponding to normalized parameter
197   * \param U - the parameter
198   * \retval int - index
199  */
200 //================================================================================
201
202 inline int StdMeshers_FaceSide::EdgeIndex( double U ) const
203 {
204   int i = myNormPar.size() - 1;
205   while ( i > 0 && U < myNormPar[ i-1 ] ) --i;
206   return i;
207 }
208
209 //================================================================================
210 /*!
211  * \brief Return edge and parameter on edge by normalized parameter
212   * \param U - the parameter
213   * \retval double - pameter on a curve
214  */
215 //================================================================================
216
217 inline double StdMeshers_FaceSide::Parameter(double U, TopoDS_Edge & edge) const
218 {
219   int i = EdgeIndex( U );
220   edge = myEdge[ i ];
221   double prevU = i ? myNormPar[ i-1 ] : 0;
222   double r = ( U - prevU )/ ( myNormPar[ i ] - prevU );
223   return myFirst[i] * ( 1 - r ) + myLast[i] * r;
224 }
225
226 //================================================================================
227 /*!
228  * \brief Return 1st vertex of the i-the edge
229  */
230 //================================================================================
231
232 inline TopoDS_Vertex StdMeshers_FaceSide::FirstVertex(int i) const
233 {
234   return i < myEdge.size() ? TopExp::FirstVertex( myEdge[i], 1 ) : TopoDS_Vertex();
235 }
236
237 //================================================================================
238 /*!
239  * \brief Return last vertex of the i-the edge
240  */
241 //================================================================================
242
243 inline TopoDS_Vertex StdMeshers_FaceSide::LastVertex(int i) const
244 {
245   return i<0 ? TopExp::LastVertex( myEdge.back(), 1) : i<myEdge.size() ? TopExp::LastVertex( myEdge[i], 1 ) : TopoDS_Vertex();
246 }
247
248 //================================================================================
249 /*!
250  * \brief Return first normalized parameter of the i-the edge
251  */
252 //================================================================================
253
254 inline double StdMeshers_FaceSide::FirstParameter(int i) const
255 {
256   return i==0 ? 0. : i<myNormPar.size() ? myNormPar[i-1] : 1.;
257 }
258
259 //================================================================================
260 /*!
261  * \brief Return ast normalized parameter of the i-the edge
262  */
263 //================================================================================
264
265 inline double StdMeshers_FaceSide::LastParameter(int i) const
266 {
267   return i<myNormPar.size() ? myNormPar[i] : 1;
268 }
269
270 #endif