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"
39 #include "SMESH_Comment.hxx"
41 #include "SMDS_MeshElement.hxx"
42 #include "SMDS_MeshNode.hxx"
43 #include "SMDS_FacePosition.hxx"
44 #include "SMDS_VolumeTool.hxx"
45 #include "SMDS_VolumeOfNodes.hxx"
48 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
49 #include <TopTools_ListOfShape.hxx>
50 #include <TopTools_ListIteratorOfListOfShape.hxx>
51 #include <TColStd_MapOfInteger.hxx>
53 #include <BRep_Tool.hxx>
54 #include <Geom_Surface.hxx>
55 #include <gp_Pnt2d.hxx>
57 #include "utilities.h"
58 #include "Utils_ExceptHandlers.hxx"
60 typedef SMESH_Comment TComm;
64 static SMESH_ComputeErrorPtr ComputePentahedralMesh(SMESH_Mesh &, const TopoDS_Shape &);
66 //=============================================================================
70 //=============================================================================
72 StdMeshers_Hexa_3D::StdMeshers_Hexa_3D(int hypId, int studyId, SMESH_Gen * gen)
73 :SMESH_3D_Algo(hypId, studyId, gen)
75 MESSAGE("StdMeshers_Hexa_3D::StdMeshers_Hexa_3D");
77 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
80 //=============================================================================
84 //=============================================================================
86 StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D()
88 MESSAGE("StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D");
91 //================================================================================
93 * \brief Clear fields and return the argument
94 * \param res - the value to return
95 * \retval bool - the argument value
97 //================================================================================
99 bool StdMeshers_Hexa_3D::ClearAndReturn(FaceQuadStruct* theQuads[6], const bool res)
101 for (int i = 0; i < 6; i++) {
109 //=============================================================================
113 //=============================================================================
115 bool StdMeshers_Hexa_3D::CheckHypothesis
117 const TopoDS_Shape& aShape,
118 SMESH_Hypothesis::Hypothesis_Status& aStatus)
120 // check nb of faces in the shape
121 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
123 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next())
127 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->side[0]->NbPoints(), quad->side[2]->NbPoints());
146 int nbvertic = Min(quad->side[1]->NbPoints(), quad->side[3]->NbPoints());
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
186 vector < SMESH_subMesh * >meshFaces;
187 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
188 SMESH_subMesh *aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
190 meshFaces.push_back(aSubMesh);
192 if (meshFaces.size() != 6)
193 return error(COMPERR_BAD_SHAPE, TComm(meshFaces.size())<<" instead of 6 faces in block");
195 // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
197 // tool for working with quadratic elements
198 SMESH_MesherHelper aTool (aMesh);
199 _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
202 typedef struct cubeStruct
212 faceQuadStruct* quad_X0;
213 faceQuadStruct* quad_X1;
214 faceQuadStruct* quad_Y0;
215 faceQuadStruct* quad_Y1;
216 faceQuadStruct* quad_Z0;
217 faceQuadStruct* quad_Z1;
218 Point3DStruct* np; // normalised 3D coordinates
224 FaceQuadStruct* aQuads[6];
225 for (int i = 0; i < 6; i++)
228 for (int i = 0; i < 6; i++)
230 TopoDS_Shape aFace = meshFaces[i]->GetSubShape();
231 SMESH_Algo *algo = _gen->GetAlgo(aMesh, aFace);
232 string algoName = algo->GetName();
233 bool isAllQuad = false;
234 if (algoName == "Quadrangle_2D") {
235 SMESHDS_SubMesh * sm = meshDS->MeshElements( aFace );
238 SMDS_ElemIteratorPtr eIt = sm->GetElements();
239 while ( isAllQuad && eIt->more() ) {
240 const SMDS_MeshElement* elem = eIt->next();
241 isAllQuad = ( elem->NbNodes()==4 ||(_quadraticMesh && elem->NbNodes()==8) );
246 SMESH_ComputeErrorPtr err = ComputePentahedralMesh(aMesh, aShape);
247 return ClearAndReturn( aQuads, error(err));
249 StdMeshers_Quadrangle_2D *quadAlgo =
250 dynamic_cast < StdMeshers_Quadrangle_2D * >(algo);
253 aQuads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aFace, _quadraticMesh);
255 catch(SALOME_Exception & S_ex) {
256 return ClearAndReturn( aQuads, error(COMPERR_SLM_EXCEPTION,TComm(S_ex.what()) <<
257 " Raised by StdMeshers_Quadrangle_2D "
258 " on face #" << meshDS->ShapeToIndex( aFace )));
261 // 0.2.1 - number of points on the opposite edges must be the same
262 if (aQuads[i]->side[0]->NbPoints() != aQuads[i]->side[2]->NbPoints() ||
263 aQuads[i]->side[1]->NbPoints() != aQuads[i]->side[3]->NbPoints()
264 /*aQuads[i]->side[0]->NbEdges() != 1 ||
265 aQuads[i]->side[1]->NbEdges() != 1 ||
266 aQuads[i]->side[2]->NbEdges() != 1 ||
267 aQuads[i]->side[3]->NbEdges() != 1*/) {
268 MESSAGE("different number of points on the opposite edges of face " << i);
269 // Try to go into penta algorithm 'cause it has been improved.
270 SMESH_ComputeErrorPtr err = ComputePentahedralMesh(aMesh, aShape);
271 return ClearAndReturn( aQuads, error(err));
275 // 1. - identify faces and vertices of the "cube"
276 // 1.1 - ancestor maps vertex->edges in the cube
278 TopTools_IndexedDataMapOfShapeListOfShape MS;
279 TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
281 // 1.2 - first face is choosen as face Y=0 of the unit cube
283 const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
284 const TopoDS_Face & F = TopoDS::Face(aFace);
286 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
288 aCube.V000 = aQuads[0]->side[0]->FirstVertex(); // will be (0,0,0) on the unit cube
289 aCube.V100 = aQuads[0]->side[0]->LastVertex(); // will be (1,0,0) on the unit cube
290 aCube.V001 = aQuads[0]->side[2]->FirstVertex(); // will be (0,0,1) on the unit cube
291 aCube.V101 = aQuads[0]->side[2]->LastVertex(); // will be (1,0,1) on the unit cube
293 TopTools_IndexedMapOfShape MV0;
294 TopExp::MapShapes(F, TopAbs_VERTEX, MV0);
296 aCube.V010 = OppositeVertex( aCube.V000, MV0, aQuads);
297 aCube.V110 = OppositeVertex( aCube.V100, MV0, aQuads);
298 aCube.V011 = OppositeVertex( aCube.V001, MV0, aQuads);
299 aCube.V111 = OppositeVertex( aCube.V101, MV0, aQuads);
301 // 1.6 - find remaining faces given 4 vertices
304 aCube.quad_Y0 = aQuads[_indY0];
306 int _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
307 aCube.V010, aCube.V011, aCube.V110, aCube.V111);
308 aCube.quad_Y1 = aQuads[_indY1];
310 int _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
311 aCube.V000, aCube.V010, aCube.V100, aCube.V110);
312 aCube.quad_Z0 = aQuads[_indZ0];
314 int _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
315 aCube.V001, aCube.V011, aCube.V101, aCube.V111);
316 aCube.quad_Z1 = aQuads[_indZ1];
318 int _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
319 aCube.V000, aCube.V001, aCube.V010, aCube.V011);
320 aCube.quad_X0 = aQuads[_indX0];
322 int _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
323 aCube.V100, aCube.V101, aCube.V110, aCube.V111);
324 aCube.quad_X1 = aQuads[_indX1];
326 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
328 Conv2DStruct cx0; // for face X=0
329 Conv2DStruct cx1; // for face X=1
335 GetConv2DCoefs(*aCube.quad_X0, meshFaces[_indX0]->GetSubShape(),
336 aCube.V000, aCube.V010, aCube.V011, aCube.V001, cx0);
337 GetConv2DCoefs(*aCube.quad_X1, meshFaces[_indX1]->GetSubShape(),
338 aCube.V100, aCube.V110, aCube.V111, aCube.V101, cx1);
339 GetConv2DCoefs(*aCube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
340 aCube.V000, aCube.V100, aCube.V101, aCube.V001, cy0);
341 GetConv2DCoefs(*aCube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
342 aCube.V010, aCube.V110, aCube.V111, aCube.V011, cy1);
343 GetConv2DCoefs(*aCube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
344 aCube.V000, aCube.V100, aCube.V110, aCube.V010, cz0);
345 GetConv2DCoefs(*aCube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
346 aCube.V001, aCube.V101, aCube.V111, aCube.V011, cz1);
348 // 1.8 - create a 3D structure for normalized values
350 int nbx = aCube.quad_Z0->side[0]->NbPoints();
351 if (cz0.a1 == 0.) nbx = aCube.quad_Z0->side[1]->NbPoints();
353 int nby = aCube.quad_X0->side[0]->NbPoints();
354 if (cx0.a1 == 0.) nby = aCube.quad_X0->side[1]->NbPoints();
356 int nbz = aCube.quad_Y0->side[0]->NbPoints();
357 if (cy0.a1 != 0.) nbz = aCube.quad_Y0->side[1]->NbPoints();
359 int i1, j1, nbxyz = nbx * nby * nbz;
360 Point3DStruct *np = new Point3DStruct[nbxyz];
362 // 1.9 - store node indexes of faces
365 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
367 faceQuadStruct *quad = aCube.quad_X0;
368 int i = 0; // j = x/face , k = y/face
369 int nbdown = quad->side[0]->NbPoints();
370 int nbright = quad->side[1]->NbPoints();
372 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
375 const SMDS_MeshNode * node = itf->next();
376 if(aTool.IsMedium(node))
378 if ( !findIJ( node, quad, i1, j1 ))
379 return ClearAndReturn( aQuads, false );
380 int ij1 = j1 * nbdown + i1;
381 quad->uv_grid[ij1].node = node;
384 for (int i1 = 0; i1 < nbdown; i1++)
385 for (int j1 = 0; j1 < nbright; j1++) {
386 int ij1 = j1 * nbdown + i1;
387 int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic; // j = x/face
388 int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc; // k = y/face
389 int ijk = k * nbx * nby + j * nbx + i;
390 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
391 np[ijk].node = quad->uv_grid[ij1].node;
392 //SCRUTE(np[ijk].nodeId);
397 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
399 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
401 faceQuadStruct *quad = aCube.quad_X1;
402 int i = nbx - 1; // j = x/face , k = y/face
403 int nbdown = quad->side[0]->NbPoints();
404 int nbright = quad->side[1]->NbPoints();
407 const SMDS_MeshNode * node = itf->next();
408 if(aTool.IsMedium(node))
410 if ( !findIJ( node, quad, i1, j1 ))
411 return ClearAndReturn( aQuads, false );
412 int ij1 = j1 * nbdown + i1;
413 quad->uv_grid[ij1].node = node;
416 for (int i1 = 0; i1 < nbdown; i1++)
417 for (int j1 = 0; j1 < nbright; j1++) {
418 int ij1 = j1 * nbdown + i1;
419 int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic; // j = x/face
420 int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc; // k = y/face
421 int ijk = k * nbx * nby + j * nbx + i;
422 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
423 np[ijk].node = quad->uv_grid[ij1].node;
424 //SCRUTE(np[ijk].nodeId);
429 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
431 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
433 faceQuadStruct *quad = aCube.quad_Y0;
434 int j = 0; // i = x/face , k = y/face
435 int nbdown = quad->side[0]->NbPoints();
436 int nbright = quad->side[1]->NbPoints();
439 const SMDS_MeshNode * node = itf->next();
440 if(aTool.IsMedium(node))
442 if ( !findIJ( node, quad, i1, j1 ))
443 return ClearAndReturn( aQuads, false );
444 int ij1 = j1 * nbdown + i1;
445 quad->uv_grid[ij1].node = node;
448 for (int i1 = 0; i1 < nbdown; i1++)
449 for (int j1 = 0; j1 < nbright; j1++) {
450 int ij1 = j1 * nbdown + i1;
451 int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic; // i = x/face
452 int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc; // k = y/face
453 int ijk = k * nbx * nby + j * nbx + i;
454 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
455 np[ijk].node = quad->uv_grid[ij1].node;
456 //SCRUTE(np[ijk].nodeId);
461 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
463 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
465 faceQuadStruct *quad = aCube.quad_Y1;
466 int j = nby - 1; // i = x/face , k = y/face
467 int nbdown = quad->side[0]->NbPoints();
468 int nbright = quad->side[1]->NbPoints();
471 const SMDS_MeshNode * node = itf->next();
472 if(aTool.IsMedium(node))
474 if ( !findIJ( node, quad, i1, j1 ))
475 return ClearAndReturn( aQuads, false );
476 int ij1 = j1 * nbdown + i1;
477 quad->uv_grid[ij1].node = node;
480 for (int i1 = 0; i1 < nbdown; i1++)
481 for (int j1 = 0; j1 < nbright; j1++) {
482 int ij1 = j1 * nbdown + i1;
483 int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic; // i = x/face
484 int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc; // k = y/face
485 int ijk = k * nbx * nby + j * nbx + i;
486 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
487 np[ijk].node = quad->uv_grid[ij1].node;
488 //SCRUTE(np[ijk].nodeId);
493 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
495 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
497 faceQuadStruct *quad = aCube.quad_Z0;
498 int k = 0; // i = x/face , j = y/face
499 int nbdown = quad->side[0]->NbPoints();
500 int nbright = quad->side[1]->NbPoints();
503 const SMDS_MeshNode * node = itf->next();
504 if(aTool.IsMedium(node))
506 if ( !findIJ( node, quad, i1, j1 ))
507 return ClearAndReturn( aQuads, false );
508 int ij1 = j1 * nbdown + i1;
509 quad->uv_grid[ij1].node = node;
512 for (int i1 = 0; i1 < nbdown; i1++)
513 for (int j1 = 0; j1 < nbright; j1++) {
514 int ij1 = j1 * nbdown + i1;
515 int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic; // i = x/face
516 int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc; // j = y/face
517 int ijk = k * nbx * nby + j * nbx + i;
518 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
519 np[ijk].node = quad->uv_grid[ij1].node;
520 //SCRUTE(np[ijk].nodeId);
525 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
527 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
529 faceQuadStruct *quad = aCube.quad_Z1;
530 int k = nbz - 1; // i = x/face , j = y/face
531 int nbdown = quad->side[0]->NbPoints();
532 int nbright = quad->side[1]->NbPoints();
535 const SMDS_MeshNode * node = itf->next();
536 if(aTool.IsMedium(node))
538 if ( !findIJ( node, quad, i1, j1 ))
539 return ClearAndReturn( aQuads, false );
540 int ij1 = j1 * nbdown + i1;
541 quad->uv_grid[ij1].node = node;
544 for (int i1 = 0; i1 < nbdown; i1++)
545 for (int j1 = 0; j1 < nbright; j1++) {
546 int ij1 = j1 * nbdown + i1;
547 int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic; // i = x/face
548 int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc; // j = y/face
549 int ijk = k * nbx * nby + j * nbx + i;
550 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
551 np[ijk].node = quad->uv_grid[ij1].node;
552 //SCRUTE(np[ijk].nodeId);
556 // 2.0 - for each node of the cube:
557 // - get the 8 points 3D = 8 vertices of the cube
558 // - get the 12 points 3D on the 12 edges of the cube
559 // - get the 6 points 3D on the 6 faces with their ID
560 // - compute the point 3D
561 // - store the point 3D in SMESHDS, store its ID in 3D structure
563 int shapeID = meshDS->ShapeToIndex( aShape );
565 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
566 Pt3 px00, px01, px10, px11;
567 Pt3 p0y0, p0y1, p1y0, p1y1;
568 Pt3 p00z, p01z, p10z, p11z;
569 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
571 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
572 GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
573 GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
574 GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
575 GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
576 GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
577 GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
578 GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
580 for (int i = 1; i < nbx - 1; i++) {
581 for (int j = 1; j < nby - 1; j++) {
582 for (int k = 1; k < nbz - 1; k++) {
583 // *** seulement maillage regulier
584 // 12 points on edges
585 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
586 GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
587 GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
588 GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
590 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
591 GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
592 GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
593 GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
595 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
596 GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
597 GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
598 GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
600 // 12 points on faces
601 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
602 GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
603 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
604 GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
605 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
606 GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
608 int ijk = k * nbx * nby + j * nbx + i;
609 double x = double (i) / double (nbx - 1); // *** seulement
610 double y = double (j) / double (nby - 1); // *** maillage
611 double z = double (k) / double (nbz - 1); // *** regulier
614 for (int i = 0; i < 3; i++) {
615 X[i] = (1 - x) * p0yz[i] + x * p1yz[i]
616 + (1 - y) * px0z[i] + y * px1z[i]
617 + (1 - z) * pxy0[i] + z * pxy1[i]
618 - (1 - x) * ((1 - y) * p00z[i] + y * p01z[i])
619 - x * ((1 - y) * p10z[i] + y * p11z[i])
620 - (1 - y) * ((1 - z) * px00[i] + z * px01[i])
621 - y * ((1 - z) * px10[i] + z * px11[i])
622 - (1 - z) * ((1 - x) * p0y0[i] + x * p1y0[i])
623 - z * ((1 - x) * p0y1[i] + x * p1y1[i])
624 + (1 - x) * ((1 - y) * ((1 - z) * p000[i] + z * p001[i])
625 + y * ((1 - z) * p010[i] + z * p011[i]))
626 + x * ((1 - y) * ((1 - z) * p100[i] + z * p101[i])
627 + y * ((1 - z) * p110[i] + z * p111[i]));
630 SMDS_MeshNode * node = meshDS->AddNode(X[0], X[1], X[2]);
632 meshDS->SetNodeInVolume(node, shapeID);
637 // find orientation of furute volumes according to MED convention
638 vector< bool > forward( nbx * nby );
639 SMDS_VolumeTool vTool;
640 for (int i = 0; i < nbx - 1; i++) {
641 for (int j = 0; j < nby - 1; j++) {
642 int n1 = j * nbx + i;
643 int n2 = j * nbx + i + 1;
644 int n3 = (j + 1) * nbx + i + 1;
645 int n4 = (j + 1) * nbx + i;
646 int n5 = nbx * nby + j * nbx + i;
647 int n6 = nbx * nby + j * nbx + i + 1;
648 int n7 = nbx * nby + (j + 1) * nbx + i + 1;
649 int n8 = nbx * nby + (j + 1) * nbx + i;
651 SMDS_VolumeOfNodes tmpVol (np[n1].node,np[n2].node,np[n3].node,np[n4].node,
652 np[n5].node,np[n6].node,np[n7].node,np[n8].node);
653 vTool.Set( &tmpVol );
654 forward[ n1 ] = vTool.IsForward();
658 //2.1 - for each node of the cube (less 3 *1 Faces):
659 // - store hexahedron in SMESHDS
660 MESSAGE("Storing hexahedron into the DS");
661 for (int i = 0; i < nbx - 1; i++) {
662 for (int j = 0; j < nby - 1; j++) {
663 bool isForw = forward.at( j * nbx + i );
664 for (int k = 0; k < nbz - 1; k++) {
665 int n1 = k * nbx * nby + j * nbx + i;
666 int n2 = k * nbx * nby + j * nbx + i + 1;
667 int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
668 int n4 = k * nbx * nby + (j + 1) * nbx + i;
669 int n5 = (k + 1) * nbx * nby + j * nbx + i;
670 int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
671 int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
672 int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
674 SMDS_MeshVolume * elt;
676 elt = aTool.AddVolume(np[n1].node, np[n2].node,
677 np[n3].node, np[n4].node,
678 np[n5].node, np[n6].node,
679 np[n7].node, np[n8].node);
682 elt = aTool.AddVolume(np[n1].node, np[n4].node,
683 np[n3].node, np[n2].node,
684 np[n5].node, np[n8].node,
685 np[n7].node, np[n6].node);
688 meshDS->SetMeshElementOnShape(elt, shapeID);
692 if ( np ) delete [] np;
693 return ClearAndReturn( aQuads, true );
696 //=============================================================================
700 //=============================================================================
702 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby, int nbz,
703 Point3DStruct * np, const SMESHDS_Mesh * meshDS)
705 int ijk = k * nbx * nby + j * nbx + i;
706 const SMDS_MeshNode * node = np[ijk].node;
710 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
713 //=============================================================================
717 //=============================================================================
719 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
720 const TopoDS_Shape & aShape,
721 const vector < SMESH_subMesh * >&meshFaces,
722 const TopoDS_Vertex & V0,
723 const TopoDS_Vertex & V1,
724 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
726 //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
728 for (int i = 1; i < 6; i++)
730 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
731 //const TopoDS_Face& F = TopoDS::Face(aFace);
732 TopTools_IndexedMapOfShape M;
733 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
734 bool verticesInShape = false;
739 verticesInShape = true;
746 ASSERT(faceIndex > 0);
751 //=============================================================================
755 //=============================================================================
758 StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
759 const TopoDS_Shape & aShape,
760 const TopoDS_Face & aFace,
761 const TopoDS_Vertex & aVertex,
762 const TopTools_IndexedDataMapOfShapeListOfShape & MS)
764 //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
765 TopTools_IndexedDataMapOfShapeListOfShape MF;
766 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
767 const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
768 const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
769 // SCRUTE(ancestorsInSolid.Extent());
770 // SCRUTE(ancestorsInFace.Extent());
771 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
772 ASSERT(ancestorsInFace.Extent() == 2);
776 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
777 for (; its.More(); its.Next())
779 TopoDS_Shape ancestor = its.Value();
780 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
781 bool isInFace = false;
782 for (; itf.More(); itf.Next())
784 TopoDS_Shape ancestorInFace = itf.Value();
785 if (ancestorInFace.IsSame(ancestor))
793 E = TopoDS::Edge(ancestor);
800 //=============================================================================
804 //=============================================================================
806 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
807 const TopoDS_Shape & aShape,
808 const TopoDS_Vertex & V0,
809 const TopoDS_Vertex & V1,
810 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
812 // MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
813 // const TopoDS_Face & F = TopoDS::Face(aShape);
814 // TopoDS_Edge E = quad.edge[0];
816 // Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
817 // TopoDS_Vertex VFirst, VLast;
818 // TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
819 // bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
820 TopoDS_Vertex VA, VB;
831 VA = quad.side[0]->FirstVertex();
832 VB = quad.side[0]->LastVertex();
834 int a1, b1, c1, a2, b2, c2;
847 ASSERT(VB.IsSame(V3));
867 ASSERT(VB.IsSame(V0));
887 ASSERT(VB.IsSame(V1));
907 ASSERT(VB.IsSame(V2));
915 // MESSAGE("X = " << c1 << "+ " << a1 << "*x + " << b1 << "*y");
916 // MESSAGE("Y = " << c2 << "+ " << a2 << "*x + " << b2 << "*y");
924 int nbdown = quad.side[0]->NbPoints();
925 int nbright = quad.side[1]->NbPoints();
929 int (c1 * a1 * a1) * (nbdown - 1) + int (c1 * b1 * b1) * (nbright - 1);
933 int (c2 * a2 * a2) * (nbdown - 1) + int (c2 * b2 * b2) * (nbright - 1);
934 // MESSAGE("I " << conv.ia << " " << conv.ib << " " << conv.ic);
935 // MESSAGE("J " << conv.ja << " " << conv.jb << " " << conv.jc);
938 //================================================================================
940 * \brief Find a vertex opposite to the given vertex of aQuads[0]
941 * \param aVertex - the vertex
942 * \param aFace - the face aVertex belongs to
943 * \param aQuads - quads
944 * \retval TopoDS_Vertex - found vertex
946 //================================================================================
948 TopoDS_Vertex StdMeshers_Hexa_3D::OppositeVertex(const TopoDS_Vertex& aVertex,
949 const TopTools_IndexedMapOfShape& aQuads0Vertices,
950 FaceQuadStruct* aQuads[6])
953 for ( i = 1; i < 6; ++i )
955 TopoDS_Vertex VV[] = { aQuads[i]->side[0]->FirstVertex(),
956 aQuads[i]->side[0]->LastVertex() ,
957 aQuads[i]->side[2]->LastVertex() ,
958 aQuads[i]->side[2]->FirstVertex() };
959 for ( j = 0; j < 4; ++j )
960 if ( aVertex.IsSame( VV[ j ]))
963 int jPrev = j ? j - 1 : 3;
964 int jNext = (j + 1) % 4;
965 if ( aQuads0Vertices.Contains( VV[ jPrev ] ))
971 return TopoDS_Vertex();
974 //modified by NIZNHY-PKV Wed Nov 17 15:34:13 2004 f
975 ///////////////////////////////////////////////////////////////////////////////
979 //=======================================================================
980 //function : ComputePentahedralMesh
982 //=======================================================================
984 SMESH_ComputeErrorPtr ComputePentahedralMesh(SMESH_Mesh & aMesh,
985 const TopoDS_Shape & aShape)
987 //printf(" ComputePentahedralMesh HERE\n");
990 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
992 StdMeshers_Penta_3D anAlgo;
994 bOK=anAlgo.Compute(aMesh, aShape);
996 err = anAlgo.GetComputeError();
998 if ( !bOK && anAlgo.ErrorStatus() == 5 )
1000 static StdMeshers_Prism_3D * aPrism3D = 0;
1002 SMESH_Gen* gen = aMesh.GetGen();
1003 aPrism3D = new StdMeshers_Prism_3D( gen->GetANewId(), 0, gen );
1005 SMESH_Hypothesis::Hypothesis_Status aStatus;
1006 if ( aPrism3D->CheckHypothesis( aMesh, aShape, aStatus ) ) {
1007 bOK = aPrism3D->Compute( aMesh, aShape );
1008 err = aPrism3D->GetComputeError();