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");
93 for (int i = 0; i < 6; i++)
94 StdMeshers_Quadrangle_2D::QuadDelete(_quads[i]);
97 //=============================================================================
101 //=============================================================================
103 bool StdMeshers_Hexa_3D::CheckHypothesis
105 const TopoDS_Shape& aShape,
106 SMESH_Hypothesis::Hypothesis_Status& aStatus)
108 //MESSAGE("StdMeshers_Hexa_3D::CheckHypothesis");
111 aStatus = SMESH_Hypothesis::HYP_OK;
118 //=======================================================================
120 //purpose : return i,j of the node
121 //=======================================================================
123 static bool findIJ (const SMDS_MeshNode* node, const FaceQuadStruct * quad, int& I, int& J)
126 const SMDS_FacePosition* fpos =
127 static_cast<const SMDS_FacePosition*>(node->GetPosition().get());
128 if ( ! fpos ) return false;
129 gp_Pnt2d uv( fpos->GetUParameter(), fpos->GetVParameter() );
131 double minDist = DBL_MAX;
132 int nbhoriz = Min(quad->nbPts[0], quad->nbPts[2]);
133 int nbvertic = Min(quad->nbPts[1], quad->nbPts[3]);
134 for (int i = 1; i < nbhoriz - 1; i++) {
135 for (int j = 1; j < nbvertic - 1; j++) {
136 int ij = j * nbhoriz + i;
137 gp_Pnt2d uv2( quad->uv_grid[ij].u, quad->uv_grid[ij].v );
138 double dist = uv.SquareDistance( uv2 );
139 if ( dist < minDist ) {
149 //=============================================================================
151 * Hexahedron mesh on hexaedron like form
152 * -0. - shape and face mesh verification
153 * -1. - identify faces and vertices of the "cube"
154 * -2. - Algorithm from:
155 * "Application de l'interpolation transfinie à la création de maillages
156 * C0 ou G1 continus sur des triangles, quadrangles, tetraedres, pentaedres
157 * et hexaedres déformés."
158 * Alain PERONNET - 8 janvier 1999
160 //=============================================================================
162 bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh & aMesh,
163 const TopoDS_Shape & aShape)throw(SALOME_Exception)
165 Unexpect aCatch(SalomeException);
166 MESSAGE("StdMeshers_Hexa_3D::Compute");
168 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
169 //SMESH_subMesh *theSubMesh = aMesh.GetSubMesh(aShape);
170 //const SMESHDS_SubMesh *& subMeshDS = theSubMesh->GetSubMeshDS();
172 // 0. - shape and face mesh verification
173 // 0.1 - shape must be a solid (or a shell) with 6 faces
176 vector < SMESH_subMesh * >meshFaces;
177 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next())
179 SMESH_subMesh *aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
181 meshFaces.push_back(aSubMesh);
183 if (meshFaces.size() != 6)
185 SCRUTE(meshFaces.size());
190 // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
193 for (int i = 0; i < 6; i++)
195 TopoDS_Shape aFace = meshFaces[i]->GetSubShape();
196 SMESH_Algo *algo = _gen->GetAlgo(aMesh, aFace);
197 string algoName = algo->GetName();
198 bool isAllQuad = false;
199 if (algoName == "Quadrangle_2D") {
200 SMESHDS_SubMesh * sm = meshDS->MeshElements( aFace );
203 SMDS_ElemIteratorPtr eIt = sm->GetElements();
204 while ( isAllQuad && eIt->more() )
205 isAllQuad = ( eIt->next()->NbNodes() == 4 );
209 //modified by NIZNHY-PKV Wed Nov 17 15:31:37 2004 f
212 bIsOk=ComputePentahedralMesh(aMesh, aShape);
216 //modified by NIZNHY-PKV Wed Nov 17 15:31:42 2004 t
221 StdMeshers_Quadrangle_2D *quadAlgo =
222 dynamic_cast < StdMeshers_Quadrangle_2D * >(algo);
226 _quads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aFace);
227 // *** to delete after usage
229 catch(SALOME_Exception & S_ex)
232 // *** throw exception
237 // 0.2.1 - number of points on the opposite edges must be the same
238 if (_quads[i]->nbPts[0] != _quads[i]->nbPts[2] ||
239 _quads[i]->nbPts[1] != _quads[i]->nbPts[3])
241 MESSAGE("different number of points on the opposite edges of face " << i);
247 // 1. - identify faces and vertices of the "cube"
248 // 1.1 - ancestor maps vertex->edges in the cube
251 TopTools_IndexedDataMapOfShapeListOfShape MS;
252 TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
254 // 1.2 - first face is choosen as face Y=0 of the unit cube
257 const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
258 const TopoDS_Face & F = TopoDS::Face(aFace);
260 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
264 TopoDS_Edge E = _quads[0]->edge[i]; //edge will be Y=0,Z=0 on unit cube
266 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
267 TopoDS_Vertex VFirst, VLast;
268 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
270 (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
274 _cube.V000 = VFirst; // will be (0,0,0) on the unit cube
275 _cube.V100 = VLast; // will be (1,0,0) on the unit cube
284 E = _quads[0]->edge[i];
285 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
286 TopExp::Vertices(E, VFirst, VLast);
287 isForward = (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
289 _cube.V101 = VLast; // will be (1,0,1) on the unit cube
294 E = _quads[0]->edge[i];
295 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
296 TopExp::Vertices(E, VFirst, VLast);
297 isForward = (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
299 _cube.V001 = VLast; // will be (0,0,1) on the unit cube
303 // 1.4 - find edge X=0, Z=0 (ancestor of V000 not in face Y=0)
304 // - find edge X=1, Z=0 (ancestor of V100 not in face Y=0)
305 // - find edge X=1, Z=1 (ancestor of V101 not in face Y=0)
306 // - find edge X=0, Z=1 (ancestor of V001 not in face Y=0)
309 TopoDS_Edge E_0Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V000, MS);
310 ASSERT(!E_0Y0.IsNull());
312 TopoDS_Edge E_1Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V100, MS);
313 ASSERT(!E_1Y0.IsNull());
315 TopoDS_Edge E_1Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V101, MS);
316 ASSERT(!E_1Y1.IsNull());
318 TopoDS_Edge E_0Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V001, MS);
319 ASSERT(!E_0Y1.IsNull());
321 // 1.5 - identify the 4 vertices in face Y=1: V010, V110, V111, V011
324 TopExp::Vertices(E_0Y0, VFirst, VLast);
325 if (VFirst.IsSame(_cube.V000))
330 TopExp::Vertices(E_1Y0, VFirst, VLast);
331 if (VFirst.IsSame(_cube.V100))
336 TopExp::Vertices(E_1Y1, VFirst, VLast);
337 if (VFirst.IsSame(_cube.V101))
342 TopExp::Vertices(E_0Y1, VFirst, VLast);
343 if (VFirst.IsSame(_cube.V001))
348 // 1.6 - find remaining faces given 4 vertices
352 _cube.quad_Y0 = _quads[_indY0];
354 _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
355 _cube.V010, _cube.V011, _cube.V110, _cube.V111);
356 _cube.quad_Y1 = _quads[_indY1];
358 _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
359 _cube.V000, _cube.V010, _cube.V100, _cube.V110);
360 _cube.quad_Z0 = _quads[_indZ0];
362 _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
363 _cube.V001, _cube.V011, _cube.V101, _cube.V111);
364 _cube.quad_Z1 = _quads[_indZ1];
366 _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
367 _cube.V000, _cube.V001, _cube.V010, _cube.V011);
368 _cube.quad_X0 = _quads[_indX0];
370 _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
371 _cube.V100, _cube.V101, _cube.V110, _cube.V111);
372 _cube.quad_X1 = _quads[_indX1];
376 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
378 Conv2DStruct cx0; // for face X=0
379 Conv2DStruct cx1; // for face X=1
385 GetConv2DCoefs(*_cube.quad_X0, meshFaces[_indX0]->GetSubShape(),
386 _cube.V000, _cube.V010, _cube.V011, _cube.V001, cx0);
387 GetConv2DCoefs(*_cube.quad_X1, meshFaces[_indX1]->GetSubShape(),
388 _cube.V100, _cube.V110, _cube.V111, _cube.V101, cx1);
389 GetConv2DCoefs(*_cube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
390 _cube.V000, _cube.V100, _cube.V101, _cube.V001, cy0);
391 GetConv2DCoefs(*_cube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
392 _cube.V010, _cube.V110, _cube.V111, _cube.V011, cy1);
393 GetConv2DCoefs(*_cube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
394 _cube.V000, _cube.V100, _cube.V110, _cube.V010, cz0);
395 GetConv2DCoefs(*_cube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
396 _cube.V001, _cube.V101, _cube.V111, _cube.V011, cz1);
398 // 1.8 - create a 3D structure for normalized values
401 int nbx = _cube.quad_Z0->nbPts[0];
402 if (cz0.a1 == 0.) nbx = _cube.quad_Z0->nbPts[1];
404 int nby = _cube.quad_X0->nbPts[0];
405 if (cx0.a1 == 0.) nby = _cube.quad_X0->nbPts[1];
407 int nbz = _cube.quad_Y0->nbPts[0];
408 if (cy0.a1 != 0.) nbz = _cube.quad_Y0->nbPts[1];
410 int i1, j1, nbxyz = nbx * nby * nbz;
411 Point3DStruct *np = new Point3DStruct[nbxyz];
413 // 1.9 - store node indexes of faces
416 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
418 faceQuadStruct *quad = _cube.quad_X0;
419 int i = 0; // j = x/face , k = y/face
420 int nbdown = quad->nbPts[0];
421 int nbright = quad->nbPts[1];
424 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
428 const SMDS_MeshNode * node = itf->next();
429 findIJ( node, quad, i1, j1 );
430 int ij1 = j1 * nbdown + i1;
431 quad->uv_grid[ij1].node = node;
434 for (int i1 = 0; i1 < nbdown; i1++)
435 for (int j1 = 0; j1 < nbright; j1++)
437 int ij1 = j1 * nbdown + i1;
438 int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic; // j = x/face
439 int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc; // k = y/face
440 int ijk = k * nbx * nby + j * nbx + i;
441 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
442 np[ijk].node = quad->uv_grid[ij1].node;
443 //SCRUTE(np[ijk].nodeId);
448 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
450 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
452 faceQuadStruct *quad = _cube.quad_X1;
453 int i = nbx - 1; // j = x/face , k = y/face
454 int nbdown = quad->nbPts[0];
455 int nbright = quad->nbPts[1];
459 const SMDS_MeshNode * node = itf->next();
460 findIJ( node, quad, i1, j1 );
461 int ij1 = j1 * nbdown + i1;
462 quad->uv_grid[ij1].node = node;
465 for (int i1 = 0; i1 < nbdown; i1++)
466 for (int j1 = 0; j1 < nbright; j1++)
468 int ij1 = j1 * nbdown + i1;
469 int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic; // j = x/face
470 int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc; // k = y/face
471 int ijk = k * nbx * nby + j * nbx + i;
472 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
473 np[ijk].node = quad->uv_grid[ij1].node;
474 //SCRUTE(np[ijk].nodeId);
479 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
481 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
483 faceQuadStruct *quad = _cube.quad_Y0;
484 int j = 0; // i = x/face , k = y/face
485 int nbdown = quad->nbPts[0];
486 int nbright = quad->nbPts[1];
490 const SMDS_MeshNode * node = itf->next();
491 findIJ( node, quad, i1, j1 );
492 int ij1 = j1 * nbdown + i1;
493 quad->uv_grid[ij1].node = node;
496 for (int i1 = 0; i1 < nbdown; i1++)
497 for (int j1 = 0; j1 < nbright; j1++)
499 int ij1 = j1 * nbdown + i1;
500 int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic; // i = x/face
501 int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc; // k = y/face
502 int ijk = k * nbx * nby + j * nbx + i;
503 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
504 np[ijk].node = quad->uv_grid[ij1].node;
505 //SCRUTE(np[ijk].nodeId);
510 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
512 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
514 faceQuadStruct *quad = _cube.quad_Y1;
515 int j = nby - 1; // i = x/face , k = y/face
516 int nbdown = quad->nbPts[0];
517 int nbright = quad->nbPts[1];
521 const SMDS_MeshNode * node = itf->next();
522 findIJ( node, quad, i1, j1 );
523 int ij1 = j1 * nbdown + i1;
524 quad->uv_grid[ij1].node = node;
527 for (int i1 = 0; i1 < nbdown; i1++)
528 for (int j1 = 0; j1 < nbright; j1++)
530 int ij1 = j1 * nbdown + i1;
531 int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic; // i = x/face
532 int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc; // k = y/face
533 int ijk = k * nbx * nby + j * nbx + i;
534 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
535 np[ijk].node = quad->uv_grid[ij1].node;
536 //SCRUTE(np[ijk].nodeId);
541 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
543 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
545 faceQuadStruct *quad = _cube.quad_Z0;
546 int k = 0; // i = x/face , j = y/face
547 int nbdown = quad->nbPts[0];
548 int nbright = quad->nbPts[1];
552 const SMDS_MeshNode * node = itf->next();
553 findIJ( node, quad, i1, j1 );
554 int ij1 = j1 * nbdown + i1;
555 quad->uv_grid[ij1].node = node;
558 for (int i1 = 0; i1 < nbdown; i1++)
559 for (int j1 = 0; j1 < nbright; j1++)
561 int ij1 = j1 * nbdown + i1;
562 int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic; // i = x/face
563 int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc; // j = y/face
564 int ijk = k * nbx * nby + j * nbx + i;
565 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
566 np[ijk].node = quad->uv_grid[ij1].node;
567 //SCRUTE(np[ijk].nodeId);
572 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
574 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
576 faceQuadStruct *quad = _cube.quad_Z1;
577 int k = nbz - 1; // i = x/face , j = y/face
578 int nbdown = quad->nbPts[0];
579 int nbright = quad->nbPts[1];
583 const SMDS_MeshNode * node = itf->next();
584 findIJ( node, quad, i1, j1 );
585 int ij1 = j1 * nbdown + i1;
586 quad->uv_grid[ij1].node = node;
589 for (int i1 = 0; i1 < nbdown; i1++)
590 for (int j1 = 0; j1 < nbright; j1++)
592 int ij1 = j1 * nbdown + i1;
593 int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic; // i = x/face
594 int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc; // j = y/face
595 int ijk = k * nbx * nby + j * nbx + i;
596 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
597 np[ijk].node = quad->uv_grid[ij1].node;
598 //SCRUTE(np[ijk].nodeId);
602 // 2.0 - for each node of the cube:
603 // - get the 8 points 3D = 8 vertices of the cube
604 // - get the 12 points 3D on the 12 edges of the cube
605 // - get the 6 points 3D on the 6 faces with their ID
606 // - compute the point 3D
607 // - store the point 3D in SMESHDS, store its ID in 3D structure
610 TopExp_Explorer exp(aShape, TopAbs_SHELL);
613 aShell = TopoDS::Shell(exp.Current());
617 MESSAGE("no shell...");
621 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
622 Pt3 px00, px01, px10, px11;
623 Pt3 p0y0, p0y1, p1y0, p1y1;
624 Pt3 p00z, p01z, p10z, p11z;
625 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
627 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
628 GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
629 GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
630 GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
631 GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
632 GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
633 GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
634 GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
636 for (int i = 1; i < nbx - 1; i++)
638 for (int j = 1; j < nby - 1; j++)
640 for (int k = 1; k < nbz - 1; k++)
642 // *** seulement maillage regulier
643 // 12 points on edges
644 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
645 GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
646 GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
647 GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
649 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
650 GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
651 GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
652 GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
654 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
655 GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
656 GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
657 GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
659 // 12 points on faces
660 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
661 GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
662 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
663 GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
664 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
665 GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
667 int ijk = k * nbx * nby + j * nbx + i;
668 double x = double (i) / double (nbx - 1); // *** seulement
669 double y = double (j) / double (nby - 1); // *** maillage
670 double z = double (k) / double (nbz - 1); // *** regulier
673 for (int i = 0; i < 3; i++)
676 (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, TopoDS::Solid(aShape));
694 meshDS->SetNodeInVolume(node, aShell);
699 // find orientation of furute volumes according to MED convention
700 vector< bool > forward( nbx * nby );
701 SMDS_VolumeTool vTool;
702 for (int i = 0; i < nbx - 1; i++)
703 for (int j = 0; j < nby - 1; j++)
705 int n1 = j * nbx + i;
706 int n2 = j * nbx + i + 1;
707 int n3 = (j + 1) * nbx + i + 1;
708 int n4 = (j + 1) * nbx + i;
709 int n5 = nbx * nby + j * nbx + i;
710 int n6 = nbx * nby + j * nbx + i + 1;
711 int n7 = nbx * nby + (j + 1) * nbx + i + 1;
712 int n8 = nbx * nby + (j + 1) * nbx + i;
714 SMDS_VolumeOfNodes tmpVol (np[n1].node,np[n2].node,np[n3].node,np[n4].node,
715 np[n5].node,np[n6].node,np[n7].node,np[n8].node);
716 vTool.Set( &tmpVol );
717 forward[ n1 ] = vTool.IsForward();
720 //2.1 - for each node of the cube (less 3 *1 Faces):
721 // - store hexahedron in SMESHDS
722 MESSAGE("Storing hexahedron into the DS");
723 for (int i = 0; i < nbx - 1; i++)
724 for (int j = 0; j < nby - 1; j++)
726 bool isForw = forward.at( j * nbx + i );
727 for (int k = 0; k < nbz - 1; k++)
729 int n1 = k * nbx * nby + j * nbx + i;
730 int n2 = k * nbx * nby + j * nbx + i + 1;
731 int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
732 int n4 = k * nbx * nby + (j + 1) * nbx + i;
733 int n5 = (k + 1) * nbx * nby + j * nbx + i;
734 int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
735 int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
736 int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
738 SMDS_MeshVolume * elt;
740 elt = meshDS->AddVolume(np[n1].node,
749 elt = meshDS->AddVolume(np[n1].node,
758 meshDS->SetMeshElementOnShape(elt, aShell);
763 if ( np ) delete [] np;
764 //MESSAGE("End of StdMeshers_Hexa_3D::Compute()");
768 //=============================================================================
772 //=============================================================================
774 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby,
775 int nbz, Point3DStruct * np, const SMESHDS_Mesh * meshDS)
777 int ijk = k * nbx * nby + j * nbx + i;
778 const SMDS_MeshNode * node = np[ijk].node;
782 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
785 //=============================================================================
789 //=============================================================================
791 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
792 const TopoDS_Shape & aShape,
793 const vector < SMESH_subMesh * >&meshFaces,
794 const TopoDS_Vertex & V0,
795 const TopoDS_Vertex & V1,
796 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
798 //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
800 for (int i = 1; i < 6; i++)
802 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
803 //const TopoDS_Face& F = TopoDS::Face(aFace);
804 TopTools_IndexedMapOfShape M;
805 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
806 bool verticesInShape = false;
811 verticesInShape = true;
818 ASSERT(faceIndex > 0);
823 //=============================================================================
827 //=============================================================================
830 StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
831 const TopoDS_Shape & aShape,
832 const TopoDS_Face & aFace,
833 const TopoDS_Vertex & aVertex,
834 const TopTools_IndexedDataMapOfShapeListOfShape & MS)
836 //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
837 TopTools_IndexedDataMapOfShapeListOfShape MF;
838 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
839 const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
840 const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
841 // SCRUTE(ancestorsInSolid.Extent());
842 // SCRUTE(ancestorsInFace.Extent());
843 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
844 ASSERT(ancestorsInFace.Extent() == 2);
848 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
849 for (; its.More(); its.Next())
851 TopoDS_Shape ancestor = its.Value();
852 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
853 bool isInFace = false;
854 for (; itf.More(); itf.Next())
856 TopoDS_Shape ancestorInFace = itf.Value();
857 if (ancestorInFace.IsSame(ancestor))
865 E = TopoDS::Edge(ancestor);
872 //=============================================================================
876 //=============================================================================
878 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
879 const TopoDS_Shape & aShape,
880 const TopoDS_Vertex & V0,
881 const TopoDS_Vertex & V1,
882 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
884 // MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
885 const TopoDS_Face & F = TopoDS::Face(aShape);
886 TopoDS_Edge E = quad.edge[0];
888 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
889 TopoDS_Vertex VFirst, VLast;
890 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
891 bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
892 TopoDS_Vertex VA, VB;
903 int a1, b1, c1, a2, b2, c2;
916 ASSERT(VB.IsSame(V3));
936 ASSERT(VB.IsSame(V0));
956 ASSERT(VB.IsSame(V1));
976 ASSERT(VB.IsSame(V2));
984 // MESSAGE("X = " << c1 << "+ " << a1 << "*x + " << b1 << "*y");
985 // MESSAGE("Y = " << c2 << "+ " << a2 << "*x + " << b2 << "*y");
993 int nbdown = quad.nbPts[0];
994 int nbright = quad.nbPts[1];
998 int (c1 * a1 * a1) * (nbdown - 1) + int (c1 * b1 * b1) * (nbright - 1);
1002 int (c2 * a2 * a2) * (nbdown - 1) + int (c2 * b2 * b2) * (nbright - 1);
1003 // MESSAGE("I " << conv.ia << " " << conv.ib << " " << conv.ic);
1004 // MESSAGE("J " << conv.ja << " " << conv.jb << " " << conv.jc);
1007 //=============================================================================
1011 //=============================================================================
1013 ostream & StdMeshers_Hexa_3D::SaveTo(ostream & save)
1018 //=============================================================================
1022 //=============================================================================
1024 istream & StdMeshers_Hexa_3D::LoadFrom(istream & load)
1029 //=============================================================================
1033 //=============================================================================
1035 ostream & operator <<(ostream & save, StdMeshers_Hexa_3D & hyp)
1037 return hyp.SaveTo( save );
1040 //=============================================================================
1044 //=============================================================================
1046 istream & operator >>(istream & load, StdMeshers_Hexa_3D & hyp)
1048 return hyp.LoadFrom( load );
1051 //modified by NIZNHY-PKV Wed Nov 17 15:34:13 2004 f
1052 ///////////////////////////////////////////////////////////////////////////////
1054 //#include <stdio.h>
1056 //=======================================================================
1057 //function : ComputePentahedralMesh
1059 //=======================================================================
1060 bool ComputePentahedralMesh(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
1062 //printf(" ComputePentahedralMesh HERE\n");
1066 StdMeshers_Penta_3D anAlgo;
1068 bOK=anAlgo.Compute(aMesh, aShape);
1070 iErr=anAlgo.ErrorStatus();
1073 printf(" *** Error# %d\n", iErr);
1076 printf(" *** No errors# %d\n", iErr);