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