Salome HOME
Copyrights update 2015.
[plugins/hexablockplugin.git] / src / HEXABLOCKPlugin / HEXABLOCKPlugin_mesh.hxx
1 // Copyright (C) 2009-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 //  File   : SMESH_HexaBlocks.hxx
20 //  Author :
21 //  Module : SMESH
22 //
23 #ifndef _SMESH_HexaBlocks_HeaderFile
24 #define _SMESH_HexaBlocks_HeaderFile
25
26 #include <SALOMEconfig.h>
27 #include "HEXABLOCKPlugin_Defs.hxx"
28
29 #include "SMESH_Mesh.hxx"
30 #include "SMESH_Group.hxx"
31 #include "hexa_base.hxx" // from HexaBlocks
32 #include "HexFaceShape.hxx" // from HexaBlocks
33
34 #ifndef _Standard_Real_HeaderFile
35 #include <Standard_Real.hxx>
36 #endif
37
38 #include <gp_Pnt.hxx>
39 #include <gp_Vec.hxx>
40 #include <TopoDS_Face.hxx>
41 #include "Handle_Geom_Curve.hxx"
42 #include <BRepAdaptor_Curve.hxx>
43
44 //=====================================================================
45 // SMESH_HexaBlocks : class definition
46 //=====================================================================
47 class HEXABLOCKPLUGINENGINE_EXPORT SMESH_HexaBlocks
48 {
49 public:
50
51 //   typedef std::vector<double>            Xx;
52   typedef std::vector<SMDS_MeshVolume*>  SMESHVolumes;
53   typedef std::vector<SMDS_MeshNode*>    SMESHNodes;
54   typedef std::vector<SMDS_MeshFace*>    SMESHFaces;
55   typedef std::vector<SMDS_MeshEdge*>    SMESHEdges;
56
57   typedef std::vector< SMESHNodes >      ArrayOfSMESHNodes;
58
59   struct Coord{
60     double x;
61     double y;
62     double z;
63   };
64
65
66    SMESH_HexaBlocks(SMESH_Mesh& theMesh);
67   ~SMESH_HexaBlocks();
68
69   // --------------------------------------------------------------
70   //  Vertex computing
71   // --------------------------------------------------------------
72   bool computeVertex( HEXA_NS::Vertex& vertex );
73
74   // --------------------------------------------------------------
75   //  Edge computing
76   // --------------------------------------------------------------
77   bool computeEdge( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
78   // Association solving
79   bool computeEdgeByAssoc( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
80
81   // Automatic solving
82   bool computeEdgeByShortestWire( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
83   bool computeEdgeByPlanWire( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
84   bool computeEdgeByIsoWire( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
85   bool computeEdgeBySegment( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
86
87   // --------------------------------------------------------------
88   //  Quad computing
89   // --------------------------------------------------------------
90   std::map<HEXA_NS::Quad*, bool>  computeQuadWays( HEXA_NS::Document* doc );
91   bool computeQuad( HEXA_NS::Quad& quad, bool way );
92   // Association solving
93   bool computeQuadByAssoc( HEXA_NS::Quad& quad, bool way );
94   // Automatic solving
95   bool computeQuadByFindingGeom( HEXA_NS::Quad& quad, bool way );
96   bool computeQuadByLinearApproximation( HEXA_NS::Quad& quad, bool way );
97
98   // --------------------------------------------------------------
99   //  Hexa computing
100   // --------------------------------------------------------------
101   bool computeHexa( HEXA_NS::Document* doc );
102
103   // --------------------------------------------------------------
104   //  Document computing: Vertex, Edge, Quad and Hexa computing
105   // --------------------------------------------------------------
106   bool computeDoc( HEXA_NS::Document* doc );
107
108
109   // --------------------------------------------------------------
110   //  Build groups
111   // --------------------------------------------------------------
112   void buildGroups(HEXA_NS::Document* doc);
113
114
115 private:
116   //    ********     METHOD FOR MESH COMPUTATION    ********
117   //  EDGE
118   double _Xx( double i, HEXA_NS::Law law, double nbNodes );
119
120   double _edgeLength(const TopoDS_Edge & E);
121
122   void _buildMyCurve(
123       const gp_Pnt&                             myCurve_start,  //IN
124       const gp_Pnt&                             myCurve_end,    //IN
125       std::list< BRepAdaptor_Curve* >&          myCurve,        //INOUT
126       double&                                   myCurve_length, //INOUT
127       std::map< BRepAdaptor_Curve*, double>&    myCurve_lengths,//INOUT
128       std::map< BRepAdaptor_Curve*, bool>&      myCurve_ways,   //INOUT
129       std::map< BRepAdaptor_Curve*, double>&    myCurve_starts,   //INOUT
130       HEXA_NS::Edge&                            edge);  // For diagnostic
131
132   gp_Pnt _getPtOnMyCurve(
133       const double&                           myCurve_u,      //IN
134       std::map< BRepAdaptor_Curve*, bool>&    myCurve_ways,   //IN
135       std::map< BRepAdaptor_Curve*, double>&  myCurve_lengths,//IN
136       std::map< BRepAdaptor_Curve*, double>&  myCurve_starts, //IN
137       std::list< BRepAdaptor_Curve* >&        myCurve,        //INOUT
138       double&                                 myCurve_start); //INOUT
139
140   // QUAD
141   void _nodeInterpolationUV( double u, double v,
142     SMDS_MeshNode* Pg, SMDS_MeshNode* Pd, SMDS_MeshNode* Ph, SMDS_MeshNode* Pb,
143     SMDS_MeshNode* S0, SMDS_MeshNode* S1, SMDS_MeshNode* S2, SMDS_MeshNode* S3,
144     double& xOut, double& yOut, double& zOut );
145
146   // TopoDS_Shape _getShapeOrCompound( const std::vector<HEXA_NS::Shape*>& shapesIn );
147   TopoDS_Shape getFaceShapes (Hex::Quad& quad);
148
149   gp_Pnt _intersect( const gp_Pnt& Pt,
150                      const gp_Vec& u, const gp_Vec& v,
151                      const TopoDS_Shape& s,
152                      Standard_Real tol = 0.0001 );
153
154   bool _computeQuadInit(
155     HEXA_NS::Quad& quad,
156     ArrayOfSMESHNodes& nodesOnQuad,
157     std::vector<double>& xx, std::vector<double>& yy);
158
159   void _searchInitialQuadWay( HEXA_NS::Quad* quad, //IN
160                               HEXA_NS::Vertex*& v0,      //INOUT
161                               HEXA_NS::Vertex*& v1 );    //INOUT
162
163
164   //    ********     DATA FOR MESH COMPUTATION    ********
165   //    NODES
166   std::map<HEXA_NS::Vertex*, SMDS_MeshNode*>        _node;    //_vertexNode;
167   std::map<const SMDS_MeshNode*, HEXA_NS::Vertex*>  _vertex;  //_nodeVertex;
168
169   //    EDGES
170   std::map<HEXA_NS::Edge*, SMESHNodes>  _nodesOnEdge; //_edgeNodes;
171 //   std::map<HEXA_NS::Edge*, Xx>                _edgeXx;
172   std::map<SMDS_MeshNode*, double>  _nodeXx; //_edgeNodes;
173   std::map<HEXA_NS::Quad*, ArrayOfSMESHNodes> _quadNodes;
174
175   bool _computeVertexOK;
176   bool _computeEdgeOK;
177   bool _computeQuadOK;
178
179   SMESHDS_Mesh* _theMeshDS;
180   SMESH_Mesh*   _theMesh;
181
182   //    ********     METHOD FOR GROUPS COMPUTATION    ********
183   SMESH_Group* _createGroup(HEXA_NS::Group& grHex);
184   void _fillGroup(HEXA_NS::Group* grHex);
185
186   //    ********     DATA FOR GROUPS COMPUTATION    ********
187   std::map<HEXA_NS::Hexa*, SMESHVolumes> _volumesOnHexa;
188   std::map<HEXA_NS::Quad*, SMESHFaces>   _facesOnQuad;
189   std::map<HEXA_NS::Edge*, SMESHEdges>   _edgesOnEdge;
190
191
192   // for DEBUG purpose only:
193   int _total;
194   int _found;
195   int _notFound;
196 };
197
198
199 #endif