Version: 8.3.0
StdMeshers_Quadrangle_2D.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 // File : StdMeshers_Quadrangle_2D.hxx
23 // Moved here from SMESH_Quadrangle_2D.hxx
24 // Author : Paul RASCLE, EDF
25 // Module : SMESH
26 
27 #ifndef _SMESH_QUADRANGLE_2D_HXX_
28 #define _SMESH_QUADRANGLE_2D_HXX_
29 
30 #include "SMESH_Algo.hxx"
31 #include "SMESH_ProxyMesh.hxx"
32 #include "SMESH_StdMeshers.hxx"
33 #include "StdMeshers_FaceSide.hxx"
35 
36 #include <TopoDS_Face.hxx>
37 #include <Bnd_B2d.hxx>
38 
39 class SMDS_MeshNode;
40 class SMESH_Mesh;
41 class SMESH_MesherHelper;
42 class SMESH_ProxyMesh;
43 struct uvPtStruct;
44 
45 
47 
50 {
51  struct Side // a side of FaceQuadStruct
52  {
53  struct Contact // contact of two sides
54  {
55  int point; // index of a grid point of this side where two sides meat
58  };
60  int from, to; // indices of grid points used by the quad
61  int di; // +1 or -1 depending on IsReversed()
62  std::set<int> forced_nodes; // indices of forced grid points
63  std::vector<Contact> contacts; // contacts with sides of other quads
64  int nbNodeOut; // nb of missing nodes on an opposite shorter side
65 
67  Side& operator=(const Side& otherSide);
68  operator StdMeshers_FaceSidePtr() { return grid; }
69  operator const StdMeshers_FaceSidePtr() const { return grid; }
70  void AddContact( int ip, Side* side, int iop );
71  int ToSideIndex( int quadNodeIndex ) const;
72  int ToQuadIndex( int sideNodeIndex ) const;
73  bool IsForced( int nodeIndex ) const;
74  bool IsReversed() const { return nbNodeOut ? false : to < from; }
75  bool Reverse(bool keepGrid);
76  int NbPoints() const { return Abs( to - from ); }
77  double Param( int nodeIndex ) const;
78  double Length( int from=-1, int to=-1) const;
79  gp_XY Value2d( double x ) const;
80  const UVPtStruct& First() const { return GetUVPtStruct()[ from ]; }
81  const UVPtStruct& Last() const {
82  return GetUVPtStruct()[ to-nbNodeOut-(IsReversed() ? -1 : +1)];
83  }
84  // some sortcuts
85  const std::vector<UVPtStruct>& GetUVPtStruct(bool isXConst=0, double constValue=0) const
86  { return nbNodeOut ?
87  grid->SimulateUVPtStruct( NbPoints()-nbNodeOut-1, isXConst, constValue ) :
88  grid->GetUVPtStruct( isXConst, constValue );
89  }
90  };
91  struct SideIterator // iterator on UVPtStruct of a Side
92  {
94  int dPtr, counter;
95  SideIterator(): uvPtr(0), uvEnd(0), dPtr(0), counter(0) {}
96  void Init( const Side& side ) {
97  dPtr = counter = 0;
98  uvPtr = uvEnd = 0;
99  if ( side.NbPoints() > 0 ) {
100  uvPtr = & side.First();
101  uvEnd = & side.Last();
102  dPtr = ( uvEnd > uvPtr ) ? +1 : -1;
103  uvEnd += dPtr;
104  }
105  }
106  bool More() const { return uvPtr != uvEnd; }
107  void Next() { uvPtr += dPtr; ++counter; }
108  UVPtStruct& UVPt() const { return (UVPtStruct&) *uvPtr; }
109  UVPtStruct& operator[](int i) { return (UVPtStruct&) uvPtr[ i*dPtr]; }
110  int Count() const { return counter; }
111  };
112 
113  std::vector< Side > side;
114  std::vector< UVPtStruct> uv_grid;
115  int iSize, jSize;
116  TopoDS_Face face;
117  Bnd_B2d uv_box;
118  std::string name; // to ease debugging
119 
120  FaceQuadStruct ( const TopoDS_Face& F = TopoDS_Face(), const std::string& nm="main" );
121  UVPtStruct& UVPt( int i, int j ) { return uv_grid[ i + j * iSize ]; }
122  double& U( int i, int j ) { return UVPt( i, j ).u; }
123  double& V( int i, int j ) { return UVPt( i, j ).v; }
124  void shift ( size_t nb, bool keepUnitOri, bool keepGrid=false );
125  int & nbNodeOut( int iSide ) { return side[ iSide ].nbNodeOut; }
126  bool findCell ( const gp_XY& uv, int & i, int & j );
127  bool isNear ( const gp_XY& uv, int & i, int & j, int nbLoops=1 );
128  bool isEqual ( const gp_XY& uv, int i, int j );
129  void normPa2IJ( double x, double y, int & i, int & j );
130  void updateUV ( const gp_XY& uv, int i, int j, bool isVertical );
131 
132  typedef boost::shared_ptr<FaceQuadStruct> Ptr;
133 };
134 
136 {
137  public:
138  StdMeshers_Quadrangle_2D(int hypId, int studyId, SMESH_Gen* gen);
139  virtual ~StdMeshers_Quadrangle_2D();
140 
141  virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
142  const TopoDS_Shape& aShape,
143  Hypothesis_Status& aStatus);
144 
145  virtual bool Compute(SMESH_Mesh& aMesh,
146  const TopoDS_Shape& aShape);
147 
148  virtual bool Evaluate(SMESH_Mesh & aMesh,
149  const TopoDS_Shape & aShape,
150  MapShapeNbElems& aResMap);
151 
152  FaceQuadStruct::Ptr CheckAnd2Dcompute(SMESH_Mesh& aMesh,
153  const TopoDS_Shape& aShape,
154  const bool CreateQuadratic);
155 
156  FaceQuadStruct::Ptr CheckNbEdges(SMESH_Mesh& aMesh,
157  const TopoDS_Shape& aShape,
158  const bool considerMesh = false,
159  SMESH_MesherHelper* aFaceHelper = 0);
160 
161  static bool IsApplicable(const TopoDS_Shape & aShape, bool toCheckAll);
162 
163  protected:
164 
165  bool checkNbEdgesForEvaluate(SMESH_Mesh& aMesh,
166  const TopoDS_Shape & aShape,
167  MapShapeNbElems& aResMap,
168  std::vector<int>& aNbNodes,
169  bool& IsQuadratic);
170 
171  bool setNormalizedGrid(FaceQuadStruct::Ptr quad);
172 
173  void splitQuadFace(SMESHDS_Mesh * theMeshDS,
174  const int theFaceID,
175  const SMDS_MeshNode* theNode1,
176  const SMDS_MeshNode* theNode2,
177  const SMDS_MeshNode* theNode3,
178  const SMDS_MeshNode* theNode4);
179 
180  bool computeQuadDominant(SMESH_Mesh& aMesh,
181  const TopoDS_Face& aFace);
182 
183  bool computeQuadDominant(SMESH_Mesh& aMesh,
184  const TopoDS_Face& aFace,
185  FaceQuadStruct::Ptr quad);
186 
187  bool computeQuadPref(SMESH_Mesh& aMesh,
188  const TopoDS_Face& aFace,
189  FaceQuadStruct::Ptr quad);
190 
191  bool computeTriangles(SMESH_Mesh& aMesh,
192  const TopoDS_Face& aFace,
193  FaceQuadStruct::Ptr quad);
194 
195  bool evaluateQuadPref(SMESH_Mesh& aMesh,
196  const TopoDS_Shape& aShape,
197  std::vector<int>& aNbNodes,
198  MapShapeNbElems& aResMap,
199  bool isQuadratic);
200 
201  bool computeReduced (SMESH_Mesh& aMesh,
202  const TopoDS_Face& aFace,
203  FaceQuadStruct::Ptr quad);
204 
205  void updateDegenUV(FaceQuadStruct::Ptr quad);
206 
207  void smooth (FaceQuadStruct::Ptr quad);
208 
209  bool check();
210 
211  int getCorners(const TopoDS_Face& theFace,
212  SMESH_Mesh & theMesh,
213  std::list<TopoDS_Edge>& theWire,
214  std::vector<TopoDS_Vertex>& theVertices,
215  int & theNbDegenEdges,
216  const bool considerMesh);
217 
218  bool getEnforcedUV();
219 
220  bool addEnforcedNodes();
221 
222  int splitQuad(FaceQuadStruct::Ptr quad, int i, int j);
223 
224  void shiftQuad(FaceQuadStruct::Ptr& quad, const int num );
225 
226  typedef std::map< StdMeshers_FaceSidePtr, std::vector< FaceQuadStruct::Ptr > > TQuadsBySide;
227  void updateSideUV( FaceQuadStruct::Side& side,
228  int iForced,
229  const TQuadsBySide& quads,
230  int * iNext=NULL);
231 
232 
233  protected: // Fields
234 
238  bool myNeedSmooth, myCheckOri;
241 
244  std::list< FaceQuadStruct::Ptr > myQuadList;
245 
246  struct ForcedPoint
247  {
248  gp_XY uv;
249  gp_XYZ xyz;
250  TopoDS_Vertex vertex;
252 
253  double U() const { return uv.X(); }
254  double V() const { return uv.Y(); }
255  operator const gp_XY& () { return uv; }
256  };
257  std::vector< ForcedPoint > myForcedPnts;
258 };
259 
260 #endif