1 // Copyright (C) 2007-2021 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, aSize, iErr;
151 smIdType iNbN, aNodeID;
153 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
154 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
155 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
156 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
157 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
161 SMESH_Mesh* pMesh=GetMesh();
163 // 1. Define the sizes of mesh
165 // 1.1 Horizontal size
167 for (i=0; i<aNbSIDs; ++i) {
168 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
169 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
171 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
172 if(!myCreateQuadratic) {
173 iNbN = aSM->NbNodes();
177 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
179 const SMDS_MeshNode* aNode = itn->next();
180 if(myTool->IsMedium(aNode))
187 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
192 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
193 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
195 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
196 if(!myCreateQuadratic) {
197 iNbN = aSM->NbNodes();
201 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
203 const SMDS_MeshNode* aNode = itn->next();
204 if(myTool->IsMedium(aNode))
211 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
213 aSize=myISize*myJSize;
214 myTNodes.resize(aSize);
216 StdMeshers_TNode aTNode;
220 // 2. Fill the repers on base face (Z=0)
223 for (k=0; k<aNbSIDs; ++k) {
225 const TopoDS_Shape& aS = myBlock.Shape(aSID);
226 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
228 const SMDS_MeshNode* aNode = ite->next();
229 if(myTool->IsMedium(aNode))
231 aNodeID=aNode->GetID();
233 aTNode.SetNode(aNode);
234 aTNode.SetShapeSupportID(aSID);
235 aTNode.SetBaseNodeID(aNodeID);
237 if ( SMESH_Block::IsEdgeID (aSID)) {
238 SMDS_EdgePositionPtr epos = aNode->GetPosition();
239 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
245 aP3D.SetCoord(aX, aY, aZ);
246 myBlock.ComputeParameters(aP3D, aS, aCoords);
248 iErr = myBlock.ErrorStatus();
250 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
251 "SMESHBlock: ComputeParameters operation failed");
252 myErrorStatus=myBlock.GetError();
255 aTNode.SetNormCoord(aCoords);
262 // 3.1 Fill maps of wall nodes
263 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
264 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
265 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
267 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
268 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
269 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
271 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
272 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
273 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
274 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
275 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
278 myErrorStatus->myName = COMPERR_BAD_INPUT_MESH;
279 myErrorStatus->myComment = SMESH_Comment() <<
280 "Can't find regular quadrangle mesh on a side face #" <<
281 pMesh->GetMeshDS()->ShapeToIndex( myBlock.Shape( wallFaceID[ i ]));
286 // 3.2 find node columns for vertical edges and edge IDs
287 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
288 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
289 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
291 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
292 ShapeSupportID(false, vID, eID);
293 verticEdgeID[ i ] = eID;
295 StdMeshers_TNode& aTNode = myTNodes[ i ];
296 verticEdgeNodes[ i ] = 0;
297 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
298 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
299 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
300 if ( ijNodes.begin()->second[0] == aTNode.Node() )
301 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
302 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
303 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
304 if ( verticEdgeNodes[ i ] )
309 // 3.3 set XYZ of vertices, and initialize of the rest
310 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
311 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
312 if ( SMESH_Block::IsVertexID( id )) {
313 TopoDS_Shape V = myBlock.Shape( id );
314 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
315 const SMDS_MeshNode* n = sm->GetNodes()->next();
316 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
319 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
323 // 4. Fill the rest repers
326 SMESH_Block::TShapeID aSSID, aBNSSID;
327 StdMeshers_TNode aTN;
330 // create top face and find UV for it's corners
331 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
332 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
333 int topfaceID = meshDS->ShapeToIndex(TopFace);
334 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
335 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
336 const SMDS_MeshNode* N = itn->next();
337 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
338 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
339 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
341 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
342 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
343 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
345 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
346 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
347 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
349 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
351 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
353 const StdMeshers_TNode& aBN = myTNodes[j];
354 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
355 iBNID = aBN.BaseNodeID();
356 const gp_XYZ& aBNXYZ = aBN.NormCoord();
357 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
359 // set XYZ on horizontal edges and get node columns of faces:
360 // 2 columns for each face, between which a base node is located
361 vector<const SMDS_MeshNode*>* nColumns[8];
362 double ratio[ NB_WALL_FACES ] = {0,0,0,0}; // base node position between columns [0.-1.]
364 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
365 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
366 nColumns[k*2], nColumns[k*2+1]);
370 // XYZ on the bottom and top faces
371 const SMDS_MeshNode* n = aBN.Node();
372 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
373 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
375 // first create or find a top node, then the rest ones in a column
376 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
378 bIsUpperLayer = (i==(myISize-1));
379 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
380 if ( createNode ) // a base node is inside a top face
382 // set XYZ on vertical edges and faces
383 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
384 // XYZ on a vertical edge
385 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
386 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
387 // XYZ on a face (part 1 from one column)
388 n = (*nColumns[k*2]) [ i ];
389 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
390 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
392 if( bIsUpperLayer ) {
393 tmp1 = myTool->GetNodeUV(TopFace,n);
394 tmp1 = ( 1. - ratio[ k ]) * tmp1;
396 // XYZ on a face (part 2 from other column)
397 n = (*nColumns[k*2+1]) [ i ];
398 xyz.SetCoord( n->X(), n->Y(), n->Z() );
399 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
400 if( bIsUpperLayer ) {
401 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
402 tmp1 += ratio[ k ] * tmp2;
414 // fill current node info
417 // -normalized coordinates
421 aZ=(double)i/(double)(myISize-1);
422 aCoords.SetCoord(aX, aY, aZ);
424 // supporting shape ID
425 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
426 if (!myErrorStatus->IsOK()) {
427 MESSAGE("StdMeshers_Penta_3D::MakeNodes() pb");
431 aTN.SetShapeSupportID(aSSID);
432 aTN.SetNormCoord(aCoords);
433 aTN.SetBaseNodeID(iBNID);
435 if (aSSID!=SMESH_Block::ID_NONE){
436 // try to find the node
437 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
438 FindNodeOnShape(aS, aCoords, i, aTN);
441 // create node and get its id
442 CreateNode (bIsUpperLayer, aCoords, aTN);
444 if ( bIsUpperLayer ) {
445 const SMDS_MeshNode* n = aTN.Node();
446 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
447 // set node on top face:
448 // find UV parameter for this node
450 // UV011+-----+----------+UV111
453 // UV_E0y1+ +node +UV_E1y1
457 // UV001+-----+----------+UV101
460 double u = aCoords.X(), v = aCoords.Y();
461 double u1 = ( 1. - u ), v1 = ( 1. - v );
462 aP.ChangeCoord() = UV_Ex01 * v1;
463 aP.ChangeCoord() += UV_Ex11 * v;
464 aP.ChangeCoord() += UV_E0y1 * u1;
465 aP.ChangeCoord() += UV_E1y1 * u;
466 aP.ChangeCoord() -= UV001 * u1 * v1;
467 aP.ChangeCoord() -= UV101 * u * v1;
468 aP.ChangeCoord() -= UV011 * u1 * v;
469 aP.ChangeCoord() -= UV111 * u * v;
470 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
473 if (!myErrorStatus->IsOK()) {
474 MESSAGE("StdMeshers_Penta_3D::MakeNodes() err");
484 //=======================================================================
485 //function : FindNodeOnShape
487 //=======================================================================
489 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
490 const gp_XYZ& aParams,
492 StdMeshers_TNode& aTN)
494 double aX, aY, aZ, aD, aTol2, minD;
497 SMESH_Mesh* pMesh = GetMesh();
498 aTol2 = myTol3D*myTol3D;
500 SMDS_MeshNode* pNode = NULL;
502 if ( aS.ShapeType() == TopAbs_FACE ||
503 aS.ShapeType() == TopAbs_EDGE ) {
504 // find a face ID to which aTN belongs to
506 if ( aS.ShapeType() == TopAbs_FACE )
507 faceID = myBlock.ShapeID( aS );
508 else { // edge maybe vertical or top horizontal
509 gp_XYZ aCoord = aParams;
510 if ( aCoord.Z() == 1. )
511 aCoord.SetZ( 0.5 ); // move from top down
513 aCoord.SetX( 0.5 ); // move along X
514 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
516 ASSERT( SMESH_Block::IsFaceID( faceID ));
517 int fIndex = SMESH_Block::ShapeIndex( faceID );
518 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
519 // look for a base node in ijNodes
520 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
521 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
522 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
523 if ( par_nVec->second[ 0 ] == baseNode ) {
524 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
530 myBlock.Point(aParams, aS, aP1);
532 SMDS_NodeIteratorPtr ite=
533 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
535 const SMDS_MeshNode* aNode = ite->next();
536 if(myTool->IsMedium(aNode))
541 aP2.SetCoord(aX, aY, aZ);
542 aD=(double)aP1.SquareDistance(aP2);
543 //printf("** D=%lf ", aD, aTol2);
545 pNode=(SMDS_MeshNode*)aNode;
555 //aTN.SetNode(pNode);
556 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
557 //myErrorStatus=11; // can not find the node;
561 //=======================================================================
562 //function : SetHorizEdgeXYZ
564 //=======================================================================
566 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
568 vector<const SMDS_MeshNode*>*& aCol1,
569 vector<const SMDS_MeshNode*>*& aCol2)
571 // find base and top edges of the face
572 enum { BASE = 0, TOP };
573 vector< int > edgeVec; // 0-base, 1-top
574 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
576 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
577 bool isForward = myBlock.IsForwardEdge( edgeVec[ BASE ] );
579 double param = aBaseNodeParams.Coord( coord );
583 // look for columns around param
584 StdMeshers_IJNodeMap & ijNodes =
585 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
586 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
587 while ( par_nVec_1->first < param )
589 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
592 if ( par_nVec_1 != ijNodes.begin() ) {
594 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
596 aCol1 = & par_nVec_1->second;
597 aCol2 = & par_nVec_2->second;
601 // this variant is better for cases with curved edges and
602 // different nodes distribution on top and base edges
603 const SMDS_MeshNode* n1 = aCol1->back();
604 const SMDS_MeshNode* n2 = aCol2->back();
605 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
606 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
607 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
610 // this variant is better for other cases
611 // SMESH_MesherHelper helper( *GetMesh() );
612 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
613 // double u1 = helper.GetNodeU( edge, n1 );
614 // double u2 = helper.GetNodeU( edge, n2 );
615 // double u = ( 1. - r ) * u1 + r * u2;
616 // gp_XYZ topNodeParams;
617 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
618 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
620 // myShapeXYZ[ edgeVec[ TOP ]]);
624 myBlock.Block().EdgePoint( edgeVec[ BASE ],
626 myShapeXYZ[ edgeVec[ BASE ]]);
631 //=======================================================================
632 //function : MakeVolumeMesh
634 //=======================================================================
635 void StdMeshers_Penta_3D::MakeVolumeMesh()
637 int i, j, ij, ik, i1, i2, aSSID;
639 SMESH_Mesh* pMesh = GetMesh();
640 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
642 int shapeID = meshDS->ShapeToIndex( myShape );
644 // 1. Set Node In Volume
646 for (i=1; i<ik; ++i){
647 for (j=0; j<myJSize; ++j){
649 const StdMeshers_TNode& aTN = myTNodes[ij];
650 aSSID=aTN.ShapeSupportID();
651 if (aSSID==SMESH_Block::ID_NONE) {
652 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
653 meshDS->SetNodeInVolume(aNode, shapeID);
658 // 2. Make pentahedrons
661 vector<const SMDS_MeshNode*> aN;
663 SMDS_ElemIteratorPtr itf, aItNodes;
665 const TopoDS_Face& aFxy0=
666 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
667 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
668 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
670 itf = aSM0->GetElements();
672 const SMDS_MeshElement* pE0 = itf->next();
674 int nbFaceNodes = pE0->NbNodes();
675 if(myCreateQuadratic)
676 nbFaceNodes = nbFaceNodes/2;
677 if ( (int) aN.size() < nbFaceNodes * 2 )
678 aN.resize( nbFaceNodes * 2 );
680 for ( k=0; k<nbFaceNodes; ++k ) {
681 const SMDS_MeshNode* pNode = pE0->GetNode(k);
682 // if(myTool->IsMedium(pNode))
684 aID0 = pNode->GetID();
685 aJ[k] = GetIndexOnLayer(aID0);
686 if (!myErrorStatus->IsOK()) {
687 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh pb");
693 for (i=0; i<ik; ++i) {
696 for(j=0; j<nbFaceNodes; ++j) {
697 ij = i1*myJSize+aJ[j];
698 const StdMeshers_TNode& aTN1 = myTNodes[ij];
699 const SMDS_MeshNode* aN1 = aTN1.Node();
703 const StdMeshers_TNode& aTN2 = myTNodes[ij];
704 const SMDS_MeshNode* aN2 = aTN2.Node();
705 aN[j+nbFaceNodes] = aN2;
707 // check if volume orientation will be ok
709 SMDS_VolumeTool vTool;
710 switch ( nbFaceNodes ) {
712 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
713 aN[3], aN[4], aN[5]);
714 vTool.Set( &tmpVol );
718 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
719 aN[4], aN[5], aN[6], aN[7]);
720 vTool.Set( &tmpVol );
726 forward = vTool.IsForward();
729 SMDS_MeshVolume* aV = 0;
730 switch ( nbFaceNodes ) {
733 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
734 // aN[3], aN[4], aN[5]);
735 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
738 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
739 // aN[3], aN[5], aN[4]);
740 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
745 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
746 // aN[4], aN[5], aN[6], aN[7]);
747 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
748 aN[4], aN[5], aN[6], aN[7]);
751 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
752 // aN[4], aN[7], aN[6], aN[5]);
753 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
754 aN[4], aN[7], aN[6], aN[5]);
760 meshDS->SetMeshElementOnShape(aV, shapeID);
765 //=======================================================================
766 //function : MakeMeshOnFxy1
768 //=======================================================================
769 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
771 int aJ, aLevel, ij, k;
772 smIdType aID0, aNbNodes;
774 SMDS_NodeIteratorPtr itn;
775 SMDS_ElemIteratorPtr itf, aItNodes;
776 SMDSAbs_ElementType aElementType;
778 const TopoDS_Face& aFxy0=
779 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
780 const TopoDS_Face& aFxy1=
781 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
783 SMESH_Mesh* pMesh = GetMesh();
784 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
786 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
787 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
788 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
790 // set nodes on aFxy1
792 itn = aSM0->GetNodes();
793 aNbNodes = aSM0->NbNodes();
794 //printf("** aNbNodes=%d\n", aNbNodes);
795 myTool->SetSubShape( aFxy1 ); // to set medium nodes to aFxy1
797 // set elements on aFxy1
798 vector<const SMDS_MeshNode*> aNodes1;
800 itf = aSM0->GetElements();
802 const SMDS_MeshElement* pE0 = itf->next();
803 aElementType = pE0->GetType();
804 if (aElementType!=SMDSAbs_Face) {
807 aNbNodes = pE0->NbNodes();
808 if(myCreateQuadratic)
809 aNbNodes = aNbNodes/2;
810 if ( (int) aNodes1.size() < aNbNodes )
811 aNodes1.resize( aNbNodes );
813 k = aNbNodes-1; // reverse a face
814 aItNodes = pE0->nodesIterator();
815 while (aItNodes->more()) {
816 const SMDS_MeshNode* pNode =
817 static_cast<const SMDS_MeshNode*> (aItNodes->next());
818 if(myTool->IsMedium(pNode))
820 aID0 = pNode->GetID();
821 aJ = GetIndexOnLayer(aID0);
822 if (!myErrorStatus->IsOK()) {
823 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() pb");
827 ij = aLevel*myJSize + aJ;
828 const StdMeshers_TNode& aTN1 = myTNodes[ij];
829 const SMDS_MeshNode* aN1 = aTN1.Node();
833 SMDS_MeshFace * face = 0;
834 switch ( aNbNodes ) {
836 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
839 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
844 meshDS->SetMeshElementOnShape(face, aFxy1);
846 myTool->SetSubShape( myShape );
848 // update compute state of top face submesh
849 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
851 // assure that mesh on the top face will be cleaned when it is cleaned
852 // on the bottom face
853 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
854 volSM->SetEventListener( new SMESH_subMeshEventListener(true, // deletable by SMESH_subMesh
855 "StdMeshers_Penta_3D"),
856 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
857 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
860 //=======================================================================
861 //function : ClearMeshOnFxy1
863 //=======================================================================
864 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
866 SMESH_subMesh* aSubMesh;
867 SMESH_Mesh* pMesh=GetMesh();
869 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
870 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
872 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
875 //=======================================================================
876 //function : GetIndexOnLayer
878 //=======================================================================
879 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
882 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
884 aMapIt=myConnectingMap.find(aID);
885 if (aMapIt==myConnectingMap.end()) {
886 myErrorStatus->myName = 200;
887 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
894 //=======================================================================
895 //function : MakeConnectingMap
897 //=======================================================================
898 void StdMeshers_Penta_3D::MakeConnectingMap()
902 for (j=0; j<myJSize; ++j) {
903 const StdMeshers_TNode& aBN=myTNodes[j];
904 aBNID=aBN.BaseNodeID();
905 myConnectingMap[aBNID]=j;
909 //=======================================================================
910 //function : CreateNode
912 //=======================================================================
913 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
914 const gp_XYZ& aParams,
915 StdMeshers_TNode& aTN)
921 SMDS_MeshNode* pNode=NULL;
924 // if (bIsUpperLayer) {
925 // // point on face Fxy1
926 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
927 // myBlock.Point(aParams, aS, aP);
930 // // point inside solid
931 // myBlock.Point(aParams, aP);
934 double u = aParams.X(), v = aParams.Y();
935 double u1 = ( 1. - u ), v1 = ( 1. - v );
936 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
937 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
938 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
939 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
941 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
942 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
943 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
944 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
947 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
950 // iErr=myBlock.ErrorStatus();
952 // myErrorStatus=12; // can not find the node point;
956 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
958 SMESH_Mesh* pMesh = GetMesh();
959 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
961 pNode = pMeshDS->AddNode(aX, aY, aZ);
966 //=======================================================================
967 //function : ShapeSupportID
969 //=======================================================================
970 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
971 const SMESH_Block::TShapeID aBNSSID,
972 SMESH_Block::TShapeID& aSSID)
975 case SMESH_Block::ID_V000:
976 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
978 case SMESH_Block::ID_V100:
979 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
981 case SMESH_Block::ID_V110:
982 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
984 case SMESH_Block::ID_V010:
985 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
987 case SMESH_Block::ID_Ex00:
988 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
990 case SMESH_Block::ID_Ex10:
991 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
993 case SMESH_Block::ID_E0y0:
994 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
996 case SMESH_Block::ID_E1y0:
997 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
999 case SMESH_Block::ID_Fxy0:
1000 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1003 aSSID=SMESH_Block::ID_NONE;
1004 myErrorStatus->myName=10; // Can not find supporting shape ID
1005 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
1010 //=======================================================================
1011 //function : MakeBlock
1013 //=======================================================================
1014 void StdMeshers_Penta_3D::MakeBlock()
1017 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1019 TopoDS_Vertex aV000, aV001;
1021 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1022 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1023 TopTools_ListIteratorOfListOfShape aIt;
1025 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1027 // 0. Find triangulated face aFTr
1028 SMDSAbs_ElementType aElementType;
1029 SMESH_Mesh* pMesh=GetMesh();
1033 for (i=1; i<=iNbF; ++i) {
1034 const TopoDS_Shape& aF = aM(i);
1035 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1037 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1038 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1039 while(itf->more()) {
1040 const SMDS_MeshElement * pElement = itf->next();
1041 aElementType = pElement->GetType();
1042 if (aElementType==SMDSAbs_Face) {
1043 iNbNodes = pElement->NbNodes();
1044 if ( iNbNodes==3 || (pElement->IsQuadratic() && iNbNodes==6) ) {
1049 // The current algorithm fails if there is more that one
1050 // face which contains triangles ...
1051 // In that case, replace return by break to try another
1052 // method (coded in "if (iCnt != 1) { ... }")
1054 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1055 // myErrorStatus=5; // more than one face has triangulation
1067 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1068 // was not reached 'cause it was not called from Hexa_3D ... Now it
1069 // can occurs and in my opinion, it is the most common case.
1072 // The suggested algorithm is the following :
1074 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1075 // then the shape is tologically equivalent to a box
1076 // o In a box, there are three set of four // edges ...
1077 // In the cascade notation, it seems to be the edges
1082 // o For each one of this set, check if the four edges
1083 // have the same number of element.
1084 // o If so, check if the "corresponding" // faces contains
1085 // only quads. It's the faces numbered:
1089 // o If so, check if the opposite edges of each // faces
1090 // have the same number of elements. It is the edges
1092 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1093 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1094 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1095 // o If so, check if the two other faces have the same
1096 // number of elements. It is the faces numbered:
1100 // This test should be improved to test if the nodes
1101 // of the two faces are really "en face".
1102 // o If so, one of the two faces is a candidate to an extrusion,
1103 // It is the faces numbered :
1107 // o Finally, if there is only one candidate, let do the
1108 // extrusion job for the corresponding face
1112 int iNbF = aM.Extent();
1115 smIdType nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1116 smIdType nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1117 smIdType nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1118 smIdType nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1119 smIdType nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1120 smIdType nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1122 int has_only_quad_f1 = 1;
1123 int has_only_quad_f2 = 1;
1124 int has_only_quad_f3 = 1;
1125 int has_only_quad_f4 = 1;
1126 int has_only_quad_f5 = 1;
1127 int has_only_quad_f6 = 1;
1129 for (i=1; i<=iNbF; ++i) {
1131 const TopoDS_Shape& aF = aM(i);
1132 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1133 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1134 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1135 while(itf->more()) {
1136 const SMDS_MeshElement * pElement = itf->next();
1137 aElementType = pElement->GetType();
1138 if (aElementType==SMDSAbs_Face) {
1139 iNbNodes = pElement->NbNodes();
1140 if ( iNbNodes!=4 ) {
1146 if (i==1) has_only_quad_f1 = ok ;
1147 if (i==2) has_only_quad_f2 = ok ;
1148 if (i==3) has_only_quad_f3 = ok ;
1149 if (i==4) has_only_quad_f4 = ok ;
1150 if (i==5) has_only_quad_f5 = ok ;
1151 if (i==6) has_only_quad_f6 = ok ;
1154 TopTools_IndexedMapOfShape aE;
1155 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1156 int iNbE = aE.Extent();
1159 smIdType nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1160 smIdType nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1161 smIdType nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1162 smIdType nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1163 smIdType nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1164 smIdType nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1165 smIdType nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1166 smIdType nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1167 smIdType nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1168 smIdType nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1169 smIdType nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1170 smIdType nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1174 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1175 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1176 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1184 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1185 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1186 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1194 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1195 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1196 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1212 myErrorStatus->myName=5; // more than one face has triangulation
1213 myErrorStatus->myComment="Incorrect input mesh";
1219 // 1. Vetrices V00, V001;
1221 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1222 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1224 // 1.1 Base vertex V000
1225 iNbE = aME.Extent();
1226 if (iNbE!= NB_WALL_FACES ){
1227 MESSAGE("StdMeshers_Penta_3D::MakeBlock() err");
1228 myErrorStatus->myName=7; // too few edges are in base face aFTr
1229 myErrorStatus->myComment=SMESH_Comment("Not a quadrilateral face #")
1230 <<pMesh->GetMeshDS()->ShapeToIndex( aFTr )<<": "<<iNbE<<" edges" ;
1233 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1234 aV000=TopExp::FirstVertex(aE1);
1236 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1237 aIt.Initialize(aLE);
1238 for (; aIt.More(); aIt.Next()) {
1239 const TopoDS_Shape& aEx=aIt.Value();
1242 iNbEV=aMEV.Extent();
1244 MESSAGE("StdMeshers_Penta_3D::MakeBlock() err");
1245 myErrorStatus->myName=7; // too few edges meet in base vertex
1246 myErrorStatus->myComment=SMESH_Comment("3 edges must share vertex #")
1247 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 )<<" but there are "<<iNbEV<<" edges";
1253 for (j=1; j<=iNbEV; ++j) {
1254 const TopoDS_Shape& aEx=aMEV(j);
1255 if (!aME.Contains(aEx)) {
1256 TopoDS_Vertex aV[2];
1258 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1259 TopExp::Vertices(aE, aV[0], aV[1]);
1260 for (i=0; i<2; ++i) {
1261 if (!aV[i].IsSame(aV000)) {
1271 MESSAGE("StdMeshers_Penta_3D::MakeBlock() err");
1272 myErrorStatus->myName=8; // can not find reper V001
1273 myErrorStatus->myComment=SMESH_Comment("Can't find opposite vertex for vertex #")
1274 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 );
1278 //gp_Pnt aP000, aP001;
1280 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1281 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1282 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1283 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1287 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1290 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1291 myErrorStatus->myName=9; // number of shells in source shape !=1
1292 myErrorStatus->myComment=SMESH_Comment("Unexpected nb of shells ")<<iNbE;
1297 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1298 myBlock.Load(aShell, aV000, aV001);
1299 iErr = myBlock.ErrorStatus();
1301 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1302 myErrorStatus=myBlock.GetError(); // SMESHBlock: Load operation failed
1306 //=======================================================================
1307 //function : CheckData
1309 //=======================================================================
1310 void StdMeshers_Penta_3D::CheckData()
1313 int iNbEx[]={8, 12, 6};
1315 TopAbs_ShapeEnum aST;
1316 TopAbs_ShapeEnum aSTEx[]={
1317 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1319 TopTools_IndexedMapOfShape aM;
1321 if (myShape.IsNull()){
1322 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1323 myErrorStatus->myName=2; // null shape
1324 myErrorStatus->myComment="Null shape";
1328 aST=myShape.ShapeType();
1329 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1330 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1331 myErrorStatus->myName=3; // not compatible type of shape
1332 myErrorStatus->myComment=SMESH_Comment("Wrong shape type (TopAbs_ShapeEnum) ")<<aST;
1336 for (i=0; i<3; ++i) {
1338 TopExp::MapShapes(myShape, aSTEx[i], aM);
1341 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1342 myErrorStatus->myName=4; // number of sub-shape is not compatible
1343 myErrorStatus->myComment="Wrong number of sub-shapes of a block";
1349 //=======================================================================
1350 //function : LoadIJNodes
1351 //purpose : Load nodes bound to theFace into column (vectors) and rows
1353 // The value of theIJNodes map is a vector of ordered nodes so
1354 // that the 0-the one lies on theBaseEdge.
1355 // The key of theIJNodes map is a normalized parameter of each
1356 // 0-the node on theBaseEdge.
1357 //=======================================================================
1359 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1360 const TopoDS_Face& theFace,
1361 const TopoDS_Edge& theBaseEdge,
1362 SMESHDS_Mesh* theMesh)
1364 // get vertices of theBaseEdge
1365 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1366 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1367 TopExp::Vertices( eFrw, vfb, vlb );
1369 // find the other edges of theFace and orientation of e1
1370 TopoDS_Edge e1, e2, eTop;
1371 bool rev1 = false, CumOri = false;
1372 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1374 for ( ; exp.More(); exp.Next() ) {
1375 if ( ++nbEdges > NB_WALL_FACES ) {
1376 return false; // more than 4 edges in theFace
1378 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1379 if ( theBaseEdge.IsSame( e ))
1381 TopoDS_Vertex vCommon;
1382 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1384 else if ( vCommon.IsSame( vfb )) {
1386 vft = TopExp::LastVertex( e1, CumOri );
1387 rev1 = vfb.IsSame( vft );
1389 vft = TopExp::FirstVertex( e1, CumOri );
1394 if ( nbEdges < NB_WALL_FACES ) {
1395 return false; // less than 4 edges in theFace
1398 // submeshes corresponding to shapes
1399 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1400 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1401 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1402 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1403 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1404 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1405 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1406 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1407 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1408 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1409 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1412 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1413 MESSAGE(" Diff nb of nodes on opposite edges" );
1416 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1417 MESSAGE("Empty submesh of vertex");
1420 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1421 // check quadratic case
1422 if ( myCreateQuadratic ) {
1423 smIdType n1 = sm1->NbNodes()/2;
1424 smIdType n2 = smb->NbNodes()/2;
1425 smIdType n3 = sm1->NbNodes() - n1;
1426 smIdType n4 = smb->NbNodes() - n2;
1427 smIdType nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1428 if( nf != smFace->NbNodes() ) {
1429 MESSAGE( "Wrong nb face nodes: " <<
1430 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1435 MESSAGE( "Wrong nb face nodes: " <<
1436 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1441 smIdType vsize = sm1->NbNodes() + 2;
1442 smIdType hsize = smb->NbNodes() + 2;
1443 if(myCreateQuadratic) {
1444 vsize = vsize - sm1->NbNodes()/2 -1;
1445 hsize = hsize - smb->NbNodes()/2 -1;
1448 // load nodes from theBaseEdge
1450 set<const SMDS_MeshNode*> loadedNodes;
1451 const SMDS_MeshNode* nullNode = 0;
1453 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1454 nVecf.resize( vsize, nullNode );
1455 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1457 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1458 nVecl.resize( vsize, nullNode );
1459 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1462 BRep_Tool::Range( eFrw, f, l );
1463 double range = l - f;
1464 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1465 const SMDS_MeshNode* node;
1466 while ( nIt->more() ) {
1468 if(myTool->IsMedium(node))
1470 SMDS_EdgePositionPtr pos = node->GetPosition();
1473 double u = ( pos->GetUParameter() - f ) / range;
1474 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1475 nVec.resize( vsize, nullNode );
1476 loadedNodes.insert( nVec[ 0 ] = node );
1478 if ( (int) theIJNodes.size() != hsize ) {
1479 MESSAGE( "Wrong node positions on theBaseEdge" );
1483 // load nodes from e1
1485 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1486 nIt = sm1->GetNodes();
1487 while ( nIt->more() ) {
1489 if(myTool->IsMedium(node))
1491 SMDS_EdgePositionPtr pos = node->GetPosition();
1494 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1496 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1497 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1498 int row = rev1 ? vsize - 1 : 0;
1499 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1502 loadedNodes.insert( nVecf[ row ] = u_n->second );
1505 // try to load the rest nodes
1507 // get all faces from theFace
1508 TIDSortedElemSet allFaces, foundFaces;
1509 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1510 while ( eIt->more() ) {
1511 const SMDS_MeshElement* e = eIt->next();
1512 if ( e->GetType() == SMDSAbs_Face )
1513 allFaces.insert( e );
1515 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1516 // the nodes belong to, and between the nodes of the found face,
1517 // look for a not loaded node considering this node to be the next
1518 // in a column of the starting second node. Repeat, starting
1519 // from nodes next to the previous starting nodes in their columns,
1520 // and so on while a face can be found. Then go the the next pair
1521 // of nodes on theBaseEdge.
1522 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1523 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1526 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1529 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1530 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1531 const SMDS_MeshElement* face = 0;
1533 // look for a face by 2 nodes
1534 face = SMESH_MeshAlgos::FindFaceInSet( n1, n2, allFaces, foundFaces );
1536 int nbFaceNodes = face->NbNodes();
1537 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1538 (myCreateQuadratic && nbFaceNodes>8) ) {
1539 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1542 // look for a not loaded node of the <face>
1544 const SMDS_MeshNode* n3 = 0; // a node different from n1 and n2
1545 eIt = face->nodesIterator() ;
1546 while ( !found && eIt->more() ) {
1547 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1548 if(myTool->IsMedium(node))
1550 found = loadedNodes.insert( node ).second;
1551 if ( !found && node != n1 && node != n2 )
1555 if ( ++row > vsize - 1 ) {
1556 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1559 par_nVec_2->second[ row ] = node;
1560 foundFaces.insert( face );
1562 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1563 n1 = par_nVec_1->second[ row ];
1566 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1567 n3 == par_nVec_1->second[ row ] ) {
1571 MESSAGE( "Not quad mesh, column "<< col );
1576 while ( face && n1 && n2 );
1578 if ( row < vsize - 1 ) {
1579 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1580 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1581 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1582 MESSAGE( "Current node 1: "<< n1);
1583 MESSAGE( "Current node 2: "<< n2);
1584 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1585 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1588 } // loop on columns
1593 //////////////////////////////////////////////////////////////////////////
1595 // StdMeshers_SMESHBlock
1597 //////////////////////////////////////////////////////////////////////////
1599 //=======================================================================
1600 //function : StdMeshers_SMESHBlock
1602 //=======================================================================
1603 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1606 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1609 //=======================================================================
1610 //function : IsForwardEdge
1612 //=======================================================================
1614 bool StdMeshers_SMESHBlock::IsForwardEdge(const int theEdgeID)
1616 int index = myTBlock.ShapeIndex( theEdgeID );
1617 if ( !myTBlock.IsEdgeID( theEdgeID ))
1620 if ( myIsEdgeForward[ index ] < 0 )
1621 myIsEdgeForward[ index ] =
1622 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1624 return myIsEdgeForward[ index ];
1627 //=======================================================================
1628 //function : ErrorStatus
1630 //=======================================================================
1631 int StdMeshers_SMESHBlock::ErrorStatus() const
1633 return myErrorStatus;
1636 //================================================================================
1638 * \brief Return problem description
1640 //================================================================================
1642 SMESH_ComputeErrorPtr StdMeshers_SMESHBlock::GetError() const
1644 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1645 string & text = err->myComment;
1646 switch ( myErrorStatus ) {
1648 case 3: text = "Internal error of StdMeshers_Penta_3D"; break;
1649 case 4: text = "Can't compute normalized parameters of a point inside a block"; break;
1650 case 5: text = "Can't compute coordinates by normalized parameters inside a block"; break;
1651 case 6: text = "Can't detect block sub-shapes. Not a block?"; break;
1654 err->myName = myErrorStatus;
1658 //=======================================================================
1661 //=======================================================================
1662 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1664 TopoDS_Vertex aV000, aV001;
1666 Load(theShell, aV000, aV001);
1669 //=======================================================================
1672 //=======================================================================
1673 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1674 const TopoDS_Vertex& theV000,
1675 const TopoDS_Vertex& theV001)
1683 myShapeIDMap.Clear();
1684 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1691 //=======================================================================
1692 //function : ComputeParameters
1694 //=======================================================================
1695 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1698 ComputeParameters(thePnt, myShell, theXYZ);
1701 //=======================================================================
1702 //function : ComputeParameters
1704 //=======================================================================
1705 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1706 const TopoDS_Shape& theShape,
1714 aID = ShapeID(theShape);
1715 if (myErrorStatus) {
1718 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1720 myErrorStatus=4; // problems with computation Parameters
1725 //=======================================================================
1726 //function : ComputeParameters
1728 //=======================================================================
1730 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1731 const TopoDS_Shape& theShape,
1739 aID = ShapeID(theShape);
1740 if (myErrorStatus) {
1743 if ( SMESH_Block::IsEdgeID( aID ))
1744 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1746 myErrorStatus=4; // problems with computation Parameters
1751 //=======================================================================
1754 //=======================================================================
1755 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams, gp_Pnt& aP3D)
1759 Point(theParams, aS, aP3D);
1762 //=======================================================================
1765 //=======================================================================
1766 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1767 const TopoDS_Shape& theShape,
1774 gp_XYZ aXYZ(99.,99.,99.);
1777 if (theShape.IsNull()) {
1778 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1782 aID=ShapeID(theShape);
1783 if (myErrorStatus) {
1787 if (SMESH_Block::IsVertexID(aID)) {
1788 bOk = myTBlock.VertexPoint(aID, aXYZ);
1790 else if (SMESH_Block::IsEdgeID(aID)) {
1791 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1794 else if (SMESH_Block::IsFaceID(aID)) {
1795 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1799 myErrorStatus=5; // problems with point computation
1805 //=======================================================================
1806 //function : ShapeID
1808 //=======================================================================
1809 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1814 TopoDS_Shape aSF, aSR;
1817 aSF.Orientation(TopAbs_FORWARD);
1819 aSR.Orientation(TopAbs_REVERSED);
1821 if (myShapeIDMap.Contains(aSF)) {
1822 aID=myShapeIDMap.FindIndex(aSF);
1825 if (myShapeIDMap.Contains(aSR)) {
1826 aID=myShapeIDMap.FindIndex(aSR);
1829 myErrorStatus=2; // unknown shape;
1833 //=======================================================================
1836 //=======================================================================
1837 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1843 aNb=myShapeIDMap.Extent();
1844 if (theID<1 || theID>aNb) {
1845 myErrorStatus=3; // ID is out of range
1846 return myEmptyShape;
1849 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);
1854 //=======================================================================
1855 //function : Evaluate
1857 //=======================================================================
1858 bool StdMeshers_Penta_3D::Evaluate(SMESH_Mesh& aMesh,
1859 const TopoDS_Shape& aShape,
1860 MapShapeNbElems& aResMap)
1862 // find face contains only triangles
1863 vector < SMESH_subMesh * >meshFaces;
1864 TopTools_SequenceOfShape aFaces;
1865 int NumBase = 0, i = 0;
1866 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
1868 aFaces.Append(exp.Current());
1869 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
1870 meshFaces.push_back(aSubMesh);
1871 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i]);
1872 if( anIt == aResMap.end() ) {
1876 std::vector<smIdType> aVec = (*anIt).second;
1877 smIdType nbtri = std::max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1878 smIdType nbqua = std::max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1879 if( nbtri>0 && nbqua==0 ) {
1885 std::vector<smIdType> aResVec(SMDSEntity_Last);
1886 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1887 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1888 aResMap.insert(std::make_pair(sm,aResVec));
1889 myErrorStatus->myName = COMPERR_ALGO_FAILED;
1890 myErrorStatus->myComment = "Submesh can not be evaluated";
1894 // find number of 1d elems for base face
1896 TopTools_MapOfShape Edges1;
1897 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1898 Edges1.Add(exp.Current());
1899 SMESH_subMesh *sm = aMesh.GetSubMesh(exp.Current());
1901 MapShapeNbElemsItr anIt = aResMap.find(sm);
1902 if( anIt == aResMap.end() ) continue;
1903 std::vector<smIdType> aVec = (*anIt).second;
1904 nb1d += std::max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1907 // find face opposite to base face
1909 for(i=1; i<=6; i++) {
1910 if(i==NumBase) continue;
1911 bool IsOpposite = true;
1912 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1913 if( Edges1.Contains(exp.Current()) ) {
1923 // find number of 2d elems on side faces
1925 for(i=1; i<=6; i++) {
1926 if( i==OppNum || i==NumBase ) continue;
1927 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1928 if( anIt == aResMap.end() ) continue;
1929 std::vector<smIdType> aVec = (*anIt).second;
1930 nb2d += std::max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1933 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1934 std::vector<smIdType> aVec = (*anIt).second;
1935 smIdType nb2d_face0 = std::max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1936 smIdType nb0d_face0 = aVec[SMDSEntity_Node];
1938 anIt = aResMap.find( meshFaces[OppNum-1] );
1939 for(i=SMDSEntity_Node; i<SMDSEntity_Last; i++)
1940 (*anIt).second[i] = aVec[i];
1942 SMESH_MesherHelper aTool (aMesh);
1943 bool _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
1945 std::vector<smIdType> aResVec(SMDSEntity_Last);
1946 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1947 if(_quadraticMesh) {
1948 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0 * ( nb2d/nb1d );
1949 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 );
1952 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1953 aResVec[SMDSEntity_Penta] = nb2d_face0 * ( nb2d/nb1d );
1955 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1956 aResMap.insert(std::make_pair(sm,aResVec));