Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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 "SMESH_StdMeshers.hxx"
39 #include "SMESH_Algo.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 class SMESH_ComputeError;
52
53 typedef struct uvPtStruct
54 {
55   double param;
56   //int    curvIndex;
57   double normParam;
58   double u; // original 2d parameter
59   double v;
60   double x; // 2d parameter, normalized [0,1]
61   double y;
62   const SMDS_MeshNode * node;
63 } UVPtStruct;
64
65 class StdMeshers_FaceSide;
66 typedef boost::shared_ptr< StdMeshers_FaceSide > StdMeshers_FaceSidePtr;
67 typedef boost::shared_ptr< uvPtStruct > UVPtStructPtr;
68 typedef std::vector< StdMeshers_FaceSidePtr > TSideVector;
69 typedef boost::shared_ptr< SMESH_ComputeError > TError;
70
71 //================================================================================
72 /*!
73  * \brief Represents a side of a quasi quadrilateral face.
74  * It can be composed of several edges. Gives access to geometry and 1D mesh of a side.
75  */
76 //================================================================================
77
78 class STDMESHERS_EXPORT StdMeshers_FaceSide
79 {
80 public:
81   /*!
82    * \brief Wrap one edge
83    */
84   StdMeshers_FaceSide(const TopoDS_Face& theFace,
85                       const TopoDS_Edge& theEdge,
86                       SMESH_Mesh*        theMesh,
87                       const bool         theIsForward,
88                       const bool         theIgnoreMediumNodes);
89   /*!
90    * \brief Wrap several edges. Edges must be properly ordered and oriented.
91    */
92   StdMeshers_FaceSide(const TopoDS_Face& theFace,
93                       list<TopoDS_Edge>& theEdges,
94                       SMESH_Mesh*        theMesh,
95                       const bool         theIsForward,
96                       const bool         theIgnoreMediumNodes);
97
98   /*!
99    * \brief Return wires of a face as StdMeshers_FaceSide's
100    */
101   static TSideVector GetFaceWires(const TopoDS_Face& theFace,
102                                   SMESH_Mesh &       theMesh,
103                                   const bool         theIgnoreMediumNodes,
104                                   TError &           theError);  
105
106   /*!
107    * \brief Change orientation of side geometry
108    */
109   void Reverse();
110   /*!
111    * \brief Return nb nodes on edges and vertices (+1 to be == GetUVPtStruct().size() )
112    */
113   int NbPoints() const { return myNbPonits; }
114   /*!
115    * \brief Return nb edges
116    */
117   int NbSegments() const { return myNbSegments; }
118   /*!
119    * \brief Return mesh
120    */
121   SMESH_Mesh* GetMesh() const { return myMesh; }
122   /*!
123    * \brief Return true if there vertices without nodes
124    */
125   bool MissVertexNode() const { return myMissingVertexNodes; }
126   /*!
127    * \brief Return detailed data on nodes
128     * \param isXConst - true if normalized parameter X is constant
129     * \param constValue - constant parameter value
130     *
131     * Missing nodes are allowed only on internal vertices
132    */
133   const vector<UVPtStruct>& GetUVPtStruct(bool isXConst =0, double constValue =0) const;
134   /*!
135    * \brief Simulates detailed data on nodes
136     * \param isXConst - true if normalized parameter X is constant
137     * \param constValue - constant parameter value
138    */
139   const vector<UVPtStruct>& SimulateUVPtStruct(int    nbSeg,
140                                                bool   isXConst   = 0,
141                                                double constValue = 0) 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 1st vertex of the i-the edge (count starts from zero)
168    */
169   inline TopoDS_Vertex FirstVertex(int i=0) const;
170   /*!
171    * \brief Return last vertex of the i-the edge (count starts from zero)
172    */
173   inline TopoDS_Vertex LastVertex(int i=-1) const;
174   /*!
175    * \brief Return first normalized parameter of the i-the edge (count starts from zero)
176    */
177   inline double FirstParameter(int i) const;
178   /*!
179    * \brief Return ast normalized parameter of the i-the edge (count starts from zero)
180    */
181   inline double LastParameter(int i) const;
182   /*!
183    * \brief Return side length
184    */
185   double Length() const { return myLength; }
186   /*!
187    * \brief Return edge index corresponding to normalized parameter
188    */
189   inline int EdgeIndex( double U ) const;
190
191   //virtual gp_Pnt Value(double U) const;
192   
193   void dump(const char* msg=0) const;
194   
195
196 protected:
197   vector<uvPtStruct>           myPoints, myFalsePoints;
198   vector<TopoDS_Edge>          myEdge;
199   vector<Handle(Geom2d_Curve)> myC2d;
200   vector<double>               myFirst, myLast;
201   vector<double>               myNormPar;
202   double                       myLength;
203   int                          myNbPonits, myNbSegments;
204   SMESH_Mesh*                  myMesh;
205   bool                         myMissingVertexNodes, myIgnoreMediumNodes;
206 };
207
208
209 //================================================================================
210 /*!
211  * \brief Return edge index corresponding to normalized parameter
212   * \param U - the parameter
213   * \retval int - index
214  */
215 //================================================================================
216
217 inline int StdMeshers_FaceSide::EdgeIndex( double U ) const
218 {
219   int i = myNormPar.size() - 1;
220   while ( i > 0 && U < myNormPar[ i-1 ] ) --i;
221   return i;
222 }
223
224 //================================================================================
225 /*!
226  * \brief Return edge and parameter on edge by normalized parameter
227   * \param U - the parameter
228   * \retval double - pameter on a curve
229  */
230 //================================================================================
231
232 inline double StdMeshers_FaceSide::Parameter(double U, TopoDS_Edge & edge) const
233 {
234   int i = EdgeIndex( U );
235   edge = myEdge[ i ];
236   double prevU = i ? myNormPar[ i-1 ] : 0;
237   double r = ( U - prevU )/ ( myNormPar[ i ] - prevU );
238   return myFirst[i] * ( 1 - r ) + myLast[i] * r;
239 }
240
241 //================================================================================
242 /*!
243  * \brief Return 1st vertex of the i-the edge
244  */
245 //================================================================================
246
247 inline TopoDS_Vertex StdMeshers_FaceSide::FirstVertex(int i) const
248 {
249   return i < myEdge.size() ? TopExp::FirstVertex( myEdge[i], 1 ) : TopoDS_Vertex();
250 }
251
252 //================================================================================
253 /*!
254  * \brief Return last vertex of the i-the edge
255  */
256 //================================================================================
257
258 inline TopoDS_Vertex StdMeshers_FaceSide::LastVertex(int i) const
259 {
260   return i<0 ? TopExp::LastVertex( myEdge.back(), 1) : i<myEdge.size() ? TopExp::LastVertex( myEdge[i], 1 ) : TopoDS_Vertex();
261 }
262
263 //================================================================================
264 /*!
265  * \brief Return first normalized parameter of the i-the edge
266  */
267 //================================================================================
268
269 inline double StdMeshers_FaceSide::FirstParameter(int i) const
270 {
271   return i==0 ? 0. : i<myNormPar.size() ? myNormPar[i-1] : 1.;
272 }
273
274 //================================================================================
275 /*!
276  * \brief Return ast normalized parameter of the i-the edge
277  */
278 //================================================================================
279
280 inline double StdMeshers_FaceSide::LastParameter(int i) const
281 {
282   return i<myNormPar.size() ? myNormPar[i] : 1;
283 }
284
285 #endif