Salome HOME
Implementation of Quadrangle (Mapping) for faces built on 3 edges (0018911 from Mantis).
[modules/smesh.git] / src / StdMeshers / StdMeshers_Hexa_3D.cxx
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 SMESH : implementaion of SMESH idl descriptions
23 //  File   : StdMeshers_Hexa_3D.cxx
24 //           Moved here from SMESH_Hexa_3D.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //
28 #include "StdMeshers_Hexa_3D.hxx"
29 #include "StdMeshers_CompositeHexa_3D.hxx"
30 #include "StdMeshers_FaceSide.hxx"
31 #include "StdMeshers_Penta_3D.hxx"
32 #include "StdMeshers_Prism_3D.hxx"
33 #include "StdMeshers_Quadrangle_2D.hxx"
34
35 #include "SMESH_Gen.hxx"
36 #include "SMESH_Mesh.hxx"
37 #include "SMESH_subMesh.hxx"
38 #include "SMESH_Comment.hxx"
39
40 #include "SMDS_MeshElement.hxx"
41 #include "SMDS_MeshNode.hxx"
42 #include "SMDS_FacePosition.hxx"
43 #include "SMDS_VolumeTool.hxx"
44 #include "SMDS_VolumeOfNodes.hxx"
45
46 #include <TopExp.hxx>
47 #include <TopExp_Explorer.hxx>
48 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
49 #include <TopTools_ListIteratorOfListOfShape.hxx>
50 #include <TopTools_ListOfShape.hxx>
51 #include <TopTools_SequenceOfShape.hxx>
52 #include <TopTools_MapOfShape.hxx>
53 #include <TopoDS.hxx>
54 #include <gp_Pnt2d.hxx>
55
56 #include "utilities.h"
57 #include "Utils_ExceptHandlers.hxx"
58
59 typedef SMESH_Comment TComm;
60
61 using namespace std;
62
63 static SMESH_ComputeErrorPtr ComputePentahedralMesh(SMESH_Mesh &,
64                                                     const TopoDS_Shape &);
65
66 static bool EvaluatePentahedralMesh(SMESH_Mesh &, const TopoDS_Shape &,
67                                     MapShapeNbElems &);
68
69 //=============================================================================
70 /*!
71  *  
72  */
73 //=============================================================================
74
75 StdMeshers_Hexa_3D::StdMeshers_Hexa_3D(int hypId, int studyId, SMESH_Gen * gen)
76   :SMESH_3D_Algo(hypId, studyId, gen)
77 {
78   MESSAGE("StdMeshers_Hexa_3D::StdMeshers_Hexa_3D");
79   _name = "Hexa_3D";
80   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);       // 1 bit /shape type
81 }
82
83 //=============================================================================
84 /*!
85  *  
86  */
87 //=============================================================================
88
89 StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D()
90 {
91   MESSAGE("StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D");
92 }
93
94 //================================================================================
95 /*!
96  * \brief Clear fields and return the argument
97   * \param res - the value to return
98   * \retval bool - the argument value
99  */
100 //================================================================================
101
102 bool StdMeshers_Hexa_3D::ClearAndReturn(FaceQuadStruct* theQuads[6], const bool res)
103 {
104   for (int i = 0; i < 6; i++) {
105     delete theQuads[i];
106     theQuads[i] = NULL;
107   }
108   return res;
109 }
110
111
112 //=============================================================================
113 /*!
114  *  
115  */
116 //=============================================================================
117
118 bool StdMeshers_Hexa_3D::CheckHypothesis
119                          (SMESH_Mesh&                          aMesh,
120                           const TopoDS_Shape&                  aShape,
121                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
122 {
123   // check nb of faces in the shape
124 /*  PAL16229
125   aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
126   int nbFaces = 0;
127   for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next())
128     if ( ++nbFaces > 6 )
129       break;
130   if ( nbFaces != 6 )
131     return false;
132 */
133   aStatus = SMESH_Hypothesis::HYP_OK;
134   return true;
135 }
136
137 //=======================================================================
138 //function : isCloser
139 //purpose  : 
140 //=======================================================================
141
142 inline bool isCloser(const int i, const int j, const int nbhoriz,
143                      const FaceQuadStruct* quad, const gp_Pnt2d uv,
144                      double & minDist)
145 {
146   int ij = j * nbhoriz + i;
147   gp_Pnt2d uv2( quad->uv_grid[ij].u, quad->uv_grid[ij].v );
148   double dist = uv.SquareDistance( uv2 );
149   if ( dist < minDist ) {
150     minDist = dist;
151     return true;
152   }
153   return false;
154 }
155
156 //=======================================================================
157 //function : findIJ
158 //purpose  : return i,j of the node
159 //=======================================================================
160
161 static bool findIJ (const SMDS_MeshNode* node, const FaceQuadStruct * quad, int& I, int& J)
162 {
163   const SMDS_FacePosition* fpos =
164     static_cast<const SMDS_FacePosition*>(node->GetPosition().get());
165   if ( ! fpos ) return false;
166   gp_Pnt2d uv( fpos->GetUParameter(), fpos->GetVParameter() );
167
168   double minDist = DBL_MAX;
169   const int nbhoriz  = quad->side[0]->NbPoints();
170   const int nbvertic = quad->side[1]->NbPoints();
171   I = nbhoriz/2; J = nbvertic/2;
172   int oldI, oldJ;
173   do {
174     oldI = I; oldJ = J;
175     while ( I + 2 < nbhoriz &&  isCloser( I + 1, J, nbhoriz, quad, uv, minDist ))
176       I += 1;
177     if ( I == oldI )
178       while ( I - 1 > 0     &&  isCloser( I - 1, J, nbhoriz, quad, uv, minDist ))
179         I -= 1;
180     if ( minDist < DBL_MIN )
181       break;
182
183     while ( J + 2 < nbvertic && isCloser( I, J + 1, nbhoriz, quad, uv, minDist ))
184       J += 1;
185     if ( J == oldJ )
186       while ( J - 1 > 0      && isCloser( I, J - 1, nbhoriz, quad, uv, minDist ))
187         J -= 1;
188     if ( minDist < DBL_MIN )
189       break;
190
191   } while ( I != oldI || J != oldJ );
192
193   if ( minDist > DBL_MIN ) {
194     for (int i = 1; i < nbhoriz - 1; i++)
195       for (int j = 1; j < nbvertic - 1; j++)
196         if ( isCloser( i, j, nbhoriz, quad, uv, minDist ))
197           I = i, J = j;
198   }
199   return true;
200 }
201
202
203 //=============================================================================
204 /*!
205  * Hexahedron mesh on hexaedron like form
206  * -0.  - shape and face mesh verification
207  * -1.  - identify faces and vertices of the "cube"
208  * -2.  - Algorithm from:
209  * "Application de l'interpolation transfinie Ã  la création de maillages
210  *  C0 ou G1 continus sur des triangles, quadrangles, tetraedres, pentaedres
211  *  et hexaedres déformés."
212  * Alain PERONNET - 8 janvier 1999
213  */
214 //=============================================================================
215
216 bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh &         aMesh,
217                                  const TopoDS_Shape & aShape)// throw(SALOME_Exception)
218 {
219   // PAL14921. Enable catching std::bad_alloc and Standard_OutOfMemory outside
220   //Unexpect aCatch(SalomeException);
221   MESSAGE("StdMeshers_Hexa_3D::Compute");
222   SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
223
224   // 0.  - shape and face mesh verification
225   // 0.1 - shape must be a solid (or a shell) with 6 faces
226
227   vector < SMESH_subMesh * >meshFaces;
228   for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
229     SMESH_subMesh *aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
230     ASSERT(aSubMesh);
231     meshFaces.push_back(aSubMesh);
232   }
233   if (meshFaces.size() != 6) {
234     //return error(COMPERR_BAD_SHAPE, TComm(meshFaces.size())<<" instead of 6 faces in a block");
235     static StdMeshers_CompositeHexa_3D compositeHexa(-10, 0, aMesh.GetGen());
236     if ( !compositeHexa.Compute( aMesh, aShape ))
237       return error( compositeHexa.GetComputeError() );
238     return true;
239   }
240
241   // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
242
243   // tool for working with quadratic elements
244   SMESH_MesherHelper aTool (aMesh);
245   _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
246
247   // cube structure
248   typedef struct cubeStruct
249   {
250     TopoDS_Vertex V000;
251     TopoDS_Vertex V001;
252     TopoDS_Vertex V010;
253     TopoDS_Vertex V011;
254     TopoDS_Vertex V100;
255     TopoDS_Vertex V101;
256     TopoDS_Vertex V110;
257     TopoDS_Vertex V111;
258     faceQuadStruct* quad_X0;
259     faceQuadStruct* quad_X1;
260     faceQuadStruct* quad_Y0;
261     faceQuadStruct* quad_Y1;
262     faceQuadStruct* quad_Z0;
263     faceQuadStruct* quad_Z1;
264     Point3DStruct* np; // normalised 3D coordinates
265   } CubeStruct;
266
267   CubeStruct aCube;
268
269   // bounding faces
270   FaceQuadStruct* aQuads[6];
271   for (int i = 0; i < 6; i++)
272     aQuads[i] = 0;
273
274   for (int i = 0; i < 6; i++)
275   {
276     TopoDS_Shape aFace = meshFaces[i]->GetSubShape();
277     SMESH_Algo *algo = _gen->GetAlgo(aMesh, aFace);
278     string algoName = algo->GetName();
279     bool isAllQuad = false;
280     if (algoName == "Quadrangle_2D") {
281       SMESHDS_SubMesh * sm = meshDS->MeshElements( aFace );
282       if ( sm ) {
283         isAllQuad = true;
284         SMDS_ElemIteratorPtr eIt = sm->GetElements();
285         while ( isAllQuad && eIt->more() ) {
286           const SMDS_MeshElement* elem =  eIt->next();
287           isAllQuad = ( elem->NbNodes()==4 ||(_quadraticMesh && elem->NbNodes()==8) );
288         }
289       }
290     }
291     if ( ! isAllQuad ) {
292       SMESH_ComputeErrorPtr err = ComputePentahedralMesh(aMesh, aShape);
293       return ClearAndReturn( aQuads, error(err));
294     }
295     StdMeshers_Quadrangle_2D *quadAlgo =
296       dynamic_cast < StdMeshers_Quadrangle_2D * >(algo);
297     ASSERT(quadAlgo);
298     try {
299       aQuads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aFace, _quadraticMesh);
300       if(!aQuads[i]) {
301         return error( quadAlgo->GetComputeError());
302       }
303     }
304     catch(SALOME_Exception & S_ex) {
305       return ClearAndReturn( aQuads, error(COMPERR_SLM_EXCEPTION,TComm(S_ex.what()) <<
306                                            " Raised by StdMeshers_Quadrangle_2D "
307                                            " on face #" << meshDS->ShapeToIndex( aFace )));
308     }
309
310     // 0.2.1 - number of points on the opposite edges must be the same
311     if (aQuads[i]->side[0]->NbPoints() != aQuads[i]->side[2]->NbPoints() ||
312         aQuads[i]->side[1]->NbPoints() != aQuads[i]->side[3]->NbPoints()
313         /*aQuads[i]->side[0]->NbEdges() != 1 ||
314         aQuads[i]->side[1]->NbEdges() != 1 ||
315         aQuads[i]->side[2]->NbEdges() != 1 ||
316         aQuads[i]->side[3]->NbEdges() != 1*/) {
317       MESSAGE("different number of points on the opposite edges of face " << i);
318       // Try to go into penta algorithm 'cause it has been improved.
319       SMESH_ComputeErrorPtr err = ComputePentahedralMesh(aMesh, aShape);
320       return ClearAndReturn( aQuads, error(err));
321     }
322   }
323
324   // 1.  - identify faces and vertices of the "cube"
325   // 1.1 - ancestor maps vertex->edges in the cube
326
327 //   TopTools_IndexedDataMapOfShapeListOfShape MS;
328 //   TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
329
330   // 1.2 - first face is choosen as face Y=0 of the unit cube
331
332   const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
333   //const TopoDS_Face & F = TopoDS::Face(aFace);
334
335   // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
336
337   aCube.V000 = aQuads[0]->side[0]->FirstVertex(); // will be (0,0,0) on the unit cube
338   aCube.V100 = aQuads[0]->side[0]->LastVertex();  // will be (1,0,0) on the unit cube
339   aCube.V001 = aQuads[0]->side[2]->FirstVertex(); // will be (0,0,1) on the unit cube
340   aCube.V101 = aQuads[0]->side[2]->LastVertex();  // will be (1,0,1) on the unit cube
341
342   TopTools_IndexedMapOfShape MV0;
343   TopExp::MapShapes(aFace, TopAbs_VERTEX, MV0);
344
345   aCube.V010 = OppositeVertex( aCube.V000, MV0, aQuads);
346   aCube.V110 = OppositeVertex( aCube.V100, MV0, aQuads);
347   aCube.V011 = OppositeVertex( aCube.V001, MV0, aQuads);
348   aCube.V111 = OppositeVertex( aCube.V101, MV0, aQuads);
349
350   // 1.6 - find remaining faces given 4 vertices
351
352   int _indY0 = 0;
353   int _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
354                             aCube.V010, aCube.V011, aCube.V110, aCube.V111);
355   int _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
356                             aCube.V000, aCube.V010, aCube.V100, aCube.V110);
357   int _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
358                             aCube.V001, aCube.V011, aCube.V101, aCube.V111);
359   int _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
360                             aCube.V000, aCube.V001, aCube.V010, aCube.V011);
361   int _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
362                             aCube.V100, aCube.V101, aCube.V110, aCube.V111);
363
364   // IPAL21120: SIGSEGV on Meshing attached Compound with Automatic Hexadralization
365   if ( _indY1 < 1 || _indZ0 < 1 || _indZ1 < 1 || _indX0 < 1 || _indX1 < 1 )
366     return error(COMPERR_BAD_SHAPE);
367
368   aCube.quad_Y0 = aQuads[_indY0];
369   aCube.quad_Y1 = aQuads[_indY1];
370   aCube.quad_Z0 = aQuads[_indZ0];
371   aCube.quad_Z1 = aQuads[_indZ1];
372   aCube.quad_X0 = aQuads[_indX0];
373   aCube.quad_X1 = aQuads[_indX1];
374
375   // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
376
377   Conv2DStruct cx0;                     // for face X=0
378   Conv2DStruct cx1;                     // for face X=1
379   Conv2DStruct cy0;
380   Conv2DStruct cy1;
381   Conv2DStruct cz0;
382   Conv2DStruct cz1;
383
384   GetConv2DCoefs(*aCube.quad_X0, meshFaces[_indX0]->GetSubShape(),
385                  aCube.V000, aCube.V010, aCube.V011, aCube.V001, cx0);
386   GetConv2DCoefs(*aCube.quad_X1, meshFaces[_indX1]->GetSubShape(),
387                  aCube.V100, aCube.V110, aCube.V111, aCube.V101, cx1);
388   GetConv2DCoefs(*aCube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
389                  aCube.V000, aCube.V100, aCube.V101, aCube.V001, cy0);
390   GetConv2DCoefs(*aCube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
391                  aCube.V010, aCube.V110, aCube.V111, aCube.V011, cy1);
392   GetConv2DCoefs(*aCube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
393                  aCube.V000, aCube.V100, aCube.V110, aCube.V010, cz0);
394   GetConv2DCoefs(*aCube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
395                  aCube.V001, aCube.V101, aCube.V111, aCube.V011, cz1);
396
397   // 1.8 - create a 3D structure for normalized values
398   
399   int nbx = aCube.quad_Z0->side[0]->NbPoints();
400   if (cz0.a1 == 0.) nbx = aCube.quad_Z0->side[1]->NbPoints();
401  
402   int nby = aCube.quad_X0->side[0]->NbPoints();
403   if (cx0.a1 == 0.) nby = aCube.quad_X0->side[1]->NbPoints();
404  
405   int nbz = aCube.quad_Y0->side[0]->NbPoints();
406   if (cy0.a1 != 0.) nbz = aCube.quad_Y0->side[1]->NbPoints();
407
408   int i1, j1, nbxyz = nbx * nby * nbz;
409   Point3DStruct *np = new Point3DStruct[nbxyz];
410
411   // 1.9 - store node indexes of faces
412
413   {
414     const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
415
416     faceQuadStruct *quad = aCube.quad_X0;
417     int i = 0;                          // j = x/face , k = y/face
418     int nbdown = quad->side[0]->NbPoints();
419     int nbright = quad->side[1]->NbPoints();
420
421     SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
422                         
423     while(itf->more()) {
424       const SMDS_MeshNode * node = itf->next();
425       if(aTool.IsMedium(node))
426         continue;
427       if ( !findIJ( node, quad, i1, j1 ))
428         return ClearAndReturn( aQuads, false );
429       int ij1 = j1 * nbdown + i1;
430       quad->uv_grid[ij1].node = node;
431     }
432
433     for (int i1 = 0; i1 < nbdown; i1++)
434       for (int j1 = 0; j1 < nbright; j1++) {
435         int ij1 = j1 * nbdown + i1;
436         int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic;     // j = x/face
437         int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc;     // k = y/face
438         int ijk = k * nbx * nby + j * nbx + i;
439         //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
440         np[ijk].node = quad->uv_grid[ij1].node;
441         //SCRUTE(np[ijk].nodeId);
442       }
443   }
444
445   {
446     const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
447
448     SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
449
450     faceQuadStruct *quad = aCube.quad_X1;
451     int i = nbx - 1;            // j = x/face , k = y/face
452     int nbdown = quad->side[0]->NbPoints();
453     int nbright = quad->side[1]->NbPoints();
454
455     while(itf->more()) {
456       const SMDS_MeshNode * node = itf->next();
457       if(aTool.IsMedium(node))
458         continue;
459       if ( !findIJ( node, quad, i1, j1 ))
460         return ClearAndReturn( aQuads, false );
461       int ij1 = j1 * nbdown + i1;
462       quad->uv_grid[ij1].node = node;
463     }
464
465     for (int i1 = 0; i1 < nbdown; i1++)
466       for (int j1 = 0; j1 < nbright; j1++) {
467         int ij1 = j1 * nbdown + i1;
468         int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic;     // j = x/face
469         int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc;     // k = y/face
470         int ijk = k * nbx * nby + j * nbx + i;
471         //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
472         np[ijk].node = quad->uv_grid[ij1].node;
473         //SCRUTE(np[ijk].nodeId);
474       }
475   }
476
477   {
478     const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
479
480     SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
481
482     faceQuadStruct *quad = aCube.quad_Y0;
483     int j = 0;                          // i = x/face , k = y/face
484     int nbdown = quad->side[0]->NbPoints();
485     int nbright = quad->side[1]->NbPoints();
486
487     while(itf->more()) {
488       const SMDS_MeshNode * node = itf->next();
489       if(aTool.IsMedium(node))
490         continue;
491       if ( !findIJ( node, quad, i1, j1 ))
492         return ClearAndReturn( aQuads, false );
493       int ij1 = j1 * nbdown + i1;
494       quad->uv_grid[ij1].node = node;
495     }
496
497     for (int i1 = 0; i1 < nbdown; i1++)
498       for (int j1 = 0; j1 < nbright; j1++) {
499         int ij1 = j1 * nbdown + i1;
500         int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic;     // i = x/face
501         int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc;     // k = y/face
502         int ijk = k * nbx * nby + j * nbx + i;
503         //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
504         np[ijk].node = quad->uv_grid[ij1].node;
505         //SCRUTE(np[ijk].nodeId);
506       }
507   }
508
509   {
510     const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
511
512     SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
513
514     faceQuadStruct *quad = aCube.quad_Y1;
515     int j = nby - 1;            // i = x/face , k = y/face
516     int nbdown = quad->side[0]->NbPoints();
517     int nbright = quad->side[1]->NbPoints();
518
519     while(itf->more()) {
520       const SMDS_MeshNode * node = itf->next();
521       if(aTool.IsMedium(node))
522         continue;
523       if ( !findIJ( node, quad, i1, j1 ))
524         return ClearAndReturn( aQuads, false );
525       int ij1 = j1 * nbdown + i1;
526       quad->uv_grid[ij1].node = node;
527     }
528
529     for (int i1 = 0; i1 < nbdown; i1++)
530       for (int j1 = 0; j1 < nbright; j1++) {
531         int ij1 = j1 * nbdown + i1;
532         int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic;     // i = x/face
533         int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc;     // k = y/face
534         int ijk = k * nbx * nby + j * nbx + i;
535         //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
536         np[ijk].node = quad->uv_grid[ij1].node;
537         //SCRUTE(np[ijk].nodeId);
538       }
539   }
540
541   {
542     const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
543
544     SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
545
546     faceQuadStruct *quad = aCube.quad_Z0;
547     int k = 0;                          // i = x/face , j = y/face
548     int nbdown = quad->side[0]->NbPoints();
549     int nbright = quad->side[1]->NbPoints();
550
551     while(itf->more()) {
552       const SMDS_MeshNode * node = itf->next();
553       if(aTool.IsMedium(node))
554         continue;
555       if ( !findIJ( node, quad, i1, j1 ))
556         return ClearAndReturn( aQuads, false );
557       int ij1 = j1 * nbdown + i1;
558       quad->uv_grid[ij1].node = node;
559     }
560
561     for (int i1 = 0; i1 < nbdown; i1++)
562       for (int j1 = 0; j1 < nbright; j1++) {
563         int ij1 = j1 * nbdown + i1;
564         int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic;     // i = x/face
565         int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc;     // j = y/face
566         int ijk = k * nbx * nby + j * nbx + i;
567         //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
568         np[ijk].node = quad->uv_grid[ij1].node;
569         //SCRUTE(np[ijk].nodeId);
570       }
571   }
572
573   {
574     const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
575
576     SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
577
578     faceQuadStruct *quad = aCube.quad_Z1;
579     int k = nbz - 1;            // i = x/face , j = y/face
580     int nbdown = quad->side[0]->NbPoints();
581     int nbright = quad->side[1]->NbPoints();
582     
583     while(itf->more()) {
584       const SMDS_MeshNode * node = itf->next();
585       if(aTool.IsMedium(node))
586         continue;
587       if ( !findIJ( node, quad, i1, j1 ))
588         return ClearAndReturn( aQuads, false );
589       int ij1 = j1 * nbdown + i1;
590       quad->uv_grid[ij1].node = node;
591     }
592
593     for (int i1 = 0; i1 < nbdown; i1++)
594       for (int j1 = 0; j1 < nbright; j1++) {
595         int ij1 = j1 * nbdown + i1;
596         int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic;     // i = x/face
597         int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc;     // j = y/face
598         int ijk = k * nbx * nby + j * nbx + i;
599         //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
600         np[ijk].node = quad->uv_grid[ij1].node;
601         //SCRUTE(np[ijk].nodeId);
602       }
603   }
604
605   // 2.0 - for each node of the cube:
606   //       - get the 8 points 3D = 8 vertices of the cube
607   //       - get the 12 points 3D on the 12 edges of the cube
608   //       - get the 6 points 3D on the 6 faces with their ID
609   //       - compute the point 3D
610   //       - store the point 3D in SMESHDS, store its ID in 3D structure
611
612   int shapeID = meshDS->ShapeToIndex( aShape );
613
614   Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
615   Pt3 px00, px01, px10, px11;
616   Pt3 p0y0, p0y1, p1y0, p1y1;
617   Pt3 p00z, p01z, p10z, p11z;
618   Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
619
620   GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
621   GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
622   GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
623   GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
624   GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
625   GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
626   GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
627   GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
628
629   for (int i = 1; i < nbx - 1; i++) {
630     for (int j = 1; j < nby - 1; j++) {
631       for (int k = 1; k < nbz - 1; k++) {
632         // *** seulement maillage regulier
633         // 12 points on edges
634         GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
635         GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
636         GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
637         GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
638
639         GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
640         GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
641         GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
642         GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
643
644         GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
645         GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
646         GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
647         GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
648
649         // 12 points on faces
650         GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
651         GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
652         GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
653         GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
654         GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
655         GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
656
657         int ijk = k * nbx * nby + j * nbx + i;
658         double x = double (i) / double (nbx - 1);       // *** seulement
659         double y = double (j) / double (nby - 1);       // *** maillage
660         double z = double (k) / double (nbz - 1);       // *** regulier
661
662         Pt3 X;
663         for (int i = 0; i < 3; i++) {
664           X[i] = (1 - x) * p0yz[i] + x * p1yz[i]
665                  + (1 - y) * px0z[i] + y * px1z[i]
666                  + (1 - z) * pxy0[i] + z * pxy1[i]
667                  - (1 - x) * ((1 - y) * p00z[i] + y * p01z[i])
668                  - x * ((1 - y) * p10z[i] + y * p11z[i])
669                  - (1 - y) * ((1 - z) * px00[i] + z * px01[i])
670                  - y * ((1 - z) * px10[i] + z * px11[i])
671                  - (1 - z) * ((1 - x) * p0y0[i] + x * p1y0[i])
672                  - z * ((1 - x) * p0y1[i] + x * p1y1[i])
673                  + (1 - x) * ((1 - y) * ((1 - z) * p000[i] + z * p001[i])
674                  + y * ((1 - z) * p010[i] + z * p011[i]))
675                  + x * ((1 - y) * ((1 - z) * p100[i] + z * p101[i])
676                  + y * ((1 - z) * p110[i] + z * p111[i]));
677         }
678
679         SMDS_MeshNode * node = meshDS->AddNode(X[0], X[1], X[2]);
680         np[ijk].node = node;
681         meshDS->SetNodeInVolume(node, shapeID);
682       }
683     }
684   }
685
686   // find orientation of furute volumes according to MED convention
687   vector< bool > forward( nbx * nby );
688   SMDS_VolumeTool vTool;
689   for (int i = 0; i < nbx - 1; i++) {
690     for (int j = 0; j < nby - 1; j++) {
691       int n1 = j * nbx + i;
692       int n2 = j * nbx + i + 1;
693       int n3 = (j + 1) * nbx + i + 1;
694       int n4 = (j + 1) * nbx + i;
695       int n5 = nbx * nby + j * nbx + i;
696       int n6 = nbx * nby + j * nbx + i + 1;
697       int n7 = nbx * nby + (j + 1) * nbx + i + 1;
698       int n8 = nbx * nby + (j + 1) * nbx + i;
699
700       SMDS_VolumeOfNodes tmpVol (np[n1].node,np[n2].node,np[n3].node,np[n4].node,
701                                  np[n5].node,np[n6].node,np[n7].node,np[n8].node);
702       vTool.Set( &tmpVol );
703       forward[ n1 ] = vTool.IsForward();
704     }
705   }
706
707   //2.1 - for each node of the cube (less 3 *1 Faces):
708   //      - store hexahedron in SMESHDS
709   MESSAGE("Storing hexahedron into the DS");
710   for (int i = 0; i < nbx - 1; i++) {
711     for (int j = 0; j < nby - 1; j++) {
712       bool isForw = forward.at( j * nbx + i );
713       for (int k = 0; k < nbz - 1; k++) {
714         int n1 = k * nbx * nby + j * nbx + i;
715         int n2 = k * nbx * nby + j * nbx + i + 1;
716         int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
717         int n4 = k * nbx * nby + (j + 1) * nbx + i;
718         int n5 = (k + 1) * nbx * nby + j * nbx + i;
719         int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
720         int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
721         int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
722
723         SMDS_MeshVolume * elt;
724         if ( isForw ) {
725           elt = aTool.AddVolume(np[n1].node, np[n2].node,
726                                 np[n3].node, np[n4].node,
727                                 np[n5].node, np[n6].node,
728                                 np[n7].node, np[n8].node);
729         }
730         else {
731           elt = aTool.AddVolume(np[n1].node, np[n4].node,
732                                 np[n3].node, np[n2].node,
733                                 np[n5].node, np[n8].node,
734                                 np[n7].node, np[n6].node);
735         }
736         
737         meshDS->SetMeshElementOnShape(elt, shapeID);
738       }
739     }
740   }
741   if ( np ) delete [] np;
742   return ClearAndReturn( aQuads, true );
743 }
744
745
746 //=============================================================================
747 /*!
748  *  Evaluate
749  */
750 //=============================================================================
751
752 bool StdMeshers_Hexa_3D::Evaluate(SMESH_Mesh & aMesh,
753                                   const TopoDS_Shape & aShape,
754                                   MapShapeNbElems& aResMap)
755 {
756   vector < SMESH_subMesh * >meshFaces;
757   TopTools_SequenceOfShape aFaces;
758   for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
759     aFaces.Append(exp.Current());
760     SMESH_subMesh *aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
761     ASSERT(aSubMesh);
762     meshFaces.push_back(aSubMesh);
763   }
764   if (meshFaces.size() != 6) {
765     //return error(COMPERR_BAD_SHAPE, TComm(meshFaces.size())<<" instead of 6 faces in a block");
766     static StdMeshers_CompositeHexa_3D compositeHexa(-10, 0, aMesh.GetGen());
767     return compositeHexa.Evaluate(aMesh, aShape, aResMap);
768   }
769   
770   int i = 0;
771   for(; i<6; i++) {
772     //TopoDS_Shape aFace = meshFaces[i]->GetSubShape();
773     TopoDS_Shape aFace = aFaces.Value(i+1);
774     SMESH_Algo *algo = _gen->GetAlgo(aMesh, aFace);
775     string algoName = algo->GetName();
776     bool isAllQuad = false;
777     if (algoName == "Quadrangle_2D") {
778       MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i]);
779       if( anIt == aResMap.end() ) continue;
780       std::vector<int> aVec = (*anIt).second;
781       int nbtri = Max(aVec[3],aVec[4]);
782       if( nbtri == 0 )
783         isAllQuad = true;
784     }
785     if ( ! isAllQuad ) {
786       return EvaluatePentahedralMesh(aMesh, aShape, aResMap);
787     }
788   }
789   
790   // find number of 1d elems for 1 face
791   int nb1d = 0;
792   TopTools_MapOfShape Edges1;
793   bool IsQuadratic = false;
794   bool IsFirst = true;
795   for (TopExp_Explorer exp(aFaces.Value(1), TopAbs_EDGE); exp.More(); exp.Next()) {
796     Edges1.Add(exp.Current());
797     SMESH_subMesh *sm = aMesh.GetSubMesh(exp.Current());
798     if( sm ) {
799       MapShapeNbElemsItr anIt = aResMap.find(sm);
800       if( anIt == aResMap.end() ) continue;
801       std::vector<int> aVec = (*anIt).second;
802       nb1d += Max(aVec[1],aVec[2]);
803       if(IsFirst) {
804         IsQuadratic = (aVec[2] > aVec[1]);
805         IsFirst = false;
806       }
807     }
808   }
809   // find face opposite to 1 face
810   int OppNum = 0;
811   for(i=2; i<=6; i++) {
812     bool IsOpposite = true;
813     for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
814       if( Edges1.Contains(exp.Current()) ) {
815         IsOpposite = false;
816         break;
817       }
818     }
819     if(IsOpposite) {
820       OppNum = i;
821       break;
822     }
823   }
824   // find number of 2d elems on side faces
825   int nb2d = 0;
826   for(i=2; i<=6; i++) {
827     if( i == OppNum ) continue;
828     MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
829     if( anIt == aResMap.end() ) continue;
830     std::vector<int> aVec = (*anIt).second;
831     nb2d += Max(aVec[5],aVec[6]);
832   }
833   
834   MapShapeNbElemsItr anIt = aResMap.find( meshFaces[0] );
835   std::vector<int> aVec = (*anIt).second;
836   int nb2d_face0 = Max(aVec[5],aVec[6]);
837   int nb0d_face0 = aVec[0];
838
839   std::vector<int> aResVec(17);
840   for(int i=0; i<17; i++) aResVec[i] = 0;
841   if(IsQuadratic) {
842     aResVec[15] = nb2d_face0 * ( nb2d/nb1d );
843     int nb1d_face0_int = ( nb2d_face0*4 - nb1d ) / 2;
844     aResVec[0] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
845   }
846   else {
847     aResVec[0] = nb0d_face0 * ( nb2d/nb1d - 1 );
848     aResVec[14] = nb2d_face0 * ( nb2d/nb1d );
849   }
850   SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
851   aResMap.insert(std::make_pair(sm,aResVec));
852
853   return true;
854 }
855
856
857 //=============================================================================
858 /*!
859  *  
860  */
861 //=============================================================================
862
863 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby, int nbz,
864                                   Point3DStruct * np, const SMESHDS_Mesh * meshDS)
865 {
866         int ijk = k * nbx * nby + j * nbx + i;
867         const SMDS_MeshNode * node = np[ijk].node;
868         p[0] = node->X();
869         p[1] = node->Y();
870         p[2] = node->Z();
871         //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
872 }
873
874 //=============================================================================
875 /*!
876  *  
877  */
878 //=============================================================================
879
880 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
881         const TopoDS_Shape & aShape,
882         const vector < SMESH_subMesh * >&meshFaces,
883         const TopoDS_Vertex & V0,
884         const TopoDS_Vertex & V1,
885         const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
886 {
887         //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
888         int faceIndex = -1;
889         for (int i = 1; i < 6; i++)
890         {
891                 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
892                 //const TopoDS_Face& F = TopoDS::Face(aFace);
893                 TopTools_IndexedMapOfShape M;
894                 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
895                 bool verticesInShape = false;
896                 if (M.Contains(V0))
897                         if (M.Contains(V1))
898                                 if (M.Contains(V2))
899                                         if (M.Contains(V3))
900                                                 verticesInShape = true;
901                 if (verticesInShape)
902                 {
903                         faceIndex = i;
904                         break;
905                 }
906         }
907         //IPAL21120 ASSERT(faceIndex > 0);
908         //SCRUTE(faceIndex);
909         return faceIndex;
910 }
911
912 //=============================================================================
913 /*!
914  *  
915  */
916 //=============================================================================
917
918 TopoDS_Edge
919         StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
920         const TopoDS_Shape & aShape,
921         const TopoDS_Face & aFace,
922         const TopoDS_Vertex & aVertex,
923         const TopTools_IndexedDataMapOfShapeListOfShape & MS)
924 {
925         //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
926         TopTools_IndexedDataMapOfShapeListOfShape MF;
927         TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
928         const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
929         const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
930 //      SCRUTE(ancestorsInSolid.Extent());
931 //      SCRUTE(ancestorsInFace.Extent());
932         ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
933         ASSERT(ancestorsInFace.Extent() == 2);
934
935         TopoDS_Edge E;
936         E.Nullify();
937         TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
938         for (; its.More(); its.Next())
939         {
940                 TopoDS_Shape ancestor = its.Value();
941                 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
942                 bool isInFace = false;
943                 for (; itf.More(); itf.Next())
944                 {
945                         TopoDS_Shape ancestorInFace = itf.Value();
946                         if (ancestorInFace.IsSame(ancestor))
947                         {
948                                 isInFace = true;
949                                 break;
950                         }
951                 }
952                 if (!isInFace)
953                 {
954                         E = TopoDS::Edge(ancestor);
955                         break;
956                 }
957         }
958         return E;
959 }
960
961 //=============================================================================
962 /*!
963  *  
964  */
965 //=============================================================================
966
967 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
968         const TopoDS_Shape & aShape,
969         const TopoDS_Vertex & V0,
970         const TopoDS_Vertex & V1,
971         const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
972 {
973 //      MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
974 //      const TopoDS_Face & F = TopoDS::Face(aShape);
975 //      TopoDS_Edge E = quad.edge[0];
976 //      double f, l;
977 //      Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
978 //      TopoDS_Vertex VFirst, VLast;
979 //      TopExp::Vertices(E, VFirst, VLast);     // corresponds to f and l
980 //      bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
981   TopoDS_Vertex VA, VB;
982 //      if (isForward)
983 //      {
984 //              VA = VFirst;
985 //              VB = VLast;
986 //      }
987 //      else
988 //      {
989 //              VA = VLast;
990 //              VB = VFirst;
991 //      }
992   VA = quad.side[0]->FirstVertex();
993   VB = quad.side[0]->LastVertex();
994   
995         int a1, b1, c1, a2, b2, c2;
996         if (VA.IsSame(V0))
997                 if (VB.IsSame(V1))
998                 {
999                         a1 = 1;
1000                         b1 = 0;
1001                         c1 = 0;                         // x
1002                         a2 = 0;
1003                         b2 = 1;
1004                         c2 = 0;                         // y
1005                 }
1006                 else
1007                 {
1008                         ASSERT(VB.IsSame(V3));
1009                         a1 = 0;
1010                         b1 = 1;
1011                         c1 = 0;                         // y
1012                         a2 = 1;
1013                         b2 = 0;
1014                         c2 = 0;                         // x
1015                 }
1016         if (VA.IsSame(V1))
1017                 if (VB.IsSame(V2))
1018                 {
1019                         a1 = 0;
1020                         b1 = -1;
1021                         c1 = 1;                         // 1-y
1022                         a2 = 1;
1023                         b2 = 0;
1024                         c2 = 0;                         // x
1025                 }
1026                 else
1027                 {
1028                         ASSERT(VB.IsSame(V0));
1029                         a1 = -1;
1030                         b1 = 0;
1031                         c1 = 1;                         // 1-x
1032                         a2 = 0;
1033                         b2 = 1;
1034                         c2 = 0;                         // y
1035                 }
1036         if (VA.IsSame(V2))
1037                 if (VB.IsSame(V3))
1038                 {
1039                         a1 = -1;
1040                         b1 = 0;
1041                         c1 = 1;                         // 1-x
1042                         a2 = 0;
1043                         b2 = -1;
1044                         c2 = 1;                         // 1-y
1045                 }
1046                 else
1047                 {
1048                         ASSERT(VB.IsSame(V1));
1049                         a1 = 0;
1050                         b1 = -1;
1051                         c1 = 1;                         // 1-y
1052                         a2 = -1;
1053                         b2 = 0;
1054                         c2 = 1;                         // 1-x
1055                 }
1056         if (VA.IsSame(V3))
1057                 if (VB.IsSame(V0))
1058                 {
1059                         a1 = 0;
1060                         b1 = 1;
1061                         c1 = 0;                         // y
1062                         a2 = -1;
1063                         b2 = 0;
1064                         c2 = 1;                         // 1-x
1065                 }
1066                 else
1067                 {
1068                         ASSERT(VB.IsSame(V2));
1069                         a1 = 1;
1070                         b1 = 0;
1071                         c1 = 0;                         // x
1072                         a2 = 0;
1073                         b2 = -1;
1074                         c2 = 1;                         // 1-y
1075                 }
1076 //      MESSAGE("X = " << c1 << "+ " << a1 << "*x + " << b1 << "*y");
1077 //      MESSAGE("Y = " << c2 << "+ " << a2 << "*x + " << b2 << "*y");
1078         conv.a1 = a1;
1079         conv.b1 = b1;
1080         conv.c1 = c1;
1081         conv.a2 = a2;
1082         conv.b2 = b2;
1083         conv.c2 = c2;
1084
1085         int nbdown = quad.side[0]->NbPoints();
1086         int nbright = quad.side[1]->NbPoints();
1087         conv.ia = int (a1);
1088         conv.ib = int (b1);
1089         conv.ic =
1090                 int (c1 * a1 * a1) * (nbdown - 1) + int (c1 * b1 * b1) * (nbright - 1);
1091         conv.ja = int (a2);
1092         conv.jb = int (b2);
1093         conv.jc =
1094                 int (c2 * a2 * a2) * (nbdown - 1) + int (c2 * b2 * b2) * (nbright - 1);
1095 //      MESSAGE("I " << conv.ia << " " << conv.ib << " " << conv.ic);
1096 //      MESSAGE("J " << conv.ja << " " << conv.jb << " " << conv.jc);
1097 }
1098
1099 //================================================================================
1100 /*!
1101  * \brief Find a vertex opposite to the given vertex of aQuads[0]
1102   * \param aVertex - the vertex
1103   * \param aFace - the face aVertex belongs to
1104   * \param aQuads - quads
1105   * \retval TopoDS_Vertex - found vertex
1106  */
1107 //================================================================================
1108
1109 TopoDS_Vertex StdMeshers_Hexa_3D::OppositeVertex(const TopoDS_Vertex& aVertex,
1110                                                  const TopTools_IndexedMapOfShape& aQuads0Vertices,
1111                                                  FaceQuadStruct* aQuads[6])
1112 {
1113   int i, j;
1114   for ( i = 1; i < 6; ++i )
1115   {
1116     TopoDS_Vertex VV[] = { aQuads[i]->side[0]->FirstVertex(),
1117                            aQuads[i]->side[0]->LastVertex() , 
1118                            aQuads[i]->side[2]->LastVertex() ,
1119                            aQuads[i]->side[2]->FirstVertex() };
1120     for ( j = 0; j < 4; ++j )
1121       if ( aVertex.IsSame( VV[ j ]))
1122         break;
1123     if ( j < 4 ) {
1124       int jPrev = j ? j - 1 : 3;
1125       int jNext = (j + 1) % 4;
1126       if ( aQuads0Vertices.Contains( VV[ jPrev ] ))
1127         return VV[ jNext ];
1128       else
1129         return VV[ jPrev ];
1130     }
1131   }
1132   return TopoDS_Vertex();
1133 }
1134
1135 //modified by NIZNHY-PKV Wed Nov 17 15:34:13 2004 f
1136 ///////////////////////////////////////////////////////////////////////////////
1137 //ZZ
1138 //#include <stdio.h>
1139
1140 //=======================================================================
1141 //function : ComputePentahedralMesh
1142 //purpose  : 
1143 //=======================================================================
1144
1145 SMESH_ComputeErrorPtr ComputePentahedralMesh(SMESH_Mesh &         aMesh,
1146                                              const TopoDS_Shape & aShape)
1147 {
1148   //printf(" ComputePentahedralMesh HERE\n");
1149   //
1150   bool bOK;
1151   SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1152   //int iErr;
1153   StdMeshers_Penta_3D anAlgo;
1154   //
1155   bOK=anAlgo.Compute(aMesh, aShape);
1156   //
1157   err = anAlgo.GetComputeError();
1158   //
1159   if ( !bOK && anAlgo.ErrorStatus() == 5 )
1160   {
1161     static StdMeshers_Prism_3D * aPrism3D = 0;
1162     if ( !aPrism3D ) {
1163       SMESH_Gen* gen = aMesh.GetGen();
1164       aPrism3D = new StdMeshers_Prism_3D( gen->GetANewId(), 0, gen );
1165     }
1166     SMESH_Hypothesis::Hypothesis_Status aStatus;
1167     if ( aPrism3D->CheckHypothesis( aMesh, aShape, aStatus ) ) {
1168       aPrism3D->InitComputeError();
1169       bOK = aPrism3D->Compute( aMesh, aShape );
1170       err = aPrism3D->GetComputeError();
1171     }
1172   }
1173   return err;
1174 }
1175
1176
1177 //=======================================================================
1178 //function : EvaluatePentahedralMesh
1179 //purpose  : 
1180 //=======================================================================
1181
1182 bool EvaluatePentahedralMesh(SMESH_Mesh & aMesh,
1183                              const TopoDS_Shape & aShape,
1184                              MapShapeNbElems& aResMap)
1185 {
1186   StdMeshers_Penta_3D anAlgo;
1187   bool bOK = anAlgo.Evaluate(aMesh, aShape, aResMap);
1188
1189   //err = anAlgo.GetComputeError();
1190   //if ( !bOK && anAlgo.ErrorStatus() == 5 )
1191   if( !bOK ) {
1192     static StdMeshers_Prism_3D * aPrism3D = 0;
1193     if ( !aPrism3D ) {
1194       SMESH_Gen* gen = aMesh.GetGen();
1195       aPrism3D = new StdMeshers_Prism_3D( gen->GetANewId(), 0, gen );
1196     }
1197     SMESH_Hypothesis::Hypothesis_Status aStatus;
1198     if ( aPrism3D->CheckHypothesis( aMesh, aShape, aStatus ) ) {
1199       return aPrism3D->Evaluate(aMesh, aShape, aResMap);
1200     }
1201   }
1202
1203   return bOK;
1204 }
1205
1206