1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : StdMeshers_Hexa_3D.cxx
25 // Moved here from SMESH_Hexa_3D.cxx
26 // Author : Paul RASCLE, EDF
30 #include "StdMeshers_Hexa_3D.hxx"
31 #include "StdMeshers_Quadrangle_2D.hxx"
32 #include "StdMeshers_FaceSide.hxx"
33 #include "StdMeshers_Penta_3D.hxx"
34 #include "StdMeshers_Prism_3D.hxx"
36 #include "SMESH_Gen.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_subMesh.hxx"
40 #include "SMDS_MeshElement.hxx"
41 #include "SMDS_MeshNode.hxx"
42 #include "SMDS_FacePosition.hxx"
43 #include "SMDS_VolumeTool.hxx"
44 #include "SMDS_VolumeOfNodes.hxx"
47 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
48 #include <TopTools_ListOfShape.hxx>
49 #include <TopTools_ListIteratorOfListOfShape.hxx>
50 #include <TColStd_ListIteratorOfListOfInteger.hxx>
51 #include <TColStd_MapOfInteger.hxx>
53 #include <BRep_Tool.hxx>
54 #include <Geom_Surface.hxx>
55 #include <Geom_Curve.hxx>
56 #include <Geom2d_Curve.hxx>
57 #include <Handle_Geom2d_Curve.hxx>
58 #include <Handle_Geom_Curve.hxx>
59 #include <gp_Pnt2d.hxx>
61 #include "utilities.h"
62 #include "Utils_ExceptHandlers.hxx"
66 static bool ComputePentahedralMesh(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape);
68 //=============================================================================
72 //=============================================================================
74 StdMeshers_Hexa_3D::StdMeshers_Hexa_3D(int hypId, int studyId,
75 SMESH_Gen * gen):SMESH_3D_Algo(hypId, studyId, gen)
77 MESSAGE("StdMeshers_Hexa_3D::StdMeshers_Hexa_3D");
79 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
82 //=============================================================================
86 //=============================================================================
88 StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D()
90 MESSAGE("StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D");
93 //================================================================================
95 * \brief Clear fields and return the argument
96 * \param res - the value to return
97 * \retval bool - the argument value
99 //================================================================================
101 bool StdMeshers_Hexa_3D::ClearAndReturn(FaceQuadStruct* theQuads[6], const bool res)
103 for (int i = 0; i < 6; i++) {
111 //=============================================================================
115 //=============================================================================
117 bool StdMeshers_Hexa_3D::CheckHypothesis
119 const TopoDS_Shape& aShape,
120 SMESH_Hypothesis::Hypothesis_Status& aStatus)
122 //MESSAGE("StdMeshers_Hexa_3D::CheckHypothesis");
125 aStatus = SMESH_Hypothesis::HYP_OK;
132 //=======================================================================
134 //purpose : return i,j of the node
135 //=======================================================================
137 static bool findIJ (const SMDS_MeshNode* node, const FaceQuadStruct * quad, int& I, int& J)
140 const SMDS_FacePosition* fpos =
141 static_cast<const SMDS_FacePosition*>(node->GetPosition().get());
142 if ( ! fpos ) return false;
143 gp_Pnt2d uv( fpos->GetUParameter(), fpos->GetVParameter() );
145 double minDist = DBL_MAX;
146 int nbhoriz = Min(quad->side[0]->NbPoints(), quad->side[2]->NbPoints());
147 int nbvertic = Min(quad->side[1]->NbPoints(), quad->side[3]->NbPoints());
148 for (int i = 1; i < nbhoriz - 1; i++) {
149 for (int j = 1; j < nbvertic - 1; j++) {
150 int ij = j * nbhoriz + i;
151 gp_Pnt2d uv2( quad->uv_grid[ij].u, quad->uv_grid[ij].v );
152 double dist = uv.SquareDistance( uv2 );
153 if ( dist < minDist ) {
164 //=============================================================================
166 * Hexahedron mesh on hexaedron like form
167 * -0. - shape and face mesh verification
168 * -1. - identify faces and vertices of the "cube"
169 * -2. - Algorithm from:
170 * "Application de l'interpolation transfinie à la création de maillages
171 * C0 ou G1 continus sur des triangles, quadrangles, tetraedres, pentaedres
172 * et hexaedres déformés."
173 * Alain PERONNET - 8 janvier 1999
175 //=============================================================================
177 bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh & aMesh,
178 const TopoDS_Shape & aShape)throw(SALOME_Exception)
180 Unexpect aCatch(SalomeException);
181 MESSAGE("StdMeshers_Hexa_3D::Compute");
182 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
184 // 0. - shape and face mesh verification
185 // 0.1 - shape must be a solid (or a shell) with 6 faces
188 vector < SMESH_subMesh * >meshFaces;
189 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
190 SMESH_subMesh *aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
192 meshFaces.push_back(aSubMesh);
194 if (meshFaces.size() != 6) {
195 SCRUTE(meshFaces.size());
199 // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
202 // tool for working with quadratic elements
203 SMESH_MesherHelper aTool (aMesh);
204 _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
207 typedef struct cubeStruct
217 faceQuadStruct* quad_X0;
218 faceQuadStruct* quad_X1;
219 faceQuadStruct* quad_Y0;
220 faceQuadStruct* quad_Y1;
221 faceQuadStruct* quad_Z0;
222 faceQuadStruct* quad_Z1;
223 Point3DStruct* np; // normalised 3D coordinates
229 FaceQuadStruct* aQuads[6];
230 for (int i = 0; i < 6; i++)
233 for (int i = 0; i < 6; i++) {
234 TopoDS_Shape aFace = meshFaces[i]->GetSubShape();
235 SMESH_Algo *algo = _gen->GetAlgo(aMesh, aFace);
236 string algoName = algo->GetName();
237 bool isAllQuad = false;
238 if (algoName == "Quadrangle_2D") {
239 SMESHDS_SubMesh * sm = meshDS->MeshElements( aFace );
242 SMDS_ElemIteratorPtr eIt = sm->GetElements();
243 while ( isAllQuad && eIt->more() ) {
244 const SMDS_MeshElement* elem = eIt->next();
245 isAllQuad = ( elem->NbNodes()==4 ||(_quadraticMesh && elem->NbNodes()==8) );
250 //modified by NIZNHY-PKV Wed Nov 17 15:31:37 2004 f
251 bool bIsOk = ComputePentahedralMesh(aMesh, aShape);
252 return ClearAndReturn( aQuads, bIsOk );
254 StdMeshers_Quadrangle_2D *quadAlgo =
255 dynamic_cast < StdMeshers_Quadrangle_2D * >(algo);
258 aQuads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aFace, _quadraticMesh);
260 catch(SALOME_Exception & S_ex) {
261 return ClearAndReturn( aQuads, false );
264 // 0.2.1 - number of points on the opposite edges must be the same
265 if (aQuads[i]->side[0]->NbPoints() != aQuads[i]->side[2]->NbPoints() ||
266 aQuads[i]->side[1]->NbPoints() != aQuads[i]->side[3]->NbPoints()
267 /*aQuads[i]->side[0]->NbEdges() != 1 ||
268 aQuads[i]->side[1]->NbEdges() != 1 ||
269 aQuads[i]->side[2]->NbEdges() != 1 ||
270 aQuads[i]->side[3]->NbEdges() != 1*/) {
271 MESSAGE("different number of points on the opposite edges of face " << i);
274 // Try to go into penta algorithm 'cause it has been improved.
275 // return ClearAndReturn( aQuads, false );
276 bool bIsOk = ComputePentahedralMesh(aMesh, aShape);
277 return ClearAndReturn( aQuads, bIsOk );
282 // 1. - identify faces and vertices of the "cube"
283 // 1.1 - ancestor maps vertex->edges in the cube
286 TopTools_IndexedDataMapOfShapeListOfShape MS;
287 TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
289 // 1.2 - first face is choosen as face Y=0 of the unit cube
292 const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
293 const TopoDS_Face & F = TopoDS::Face(aFace);
295 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
298 aCube.V000 = aQuads[0]->side[0]->FirstVertex(); // will be (0,0,0) on the unit cube
299 aCube.V100 = aQuads[0]->side[0]->LastVertex(); // will be (1,0,0) on the unit cube
300 aCube.V001 = aQuads[0]->side[2]->FirstVertex(); // will be (0,0,1) on the unit cube
301 aCube.V101 = aQuads[0]->side[2]->LastVertex(); // will be (1,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, aCube.V000, MS);
310 // ASSERT(!E_0Y0.IsNull());
312 // TopoDS_Edge E_1Y0 = EdgeNotInFace(aMesh, aShape, F, aCube.V100, MS);
313 // ASSERT(!E_1Y0.IsNull());
315 // TopoDS_Edge E_1Y1 = EdgeNotInFace(aMesh, aShape, F, aCube.V101, MS);
316 // ASSERT(!E_1Y1.IsNull());
318 // TopoDS_Edge E_0Y1 = EdgeNotInFace(aMesh, aShape, F, aCube.V001, MS);
319 // ASSERT(!E_0Y1.IsNull());
321 // 1.5 - identify the 4 vertices in face Y=1: V010, V110, V111, V011
324 TopTools_IndexedMapOfShape MV0;
325 TopExp::MapShapes(F, TopAbs_VERTEX, MV0);
327 aCube.V010 = OppositeVertex( aCube.V000, MV0, aQuads);
328 aCube.V110 = OppositeVertex( aCube.V100, MV0, aQuads);
329 aCube.V011 = OppositeVertex( aCube.V001, MV0, aQuads);
330 aCube.V111 = OppositeVertex( aCube.V101, MV0, aQuads);
332 // TopoDS_Vertex VFirst, VLast;
333 // TopExp::Vertices(E_0Y0, VFirst, VLast);
334 // if (VFirst.IsSame(aCube.V000))
335 // aCube.V010 = VLast;
337 // aCube.V010 = VFirst;
339 // TopExp::Vertices(E_1Y0, VFirst, VLast);
340 // if (VFirst.IsSame(aCube.V100))
341 // aCube.V110 = VLast;
343 // aCube.V110 = VFirst;
345 // TopExp::Vertices(E_1Y1, VFirst, VLast);
346 // if (VFirst.IsSame(aCube.V101))
347 // aCube.V111 = VLast;
349 // aCube.V111 = VFirst;
351 // TopExp::Vertices(E_0Y1, VFirst, VLast);
352 // if (VFirst.IsSame(aCube.V001))
353 // aCube.V011 = VLast;
355 // aCube.V011 = VFirst;
357 // 1.6 - find remaining faces given 4 vertices
361 aCube.quad_Y0 = aQuads[_indY0];
363 int _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
364 aCube.V010, aCube.V011, aCube.V110, aCube.V111);
365 aCube.quad_Y1 = aQuads[_indY1];
367 int _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
368 aCube.V000, aCube.V010, aCube.V100, aCube.V110);
369 aCube.quad_Z0 = aQuads[_indZ0];
371 int _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
372 aCube.V001, aCube.V011, aCube.V101, aCube.V111);
373 aCube.quad_Z1 = aQuads[_indZ1];
375 int _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
376 aCube.V000, aCube.V001, aCube.V010, aCube.V011);
377 aCube.quad_X0 = aQuads[_indX0];
379 int _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
380 aCube.V100, aCube.V101, aCube.V110, aCube.V111);
381 aCube.quad_X1 = aQuads[_indX1];
385 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
387 Conv2DStruct cx0; // for face X=0
388 Conv2DStruct cx1; // for face X=1
394 GetConv2DCoefs(*aCube.quad_X0, meshFaces[_indX0]->GetSubShape(),
395 aCube.V000, aCube.V010, aCube.V011, aCube.V001, cx0);
396 GetConv2DCoefs(*aCube.quad_X1, meshFaces[_indX1]->GetSubShape(),
397 aCube.V100, aCube.V110, aCube.V111, aCube.V101, cx1);
398 GetConv2DCoefs(*aCube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
399 aCube.V000, aCube.V100, aCube.V101, aCube.V001, cy0);
400 GetConv2DCoefs(*aCube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
401 aCube.V010, aCube.V110, aCube.V111, aCube.V011, cy1);
402 GetConv2DCoefs(*aCube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
403 aCube.V000, aCube.V100, aCube.V110, aCube.V010, cz0);
404 GetConv2DCoefs(*aCube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
405 aCube.V001, aCube.V101, aCube.V111, aCube.V011, cz1);
407 // 1.8 - create a 3D structure for normalized values
410 int nbx = aCube.quad_Z0->side[0]->NbPoints();
411 if (cz0.a1 == 0.) nbx = aCube.quad_Z0->side[1]->NbPoints();
413 int nby = aCube.quad_X0->side[0]->NbPoints();
414 if (cx0.a1 == 0.) nby = aCube.quad_X0->side[1]->NbPoints();
416 int nbz = aCube.quad_Y0->side[0]->NbPoints();
417 if (cy0.a1 != 0.) nbz = aCube.quad_Y0->side[1]->NbPoints();
419 int i1, j1, nbxyz = nbx * nby * nbz;
420 Point3DStruct *np = new Point3DStruct[nbxyz];
422 // 1.9 - store node indexes of faces
425 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
427 faceQuadStruct *quad = aCube.quad_X0;
428 int i = 0; // j = x/face , k = y/face
429 int nbdown = quad->side[0]->NbPoints();
430 int nbright = quad->side[1]->NbPoints();
432 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
435 const SMDS_MeshNode * node = itf->next();
436 if(aTool.IsMedium(node))
438 if ( !findIJ( node, quad, i1, j1 ))
439 return ClearAndReturn( aQuads, false );
440 int ij1 = j1 * nbdown + i1;
441 quad->uv_grid[ij1].node = node;
444 for (int i1 = 0; i1 < nbdown; i1++)
445 for (int j1 = 0; j1 < nbright; j1++) {
446 int ij1 = j1 * nbdown + i1;
447 int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic; // j = x/face
448 int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc; // k = y/face
449 int ijk = k * nbx * nby + j * nbx + i;
450 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
451 np[ijk].node = quad->uv_grid[ij1].node;
452 //SCRUTE(np[ijk].nodeId);
457 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
459 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
461 faceQuadStruct *quad = aCube.quad_X1;
462 int i = nbx - 1; // j = x/face , k = y/face
463 int nbdown = quad->side[0]->NbPoints();
464 int nbright = quad->side[1]->NbPoints();
467 const SMDS_MeshNode * node = itf->next();
468 if(aTool.IsMedium(node))
470 if ( !findIJ( node, quad, i1, j1 ))
471 return ClearAndReturn( aQuads, false );
472 int ij1 = j1 * nbdown + i1;
473 quad->uv_grid[ij1].node = node;
476 for (int i1 = 0; i1 < nbdown; i1++)
477 for (int j1 = 0; j1 < nbright; j1++) {
478 int ij1 = j1 * nbdown + i1;
479 int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic; // j = x/face
480 int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc; // k = y/face
481 int ijk = k * nbx * nby + j * nbx + i;
482 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
483 np[ijk].node = quad->uv_grid[ij1].node;
484 //SCRUTE(np[ijk].nodeId);
489 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
491 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
493 faceQuadStruct *quad = aCube.quad_Y0;
494 int j = 0; // i = x/face , k = y/face
495 int nbdown = quad->side[0]->NbPoints();
496 int nbright = quad->side[1]->NbPoints();
499 const SMDS_MeshNode * node = itf->next();
500 if(aTool.IsMedium(node))
502 if ( !findIJ( node, quad, i1, j1 ))
503 return ClearAndReturn( aQuads, false );
504 int ij1 = j1 * nbdown + i1;
505 quad->uv_grid[ij1].node = node;
508 for (int i1 = 0; i1 < nbdown; i1++)
509 for (int j1 = 0; j1 < nbright; j1++) {
510 int ij1 = j1 * nbdown + i1;
511 int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic; // i = x/face
512 int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc; // k = y/face
513 int ijk = k * nbx * nby + j * nbx + i;
514 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
515 np[ijk].node = quad->uv_grid[ij1].node;
516 //SCRUTE(np[ijk].nodeId);
521 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
523 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
525 faceQuadStruct *quad = aCube.quad_Y1;
526 int j = nby - 1; // i = x/face , k = y/face
527 int nbdown = quad->side[0]->NbPoints();
528 int nbright = quad->side[1]->NbPoints();
531 const SMDS_MeshNode * node = itf->next();
532 if(aTool.IsMedium(node))
534 if ( !findIJ( node, quad, i1, j1 ))
535 return ClearAndReturn( aQuads, false );
536 int ij1 = j1 * nbdown + i1;
537 quad->uv_grid[ij1].node = node;
540 for (int i1 = 0; i1 < nbdown; i1++)
541 for (int j1 = 0; j1 < nbright; j1++) {
542 int ij1 = j1 * nbdown + i1;
543 int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic; // i = x/face
544 int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc; // k = y/face
545 int ijk = k * nbx * nby + j * nbx + i;
546 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
547 np[ijk].node = quad->uv_grid[ij1].node;
548 //SCRUTE(np[ijk].nodeId);
553 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
555 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
557 faceQuadStruct *quad = aCube.quad_Z0;
558 int k = 0; // i = x/face , j = y/face
559 int nbdown = quad->side[0]->NbPoints();
560 int nbright = quad->side[1]->NbPoints();
563 const SMDS_MeshNode * node = itf->next();
564 if(aTool.IsMedium(node))
566 if ( !findIJ( node, quad, i1, j1 ))
567 return ClearAndReturn( aQuads, false );
568 int ij1 = j1 * nbdown + i1;
569 quad->uv_grid[ij1].node = node;
572 for (int i1 = 0; i1 < nbdown; i1++)
573 for (int j1 = 0; j1 < nbright; j1++) {
574 int ij1 = j1 * nbdown + i1;
575 int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic; // i = x/face
576 int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc; // j = y/face
577 int ijk = k * nbx * nby + j * nbx + i;
578 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
579 np[ijk].node = quad->uv_grid[ij1].node;
580 //SCRUTE(np[ijk].nodeId);
585 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
587 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
589 faceQuadStruct *quad = aCube.quad_Z1;
590 int k = nbz - 1; // i = x/face , j = y/face
591 int nbdown = quad->side[0]->NbPoints();
592 int nbright = quad->side[1]->NbPoints();
595 const SMDS_MeshNode * node = itf->next();
596 if(aTool.IsMedium(node))
598 if ( !findIJ( node, quad, i1, j1 ))
599 return ClearAndReturn( aQuads, false );
600 int ij1 = j1 * nbdown + i1;
601 quad->uv_grid[ij1].node = node;
604 for (int i1 = 0; i1 < nbdown; i1++)
605 for (int j1 = 0; j1 < nbright; j1++) {
606 int ij1 = j1 * nbdown + i1;
607 int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic; // i = x/face
608 int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc; // j = y/face
609 int ijk = k * nbx * nby + j * nbx + i;
610 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
611 np[ijk].node = quad->uv_grid[ij1].node;
612 //SCRUTE(np[ijk].nodeId);
616 // 2.0 - for each node of the cube:
617 // - get the 8 points 3D = 8 vertices of the cube
618 // - get the 12 points 3D on the 12 edges of the cube
619 // - get the 6 points 3D on the 6 faces with their ID
620 // - compute the point 3D
621 // - store the point 3D in SMESHDS, store its ID in 3D structure
623 int shapeID = meshDS->ShapeToIndex( aShape );
625 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
626 Pt3 px00, px01, px10, px11;
627 Pt3 p0y0, p0y1, p1y0, p1y1;
628 Pt3 p00z, p01z, p10z, p11z;
629 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
631 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
632 GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
633 GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
634 GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
635 GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
636 GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
637 GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
638 GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
640 for (int i = 1; i < nbx - 1; i++) {
641 for (int j = 1; j < nby - 1; j++) {
642 for (int k = 1; k < nbz - 1; k++) {
643 // *** seulement maillage regulier
644 // 12 points on edges
645 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
646 GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
647 GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
648 GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
650 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
651 GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
652 GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
653 GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
655 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
656 GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
657 GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
658 GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
660 // 12 points on faces
661 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
662 GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
663 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
664 GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
665 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
666 GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
668 int ijk = k * nbx * nby + j * nbx + i;
669 double x = double (i) / double (nbx - 1); // *** seulement
670 double y = double (j) / double (nby - 1); // *** maillage
671 double z = double (k) / double (nbz - 1); // *** regulier
674 for (int i = 0; i < 3; i++) {
675 X[i] = (1 - x) * p0yz[i] + x * p1yz[i]
676 + (1 - y) * px0z[i] + y * px1z[i]
677 + (1 - z) * pxy0[i] + z * pxy1[i]
678 - (1 - x) * ((1 - y) * p00z[i] + y * p01z[i])
679 - x * ((1 - y) * p10z[i] + y * p11z[i])
680 - (1 - y) * ((1 - z) * px00[i] + z * px01[i])
681 - y * ((1 - z) * px10[i] + z * px11[i])
682 - (1 - z) * ((1 - x) * p0y0[i] + x * p1y0[i])
683 - z * ((1 - x) * p0y1[i] + x * p1y1[i])
684 + (1 - x) * ((1 - y) * ((1 - z) * p000[i] + z * p001[i])
685 + y * ((1 - z) * p010[i] + z * p011[i]))
686 + x * ((1 - y) * ((1 - z) * p100[i] + z * p101[i])
687 + y * ((1 - z) * p110[i] + z * p111[i]));
690 SMDS_MeshNode * node = meshDS->AddNode(X[0], X[1], X[2]);
692 meshDS->SetNodeInVolume(node, shapeID);
697 // find orientation of furute volumes according to MED convention
698 vector< bool > forward( nbx * nby );
699 SMDS_VolumeTool vTool;
700 for (int i = 0; i < nbx - 1; i++) {
701 for (int j = 0; j < nby - 1; j++) {
702 int n1 = j * nbx + i;
703 int n2 = j * nbx + i + 1;
704 int n3 = (j + 1) * nbx + i + 1;
705 int n4 = (j + 1) * nbx + i;
706 int n5 = nbx * nby + j * nbx + i;
707 int n6 = nbx * nby + j * nbx + i + 1;
708 int n7 = nbx * nby + (j + 1) * nbx + i + 1;
709 int n8 = nbx * nby + (j + 1) * nbx + i;
711 SMDS_VolumeOfNodes tmpVol (np[n1].node,np[n2].node,np[n3].node,np[n4].node,
712 np[n5].node,np[n6].node,np[n7].node,np[n8].node);
713 vTool.Set( &tmpVol );
714 forward[ n1 ] = vTool.IsForward();
718 //2.1 - for each node of the cube (less 3 *1 Faces):
719 // - store hexahedron in SMESHDS
720 MESSAGE("Storing hexahedron into the DS");
721 for (int i = 0; i < nbx - 1; i++) {
722 for (int j = 0; j < nby - 1; j++) {
723 bool isForw = forward.at( j * nbx + i );
724 for (int k = 0; k < nbz - 1; k++) {
725 int n1 = k * nbx * nby + j * nbx + i;
726 int n2 = k * nbx * nby + j * nbx + i + 1;
727 int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
728 int n4 = k * nbx * nby + (j + 1) * nbx + i;
729 int n5 = (k + 1) * nbx * nby + j * nbx + i;
730 int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
731 int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
732 int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
734 SMDS_MeshVolume * elt;
736 //elt = meshDS->AddVolume(np[n1].node, np[n2].node,
737 // np[n3].node, np[n4].node,
738 // np[n5].node, np[n6].node,
739 // np[n7].node, np[n8].node);
740 elt = aTool.AddVolume(np[n1].node, np[n2].node,
741 np[n3].node, np[n4].node,
742 np[n5].node, np[n6].node,
743 np[n7].node, np[n8].node);
746 //elt = meshDS->AddVolume(np[n1].node, np[n4].node,
747 // np[n3].node, np[n2].node,
748 // np[n5].node, np[n8].node,
749 // np[n7].node, np[n6].node);
750 elt = aTool.AddVolume(np[n1].node, np[n4].node,
751 np[n3].node, np[n2].node,
752 np[n5].node, np[n8].node,
753 np[n7].node, np[n6].node);
756 meshDS->SetMeshElementOnShape(elt, shapeID);
760 if ( np ) delete [] np;
761 //MESSAGE("End of StdMeshers_Hexa_3D::Compute()");
762 return ClearAndReturn( aQuads, true );
765 //=============================================================================
769 //=============================================================================
771 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby,
772 int nbz, Point3DStruct * np, const SMESHDS_Mesh * meshDS)
774 int ijk = k * nbx * nby + j * nbx + i;
775 const SMDS_MeshNode * node = np[ijk].node;
779 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
782 //=============================================================================
786 //=============================================================================
788 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
789 const TopoDS_Shape & aShape,
790 const vector < SMESH_subMesh * >&meshFaces,
791 const TopoDS_Vertex & V0,
792 const TopoDS_Vertex & V1,
793 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
795 //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
797 for (int i = 1; i < 6; i++)
799 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
800 //const TopoDS_Face& F = TopoDS::Face(aFace);
801 TopTools_IndexedMapOfShape M;
802 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
803 bool verticesInShape = false;
808 verticesInShape = true;
815 ASSERT(faceIndex > 0);
820 //=============================================================================
824 //=============================================================================
827 StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
828 const TopoDS_Shape & aShape,
829 const TopoDS_Face & aFace,
830 const TopoDS_Vertex & aVertex,
831 const TopTools_IndexedDataMapOfShapeListOfShape & MS)
833 //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
834 TopTools_IndexedDataMapOfShapeListOfShape MF;
835 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
836 const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
837 const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
838 // SCRUTE(ancestorsInSolid.Extent());
839 // SCRUTE(ancestorsInFace.Extent());
840 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
841 ASSERT(ancestorsInFace.Extent() == 2);
845 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
846 for (; its.More(); its.Next())
848 TopoDS_Shape ancestor = its.Value();
849 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
850 bool isInFace = false;
851 for (; itf.More(); itf.Next())
853 TopoDS_Shape ancestorInFace = itf.Value();
854 if (ancestorInFace.IsSame(ancestor))
862 E = TopoDS::Edge(ancestor);
869 //=============================================================================
873 //=============================================================================
875 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
876 const TopoDS_Shape & aShape,
877 const TopoDS_Vertex & V0,
878 const TopoDS_Vertex & V1,
879 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
881 // MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
882 // const TopoDS_Face & F = TopoDS::Face(aShape);
883 // TopoDS_Edge E = quad.edge[0];
885 // Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
886 // TopoDS_Vertex VFirst, VLast;
887 // TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
888 // bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
889 TopoDS_Vertex VA, VB;
900 VA = quad.side[0]->FirstVertex();
901 VB = quad.side[0]->LastVertex();
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.side[0]->NbPoints();
994 int nbright = quad.side[1]->NbPoints();
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 //================================================================================
1009 * \brief Find a vertex opposite to the given vertex of aQuads[0]
1010 * \param aVertex - the vertex
1011 * \param aFace - the face aVertex belongs to
1012 * \param aQuads - quads
1013 * \retval TopoDS_Vertex - found vertex
1015 //================================================================================
1017 TopoDS_Vertex StdMeshers_Hexa_3D::OppositeVertex(const TopoDS_Vertex& aVertex,
1018 const TopTools_IndexedMapOfShape& aQuads0Vertices,
1019 FaceQuadStruct* aQuads[6])
1022 for ( i = 1; i < 6; ++i )
1024 TopoDS_Vertex VV[] = { aQuads[i]->side[0]->FirstVertex(),
1025 aQuads[i]->side[0]->LastVertex() ,
1026 aQuads[i]->side[2]->LastVertex() ,
1027 aQuads[i]->side[2]->FirstVertex() };
1028 for ( j = 0; j < 4; ++j )
1029 if ( aVertex.IsSame( VV[ j ]))
1032 int jPrev = j ? j - 1 : 3;
1033 int jNext = (j + 1) % 4;
1034 if ( aQuads0Vertices.Contains( VV[ jPrev ] ))
1040 return TopoDS_Vertex();
1043 //modified by NIZNHY-PKV Wed Nov 17 15:34:13 2004 f
1044 ///////////////////////////////////////////////////////////////////////////////
1046 //#include <stdio.h>
1048 //=======================================================================
1049 //function : ComputePentahedralMesh
1051 //=======================================================================
1052 bool ComputePentahedralMesh(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
1054 //printf(" ComputePentahedralMesh HERE\n");
1058 StdMeshers_Penta_3D anAlgo;
1060 bOK=anAlgo.Compute(aMesh, aShape);
1062 if ( !bOK && anAlgo.ErrorStatus() == 5 )
1064 static StdMeshers_Prism_3D * aPrism3D = 0;
1066 SMESH_Gen* gen = aMesh.GetGen();
1067 aPrism3D = new StdMeshers_Prism_3D( gen->GetANewId(), 0, gen );
1069 SMESH_Hypothesis::Hypothesis_Status aStatus;
1070 if ( aPrism3D->CheckHypothesis( aMesh, aShape, aStatus ) )
1071 bOK = aPrism3D->Compute( aMesh, aShape );