1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : StdMeshers_Hexa_3D.cxx
25 // Moved here from SMESH_Hexa_3D.cxx
26 // Author : Paul RASCLE, EDF
30 #include "StdMeshers_Hexa_3D.hxx"
31 #include "StdMeshers_Quadrangle_2D.hxx"
32 #include "StdMeshers_FaceSide.hxx"
33 #include "StdMeshers_Penta_3D.hxx"
34 #include "StdMeshers_Prism_3D.hxx"
36 #include "SMESH_Gen.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_subMesh.hxx"
39 #include "SMESH_Comment.hxx"
41 #include "SMDS_MeshElement.hxx"
42 #include "SMDS_MeshNode.hxx"
43 #include "SMDS_FacePosition.hxx"
44 #include "SMDS_VolumeTool.hxx"
45 #include "SMDS_VolumeOfNodes.hxx"
48 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
49 #include <TopTools_ListOfShape.hxx>
50 #include <TopTools_ListIteratorOfListOfShape.hxx>
51 #include <TColStd_MapOfInteger.hxx>
53 #include <BRep_Tool.hxx>
54 #include <Geom_Surface.hxx>
55 #include <gp_Pnt2d.hxx>
57 #include "utilities.h"
58 #include "Utils_ExceptHandlers.hxx"
60 typedef SMESH_Comment TComm;
64 static SMESH_ComputeErrorPtr ComputePentahedralMesh(SMESH_Mesh &, const TopoDS_Shape &);
66 //=============================================================================
70 //=============================================================================
72 StdMeshers_Hexa_3D::StdMeshers_Hexa_3D(int hypId, int studyId, SMESH_Gen * gen)
73 :SMESH_3D_Algo(hypId, studyId, gen)
75 MESSAGE("StdMeshers_Hexa_3D::StdMeshers_Hexa_3D");
77 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
80 //=============================================================================
84 //=============================================================================
86 StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D()
88 MESSAGE("StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D");
91 //================================================================================
93 * \brief Clear fields and return the argument
94 * \param res - the value to return
95 * \retval bool - the argument value
97 //================================================================================
99 bool StdMeshers_Hexa_3D::ClearAndReturn(FaceQuadStruct* theQuads[6], const bool res)
101 for (int i = 0; i < 6; i++) {
109 //=============================================================================
113 //=============================================================================
115 bool StdMeshers_Hexa_3D::CheckHypothesis
117 const TopoDS_Shape& aShape,
118 SMESH_Hypothesis::Hypothesis_Status& aStatus)
120 // check nb of faces in the shape
121 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
123 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next())
129 aStatus = SMESH_Hypothesis::HYP_OK;
133 //=======================================================================
135 //purpose : return i,j of the node
136 //=======================================================================
138 static bool findIJ (const SMDS_MeshNode* node, const FaceQuadStruct * quad, int& I, int& J)
141 const SMDS_FacePosition* fpos =
142 static_cast<const SMDS_FacePosition*>(node->GetPosition().get());
143 if ( ! fpos ) return false;
144 gp_Pnt2d uv( fpos->GetUParameter(), fpos->GetVParameter() );
146 double minDist = DBL_MAX;
147 int nbhoriz = Min(quad->side[0]->NbPoints(), quad->side[2]->NbPoints());
148 int nbvertic = Min(quad->side[1]->NbPoints(), quad->side[3]->NbPoints());
149 for (int i = 1; i < nbhoriz - 1; i++) {
150 for (int j = 1; j < nbvertic - 1; j++) {
151 int ij = j * nbhoriz + i;
152 gp_Pnt2d uv2( quad->uv_grid[ij].u, quad->uv_grid[ij].v );
153 double dist = uv.SquareDistance( uv2 );
154 if ( dist < minDist ) {
165 //=============================================================================
167 * Hexahedron mesh on hexaedron like form
168 * -0. - shape and face mesh verification
169 * -1. - identify faces and vertices of the "cube"
170 * -2. - Algorithm from:
171 * "Application de l'interpolation transfinie à la création de maillages
172 * C0 ou G1 continus sur des triangles, quadrangles, tetraedres, pentaedres
173 * et hexaedres déformés."
174 * Alain PERONNET - 8 janvier 1999
176 //=============================================================================
178 bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh & aMesh,
179 const TopoDS_Shape & aShape)// throw(SALOME_Exception)
181 // PAL14921. Enable catching std::bad_alloc and Standard_OutOfMemory outside
182 //Unexpect aCatch(SalomeException);
183 MESSAGE("StdMeshers_Hexa_3D::Compute");
184 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
186 // 0. - shape and face mesh verification
187 // 0.1 - shape must be a solid (or a shell) with 6 faces
189 vector < SMESH_subMesh * >meshFaces;
190 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
191 SMESH_subMesh *aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
193 meshFaces.push_back(aSubMesh);
195 if (meshFaces.size() != 6)
196 return error(COMPERR_BAD_SHAPE, TComm(meshFaces.size())<<" instead of 6 faces in block");
198 // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
200 // tool for working with quadratic elements
201 SMESH_MesherHelper aTool (aMesh);
202 _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
205 typedef struct cubeStruct
215 faceQuadStruct* quad_X0;
216 faceQuadStruct* quad_X1;
217 faceQuadStruct* quad_Y0;
218 faceQuadStruct* quad_Y1;
219 faceQuadStruct* quad_Z0;
220 faceQuadStruct* quad_Z1;
221 Point3DStruct* np; // normalised 3D coordinates
227 FaceQuadStruct* aQuads[6];
228 for (int i = 0; i < 6; i++)
231 for (int i = 0; i < 6; i++)
233 TopoDS_Shape aFace = meshFaces[i]->GetSubShape();
234 SMESH_Algo *algo = _gen->GetAlgo(aMesh, aFace);
235 string algoName = algo->GetName();
236 bool isAllQuad = false;
237 if (algoName == "Quadrangle_2D") {
238 SMESHDS_SubMesh * sm = meshDS->MeshElements( aFace );
241 SMDS_ElemIteratorPtr eIt = sm->GetElements();
242 while ( isAllQuad && eIt->more() ) {
243 const SMDS_MeshElement* elem = eIt->next();
244 isAllQuad = ( elem->NbNodes()==4 ||(_quadraticMesh && elem->NbNodes()==8) );
249 SMESH_ComputeErrorPtr err = ComputePentahedralMesh(aMesh, aShape);
250 return ClearAndReturn( aQuads, error(err));
252 StdMeshers_Quadrangle_2D *quadAlgo =
253 dynamic_cast < StdMeshers_Quadrangle_2D * >(algo);
256 aQuads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aFace, _quadraticMesh);
258 catch(SALOME_Exception & S_ex) {
259 return ClearAndReturn( aQuads, error(COMPERR_SLM_EXCEPTION,TComm(S_ex.what()) <<
260 " Raised by StdMeshers_Quadrangle_2D "
261 " on face #" << meshDS->ShapeToIndex( aFace )));
264 // 0.2.1 - number of points on the opposite edges must be the same
265 if (aQuads[i]->side[0]->NbPoints() != aQuads[i]->side[2]->NbPoints() ||
266 aQuads[i]->side[1]->NbPoints() != aQuads[i]->side[3]->NbPoints()
267 /*aQuads[i]->side[0]->NbEdges() != 1 ||
268 aQuads[i]->side[1]->NbEdges() != 1 ||
269 aQuads[i]->side[2]->NbEdges() != 1 ||
270 aQuads[i]->side[3]->NbEdges() != 1*/) {
271 MESSAGE("different number of points on the opposite edges of face " << i);
272 // Try to go into penta algorithm 'cause it has been improved.
273 SMESH_ComputeErrorPtr err = ComputePentahedralMesh(aMesh, aShape);
274 return ClearAndReturn( aQuads, error(err));
278 // 1. - identify faces and vertices of the "cube"
279 // 1.1 - ancestor maps vertex->edges in the cube
281 TopTools_IndexedDataMapOfShapeListOfShape MS;
282 TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
284 // 1.2 - first face is choosen as face Y=0 of the unit cube
286 const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
287 const TopoDS_Face & F = TopoDS::Face(aFace);
289 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
291 aCube.V000 = aQuads[0]->side[0]->FirstVertex(); // will be (0,0,0) on the unit cube
292 aCube.V100 = aQuads[0]->side[0]->LastVertex(); // will be (1,0,0) on the unit cube
293 aCube.V001 = aQuads[0]->side[2]->FirstVertex(); // will be (0,0,1) on the unit cube
294 aCube.V101 = aQuads[0]->side[2]->LastVertex(); // will be (1,0,1) on the unit cube
296 TopTools_IndexedMapOfShape MV0;
297 TopExp::MapShapes(F, TopAbs_VERTEX, MV0);
299 aCube.V010 = OppositeVertex( aCube.V000, MV0, aQuads);
300 aCube.V110 = OppositeVertex( aCube.V100, MV0, aQuads);
301 aCube.V011 = OppositeVertex( aCube.V001, MV0, aQuads);
302 aCube.V111 = OppositeVertex( aCube.V101, MV0, aQuads);
304 // 1.6 - find remaining faces given 4 vertices
307 aCube.quad_Y0 = aQuads[_indY0];
309 int _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
310 aCube.V010, aCube.V011, aCube.V110, aCube.V111);
311 aCube.quad_Y1 = aQuads[_indY1];
313 int _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
314 aCube.V000, aCube.V010, aCube.V100, aCube.V110);
315 aCube.quad_Z0 = aQuads[_indZ0];
317 int _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
318 aCube.V001, aCube.V011, aCube.V101, aCube.V111);
319 aCube.quad_Z1 = aQuads[_indZ1];
321 int _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
322 aCube.V000, aCube.V001, aCube.V010, aCube.V011);
323 aCube.quad_X0 = aQuads[_indX0];
325 int _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
326 aCube.V100, aCube.V101, aCube.V110, aCube.V111);
327 aCube.quad_X1 = aQuads[_indX1];
329 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
331 Conv2DStruct cx0; // for face X=0
332 Conv2DStruct cx1; // for face X=1
338 GetConv2DCoefs(*aCube.quad_X0, meshFaces[_indX0]->GetSubShape(),
339 aCube.V000, aCube.V010, aCube.V011, aCube.V001, cx0);
340 GetConv2DCoefs(*aCube.quad_X1, meshFaces[_indX1]->GetSubShape(),
341 aCube.V100, aCube.V110, aCube.V111, aCube.V101, cx1);
342 GetConv2DCoefs(*aCube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
343 aCube.V000, aCube.V100, aCube.V101, aCube.V001, cy0);
344 GetConv2DCoefs(*aCube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
345 aCube.V010, aCube.V110, aCube.V111, aCube.V011, cy1);
346 GetConv2DCoefs(*aCube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
347 aCube.V000, aCube.V100, aCube.V110, aCube.V010, cz0);
348 GetConv2DCoefs(*aCube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
349 aCube.V001, aCube.V101, aCube.V111, aCube.V011, cz1);
351 // 1.8 - create a 3D structure for normalized values
353 int nbx = aCube.quad_Z0->side[0]->NbPoints();
354 if (cz0.a1 == 0.) nbx = aCube.quad_Z0->side[1]->NbPoints();
356 int nby = aCube.quad_X0->side[0]->NbPoints();
357 if (cx0.a1 == 0.) nby = aCube.quad_X0->side[1]->NbPoints();
359 int nbz = aCube.quad_Y0->side[0]->NbPoints();
360 if (cy0.a1 != 0.) nbz = aCube.quad_Y0->side[1]->NbPoints();
362 int i1, j1, nbxyz = nbx * nby * nbz;
363 Point3DStruct *np = new Point3DStruct[nbxyz];
365 // 1.9 - store node indexes of faces
368 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
370 faceQuadStruct *quad = aCube.quad_X0;
371 int i = 0; // j = x/face , k = y/face
372 int nbdown = quad->side[0]->NbPoints();
373 int nbright = quad->side[1]->NbPoints();
375 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
378 const SMDS_MeshNode * node = itf->next();
379 if(aTool.IsMedium(node))
381 if ( !findIJ( node, quad, i1, j1 ))
382 return ClearAndReturn( aQuads, false );
383 int ij1 = j1 * nbdown + i1;
384 quad->uv_grid[ij1].node = node;
387 for (int i1 = 0; i1 < nbdown; i1++)
388 for (int j1 = 0; j1 < nbright; j1++) {
389 int ij1 = j1 * nbdown + i1;
390 int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic; // j = x/face
391 int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc; // k = y/face
392 int ijk = k * nbx * nby + j * nbx + i;
393 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
394 np[ijk].node = quad->uv_grid[ij1].node;
395 //SCRUTE(np[ijk].nodeId);
400 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
402 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
404 faceQuadStruct *quad = aCube.quad_X1;
405 int i = nbx - 1; // j = x/face , k = y/face
406 int nbdown = quad->side[0]->NbPoints();
407 int nbright = quad->side[1]->NbPoints();
410 const SMDS_MeshNode * node = itf->next();
411 if(aTool.IsMedium(node))
413 if ( !findIJ( node, quad, i1, j1 ))
414 return ClearAndReturn( aQuads, false );
415 int ij1 = j1 * nbdown + i1;
416 quad->uv_grid[ij1].node = node;
419 for (int i1 = 0; i1 < nbdown; i1++)
420 for (int j1 = 0; j1 < nbright; j1++) {
421 int ij1 = j1 * nbdown + i1;
422 int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic; // j = x/face
423 int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc; // k = y/face
424 int ijk = k * nbx * nby + j * nbx + i;
425 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
426 np[ijk].node = quad->uv_grid[ij1].node;
427 //SCRUTE(np[ijk].nodeId);
432 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
434 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
436 faceQuadStruct *quad = aCube.quad_Y0;
437 int j = 0; // i = x/face , k = y/face
438 int nbdown = quad->side[0]->NbPoints();
439 int nbright = quad->side[1]->NbPoints();
442 const SMDS_MeshNode * node = itf->next();
443 if(aTool.IsMedium(node))
445 if ( !findIJ( node, quad, i1, j1 ))
446 return ClearAndReturn( aQuads, false );
447 int ij1 = j1 * nbdown + i1;
448 quad->uv_grid[ij1].node = node;
451 for (int i1 = 0; i1 < nbdown; i1++)
452 for (int j1 = 0; j1 < nbright; j1++) {
453 int ij1 = j1 * nbdown + i1;
454 int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic; // i = x/face
455 int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc; // k = y/face
456 int ijk = k * nbx * nby + j * nbx + i;
457 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
458 np[ijk].node = quad->uv_grid[ij1].node;
459 //SCRUTE(np[ijk].nodeId);
464 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
466 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
468 faceQuadStruct *quad = aCube.quad_Y1;
469 int j = nby - 1; // i = x/face , k = y/face
470 int nbdown = quad->side[0]->NbPoints();
471 int nbright = quad->side[1]->NbPoints();
474 const SMDS_MeshNode * node = itf->next();
475 if(aTool.IsMedium(node))
477 if ( !findIJ( node, quad, i1, j1 ))
478 return ClearAndReturn( aQuads, false );
479 int ij1 = j1 * nbdown + i1;
480 quad->uv_grid[ij1].node = node;
483 for (int i1 = 0; i1 < nbdown; i1++)
484 for (int j1 = 0; j1 < nbright; j1++) {
485 int ij1 = j1 * nbdown + i1;
486 int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic; // i = x/face
487 int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc; // k = y/face
488 int ijk = k * nbx * nby + j * nbx + i;
489 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
490 np[ijk].node = quad->uv_grid[ij1].node;
491 //SCRUTE(np[ijk].nodeId);
496 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
498 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
500 faceQuadStruct *quad = aCube.quad_Z0;
501 int k = 0; // i = x/face , j = y/face
502 int nbdown = quad->side[0]->NbPoints();
503 int nbright = quad->side[1]->NbPoints();
506 const SMDS_MeshNode * node = itf->next();
507 if(aTool.IsMedium(node))
509 if ( !findIJ( node, quad, i1, j1 ))
510 return ClearAndReturn( aQuads, false );
511 int ij1 = j1 * nbdown + i1;
512 quad->uv_grid[ij1].node = node;
515 for (int i1 = 0; i1 < nbdown; i1++)
516 for (int j1 = 0; j1 < nbright; j1++) {
517 int ij1 = j1 * nbdown + i1;
518 int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic; // i = x/face
519 int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc; // j = y/face
520 int ijk = k * nbx * nby + j * nbx + i;
521 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
522 np[ijk].node = quad->uv_grid[ij1].node;
523 //SCRUTE(np[ijk].nodeId);
528 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
530 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
532 faceQuadStruct *quad = aCube.quad_Z1;
533 int k = nbz - 1; // i = x/face , j = y/face
534 int nbdown = quad->side[0]->NbPoints();
535 int nbright = quad->side[1]->NbPoints();
538 const SMDS_MeshNode * node = itf->next();
539 if(aTool.IsMedium(node))
541 if ( !findIJ( node, quad, i1, j1 ))
542 return ClearAndReturn( aQuads, false );
543 int ij1 = j1 * nbdown + i1;
544 quad->uv_grid[ij1].node = node;
547 for (int i1 = 0; i1 < nbdown; i1++)
548 for (int j1 = 0; j1 < nbright; j1++) {
549 int ij1 = j1 * nbdown + i1;
550 int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic; // i = x/face
551 int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc; // j = y/face
552 int ijk = k * nbx * nby + j * nbx + i;
553 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
554 np[ijk].node = quad->uv_grid[ij1].node;
555 //SCRUTE(np[ijk].nodeId);
559 // 2.0 - for each node of the cube:
560 // - get the 8 points 3D = 8 vertices of the cube
561 // - get the 12 points 3D on the 12 edges of the cube
562 // - get the 6 points 3D on the 6 faces with their ID
563 // - compute the point 3D
564 // - store the point 3D in SMESHDS, store its ID in 3D structure
566 int shapeID = meshDS->ShapeToIndex( aShape );
568 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
569 Pt3 px00, px01, px10, px11;
570 Pt3 p0y0, p0y1, p1y0, p1y1;
571 Pt3 p00z, p01z, p10z, p11z;
572 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
574 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
575 GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
576 GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
577 GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
578 GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
579 GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
580 GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
581 GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
583 for (int i = 1; i < nbx - 1; i++) {
584 for (int j = 1; j < nby - 1; j++) {
585 for (int k = 1; k < nbz - 1; k++) {
586 // *** seulement maillage regulier
587 // 12 points on edges
588 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
589 GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
590 GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
591 GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
593 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
594 GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
595 GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
596 GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
598 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
599 GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
600 GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
601 GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
603 // 12 points on faces
604 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
605 GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
606 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
607 GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
608 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
609 GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
611 int ijk = k * nbx * nby + j * nbx + i;
612 double x = double (i) / double (nbx - 1); // *** seulement
613 double y = double (j) / double (nby - 1); // *** maillage
614 double z = double (k) / double (nbz - 1); // *** regulier
617 for (int i = 0; i < 3; i++) {
618 X[i] = (1 - x) * p0yz[i] + x * p1yz[i]
619 + (1 - y) * px0z[i] + y * px1z[i]
620 + (1 - z) * pxy0[i] + z * pxy1[i]
621 - (1 - x) * ((1 - y) * p00z[i] + y * p01z[i])
622 - x * ((1 - y) * p10z[i] + y * p11z[i])
623 - (1 - y) * ((1 - z) * px00[i] + z * px01[i])
624 - y * ((1 - z) * px10[i] + z * px11[i])
625 - (1 - z) * ((1 - x) * p0y0[i] + x * p1y0[i])
626 - z * ((1 - x) * p0y1[i] + x * p1y1[i])
627 + (1 - x) * ((1 - y) * ((1 - z) * p000[i] + z * p001[i])
628 + y * ((1 - z) * p010[i] + z * p011[i]))
629 + x * ((1 - y) * ((1 - z) * p100[i] + z * p101[i])
630 + y * ((1 - z) * p110[i] + z * p111[i]));
633 SMDS_MeshNode * node = meshDS->AddNode(X[0], X[1], X[2]);
635 meshDS->SetNodeInVolume(node, shapeID);
640 // find orientation of furute volumes according to MED convention
641 vector< bool > forward( nbx * nby );
642 SMDS_VolumeTool vTool;
643 for (int i = 0; i < nbx - 1; i++) {
644 for (int j = 0; j < nby - 1; j++) {
645 int n1 = j * nbx + i;
646 int n2 = j * nbx + i + 1;
647 int n3 = (j + 1) * nbx + i + 1;
648 int n4 = (j + 1) * nbx + i;
649 int n5 = nbx * nby + j * nbx + i;
650 int n6 = nbx * nby + j * nbx + i + 1;
651 int n7 = nbx * nby + (j + 1) * nbx + i + 1;
652 int n8 = nbx * nby + (j + 1) * nbx + i;
654 SMDS_VolumeOfNodes tmpVol (np[n1].node,np[n2].node,np[n3].node,np[n4].node,
655 np[n5].node,np[n6].node,np[n7].node,np[n8].node);
656 vTool.Set( &tmpVol );
657 forward[ n1 ] = vTool.IsForward();
661 //2.1 - for each node of the cube (less 3 *1 Faces):
662 // - store hexahedron in SMESHDS
663 MESSAGE("Storing hexahedron into the DS");
664 for (int i = 0; i < nbx - 1; i++) {
665 for (int j = 0; j < nby - 1; j++) {
666 bool isForw = forward.at( j * nbx + i );
667 for (int k = 0; k < nbz - 1; k++) {
668 int n1 = k * nbx * nby + j * nbx + i;
669 int n2 = k * nbx * nby + j * nbx + i + 1;
670 int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
671 int n4 = k * nbx * nby + (j + 1) * nbx + i;
672 int n5 = (k + 1) * nbx * nby + j * nbx + i;
673 int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
674 int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
675 int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
677 SMDS_MeshVolume * elt;
679 elt = aTool.AddVolume(np[n1].node, np[n2].node,
680 np[n3].node, np[n4].node,
681 np[n5].node, np[n6].node,
682 np[n7].node, np[n8].node);
685 elt = aTool.AddVolume(np[n1].node, np[n4].node,
686 np[n3].node, np[n2].node,
687 np[n5].node, np[n8].node,
688 np[n7].node, np[n6].node);
691 meshDS->SetMeshElementOnShape(elt, shapeID);
695 if ( np ) delete [] np;
696 return ClearAndReturn( aQuads, true );
699 //=============================================================================
703 //=============================================================================
705 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby, int nbz,
706 Point3DStruct * np, const SMESHDS_Mesh * meshDS)
708 int ijk = k * nbx * nby + j * nbx + i;
709 const SMDS_MeshNode * node = np[ijk].node;
713 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
716 //=============================================================================
720 //=============================================================================
722 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
723 const TopoDS_Shape & aShape,
724 const vector < SMESH_subMesh * >&meshFaces,
725 const TopoDS_Vertex & V0,
726 const TopoDS_Vertex & V1,
727 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
729 //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
731 for (int i = 1; i < 6; i++)
733 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
734 //const TopoDS_Face& F = TopoDS::Face(aFace);
735 TopTools_IndexedMapOfShape M;
736 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
737 bool verticesInShape = false;
742 verticesInShape = true;
749 ASSERT(faceIndex > 0);
754 //=============================================================================
758 //=============================================================================
761 StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
762 const TopoDS_Shape & aShape,
763 const TopoDS_Face & aFace,
764 const TopoDS_Vertex & aVertex,
765 const TopTools_IndexedDataMapOfShapeListOfShape & MS)
767 //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
768 TopTools_IndexedDataMapOfShapeListOfShape MF;
769 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
770 const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
771 const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
772 // SCRUTE(ancestorsInSolid.Extent());
773 // SCRUTE(ancestorsInFace.Extent());
774 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
775 ASSERT(ancestorsInFace.Extent() == 2);
779 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
780 for (; its.More(); its.Next())
782 TopoDS_Shape ancestor = its.Value();
783 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
784 bool isInFace = false;
785 for (; itf.More(); itf.Next())
787 TopoDS_Shape ancestorInFace = itf.Value();
788 if (ancestorInFace.IsSame(ancestor))
796 E = TopoDS::Edge(ancestor);
803 //=============================================================================
807 //=============================================================================
809 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
810 const TopoDS_Shape & aShape,
811 const TopoDS_Vertex & V0,
812 const TopoDS_Vertex & V1,
813 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
815 // MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
816 // const TopoDS_Face & F = TopoDS::Face(aShape);
817 // TopoDS_Edge E = quad.edge[0];
819 // Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
820 // TopoDS_Vertex VFirst, VLast;
821 // TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
822 // bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
823 TopoDS_Vertex VA, VB;
834 VA = quad.side[0]->FirstVertex();
835 VB = quad.side[0]->LastVertex();
837 int a1, b1, c1, a2, b2, c2;
850 ASSERT(VB.IsSame(V3));
870 ASSERT(VB.IsSame(V0));
890 ASSERT(VB.IsSame(V1));
910 ASSERT(VB.IsSame(V2));
918 // MESSAGE("X = " << c1 << "+ " << a1 << "*x + " << b1 << "*y");
919 // MESSAGE("Y = " << c2 << "+ " << a2 << "*x + " << b2 << "*y");
927 int nbdown = quad.side[0]->NbPoints();
928 int nbright = quad.side[1]->NbPoints();
932 int (c1 * a1 * a1) * (nbdown - 1) + int (c1 * b1 * b1) * (nbright - 1);
936 int (c2 * a2 * a2) * (nbdown - 1) + int (c2 * b2 * b2) * (nbright - 1);
937 // MESSAGE("I " << conv.ia << " " << conv.ib << " " << conv.ic);
938 // MESSAGE("J " << conv.ja << " " << conv.jb << " " << conv.jc);
941 //================================================================================
943 * \brief Find a vertex opposite to the given vertex of aQuads[0]
944 * \param aVertex - the vertex
945 * \param aFace - the face aVertex belongs to
946 * \param aQuads - quads
947 * \retval TopoDS_Vertex - found vertex
949 //================================================================================
951 TopoDS_Vertex StdMeshers_Hexa_3D::OppositeVertex(const TopoDS_Vertex& aVertex,
952 const TopTools_IndexedMapOfShape& aQuads0Vertices,
953 FaceQuadStruct* aQuads[6])
956 for ( i = 1; i < 6; ++i )
958 TopoDS_Vertex VV[] = { aQuads[i]->side[0]->FirstVertex(),
959 aQuads[i]->side[0]->LastVertex() ,
960 aQuads[i]->side[2]->LastVertex() ,
961 aQuads[i]->side[2]->FirstVertex() };
962 for ( j = 0; j < 4; ++j )
963 if ( aVertex.IsSame( VV[ j ]))
966 int jPrev = j ? j - 1 : 3;
967 int jNext = (j + 1) % 4;
968 if ( aQuads0Vertices.Contains( VV[ jPrev ] ))
974 return TopoDS_Vertex();
977 //modified by NIZNHY-PKV Wed Nov 17 15:34:13 2004 f
978 ///////////////////////////////////////////////////////////////////////////////
982 //=======================================================================
983 //function : ComputePentahedralMesh
985 //=======================================================================
987 SMESH_ComputeErrorPtr ComputePentahedralMesh(SMESH_Mesh & aMesh,
988 const TopoDS_Shape & aShape)
990 //printf(" ComputePentahedralMesh HERE\n");
993 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
995 StdMeshers_Penta_3D anAlgo;
997 bOK=anAlgo.Compute(aMesh, aShape);
999 err = anAlgo.GetComputeError();
1001 if ( !bOK && anAlgo.ErrorStatus() == 5 )
1003 static StdMeshers_Prism_3D * aPrism3D = 0;
1005 SMESH_Gen* gen = aMesh.GetGen();
1006 aPrism3D = new StdMeshers_Prism_3D( gen->GetANewId(), 0, gen );
1008 SMESH_Hypothesis::Hypothesis_Status aStatus;
1009 if ( aPrism3D->CheckHypothesis( aMesh, aShape, aStatus ) ) {
1010 bOK = aPrism3D->Compute( aMesh, aShape );
1011 err = aPrism3D->GetComputeError();