1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
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
29 #include "StdMeshers_Hexa_3D.hxx"
30 #include "StdMeshers_Quadrangle_2D.hxx"
31 #include "StdMeshers_FaceSide.hxx"
32 #include "StdMeshers_Penta_3D.hxx"
33 #include "StdMeshers_Prism_3D.hxx"
35 #include "SMESH_Gen.hxx"
36 #include "SMESH_Mesh.hxx"
37 #include "SMESH_subMesh.hxx"
38 #include "SMESH_Comment.hxx"
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"
47 #include <TopExp_Explorer.hxx>
48 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
49 #include <TopTools_ListIteratorOfListOfShape.hxx>
50 #include <TopTools_ListOfShape.hxx>
52 #include <gp_Pnt2d.hxx>
54 #include "utilities.h"
55 #include "Utils_ExceptHandlers.hxx"
57 typedef SMESH_Comment TComm;
61 static SMESH_ComputeErrorPtr ComputePentahedralMesh(SMESH_Mesh &, const TopoDS_Shape &);
63 //=============================================================================
67 //=============================================================================
69 StdMeshers_Hexa_3D::StdMeshers_Hexa_3D(int hypId, int studyId, SMESH_Gen * gen)
70 :SMESH_3D_Algo(hypId, studyId, gen)
72 MESSAGE("StdMeshers_Hexa_3D::StdMeshers_Hexa_3D");
74 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
77 //=============================================================================
81 //=============================================================================
83 StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D()
85 MESSAGE("StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D");
88 //================================================================================
90 * \brief Clear fields and return the argument
91 * \param res - the value to return
92 * \retval bool - the argument value
94 //================================================================================
96 bool StdMeshers_Hexa_3D::ClearAndReturn(FaceQuadStruct* theQuads[6], const bool res)
98 for (int i = 0; i < 6; i++) {
106 //=============================================================================
110 //=============================================================================
112 bool StdMeshers_Hexa_3D::CheckHypothesis
114 const TopoDS_Shape& aShape,
115 SMESH_Hypothesis::Hypothesis_Status& aStatus)
117 // check nb of faces in the shape
119 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
121 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next())
127 aStatus = SMESH_Hypothesis::HYP_OK;
131 //=======================================================================
132 //function : isCloser
134 //=======================================================================
136 inline bool isCloser(const int i, const int j, const int nbhoriz,
137 const FaceQuadStruct* quad, const gp_Pnt2d uv,
140 int ij = j * nbhoriz + i;
141 gp_Pnt2d uv2( quad->uv_grid[ij].u, quad->uv_grid[ij].v );
142 double dist = uv.SquareDistance( uv2 );
143 if ( dist < minDist ) {
150 //=======================================================================
152 //purpose : return i,j of the node
153 //=======================================================================
155 static bool findIJ (const SMDS_MeshNode* node, const FaceQuadStruct * quad, int& I, int& J)
157 const SMDS_FacePosition* fpos =
158 static_cast<const SMDS_FacePosition*>(node->GetPosition().get());
159 if ( ! fpos ) return false;
160 gp_Pnt2d uv( fpos->GetUParameter(), fpos->GetVParameter() );
162 double minDist = DBL_MAX;
163 const int nbhoriz = quad->side[0]->NbPoints();
164 const int nbvertic = quad->side[1]->NbPoints();
165 I = nbhoriz/2; J = nbvertic/2;
169 while ( I + 2 < nbhoriz && isCloser( I + 1, J, nbhoriz, quad, uv, minDist ))
172 while ( I - 1 > 0 && isCloser( I - 1, J, nbhoriz, quad, uv, minDist ))
174 if ( minDist < DBL_MIN )
177 while ( J + 2 < nbvertic && isCloser( I, J + 1, nbhoriz, quad, uv, minDist ))
180 while ( J - 1 > 0 && isCloser( I, J - 1, nbhoriz, quad, uv, minDist ))
182 if ( minDist < DBL_MIN )
185 } while ( I != oldI || J != oldJ );
187 if ( minDist > DBL_MIN ) {
188 for (int i = 1; i < nbhoriz - 1; i++)
189 for (int j = 1; j < nbvertic - 1; j++)
190 if ( isCloser( i, j, nbhoriz, quad, uv, minDist ))
197 //=============================================================================
199 * Hexahedron mesh on hexaedron like form
200 * -0. - shape and face mesh verification
201 * -1. - identify faces and vertices of the "cube"
202 * -2. - Algorithm from:
203 * "Application de l'interpolation transfinie à la création de maillages
204 * C0 ou G1 continus sur des triangles, quadrangles, tetraedres, pentaedres
205 * et hexaedres déformés."
206 * Alain PERONNET - 8 janvier 1999
208 //=============================================================================
210 bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh & aMesh,
211 const TopoDS_Shape & aShape)// throw(SALOME_Exception)
213 // PAL14921. Enable catching std::bad_alloc and Standard_OutOfMemory outside
214 //Unexpect aCatch(SalomeException);
215 MESSAGE("StdMeshers_Hexa_3D::Compute");
216 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
218 // 0. - shape and face mesh verification
219 // 0.1 - shape must be a solid (or a shell) with 6 faces
221 vector < SMESH_subMesh * >meshFaces;
222 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
223 SMESH_subMesh *aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
225 meshFaces.push_back(aSubMesh);
227 if (meshFaces.size() != 6)
228 return error(COMPERR_BAD_SHAPE, TComm(meshFaces.size())<<" instead of 6 faces in a block");
230 // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
232 // tool for working with quadratic elements
233 SMESH_MesherHelper aTool (aMesh);
234 _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
237 typedef struct cubeStruct
247 faceQuadStruct* quad_X0;
248 faceQuadStruct* quad_X1;
249 faceQuadStruct* quad_Y0;
250 faceQuadStruct* quad_Y1;
251 faceQuadStruct* quad_Z0;
252 faceQuadStruct* quad_Z1;
253 Point3DStruct* np; // normalised 3D coordinates
259 FaceQuadStruct* aQuads[6];
260 for (int i = 0; i < 6; i++)
263 for (int i = 0; i < 6; i++)
265 TopoDS_Shape aFace = meshFaces[i]->GetSubShape();
266 SMESH_Algo *algo = _gen->GetAlgo(aMesh, aFace);
267 string algoName = algo->GetName();
268 bool isAllQuad = false;
269 if (algoName == "Quadrangle_2D") {
270 SMESHDS_SubMesh * sm = meshDS->MeshElements( aFace );
273 SMDS_ElemIteratorPtr eIt = sm->GetElements();
274 while ( isAllQuad && eIt->more() ) {
275 const SMDS_MeshElement* elem = eIt->next();
276 isAllQuad = ( elem->NbNodes()==4 ||(_quadraticMesh && elem->NbNodes()==8) );
281 SMESH_ComputeErrorPtr err = ComputePentahedralMesh(aMesh, aShape);
282 return ClearAndReturn( aQuads, error(err));
284 StdMeshers_Quadrangle_2D *quadAlgo =
285 dynamic_cast < StdMeshers_Quadrangle_2D * >(algo);
288 aQuads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aFace, _quadraticMesh);
290 return error( quadAlgo->GetComputeError());
293 catch(SALOME_Exception & S_ex) {
294 return ClearAndReturn( aQuads, error(COMPERR_SLM_EXCEPTION,TComm(S_ex.what()) <<
295 " Raised by StdMeshers_Quadrangle_2D "
296 " on face #" << meshDS->ShapeToIndex( aFace )));
299 // 0.2.1 - number of points on the opposite edges must be the same
300 if (aQuads[i]->side[0]->NbPoints() != aQuads[i]->side[2]->NbPoints() ||
301 aQuads[i]->side[1]->NbPoints() != aQuads[i]->side[3]->NbPoints()
302 /*aQuads[i]->side[0]->NbEdges() != 1 ||
303 aQuads[i]->side[1]->NbEdges() != 1 ||
304 aQuads[i]->side[2]->NbEdges() != 1 ||
305 aQuads[i]->side[3]->NbEdges() != 1*/) {
306 MESSAGE("different number of points on the opposite edges of face " << i);
307 // Try to go into penta algorithm 'cause it has been improved.
308 SMESH_ComputeErrorPtr err = ComputePentahedralMesh(aMesh, aShape);
309 return ClearAndReturn( aQuads, error(err));
313 // 1. - identify faces and vertices of the "cube"
314 // 1.1 - ancestor maps vertex->edges in the cube
316 TopTools_IndexedDataMapOfShapeListOfShape MS;
317 TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
319 // 1.2 - first face is choosen as face Y=0 of the unit cube
321 const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
322 const TopoDS_Face & F = TopoDS::Face(aFace);
324 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
326 aCube.V000 = aQuads[0]->side[0]->FirstVertex(); // will be (0,0,0) on the unit cube
327 aCube.V100 = aQuads[0]->side[0]->LastVertex(); // will be (1,0,0) on the unit cube
328 aCube.V001 = aQuads[0]->side[2]->FirstVertex(); // will be (0,0,1) on the unit cube
329 aCube.V101 = aQuads[0]->side[2]->LastVertex(); // will be (1,0,1) on the unit cube
331 TopTools_IndexedMapOfShape MV0;
332 TopExp::MapShapes(F, TopAbs_VERTEX, MV0);
334 aCube.V010 = OppositeVertex( aCube.V000, MV0, aQuads);
335 aCube.V110 = OppositeVertex( aCube.V100, MV0, aQuads);
336 aCube.V011 = OppositeVertex( aCube.V001, MV0, aQuads);
337 aCube.V111 = OppositeVertex( aCube.V101, MV0, aQuads);
339 // 1.6 - find remaining faces given 4 vertices
342 aCube.quad_Y0 = aQuads[_indY0];
344 int _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
345 aCube.V010, aCube.V011, aCube.V110, aCube.V111);
346 aCube.quad_Y1 = aQuads[_indY1];
348 int _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
349 aCube.V000, aCube.V010, aCube.V100, aCube.V110);
350 aCube.quad_Z0 = aQuads[_indZ0];
352 int _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
353 aCube.V001, aCube.V011, aCube.V101, aCube.V111);
354 aCube.quad_Z1 = aQuads[_indZ1];
356 int _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
357 aCube.V000, aCube.V001, aCube.V010, aCube.V011);
358 aCube.quad_X0 = aQuads[_indX0];
360 int _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
361 aCube.V100, aCube.V101, aCube.V110, aCube.V111);
362 aCube.quad_X1 = aQuads[_indX1];
364 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
366 Conv2DStruct cx0; // for face X=0
367 Conv2DStruct cx1; // for face X=1
373 GetConv2DCoefs(*aCube.quad_X0, meshFaces[_indX0]->GetSubShape(),
374 aCube.V000, aCube.V010, aCube.V011, aCube.V001, cx0);
375 GetConv2DCoefs(*aCube.quad_X1, meshFaces[_indX1]->GetSubShape(),
376 aCube.V100, aCube.V110, aCube.V111, aCube.V101, cx1);
377 GetConv2DCoefs(*aCube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
378 aCube.V000, aCube.V100, aCube.V101, aCube.V001, cy0);
379 GetConv2DCoefs(*aCube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
380 aCube.V010, aCube.V110, aCube.V111, aCube.V011, cy1);
381 GetConv2DCoefs(*aCube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
382 aCube.V000, aCube.V100, aCube.V110, aCube.V010, cz0);
383 GetConv2DCoefs(*aCube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
384 aCube.V001, aCube.V101, aCube.V111, aCube.V011, cz1);
386 // 1.8 - create a 3D structure for normalized values
388 int nbx = aCube.quad_Z0->side[0]->NbPoints();
389 if (cz0.a1 == 0.) nbx = aCube.quad_Z0->side[1]->NbPoints();
391 int nby = aCube.quad_X0->side[0]->NbPoints();
392 if (cx0.a1 == 0.) nby = aCube.quad_X0->side[1]->NbPoints();
394 int nbz = aCube.quad_Y0->side[0]->NbPoints();
395 if (cy0.a1 != 0.) nbz = aCube.quad_Y0->side[1]->NbPoints();
397 int i1, j1, nbxyz = nbx * nby * nbz;
398 Point3DStruct *np = new Point3DStruct[nbxyz];
400 // 1.9 - store node indexes of faces
403 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
405 faceQuadStruct *quad = aCube.quad_X0;
406 int i = 0; // j = x/face , k = y/face
407 int nbdown = quad->side[0]->NbPoints();
408 int nbright = quad->side[1]->NbPoints();
410 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
413 const SMDS_MeshNode * node = itf->next();
414 if(aTool.IsMedium(node))
416 if ( !findIJ( node, quad, i1, j1 ))
417 return ClearAndReturn( aQuads, false );
418 int ij1 = j1 * nbdown + i1;
419 quad->uv_grid[ij1].node = node;
422 for (int i1 = 0; i1 < nbdown; i1++)
423 for (int j1 = 0; j1 < nbright; j1++) {
424 int ij1 = j1 * nbdown + i1;
425 int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic; // j = x/face
426 int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc; // k = y/face
427 int ijk = k * nbx * nby + j * nbx + i;
428 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
429 np[ijk].node = quad->uv_grid[ij1].node;
430 //SCRUTE(np[ijk].nodeId);
435 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
437 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
439 faceQuadStruct *quad = aCube.quad_X1;
440 int i = nbx - 1; // j = x/face , k = y/face
441 int nbdown = quad->side[0]->NbPoints();
442 int nbright = quad->side[1]->NbPoints();
445 const SMDS_MeshNode * node = itf->next();
446 if(aTool.IsMedium(node))
448 if ( !findIJ( node, quad, i1, j1 ))
449 return ClearAndReturn( aQuads, false );
450 int ij1 = j1 * nbdown + i1;
451 quad->uv_grid[ij1].node = node;
454 for (int i1 = 0; i1 < nbdown; i1++)
455 for (int j1 = 0; j1 < nbright; j1++) {
456 int ij1 = j1 * nbdown + i1;
457 int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic; // j = x/face
458 int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc; // k = y/face
459 int ijk = k * nbx * nby + j * nbx + i;
460 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
461 np[ijk].node = quad->uv_grid[ij1].node;
462 //SCRUTE(np[ijk].nodeId);
467 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
469 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
471 faceQuadStruct *quad = aCube.quad_Y0;
472 int j = 0; // i = x/face , k = y/face
473 int nbdown = quad->side[0]->NbPoints();
474 int nbright = quad->side[1]->NbPoints();
477 const SMDS_MeshNode * node = itf->next();
478 if(aTool.IsMedium(node))
480 if ( !findIJ( node, quad, i1, j1 ))
481 return ClearAndReturn( aQuads, false );
482 int ij1 = j1 * nbdown + i1;
483 quad->uv_grid[ij1].node = node;
486 for (int i1 = 0; i1 < nbdown; i1++)
487 for (int j1 = 0; j1 < nbright; j1++) {
488 int ij1 = j1 * nbdown + i1;
489 int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic; // i = x/face
490 int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc; // k = y/face
491 int ijk = k * nbx * nby + j * nbx + i;
492 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
493 np[ijk].node = quad->uv_grid[ij1].node;
494 //SCRUTE(np[ijk].nodeId);
499 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
501 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
503 faceQuadStruct *quad = aCube.quad_Y1;
504 int j = nby - 1; // i = x/face , k = y/face
505 int nbdown = quad->side[0]->NbPoints();
506 int nbright = quad->side[1]->NbPoints();
509 const SMDS_MeshNode * node = itf->next();
510 if(aTool.IsMedium(node))
512 if ( !findIJ( node, quad, i1, j1 ))
513 return ClearAndReturn( aQuads, false );
514 int ij1 = j1 * nbdown + i1;
515 quad->uv_grid[ij1].node = node;
518 for (int i1 = 0; i1 < nbdown; i1++)
519 for (int j1 = 0; j1 < nbright; j1++) {
520 int ij1 = j1 * nbdown + i1;
521 int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic; // i = x/face
522 int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc; // k = y/face
523 int ijk = k * nbx * nby + j * nbx + i;
524 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
525 np[ijk].node = quad->uv_grid[ij1].node;
526 //SCRUTE(np[ijk].nodeId);
531 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
533 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
535 faceQuadStruct *quad = aCube.quad_Z0;
536 int k = 0; // i = x/face , j = y/face
537 int nbdown = quad->side[0]->NbPoints();
538 int nbright = quad->side[1]->NbPoints();
541 const SMDS_MeshNode * node = itf->next();
542 if(aTool.IsMedium(node))
544 if ( !findIJ( node, quad, i1, j1 ))
545 return ClearAndReturn( aQuads, false );
546 int ij1 = j1 * nbdown + i1;
547 quad->uv_grid[ij1].node = node;
550 for (int i1 = 0; i1 < nbdown; i1++)
551 for (int j1 = 0; j1 < nbright; j1++) {
552 int ij1 = j1 * nbdown + i1;
553 int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic; // i = x/face
554 int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc; // j = y/face
555 int ijk = k * nbx * nby + j * nbx + i;
556 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
557 np[ijk].node = quad->uv_grid[ij1].node;
558 //SCRUTE(np[ijk].nodeId);
563 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
565 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
567 faceQuadStruct *quad = aCube.quad_Z1;
568 int k = nbz - 1; // i = x/face , j = y/face
569 int nbdown = quad->side[0]->NbPoints();
570 int nbright = quad->side[1]->NbPoints();
573 const SMDS_MeshNode * node = itf->next();
574 if(aTool.IsMedium(node))
576 if ( !findIJ( node, quad, i1, j1 ))
577 return ClearAndReturn( aQuads, false );
578 int ij1 = j1 * nbdown + i1;
579 quad->uv_grid[ij1].node = node;
582 for (int i1 = 0; i1 < nbdown; i1++)
583 for (int j1 = 0; j1 < nbright; j1++) {
584 int ij1 = j1 * nbdown + i1;
585 int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic; // i = x/face
586 int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc; // j = y/face
587 int ijk = k * nbx * nby + j * nbx + i;
588 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
589 np[ijk].node = quad->uv_grid[ij1].node;
590 //SCRUTE(np[ijk].nodeId);
594 // 2.0 - for each node of the cube:
595 // - get the 8 points 3D = 8 vertices of the cube
596 // - get the 12 points 3D on the 12 edges of the cube
597 // - get the 6 points 3D on the 6 faces with their ID
598 // - compute the point 3D
599 // - store the point 3D in SMESHDS, store its ID in 3D structure
601 int shapeID = meshDS->ShapeToIndex( aShape );
603 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
604 Pt3 px00, px01, px10, px11;
605 Pt3 p0y0, p0y1, p1y0, p1y1;
606 Pt3 p00z, p01z, p10z, p11z;
607 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
609 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
610 GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
611 GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
612 GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
613 GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
614 GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
615 GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
616 GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
618 for (int i = 1; i < nbx - 1; i++) {
619 for (int j = 1; j < nby - 1; j++) {
620 for (int k = 1; k < nbz - 1; k++) {
621 // *** seulement maillage regulier
622 // 12 points on edges
623 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
624 GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
625 GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
626 GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
628 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
629 GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
630 GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
631 GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
633 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
634 GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
635 GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
636 GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
638 // 12 points on faces
639 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
640 GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
641 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
642 GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
643 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
644 GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
646 int ijk = k * nbx * nby + j * nbx + i;
647 double x = double (i) / double (nbx - 1); // *** seulement
648 double y = double (j) / double (nby - 1); // *** maillage
649 double z = double (k) / double (nbz - 1); // *** regulier
652 for (int i = 0; i < 3; i++) {
653 X[i] = (1 - x) * p0yz[i] + x * p1yz[i]
654 + (1 - y) * px0z[i] + y * px1z[i]
655 + (1 - z) * pxy0[i] + z * pxy1[i]
656 - (1 - x) * ((1 - y) * p00z[i] + y * p01z[i])
657 - x * ((1 - y) * p10z[i] + y * p11z[i])
658 - (1 - y) * ((1 - z) * px00[i] + z * px01[i])
659 - y * ((1 - z) * px10[i] + z * px11[i])
660 - (1 - z) * ((1 - x) * p0y0[i] + x * p1y0[i])
661 - z * ((1 - x) * p0y1[i] + x * p1y1[i])
662 + (1 - x) * ((1 - y) * ((1 - z) * p000[i] + z * p001[i])
663 + y * ((1 - z) * p010[i] + z * p011[i]))
664 + x * ((1 - y) * ((1 - z) * p100[i] + z * p101[i])
665 + y * ((1 - z) * p110[i] + z * p111[i]));
668 SMDS_MeshNode * node = meshDS->AddNode(X[0], X[1], X[2]);
670 meshDS->SetNodeInVolume(node, shapeID);
675 // find orientation of furute volumes according to MED convention
676 vector< bool > forward( nbx * nby );
677 SMDS_VolumeTool vTool;
678 for (int i = 0; i < nbx - 1; i++) {
679 for (int j = 0; j < nby - 1; j++) {
680 int n1 = j * nbx + i;
681 int n2 = j * nbx + i + 1;
682 int n3 = (j + 1) * nbx + i + 1;
683 int n4 = (j + 1) * nbx + i;
684 int n5 = nbx * nby + j * nbx + i;
685 int n6 = nbx * nby + j * nbx + i + 1;
686 int n7 = nbx * nby + (j + 1) * nbx + i + 1;
687 int n8 = nbx * nby + (j + 1) * nbx + i;
689 SMDS_VolumeOfNodes tmpVol (np[n1].node,np[n2].node,np[n3].node,np[n4].node,
690 np[n5].node,np[n6].node,np[n7].node,np[n8].node);
691 vTool.Set( &tmpVol );
692 forward[ n1 ] = vTool.IsForward();
696 //2.1 - for each node of the cube (less 3 *1 Faces):
697 // - store hexahedron in SMESHDS
698 MESSAGE("Storing hexahedron into the DS");
699 for (int i = 0; i < nbx - 1; i++) {
700 for (int j = 0; j < nby - 1; j++) {
701 bool isForw = forward.at( j * nbx + i );
702 for (int k = 0; k < nbz - 1; k++) {
703 int n1 = k * nbx * nby + j * nbx + i;
704 int n2 = k * nbx * nby + j * nbx + i + 1;
705 int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
706 int n4 = k * nbx * nby + (j + 1) * nbx + i;
707 int n5 = (k + 1) * nbx * nby + j * nbx + i;
708 int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
709 int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
710 int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
712 SMDS_MeshVolume * elt;
714 elt = aTool.AddVolume(np[n1].node, np[n2].node,
715 np[n3].node, np[n4].node,
716 np[n5].node, np[n6].node,
717 np[n7].node, np[n8].node);
720 elt = aTool.AddVolume(np[n1].node, np[n4].node,
721 np[n3].node, np[n2].node,
722 np[n5].node, np[n8].node,
723 np[n7].node, np[n6].node);
726 meshDS->SetMeshElementOnShape(elt, shapeID);
730 if ( np ) delete [] np;
731 return ClearAndReturn( aQuads, true );
734 //=============================================================================
738 //=============================================================================
740 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby, int nbz,
741 Point3DStruct * np, const SMESHDS_Mesh * meshDS)
743 int ijk = k * nbx * nby + j * nbx + i;
744 const SMDS_MeshNode * node = np[ijk].node;
748 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
751 //=============================================================================
755 //=============================================================================
757 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
758 const TopoDS_Shape & aShape,
759 const vector < SMESH_subMesh * >&meshFaces,
760 const TopoDS_Vertex & V0,
761 const TopoDS_Vertex & V1,
762 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
764 //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
766 for (int i = 1; i < 6; i++)
768 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
769 //const TopoDS_Face& F = TopoDS::Face(aFace);
770 TopTools_IndexedMapOfShape M;
771 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
772 bool verticesInShape = false;
777 verticesInShape = true;
784 ASSERT(faceIndex > 0);
789 //=============================================================================
793 //=============================================================================
796 StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
797 const TopoDS_Shape & aShape,
798 const TopoDS_Face & aFace,
799 const TopoDS_Vertex & aVertex,
800 const TopTools_IndexedDataMapOfShapeListOfShape & MS)
802 //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
803 TopTools_IndexedDataMapOfShapeListOfShape MF;
804 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
805 const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
806 const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
807 // SCRUTE(ancestorsInSolid.Extent());
808 // SCRUTE(ancestorsInFace.Extent());
809 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
810 ASSERT(ancestorsInFace.Extent() == 2);
814 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
815 for (; its.More(); its.Next())
817 TopoDS_Shape ancestor = its.Value();
818 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
819 bool isInFace = false;
820 for (; itf.More(); itf.Next())
822 TopoDS_Shape ancestorInFace = itf.Value();
823 if (ancestorInFace.IsSame(ancestor))
831 E = TopoDS::Edge(ancestor);
838 //=============================================================================
842 //=============================================================================
844 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
845 const TopoDS_Shape & aShape,
846 const TopoDS_Vertex & V0,
847 const TopoDS_Vertex & V1,
848 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
850 // MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
851 // const TopoDS_Face & F = TopoDS::Face(aShape);
852 // TopoDS_Edge E = quad.edge[0];
854 // Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
855 // TopoDS_Vertex VFirst, VLast;
856 // TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
857 // bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
858 TopoDS_Vertex VA, VB;
869 VA = quad.side[0]->FirstVertex();
870 VB = quad.side[0]->LastVertex();
872 int a1, b1, c1, a2, b2, c2;
885 ASSERT(VB.IsSame(V3));
905 ASSERT(VB.IsSame(V0));
925 ASSERT(VB.IsSame(V1));
945 ASSERT(VB.IsSame(V2));
953 // MESSAGE("X = " << c1 << "+ " << a1 << "*x + " << b1 << "*y");
954 // MESSAGE("Y = " << c2 << "+ " << a2 << "*x + " << b2 << "*y");
962 int nbdown = quad.side[0]->NbPoints();
963 int nbright = quad.side[1]->NbPoints();
967 int (c1 * a1 * a1) * (nbdown - 1) + int (c1 * b1 * b1) * (nbright - 1);
971 int (c2 * a2 * a2) * (nbdown - 1) + int (c2 * b2 * b2) * (nbright - 1);
972 // MESSAGE("I " << conv.ia << " " << conv.ib << " " << conv.ic);
973 // MESSAGE("J " << conv.ja << " " << conv.jb << " " << conv.jc);
976 //================================================================================
978 * \brief Find a vertex opposite to the given vertex of aQuads[0]
979 * \param aVertex - the vertex
980 * \param aFace - the face aVertex belongs to
981 * \param aQuads - quads
982 * \retval TopoDS_Vertex - found vertex
984 //================================================================================
986 TopoDS_Vertex StdMeshers_Hexa_3D::OppositeVertex(const TopoDS_Vertex& aVertex,
987 const TopTools_IndexedMapOfShape& aQuads0Vertices,
988 FaceQuadStruct* aQuads[6])
991 for ( i = 1; i < 6; ++i )
993 TopoDS_Vertex VV[] = { aQuads[i]->side[0]->FirstVertex(),
994 aQuads[i]->side[0]->LastVertex() ,
995 aQuads[i]->side[2]->LastVertex() ,
996 aQuads[i]->side[2]->FirstVertex() };
997 for ( j = 0; j < 4; ++j )
998 if ( aVertex.IsSame( VV[ j ]))
1001 int jPrev = j ? j - 1 : 3;
1002 int jNext = (j + 1) % 4;
1003 if ( aQuads0Vertices.Contains( VV[ jPrev ] ))
1009 return TopoDS_Vertex();
1012 //modified by NIZNHY-PKV Wed Nov 17 15:34:13 2004 f
1013 ///////////////////////////////////////////////////////////////////////////////
1015 //#include <stdio.h>
1017 //=======================================================================
1018 //function : ComputePentahedralMesh
1020 //=======================================================================
1022 SMESH_ComputeErrorPtr ComputePentahedralMesh(SMESH_Mesh & aMesh,
1023 const TopoDS_Shape & aShape)
1025 //printf(" ComputePentahedralMesh HERE\n");
1028 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1030 StdMeshers_Penta_3D anAlgo;
1032 bOK=anAlgo.Compute(aMesh, aShape);
1034 err = anAlgo.GetComputeError();
1036 if ( !bOK && anAlgo.ErrorStatus() == 5 )
1038 static StdMeshers_Prism_3D * aPrism3D = 0;
1040 SMESH_Gen* gen = aMesh.GetGen();
1041 aPrism3D = new StdMeshers_Prism_3D( gen->GetANewId(), 0, gen );
1043 SMESH_Hypothesis::Hypothesis_Status aStatus;
1044 if ( aPrism3D->CheckHypothesis( aMesh, aShape, aStatus ) ) {
1045 bOK = aPrism3D->Compute( aMesh, aShape );
1046 err = aPrism3D->GetComputeError();