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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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>
49 #include <BRep_Tool.hxx>
50 #include <Geom_Surface.hxx>
51 #include <Geom_Curve.hxx>
52 #include <Geom2d_Curve.hxx>
53 #include <Handle_Geom2d_Curve.hxx>
54 #include <Handle_Geom_Curve.hxx>
55 #include <gp_Pnt2d.hxx>
57 #include "utilities.h"
58 #include "Utils_ExceptHandlers.hxx"
60 //modified by NIZNHY-PKV Wed Nov 17 15:31:58 2004 f
61 #include "StdMeshers_Penta_3D.hxx"
63 static bool ComputePentahedralMesh(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape);
64 //modified by NIZNHY-PKV Wed Nov 17 15:32:00 2004 t
66 //=============================================================================
70 //=============================================================================
72 StdMeshers_Hexa_3D::StdMeshers_Hexa_3D(int hypId, int studyId,
73 SMESH_Gen * gen):SMESH_3D_Algo(hypId, studyId, gen)
75 MESSAGE("StdMeshers_Hexa_3D::StdMeshers_Hexa_3D");
77 // _shapeType = TopAbs_SOLID;
78 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
79 // MESSAGE("_shapeType octal " << oct << _shapeType);
80 for (int i = 0; i < 6; i++)
84 //=============================================================================
88 //=============================================================================
90 StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D()
92 MESSAGE("StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D");
95 //=============================================================================
99 //=============================================================================
101 bool StdMeshers_Hexa_3D::CheckHypothesis
103 const TopoDS_Shape& aShape,
104 SMESH_Hypothesis::Hypothesis_Status& aStatus)
106 //MESSAGE("StdMeshers_Hexa_3D::CheckHypothesis");
109 aStatus = SMESH_Hypothesis::HYP_OK;
116 //=======================================================================
118 //purpose : return i,j of the node
119 //=======================================================================
121 static bool findIJ (const SMDS_MeshNode* node, const FaceQuadStruct * quad, int& I, int& J)
124 const SMDS_FacePosition* fpos =
125 static_cast<const SMDS_FacePosition*>(node->GetPosition().get());
126 if ( ! fpos ) return false;
127 gp_Pnt2d uv( fpos->GetUParameter(), fpos->GetVParameter() );
129 double minDist = DBL_MAX;
130 int nbhoriz = Min(quad->nbPts[0], quad->nbPts[2]);
131 int nbvertic = Min(quad->nbPts[1], quad->nbPts[3]);
132 for (int i = 1; i < nbhoriz - 1; i++) {
133 for (int j = 1; j < nbvertic - 1; j++) {
134 int ij = j * nbhoriz + i;
135 gp_Pnt2d uv2( quad->uv_grid[ij].u, quad->uv_grid[ij].v );
136 double dist = uv.SquareDistance( uv2 );
137 if ( dist < minDist ) {
147 //=============================================================================
149 * Hexahedron mesh on hexaedron like form
150 * -0. - shape and face mesh verification
151 * -1. - identify faces and vertices of the "cube"
152 * -2. - Algorithm from:
153 * "Application de l'interpolation transfinie à la création de maillages
154 * C0 ou G1 continus sur des triangles, quadrangles, tetraedres, pentaedres
155 * et hexaedres déformés."
156 * Alain PERONNET - 8 janvier 1999
158 //=============================================================================
160 bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh & aMesh,
161 const TopoDS_Shape & aShape)throw(SALOME_Exception)
163 Unexpect aCatch(SalomeException);
164 MESSAGE("StdMeshers_Hexa_3D::Compute");
166 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
167 //SMESH_subMesh *theSubMesh = aMesh.GetSubMesh(aShape);
168 //const SMESHDS_SubMesh *& subMeshDS = theSubMesh->GetSubMeshDS();
170 // 0. - shape and face mesh verification
171 // 0.1 - shape must be a solid (or a shell) with 6 faces
174 vector < SMESH_subMesh * >meshFaces;
175 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next())
177 SMESH_subMesh *aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
179 meshFaces.push_back(aSubMesh);
181 if (meshFaces.size() != 6)
183 SCRUTE(meshFaces.size());
188 // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
191 for (int i = 0; i < 6; i++)
193 TopoDS_Shape aFace = meshFaces[i]->GetSubShape();
194 SMESH_Algo *algo = _gen->GetAlgo(aMesh, aFace);
195 string algoName = algo->GetName();
196 bool isAllQuad = false;
197 if (algoName == "Quadrangle_2D") {
198 SMESHDS_SubMesh * sm = meshDS->MeshElements( aFace );
201 SMDS_ElemIteratorPtr eIt = sm->GetElements();
202 while ( isAllQuad && eIt->more() )
203 isAllQuad = ( eIt->next()->NbNodes() == 4 );
207 //modified by NIZNHY-PKV Wed Nov 17 15:31:37 2004 f
210 bIsOk=ComputePentahedralMesh(aMesh, aShape);
214 //modified by NIZNHY-PKV Wed Nov 17 15:31:42 2004 t
219 StdMeshers_Quadrangle_2D *quadAlgo =
220 dynamic_cast < StdMeshers_Quadrangle_2D * >(algo);
224 _quads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aFace);
225 // *** to delete after usage
227 catch(SALOME_Exception & S_ex)
230 // *** throw exception
235 // 0.2.1 - number of points on the opposite edges must be the same
236 if (_quads[i]->nbPts[0] != _quads[i]->nbPts[2] ||
237 _quads[i]->nbPts[1] != _quads[i]->nbPts[3])
239 MESSAGE("different number of points on the opposite edges of face " << i);
245 // 1. - identify faces and vertices of the "cube"
246 // 1.1 - ancestor maps vertex->edges in the cube
249 TopTools_IndexedDataMapOfShapeListOfShape MS;
250 TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
252 // 1.2 - first face is choosen as face Y=0 of the unit cube
255 const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
256 const TopoDS_Face & F = TopoDS::Face(aFace);
258 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
262 TopoDS_Edge E = _quads[0]->edge[i]; //edge will be Y=0,Z=0 on unit cube
264 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
265 TopoDS_Vertex VFirst, VLast;
266 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
268 (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
272 _cube.V000 = VFirst; // will be (0,0,0) on the unit cube
273 _cube.V100 = VLast; // will be (1,0,0) on the unit cube
282 E = _quads[0]->edge[i];
283 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
284 TopExp::Vertices(E, VFirst, VLast);
285 isForward = (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
287 _cube.V101 = VLast; // will be (1,0,1) on the unit cube
292 E = _quads[0]->edge[i];
293 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
294 TopExp::Vertices(E, VFirst, VLast);
295 isForward = (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
297 _cube.V001 = VLast; // will be (0,0,1) on the unit cube
301 // 1.4 - find edge X=0, Z=0 (ancestor of V000 not in face Y=0)
302 // - find edge X=1, Z=0 (ancestor of V100 not in face Y=0)
303 // - find edge X=1, Z=1 (ancestor of V101 not in face Y=0)
304 // - find edge X=0, Z=1 (ancestor of V001 not in face Y=0)
307 TopoDS_Edge E_0Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V000, MS);
308 ASSERT(!E_0Y0.IsNull());
310 TopoDS_Edge E_1Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V100, MS);
311 ASSERT(!E_1Y0.IsNull());
313 TopoDS_Edge E_1Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V101, MS);
314 ASSERT(!E_1Y1.IsNull());
316 TopoDS_Edge E_0Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V001, MS);
317 ASSERT(!E_0Y1.IsNull());
319 // 1.5 - identify the 4 vertices in face Y=1: V010, V110, V111, V011
322 TopExp::Vertices(E_0Y0, VFirst, VLast);
323 if (VFirst.IsSame(_cube.V000))
328 TopExp::Vertices(E_1Y0, VFirst, VLast);
329 if (VFirst.IsSame(_cube.V100))
334 TopExp::Vertices(E_1Y1, VFirst, VLast);
335 if (VFirst.IsSame(_cube.V101))
340 TopExp::Vertices(E_0Y1, VFirst, VLast);
341 if (VFirst.IsSame(_cube.V001))
346 // 1.6 - find remaining faces given 4 vertices
350 _cube.quad_Y0 = _quads[_indY0];
352 _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
353 _cube.V010, _cube.V011, _cube.V110, _cube.V111);
354 _cube.quad_Y1 = _quads[_indY1];
356 _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
357 _cube.V000, _cube.V010, _cube.V100, _cube.V110);
358 _cube.quad_Z0 = _quads[_indZ0];
360 _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
361 _cube.V001, _cube.V011, _cube.V101, _cube.V111);
362 _cube.quad_Z1 = _quads[_indZ1];
364 _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
365 _cube.V000, _cube.V001, _cube.V010, _cube.V011);
366 _cube.quad_X0 = _quads[_indX0];
368 _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
369 _cube.V100, _cube.V101, _cube.V110, _cube.V111);
370 _cube.quad_X1 = _quads[_indX1];
374 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
376 Conv2DStruct cx0; // for face X=0
377 Conv2DStruct cx1; // for face X=1
383 GetConv2DCoefs(*_cube.quad_X0, meshFaces[_indX0]->GetSubShape(),
384 _cube.V000, _cube.V010, _cube.V011, _cube.V001, cx0);
385 GetConv2DCoefs(*_cube.quad_X1, meshFaces[_indX1]->GetSubShape(),
386 _cube.V100, _cube.V110, _cube.V111, _cube.V101, cx1);
387 GetConv2DCoefs(*_cube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
388 _cube.V000, _cube.V100, _cube.V101, _cube.V001, cy0);
389 GetConv2DCoefs(*_cube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
390 _cube.V010, _cube.V110, _cube.V111, _cube.V011, cy1);
391 GetConv2DCoefs(*_cube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
392 _cube.V000, _cube.V100, _cube.V110, _cube.V010, cz0);
393 GetConv2DCoefs(*_cube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
394 _cube.V001, _cube.V101, _cube.V111, _cube.V011, cz1);
396 // 1.8 - create a 3D structure for normalized values
399 int nbx = _cube.quad_Z0->nbPts[0];
400 if (cz0.a1 == 0.) nbx = _cube.quad_Z0->nbPts[1];
402 int nby = _cube.quad_X0->nbPts[0];
403 if (cx0.a1 == 0.) nby = _cube.quad_X0->nbPts[1];
405 int nbz = _cube.quad_Y0->nbPts[0];
406 if (cy0.a1 != 0.) nbz = _cube.quad_Y0->nbPts[1];
407 // int nbx = _cube.quad_Y0->nbPts[0];
408 // int nby = _cube.quad_Y0->nbPts[1];
411 // nbz = _cube.quad_X0->nbPts[1];
413 // nbz = _cube.quad_X0->nbPts[0];
417 int i1, j1, nbxyz = nbx * nby * nbz;
418 Point3DStruct *np = new Point3DStruct[nbxyz];
420 // 1.9 - store node indexes of faces
423 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
425 faceQuadStruct *quad = _cube.quad_X0;
426 int i = 0; // j = x/face , k = y/face
427 int nbdown = quad->nbPts[0];
428 int nbright = quad->nbPts[1];
431 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
435 const SMDS_MeshNode * node = itf->next();
436 findIJ( node, quad, i1, j1 );
437 int ij1 = j1 * nbdown + i1;
438 quad->uv_grid[ij1].node = node;
441 for (int i1 = 0; i1 < nbdown; i1++)
442 for (int j1 = 0; j1 < nbright; j1++)
444 int ij1 = j1 * nbdown + i1;
445 int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic; // j = x/face
446 int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc; // k = y/face
447 int ijk = k * nbx * nby + j * nbx + i;
448 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
449 np[ijk].node = quad->uv_grid[ij1].node;
450 //SCRUTE(np[ijk].nodeId);
455 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
457 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
459 faceQuadStruct *quad = _cube.quad_X1;
460 int i = nbx - 1; // j = x/face , k = y/face
461 int nbdown = quad->nbPts[0];
462 int nbright = quad->nbPts[1];
466 const SMDS_MeshNode * node = itf->next();
467 findIJ( node, quad, i1, j1 );
468 int ij1 = j1 * nbdown + i1;
469 quad->uv_grid[ij1].node = node;
472 for (int i1 = 0; i1 < nbdown; i1++)
473 for (int j1 = 0; j1 < nbright; j1++)
475 int ij1 = j1 * nbdown + i1;
476 int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic; // j = x/face
477 int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc; // k = y/face
478 int ijk = k * nbx * nby + j * nbx + i;
479 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
480 np[ijk].node = quad->uv_grid[ij1].node;
481 //SCRUTE(np[ijk].nodeId);
486 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
488 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
490 faceQuadStruct *quad = _cube.quad_Y0;
491 int j = 0; // i = x/face , k = y/face
492 int nbdown = quad->nbPts[0];
493 int nbright = quad->nbPts[1];
497 const SMDS_MeshNode * node = itf->next();
498 findIJ( node, quad, i1, j1 );
499 int ij1 = j1 * nbdown + i1;
500 quad->uv_grid[ij1].node = node;
503 for (int i1 = 0; i1 < nbdown; i1++)
504 for (int j1 = 0; j1 < nbright; j1++)
506 int ij1 = j1 * nbdown + i1;
507 int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic; // i = x/face
508 int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc; // k = y/face
509 int ijk = k * nbx * nby + j * nbx + i;
510 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
511 np[ijk].node = quad->uv_grid[ij1].node;
512 //SCRUTE(np[ijk].nodeId);
517 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
519 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
521 faceQuadStruct *quad = _cube.quad_Y1;
522 int j = nby - 1; // i = x/face , k = y/face
523 int nbdown = quad->nbPts[0];
524 int nbright = quad->nbPts[1];
528 const SMDS_MeshNode * node = itf->next();
529 findIJ( node, quad, i1, j1 );
530 int ij1 = j1 * nbdown + i1;
531 quad->uv_grid[ij1].node = node;
534 for (int i1 = 0; i1 < nbdown; i1++)
535 for (int j1 = 0; j1 < nbright; j1++)
537 int ij1 = j1 * nbdown + i1;
538 int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic; // i = x/face
539 int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc; // k = y/face
540 int ijk = k * nbx * nby + j * nbx + i;
541 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
542 np[ijk].node = quad->uv_grid[ij1].node;
543 //SCRUTE(np[ijk].nodeId);
548 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
550 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
552 faceQuadStruct *quad = _cube.quad_Z0;
553 int k = 0; // i = x/face , j = y/face
554 int nbdown = quad->nbPts[0];
555 int nbright = quad->nbPts[1];
559 const SMDS_MeshNode * node = itf->next();
560 findIJ( node, quad, i1, j1 );
561 int ij1 = j1 * nbdown + i1;
562 quad->uv_grid[ij1].node = node;
565 for (int i1 = 0; i1 < nbdown; i1++)
566 for (int j1 = 0; j1 < nbright; j1++)
568 int ij1 = j1 * nbdown + i1;
569 int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic; // i = x/face
570 int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc; // j = y/face
571 int ijk = k * nbx * nby + j * nbx + i;
572 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
573 np[ijk].node = quad->uv_grid[ij1].node;
574 //SCRUTE(np[ijk].nodeId);
579 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
581 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
583 faceQuadStruct *quad = _cube.quad_Z1;
584 int k = nbz - 1; // i = x/face , j = y/face
585 int nbdown = quad->nbPts[0];
586 int nbright = quad->nbPts[1];
590 const SMDS_MeshNode * node = itf->next();
591 findIJ( node, quad, i1, j1 );
592 int ij1 = j1 * nbdown + i1;
593 quad->uv_grid[ij1].node = node;
596 for (int i1 = 0; i1 < nbdown; i1++)
597 for (int j1 = 0; j1 < nbright; j1++)
599 int ij1 = j1 * nbdown + i1;
600 int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic; // i = x/face
601 int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc; // j = y/face
602 int ijk = k * nbx * nby + j * nbx + i;
603 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
604 np[ijk].node = quad->uv_grid[ij1].node;
605 //SCRUTE(np[ijk].nodeId);
609 // 2.0 - for each node of the cube:
610 // - get the 8 points 3D = 8 vertices of the cube
611 // - get the 12 points 3D on the 12 edges of the cube
612 // - get the 6 points 3D on the 6 faces with their ID
613 // - compute the point 3D
614 // - store the point 3D in SMESHDS, store its ID in 3D structure
617 TopExp_Explorer exp(aShape, TopAbs_SHELL);
620 aShell = TopoDS::Shell(exp.Current());
624 MESSAGE("no shell...");
628 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
629 Pt3 px00, px01, px10, px11;
630 Pt3 p0y0, p0y1, p1y0, p1y1;
631 Pt3 p00z, p01z, p10z, p11z;
632 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
634 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
635 GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
636 GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
637 GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
638 GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
639 GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
640 GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
641 GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
643 for (int i = 1; i < nbx - 1; i++)
645 for (int j = 1; j < nby - 1; j++)
647 for (int k = 1; k < nbz - 1; k++)
649 // *** seulement maillage regulier
650 // 12 points on edges
651 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
652 GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
653 GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
654 GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
656 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
657 GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
658 GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
659 GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
661 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
662 GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
663 GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
664 GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
666 // 12 points on faces
667 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
668 GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
669 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
670 GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
671 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
672 GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
674 int ijk = k * nbx * nby + j * nbx + i;
675 double x = double (i) / double (nbx - 1); // *** seulement
676 double y = double (j) / double (nby - 1); // *** maillage
677 double z = double (k) / double (nbz - 1); // *** regulier
680 for (int i = 0; i < 3; i++)
683 (1 - x) * p0yz[i] + x * p1yz[i]
684 + (1 - y) * px0z[i] + y * px1z[i]
685 + (1 - z) * pxy0[i] + z * pxy1[i]
686 - (1 - x) * ((1 - y) * p00z[i] + y * p01z[i])
687 - x * ((1 - y) * p10z[i] + y * p11z[i])
688 - (1 - y) * ((1 - z) * px00[i] + z * px01[i])
689 - y * ((1 - z) * px10[i] + z * px11[i])
690 - (1 - z) * ((1 - x) * p0y0[i] + x * p1y0[i])
691 - z * ((1 - x) * p0y1[i] + x * p1y1[i])
692 + (1 - x) * ((1 - y) * ((1 - z) * p000[i] + z * p001[i])
693 + y * ((1 - z) * p010[i] + z * p011[i]))
694 + x * ((1 - y) * ((1 - z) * p100[i] + z * p101[i])
695 + y * ((1 - z) * p110[i] + z * p111[i]));
698 SMDS_MeshNode * node = meshDS->AddNode(X[0], X[1], X[2]);
700 //meshDS->SetNodeInVolume(node, TopoDS::Solid(aShape));
701 meshDS->SetNodeInVolume(node, aShell);
706 // find orientation of furute volumes according to MED convention
707 vector< bool > forward( nbx * nby );
708 SMDS_VolumeTool vTool;
709 for (int i = 0; i < nbx - 1; i++)
710 for (int j = 0; j < nby - 1; j++)
712 int n1 = j * nbx + i;
713 int n2 = j * nbx + i + 1;
714 int n3 = (j + 1) * nbx + i + 1;
715 int n4 = (j + 1) * nbx + i;
716 int n5 = nbx * nby + j * nbx + i;
717 int n6 = nbx * nby + j * nbx + i + 1;
718 int n7 = nbx * nby + (j + 1) * nbx + i + 1;
719 int n8 = nbx * nby + (j + 1) * nbx + i;
721 SMDS_VolumeOfNodes tmpVol (np[n1].node,np[n2].node,np[n3].node,np[n4].node,
722 np[n5].node,np[n6].node,np[n7].node,np[n8].node);
723 vTool.Set( &tmpVol );
724 forward[ n1 ] = vTool.IsForward();
727 //2.1 - for each node of the cube (less 3 *1 Faces):
728 // - store hexahedron in SMESHDS
729 MESSAGE("Storing hexahedron into the DS");
730 for (int i = 0; i < nbx - 1; i++)
731 for (int j = 0; j < nby - 1; j++)
733 bool isForw = forward.at( j * nbx + i );
734 for (int k = 0; k < nbz - 1; k++)
736 int n1 = k * nbx * nby + j * nbx + i;
737 int n2 = k * nbx * nby + j * nbx + i + 1;
738 int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
739 int n4 = k * nbx * nby + (j + 1) * nbx + i;
740 int n5 = (k + 1) * nbx * nby + j * nbx + i;
741 int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
742 int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
743 int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
745 SMDS_MeshVolume * elt;
747 elt = meshDS->AddVolume(np[n1].node,
756 elt = meshDS->AddVolume(np[n1].node,
765 meshDS->SetMeshElementOnShape(elt, aShell);
770 if ( np ) delete [] np;
771 //MESSAGE("End of StdMeshers_Hexa_3D::Compute()");
775 //=============================================================================
779 //=============================================================================
781 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby,
782 int nbz, Point3DStruct * np, const SMESHDS_Mesh * meshDS)
784 int ijk = k * nbx * nby + j * nbx + i;
785 const SMDS_MeshNode * node = np[ijk].node;
789 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
792 //=============================================================================
796 //=============================================================================
798 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
799 const TopoDS_Shape & aShape,
800 const vector < SMESH_subMesh * >&meshFaces,
801 const TopoDS_Vertex & V0,
802 const TopoDS_Vertex & V1,
803 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
805 //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
807 for (int i = 1; i < 6; i++)
809 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
810 //const TopoDS_Face& F = TopoDS::Face(aFace);
811 TopTools_IndexedMapOfShape M;
812 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
813 bool verticesInShape = false;
818 verticesInShape = true;
825 ASSERT(faceIndex > 0);
830 //=============================================================================
834 //=============================================================================
837 StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
838 const TopoDS_Shape & aShape,
839 const TopoDS_Face & aFace,
840 const TopoDS_Vertex & aVertex,
841 const TopTools_IndexedDataMapOfShapeListOfShape & MS)
843 //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
844 TopTools_IndexedDataMapOfShapeListOfShape MF;
845 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
846 const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
847 const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
848 // SCRUTE(ancestorsInSolid.Extent());
849 // SCRUTE(ancestorsInFace.Extent());
850 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
851 ASSERT(ancestorsInFace.Extent() == 2);
855 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
856 for (; its.More(); its.Next())
858 TopoDS_Shape ancestor = its.Value();
859 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
860 bool isInFace = false;
861 for (; itf.More(); itf.Next())
863 TopoDS_Shape ancestorInFace = itf.Value();
864 if (ancestorInFace.IsSame(ancestor))
872 E = TopoDS::Edge(ancestor);
879 //=============================================================================
883 //=============================================================================
885 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
886 const TopoDS_Shape & aShape,
887 const TopoDS_Vertex & V0,
888 const TopoDS_Vertex & V1,
889 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
891 // MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
892 const TopoDS_Face & F = TopoDS::Face(aShape);
893 TopoDS_Edge E = quad.edge[0];
895 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
896 TopoDS_Vertex VFirst, VLast;
897 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
898 bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
899 TopoDS_Vertex VA, VB;
910 int a1, b1, c1, a2, b2, c2;
923 ASSERT(VB.IsSame(V3));
943 ASSERT(VB.IsSame(V0));
963 ASSERT(VB.IsSame(V1));
983 ASSERT(VB.IsSame(V2));
991 // MESSAGE("X = " << c1 << "+ " << a1 << "*x + " << b1 << "*y");
992 // MESSAGE("Y = " << c2 << "+ " << a2 << "*x + " << b2 << "*y");
1000 int nbdown = quad.nbPts[0];
1001 int nbright = quad.nbPts[1];
1005 int (c1 * a1 * a1) * (nbdown - 1) + int (c1 * b1 * b1) * (nbright - 1);
1009 int (c2 * a2 * a2) * (nbdown - 1) + int (c2 * b2 * b2) * (nbright - 1);
1010 // MESSAGE("I " << conv.ia << " " << conv.ib << " " << conv.ic);
1011 // MESSAGE("J " << conv.ja << " " << conv.jb << " " << conv.jc);
1014 //=============================================================================
1018 //=============================================================================
1020 ostream & StdMeshers_Hexa_3D::SaveTo(ostream & save)
1025 //=============================================================================
1029 //=============================================================================
1031 istream & StdMeshers_Hexa_3D::LoadFrom(istream & load)
1036 //=============================================================================
1040 //=============================================================================
1042 ostream & operator <<(ostream & save, StdMeshers_Hexa_3D & hyp)
1044 return hyp.SaveTo( save );
1047 //=============================================================================
1051 //=============================================================================
1053 istream & operator >>(istream & load, StdMeshers_Hexa_3D & hyp)
1055 return hyp.LoadFrom( load );
1058 //modified by NIZNHY-PKV Wed Nov 17 15:34:13 2004 f
1059 ///////////////////////////////////////////////////////////////////////////////
1061 //#include <stdio.h>
1063 //=======================================================================
1064 //function : ComputePentahedralMesh
1066 //=======================================================================
1067 bool ComputePentahedralMesh(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
1069 //printf(" ComputePentahedralMesh HERE\n");
1073 StdMeshers_Penta_3D anAlgo;
1075 bOK=anAlgo.Compute(aMesh, aShape);
1077 iErr=anAlgo.ErrorStatus();
1080 printf(" *** Error# %d\n", iErr);
1083 printf(" *** No errors# %d\n", iErr);