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
31 #include "StdMeshers_Hexa_3D.hxx"
32 #include "StdMeshers_Quadrangle_2D.hxx"
33 #include "SMESH_Gen.hxx"
34 #include "SMESH_Mesh.hxx"
35 #include "SMESH_subMesh.hxx"
37 #include "SMDS_MeshElement.hxx"
38 #include "SMDS_MeshNode.hxx"
39 #include "SMDS_FacePosition.hxx"
40 #include "SMDS_VolumeTool.hxx"
41 #include "SMDS_VolumeOfNodes.hxx"
44 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
45 #include <TopTools_ListOfShape.hxx>
46 #include <TopTools_ListIteratorOfListOfShape.hxx>
47 #include <TColStd_ListIteratorOfListOfInteger.hxx>
48 #include <TColStd_MapOfInteger.hxx>
50 #include <BRep_Tool.hxx>
51 #include <Geom_Surface.hxx>
52 #include <Geom_Curve.hxx>
53 #include <Geom2d_Curve.hxx>
54 #include <Handle_Geom2d_Curve.hxx>
55 #include <Handle_Geom_Curve.hxx>
56 #include <gp_Pnt2d.hxx>
58 #include "utilities.h"
59 #include "Utils_ExceptHandlers.hxx"
61 //modified by NIZNHY-PKV Wed Nov 17 15:31:58 2004 f
62 #include "StdMeshers_Penta_3D.hxx"
64 static bool ComputePentahedralMesh(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape);
65 //modified by NIZNHY-PKV Wed Nov 17 15:32:00 2004 t
67 //=============================================================================
71 //=============================================================================
73 StdMeshers_Hexa_3D::StdMeshers_Hexa_3D(int hypId, int studyId,
74 SMESH_Gen * gen):SMESH_3D_Algo(hypId, studyId, gen)
76 MESSAGE("StdMeshers_Hexa_3D::StdMeshers_Hexa_3D");
78 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
81 //=============================================================================
85 //=============================================================================
87 StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D()
89 MESSAGE("StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D");
92 //================================================================================
94 * \brief Clear fields and return the argument
95 * \param res - the value to return
96 * \retval bool - the argument value
98 //================================================================================
100 bool StdMeshers_Hexa_3D::ClearAndReturn(FaceQuadStruct* theQuads[6], const bool res)
102 for (int i = 0; i < 6; i++) {
103 StdMeshers_Quadrangle_2D::QuadDelete(theQuads[i]);
110 //=============================================================================
114 //=============================================================================
116 bool StdMeshers_Hexa_3D::CheckHypothesis
118 const TopoDS_Shape& aShape,
119 SMESH_Hypothesis::Hypothesis_Status& aStatus)
121 //MESSAGE("StdMeshers_Hexa_3D::CheckHypothesis");
124 aStatus = SMESH_Hypothesis::HYP_OK;
131 //=======================================================================
133 //purpose : return i,j of the node
134 //=======================================================================
136 static bool findIJ (const SMDS_MeshNode* node, const FaceQuadStruct * quad, int& I, int& J)
139 const SMDS_FacePosition* fpos =
140 static_cast<const SMDS_FacePosition*>(node->GetPosition().get());
141 if ( ! fpos ) return false;
142 gp_Pnt2d uv( fpos->GetUParameter(), fpos->GetVParameter() );
144 double minDist = DBL_MAX;
145 int nbhoriz = Min(quad->nbPts[0], quad->nbPts[2]);
146 int nbvertic = Min(quad->nbPts[1], quad->nbPts[3]);
147 for (int i = 1; i < nbhoriz - 1; i++) {
148 for (int j = 1; j < nbvertic - 1; j++) {
149 int ij = j * nbhoriz + i;
150 gp_Pnt2d uv2( quad->uv_grid[ij].u, quad->uv_grid[ij].v );
151 double dist = uv.SquareDistance( uv2 );
152 if ( dist < minDist ) {
163 //=============================================================================
165 * Hexahedron mesh on hexaedron like form
166 * -0. - shape and face mesh verification
167 * -1. - identify faces and vertices of the "cube"
168 * -2. - Algorithm from:
169 * "Application de l'interpolation transfinie à la création de maillages
170 * C0 ou G1 continus sur des triangles, quadrangles, tetraedres, pentaedres
171 * et hexaedres déformés."
172 * Alain PERONNET - 8 janvier 1999
174 //=============================================================================
176 bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh & aMesh,
177 const TopoDS_Shape & aShape)throw(SALOME_Exception)
179 Unexpect aCatch(SalomeException);
180 MESSAGE("StdMeshers_Hexa_3D::Compute");
181 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
183 // 0. - shape and face mesh verification
184 // 0.1 - shape must be a solid (or a shell) with 6 faces
187 vector < SMESH_subMesh * >meshFaces;
188 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
189 SMESH_subMesh *aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
191 meshFaces.push_back(aSubMesh);
193 if (meshFaces.size() != 6) {
194 SCRUTE(meshFaces.size());
198 // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
201 // tool for working with quadratic elements
202 SMESH_MesherHelper aTool (aMesh);
203 _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
206 typedef struct cubeStruct
216 faceQuadStruct* quad_X0;
217 faceQuadStruct* quad_X1;
218 faceQuadStruct* quad_Y0;
219 faceQuadStruct* quad_Y1;
220 faceQuadStruct* quad_Z0;
221 faceQuadStruct* quad_Z1;
222 Point3DStruct* np; // normalised 3D coordinates
228 FaceQuadStruct* aQuads[6];
229 for (int i = 0; i < 6; i++)
232 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 //modified by NIZNHY-PKV Wed Nov 17 15:31:37 2004 f
250 bool bIsOk = ComputePentahedralMesh(aMesh, aShape);
251 return ClearAndReturn( aQuads, bIsOk );
253 StdMeshers_Quadrangle_2D *quadAlgo =
254 dynamic_cast < StdMeshers_Quadrangle_2D * >(algo);
257 aQuads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aFace, _quadraticMesh);
259 catch(SALOME_Exception & S_ex) {
260 return ClearAndReturn( aQuads, false );
263 // 0.2.1 - number of points on the opposite edges must be the same
264 if (aQuads[i]->nbPts[0] != aQuads[i]->nbPts[2] ||
265 aQuads[i]->nbPts[1] != aQuads[i]->nbPts[3]) {
266 MESSAGE("different number of points on the opposite edges of face " << i);
269 // Try to go into penta algorithm 'cause it has been improved.
270 // return ClearAndReturn( aQuads, false );
271 bool bIsOk = ComputePentahedralMesh(aMesh, aShape);
272 return ClearAndReturn( aQuads, bIsOk );
277 // 1. - identify faces and vertices of the "cube"
278 // 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
287 const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
288 const TopoDS_Face & F = TopoDS::Face(aFace);
290 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
294 TopoDS_Edge E = aQuads[0]->edge[i]; //edge will be Y=0,Z=0 on unit cube
296 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
297 TopoDS_Vertex VFirst, VLast;
298 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
299 bool isForward = (((l - f) * (aQuads[0]->last[i] - aQuads[0]->first[i])) > 0);
302 aCube.V000 = VFirst; // will be (0,0,0) on the unit cube
303 aCube.V100 = VLast; // will be (1,0,0) on the unit cube
311 E = aQuads[0]->edge[i];
312 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
313 TopExp::Vertices(E, VFirst, VLast);
314 isForward = (((l - f) * (aQuads[0]->last[i] - aQuads[0]->first[i])) > 0);
316 aCube.V101 = VLast; // will be (1,0,1) on the unit cube
321 E = aQuads[0]->edge[i];
322 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
323 TopExp::Vertices(E, VFirst, VLast);
324 isForward = (((l - f) * (aQuads[0]->last[i] - aQuads[0]->first[i])) > 0);
326 aCube.V001 = VLast; // will be (0,0,1) on the unit cube
330 // 1.4 - find edge X=0, Z=0 (ancestor of V000 not in face Y=0)
331 // - find edge X=1, Z=0 (ancestor of V100 not in face Y=0)
332 // - find edge X=1, Z=1 (ancestor of V101 not in face Y=0)
333 // - find edge X=0, Z=1 (ancestor of V001 not in face Y=0)
336 TopoDS_Edge E_0Y0 = EdgeNotInFace(aMesh, aShape, F, aCube.V000, MS);
337 ASSERT(!E_0Y0.IsNull());
339 TopoDS_Edge E_1Y0 = EdgeNotInFace(aMesh, aShape, F, aCube.V100, MS);
340 ASSERT(!E_1Y0.IsNull());
342 TopoDS_Edge E_1Y1 = EdgeNotInFace(aMesh, aShape, F, aCube.V101, MS);
343 ASSERT(!E_1Y1.IsNull());
345 TopoDS_Edge E_0Y1 = EdgeNotInFace(aMesh, aShape, F, aCube.V001, MS);
346 ASSERT(!E_0Y1.IsNull());
348 // 1.5 - identify the 4 vertices in face Y=1: V010, V110, V111, V011
351 TopExp::Vertices(E_0Y0, VFirst, VLast);
352 if (VFirst.IsSame(aCube.V000))
357 TopExp::Vertices(E_1Y0, VFirst, VLast);
358 if (VFirst.IsSame(aCube.V100))
363 TopExp::Vertices(E_1Y1, VFirst, VLast);
364 if (VFirst.IsSame(aCube.V101))
369 TopExp::Vertices(E_0Y1, VFirst, VLast);
370 if (VFirst.IsSame(aCube.V001))
375 // 1.6 - find remaining faces given 4 vertices
379 aCube.quad_Y0 = aQuads[_indY0];
381 int _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
382 aCube.V010, aCube.V011, aCube.V110, aCube.V111);
383 aCube.quad_Y1 = aQuads[_indY1];
385 int _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
386 aCube.V000, aCube.V010, aCube.V100, aCube.V110);
387 aCube.quad_Z0 = aQuads[_indZ0];
389 int _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
390 aCube.V001, aCube.V011, aCube.V101, aCube.V111);
391 aCube.quad_Z1 = aQuads[_indZ1];
393 int _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
394 aCube.V000, aCube.V001, aCube.V010, aCube.V011);
395 aCube.quad_X0 = aQuads[_indX0];
397 int _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
398 aCube.V100, aCube.V101, aCube.V110, aCube.V111);
399 aCube.quad_X1 = aQuads[_indX1];
403 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
405 Conv2DStruct cx0; // for face X=0
406 Conv2DStruct cx1; // for face X=1
412 GetConv2DCoefs(*aCube.quad_X0, meshFaces[_indX0]->GetSubShape(),
413 aCube.V000, aCube.V010, aCube.V011, aCube.V001, cx0);
414 GetConv2DCoefs(*aCube.quad_X1, meshFaces[_indX1]->GetSubShape(),
415 aCube.V100, aCube.V110, aCube.V111, aCube.V101, cx1);
416 GetConv2DCoefs(*aCube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
417 aCube.V000, aCube.V100, aCube.V101, aCube.V001, cy0);
418 GetConv2DCoefs(*aCube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
419 aCube.V010, aCube.V110, aCube.V111, aCube.V011, cy1);
420 GetConv2DCoefs(*aCube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
421 aCube.V000, aCube.V100, aCube.V110, aCube.V010, cz0);
422 GetConv2DCoefs(*aCube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
423 aCube.V001, aCube.V101, aCube.V111, aCube.V011, cz1);
425 // 1.8 - create a 3D structure for normalized values
428 int nbx = aCube.quad_Z0->nbPts[0];
429 if (cz0.a1 == 0.) nbx = aCube.quad_Z0->nbPts[1];
431 int nby = aCube.quad_X0->nbPts[0];
432 if (cx0.a1 == 0.) nby = aCube.quad_X0->nbPts[1];
434 int nbz = aCube.quad_Y0->nbPts[0];
435 if (cy0.a1 != 0.) nbz = aCube.quad_Y0->nbPts[1];
437 int i1, j1, nbxyz = nbx * nby * nbz;
438 Point3DStruct *np = new Point3DStruct[nbxyz];
440 // 1.9 - store node indexes of faces
443 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
445 faceQuadStruct *quad = aCube.quad_X0;
446 int i = 0; // j = x/face , k = y/face
447 int nbdown = quad->nbPts[0];
448 int nbright = quad->nbPts[1];
450 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
453 const SMDS_MeshNode * node = itf->next();
454 if(aTool.IsMedium(node))
456 findIJ( node, quad, i1, j1 );
457 int ij1 = j1 * nbdown + i1;
458 quad->uv_grid[ij1].node = node;
461 for (int i1 = 0; i1 < nbdown; i1++)
462 for (int j1 = 0; j1 < nbright; j1++) {
463 int ij1 = j1 * nbdown + i1;
464 int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic; // j = x/face
465 int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc; // k = y/face
466 int ijk = k * nbx * nby + j * nbx + i;
467 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
468 np[ijk].node = quad->uv_grid[ij1].node;
469 //SCRUTE(np[ijk].nodeId);
474 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
476 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
478 faceQuadStruct *quad = aCube.quad_X1;
479 int i = nbx - 1; // j = x/face , k = y/face
480 int nbdown = quad->nbPts[0];
481 int nbright = quad->nbPts[1];
484 const SMDS_MeshNode * node = itf->next();
485 if(aTool.IsMedium(node))
487 findIJ( node, quad, i1, j1 );
488 int ij1 = j1 * nbdown + i1;
489 quad->uv_grid[ij1].node = node;
492 for (int i1 = 0; i1 < nbdown; i1++)
493 for (int j1 = 0; j1 < nbright; j1++) {
494 int ij1 = j1 * nbdown + i1;
495 int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic; // j = x/face
496 int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc; // k = y/face
497 int ijk = k * nbx * nby + j * nbx + i;
498 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
499 np[ijk].node = quad->uv_grid[ij1].node;
500 //SCRUTE(np[ijk].nodeId);
505 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
507 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
509 faceQuadStruct *quad = aCube.quad_Y0;
510 int j = 0; // i = x/face , k = y/face
511 int nbdown = quad->nbPts[0];
512 int nbright = quad->nbPts[1];
515 const SMDS_MeshNode * node = itf->next();
516 if(aTool.IsMedium(node))
518 findIJ( node, quad, i1, j1 );
519 int ij1 = j1 * nbdown + i1;
520 quad->uv_grid[ij1].node = node;
523 for (int i1 = 0; i1 < nbdown; i1++)
524 for (int j1 = 0; j1 < nbright; j1++) {
525 int ij1 = j1 * nbdown + i1;
526 int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic; // i = x/face
527 int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc; // k = y/face
528 int ijk = k * nbx * nby + j * nbx + i;
529 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
530 np[ijk].node = quad->uv_grid[ij1].node;
531 //SCRUTE(np[ijk].nodeId);
536 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
538 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
540 faceQuadStruct *quad = aCube.quad_Y1;
541 int j = nby - 1; // i = x/face , k = y/face
542 int nbdown = quad->nbPts[0];
543 int nbright = quad->nbPts[1];
546 const SMDS_MeshNode * node = itf->next();
547 if(aTool.IsMedium(node))
549 findIJ( node, quad, i1, j1 );
550 int ij1 = j1 * nbdown + i1;
551 quad->uv_grid[ij1].node = node;
554 for (int i1 = 0; i1 < nbdown; i1++)
555 for (int j1 = 0; j1 < nbright; j1++) {
556 int ij1 = j1 * nbdown + i1;
557 int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic; // i = x/face
558 int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc; // k = y/face
559 int ijk = k * nbx * nby + j * nbx + i;
560 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
561 np[ijk].node = quad->uv_grid[ij1].node;
562 //SCRUTE(np[ijk].nodeId);
567 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
569 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
571 faceQuadStruct *quad = aCube.quad_Z0;
572 int k = 0; // i = x/face , j = y/face
573 int nbdown = quad->nbPts[0];
574 int nbright = quad->nbPts[1];
577 const SMDS_MeshNode * node = itf->next();
578 if(aTool.IsMedium(node))
580 findIJ( node, quad, i1, j1 );
581 int ij1 = j1 * nbdown + i1;
582 quad->uv_grid[ij1].node = node;
585 for (int i1 = 0; i1 < nbdown; i1++)
586 for (int j1 = 0; j1 < nbright; j1++) {
587 int ij1 = j1 * nbdown + i1;
588 int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic; // i = x/face
589 int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc; // j = y/face
590 int ijk = k * nbx * nby + j * nbx + i;
591 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
592 np[ijk].node = quad->uv_grid[ij1].node;
593 //SCRUTE(np[ijk].nodeId);
598 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
600 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
602 faceQuadStruct *quad = aCube.quad_Z1;
603 int k = nbz - 1; // i = x/face , j = y/face
604 int nbdown = quad->nbPts[0];
605 int nbright = quad->nbPts[1];
608 const SMDS_MeshNode * node = itf->next();
609 if(aTool.IsMedium(node))
611 findIJ( node, quad, i1, j1 );
612 int ij1 = j1 * nbdown + i1;
613 quad->uv_grid[ij1].node = node;
616 for (int i1 = 0; i1 < nbdown; i1++)
617 for (int j1 = 0; j1 < nbright; j1++) {
618 int ij1 = j1 * nbdown + i1;
619 int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic; // i = x/face
620 int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc; // j = y/face
621 int ijk = k * nbx * nby + j * nbx + i;
622 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
623 np[ijk].node = quad->uv_grid[ij1].node;
624 //SCRUTE(np[ijk].nodeId);
628 // 2.0 - for each node of the cube:
629 // - get the 8 points 3D = 8 vertices of the cube
630 // - get the 12 points 3D on the 12 edges of the cube
631 // - get the 6 points 3D on the 6 faces with their ID
632 // - compute the point 3D
633 // - store the point 3D in SMESHDS, store its ID in 3D structure
635 int shapeID = meshDS->ShapeToIndex( aShape );
637 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
638 Pt3 px00, px01, px10, px11;
639 Pt3 p0y0, p0y1, p1y0, p1y1;
640 Pt3 p00z, p01z, p10z, p11z;
641 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
643 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
644 GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
645 GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
646 GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
647 GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
648 GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
649 GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
650 GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
652 for (int i = 1; i < nbx - 1; i++) {
653 for (int j = 1; j < nby - 1; j++) {
654 for (int k = 1; k < nbz - 1; k++) {
655 // *** seulement maillage regulier
656 // 12 points on edges
657 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
658 GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
659 GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
660 GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
662 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
663 GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
664 GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
665 GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
667 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
668 GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
669 GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
670 GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
672 // 12 points on faces
673 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
674 GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
675 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
676 GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
677 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
678 GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
680 int ijk = k * nbx * nby + j * nbx + i;
681 double x = double (i) / double (nbx - 1); // *** seulement
682 double y = double (j) / double (nby - 1); // *** maillage
683 double z = double (k) / double (nbz - 1); // *** regulier
686 for (int i = 0; i < 3; i++) {
687 X[i] = (1 - x) * p0yz[i] + x * p1yz[i]
688 + (1 - y) * px0z[i] + y * px1z[i]
689 + (1 - z) * pxy0[i] + z * pxy1[i]
690 - (1 - x) * ((1 - y) * p00z[i] + y * p01z[i])
691 - x * ((1 - y) * p10z[i] + y * p11z[i])
692 - (1 - y) * ((1 - z) * px00[i] + z * px01[i])
693 - y * ((1 - z) * px10[i] + z * px11[i])
694 - (1 - z) * ((1 - x) * p0y0[i] + x * p1y0[i])
695 - z * ((1 - x) * p0y1[i] + x * p1y1[i])
696 + (1 - x) * ((1 - y) * ((1 - z) * p000[i] + z * p001[i])
697 + y * ((1 - z) * p010[i] + z * p011[i]))
698 + x * ((1 - y) * ((1 - z) * p100[i] + z * p101[i])
699 + y * ((1 - z) * p110[i] + z * p111[i]));
702 SMDS_MeshNode * node = meshDS->AddNode(X[0], X[1], X[2]);
704 meshDS->SetNodeInVolume(node, shapeID);
709 // find orientation of furute volumes according to MED convention
710 vector< bool > forward( nbx * nby );
711 SMDS_VolumeTool vTool;
712 for (int i = 0; i < nbx - 1; i++) {
713 for (int j = 0; j < nby - 1; j++) {
714 int n1 = j * nbx + i;
715 int n2 = j * nbx + i + 1;
716 int n3 = (j + 1) * nbx + i + 1;
717 int n4 = (j + 1) * nbx + i;
718 int n5 = nbx * nby + j * nbx + i;
719 int n6 = nbx * nby + j * nbx + i + 1;
720 int n7 = nbx * nby + (j + 1) * nbx + i + 1;
721 int n8 = nbx * nby + (j + 1) * nbx + i;
723 SMDS_VolumeOfNodes tmpVol (np[n1].node,np[n2].node,np[n3].node,np[n4].node,
724 np[n5].node,np[n6].node,np[n7].node,np[n8].node);
725 vTool.Set( &tmpVol );
726 forward[ n1 ] = vTool.IsForward();
730 //2.1 - for each node of the cube (less 3 *1 Faces):
731 // - store hexahedron in SMESHDS
732 MESSAGE("Storing hexahedron into the DS");
733 for (int i = 0; i < nbx - 1; i++) {
734 for (int j = 0; j < nby - 1; j++) {
735 bool isForw = forward.at( j * nbx + i );
736 for (int k = 0; k < nbz - 1; k++) {
737 int n1 = k * nbx * nby + j * nbx + i;
738 int n2 = k * nbx * nby + j * nbx + i + 1;
739 int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
740 int n4 = k * nbx * nby + (j + 1) * nbx + i;
741 int n5 = (k + 1) * nbx * nby + j * nbx + i;
742 int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
743 int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
744 int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
746 SMDS_MeshVolume * elt;
748 //elt = meshDS->AddVolume(np[n1].node, np[n2].node,
749 // np[n3].node, np[n4].node,
750 // np[n5].node, np[n6].node,
751 // np[n7].node, np[n8].node);
752 elt = aTool.AddVolume(np[n1].node, np[n2].node,
753 np[n3].node, np[n4].node,
754 np[n5].node, np[n6].node,
755 np[n7].node, np[n8].node);
758 //elt = meshDS->AddVolume(np[n1].node, np[n4].node,
759 // np[n3].node, np[n2].node,
760 // np[n5].node, np[n8].node,
761 // np[n7].node, np[n6].node);
762 elt = aTool.AddVolume(np[n1].node, np[n4].node,
763 np[n3].node, np[n2].node,
764 np[n5].node, np[n8].node,
765 np[n7].node, np[n6].node);
768 meshDS->SetMeshElementOnShape(elt, shapeID);
772 if ( np ) delete [] np;
773 //MESSAGE("End of StdMeshers_Hexa_3D::Compute()");
774 return ClearAndReturn( aQuads, true );
777 //=============================================================================
781 //=============================================================================
783 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby,
784 int nbz, Point3DStruct * np, const SMESHDS_Mesh * meshDS)
786 int ijk = k * nbx * nby + j * nbx + i;
787 const SMDS_MeshNode * node = np[ijk].node;
791 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
794 //=============================================================================
798 //=============================================================================
800 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
801 const TopoDS_Shape & aShape,
802 const vector < SMESH_subMesh * >&meshFaces,
803 const TopoDS_Vertex & V0,
804 const TopoDS_Vertex & V1,
805 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
807 //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
809 for (int i = 1; i < 6; i++)
811 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
812 //const TopoDS_Face& F = TopoDS::Face(aFace);
813 TopTools_IndexedMapOfShape M;
814 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
815 bool verticesInShape = false;
820 verticesInShape = true;
827 ASSERT(faceIndex > 0);
832 //=============================================================================
836 //=============================================================================
839 StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
840 const TopoDS_Shape & aShape,
841 const TopoDS_Face & aFace,
842 const TopoDS_Vertex & aVertex,
843 const TopTools_IndexedDataMapOfShapeListOfShape & MS)
845 //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
846 TopTools_IndexedDataMapOfShapeListOfShape MF;
847 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
848 const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
849 const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
850 // SCRUTE(ancestorsInSolid.Extent());
851 // SCRUTE(ancestorsInFace.Extent());
852 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
853 ASSERT(ancestorsInFace.Extent() == 2);
857 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
858 for (; its.More(); its.Next())
860 TopoDS_Shape ancestor = its.Value();
861 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
862 bool isInFace = false;
863 for (; itf.More(); itf.Next())
865 TopoDS_Shape ancestorInFace = itf.Value();
866 if (ancestorInFace.IsSame(ancestor))
874 E = TopoDS::Edge(ancestor);
881 //=============================================================================
885 //=============================================================================
887 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
888 const TopoDS_Shape & aShape,
889 const TopoDS_Vertex & V0,
890 const TopoDS_Vertex & V1,
891 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
893 // MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
894 const TopoDS_Face & F = TopoDS::Face(aShape);
895 TopoDS_Edge E = quad.edge[0];
897 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
898 TopoDS_Vertex VFirst, VLast;
899 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
900 bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
901 TopoDS_Vertex VA, VB;
912 int a1, b1, c1, a2, b2, c2;
925 ASSERT(VB.IsSame(V3));
945 ASSERT(VB.IsSame(V0));
965 ASSERT(VB.IsSame(V1));
985 ASSERT(VB.IsSame(V2));
993 // MESSAGE("X = " << c1 << "+ " << a1 << "*x + " << b1 << "*y");
994 // MESSAGE("Y = " << c2 << "+ " << a2 << "*x + " << b2 << "*y");
1002 int nbdown = quad.nbPts[0];
1003 int nbright = quad.nbPts[1];
1007 int (c1 * a1 * a1) * (nbdown - 1) + int (c1 * b1 * b1) * (nbright - 1);
1011 int (c2 * a2 * a2) * (nbdown - 1) + int (c2 * b2 * b2) * (nbright - 1);
1012 // MESSAGE("I " << conv.ia << " " << conv.ib << " " << conv.ic);
1013 // MESSAGE("J " << conv.ja << " " << conv.jb << " " << conv.jc);
1016 //=============================================================================
1020 //=============================================================================
1022 ostream & StdMeshers_Hexa_3D::SaveTo(ostream & save)
1027 //=============================================================================
1031 //=============================================================================
1033 istream & StdMeshers_Hexa_3D::LoadFrom(istream & load)
1038 //=============================================================================
1042 //=============================================================================
1044 ostream & operator <<(ostream & save, StdMeshers_Hexa_3D & hyp)
1046 return hyp.SaveTo( save );
1049 //=============================================================================
1053 //=============================================================================
1055 istream & operator >>(istream & load, StdMeshers_Hexa_3D & hyp)
1057 return hyp.LoadFrom( load );
1060 //modified by NIZNHY-PKV Wed Nov 17 15:34:13 2004 f
1061 ///////////////////////////////////////////////////////////////////////////////
1063 //#include <stdio.h>
1065 //=======================================================================
1066 //function : ComputePentahedralMesh
1068 //=======================================================================
1069 bool ComputePentahedralMesh(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
1071 //printf(" ComputePentahedralMesh HERE\n");
1075 StdMeshers_Penta_3D anAlgo;
1077 bOK=anAlgo.Compute(aMesh, aShape);
1079 iErr=anAlgo.ErrorStatus();
1082 printf(" *** Error# %d\n", iErr);
1085 printf(" *** No errors# %d\n", iErr);