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"
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 <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
48 #include <TopTools_ListOfShape.hxx>
49 #include <TopTools_ListIteratorOfListOfShape.hxx>
50 //#include <TColStd_ListIteratorOfListOfInteger.hxx>
51 #include <TColStd_MapOfInteger.hxx>
53 #include <BRep_Tool.hxx>
54 #include <Geom_Surface.hxx>
55 // #include <Geom_Curve.hxx>
56 // #include <Geom2d_Curve.hxx>
57 // #include <Handle_Geom2d_Curve.hxx>
58 // #include <Handle_Geom_Curve.hxx>
59 #include <gp_Pnt2d.hxx>
61 #include "utilities.h"
62 #include "Utils_ExceptHandlers.hxx"
66 static bool ComputePentahedralMesh(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape);
68 //=============================================================================
72 //=============================================================================
74 StdMeshers_Hexa_3D::StdMeshers_Hexa_3D(int hypId, int studyId,
75 SMESH_Gen * gen):SMESH_3D_Algo(hypId, studyId, gen)
77 MESSAGE("StdMeshers_Hexa_3D::StdMeshers_Hexa_3D");
79 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
82 //=============================================================================
86 //=============================================================================
88 StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D()
90 MESSAGE("StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D");
93 //================================================================================
95 * \brief Clear fields and return the argument
96 * \param res - the value to return
97 * \retval bool - the argument value
99 //================================================================================
101 bool StdMeshers_Hexa_3D::ClearAndReturn(FaceQuadStruct* theQuads[6], const bool res)
103 for (int i = 0; i < 6; i++) {
111 //=============================================================================
115 //=============================================================================
117 bool StdMeshers_Hexa_3D::CheckHypothesis
119 const TopoDS_Shape& aShape,
120 SMESH_Hypothesis::Hypothesis_Status& aStatus)
122 // check nb of faces in the shape
123 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
125 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 Unexpect aCatch(SalomeException);
182 MESSAGE("StdMeshers_Hexa_3D::Compute");
183 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
185 // 0. - shape and face mesh verification
186 // 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 SCRUTE(meshFaces.size());
200 // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
203 // tool for working with quadratic elements
204 SMESH_MesherHelper aTool (aMesh);
205 _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
208 typedef struct cubeStruct
218 faceQuadStruct* quad_X0;
219 faceQuadStruct* quad_X1;
220 faceQuadStruct* quad_Y0;
221 faceQuadStruct* quad_Y1;
222 faceQuadStruct* quad_Z0;
223 faceQuadStruct* quad_Z1;
224 Point3DStruct* np; // normalised 3D coordinates
230 FaceQuadStruct* aQuads[6];
231 for (int i = 0; i < 6; i++)
234 for (int i = 0; i < 6; i++) {
235 TopoDS_Shape aFace = meshFaces[i]->GetSubShape();
236 SMESH_Algo *algo = _gen->GetAlgo(aMesh, aFace);
237 string algoName = algo->GetName();
238 bool isAllQuad = false;
239 if (algoName == "Quadrangle_2D") {
240 SMESHDS_SubMesh * sm = meshDS->MeshElements( aFace );
243 SMDS_ElemIteratorPtr eIt = sm->GetElements();
244 while ( isAllQuad && eIt->more() ) {
245 const SMDS_MeshElement* elem = eIt->next();
246 isAllQuad = ( elem->NbNodes()==4 ||(_quadraticMesh && elem->NbNodes()==8) );
251 //modified by NIZNHY-PKV Wed Nov 17 15:31:37 2004 f
252 bool bIsOk = ComputePentahedralMesh(aMesh, aShape);
253 return ClearAndReturn( aQuads, bIsOk );
255 StdMeshers_Quadrangle_2D *quadAlgo =
256 dynamic_cast < StdMeshers_Quadrangle_2D * >(algo);
259 aQuads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aFace, _quadraticMesh);
261 catch(SALOME_Exception & S_ex) {
262 return ClearAndReturn( aQuads, false );
265 // 0.2.1 - number of points on the opposite edges must be the same
266 if (aQuads[i]->side[0]->NbPoints() != aQuads[i]->side[2]->NbPoints() ||
267 aQuads[i]->side[1]->NbPoints() != aQuads[i]->side[3]->NbPoints()
268 /*aQuads[i]->side[0]->NbEdges() != 1 ||
269 aQuads[i]->side[1]->NbEdges() != 1 ||
270 aQuads[i]->side[2]->NbEdges() != 1 ||
271 aQuads[i]->side[3]->NbEdges() != 1*/) {
272 MESSAGE("different number of points on the opposite edges of face " << i);
275 // Try to go into penta algorithm 'cause it has been improved.
276 // return ClearAndReturn( aQuads, false );
277 bool bIsOk = ComputePentahedralMesh(aMesh, aShape);
278 return ClearAndReturn( aQuads, bIsOk );
283 // 1. - identify faces and vertices of the "cube"
284 // 1.1 - ancestor maps vertex->edges in the cube
287 TopTools_IndexedDataMapOfShapeListOfShape MS;
288 TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
290 // 1.2 - first face is choosen as face Y=0 of the unit cube
293 const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
294 const TopoDS_Face & F = TopoDS::Face(aFace);
296 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
299 aCube.V000 = aQuads[0]->side[0]->FirstVertex(); // will be (0,0,0) on the unit cube
300 aCube.V100 = aQuads[0]->side[0]->LastVertex(); // will be (1,0,0) on the unit cube
301 aCube.V001 = aQuads[0]->side[2]->FirstVertex(); // will be (0,0,1) on the unit cube
302 aCube.V101 = aQuads[0]->side[2]->LastVertex(); // will be (1,0,1) on the unit cube
304 // 1.4 - find edge X=0, Z=0 (ancestor of V000 not in face Y=0)
305 // - find edge X=1, Z=0 (ancestor of V100 not in face Y=0)
306 // - find edge X=1, Z=1 (ancestor of V101 not in face Y=0)
307 // - find edge X=0, Z=1 (ancestor of V001 not in face Y=0)
310 // TopoDS_Edge E_0Y0 = EdgeNotInFace(aMesh, aShape, F, aCube.V000, MS);
311 // ASSERT(!E_0Y0.IsNull());
313 // TopoDS_Edge E_1Y0 = EdgeNotInFace(aMesh, aShape, F, aCube.V100, MS);
314 // ASSERT(!E_1Y0.IsNull());
316 // TopoDS_Edge E_1Y1 = EdgeNotInFace(aMesh, aShape, F, aCube.V101, MS);
317 // ASSERT(!E_1Y1.IsNull());
319 // TopoDS_Edge E_0Y1 = EdgeNotInFace(aMesh, aShape, F, aCube.V001, MS);
320 // ASSERT(!E_0Y1.IsNull());
322 // 1.5 - identify the 4 vertices in face Y=1: V010, V110, V111, V011
325 TopTools_IndexedMapOfShape MV0;
326 TopExp::MapShapes(F, TopAbs_VERTEX, MV0);
328 aCube.V010 = OppositeVertex( aCube.V000, MV0, aQuads);
329 aCube.V110 = OppositeVertex( aCube.V100, MV0, aQuads);
330 aCube.V011 = OppositeVertex( aCube.V001, MV0, aQuads);
331 aCube.V111 = OppositeVertex( aCube.V101, MV0, aQuads);
333 // TopoDS_Vertex VFirst, VLast;
334 // TopExp::Vertices(E_0Y0, VFirst, VLast);
335 // if (VFirst.IsSame(aCube.V000))
336 // aCube.V010 = VLast;
338 // aCube.V010 = VFirst;
340 // TopExp::Vertices(E_1Y0, VFirst, VLast);
341 // if (VFirst.IsSame(aCube.V100))
342 // aCube.V110 = VLast;
344 // aCube.V110 = VFirst;
346 // TopExp::Vertices(E_1Y1, VFirst, VLast);
347 // if (VFirst.IsSame(aCube.V101))
348 // aCube.V111 = VLast;
350 // aCube.V111 = VFirst;
352 // TopExp::Vertices(E_0Y1, VFirst, VLast);
353 // if (VFirst.IsSame(aCube.V001))
354 // aCube.V011 = VLast;
356 // aCube.V011 = VFirst;
358 // 1.6 - find remaining faces given 4 vertices
362 aCube.quad_Y0 = aQuads[_indY0];
364 int _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
365 aCube.V010, aCube.V011, aCube.V110, aCube.V111);
366 aCube.quad_Y1 = aQuads[_indY1];
368 int _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
369 aCube.V000, aCube.V010, aCube.V100, aCube.V110);
370 aCube.quad_Z0 = aQuads[_indZ0];
372 int _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
373 aCube.V001, aCube.V011, aCube.V101, aCube.V111);
374 aCube.quad_Z1 = aQuads[_indZ1];
376 int _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
377 aCube.V000, aCube.V001, aCube.V010, aCube.V011);
378 aCube.quad_X0 = aQuads[_indX0];
380 int _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
381 aCube.V100, aCube.V101, aCube.V110, aCube.V111);
382 aCube.quad_X1 = aQuads[_indX1];
386 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
388 Conv2DStruct cx0; // for face X=0
389 Conv2DStruct cx1; // for face X=1
395 GetConv2DCoefs(*aCube.quad_X0, meshFaces[_indX0]->GetSubShape(),
396 aCube.V000, aCube.V010, aCube.V011, aCube.V001, cx0);
397 GetConv2DCoefs(*aCube.quad_X1, meshFaces[_indX1]->GetSubShape(),
398 aCube.V100, aCube.V110, aCube.V111, aCube.V101, cx1);
399 GetConv2DCoefs(*aCube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
400 aCube.V000, aCube.V100, aCube.V101, aCube.V001, cy0);
401 GetConv2DCoefs(*aCube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
402 aCube.V010, aCube.V110, aCube.V111, aCube.V011, cy1);
403 GetConv2DCoefs(*aCube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
404 aCube.V000, aCube.V100, aCube.V110, aCube.V010, cz0);
405 GetConv2DCoefs(*aCube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
406 aCube.V001, aCube.V101, aCube.V111, aCube.V011, cz1);
408 // 1.8 - create a 3D structure for normalized values
411 int nbx = aCube.quad_Z0->side[0]->NbPoints();
412 if (cz0.a1 == 0.) nbx = aCube.quad_Z0->side[1]->NbPoints();
414 int nby = aCube.quad_X0->side[0]->NbPoints();
415 if (cx0.a1 == 0.) nby = aCube.quad_X0->side[1]->NbPoints();
417 int nbz = aCube.quad_Y0->side[0]->NbPoints();
418 if (cy0.a1 != 0.) nbz = aCube.quad_Y0->side[1]->NbPoints();
420 int i1, j1, nbxyz = nbx * nby * nbz;
421 Point3DStruct *np = new Point3DStruct[nbxyz];
423 // 1.9 - store node indexes of faces
426 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
428 faceQuadStruct *quad = aCube.quad_X0;
429 int i = 0; // j = x/face , k = y/face
430 int nbdown = quad->side[0]->NbPoints();
431 int nbright = quad->side[1]->NbPoints();
433 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
436 const SMDS_MeshNode * node = itf->next();
437 if(aTool.IsMedium(node))
439 if ( !findIJ( node, quad, i1, j1 ))
440 return ClearAndReturn( aQuads, false );
441 int ij1 = j1 * nbdown + i1;
442 quad->uv_grid[ij1].node = node;
445 for (int i1 = 0; i1 < nbdown; i1++)
446 for (int j1 = 0; j1 < nbright; j1++) {
447 int ij1 = j1 * nbdown + i1;
448 int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic; // j = x/face
449 int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc; // k = y/face
450 int ijk = k * nbx * nby + j * nbx + i;
451 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
452 np[ijk].node = quad->uv_grid[ij1].node;
453 //SCRUTE(np[ijk].nodeId);
458 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
460 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
462 faceQuadStruct *quad = aCube.quad_X1;
463 int i = nbx - 1; // j = x/face , k = y/face
464 int nbdown = quad->side[0]->NbPoints();
465 int nbright = quad->side[1]->NbPoints();
468 const SMDS_MeshNode * node = itf->next();
469 if(aTool.IsMedium(node))
471 if ( !findIJ( node, quad, i1, j1 ))
472 return ClearAndReturn( aQuads, false );
473 int ij1 = j1 * nbdown + i1;
474 quad->uv_grid[ij1].node = node;
477 for (int i1 = 0; i1 < nbdown; i1++)
478 for (int j1 = 0; j1 < nbright; j1++) {
479 int ij1 = j1 * nbdown + i1;
480 int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic; // j = x/face
481 int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc; // k = y/face
482 int ijk = k * nbx * nby + j * nbx + i;
483 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
484 np[ijk].node = quad->uv_grid[ij1].node;
485 //SCRUTE(np[ijk].nodeId);
490 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
492 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
494 faceQuadStruct *quad = aCube.quad_Y0;
495 int j = 0; // i = x/face , k = y/face
496 int nbdown = quad->side[0]->NbPoints();
497 int nbright = quad->side[1]->NbPoints();
500 const SMDS_MeshNode * node = itf->next();
501 if(aTool.IsMedium(node))
503 if ( !findIJ( node, quad, i1, j1 ))
504 return ClearAndReturn( aQuads, false );
505 int ij1 = j1 * nbdown + i1;
506 quad->uv_grid[ij1].node = node;
509 for (int i1 = 0; i1 < nbdown; i1++)
510 for (int j1 = 0; j1 < nbright; j1++) {
511 int ij1 = j1 * nbdown + i1;
512 int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic; // i = x/face
513 int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc; // k = y/face
514 int ijk = k * nbx * nby + j * nbx + i;
515 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
516 np[ijk].node = quad->uv_grid[ij1].node;
517 //SCRUTE(np[ijk].nodeId);
522 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
524 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
526 faceQuadStruct *quad = aCube.quad_Y1;
527 int j = nby - 1; // i = x/face , k = y/face
528 int nbdown = quad->side[0]->NbPoints();
529 int nbright = quad->side[1]->NbPoints();
532 const SMDS_MeshNode * node = itf->next();
533 if(aTool.IsMedium(node))
535 if ( !findIJ( node, quad, i1, j1 ))
536 return ClearAndReturn( aQuads, false );
537 int ij1 = j1 * nbdown + i1;
538 quad->uv_grid[ij1].node = node;
541 for (int i1 = 0; i1 < nbdown; i1++)
542 for (int j1 = 0; j1 < nbright; j1++) {
543 int ij1 = j1 * nbdown + i1;
544 int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic; // i = x/face
545 int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc; // k = y/face
546 int ijk = k * nbx * nby + j * nbx + i;
547 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
548 np[ijk].node = quad->uv_grid[ij1].node;
549 //SCRUTE(np[ijk].nodeId);
554 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
556 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
558 faceQuadStruct *quad = aCube.quad_Z0;
559 int k = 0; // i = x/face , j = y/face
560 int nbdown = quad->side[0]->NbPoints();
561 int nbright = quad->side[1]->NbPoints();
564 const SMDS_MeshNode * node = itf->next();
565 if(aTool.IsMedium(node))
567 if ( !findIJ( node, quad, i1, j1 ))
568 return ClearAndReturn( aQuads, false );
569 int ij1 = j1 * nbdown + i1;
570 quad->uv_grid[ij1].node = node;
573 for (int i1 = 0; i1 < nbdown; i1++)
574 for (int j1 = 0; j1 < nbright; j1++) {
575 int ij1 = j1 * nbdown + i1;
576 int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic; // i = x/face
577 int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc; // j = y/face
578 int ijk = k * nbx * nby + j * nbx + i;
579 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
580 np[ijk].node = quad->uv_grid[ij1].node;
581 //SCRUTE(np[ijk].nodeId);
586 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
588 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
590 faceQuadStruct *quad = aCube.quad_Z1;
591 int k = nbz - 1; // i = x/face , j = y/face
592 int nbdown = quad->side[0]->NbPoints();
593 int nbright = quad->side[1]->NbPoints();
596 const SMDS_MeshNode * node = itf->next();
597 if(aTool.IsMedium(node))
599 if ( !findIJ( node, quad, i1, j1 ))
600 return ClearAndReturn( aQuads, false );
601 int ij1 = j1 * nbdown + i1;
602 quad->uv_grid[ij1].node = node;
605 for (int i1 = 0; i1 < nbdown; i1++)
606 for (int j1 = 0; j1 < nbright; j1++) {
607 int ij1 = j1 * nbdown + i1;
608 int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic; // i = x/face
609 int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc; // j = y/face
610 int ijk = k * nbx * nby + j * nbx + i;
611 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
612 np[ijk].node = quad->uv_grid[ij1].node;
613 //SCRUTE(np[ijk].nodeId);
617 // 2.0 - for each node of the cube:
618 // - get the 8 points 3D = 8 vertices of the cube
619 // - get the 12 points 3D on the 12 edges of the cube
620 // - get the 6 points 3D on the 6 faces with their ID
621 // - compute the point 3D
622 // - store the point 3D in SMESHDS, store its ID in 3D structure
624 int shapeID = meshDS->ShapeToIndex( aShape );
626 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
627 Pt3 px00, px01, px10, px11;
628 Pt3 p0y0, p0y1, p1y0, p1y1;
629 Pt3 p00z, p01z, p10z, p11z;
630 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
632 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
633 GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
634 GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
635 GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
636 GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
637 GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
638 GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
639 GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
641 for (int i = 1; i < nbx - 1; i++) {
642 for (int j = 1; j < nby - 1; j++) {
643 for (int k = 1; k < nbz - 1; k++) {
644 // *** seulement maillage regulier
645 // 12 points on edges
646 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
647 GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
648 GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
649 GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
651 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
652 GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
653 GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
654 GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
656 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
657 GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
658 GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
659 GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
661 // 12 points on faces
662 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
663 GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
664 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
665 GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
666 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
667 GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
669 int ijk = k * nbx * nby + j * nbx + i;
670 double x = double (i) / double (nbx - 1); // *** seulement
671 double y = double (j) / double (nby - 1); // *** maillage
672 double z = double (k) / double (nbz - 1); // *** regulier
675 for (int i = 0; i < 3; i++) {
676 X[i] = (1 - x) * p0yz[i] + x * p1yz[i]
677 + (1 - y) * px0z[i] + y * px1z[i]
678 + (1 - z) * pxy0[i] + z * pxy1[i]
679 - (1 - x) * ((1 - y) * p00z[i] + y * p01z[i])
680 - x * ((1 - y) * p10z[i] + y * p11z[i])
681 - (1 - y) * ((1 - z) * px00[i] + z * px01[i])
682 - y * ((1 - z) * px10[i] + z * px11[i])
683 - (1 - z) * ((1 - x) * p0y0[i] + x * p1y0[i])
684 - z * ((1 - x) * p0y1[i] + x * p1y1[i])
685 + (1 - x) * ((1 - y) * ((1 - z) * p000[i] + z * p001[i])
686 + y * ((1 - z) * p010[i] + z * p011[i]))
687 + x * ((1 - y) * ((1 - z) * p100[i] + z * p101[i])
688 + y * ((1 - z) * p110[i] + z * p111[i]));
691 SMDS_MeshNode * node = meshDS->AddNode(X[0], X[1], X[2]);
693 meshDS->SetNodeInVolume(node, shapeID);
698 // find orientation of furute volumes according to MED convention
699 vector< bool > forward( nbx * nby );
700 SMDS_VolumeTool vTool;
701 for (int i = 0; i < nbx - 1; i++) {
702 for (int j = 0; j < nby - 1; j++) {
703 int n1 = j * nbx + i;
704 int n2 = j * nbx + i + 1;
705 int n3 = (j + 1) * nbx + i + 1;
706 int n4 = (j + 1) * nbx + i;
707 int n5 = nbx * nby + j * nbx + i;
708 int n6 = nbx * nby + j * nbx + i + 1;
709 int n7 = nbx * nby + (j + 1) * nbx + i + 1;
710 int n8 = nbx * nby + (j + 1) * nbx + i;
712 SMDS_VolumeOfNodes tmpVol (np[n1].node,np[n2].node,np[n3].node,np[n4].node,
713 np[n5].node,np[n6].node,np[n7].node,np[n8].node);
714 vTool.Set( &tmpVol );
715 forward[ n1 ] = vTool.IsForward();
719 //2.1 - for each node of the cube (less 3 *1 Faces):
720 // - store hexahedron in SMESHDS
721 MESSAGE("Storing hexahedron into the DS");
722 for (int i = 0; i < nbx - 1; i++) {
723 for (int j = 0; j < nby - 1; j++) {
724 bool isForw = forward.at( j * nbx + i );
725 for (int k = 0; k < nbz - 1; k++) {
726 int n1 = k * nbx * nby + j * nbx + i;
727 int n2 = k * nbx * nby + j * nbx + i + 1;
728 int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
729 int n4 = k * nbx * nby + (j + 1) * nbx + i;
730 int n5 = (k + 1) * nbx * nby + j * nbx + i;
731 int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
732 int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
733 int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
735 SMDS_MeshVolume * elt;
737 //elt = meshDS->AddVolume(np[n1].node, np[n2].node,
738 // np[n3].node, np[n4].node,
739 // np[n5].node, np[n6].node,
740 // np[n7].node, np[n8].node);
741 elt = aTool.AddVolume(np[n1].node, np[n2].node,
742 np[n3].node, np[n4].node,
743 np[n5].node, np[n6].node,
744 np[n7].node, np[n8].node);
747 //elt = meshDS->AddVolume(np[n1].node, np[n4].node,
748 // np[n3].node, np[n2].node,
749 // np[n5].node, np[n8].node,
750 // np[n7].node, np[n6].node);
751 elt = aTool.AddVolume(np[n1].node, np[n4].node,
752 np[n3].node, np[n2].node,
753 np[n5].node, np[n8].node,
754 np[n7].node, np[n6].node);
757 meshDS->SetMeshElementOnShape(elt, shapeID);
761 if ( np ) delete [] np;
762 //MESSAGE("End of StdMeshers_Hexa_3D::Compute()");
763 return ClearAndReturn( aQuads, true );
766 //=============================================================================
770 //=============================================================================
772 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby,
773 int nbz, Point3DStruct * np, const SMESHDS_Mesh * meshDS)
775 int ijk = k * nbx * nby + j * nbx + i;
776 const SMDS_MeshNode * node = np[ijk].node;
780 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
783 //=============================================================================
787 //=============================================================================
789 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
790 const TopoDS_Shape & aShape,
791 const vector < SMESH_subMesh * >&meshFaces,
792 const TopoDS_Vertex & V0,
793 const TopoDS_Vertex & V1,
794 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
796 //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
798 for (int i = 1; i < 6; i++)
800 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
801 //const TopoDS_Face& F = TopoDS::Face(aFace);
802 TopTools_IndexedMapOfShape M;
803 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
804 bool verticesInShape = false;
809 verticesInShape = true;
816 ASSERT(faceIndex > 0);
821 //=============================================================================
825 //=============================================================================
828 StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
829 const TopoDS_Shape & aShape,
830 const TopoDS_Face & aFace,
831 const TopoDS_Vertex & aVertex,
832 const TopTools_IndexedDataMapOfShapeListOfShape & MS)
834 //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
835 TopTools_IndexedDataMapOfShapeListOfShape MF;
836 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
837 const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
838 const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
839 // SCRUTE(ancestorsInSolid.Extent());
840 // SCRUTE(ancestorsInFace.Extent());
841 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
842 ASSERT(ancestorsInFace.Extent() == 2);
846 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
847 for (; its.More(); its.Next())
849 TopoDS_Shape ancestor = its.Value();
850 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
851 bool isInFace = false;
852 for (; itf.More(); itf.Next())
854 TopoDS_Shape ancestorInFace = itf.Value();
855 if (ancestorInFace.IsSame(ancestor))
863 E = TopoDS::Edge(ancestor);
870 //=============================================================================
874 //=============================================================================
876 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
877 const TopoDS_Shape & aShape,
878 const TopoDS_Vertex & V0,
879 const TopoDS_Vertex & V1,
880 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
882 // MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
883 // const TopoDS_Face & F = TopoDS::Face(aShape);
884 // TopoDS_Edge E = quad.edge[0];
886 // Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
887 // TopoDS_Vertex VFirst, VLast;
888 // TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
889 // bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
890 TopoDS_Vertex VA, VB;
901 VA = quad.side[0]->FirstVertex();
902 VB = quad.side[0]->LastVertex();
904 int a1, b1, c1, a2, b2, c2;
917 ASSERT(VB.IsSame(V3));
937 ASSERT(VB.IsSame(V0));
957 ASSERT(VB.IsSame(V1));
977 ASSERT(VB.IsSame(V2));
985 // MESSAGE("X = " << c1 << "+ " << a1 << "*x + " << b1 << "*y");
986 // MESSAGE("Y = " << c2 << "+ " << a2 << "*x + " << b2 << "*y");
994 int nbdown = quad.side[0]->NbPoints();
995 int nbright = quad.side[1]->NbPoints();
999 int (c1 * a1 * a1) * (nbdown - 1) + int (c1 * b1 * b1) * (nbright - 1);
1003 int (c2 * a2 * a2) * (nbdown - 1) + int (c2 * b2 * b2) * (nbright - 1);
1004 // MESSAGE("I " << conv.ia << " " << conv.ib << " " << conv.ic);
1005 // MESSAGE("J " << conv.ja << " " << conv.jb << " " << conv.jc);
1008 //================================================================================
1010 * \brief Find a vertex opposite to the given vertex of aQuads[0]
1011 * \param aVertex - the vertex
1012 * \param aFace - the face aVertex belongs to
1013 * \param aQuads - quads
1014 * \retval TopoDS_Vertex - found vertex
1016 //================================================================================
1018 TopoDS_Vertex StdMeshers_Hexa_3D::OppositeVertex(const TopoDS_Vertex& aVertex,
1019 const TopTools_IndexedMapOfShape& aQuads0Vertices,
1020 FaceQuadStruct* aQuads[6])
1023 for ( i = 1; i < 6; ++i )
1025 TopoDS_Vertex VV[] = { aQuads[i]->side[0]->FirstVertex(),
1026 aQuads[i]->side[0]->LastVertex() ,
1027 aQuads[i]->side[2]->LastVertex() ,
1028 aQuads[i]->side[2]->FirstVertex() };
1029 for ( j = 0; j < 4; ++j )
1030 if ( aVertex.IsSame( VV[ j ]))
1033 int jPrev = j ? j - 1 : 3;
1034 int jNext = (j + 1) % 4;
1035 if ( aQuads0Vertices.Contains( VV[ jPrev ] ))
1041 return TopoDS_Vertex();
1044 //modified by NIZNHY-PKV Wed Nov 17 15:34:13 2004 f
1045 ///////////////////////////////////////////////////////////////////////////////
1047 //#include <stdio.h>
1049 //=======================================================================
1050 //function : ComputePentahedralMesh
1052 //=======================================================================
1053 bool ComputePentahedralMesh(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
1055 //printf(" ComputePentahedralMesh HERE\n");
1059 StdMeshers_Penta_3D anAlgo;
1061 bOK=anAlgo.Compute(aMesh, aShape);
1063 if ( !bOK && anAlgo.ErrorStatus() == 5 )
1065 static StdMeshers_Prism_3D * aPrism3D = 0;
1067 SMESH_Gen* gen = aMesh.GetGen();
1068 aPrism3D = new StdMeshers_Prism_3D( gen->GetANewId(), 0, gen );
1070 SMESH_Hypothesis::Hypothesis_Status aStatus;
1071 if ( aPrism3D->CheckHypothesis( aMesh, aShape, aStatus ) )
1072 bOK = aPrism3D->Compute( aMesh, aShape );