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