1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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
23 // SMESH StdMeshers_Penta_3D implementation of SMESH idl descriptions
24 // File : StdMeshers_Penta_3D.cxx
27 #include "StdMeshers_Penta_3D.hxx"
29 #include "utilities.h"
30 #include "Utils_ExceptHandlers.hxx"
32 #include "SMDS_EdgePosition.hxx"
33 #include "SMDS_MeshElement.hxx"
34 #include "SMDS_VolumeOfNodes.hxx"
35 #include "SMDS_VolumeTool.hxx"
36 #include "SMESHDS_Mesh.hxx"
37 #include "SMESHDS_SubMesh.hxx"
38 #include "SMESH_Comment.hxx"
39 #include "SMESH_Mesh.hxx"
40 #include "SMESH_MeshAlgos.hxx"
41 #include "SMESH_MesherHelper.hxx"
42 #include "SMESH_subMesh.hxx"
43 #include "SMESH_subMeshEventListener.hxx"
45 #include <BRep_Tool.hxx>
47 #include <TopExp_Explorer.hxx>
48 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
50 #include <TopTools_ListIteratorOfListOfShape.hxx>
51 #include <TopTools_ListOfShape.hxx>
52 #include <TopTools_SequenceOfShape.hxx>
53 #include <TopTools_MapOfShape.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Shell.hxx>
57 #include <TopoDS_Vertex.hxx>
65 typedef map < int, int, less<int> >::iterator \
66 StdMeshers_IteratorOfDataMapOfIntegerInteger;
68 enum { NB_WALL_FACES = 4 };
70 //=======================================================================
71 //function : StdMeshers_Penta_3D
73 //=======================================================================
74 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
75 : myErrorStatus(SMESH_ComputeError::New())
78 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
79 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
83 //=======================================================================
84 //function : ~StdMeshers_Penta_3D
86 //=======================================================================
88 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
92 //=======================================================================
95 //=======================================================================
96 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
97 const TopoDS_Shape& aShape)
105 if (!myErrorStatus->IsOK()) {
111 if (!myErrorStatus->IsOK()) {
116 if (!myErrorStatus->IsOK()) {
120 // now unnecessary faces removed, we can load medium nodes
121 SMESH_MesherHelper helper(aMesh);
123 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
127 if (!myErrorStatus->IsOK()) {
134 if (!myErrorStatus->IsOK()) {
143 //=======================================================================
144 //function : MakeNodes
146 //=======================================================================
147 void StdMeshers_Penta_3D::MakeNodes()
150 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
152 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
153 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
154 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
155 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
156 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
160 SMESH_Mesh* pMesh=GetMesh();
162 // 1. Define the sizes of mesh
164 // 1.1 Horizontal size
166 for (i=0; i<aNbSIDs; ++i) {
167 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
168 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
170 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
171 if(!myCreateQuadratic) {
172 iNbN = aSM->NbNodes();
176 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
178 const SMDS_MeshNode* aNode = itn->next();
179 if(myTool->IsMedium(aNode))
186 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
191 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
192 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
194 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
195 if(!myCreateQuadratic) {
196 iNbN = aSM->NbNodes();
200 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
202 const SMDS_MeshNode* aNode = itn->next();
203 if(myTool->IsMedium(aNode))
210 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
212 aSize=myISize*myJSize;
213 myTNodes.resize(aSize);
215 StdMeshers_TNode aTNode;
219 // 2. Fill the repers on base face (Z=0)
222 for (k=0; k<aNbSIDs; ++k) {
224 const TopoDS_Shape& aS = myBlock.Shape(aSID);
225 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
227 const SMDS_MeshNode* aNode = ite->next();
228 if(myTool->IsMedium(aNode))
230 aNodeID=aNode->GetID();
232 aTNode.SetNode(aNode);
233 aTNode.SetShapeSupportID(aSID);
234 aTNode.SetBaseNodeID(aNodeID);
236 if ( SMESH_Block::IsEdgeID (aSID)) {
237 SMDS_EdgePositionPtr epos = aNode->GetPosition();
238 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
244 aP3D.SetCoord(aX, aY, aZ);
245 myBlock.ComputeParameters(aP3D, aS, aCoords);
247 iErr = myBlock.ErrorStatus();
249 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
250 "SMESHBlock: ComputeParameters operation failed");
251 myErrorStatus=myBlock.GetError();
254 aTNode.SetNormCoord(aCoords);
261 // 3.1 Fill maps of wall nodes
262 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
263 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
264 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
266 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
267 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
268 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
270 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
271 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
272 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
273 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
274 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
277 myErrorStatus->myName = COMPERR_BAD_INPUT_MESH;
278 myErrorStatus->myComment = SMESH_Comment() <<
279 "Can't find regular quadrangle mesh on a side face #" <<
280 pMesh->GetMeshDS()->ShapeToIndex( myBlock.Shape( wallFaceID[ i ]));
285 // 3.2 find node columns for vertical edges and edge IDs
286 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
287 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
288 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
290 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
291 ShapeSupportID(false, vID, eID);
292 verticEdgeID[ i ] = eID;
294 StdMeshers_TNode& aTNode = myTNodes[ i ];
295 verticEdgeNodes[ i ] = 0;
296 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
297 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
298 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
299 if ( ijNodes.begin()->second[0] == aTNode.Node() )
300 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
301 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
302 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
303 if ( verticEdgeNodes[ i ] )
308 // 3.3 set XYZ of vertices, and initialize of the rest
309 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
310 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
311 if ( SMESH_Block::IsVertexID( id )) {
312 TopoDS_Shape V = myBlock.Shape( id );
313 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
314 const SMDS_MeshNode* n = sm->GetNodes()->next();
315 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
318 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
322 // 4. Fill the rest repers
325 SMESH_Block::TShapeID aSSID, aBNSSID;
326 StdMeshers_TNode aTN;
329 // create top face and find UV for it's corners
330 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
331 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
332 int topfaceID = meshDS->ShapeToIndex(TopFace);
333 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
334 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
335 const SMDS_MeshNode* N = itn->next();
336 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
337 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
338 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
340 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
341 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
342 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
344 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
345 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
346 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
348 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
350 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
352 const StdMeshers_TNode& aBN = myTNodes[j];
353 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
354 iBNID = aBN.BaseNodeID();
355 const gp_XYZ& aBNXYZ = aBN.NormCoord();
356 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
358 // set XYZ on horizontal edges and get node columns of faces:
359 // 2 columns for each face, between which a base node is located
360 vector<const SMDS_MeshNode*>* nColumns[8];
361 double ratio[ NB_WALL_FACES ] = {0,0,0,0}; // base node position between columns [0.-1.]
363 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
364 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
365 nColumns[k*2], nColumns[k*2+1]);
369 // XYZ on the bottom and top faces
370 const SMDS_MeshNode* n = aBN.Node();
371 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
372 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
374 // first create or find a top node, then the rest ones in a column
375 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
377 bIsUpperLayer = (i==(myISize-1));
378 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
379 if ( createNode ) // a base node is inside a top face
381 // set XYZ on vertical edges and faces
382 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
383 // XYZ on a vertical edge
384 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
385 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
386 // XYZ on a face (part 1 from one column)
387 n = (*nColumns[k*2]) [ i ];
388 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
389 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
391 if( bIsUpperLayer ) {
392 tmp1 = myTool->GetNodeUV(TopFace,n);
393 tmp1 = ( 1. - ratio[ k ]) * tmp1;
395 // XYZ on a face (part 2 from other column)
396 n = (*nColumns[k*2+1]) [ i ];
397 xyz.SetCoord( n->X(), n->Y(), n->Z() );
398 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
399 if( bIsUpperLayer ) {
400 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
401 tmp1 += ratio[ k ] * tmp2;
413 // fill current node info
416 // -normalized coordinates
420 aZ=(double)i/(double)(myISize-1);
421 aCoords.SetCoord(aX, aY, aZ);
423 // supporting shape ID
424 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
425 if (!myErrorStatus->IsOK()) {
426 MESSAGE("StdMeshers_Penta_3D::MakeNodes() pb");
430 aTN.SetShapeSupportID(aSSID);
431 aTN.SetNormCoord(aCoords);
432 aTN.SetBaseNodeID(iBNID);
434 if (aSSID!=SMESH_Block::ID_NONE){
435 // try to find the node
436 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
437 FindNodeOnShape(aS, aCoords, i, aTN);
440 // create node and get its id
441 CreateNode (bIsUpperLayer, aCoords, aTN);
443 if ( bIsUpperLayer ) {
444 const SMDS_MeshNode* n = aTN.Node();
445 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
446 // set node on top face:
447 // find UV parameter for this node
449 // UV011+-----+----------+UV111
452 // UV_E0y1+ +node +UV_E1y1
456 // UV001+-----+----------+UV101
459 double u = aCoords.X(), v = aCoords.Y();
460 double u1 = ( 1. - u ), v1 = ( 1. - v );
461 aP.ChangeCoord() = UV_Ex01 * v1;
462 aP.ChangeCoord() += UV_Ex11 * v;
463 aP.ChangeCoord() += UV_E0y1 * u1;
464 aP.ChangeCoord() += UV_E1y1 * u;
465 aP.ChangeCoord() -= UV001 * u1 * v1;
466 aP.ChangeCoord() -= UV101 * u * v1;
467 aP.ChangeCoord() -= UV011 * u1 * v;
468 aP.ChangeCoord() -= UV111 * u * v;
469 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
472 if (!myErrorStatus->IsOK()) {
473 MESSAGE("StdMeshers_Penta_3D::MakeNodes() err");
483 //=======================================================================
484 //function : FindNodeOnShape
486 //=======================================================================
488 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
489 const gp_XYZ& aParams,
491 StdMeshers_TNode& aTN)
493 double aX, aY, aZ, aD, aTol2, minD;
496 SMESH_Mesh* pMesh = GetMesh();
497 aTol2 = myTol3D*myTol3D;
499 SMDS_MeshNode* pNode = NULL;
501 if ( aS.ShapeType() == TopAbs_FACE ||
502 aS.ShapeType() == TopAbs_EDGE ) {
503 // find a face ID to which aTN belongs to
505 if ( aS.ShapeType() == TopAbs_FACE )
506 faceID = myBlock.ShapeID( aS );
507 else { // edge maybe vertical or top horizontal
508 gp_XYZ aCoord = aParams;
509 if ( aCoord.Z() == 1. )
510 aCoord.SetZ( 0.5 ); // move from top down
512 aCoord.SetX( 0.5 ); // move along X
513 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
515 ASSERT( SMESH_Block::IsFaceID( faceID ));
516 int fIndex = SMESH_Block::ShapeIndex( faceID );
517 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
518 // look for a base node in ijNodes
519 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
520 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
521 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
522 if ( par_nVec->second[ 0 ] == baseNode ) {
523 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
529 myBlock.Point(aParams, aS, aP1);
531 SMDS_NodeIteratorPtr ite=
532 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
534 const SMDS_MeshNode* aNode = ite->next();
535 if(myTool->IsMedium(aNode))
540 aP2.SetCoord(aX, aY, aZ);
541 aD=(double)aP1.SquareDistance(aP2);
542 //printf("** D=%lf ", aD, aTol2);
544 pNode=(SMDS_MeshNode*)aNode;
554 //aTN.SetNode(pNode);
555 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
556 //myErrorStatus=11; // can not find the node;
560 //=======================================================================
561 //function : SetHorizEdgeXYZ
563 //=======================================================================
565 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
567 vector<const SMDS_MeshNode*>*& aCol1,
568 vector<const SMDS_MeshNode*>*& aCol2)
570 // find base and top edges of the face
571 enum { BASE = 0, TOP };
572 vector< int > edgeVec; // 0-base, 1-top
573 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
575 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
576 bool isForward = myBlock.IsForwardEdge( edgeVec[ BASE ] );
578 double param = aBaseNodeParams.Coord( coord );
582 // look for columns around param
583 StdMeshers_IJNodeMap & ijNodes =
584 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
585 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
586 while ( par_nVec_1->first < param )
588 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
591 if ( par_nVec_1 != ijNodes.begin() ) {
593 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
595 aCol1 = & par_nVec_1->second;
596 aCol2 = & par_nVec_2->second;
600 // this variant is better for cases with curved edges and
601 // different nodes distribution on top and base edges
602 const SMDS_MeshNode* n1 = aCol1->back();
603 const SMDS_MeshNode* n2 = aCol2->back();
604 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
605 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
606 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
609 // this variant is better for other cases
610 // SMESH_MesherHelper helper( *GetMesh() );
611 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
612 // double u1 = helper.GetNodeU( edge, n1 );
613 // double u2 = helper.GetNodeU( edge, n2 );
614 // double u = ( 1. - r ) * u1 + r * u2;
615 // gp_XYZ topNodeParams;
616 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
617 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
619 // myShapeXYZ[ edgeVec[ TOP ]]);
623 myBlock.Block().EdgePoint( edgeVec[ BASE ],
625 myShapeXYZ[ edgeVec[ BASE ]]);
630 //=======================================================================
631 //function : MakeVolumeMesh
633 //=======================================================================
634 void StdMeshers_Penta_3D::MakeVolumeMesh()
636 int i, j, ij, ik, i1, i2, aSSID;
638 SMESH_Mesh* pMesh = GetMesh();
639 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
641 int shapeID = meshDS->ShapeToIndex( myShape );
643 // 1. Set Node In Volume
645 for (i=1; i<ik; ++i){
646 for (j=0; j<myJSize; ++j){
648 const StdMeshers_TNode& aTN = myTNodes[ij];
649 aSSID=aTN.ShapeSupportID();
650 if (aSSID==SMESH_Block::ID_NONE) {
651 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
652 meshDS->SetNodeInVolume(aNode, shapeID);
657 // 2. Make pentahedrons
659 vector<const SMDS_MeshNode*> aN;
661 SMDS_ElemIteratorPtr itf, aItNodes;
663 const TopoDS_Face& aFxy0=
664 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
665 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
666 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
668 itf = aSM0->GetElements();
670 const SMDS_MeshElement* pE0 = itf->next();
672 int nbFaceNodes = pE0->NbNodes();
673 if(myCreateQuadratic)
674 nbFaceNodes = nbFaceNodes/2;
675 if ( (int) aN.size() < nbFaceNodes * 2 )
676 aN.resize( nbFaceNodes * 2 );
678 for ( k=0; k<nbFaceNodes; ++k ) {
679 const SMDS_MeshNode* pNode = pE0->GetNode(k);
680 // if(myTool->IsMedium(pNode))
682 aID0 = pNode->GetID();
683 aJ[k] = GetIndexOnLayer(aID0);
684 if (!myErrorStatus->IsOK()) {
685 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh pb");
691 for (i=0; i<ik; ++i) {
694 for(j=0; j<nbFaceNodes; ++j) {
695 ij = i1*myJSize+aJ[j];
696 const StdMeshers_TNode& aTN1 = myTNodes[ij];
697 const SMDS_MeshNode* aN1 = aTN1.Node();
701 const StdMeshers_TNode& aTN2 = myTNodes[ij];
702 const SMDS_MeshNode* aN2 = aTN2.Node();
703 aN[j+nbFaceNodes] = aN2;
705 // check if volume orientation will be ok
707 SMDS_VolumeTool vTool;
708 switch ( nbFaceNodes ) {
710 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
711 aN[3], aN[4], aN[5]);
712 vTool.Set( &tmpVol );
716 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
717 aN[4], aN[5], aN[6], aN[7]);
718 vTool.Set( &tmpVol );
724 forward = vTool.IsForward();
727 SMDS_MeshVolume* aV = 0;
728 switch ( nbFaceNodes ) {
731 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
732 // aN[3], aN[4], aN[5]);
733 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
736 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
737 // aN[3], aN[5], aN[4]);
738 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
743 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
744 // aN[4], aN[5], aN[6], aN[7]);
745 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
746 aN[4], aN[5], aN[6], aN[7]);
749 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
750 // aN[4], aN[7], aN[6], aN[5]);
751 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
752 aN[4], aN[7], aN[6], aN[5]);
758 meshDS->SetMeshElementOnShape(aV, shapeID);
763 //=======================================================================
764 //function : MakeMeshOnFxy1
766 //=======================================================================
767 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
769 int aID0, aJ, aLevel, ij, aNbNodes, k;
771 SMDS_NodeIteratorPtr itn;
772 SMDS_ElemIteratorPtr itf, aItNodes;
773 SMDSAbs_ElementType aElementType;
775 const TopoDS_Face& aFxy0=
776 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
777 const TopoDS_Face& aFxy1=
778 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
780 SMESH_Mesh* pMesh = GetMesh();
781 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
783 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
784 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
785 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
787 // set nodes on aFxy1
789 itn = aSM0->GetNodes();
790 aNbNodes = aSM0->NbNodes();
791 //printf("** aNbNodes=%d\n", aNbNodes);
792 myTool->SetSubShape( aFxy1 ); // to set medium nodes to aFxy1
794 // set elements on aFxy1
795 vector<const SMDS_MeshNode*> aNodes1;
797 itf = aSM0->GetElements();
799 const SMDS_MeshElement* pE0 = itf->next();
800 aElementType = pE0->GetType();
801 if (!aElementType==SMDSAbs_Face) {
804 aNbNodes = pE0->NbNodes();
805 if(myCreateQuadratic)
806 aNbNodes = aNbNodes/2;
807 if ( (int) aNodes1.size() < aNbNodes )
808 aNodes1.resize( aNbNodes );
810 k = aNbNodes-1; // reverse a face
811 aItNodes = pE0->nodesIterator();
812 while (aItNodes->more()) {
813 const SMDS_MeshNode* pNode =
814 static_cast<const SMDS_MeshNode*> (aItNodes->next());
815 if(myTool->IsMedium(pNode))
817 aID0 = pNode->GetID();
818 aJ = GetIndexOnLayer(aID0);
819 if (!myErrorStatus->IsOK()) {
820 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() pb");
824 ij = aLevel*myJSize + aJ;
825 const StdMeshers_TNode& aTN1 = myTNodes[ij];
826 const SMDS_MeshNode* aN1 = aTN1.Node();
830 SMDS_MeshFace * face = 0;
831 switch ( aNbNodes ) {
833 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
836 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
841 meshDS->SetMeshElementOnShape(face, aFxy1);
843 myTool->SetSubShape( myShape );
845 // update compute state of top face submesh
846 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
848 // assure that mesh on the top face will be cleaned when it is cleaned
849 // on the bottom face
850 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
851 volSM->SetEventListener( new SMESH_subMeshEventListener(true, // deletable by SMESH_subMesh
852 "StdMeshers_Penta_3D"),
853 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
854 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
857 //=======================================================================
858 //function : ClearMeshOnFxy1
860 //=======================================================================
861 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
863 SMESH_subMesh* aSubMesh;
864 SMESH_Mesh* pMesh=GetMesh();
866 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
867 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
869 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
872 //=======================================================================
873 //function : GetIndexOnLayer
875 //=======================================================================
876 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
879 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
881 aMapIt=myConnectingMap.find(aID);
882 if (aMapIt==myConnectingMap.end()) {
883 myErrorStatus->myName = 200;
884 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
891 //=======================================================================
892 //function : MakeConnectingMap
894 //=======================================================================
895 void StdMeshers_Penta_3D::MakeConnectingMap()
899 for (j=0; j<myJSize; ++j) {
900 const StdMeshers_TNode& aBN=myTNodes[j];
901 aBNID=aBN.BaseNodeID();
902 myConnectingMap[aBNID]=j;
906 //=======================================================================
907 //function : CreateNode
909 //=======================================================================
910 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
911 const gp_XYZ& aParams,
912 StdMeshers_TNode& aTN)
918 SMDS_MeshNode* pNode=NULL;
921 // if (bIsUpperLayer) {
922 // // point on face Fxy1
923 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
924 // myBlock.Point(aParams, aS, aP);
927 // // point inside solid
928 // myBlock.Point(aParams, aP);
931 double u = aParams.X(), v = aParams.Y();
932 double u1 = ( 1. - u ), v1 = ( 1. - v );
933 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
934 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
935 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
936 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
938 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
939 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
940 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
941 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
944 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
947 // iErr=myBlock.ErrorStatus();
949 // myErrorStatus=12; // can not find the node point;
953 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
955 SMESH_Mesh* pMesh = GetMesh();
956 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
958 pNode = pMeshDS->AddNode(aX, aY, aZ);
963 //=======================================================================
964 //function : ShapeSupportID
966 //=======================================================================
967 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
968 const SMESH_Block::TShapeID aBNSSID,
969 SMESH_Block::TShapeID& aSSID)
972 case SMESH_Block::ID_V000:
973 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
975 case SMESH_Block::ID_V100:
976 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
978 case SMESH_Block::ID_V110:
979 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
981 case SMESH_Block::ID_V010:
982 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
984 case SMESH_Block::ID_Ex00:
985 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
987 case SMESH_Block::ID_Ex10:
988 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
990 case SMESH_Block::ID_E0y0:
991 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
993 case SMESH_Block::ID_E1y0:
994 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
996 case SMESH_Block::ID_Fxy0:
997 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1000 aSSID=SMESH_Block::ID_NONE;
1001 myErrorStatus->myName=10; // Can not find supporting shape ID
1002 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
1007 //=======================================================================
1008 //function : MakeBlock
1010 //=======================================================================
1011 void StdMeshers_Penta_3D::MakeBlock()
1014 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1016 TopoDS_Vertex aV000, aV001;
1018 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1019 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1020 TopTools_ListIteratorOfListOfShape aIt;
1022 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1024 // 0. Find triangulated face aFTr
1025 SMDSAbs_ElementType aElementType;
1026 SMESH_Mesh* pMesh=GetMesh();
1030 for (i=1; i<=iNbF; ++i) {
1031 const TopoDS_Shape& aF = aM(i);
1032 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1034 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1035 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1036 while(itf->more()) {
1037 const SMDS_MeshElement * pElement = itf->next();
1038 aElementType = pElement->GetType();
1039 if (aElementType==SMDSAbs_Face) {
1040 iNbNodes = pElement->NbNodes();
1041 if ( iNbNodes==3 || (pElement->IsQuadratic() && iNbNodes==6) ) {
1046 // The current algorithm fails if there is more that one
1047 // face which contains triangles ...
1048 // In that case, replace return by break to try another
1049 // method (coded in "if (iCnt != 1) { ... }")
1051 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1052 // myErrorStatus=5; // more than one face has triangulation
1064 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1065 // was not reached 'cause it was not called from Hexa_3D ... Now it
1066 // can occurs and in my opinion, it is the most common case.
1069 // The suggested algorithm is the following :
1071 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1072 // then the shape is tologically equivalent to a box
1073 // o In a box, there are three set of four // edges ...
1074 // In the cascade notation, it seems to be the edges
1079 // o For each one of this set, check if the four edges
1080 // have the same number of element.
1081 // o If so, check if the "corresponding" // faces contains
1082 // only quads. It's the faces numbered:
1086 // o If so, check if the opposite edges of each // faces
1087 // have the same number of elements. It is the edges
1089 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1090 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1091 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1092 // o If so, check if the two other faces have the same
1093 // number of elements. It is the faces numbered:
1097 // This test should be improved to test if the nodes
1098 // of the two faces are really "en face".
1099 // o If so, one of the two faces is a candidate to an extrusion,
1100 // It is the faces numbered :
1104 // o Finally, if there is only one candidate, let do the
1105 // extrusion job for the corresponding face
1109 int iNbF = aM.Extent();
1112 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1113 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1114 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1115 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1116 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1117 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1119 int has_only_quad_f1 = 1;
1120 int has_only_quad_f2 = 1;
1121 int has_only_quad_f3 = 1;
1122 int has_only_quad_f4 = 1;
1123 int has_only_quad_f5 = 1;
1124 int has_only_quad_f6 = 1;
1126 for (i=1; i<=iNbF; ++i) {
1128 const TopoDS_Shape& aF = aM(i);
1129 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1130 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1131 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1132 while(itf->more()) {
1133 const SMDS_MeshElement * pElement = itf->next();
1134 aElementType = pElement->GetType();
1135 if (aElementType==SMDSAbs_Face) {
1136 iNbNodes = pElement->NbNodes();
1137 if ( iNbNodes!=4 ) {
1143 if (i==1) has_only_quad_f1 = ok ;
1144 if (i==2) has_only_quad_f2 = ok ;
1145 if (i==3) has_only_quad_f3 = ok ;
1146 if (i==4) has_only_quad_f4 = ok ;
1147 if (i==5) has_only_quad_f5 = ok ;
1148 if (i==6) has_only_quad_f6 = ok ;
1151 TopTools_IndexedMapOfShape aE;
1152 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1153 int iNbE = aE.Extent();
1156 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1157 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1158 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1159 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1160 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1161 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1162 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1163 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1164 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1165 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1166 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1167 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1171 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1172 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1173 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1181 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1182 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1183 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1191 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1192 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1193 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1209 myErrorStatus->myName=5; // more than one face has triangulation
1210 myErrorStatus->myComment="Incorrect input mesh";
1216 // 1. Vetrices V00, V001;
1218 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1219 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1221 // 1.1 Base vertex V000
1222 iNbE = aME.Extent();
1223 if (iNbE!= NB_WALL_FACES ){
1224 MESSAGE("StdMeshers_Penta_3D::MakeBlock() err");
1225 myErrorStatus->myName=7; // too few edges are in base face aFTr
1226 myErrorStatus->myComment=SMESH_Comment("Not a quadrilateral face #")
1227 <<pMesh->GetMeshDS()->ShapeToIndex( aFTr )<<": "<<iNbE<<" edges" ;
1230 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1231 aV000=TopExp::FirstVertex(aE1);
1233 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1234 aIt.Initialize(aLE);
1235 for (; aIt.More(); aIt.Next()) {
1236 const TopoDS_Shape& aEx=aIt.Value();
1239 iNbEV=aMEV.Extent();
1241 MESSAGE("StdMeshers_Penta_3D::MakeBlock() err");
1242 myErrorStatus->myName=7; // too few edges meet in base vertex
1243 myErrorStatus->myComment=SMESH_Comment("3 edges must share vertex #")
1244 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 )<<" but there are "<<iNbEV<<" edges";
1250 for (j=1; j<=iNbEV; ++j) {
1251 const TopoDS_Shape& aEx=aMEV(j);
1252 if (!aME.Contains(aEx)) {
1253 TopoDS_Vertex aV[2];
1255 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1256 TopExp::Vertices(aE, aV[0], aV[1]);
1257 for (i=0; i<2; ++i) {
1258 if (!aV[i].IsSame(aV000)) {
1268 MESSAGE("StdMeshers_Penta_3D::MakeBlock() err");
1269 myErrorStatus->myName=8; // can not find reper V001
1270 myErrorStatus->myComment=SMESH_Comment("Can't find opposite vertex for vertex #")
1271 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 );
1275 //gp_Pnt aP000, aP001;
1277 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1278 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1279 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1280 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1284 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1287 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1288 myErrorStatus->myName=9; // number of shells in source shape !=1
1289 myErrorStatus->myComment=SMESH_Comment("Unexpected nb of shells ")<<iNbE;
1294 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1295 myBlock.Load(aShell, aV000, aV001);
1296 iErr = myBlock.ErrorStatus();
1298 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1299 myErrorStatus=myBlock.GetError(); // SMESHBlock: Load operation failed
1303 //=======================================================================
1304 //function : CheckData
1306 //=======================================================================
1307 void StdMeshers_Penta_3D::CheckData()
1310 int iNbEx[]={8, 12, 6};
1312 TopAbs_ShapeEnum aST;
1313 TopAbs_ShapeEnum aSTEx[]={
1314 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1316 TopTools_IndexedMapOfShape aM;
1318 if (myShape.IsNull()){
1319 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1320 myErrorStatus->myName=2; // null shape
1321 myErrorStatus->myComment="Null shape";
1325 aST=myShape.ShapeType();
1326 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1327 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1328 myErrorStatus->myName=3; // not compatible type of shape
1329 myErrorStatus->myComment=SMESH_Comment("Wrong shape type (TopAbs_ShapeEnum) ")<<aST;
1333 for (i=0; i<3; ++i) {
1335 TopExp::MapShapes(myShape, aSTEx[i], aM);
1338 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1339 myErrorStatus->myName=4; // number of sub-shape is not compatible
1340 myErrorStatus->myComment="Wrong number of sub-shapes of a block";
1346 //=======================================================================
1347 //function : LoadIJNodes
1348 //purpose : Load nodes bound to theFace into column (vectors) and rows
1350 // The value of theIJNodes map is a vector of ordered nodes so
1351 // that the 0-the one lies on theBaseEdge.
1352 // The key of theIJNodes map is a normalized parameter of each
1353 // 0-the node on theBaseEdge.
1354 //=======================================================================
1356 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1357 const TopoDS_Face& theFace,
1358 const TopoDS_Edge& theBaseEdge,
1359 SMESHDS_Mesh* theMesh)
1361 // get vertices of theBaseEdge
1362 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1363 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1364 TopExp::Vertices( eFrw, vfb, vlb );
1366 // find the other edges of theFace and orientation of e1
1367 TopoDS_Edge e1, e2, eTop;
1368 bool rev1 = false, CumOri = false;
1369 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1371 for ( ; exp.More(); exp.Next() ) {
1372 if ( ++nbEdges > NB_WALL_FACES ) {
1373 return false; // more than 4 edges in theFace
1375 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1376 if ( theBaseEdge.IsSame( e ))
1378 TopoDS_Vertex vCommon;
1379 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1381 else if ( vCommon.IsSame( vfb )) {
1383 vft = TopExp::LastVertex( e1, CumOri );
1384 rev1 = vfb.IsSame( vft );
1386 vft = TopExp::FirstVertex( e1, CumOri );
1391 if ( nbEdges < NB_WALL_FACES ) {
1392 return false; // less than 4 edges in theFace
1395 // submeshes corresponding to shapes
1396 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1397 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1398 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1399 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1400 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1401 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1402 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1403 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1404 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1405 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1406 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1409 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1410 MESSAGE(" Diff nb of nodes on opposite edges" );
1413 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1414 MESSAGE("Empty submesh of vertex");
1417 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1418 // check quadratic case
1419 if ( myCreateQuadratic ) {
1420 int n1 = sm1->NbNodes()/2;
1421 int n2 = smb->NbNodes()/2;
1422 int n3 = sm1->NbNodes() - n1;
1423 int n4 = smb->NbNodes() - n2;
1424 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1425 if( nf != smFace->NbNodes() ) {
1426 MESSAGE( "Wrong nb face nodes: " <<
1427 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1432 MESSAGE( "Wrong nb face nodes: " <<
1433 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1438 int vsize = sm1->NbNodes() + 2;
1439 int hsize = smb->NbNodes() + 2;
1440 if(myCreateQuadratic) {
1441 vsize = vsize - sm1->NbNodes()/2 -1;
1442 hsize = hsize - smb->NbNodes()/2 -1;
1445 // load nodes from theBaseEdge
1447 set<const SMDS_MeshNode*> loadedNodes;
1448 const SMDS_MeshNode* nullNode = 0;
1450 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1451 nVecf.resize( vsize, nullNode );
1452 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1454 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1455 nVecl.resize( vsize, nullNode );
1456 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1459 BRep_Tool::Range( eFrw, f, l );
1460 double range = l - f;
1461 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1462 const SMDS_MeshNode* node;
1463 while ( nIt->more() ) {
1465 if(myTool->IsMedium(node))
1467 SMDS_EdgePositionPtr pos = node->GetPosition();
1470 double u = ( pos->GetUParameter() - f ) / range;
1471 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1472 nVec.resize( vsize, nullNode );
1473 loadedNodes.insert( nVec[ 0 ] = node );
1475 if ( (int) theIJNodes.size() != hsize ) {
1476 MESSAGE( "Wrong node positions on theBaseEdge" );
1480 // load nodes from e1
1482 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1483 nIt = sm1->GetNodes();
1484 while ( nIt->more() ) {
1486 if(myTool->IsMedium(node))
1488 SMDS_EdgePositionPtr pos = node->GetPosition();
1491 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1493 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1494 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1495 int row = rev1 ? vsize - 1 : 0;
1496 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1499 loadedNodes.insert( nVecf[ row ] = u_n->second );
1502 // try to load the rest nodes
1504 // get all faces from theFace
1505 TIDSortedElemSet allFaces, foundFaces;
1506 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1507 while ( eIt->more() ) {
1508 const SMDS_MeshElement* e = eIt->next();
1509 if ( e->GetType() == SMDSAbs_Face )
1510 allFaces.insert( e );
1512 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1513 // the nodes belong to, and between the nodes of the found face,
1514 // look for a not loaded node considering this node to be the next
1515 // in a column of the starting second node. Repeat, starting
1516 // from nodes next to the previous starting nodes in their columns,
1517 // and so on while a face can be found. Then go the the next pair
1518 // of nodes on theBaseEdge.
1519 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1520 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1523 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1526 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1527 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1528 const SMDS_MeshElement* face = 0;
1530 // look for a face by 2 nodes
1531 face = SMESH_MeshAlgos::FindFaceInSet( n1, n2, allFaces, foundFaces );
1533 int nbFaceNodes = face->NbNodes();
1534 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1535 (myCreateQuadratic && nbFaceNodes>8) ) {
1536 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1539 // look for a not loaded node of the <face>
1541 const SMDS_MeshNode* n3 = 0; // a node different from n1 and n2
1542 eIt = face->nodesIterator() ;
1543 while ( !found && eIt->more() ) {
1544 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1545 if(myTool->IsMedium(node))
1547 found = loadedNodes.insert( node ).second;
1548 if ( !found && node != n1 && node != n2 )
1552 if ( ++row > vsize - 1 ) {
1553 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1556 par_nVec_2->second[ row ] = node;
1557 foundFaces.insert( face );
1559 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1560 n1 = par_nVec_1->second[ row ];
1563 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1564 n3 == par_nVec_1->second[ row ] ) {
1568 MESSAGE( "Not quad mesh, column "<< col );
1573 while ( face && n1 && n2 );
1575 if ( row < vsize - 1 ) {
1576 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1577 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1578 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1579 MESSAGE( "Current node 1: "<< n1);
1580 MESSAGE( "Current node 2: "<< n2);
1581 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1582 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1585 } // loop on columns
1590 //////////////////////////////////////////////////////////////////////////
1592 // StdMeshers_SMESHBlock
1594 //////////////////////////////////////////////////////////////////////////
1596 //=======================================================================
1597 //function : StdMeshers_SMESHBlock
1599 //=======================================================================
1600 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1603 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1606 //=======================================================================
1607 //function : IsForwardEdge
1609 //=======================================================================
1611 bool StdMeshers_SMESHBlock::IsForwardEdge(const int theEdgeID)
1613 int index = myTBlock.ShapeIndex( theEdgeID );
1614 if ( !myTBlock.IsEdgeID( theEdgeID ))
1617 if ( myIsEdgeForward[ index ] < 0 )
1618 myIsEdgeForward[ index ] =
1619 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1621 return myIsEdgeForward[ index ];
1624 //=======================================================================
1625 //function : ErrorStatus
1627 //=======================================================================
1628 int StdMeshers_SMESHBlock::ErrorStatus() const
1630 return myErrorStatus;
1633 //================================================================================
1635 * \brief Return problem description
1637 //================================================================================
1639 SMESH_ComputeErrorPtr StdMeshers_SMESHBlock::GetError() const
1641 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1642 string & text = err->myComment;
1643 switch ( myErrorStatus ) {
1645 case 3: text = "Internal error of StdMeshers_Penta_3D"; break;
1646 case 4: text = "Can't compute normalized parameters of a point inside a block"; break;
1647 case 5: text = "Can't compute coordinates by normalized parameters inside a block"; break;
1648 case 6: text = "Can't detect block sub-shapes. Not a block?"; break;
1651 err->myName = myErrorStatus;
1655 //=======================================================================
1658 //=======================================================================
1659 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1661 TopoDS_Vertex aV000, aV001;
1663 Load(theShell, aV000, aV001);
1666 //=======================================================================
1669 //=======================================================================
1670 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1671 const TopoDS_Vertex& theV000,
1672 const TopoDS_Vertex& theV001)
1680 myShapeIDMap.Clear();
1681 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1688 //=======================================================================
1689 //function : ComputeParameters
1691 //=======================================================================
1692 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1695 ComputeParameters(thePnt, myShell, theXYZ);
1698 //=======================================================================
1699 //function : ComputeParameters
1701 //=======================================================================
1702 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1703 const TopoDS_Shape& theShape,
1711 aID = ShapeID(theShape);
1712 if (myErrorStatus) {
1715 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1717 myErrorStatus=4; // problems with computation Parameters
1722 //=======================================================================
1723 //function : ComputeParameters
1725 //=======================================================================
1727 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1728 const TopoDS_Shape& theShape,
1736 aID = ShapeID(theShape);
1737 if (myErrorStatus) {
1740 if ( SMESH_Block::IsEdgeID( aID ))
1741 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1743 myErrorStatus=4; // problems with computation Parameters
1748 //=======================================================================
1751 //=======================================================================
1752 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams, gp_Pnt& aP3D)
1756 Point(theParams, aS, aP3D);
1759 //=======================================================================
1762 //=======================================================================
1763 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1764 const TopoDS_Shape& theShape,
1771 gp_XYZ aXYZ(99.,99.,99.);
1774 if (theShape.IsNull()) {
1775 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1779 aID=ShapeID(theShape);
1780 if (myErrorStatus) {
1784 if (SMESH_Block::IsVertexID(aID)) {
1785 bOk = myTBlock.VertexPoint(aID, aXYZ);
1787 else if (SMESH_Block::IsEdgeID(aID)) {
1788 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1791 else if (SMESH_Block::IsFaceID(aID)) {
1792 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1796 myErrorStatus=5; // problems with point computation
1802 //=======================================================================
1803 //function : ShapeID
1805 //=======================================================================
1806 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1811 TopoDS_Shape aSF, aSR;
1814 aSF.Orientation(TopAbs_FORWARD);
1816 aSR.Orientation(TopAbs_REVERSED);
1818 if (myShapeIDMap.Contains(aSF)) {
1819 aID=myShapeIDMap.FindIndex(aSF);
1822 if (myShapeIDMap.Contains(aSR)) {
1823 aID=myShapeIDMap.FindIndex(aSR);
1826 myErrorStatus=2; // unknown shape;
1830 //=======================================================================
1833 //=======================================================================
1834 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1840 aNb=myShapeIDMap.Extent();
1841 if (theID<1 || theID>aNb) {
1842 myErrorStatus=3; // ID is out of range
1843 return myEmptyShape;
1846 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);
1851 //=======================================================================
1852 //function : Evaluate
1854 //=======================================================================
1855 bool StdMeshers_Penta_3D::Evaluate(SMESH_Mesh& aMesh,
1856 const TopoDS_Shape& aShape,
1857 MapShapeNbElems& aResMap)
1859 // find face contains only triangles
1860 vector < SMESH_subMesh * >meshFaces;
1861 TopTools_SequenceOfShape aFaces;
1862 int NumBase = 0, i = 0;
1863 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
1865 aFaces.Append(exp.Current());
1866 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
1867 meshFaces.push_back(aSubMesh);
1868 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i]);
1869 if( anIt == aResMap.end() ) {
1873 std::vector<int> aVec = (*anIt).second;
1874 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1875 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1876 if( nbtri>0 && nbqua==0 ) {
1882 std::vector<int> aResVec(SMDSEntity_Last);
1883 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1884 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1885 aResMap.insert(std::make_pair(sm,aResVec));
1886 myErrorStatus->myName = COMPERR_ALGO_FAILED;
1887 myErrorStatus->myComment = "Submesh can not be evaluated";
1891 // find number of 1d elems for base face
1893 TopTools_MapOfShape Edges1;
1894 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1895 Edges1.Add(exp.Current());
1896 SMESH_subMesh *sm = aMesh.GetSubMesh(exp.Current());
1898 MapShapeNbElemsItr anIt = aResMap.find(sm);
1899 if( anIt == aResMap.end() ) continue;
1900 std::vector<int> aVec = (*anIt).second;
1901 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1904 // find face opposite to base face
1906 for(i=1; i<=6; i++) {
1907 if(i==NumBase) continue;
1908 bool IsOpposite = true;
1909 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1910 if( Edges1.Contains(exp.Current()) ) {
1920 // find number of 2d elems on side faces
1922 for(i=1; i<=6; i++) {
1923 if( i==OppNum || i==NumBase ) continue;
1924 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1925 if( anIt == aResMap.end() ) continue;
1926 std::vector<int> aVec = (*anIt).second;
1927 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1930 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1931 std::vector<int> aVec = (*anIt).second;
1932 int nb2d_face0 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1933 int nb0d_face0 = aVec[SMDSEntity_Node];
1935 anIt = aResMap.find( meshFaces[OppNum-1] );
1936 for(i=SMDSEntity_Node; i<SMDSEntity_Last; i++)
1937 (*anIt).second[i] = aVec[i];
1939 SMESH_MesherHelper aTool (aMesh);
1940 bool _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
1942 std::vector<int> aResVec(SMDSEntity_Last);
1943 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1944 if(_quadraticMesh) {
1945 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0 * ( nb2d/nb1d );
1946 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 );
1949 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1950 aResVec[SMDSEntity_Penta] = nb2d_face0 * ( nb2d/nb1d );
1952 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1953 aResMap.insert(std::make_pair(sm,aResVec));