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