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>
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);
268 return ClearAndReturn( aQuads, false );
272 // 1. - identify faces and vertices of the "cube"
273 // 1.1 - ancestor maps vertex->edges in the cube
276 TopTools_IndexedDataMapOfShapeListOfShape MS;
277 TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
279 // 1.2 - first face is choosen as face Y=0 of the unit cube
282 const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
283 const TopoDS_Face & F = TopoDS::Face(aFace);
285 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
289 TopoDS_Edge E = aQuads[0]->edge[i]; //edge will be Y=0,Z=0 on unit cube
291 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
292 TopoDS_Vertex VFirst, VLast;
293 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
294 bool isForward = (((l - f) * (aQuads[0]->last[i] - aQuads[0]->first[i])) > 0);
297 aCube.V000 = VFirst; // will be (0,0,0) on the unit cube
298 aCube.V100 = VLast; // will be (1,0,0) on the unit cube
306 E = aQuads[0]->edge[i];
307 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
308 TopExp::Vertices(E, VFirst, VLast);
309 isForward = (((l - f) * (aQuads[0]->last[i] - aQuads[0]->first[i])) > 0);
311 aCube.V101 = VLast; // will be (1,0,1) on the unit cube
316 E = aQuads[0]->edge[i];
317 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
318 TopExp::Vertices(E, VFirst, VLast);
319 isForward = (((l - f) * (aQuads[0]->last[i] - aQuads[0]->first[i])) > 0);
321 aCube.V001 = VLast; // will be (0,0,1) on the unit cube
325 // 1.4 - find edge X=0, Z=0 (ancestor of V000 not in face Y=0)
326 // - find edge X=1, Z=0 (ancestor of V100 not in face Y=0)
327 // - find edge X=1, Z=1 (ancestor of V101 not in face Y=0)
328 // - find edge X=0, Z=1 (ancestor of V001 not in face Y=0)
331 TopoDS_Edge E_0Y0 = EdgeNotInFace(aMesh, aShape, F, aCube.V000, MS);
332 ASSERT(!E_0Y0.IsNull());
334 TopoDS_Edge E_1Y0 = EdgeNotInFace(aMesh, aShape, F, aCube.V100, MS);
335 ASSERT(!E_1Y0.IsNull());
337 TopoDS_Edge E_1Y1 = EdgeNotInFace(aMesh, aShape, F, aCube.V101, MS);
338 ASSERT(!E_1Y1.IsNull());
340 TopoDS_Edge E_0Y1 = EdgeNotInFace(aMesh, aShape, F, aCube.V001, MS);
341 ASSERT(!E_0Y1.IsNull());
343 // 1.5 - identify the 4 vertices in face Y=1: V010, V110, V111, V011
346 TopExp::Vertices(E_0Y0, VFirst, VLast);
347 if (VFirst.IsSame(aCube.V000))
352 TopExp::Vertices(E_1Y0, VFirst, VLast);
353 if (VFirst.IsSame(aCube.V100))
358 TopExp::Vertices(E_1Y1, VFirst, VLast);
359 if (VFirst.IsSame(aCube.V101))
364 TopExp::Vertices(E_0Y1, VFirst, VLast);
365 if (VFirst.IsSame(aCube.V001))
370 // 1.6 - find remaining faces given 4 vertices
374 aCube.quad_Y0 = aQuads[_indY0];
376 int _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
377 aCube.V010, aCube.V011, aCube.V110, aCube.V111);
378 aCube.quad_Y1 = aQuads[_indY1];
380 int _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
381 aCube.V000, aCube.V010, aCube.V100, aCube.V110);
382 aCube.quad_Z0 = aQuads[_indZ0];
384 int _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
385 aCube.V001, aCube.V011, aCube.V101, aCube.V111);
386 aCube.quad_Z1 = aQuads[_indZ1];
388 int _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
389 aCube.V000, aCube.V001, aCube.V010, aCube.V011);
390 aCube.quad_X0 = aQuads[_indX0];
392 int _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
393 aCube.V100, aCube.V101, aCube.V110, aCube.V111);
394 aCube.quad_X1 = aQuads[_indX1];
398 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
400 Conv2DStruct cx0; // for face X=0
401 Conv2DStruct cx1; // for face X=1
407 GetConv2DCoefs(*aCube.quad_X0, meshFaces[_indX0]->GetSubShape(),
408 aCube.V000, aCube.V010, aCube.V011, aCube.V001, cx0);
409 GetConv2DCoefs(*aCube.quad_X1, meshFaces[_indX1]->GetSubShape(),
410 aCube.V100, aCube.V110, aCube.V111, aCube.V101, cx1);
411 GetConv2DCoefs(*aCube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
412 aCube.V000, aCube.V100, aCube.V101, aCube.V001, cy0);
413 GetConv2DCoefs(*aCube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
414 aCube.V010, aCube.V110, aCube.V111, aCube.V011, cy1);
415 GetConv2DCoefs(*aCube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
416 aCube.V000, aCube.V100, aCube.V110, aCube.V010, cz0);
417 GetConv2DCoefs(*aCube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
418 aCube.V001, aCube.V101, aCube.V111, aCube.V011, cz1);
420 // 1.8 - create a 3D structure for normalized values
423 int nbx = aCube.quad_Z0->nbPts[0];
424 if (cz0.a1 == 0.) nbx = aCube.quad_Z0->nbPts[1];
426 int nby = aCube.quad_X0->nbPts[0];
427 if (cx0.a1 == 0.) nby = aCube.quad_X0->nbPts[1];
429 int nbz = aCube.quad_Y0->nbPts[0];
430 if (cy0.a1 != 0.) nbz = aCube.quad_Y0->nbPts[1];
432 int i1, j1, nbxyz = nbx * nby * nbz;
433 Point3DStruct *np = new Point3DStruct[nbxyz];
435 // 1.9 - store node indexes of faces
438 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
440 faceQuadStruct *quad = aCube.quad_X0;
441 int i = 0; // j = x/face , k = y/face
442 int nbdown = quad->nbPts[0];
443 int nbright = quad->nbPts[1];
445 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
448 const SMDS_MeshNode * node = itf->next();
449 if(aTool.IsMedium(node))
451 findIJ( node, quad, i1, j1 );
452 int ij1 = j1 * nbdown + i1;
453 quad->uv_grid[ij1].node = node;
456 for (int i1 = 0; i1 < nbdown; i1++)
457 for (int j1 = 0; j1 < nbright; j1++) {
458 int ij1 = j1 * nbdown + i1;
459 int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic; // j = x/face
460 int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc; // k = y/face
461 int ijk = k * nbx * nby + j * nbx + i;
462 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
463 np[ijk].node = quad->uv_grid[ij1].node;
464 //SCRUTE(np[ijk].nodeId);
469 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
471 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
473 faceQuadStruct *quad = aCube.quad_X1;
474 int i = nbx - 1; // j = x/face , k = y/face
475 int nbdown = quad->nbPts[0];
476 int nbright = quad->nbPts[1];
479 const SMDS_MeshNode * node = itf->next();
480 if(aTool.IsMedium(node))
482 findIJ( node, quad, i1, j1 );
483 int ij1 = j1 * nbdown + i1;
484 quad->uv_grid[ij1].node = node;
487 for (int i1 = 0; i1 < nbdown; i1++)
488 for (int j1 = 0; j1 < nbright; j1++) {
489 int ij1 = j1 * nbdown + i1;
490 int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic; // j = x/face
491 int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc; // k = y/face
492 int ijk = k * nbx * nby + j * nbx + i;
493 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
494 np[ijk].node = quad->uv_grid[ij1].node;
495 //SCRUTE(np[ijk].nodeId);
500 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
502 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
504 faceQuadStruct *quad = aCube.quad_Y0;
505 int j = 0; // i = x/face , k = y/face
506 int nbdown = quad->nbPts[0];
507 int nbright = quad->nbPts[1];
510 const SMDS_MeshNode * node = itf->next();
511 if(aTool.IsMedium(node))
513 findIJ( node, quad, i1, j1 );
514 int ij1 = j1 * nbdown + i1;
515 quad->uv_grid[ij1].node = node;
518 for (int i1 = 0; i1 < nbdown; i1++)
519 for (int j1 = 0; j1 < nbright; j1++) {
520 int ij1 = j1 * nbdown + i1;
521 int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic; // i = x/face
522 int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc; // k = y/face
523 int ijk = k * nbx * nby + j * nbx + i;
524 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
525 np[ijk].node = quad->uv_grid[ij1].node;
526 //SCRUTE(np[ijk].nodeId);
531 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
533 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
535 faceQuadStruct *quad = aCube.quad_Y1;
536 int j = nby - 1; // i = x/face , k = y/face
537 int nbdown = quad->nbPts[0];
538 int nbright = quad->nbPts[1];
541 const SMDS_MeshNode * node = itf->next();
542 if(aTool.IsMedium(node))
544 findIJ( node, quad, i1, j1 );
545 int ij1 = j1 * nbdown + i1;
546 quad->uv_grid[ij1].node = node;
549 for (int i1 = 0; i1 < nbdown; i1++)
550 for (int j1 = 0; j1 < nbright; j1++) {
551 int ij1 = j1 * nbdown + i1;
552 int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic; // i = x/face
553 int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc; // k = y/face
554 int ijk = k * nbx * nby + j * nbx + i;
555 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
556 np[ijk].node = quad->uv_grid[ij1].node;
557 //SCRUTE(np[ijk].nodeId);
562 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
564 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
566 faceQuadStruct *quad = aCube.quad_Z0;
567 int k = 0; // i = x/face , j = y/face
568 int nbdown = quad->nbPts[0];
569 int nbright = quad->nbPts[1];
572 const SMDS_MeshNode * node = itf->next();
573 if(aTool.IsMedium(node))
575 findIJ( node, quad, i1, j1 );
576 int ij1 = j1 * nbdown + i1;
577 quad->uv_grid[ij1].node = node;
580 for (int i1 = 0; i1 < nbdown; i1++)
581 for (int j1 = 0; j1 < nbright; j1++) {
582 int ij1 = j1 * nbdown + i1;
583 int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic; // i = x/face
584 int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc; // j = y/face
585 int ijk = k * nbx * nby + j * nbx + i;
586 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
587 np[ijk].node = quad->uv_grid[ij1].node;
588 //SCRUTE(np[ijk].nodeId);
593 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
595 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
597 faceQuadStruct *quad = aCube.quad_Z1;
598 int k = nbz - 1; // i = x/face , j = y/face
599 int nbdown = quad->nbPts[0];
600 int nbright = quad->nbPts[1];
603 const SMDS_MeshNode * node = itf->next();
604 if(aTool.IsMedium(node))
606 findIJ( node, quad, i1, j1 );
607 int ij1 = j1 * nbdown + i1;
608 quad->uv_grid[ij1].node = node;
611 for (int i1 = 0; i1 < nbdown; i1++)
612 for (int j1 = 0; j1 < nbright; j1++) {
613 int ij1 = j1 * nbdown + i1;
614 int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic; // i = x/face
615 int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc; // j = y/face
616 int ijk = k * nbx * nby + j * nbx + i;
617 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
618 np[ijk].node = quad->uv_grid[ij1].node;
619 //SCRUTE(np[ijk].nodeId);
623 // 2.0 - for each node of the cube:
624 // - get the 8 points 3D = 8 vertices of the cube
625 // - get the 12 points 3D on the 12 edges of the cube
626 // - get the 6 points 3D on the 6 faces with their ID
627 // - compute the point 3D
628 // - store the point 3D in SMESHDS, store its ID in 3D structure
630 int shapeID = meshDS->ShapeToIndex( aShape );
632 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
633 Pt3 px00, px01, px10, px11;
634 Pt3 p0y0, p0y1, p1y0, p1y1;
635 Pt3 p00z, p01z, p10z, p11z;
636 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
638 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
639 GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
640 GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
641 GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
642 GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
643 GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
644 GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
645 GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
647 for (int i = 1; i < nbx - 1; i++) {
648 for (int j = 1; j < nby - 1; j++) {
649 for (int k = 1; k < nbz - 1; k++) {
650 // *** seulement maillage regulier
651 // 12 points on edges
652 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
653 GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
654 GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
655 GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
657 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
658 GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
659 GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
660 GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
662 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
663 GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
664 GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
665 GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
667 // 12 points on faces
668 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
669 GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
670 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
671 GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
672 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
673 GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
675 int ijk = k * nbx * nby + j * nbx + i;
676 double x = double (i) / double (nbx - 1); // *** seulement
677 double y = double (j) / double (nby - 1); // *** maillage
678 double z = double (k) / double (nbz - 1); // *** regulier
681 for (int i = 0; i < 3; i++) {
682 X[i] = (1 - x) * p0yz[i] + x * p1yz[i]
683 + (1 - y) * px0z[i] + y * px1z[i]
684 + (1 - z) * pxy0[i] + z * pxy1[i]
685 - (1 - x) * ((1 - y) * p00z[i] + y * p01z[i])
686 - x * ((1 - y) * p10z[i] + y * p11z[i])
687 - (1 - y) * ((1 - z) * px00[i] + z * px01[i])
688 - y * ((1 - z) * px10[i] + z * px11[i])
689 - (1 - z) * ((1 - x) * p0y0[i] + x * p1y0[i])
690 - z * ((1 - x) * p0y1[i] + x * p1y1[i])
691 + (1 - x) * ((1 - y) * ((1 - z) * p000[i] + z * p001[i])
692 + y * ((1 - z) * p010[i] + z * p011[i]))
693 + x * ((1 - y) * ((1 - z) * p100[i] + z * p101[i])
694 + y * ((1 - z) * p110[i] + z * p111[i]));
697 SMDS_MeshNode * node = meshDS->AddNode(X[0], X[1], X[2]);
699 meshDS->SetNodeInVolume(node, shapeID);
704 // find orientation of furute volumes according to MED convention
705 vector< bool > forward( nbx * nby );
706 SMDS_VolumeTool vTool;
707 for (int i = 0; i < nbx - 1; i++) {
708 for (int j = 0; j < nby - 1; j++) {
709 int n1 = j * nbx + i;
710 int n2 = j * nbx + i + 1;
711 int n3 = (j + 1) * nbx + i + 1;
712 int n4 = (j + 1) * nbx + i;
713 int n5 = nbx * nby + j * nbx + i;
714 int n6 = nbx * nby + j * nbx + i + 1;
715 int n7 = nbx * nby + (j + 1) * nbx + i + 1;
716 int n8 = nbx * nby + (j + 1) * nbx + i;
718 SMDS_VolumeOfNodes tmpVol (np[n1].node,np[n2].node,np[n3].node,np[n4].node,
719 np[n5].node,np[n6].node,np[n7].node,np[n8].node);
720 vTool.Set( &tmpVol );
721 forward[ n1 ] = vTool.IsForward();
725 //2.1 - for each node of the cube (less 3 *1 Faces):
726 // - store hexahedron in SMESHDS
727 MESSAGE("Storing hexahedron into the DS");
728 for (int i = 0; i < nbx - 1; i++) {
729 for (int j = 0; j < nby - 1; j++) {
730 bool isForw = forward.at( j * nbx + i );
731 for (int k = 0; k < nbz - 1; k++) {
732 int n1 = k * nbx * nby + j * nbx + i;
733 int n2 = k * nbx * nby + j * nbx + i + 1;
734 int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
735 int n4 = k * nbx * nby + (j + 1) * nbx + i;
736 int n5 = (k + 1) * nbx * nby + j * nbx + i;
737 int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
738 int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
739 int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
741 SMDS_MeshVolume * elt;
743 //elt = meshDS->AddVolume(np[n1].node, np[n2].node,
744 // np[n3].node, np[n4].node,
745 // np[n5].node, np[n6].node,
746 // np[n7].node, np[n8].node);
747 elt = aTool.AddVolume(np[n1].node, np[n2].node,
748 np[n3].node, np[n4].node,
749 np[n5].node, np[n6].node,
750 np[n7].node, np[n8].node);
753 //elt = meshDS->AddVolume(np[n1].node, np[n4].node,
754 // np[n3].node, np[n2].node,
755 // np[n5].node, np[n8].node,
756 // np[n7].node, np[n6].node);
757 elt = aTool.AddVolume(np[n1].node, np[n4].node,
758 np[n3].node, np[n2].node,
759 np[n5].node, np[n8].node,
760 np[n7].node, np[n6].node);
763 meshDS->SetMeshElementOnShape(elt, shapeID);
767 if ( np ) delete [] np;
768 //MESSAGE("End of StdMeshers_Hexa_3D::Compute()");
769 return ClearAndReturn( aQuads, true );
772 //=============================================================================
776 //=============================================================================
778 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby,
779 int nbz, Point3DStruct * np, const SMESHDS_Mesh * meshDS)
781 int ijk = k * nbx * nby + j * nbx + i;
782 const SMDS_MeshNode * node = np[ijk].node;
786 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
789 //=============================================================================
793 //=============================================================================
795 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
796 const TopoDS_Shape & aShape,
797 const vector < SMESH_subMesh * >&meshFaces,
798 const TopoDS_Vertex & V0,
799 const TopoDS_Vertex & V1,
800 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
802 //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
804 for (int i = 1; i < 6; i++)
806 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
807 //const TopoDS_Face& F = TopoDS::Face(aFace);
808 TopTools_IndexedMapOfShape M;
809 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
810 bool verticesInShape = false;
815 verticesInShape = true;
822 ASSERT(faceIndex > 0);
827 //=============================================================================
831 //=============================================================================
834 StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
835 const TopoDS_Shape & aShape,
836 const TopoDS_Face & aFace,
837 const TopoDS_Vertex & aVertex,
838 const TopTools_IndexedDataMapOfShapeListOfShape & MS)
840 //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
841 TopTools_IndexedDataMapOfShapeListOfShape MF;
842 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
843 const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
844 const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
845 // SCRUTE(ancestorsInSolid.Extent());
846 // SCRUTE(ancestorsInFace.Extent());
847 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
848 ASSERT(ancestorsInFace.Extent() == 2);
852 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
853 for (; its.More(); its.Next())
855 TopoDS_Shape ancestor = its.Value();
856 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
857 bool isInFace = false;
858 for (; itf.More(); itf.Next())
860 TopoDS_Shape ancestorInFace = itf.Value();
861 if (ancestorInFace.IsSame(ancestor))
869 E = TopoDS::Edge(ancestor);
876 //=============================================================================
880 //=============================================================================
882 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
883 const TopoDS_Shape & aShape,
884 const TopoDS_Vertex & V0,
885 const TopoDS_Vertex & V1,
886 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
888 // MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
889 const TopoDS_Face & F = TopoDS::Face(aShape);
890 TopoDS_Edge E = quad.edge[0];
892 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
893 TopoDS_Vertex VFirst, VLast;
894 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
895 bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
896 TopoDS_Vertex VA, VB;
907 int a1, b1, c1, a2, b2, c2;
920 ASSERT(VB.IsSame(V3));
940 ASSERT(VB.IsSame(V0));
960 ASSERT(VB.IsSame(V1));
980 ASSERT(VB.IsSame(V2));
988 // MESSAGE("X = " << c1 << "+ " << a1 << "*x + " << b1 << "*y");
989 // MESSAGE("Y = " << c2 << "+ " << a2 << "*x + " << b2 << "*y");
997 int nbdown = quad.nbPts[0];
998 int nbright = quad.nbPts[1];
1002 int (c1 * a1 * a1) * (nbdown - 1) + int (c1 * b1 * b1) * (nbright - 1);
1006 int (c2 * a2 * a2) * (nbdown - 1) + int (c2 * b2 * b2) * (nbright - 1);
1007 // MESSAGE("I " << conv.ia << " " << conv.ib << " " << conv.ic);
1008 // MESSAGE("J " << conv.ja << " " << conv.jb << " " << conv.jc);
1011 //=============================================================================
1015 //=============================================================================
1017 ostream & StdMeshers_Hexa_3D::SaveTo(ostream & save)
1022 //=============================================================================
1026 //=============================================================================
1028 istream & StdMeshers_Hexa_3D::LoadFrom(istream & load)
1033 //=============================================================================
1037 //=============================================================================
1039 ostream & operator <<(ostream & save, StdMeshers_Hexa_3D & hyp)
1041 return hyp.SaveTo( save );
1044 //=============================================================================
1048 //=============================================================================
1050 istream & operator >>(istream & load, StdMeshers_Hexa_3D & hyp)
1052 return hyp.LoadFrom( load );
1055 //modified by NIZNHY-PKV Wed Nov 17 15:34:13 2004 f
1056 ///////////////////////////////////////////////////////////////////////////////
1058 //#include <stdio.h>
1060 //=======================================================================
1061 //function : ComputePentahedralMesh
1063 //=======================================================================
1064 bool ComputePentahedralMesh(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
1066 //printf(" ComputePentahedralMesh HERE\n");
1070 StdMeshers_Penta_3D anAlgo;
1072 bOK=anAlgo.Compute(aMesh, aShape);
1074 iErr=anAlgo.ErrorStatus();
1077 printf(" *** Error# %d\n", iErr);
1080 printf(" *** No errors# %d\n", iErr);