Salome HOME
7b8b66158df4424a0dce8adef4aa9548f6efb898
[plugins/hexablockplugin.git] / src / HEXABLOCKPlugin / HEXABLOCKPlugin_mesh.hxx
1 // Copyright (C) 2009-2012  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.
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
28 #ifdef WNT
29 # if defined HEXABLOCKS_EXPORTS || defined HexaBlocks_EXPORTS
30 #  define HEXABLOCKS_EXPORT __declspec( dllexport )
31 # else
32 #  define HEXABLOCKS_EXPORT __declspec( dllimport )
33 # endif
34 #else
35 # define HEXABLOCKS_EXPORT
36 #endif
37
38 #include "SMESH_Mesh.hxx"
39 #include "SMESH_Group.hxx"
40 #include "hexa_base.hxx" // from HexaBlocks
41 #include "HexFaceShape.hxx" // from HexaBlocks
42
43 #ifndef _Standard_Real_HeaderFile
44 #include <Standard_Real.hxx>
45 #endif
46
47 #include <gp_Pnt.hxx>
48 #include <gp_Vec.hxx>
49 #include <TopoDS_Face.hxx>
50 #include "Handle_Geom_Curve.hxx"
51 #include <BRepAdaptor_Curve.hxx>
52
53 //=====================================================================
54 // SMESH_HexaBlocks : class definition
55 //=====================================================================
56 class HEXABLOCKS_EXPORT SMESH_HexaBlocks
57 {
58 public:
59
60 //   typedef std::vector<double>            Xx;
61   typedef std::vector<SMDS_MeshVolume*>  SMESHVolumes;
62   typedef std::vector<SMDS_MeshNode*>    SMESHNodes;
63   typedef std::vector<SMDS_MeshFace*>    SMESHFaces;
64   typedef std::vector<SMDS_MeshEdge*>    SMESHEdges;
65
66   typedef std::vector< SMESHNodes >      ArrayOfSMESHNodes;
67
68   struct Coord{
69     double x;
70     double y;
71     double z;
72   };
73
74
75    SMESH_HexaBlocks(SMESH_Mesh& theMesh);
76   ~SMESH_HexaBlocks();
77
78   // --------------------------------------------------------------
79   //  Vertex computing
80   // --------------------------------------------------------------
81   bool computeVertex( HEXA_NS::Vertex& vertex );
82
83   // --------------------------------------------------------------
84   //  Edge computing
85   // --------------------------------------------------------------
86   bool computeEdge( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
87   // Association solving
88   bool computeEdgeByAssoc( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
89
90   // Automatic solving
91   bool computeEdgeByShortestWire( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
92   bool computeEdgeByPlanWire( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
93   bool computeEdgeByIsoWire( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
94   bool computeEdgeBySegment( HEXA_NS::Edge& edge, HEXA_NS::Law& law);
95
96   // --------------------------------------------------------------
97   //  Quad computing
98   // --------------------------------------------------------------
99   std::map<HEXA_NS::Quad*, bool>  computeQuadWays( HEXA_NS::Document* doc );
100   bool computeQuad( HEXA_NS::Quad& quad, bool way );
101   // Association solving
102   bool computeQuadByAssoc( HEXA_NS::Quad& quad, bool way );
103   // Automatic solving
104   bool computeQuadByFindingGeom( HEXA_NS::Quad& quad, bool way );
105   bool computeQuadByLinearApproximation( HEXA_NS::Quad& quad, bool way );
106
107   // --------------------------------------------------------------
108   //  Hexa computing
109   // --------------------------------------------------------------
110   bool computeHexa( HEXA_NS::Document* doc );
111
112   // --------------------------------------------------------------
113   //  Document computing: Vertex, Edge, Quad and Hexa computing
114   // --------------------------------------------------------------
115   bool computeDoc( HEXA_NS::Document* doc );
116
117
118   // --------------------------------------------------------------
119   //  Build groups
120   // --------------------------------------------------------------
121   void buildGroups(HEXA_NS::Document* doc);
122
123
124 private:
125   //    ********     METHOD FOR MESH COMPUTATION    ********
126   //  EDGE
127   double _Xx( double i, HEXA_NS::Law law, double nbNodes );
128
129   double _edgeLength(const TopoDS_Edge & E);
130
131   void _buildMyCurve(
132       const gp_Pnt&                             myCurve_start,  //IN
133       const gp_Pnt&                             myCurve_end,    //IN
134       std::list< BRepAdaptor_Curve* >&          myCurve,        //INOUT
135       double&                                   myCurve_length, //INOUT
136       std::map< BRepAdaptor_Curve*, double>&    myCurve_lengths,//INOUT
137       std::map< BRepAdaptor_Curve*, bool>&      myCurve_ways,   //INOUT
138       std::map< BRepAdaptor_Curve*, double>&    myCurve_starts,   //INOUT
139       HEXA_NS::Edge&                            edge);  // For diagnostic
140
141   gp_Pnt _getPtOnMyCurve(
142       const double&                           myCurve_u,      //IN
143       std::map< BRepAdaptor_Curve*, bool>&    myCurve_ways,   //IN
144       std::map< BRepAdaptor_Curve*, double>&  myCurve_lengths,//IN
145       std::map< BRepAdaptor_Curve*, double>&  myCurve_starts, //IN
146       std::list< BRepAdaptor_Curve* >&        myCurve,        //INOUT
147       double&                                 myCurve_start); //INOUT
148
149   // QUAD
150   void _nodeInterpolationUV( double u, double v,
151     SMDS_MeshNode* Pg, SMDS_MeshNode* Pd, SMDS_MeshNode* Ph, SMDS_MeshNode* Pb,
152     SMDS_MeshNode* S0, SMDS_MeshNode* S1, SMDS_MeshNode* S2, SMDS_MeshNode* S3,
153     double& xOut, double& yOut, double& zOut );
154
155   // TopoDS_Shape _getShapeOrCompound( const std::vector<HEXA_NS::Shape*>& shapesIn );
156   TopoDS_Shape getFaceShapes (Hex::Quad& quad);
157
158   gp_Pnt _intersect( const gp_Pnt& Pt,
159                      const gp_Vec& u, const gp_Vec& v,
160                      const TopoDS_Shape& s,
161                      Standard_Real tol = 0.0001 );
162
163   bool _computeQuadInit(
164     HEXA_NS::Quad& quad,
165     ArrayOfSMESHNodes& nodesOnQuad,
166     std::vector<double>& xx, std::vector<double>& yy);
167
168   void _searchInitialQuadWay( HEXA_NS::Quad* quad, //IN
169                               HEXA_NS::Vertex*& v0,      //INOUT
170                               HEXA_NS::Vertex*& v1 );    //INOUT
171
172
173   //    ********     DATA FOR MESH COMPUTATION    ********
174   //    NODES
175   std::map<HEXA_NS::Vertex*, SMDS_MeshNode*>        _node;    //_vertexNode;
176   std::map<const SMDS_MeshNode*, HEXA_NS::Vertex*>  _vertex;  //_nodeVertex;
177
178   //    EDGES
179   std::map<HEXA_NS::Edge*, SMESHNodes>  _nodesOnEdge; //_edgeNodes;
180 //   std::map<HEXA_NS::Edge*, Xx>                _edgeXx;
181   std::map<SMDS_MeshNode*, double>  _nodeXx; //_edgeNodes;
182   std::map<HEXA_NS::Quad*, ArrayOfSMESHNodes> _quadNodes;
183
184   bool _computeVertexOK;
185   bool _computeEdgeOK;
186   bool _computeQuadOK;
187
188   SMESHDS_Mesh* _theMeshDS;
189   SMESH_Mesh*   _theMesh;
190
191   //    ********     METHOD FOR GROUPS COMPUTATION    ********
192   SMESH_Group* _createGroup(HEXA_NS::Group& grHex);
193   void _fillGroup(HEXA_NS::Group* grHex);
194
195   //    ********     DATA FOR GROUPS COMPUTATION    ********
196   std::map<HEXA_NS::Hexa*, SMESHVolumes> _volumesOnHexa;
197   std::map<HEXA_NS::Quad*, SMESHFaces>   _facesOnQuad;
198   std::map<HEXA_NS::Edge*, SMESHEdges>   _edgesOnEdge;
199
200
201   // for DEBUG purpose only:
202   int _total;
203   int _found;
204   int _notFound;
205 };
206
207
208 #endif