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