1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_FaceSide.hxx
24 // Created : Wed Jan 31 18:41:25 2007
25 // Author : Edward AGAPOV (eap)
28 #ifndef StdMeshers_FaceSide_HeaderFile
29 #define StdMeshers_FaceSide_HeaderFile
31 #include "SMESH_StdMeshers.hxx"
33 #include "SMESH_ProxyMesh.hxx"
35 #include <Geom2d_Curve.hxx>
36 #include <GeomAdaptor_Curve.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <gp_Pnt2d.hxx>
43 #include <boost/shared_ptr.hpp>
47 class Adaptor2d_Curve2d;
48 class Adaptor3d_Curve;
49 class BRepAdaptor_CompCurve;
51 struct SMESH_ComputeError;
52 class StdMeshers_FaceSide;
54 typedef boost::shared_ptr< SMESH_ComputeError > TError;
55 typedef boost::shared_ptr< StdMeshers_FaceSide > StdMeshers_FaceSidePtr;
56 typedef std::vector< StdMeshers_FaceSidePtr > TSideVector;
58 //================================================================================
60 * \brief Represents a side of a quasi quadrilateral face.
61 * It can be composed of several edges. Gives access to geometry and 1D mesh of a side.
63 //================================================================================
65 class STDMESHERS_EXPORT StdMeshers_FaceSide
69 * \brief Wrap one edge
71 StdMeshers_FaceSide(const TopoDS_Face& theFace,
72 const TopoDS_Edge& theEdge,
74 const bool theIsForward,
75 const bool theIgnoreMediumNodes,
76 SMESH_ProxyMesh::Ptr theProxyMesh = SMESH_ProxyMesh::Ptr());
78 * \brief Wrap several edges. Edges must be properly ordered and oriented.
80 StdMeshers_FaceSide(const TopoDS_Face& theFace,
81 std::list<TopoDS_Edge>& theEdges,
83 const bool theIsForward,
84 const bool theIgnoreMediumNodes,
85 SMESH_ProxyMesh::Ptr theProxyMesh = SMESH_ProxyMesh::Ptr());
87 * \brief Simulate a side from a vertex using data from other FaceSide
89 StdMeshers_FaceSide(const StdMeshers_FaceSide* theSide,
90 const SMDS_MeshNode* theNode,
91 const gp_Pnt2d* thePnt2d1,
92 const gp_Pnt2d* thePnt2d2=NULL,
93 const Handle(Geom2d_Curve)& theC2d=NULL,
94 const double theUFirst=0.,
95 const double theULast=1.);
97 * \brief Return wires of a face as StdMeshers_FaceSide's
99 static TSideVector GetFaceWires(const TopoDS_Face& theFace,
100 SMESH_Mesh & theMesh,
101 const bool theIgnoreMediumNodes,
103 SMESH_ProxyMesh::Ptr theProxyMesh = SMESH_ProxyMesh::Ptr());
105 * \brief Change orientation of side geometry
109 * \brief Make ignore medium nodes
111 void SetIgnoreMediumNodes(bool toIgnore);
114 * \brief Return nb nodes on edges and vertices (+1 to be == GetUVPtStruct().size() ).
115 * Call it with update == true if mesh of this side can be recomputed
116 * since creation of this side
118 int NbPoints(const bool update = false) const;
120 * \brief Return nb edges
121 * Call it with update == true if mesh of this side can be recomputed
122 * since creation of this side
124 int NbSegments(const bool update = false) const;
128 SMESH_Mesh* GetMesh() const { return myProxyMesh->GetMesh(); }
130 * \brief Return true if there are vertices without nodes
132 bool MissVertexNode() const { return myMissingVertexNodes; }
135 * \brief Return detailed data on nodes
136 * \param isXConst - true if normalized parameter X is constant
137 * \param constValue - constant parameter value
139 * Missing nodes are allowed only on internal vertices.
140 * For a closed side, the 1st point repeats at end
142 const UVPtStructVec& GetUVPtStruct(bool isXConst =0, double constValue =0) const;
144 * \brief Simulates detailed data on nodes
145 * \param isXConst - true if normalized parameter X is constant
146 * \param constValue - constant parameter value
148 const UVPtStructVec& SimulateUVPtStruct(int nbSeg,
150 double constValue = 0) const;
152 * \brief Return nodes in the order they encounter while walking along the side.
153 * For a closed side, the 1st point repeats at end
155 std::vector<const SMDS_MeshNode*> GetOrderedNodes() const;
158 * \brief Return edge and parameter on edge by normalized parameter
160 inline double Parameter(double U, TopoDS_Edge & edge) const;
162 * \brief Return UV by normalized parameter
164 gp_Pnt2d Value2d(double U) const;
166 * \brief Return XYZ by normalized parameter
168 gp_Pnt Value3d(double U) const;
170 * \brief Creates a Adaptor2d_Curve2d to be used in SMESH_Block
172 Adaptor2d_Curve2d* GetCurve2d() const;
174 * \brief Creates a fully functional Adaptor_Curve
176 BRepAdaptor_CompCurve* GetCurve3d() const;
178 * \brief Return nb of wrapped edges
180 int NbEdges() const { return myEdge.size(); }
182 * \brief Return i-th wrapped edge (count starts from zero)
184 const TopoDS_Edge& Edge(int i) const { return myEdge[i]; }
186 * \brief Return all edges
188 const std::vector<TopoDS_Edge>& Edges() const { return myEdge; }
190 * \brief Return 1st vertex of the i-the edge (count starts from zero)
192 TopoDS_Vertex FirstVertex(int i=0) const;
194 * \brief Return last vertex of the i-the edge (count starts from zero)
196 TopoDS_Vertex LastVertex(int i=-1) const;
198 * \brief Return side length
200 double Length() const { return myLength; }
202 * \brief Return edge index corresponding to normalized parameter
204 inline int EdgeIndex( double U ) const;
206 //virtual gp_Pnt Value(double U) const;
208 void dump(const char* msg=0) const;
211 * \brief Return ID of i-th wrapped edge (count starts from zero)
213 inline int EdgeID(int i) const;
215 * \brief Return p-curve of i-th wrapped edge (count starts from zero)
217 inline Handle(Geom2d_Curve) Curve2d(int i) const;
219 * \brief Return first normalized parameter of the i-the edge (count starts from zero)
221 inline double FirstParameter(int i) const;
223 * \brief Return last normalized parameter of the i-the edge (count starts from zero)
225 inline double LastParameter(int i) const;
227 * \brief Return first parameter of the i-the edge (count starts from zero).
228 * EDGE orientation is taken into account
230 inline double FirstU(int i) const;
232 * \brief Return last parameter of the i-the edge (count starts from zero).
233 * EDGE orientation is taken into account
235 inline double LastU(int i) const;
237 * \brief Return length of i-th wrapped edge (count starts from zero)
239 inline double EdgeLength(int i) const;
241 * \brief Return orientation of i-th wrapped edge (count starts from zero)
243 inline bool IsReversed(int i) const;
247 void reverseProxySubmesh( const TopoDS_Edge& E );
249 // DON't FORGET to update Reverse() when adding one more vector!
250 std::vector<uvPtStruct> myPoints, myFalsePoints;
251 std::vector<TopoDS_Edge> myEdge;
252 std::vector<int> myEdgeID;
253 std::vector<Handle(Geom2d_Curve)> myC2d;
254 std::vector<GeomAdaptor_Curve> myC3dAdaptor;
255 std::vector<double> myFirst, myLast;
256 std::vector<double> myNormPar;
257 std::vector<double> myEdgeLength;
258 std::vector<int> myIsUniform;
260 int myNbPonits, myNbSegments;
261 SMESH_ProxyMesh::Ptr myProxyMesh;
262 bool myMissingVertexNodes, myIgnoreMediumNodes;
263 gp_Pnt2d myDefaultPnt2d;
267 //================================================================================
269 * \brief Return edge index corresponding to normalized parameter
270 * \param U - the parameter
271 * \retval int - index
273 //================================================================================
275 inline int StdMeshers_FaceSide::EdgeIndex( double U ) const
277 int i = myNormPar.size() - 1;
278 while ( i > 0 && U < myNormPar[ i-1 ] ) --i;
282 //================================================================================
284 * \brief Return edge and parameter on edge by normalized parameter
285 * \param U - the parameter
286 * \retval double - pameter on a curve
288 //================================================================================
290 inline double StdMeshers_FaceSide::Parameter(double U, TopoDS_Edge & edge) const
292 int i = EdgeIndex( U );
294 double prevU = i ? myNormPar[ i-1 ] : 0;
295 double r = ( U - prevU )/ ( myNormPar[ i ] - prevU );
296 return myFirst[i] * ( 1 - r ) + myLast[i] * r;
299 //================================================================================
301 * \brief Return first normalized parameter of the i-the edge
303 //================================================================================
305 inline double StdMeshers_FaceSide::FirstParameter(int i) const
307 return i==0 ? 0. : i<(int)myNormPar.size() ? myNormPar[i-1] : 1.;
310 //================================================================================
312 * \brief Return ast normalized parameter of the i-the edge
314 //================================================================================
316 inline double StdMeshers_FaceSide::LastParameter(int i) const
318 return i < (int)myNormPar.size() ? myNormPar[i] : 1;
321 //================================================================================
323 * \brief Return first parameter of the i-the edge
325 //================================================================================
327 inline double StdMeshers_FaceSide::FirstU(int i) const
329 return myFirst[ i % myFirst.size() ];
332 //================================================================================
334 * \brief Return last parameter of the i-the edge
336 //================================================================================
338 inline double StdMeshers_FaceSide::LastU(int i) const
340 return myLast[ i % myLast.size() ];
343 //================================================================================
345 * \brief Return ID of i-th wrapped edge (count starts from zero)
347 //================================================================================
349 inline int StdMeshers_FaceSide::EdgeID(int i) const
351 return myEdgeID[ i % myEdgeID.size() ];
354 //================================================================================
356 * \brief Return p-curve of i-th wrapped edge (count starts from zero)
358 //================================================================================
360 inline Handle(Geom2d_Curve) StdMeshers_FaceSide::Curve2d(int i) const
362 return myC2d[ i % myC2d.size() ];
365 //================================================================================
367 * \brief Return length of i-th wrapped edge (count starts from zero)
369 //================================================================================
371 inline double StdMeshers_FaceSide::EdgeLength(int i) const
373 return myEdgeLength[ i % myEdgeLength.size() ];
376 //================================================================================
378 * \brief Return orientation of i-th wrapped edge (count starts from zero)
380 //================================================================================
382 inline bool StdMeshers_FaceSide::IsReversed(int i) const
384 return myFirst[i] > myLast[i];