1 // SMESH StdMeshers_Penta_3D implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : StdMeshers_Penta_3D.cxx
29 #include "StdMeshers_Penta_3D.hxx"
31 #include "utilities.h"
32 #include "Utils_ExceptHandlers.hxx"
34 #include "SMDS_EdgePosition.hxx"
35 #include "SMDS_MeshElement.hxx"
36 #include "SMDS_VolumeOfNodes.hxx"
37 #include "SMDS_VolumeTool.hxx"
38 #include "SMESHDS_SubMesh.hxx"
39 #include "SMESH_Mesh.hxx"
40 #include "SMESH_MeshEditor.hxx"
41 #include "SMESH_subMesh.hxx"
42 #include "SMESH_subMeshEventListener.hxx"
43 #include "SMESH_Comment.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>
53 #include <TopoDS_Edge.hxx>
54 #include <TopoDS_Shell.hxx>
55 #include <TopoDS_Vertex.hxx>
63 typedef map < int, int, less<int> >::iterator \
64 StdMeshers_IteratorOfDataMapOfIntegerInteger;
66 enum { NB_WALL_FACES = 4 };
68 //=======================================================================
69 //function : StdMeshers_Penta_3D
71 //=======================================================================
72 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
73 : myErrorStatus(SMESH_ComputeError::New())
76 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
77 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
81 //=======================================================================
82 //function : ~StdMeshers_Penta_3D
84 //=======================================================================
86 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
90 //=======================================================================
93 //=======================================================================
94 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
95 const TopoDS_Shape& aShape)
97 MESSAGE("StdMeshers_Penta_3D::Compute()");
105 if (!myErrorStatus->IsOK()) {
109 SMESH_MesherHelper helper(aMesh);
111 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
115 if (!myErrorStatus->IsOK()) {
120 if (!myErrorStatus->IsOK()) {
125 if (!myErrorStatus->IsOK()) {
132 if (!myErrorStatus->IsOK()) {
141 //=======================================================================
142 //function : MakeNodes
144 //=======================================================================
145 void StdMeshers_Penta_3D::MakeNodes()
148 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
150 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
151 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
152 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
153 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
154 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
158 SMESH_Mesh* pMesh=GetMesh();
160 // 1. Define the sizes of mesh
162 // 1.1 Horizontal size
164 for (i=0; i<aNbSIDs; ++i) {
165 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
166 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
168 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
169 if(!myCreateQuadratic) {
170 iNbN = aSM->NbNodes();
174 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
176 const SMDS_MeshNode* aNode = itn->next();
177 if(myTool->IsMedium(aNode))
184 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
189 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
190 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
192 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
193 if(!myCreateQuadratic) {
194 iNbN = aSM->NbNodes();
198 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
200 const SMDS_MeshNode* aNode = itn->next();
201 if(myTool->IsMedium(aNode))
208 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
210 aSize=myISize*myJSize;
211 myTNodes.resize(aSize);
213 StdMeshers_TNode aTNode;
217 // 2. Fill the repers on base face (Z=0)
220 for (k=0; k<aNbSIDs; ++k) {
222 const TopoDS_Shape& aS = myBlock.Shape(aSID);
223 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
225 const SMDS_MeshNode* aNode = ite->next();
226 if(myTool->IsMedium(aNode))
228 aNodeID=aNode->GetID();
230 aTNode.SetNode(aNode);
231 aTNode.SetShapeSupportID(aSID);
232 aTNode.SetBaseNodeID(aNodeID);
234 if ( SMESH_Block::IsEdgeID (aSID)) {
235 const SMDS_EdgePosition* epos =
236 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
237 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
243 aP3D.SetCoord(aX, aY, aZ);
244 myBlock.ComputeParameters(aP3D, aS, aCoords);
246 iErr = myBlock.ErrorStatus();
248 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
249 "SMESHBlock: ComputeParameters operation failed");
250 myErrorStatus=myBlock.GetError();
253 aTNode.SetNormCoord(aCoords);
260 // 3.1 Fill maps of wall nodes
261 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
262 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
263 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
265 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
266 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
267 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
269 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
270 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
271 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
272 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
273 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
276 myErrorStatus->myName = COMPERR_BAD_INPUT_MESH;
277 myErrorStatus->myComment = SMESH_Comment() <<
278 "Can't find regular quadrangle mesh on a side face #" <<
279 pMesh->GetMeshDS()->ShapeToIndex( myBlock.Shape( wallFaceID[ i ]));
284 // 3.2 find node columns for vertical edges and edge IDs
285 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
286 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
287 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
289 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
290 ShapeSupportID(false, vID, eID);
291 verticEdgeID[ i ] = eID;
293 StdMeshers_TNode& aTNode = myTNodes[ i ];
294 verticEdgeNodes[ i ] = 0;
295 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
296 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
297 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
298 if ( ijNodes.begin()->second[0] == aTNode.Node() )
299 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
300 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
301 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
302 if ( verticEdgeNodes[ i ] )
307 // 3.3 set XYZ of vertices, and initialize of the rest
308 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
309 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
310 if ( SMESH_Block::IsVertexID( id )) {
311 TopoDS_Shape V = myBlock.Shape( id );
312 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
313 const SMDS_MeshNode* n = sm->GetNodes()->next();
314 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
317 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
321 // 4. Fill the rest repers
324 SMESH_Block::TShapeID aSSID, aBNSSID;
325 StdMeshers_TNode aTN;
328 // create top face and find UV for it's corners
329 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
330 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
331 int topfaceID = meshDS->ShapeToIndex(TopFace);
332 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
333 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
334 const SMDS_MeshNode* N = itn->next();
335 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
336 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
337 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
339 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
340 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
341 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
343 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
344 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
345 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
347 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
349 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
351 const StdMeshers_TNode& aBN = myTNodes[j];
352 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
353 iBNID = aBN.BaseNodeID();
354 const gp_XYZ& aBNXYZ = aBN.NormCoord();
355 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
357 // set XYZ on horizontal edges and get node columns of faces:
358 // 2 columns for each face, between which a base node is located
359 vector<const SMDS_MeshNode*>* nColumns[8];
360 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
362 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
363 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
364 nColumns[k*2], nColumns[k*2+1]);
368 // XYZ on the bottom and top faces
369 const SMDS_MeshNode* n = aBN.Node();
370 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
371 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
373 // first create or find a top node, then the rest ones in a column
374 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
376 bIsUpperLayer = (i==(myISize-1));
377 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
378 if ( createNode ) // a base node is inside a top face
380 // set XYZ on vertical edges and faces
381 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
382 // XYZ on a vertical edge
383 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
384 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
385 // XYZ on a face (part 1 from one column)
386 n = (*nColumns[k*2]) [ i ];
387 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
388 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
390 if( bIsUpperLayer ) {
391 tmp1 = myTool->GetNodeUV(TopFace,n);
392 tmp1 = ( 1. - ratio[ k ]) * tmp1;
394 // XYZ on a face (part 2 from other column)
395 n = (*nColumns[k*2+1]) [ i ];
396 xyz.SetCoord( n->X(), n->Y(), n->Z() );
397 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
398 if( bIsUpperLayer ) {
399 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
400 tmp1 += ratio[ k ] * tmp2;
412 // fill current node info
415 // -normalized coordinates
419 aZ=(double)i/(double)(myISize-1);
420 aCoords.SetCoord(aX, aY, aZ);
422 // suporting shape ID
423 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
424 if (!myErrorStatus->IsOK()) {
425 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
429 aTN.SetShapeSupportID(aSSID);
430 aTN.SetNormCoord(aCoords);
431 aTN.SetBaseNodeID(iBNID);
433 if (aSSID!=SMESH_Block::ID_NONE){
434 // try to find the node
435 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
436 FindNodeOnShape(aS, aCoords, i, aTN);
439 // create node and get it id
440 CreateNode (bIsUpperLayer, aCoords, aTN);
442 if ( bIsUpperLayer ) {
443 const SMDS_MeshNode* n = aTN.Node();
444 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
445 // set node on top face:
446 // find UV parameter for this node
448 // UV011+-----+----------+UV111
451 // UV_E0y1+ +node +UV_E1y1
455 // UV001+-----+----------+UV101
458 double u = aCoords.X(), v = aCoords.Y();
459 double u1 = ( 1. - u ), v1 = ( 1. - v );
460 aP.ChangeCoord() = UV_Ex01 * v1;
461 aP.ChangeCoord() += UV_Ex11 * v;
462 aP.ChangeCoord() += UV_E0y1 * u1;
463 aP.ChangeCoord() += UV_E1y1 * u;
464 aP.ChangeCoord() -= UV001 * u1 * v1;
465 aP.ChangeCoord() -= UV101 * u * v1;
466 aP.ChangeCoord() -= UV011 * u1 * v;
467 aP.ChangeCoord() -= UV111 * u * v;
468 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
471 if (!myErrorStatus->IsOK()) {
472 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
482 int iSSID, iBNID, aID;
484 for (i=0; i<myISize; ++i) {
485 printf(" Layer# %d\n", i);
486 for (j=0; j<myJSize; ++j) {
488 const StdMeshers_TNode& aTN=myTNodes[ij];
489 //const StdMeshers_TNode& aTN=aTNodes[ij];
490 const gp_XYZ& aXYZ=aTN.NormCoord();
491 iSSID=aTN.ShapeSupportID();
492 iBNID=aTN.BaseNodeID();
494 const SMDS_MeshNode* aNode=aTN.Node();
499 printf("*** j:%d BNID#%d iSSID:%d ID:%d { %lf %lf %lf }, { %lf %lf %lf }\n",
500 j, iBNID, iSSID, aID, aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aX, aY, aZ);
509 //=======================================================================
510 //function : FindNodeOnShape
512 //=======================================================================
514 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
515 const gp_XYZ& aParams,
517 StdMeshers_TNode& aTN)
519 double aX, aY, aZ, aD, aTol2, minD;
522 SMESH_Mesh* pMesh = GetMesh();
523 aTol2 = myTol3D*myTol3D;
525 SMDS_MeshNode* pNode = NULL;
527 if ( aS.ShapeType() == TopAbs_FACE ||
528 aS.ShapeType() == TopAbs_EDGE ) {
529 // find a face ID to which aTN belongs to
531 if ( aS.ShapeType() == TopAbs_FACE )
532 faceID = myBlock.ShapeID( aS );
533 else { // edge maybe vertical or top horizontal
534 gp_XYZ aCoord = aParams;
535 if ( aCoord.Z() == 1. )
536 aCoord.SetZ( 0.5 ); // move from top down
538 aCoord.SetX( 0.5 ); // move along X
539 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
541 ASSERT( SMESH_Block::IsFaceID( faceID ));
542 int fIndex = SMESH_Block::ShapeIndex( faceID );
543 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
544 // look for a base node in ijNodes
545 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
546 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
547 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
548 if ( par_nVec->second[ 0 ] == baseNode ) {
549 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
555 myBlock.Point(aParams, aS, aP1);
557 SMDS_NodeIteratorPtr ite=
558 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
560 const SMDS_MeshNode* aNode = ite->next();
561 if(myTool->IsMedium(aNode))
566 aP2.SetCoord(aX, aY, aZ);
567 aD=(double)aP1.SquareDistance(aP2);
568 //printf("** D=%lf ", aD, aTol2);
570 pNode=(SMDS_MeshNode*)aNode;
580 //aTN.SetNode(pNode);
581 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
582 //myErrorStatus=11; // can not find the node;
586 //=======================================================================
587 //function : SetHorizEdgeXYZ
589 //=======================================================================
591 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
593 vector<const SMDS_MeshNode*>*& aCol1,
594 vector<const SMDS_MeshNode*>*& aCol2)
596 // find base and top edges of the face
597 enum { BASE = 0, TOP };
598 vector< int > edgeVec; // 0-base, 1-top
599 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
601 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
602 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
604 double param = aBaseNodeParams.Coord( coord );
608 // look for columns around param
609 StdMeshers_IJNodeMap & ijNodes =
610 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
611 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
612 while ( par_nVec_1->first < param )
614 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
617 if ( par_nVec_1 != ijNodes.begin() ) {
619 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
621 aCol1 = & par_nVec_1->second;
622 aCol2 = & par_nVec_2->second;
626 // this variant is better for cases with curved edges and
627 // different nodes distribution on top and base edges
628 const SMDS_MeshNode* n1 = aCol1->back();
629 const SMDS_MeshNode* n2 = aCol2->back();
630 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
631 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
632 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
635 // this variant is better for other cases
636 // SMESH_MesherHelper helper( *GetMesh() );
637 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
638 // double u1 = helper.GetNodeU( edge, n1 );
639 // double u2 = helper.GetNodeU( edge, n2 );
640 // double u = ( 1. - r ) * u1 + r * u2;
641 // gp_XYZ topNodeParams;
642 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
643 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
645 // myShapeXYZ[ edgeVec[ TOP ]]);
649 myBlock.Block().EdgePoint( edgeVec[ BASE ],
651 myShapeXYZ[ edgeVec[ BASE ]]);
656 //=======================================================================
657 //function : MakeVolumeMesh
659 //=======================================================================
660 void StdMeshers_Penta_3D::MakeVolumeMesh()
662 int i, j, ij, ik, i1, i2, aSSID;
664 SMESH_Mesh* pMesh = GetMesh();
665 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
667 int shapeID = meshDS->ShapeToIndex( myShape );
669 // 1. Set Node In Volume
671 for (i=1; i<ik; ++i){
672 for (j=0; j<myJSize; ++j){
674 const StdMeshers_TNode& aTN = myTNodes[ij];
675 aSSID=aTN.ShapeSupportID();
676 if (aSSID==SMESH_Block::ID_NONE) {
677 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
678 meshDS->SetNodeInVolume(aNode, shapeID);
683 // 2. Make pentahedrons
685 vector<const SMDS_MeshNode*> aN;
687 SMDS_ElemIteratorPtr itf, aItNodes;
689 const TopoDS_Face& aFxy0=
690 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
691 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
692 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
694 itf = aSM0->GetElements();
696 const SMDS_MeshElement* pE0 = itf->next();
698 int nbFaceNodes = pE0->NbNodes();
699 if(myCreateQuadratic)
700 nbFaceNodes = nbFaceNodes/2;
701 if ( aN.size() < nbFaceNodes * 2 )
702 aN.resize( nbFaceNodes * 2 );
705 aItNodes=pE0->nodesIterator();
706 while (aItNodes->more()) {
707 //const SMDS_MeshElement* pNode = aItNodes->next();
708 const SMDS_MeshNode* pNode =
709 static_cast<const SMDS_MeshNode*> (aItNodes->next());
710 if(myTool->IsMedium(pNode))
712 aID0 = pNode->GetID();
713 aJ[k] = GetIndexOnLayer(aID0);
714 if (!myErrorStatus->IsOK()) {
715 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
723 for (i=0; i<ik; ++i) {
726 for(j=0; j<nbFaceNodes; ++j) {
727 ij = i1*myJSize+aJ[j];
728 const StdMeshers_TNode& aTN1 = myTNodes[ij];
729 const SMDS_MeshNode* aN1 = aTN1.Node();
733 const StdMeshers_TNode& aTN2 = myTNodes[ij];
734 const SMDS_MeshNode* aN2 = aTN2.Node();
735 aN[j+nbFaceNodes] = aN2;
737 // check if volume orientation will be ok
739 SMDS_VolumeTool vTool;
740 switch ( nbFaceNodes ) {
742 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
743 aN[3], aN[4], aN[5]);
744 vTool.Set( &tmpVol );
748 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
749 aN[4], aN[5], aN[6], aN[7]);
750 vTool.Set( &tmpVol );
756 forward = vTool.IsForward();
759 SMDS_MeshVolume* aV = 0;
760 switch ( nbFaceNodes ) {
763 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
764 // aN[3], aN[4], aN[5]);
765 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
768 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
769 // aN[3], aN[5], aN[4]);
770 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
775 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
776 // aN[4], aN[5], aN[6], aN[7]);
777 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
778 aN[4], aN[5], aN[6], aN[7]);
781 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
782 // aN[4], aN[7], aN[6], aN[5]);
783 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
784 aN[4], aN[7], aN[6], aN[5]);
790 meshDS->SetMeshElementOnShape(aV, shapeID);
795 //=======================================================================
796 //function : MakeMeshOnFxy1
798 //=======================================================================
799 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
801 int aID0, aJ, aLevel, ij, aNbNodes, k;
803 SMDS_NodeIteratorPtr itn;
804 SMDS_ElemIteratorPtr itf, aItNodes;
805 SMDSAbs_ElementType aElementType;
807 const TopoDS_Face& aFxy0=
808 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
809 const TopoDS_Face& aFxy1=
810 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
811 SMESH_MesherHelper faceHelper( *GetMesh() );
812 faceHelper.IsQuadraticSubMesh(aFxy1);
814 SMESH_Mesh* pMesh = GetMesh();
815 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
817 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
818 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
819 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
821 // set nodes on aFxy1
823 itn = aSM0->GetNodes();
824 aNbNodes = aSM0->NbNodes();
825 //printf("** aNbNodes=%d\n", aNbNodes);
828 // set elements on aFxy1
829 vector<const SMDS_MeshNode*> aNodes1;
831 itf = aSM0->GetElements();
833 const SMDS_MeshElement* pE0 = itf->next();
834 aElementType = pE0->GetType();
835 if (!aElementType==SMDSAbs_Face) {
838 aNbNodes = pE0->NbNodes();
839 if(myCreateQuadratic)
840 aNbNodes = aNbNodes/2;
841 if ( aNodes1.size() < aNbNodes )
842 aNodes1.resize( aNbNodes );
844 k = aNbNodes-1; // reverse a face
845 aItNodes = pE0->nodesIterator();
846 while (aItNodes->more()) {
847 const SMDS_MeshNode* pNode =
848 static_cast<const SMDS_MeshNode*> (aItNodes->next());
849 if(myTool->IsMedium(pNode))
851 aID0 = pNode->GetID();
852 aJ = GetIndexOnLayer(aID0);
853 if (!myErrorStatus->IsOK()) {
854 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
858 ij = aLevel*myJSize + aJ;
859 const StdMeshers_TNode& aTN1 = myTNodes[ij];
860 const SMDS_MeshNode* aN1 = aTN1.Node();
864 SMDS_MeshFace * face = 0;
865 switch ( aNbNodes ) {
867 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
870 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
875 meshDS->SetMeshElementOnShape(face, aFxy1);
878 // update compute state of top face submesh
879 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
881 // assure that mesh on the top face will be cleaned when it is cleaned
882 // on the bottom face
883 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
884 volSM->SetEventListener( new SMESH_subMeshEventListener(true),
885 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
886 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
889 //=======================================================================
890 //function : ClearMeshOnFxy1
892 //=======================================================================
893 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
895 SMESH_subMesh* aSubMesh;
896 SMESH_Mesh* pMesh=GetMesh();
898 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
899 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
901 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
904 //=======================================================================
905 //function : GetIndexOnLayer
907 //=======================================================================
908 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
911 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
913 aMapIt=myConnectingMap.find(aID);
914 if (aMapIt==myConnectingMap.end()) {
915 myErrorStatus->myName = 200;
916 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
923 //=======================================================================
924 //function : MakeConnectingMap
926 //=======================================================================
927 void StdMeshers_Penta_3D::MakeConnectingMap()
931 for (j=0; j<myJSize; ++j) {
932 const StdMeshers_TNode& aBN=myTNodes[j];
933 aBNID=aBN.BaseNodeID();
934 myConnectingMap[aBNID]=j;
938 //=======================================================================
939 //function : CreateNode
941 //=======================================================================
942 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
943 const gp_XYZ& aParams,
944 StdMeshers_TNode& aTN)
950 SMDS_MeshNode* pNode=NULL;
953 // if (bIsUpperLayer) {
954 // // point on face Fxy1
955 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
956 // myBlock.Point(aParams, aS, aP);
959 // // point inside solid
960 // myBlock.Point(aParams, aP);
963 double u = aParams.X(), v = aParams.Y();
964 double u1 = ( 1. - u ), v1 = ( 1. - v );
965 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
966 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
967 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
968 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
970 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
971 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
972 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
973 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
976 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
979 // iErr=myBlock.ErrorStatus();
981 // myErrorStatus=12; // can not find the node point;
985 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
987 SMESH_Mesh* pMesh = GetMesh();
988 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
990 pNode = pMeshDS->AddNode(aX, aY, aZ);
995 //=======================================================================
996 //function : ShapeSupportID
998 //=======================================================================
999 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
1000 const SMESH_Block::TShapeID aBNSSID,
1001 SMESH_Block::TShapeID& aSSID)
1004 case SMESH_Block::ID_V000:
1005 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
1007 case SMESH_Block::ID_V100:
1008 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
1010 case SMESH_Block::ID_V110:
1011 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
1013 case SMESH_Block::ID_V010:
1014 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
1016 case SMESH_Block::ID_Ex00:
1017 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
1019 case SMESH_Block::ID_Ex10:
1020 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
1022 case SMESH_Block::ID_E0y0:
1023 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
1025 case SMESH_Block::ID_E1y0:
1026 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
1028 case SMESH_Block::ID_Fxy0:
1029 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1032 aSSID=SMESH_Block::ID_NONE;
1033 myErrorStatus->myName=10; // Can not find supporting shape ID
1034 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
1039 //=======================================================================
1040 //function : MakeBlock
1042 //=======================================================================
1043 void StdMeshers_Penta_3D::MakeBlock()
1046 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1048 TopoDS_Vertex aV000, aV001;
1050 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1051 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1052 TopTools_ListIteratorOfListOfShape aIt;
1054 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1056 // 0. Find triangulated face aFTr
1057 SMDSAbs_ElementType aElementType;
1058 SMESH_Mesh* pMesh=GetMesh();
1062 for (i=1; i<=iNbF; ++i) {
1063 const TopoDS_Shape& aF = aM(i);
1064 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1066 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1067 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1068 while(itf->more()) {
1069 const SMDS_MeshElement * pElement = itf->next();
1070 aElementType = pElement->GetType();
1071 if (aElementType==SMDSAbs_Face) {
1072 iNbNodes = pElement->NbNodes();
1073 if ( iNbNodes==3 || (myCreateQuadratic && iNbNodes==6) ) {
1078 // The current algorithm fails if there is more that one
1079 // face wich contains triangles ...
1080 // In that case, replace return by break to try another
1081 // method (coded in "if (iCnt != 1) { ... }")
1083 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1084 // myErrorStatus=5; // more than one face has triangulation
1096 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1097 // was not reached 'cause it was not called from Hexa_3D ... Now it
1098 // can occurs and in my opinion, it is the most common case.
1101 // The suggested algorithm is the following :
1103 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1104 // then the shape is tologically equivalent to a box
1105 // o In a box, there are three set of four // edges ...
1106 // In the cascade notation, it seems to be the edges
1111 // o For each one of this set, check if the four edges
1112 // have the same number of element.
1113 // o If so, check if the "corresponding" // faces contains
1114 // only quads. It's the faces numbered:
1118 // o If so, check if the opposite edges of each // faces
1119 // have the same number of elements. It is the edges
1121 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1122 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1123 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1124 // o If so, check if the two other faces have the same
1125 // number of elements. It is the faces numbered:
1129 // This test should be improved to test if the nodes
1130 // of the two faces are really "en face".
1131 // o If so, one of the two faces is a candidate to an extrusion,
1132 // It is the faces numbered :
1136 // o Finally, if there is only one candidate, let do the
1137 // extrusion job for the corresponding face
1141 int iNbF = aM.Extent();
1144 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1145 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1146 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1147 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1148 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1149 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1151 int has_only_quad_f1 = 1;
1152 int has_only_quad_f2 = 1;
1153 int has_only_quad_f3 = 1;
1154 int has_only_quad_f4 = 1;
1155 int has_only_quad_f5 = 1;
1156 int has_only_quad_f6 = 1;
1158 for (i=1; i<=iNbF; ++i) {
1160 const TopoDS_Shape& aF = aM(i);
1161 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1162 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1163 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1164 while(itf->more()) {
1165 const SMDS_MeshElement * pElement = itf->next();
1166 aElementType = pElement->GetType();
1167 if (aElementType==SMDSAbs_Face) {
1168 iNbNodes = pElement->NbNodes();
1169 if ( iNbNodes!=4 ) {
1175 if (i==1) has_only_quad_f1 = ok ;
1176 if (i==2) has_only_quad_f2 = ok ;
1177 if (i==3) has_only_quad_f3 = ok ;
1178 if (i==4) has_only_quad_f4 = ok ;
1179 if (i==5) has_only_quad_f5 = ok ;
1180 if (i==6) has_only_quad_f6 = ok ;
1183 TopTools_IndexedMapOfShape aE;
1184 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1185 int iNbE = aE.Extent();
1188 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1189 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1190 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1191 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1192 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1193 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1194 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1195 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1196 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1197 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1198 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1199 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1203 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1204 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1205 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1213 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1214 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1215 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1223 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1224 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1225 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1241 myErrorStatus->myName=5; // more than one face has triangulation
1242 myErrorStatus->myComment="Incorrect input mesh";
1248 // 1. Vetrices V00, V001;
1250 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1251 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1253 // 1.1 Base vertex V000
1254 iNbE = aME.Extent();
1255 if (iNbE!= NB_WALL_FACES ){
1256 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1257 myErrorStatus->myName=7; // too few edges are in base face aFTr
1258 myErrorStatus->myComment=SMESH_Comment("Not a quadrilateral face #")
1259 <<pMesh->GetMeshDS()->ShapeToIndex( aFTr )<<": "<<iNbE<<" edges" ;
1262 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1263 aV000=TopExp::FirstVertex(aE1);
1265 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1266 aIt.Initialize(aLE);
1267 for (; aIt.More(); aIt.Next()) {
1268 const TopoDS_Shape& aEx=aIt.Value();
1271 iNbEV=aMEV.Extent();
1273 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1274 myErrorStatus->myName=7; // too few edges meet in base vertex
1275 myErrorStatus->myComment=SMESH_Comment("3 edges must share vertex #")
1276 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 )<<" but there are "<<iNbEV<<" edges";
1282 for (j=1; j<=iNbEV; ++j) {
1283 const TopoDS_Shape& aEx=aMEV(j);
1284 if (!aME.Contains(aEx)) {
1285 TopoDS_Vertex aV[2];
1287 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1288 TopExp::Vertices(aE, aV[0], aV[1]);
1289 for (i=0; i<2; ++i) {
1290 if (!aV[i].IsSame(aV000)) {
1300 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1301 myErrorStatus->myName=8; // can not find reper V001
1302 myErrorStatus->myComment=SMESH_Comment("Can't find opposite vertex for vertex #")
1303 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 );
1307 //gp_Pnt aP000, aP001;
1309 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1310 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1311 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1312 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1316 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1319 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1320 myErrorStatus->myName=9; // number of shells in source shape !=1
1321 myErrorStatus->myComment=SMESH_Comment("Unexpected nb of shells ")<<iNbE;
1326 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1327 myBlock.Load(aShell, aV000, aV001);
1328 iErr = myBlock.ErrorStatus();
1330 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1331 myErrorStatus=myBlock.GetError(); // SMESHBlock: Load operation failed
1335 //=======================================================================
1336 //function : CheckData
1338 //=======================================================================
1339 void StdMeshers_Penta_3D::CheckData()
1342 int iNbEx[]={8, 12, 6};
1344 TopAbs_ShapeEnum aST;
1345 TopAbs_ShapeEnum aSTEx[]={
1346 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1348 TopTools_IndexedMapOfShape aM;
1350 if (myShape.IsNull()){
1351 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1352 myErrorStatus->myName=2; // null shape
1353 myErrorStatus->myComment="Null shape";
1357 aST=myShape.ShapeType();
1358 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1359 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1360 myErrorStatus->myName=3; // not compatible type of shape
1361 myErrorStatus->myComment=SMESH_Comment("Wrong shape type (TopAbs_ShapeEnum) ")<<aST;
1365 for (i=0; i<3; ++i) {
1367 TopExp::MapShapes(myShape, aSTEx[i], aM);
1370 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1371 myErrorStatus->myName=4; // number of subshape is not compatible
1372 myErrorStatus->myComment="Wrong number of subshapes of a block";
1378 //=======================================================================
1379 //function : LoadIJNodes
1380 //purpose : Load nodes bound to theFace into column (vectors) and rows
1382 // The value of theIJNodes map is a vector of ordered nodes so
1383 // that the 0-the one lies on theBaseEdge.
1384 // The key of theIJNodes map is a normalized parameter of each
1385 // 0-the node on theBaseEdge.
1386 //=======================================================================
1388 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1389 const TopoDS_Face& theFace,
1390 const TopoDS_Edge& theBaseEdge,
1391 SMESHDS_Mesh* theMesh)
1393 // get vertices of theBaseEdge
1394 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1395 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1396 TopExp::Vertices( eFrw, vfb, vlb );
1398 // find the other edges of theFace and orientation of e1
1399 TopoDS_Edge e1, e2, eTop;
1400 bool rev1, CumOri = false;
1401 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1403 for ( ; exp.More(); exp.Next() ) {
1404 if ( ++nbEdges > NB_WALL_FACES ) {
1405 return false; // more than 4 edges in theFace
1407 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1408 if ( theBaseEdge.IsSame( e ))
1410 TopoDS_Vertex vCommon;
1411 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1413 else if ( vCommon.IsSame( vfb )) {
1415 vft = TopExp::LastVertex( e1, CumOri );
1416 rev1 = vfb.IsSame( vft );
1418 vft = TopExp::FirstVertex( e1, CumOri );
1423 if ( nbEdges < NB_WALL_FACES ) {
1424 return false; // less than 4 edges in theFace
1427 // submeshes corresponding to shapes
1428 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1429 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1430 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1431 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1432 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1433 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1434 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1435 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1436 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1437 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1438 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1441 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1442 MESSAGE(" Diff nb of nodes on opposite edges" );
1445 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1446 MESSAGE("Empty submesh of vertex");
1449 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1450 // check quadratic case
1451 if ( myCreateQuadratic ) {
1452 int n1 = sm1->NbNodes()/2;
1453 int n2 = smb->NbNodes()/2;
1454 int n3 = sm1->NbNodes() - n1;
1455 int n4 = smb->NbNodes() - n2;
1456 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1457 if( nf != smFace->NbNodes() ) {
1458 MESSAGE( "Wrong nb face nodes: " <<
1459 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1464 MESSAGE( "Wrong nb face nodes: " <<
1465 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1470 int vsize = sm1->NbNodes() + 2;
1471 int hsize = smb->NbNodes() + 2;
1472 if(myCreateQuadratic) {
1473 vsize = vsize - sm1->NbNodes()/2 -1;
1474 hsize = hsize - smb->NbNodes()/2 -1;
1477 // load nodes from theBaseEdge
1479 set<const SMDS_MeshNode*> loadedNodes;
1480 const SMDS_MeshNode* nullNode = 0;
1482 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1483 nVecf.resize( vsize, nullNode );
1484 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1486 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1487 nVecl.resize( vsize, nullNode );
1488 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1491 BRep_Tool::Range( eFrw, f, l );
1492 double range = l - f;
1493 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1494 const SMDS_MeshNode* node;
1495 while ( nIt->more() ) {
1497 if(myTool->IsMedium(node))
1499 const SMDS_EdgePosition* pos =
1500 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1504 double u = ( pos->GetUParameter() - f ) / range;
1505 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1506 nVec.resize( vsize, nullNode );
1507 loadedNodes.insert( nVec[ 0 ] = node );
1509 if ( theIJNodes.size() != hsize ) {
1510 MESSAGE( "Wrong node positions on theBaseEdge" );
1514 // load nodes from e1
1516 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1517 nIt = sm1->GetNodes();
1518 while ( nIt->more() ) {
1520 if(myTool->IsMedium(node))
1522 const SMDS_EdgePosition* pos =
1523 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1527 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1529 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1530 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1531 int row = rev1 ? vsize - 1 : 0;
1532 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1535 loadedNodes.insert( nVecf[ row ] = u_n->second );
1538 // try to load the rest nodes
1540 // get all faces from theFace
1541 TIDSortedElemSet allFaces, foundFaces;
1542 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1543 while ( eIt->more() ) {
1544 const SMDS_MeshElement* e = eIt->next();
1545 if ( e->GetType() == SMDSAbs_Face )
1546 allFaces.insert( e );
1548 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1549 // the nodes belong to, and between the nodes of the found face,
1550 // look for a not loaded node considering this node to be the next
1551 // in a column of the starting second node. Repeat, starting
1552 // from nodes next to the previous starting nodes in their columns,
1553 // and so on while a face can be found. Then go the the next pair
1554 // of nodes on theBaseEdge.
1555 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1556 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1559 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1562 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1563 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1564 const SMDS_MeshElement* face = 0;
1566 // look for a face by 2 nodes
1567 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1569 int nbFaceNodes = face->NbNodes();
1570 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1571 (myCreateQuadratic && nbFaceNodes>8) ) {
1572 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1575 // look for a not loaded node of the <face>
1577 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1578 eIt = face->nodesIterator() ;
1579 while ( !found && eIt->more() ) {
1580 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1581 if(myTool->IsMedium(node))
1583 found = loadedNodes.insert( node ).second;
1584 if ( !found && node != n1 && node != n2 )
1588 if ( ++row > vsize - 1 ) {
1589 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1592 par_nVec_2->second[ row ] = node;
1593 foundFaces.insert( face );
1595 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1596 n1 = par_nVec_1->second[ row ];
1599 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1600 n3 == par_nVec_1->second[ row ] ) {
1604 MESSAGE( "Not quad mesh, column "<< col );
1609 while ( face && n1 && n2 );
1611 if ( row < vsize - 1 ) {
1612 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1613 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1614 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1615 MESSAGE( "Current node 1: "<< n1);
1616 MESSAGE( "Current node 2: "<< n2);
1617 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1618 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1621 } // loop on columns
1626 //////////////////////////////////////////////////////////////////////////
1628 // StdMeshers_SMESHBlock
1630 //////////////////////////////////////////////////////////////////////////
1632 //=======================================================================
1633 //function : StdMeshers_SMESHBlock
1635 //=======================================================================
1636 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1639 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1642 //=======================================================================
1643 //function : IsForwadEdge
1645 //=======================================================================
1647 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1649 int index = myTBlock.ShapeIndex( theEdgeID );
1650 if ( !myTBlock.IsEdgeID( theEdgeID ))
1653 if ( myIsEdgeForward[ index ] < 0 )
1654 myIsEdgeForward[ index ] =
1655 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1657 return myIsEdgeForward[ index ];
1660 //=======================================================================
1661 //function : ErrorStatus
1663 //=======================================================================
1664 int StdMeshers_SMESHBlock::ErrorStatus() const
1666 return myErrorStatus;
1669 //================================================================================
1671 * \brief Return problem description
1673 //================================================================================
1675 SMESH_ComputeErrorPtr StdMeshers_SMESHBlock::GetError() const
1677 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1678 string & text = err->myComment;
1679 switch ( myErrorStatus ) {
1681 case 3: text = "Internal error of StdMeshers_Penta_3D"; break;
1682 case 4: text = "Can't compute normalized parameters of a point inside a block"; break;
1683 case 5: text = "Can't compute coordinates by normalized parameters inside a block"; break;
1684 case 6: text = "Can't detect block subshapes. Not a block?"; break;
1687 err->myName = myErrorStatus;
1691 //=======================================================================
1694 //=======================================================================
1695 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1697 TopoDS_Vertex aV000, aV001;
1699 Load(theShell, aV000, aV001);
1702 //=======================================================================
1705 //=======================================================================
1706 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1707 const TopoDS_Vertex& theV000,
1708 const TopoDS_Vertex& theV001)
1716 myShapeIDMap.Clear();
1717 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1724 //=======================================================================
1725 //function : ComputeParameters
1727 //=======================================================================
1728 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1731 ComputeParameters(thePnt, myShell, theXYZ);
1734 //=======================================================================
1735 //function : ComputeParameters
1737 //=======================================================================
1738 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1739 const TopoDS_Shape& theShape,
1747 aID = ShapeID(theShape);
1748 if (myErrorStatus) {
1751 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1753 myErrorStatus=4; // problems with computation Parameters
1758 //=======================================================================
1759 //function : ComputeParameters
1761 //=======================================================================
1763 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1764 const TopoDS_Shape& theShape,
1772 aID = ShapeID(theShape);
1773 if (myErrorStatus) {
1776 if ( SMESH_Block::IsEdgeID( aID ))
1777 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1779 myErrorStatus=4; // problems with computation Parameters
1784 //=======================================================================
1787 //=======================================================================
1788 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1793 Point(theParams, aS, aP3D);
1796 //=======================================================================
1799 //=======================================================================
1800 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1801 const TopoDS_Shape& theShape,
1808 gp_XYZ aXYZ(99.,99.,99.);
1811 if (theShape.IsNull()) {
1812 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1816 aID=ShapeID(theShape);
1817 if (myErrorStatus) {
1821 if (SMESH_Block::IsVertexID(aID)) {
1822 bOk = myTBlock.VertexPoint(aID, aXYZ);
1824 else if (SMESH_Block::IsEdgeID(aID)) {
1825 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1828 else if (SMESH_Block::IsFaceID(aID)) {
1829 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1833 myErrorStatus=5; // problems with point computation
1839 //=======================================================================
1840 //function : ShapeID
1842 //=======================================================================
1843 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1848 TopoDS_Shape aSF, aSR;
1851 aSF.Orientation(TopAbs_FORWARD);
1853 aSR.Orientation(TopAbs_REVERSED);
1855 if (myShapeIDMap.Contains(aSF)) {
1856 aID=myShapeIDMap.FindIndex(aSF);
1859 if (myShapeIDMap.Contains(aSR)) {
1860 aID=myShapeIDMap.FindIndex(aSR);
1863 myErrorStatus=2; // unknown shape;
1867 //=======================================================================
1870 //=======================================================================
1871 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1877 aNb=myShapeIDMap.Extent();
1878 if (theID<1 || theID>aNb) {
1879 myErrorStatus=3; // ID is out of range
1880 return myEmptyShape;
1883 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);