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
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_SubMesh.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_MeshEditor.hxx"
39 #include "SMESH_subMesh.hxx"
40 #include "SMESH_subMeshEventListener.hxx"
41 #include "SMESH_Comment.hxx"
43 #include <BRep_Tool.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <TopTools_ListIteratorOfListOfShape.hxx>
49 #include <TopTools_ListOfShape.hxx>
51 #include <TopoDS_Edge.hxx>
52 #include <TopoDS_Shell.hxx>
53 #include <TopoDS_Vertex.hxx>
61 typedef map < int, int, less<int> >::iterator \
62 StdMeshers_IteratorOfDataMapOfIntegerInteger;
64 enum { NB_WALL_FACES = 4 };
66 //=======================================================================
67 //function : StdMeshers_Penta_3D
69 //=======================================================================
70 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
71 : myErrorStatus(SMESH_ComputeError::New())
74 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
75 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
79 //=======================================================================
80 //function : ~StdMeshers_Penta_3D
82 //=======================================================================
84 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
88 //=======================================================================
91 //=======================================================================
92 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
93 const TopoDS_Shape& aShape)
95 MESSAGE("StdMeshers_Penta_3D::Compute()");
103 if (!myErrorStatus->IsOK()) {
107 SMESH_MesherHelper helper(aMesh);
109 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
113 if (!myErrorStatus->IsOK()) {
118 if (!myErrorStatus->IsOK()) {
123 if (!myErrorStatus->IsOK()) {
130 if (!myErrorStatus->IsOK()) {
139 //=======================================================================
140 //function : MakeNodes
142 //=======================================================================
143 void StdMeshers_Penta_3D::MakeNodes()
146 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
148 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
149 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
150 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
151 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
152 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
156 SMESH_Mesh* pMesh=GetMesh();
158 // 1. Define the sizes of mesh
160 // 1.1 Horizontal size
162 for (i=0; i<aNbSIDs; ++i) {
163 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
164 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
166 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
167 if(!myCreateQuadratic) {
168 iNbN = aSM->NbNodes();
172 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
174 const SMDS_MeshNode* aNode = itn->next();
175 if(myTool->IsMedium(aNode))
182 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
187 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
188 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
190 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
191 if(!myCreateQuadratic) {
192 iNbN = aSM->NbNodes();
196 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
198 const SMDS_MeshNode* aNode = itn->next();
199 if(myTool->IsMedium(aNode))
206 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
208 aSize=myISize*myJSize;
209 myTNodes.resize(aSize);
211 StdMeshers_TNode aTNode;
215 // 2. Fill the repers on base face (Z=0)
218 for (k=0; k<aNbSIDs; ++k) {
220 const TopoDS_Shape& aS = myBlock.Shape(aSID);
221 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
223 const SMDS_MeshNode* aNode = ite->next();
224 if(myTool->IsMedium(aNode))
226 aNodeID=aNode->GetID();
228 aTNode.SetNode(aNode);
229 aTNode.SetShapeSupportID(aSID);
230 aTNode.SetBaseNodeID(aNodeID);
232 if ( SMESH_Block::IsEdgeID (aSID)) {
233 const SMDS_EdgePosition* epos =
234 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
235 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
241 aP3D.SetCoord(aX, aY, aZ);
242 myBlock.ComputeParameters(aP3D, aS, aCoords);
244 iErr = myBlock.ErrorStatus();
246 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
247 "SMESHBlock: ComputeParameters operation failed");
248 myErrorStatus=myBlock.GetError();
251 aTNode.SetNormCoord(aCoords);
258 // 3.1 Fill maps of wall nodes
259 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
260 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
261 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
263 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
264 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
265 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
267 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
268 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
269 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
270 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
271 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
274 myErrorStatus->myName = COMPERR_BAD_INPUT_MESH;
275 myErrorStatus->myComment = SMESH_Comment() <<
276 "Can't find regular quadrangle mesh on a side face #" <<
277 pMesh->GetMeshDS()->ShapeToIndex( myBlock.Shape( wallFaceID[ i ]));
282 // 3.2 find node columns for vertical edges and edge IDs
283 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
284 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
285 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
287 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
288 ShapeSupportID(false, vID, eID);
289 verticEdgeID[ i ] = eID;
291 StdMeshers_TNode& aTNode = myTNodes[ i ];
292 verticEdgeNodes[ i ] = 0;
293 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
294 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
295 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
296 if ( ijNodes.begin()->second[0] == aTNode.Node() )
297 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
298 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
299 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
300 if ( verticEdgeNodes[ i ] )
305 // 3.3 set XYZ of vertices, and initialize of the rest
306 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
307 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
308 if ( SMESH_Block::IsVertexID( id )) {
309 TopoDS_Shape V = myBlock.Shape( id );
310 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
311 const SMDS_MeshNode* n = sm->GetNodes()->next();
312 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
315 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
319 // 4. Fill the rest repers
322 SMESH_Block::TShapeID aSSID, aBNSSID;
323 StdMeshers_TNode aTN;
326 // create top face and find UV for it's corners
327 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
328 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
329 int topfaceID = meshDS->ShapeToIndex(TopFace);
330 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
331 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
332 const SMDS_MeshNode* N = itn->next();
333 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
334 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
335 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
337 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
338 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
339 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
341 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
342 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
343 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
345 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
347 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
349 const StdMeshers_TNode& aBN = myTNodes[j];
350 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
351 iBNID = aBN.BaseNodeID();
352 const gp_XYZ& aBNXYZ = aBN.NormCoord();
353 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
355 // set XYZ on horizontal edges and get node columns of faces:
356 // 2 columns for each face, between which a base node is located
357 vector<const SMDS_MeshNode*>* nColumns[8];
358 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
360 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
361 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
362 nColumns[k*2], nColumns[k*2+1]);
366 // XYZ on the bottom and top faces
367 const SMDS_MeshNode* n = aBN.Node();
368 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
369 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
371 // first create or find a top node, then the rest ones in a column
372 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
374 bIsUpperLayer = (i==(myISize-1));
375 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
376 if ( createNode ) // a base node is inside a top face
378 // set XYZ on vertical edges and faces
379 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
380 // XYZ on a vertical edge
381 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
382 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
383 // XYZ on a face (part 1 from one column)
384 n = (*nColumns[k*2]) [ i ];
385 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
386 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
388 if( bIsUpperLayer ) {
389 tmp1 = myTool->GetNodeUV(TopFace,n);
390 tmp1 = ( 1. - ratio[ k ]) * tmp1;
392 // XYZ on a face (part 2 from other column)
393 n = (*nColumns[k*2+1]) [ i ];
394 xyz.SetCoord( n->X(), n->Y(), n->Z() );
395 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
396 if( bIsUpperLayer ) {
397 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
398 tmp1 += ratio[ k ] * tmp2;
410 // fill current node info
413 // -normalized coordinates
417 aZ=(double)i/(double)(myISize-1);
418 aCoords.SetCoord(aX, aY, aZ);
420 // suporting shape ID
421 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
422 if (!myErrorStatus->IsOK()) {
423 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
427 aTN.SetShapeSupportID(aSSID);
428 aTN.SetNormCoord(aCoords);
429 aTN.SetBaseNodeID(iBNID);
431 if (aSSID!=SMESH_Block::ID_NONE){
432 // try to find the node
433 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
434 FindNodeOnShape(aS, aCoords, i, aTN);
437 // create node and get it id
438 CreateNode (bIsUpperLayer, aCoords, aTN);
440 if ( bIsUpperLayer ) {
441 const SMDS_MeshNode* n = aTN.Node();
442 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
443 // set node on top face:
444 // find UV parameter for this node
446 // UV011+-----+----------+UV111
449 // UV_E0y1+ +node +UV_E1y1
453 // UV001+-----+----------+UV101
456 double u = aCoords.X(), v = aCoords.Y();
457 double u1 = ( 1. - u ), v1 = ( 1. - v );
458 aP.ChangeCoord() = UV_Ex01 * v1;
459 aP.ChangeCoord() += UV_Ex11 * v;
460 aP.ChangeCoord() += UV_E0y1 * u1;
461 aP.ChangeCoord() += UV_E1y1 * u;
462 aP.ChangeCoord() -= UV001 * u1 * v1;
463 aP.ChangeCoord() -= UV101 * u * v1;
464 aP.ChangeCoord() -= UV011 * u1 * v;
465 aP.ChangeCoord() -= UV111 * u * v;
466 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
469 if (!myErrorStatus->IsOK()) {
470 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
480 int iSSID, iBNID, aID;
482 for (i=0; i<myISize; ++i) {
483 printf(" Layer# %d\n", i);
484 for (j=0; j<myJSize; ++j) {
486 const StdMeshers_TNode& aTN=myTNodes[ij];
487 //const StdMeshers_TNode& aTN=aTNodes[ij];
488 const gp_XYZ& aXYZ=aTN.NormCoord();
489 iSSID=aTN.ShapeSupportID();
490 iBNID=aTN.BaseNodeID();
492 const SMDS_MeshNode* aNode=aTN.Node();
497 printf("*** j:%d BNID#%d iSSID:%d ID:%d { %lf %lf %lf }, { %lf %lf %lf }\n",
498 j, iBNID, iSSID, aID, aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aX, aY, aZ);
507 //=======================================================================
508 //function : FindNodeOnShape
510 //=======================================================================
512 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
513 const gp_XYZ& aParams,
515 StdMeshers_TNode& aTN)
517 double aX, aY, aZ, aD, aTol2, minD;
520 SMESH_Mesh* pMesh = GetMesh();
521 aTol2 = myTol3D*myTol3D;
523 SMDS_MeshNode* pNode = NULL;
525 if ( aS.ShapeType() == TopAbs_FACE ||
526 aS.ShapeType() == TopAbs_EDGE ) {
527 // find a face ID to which aTN belongs to
529 if ( aS.ShapeType() == TopAbs_FACE )
530 faceID = myBlock.ShapeID( aS );
531 else { // edge maybe vertical or top horizontal
532 gp_XYZ aCoord = aParams;
533 if ( aCoord.Z() == 1. )
534 aCoord.SetZ( 0.5 ); // move from top down
536 aCoord.SetX( 0.5 ); // move along X
537 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
539 ASSERT( SMESH_Block::IsFaceID( faceID ));
540 int fIndex = SMESH_Block::ShapeIndex( faceID );
541 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
542 // look for a base node in ijNodes
543 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
544 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
545 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
546 if ( par_nVec->second[ 0 ] == baseNode ) {
547 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
553 myBlock.Point(aParams, aS, aP1);
555 SMDS_NodeIteratorPtr ite=
556 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
558 const SMDS_MeshNode* aNode = ite->next();
559 if(myTool->IsMedium(aNode))
564 aP2.SetCoord(aX, aY, aZ);
565 aD=(double)aP1.SquareDistance(aP2);
566 //printf("** D=%lf ", aD, aTol2);
568 pNode=(SMDS_MeshNode*)aNode;
578 //aTN.SetNode(pNode);
579 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
580 //myErrorStatus=11; // can not find the node;
584 //=======================================================================
585 //function : SetHorizEdgeXYZ
587 //=======================================================================
589 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
591 vector<const SMDS_MeshNode*>*& aCol1,
592 vector<const SMDS_MeshNode*>*& aCol2)
594 // find base and top edges of the face
595 enum { BASE = 0, TOP };
596 vector< int > edgeVec; // 0-base, 1-top
597 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
599 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
600 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
602 double param = aBaseNodeParams.Coord( coord );
606 // look for columns around param
607 StdMeshers_IJNodeMap & ijNodes =
608 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
609 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
610 while ( par_nVec_1->first < param )
612 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
615 if ( par_nVec_1 != ijNodes.begin() ) {
617 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
619 aCol1 = & par_nVec_1->second;
620 aCol2 = & par_nVec_2->second;
624 // this variant is better for cases with curved edges and
625 // different nodes distribution on top and base edges
626 const SMDS_MeshNode* n1 = aCol1->back();
627 const SMDS_MeshNode* n2 = aCol2->back();
628 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
629 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
630 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
633 // this variant is better for other cases
634 // SMESH_MesherHelper helper( *GetMesh() );
635 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
636 // double u1 = helper.GetNodeU( edge, n1 );
637 // double u2 = helper.GetNodeU( edge, n2 );
638 // double u = ( 1. - r ) * u1 + r * u2;
639 // gp_XYZ topNodeParams;
640 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
641 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
643 // myShapeXYZ[ edgeVec[ TOP ]]);
647 myBlock.Block().EdgePoint( edgeVec[ BASE ],
649 myShapeXYZ[ edgeVec[ BASE ]]);
654 //=======================================================================
655 //function : MakeVolumeMesh
657 //=======================================================================
658 void StdMeshers_Penta_3D::MakeVolumeMesh()
660 int i, j, ij, ik, i1, i2, aSSID;
662 SMESH_Mesh* pMesh = GetMesh();
663 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
665 int shapeID = meshDS->ShapeToIndex( myShape );
667 // 1. Set Node In Volume
669 for (i=1; i<ik; ++i){
670 for (j=0; j<myJSize; ++j){
672 const StdMeshers_TNode& aTN = myTNodes[ij];
673 aSSID=aTN.ShapeSupportID();
674 if (aSSID==SMESH_Block::ID_NONE) {
675 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
676 meshDS->SetNodeInVolume(aNode, shapeID);
681 // 2. Make pentahedrons
683 vector<const SMDS_MeshNode*> aN;
685 SMDS_ElemIteratorPtr itf, aItNodes;
687 const TopoDS_Face& aFxy0=
688 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
689 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
690 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
692 itf = aSM0->GetElements();
694 const SMDS_MeshElement* pE0 = itf->next();
696 int nbFaceNodes = pE0->NbNodes();
697 if(myCreateQuadratic)
698 nbFaceNodes = nbFaceNodes/2;
699 if ( aN.size() < nbFaceNodes * 2 )
700 aN.resize( nbFaceNodes * 2 );
703 aItNodes=pE0->nodesIterator();
704 while (aItNodes->more()) {
705 //const SMDS_MeshElement* pNode = aItNodes->next();
706 const SMDS_MeshNode* pNode =
707 static_cast<const SMDS_MeshNode*> (aItNodes->next());
708 if(myTool->IsMedium(pNode))
710 aID0 = pNode->GetID();
711 aJ[k] = GetIndexOnLayer(aID0);
712 if (!myErrorStatus->IsOK()) {
713 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
721 for (i=0; i<ik; ++i) {
724 for(j=0; j<nbFaceNodes; ++j) {
725 ij = i1*myJSize+aJ[j];
726 const StdMeshers_TNode& aTN1 = myTNodes[ij];
727 const SMDS_MeshNode* aN1 = aTN1.Node();
731 const StdMeshers_TNode& aTN2 = myTNodes[ij];
732 const SMDS_MeshNode* aN2 = aTN2.Node();
733 aN[j+nbFaceNodes] = aN2;
735 // check if volume orientation will be ok
737 SMDS_VolumeTool vTool;
738 switch ( nbFaceNodes ) {
740 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
741 aN[3], aN[4], aN[5]);
742 vTool.Set( &tmpVol );
746 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
747 aN[4], aN[5], aN[6], aN[7]);
748 vTool.Set( &tmpVol );
754 forward = vTool.IsForward();
757 SMDS_MeshVolume* aV = 0;
758 switch ( nbFaceNodes ) {
761 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
762 // aN[3], aN[4], aN[5]);
763 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
766 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
767 // aN[3], aN[5], aN[4]);
768 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
773 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
774 // aN[4], aN[5], aN[6], aN[7]);
775 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
776 aN[4], aN[5], aN[6], aN[7]);
779 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
780 // aN[4], aN[7], aN[6], aN[5]);
781 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
782 aN[4], aN[7], aN[6], aN[5]);
788 meshDS->SetMeshElementOnShape(aV, shapeID);
793 //=======================================================================
794 //function : MakeMeshOnFxy1
796 //=======================================================================
797 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
799 int aID0, aJ, aLevel, ij, aNbNodes, k;
801 SMDS_NodeIteratorPtr itn;
802 SMDS_ElemIteratorPtr itf, aItNodes;
803 SMDSAbs_ElementType aElementType;
805 const TopoDS_Face& aFxy0=
806 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
807 const TopoDS_Face& aFxy1=
808 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
809 SMESH_MesherHelper faceHelper( *GetMesh() );
810 faceHelper.IsQuadraticSubMesh(aFxy1);
812 SMESH_Mesh* pMesh = GetMesh();
813 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
815 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
816 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
817 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
819 // set nodes on aFxy1
821 itn = aSM0->GetNodes();
822 aNbNodes = aSM0->NbNodes();
823 //printf("** aNbNodes=%d\n", aNbNodes);
826 // set elements on aFxy1
827 vector<const SMDS_MeshNode*> aNodes1;
829 itf = aSM0->GetElements();
831 const SMDS_MeshElement* pE0 = itf->next();
832 aElementType = pE0->GetType();
833 if (!aElementType==SMDSAbs_Face) {
836 aNbNodes = pE0->NbNodes();
837 if(myCreateQuadratic)
838 aNbNodes = aNbNodes/2;
839 if ( aNodes1.size() < aNbNodes )
840 aNodes1.resize( aNbNodes );
842 k = aNbNodes-1; // reverse a face
843 aItNodes = pE0->nodesIterator();
844 while (aItNodes->more()) {
845 const SMDS_MeshNode* pNode =
846 static_cast<const SMDS_MeshNode*> (aItNodes->next());
847 if(myTool->IsMedium(pNode))
849 aID0 = pNode->GetID();
850 aJ = GetIndexOnLayer(aID0);
851 if (!myErrorStatus->IsOK()) {
852 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
856 ij = aLevel*myJSize + aJ;
857 const StdMeshers_TNode& aTN1 = myTNodes[ij];
858 const SMDS_MeshNode* aN1 = aTN1.Node();
862 SMDS_MeshFace * face = 0;
863 switch ( aNbNodes ) {
865 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
868 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
873 meshDS->SetMeshElementOnShape(face, aFxy1);
876 // update compute state of top face submesh
877 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
879 // assure that mesh on the top face will be cleaned when it is cleaned
880 // on the bottom face
881 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
882 volSM->SetEventListener( new SMESH_subMeshEventListener(true),
883 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
884 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
887 //=======================================================================
888 //function : ClearMeshOnFxy1
890 //=======================================================================
891 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
893 SMESH_subMesh* aSubMesh;
894 SMESH_Mesh* pMesh=GetMesh();
896 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
897 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
899 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
902 //=======================================================================
903 //function : GetIndexOnLayer
905 //=======================================================================
906 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
909 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
911 aMapIt=myConnectingMap.find(aID);
912 if (aMapIt==myConnectingMap.end()) {
913 myErrorStatus->myName = 200;
914 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
921 //=======================================================================
922 //function : MakeConnectingMap
924 //=======================================================================
925 void StdMeshers_Penta_3D::MakeConnectingMap()
929 for (j=0; j<myJSize; ++j) {
930 const StdMeshers_TNode& aBN=myTNodes[j];
931 aBNID=aBN.BaseNodeID();
932 myConnectingMap[aBNID]=j;
936 //=======================================================================
937 //function : CreateNode
939 //=======================================================================
940 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
941 const gp_XYZ& aParams,
942 StdMeshers_TNode& aTN)
948 SMDS_MeshNode* pNode=NULL;
951 // if (bIsUpperLayer) {
952 // // point on face Fxy1
953 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
954 // myBlock.Point(aParams, aS, aP);
957 // // point inside solid
958 // myBlock.Point(aParams, aP);
961 double u = aParams.X(), v = aParams.Y();
962 double u1 = ( 1. - u ), v1 = ( 1. - v );
963 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
964 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
965 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
966 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
968 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
969 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
970 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
971 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
974 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
977 // iErr=myBlock.ErrorStatus();
979 // myErrorStatus=12; // can not find the node point;
983 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
985 SMESH_Mesh* pMesh = GetMesh();
986 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
988 pNode = pMeshDS->AddNode(aX, aY, aZ);
993 //=======================================================================
994 //function : ShapeSupportID
996 //=======================================================================
997 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
998 const SMESH_Block::TShapeID aBNSSID,
999 SMESH_Block::TShapeID& aSSID)
1002 case SMESH_Block::ID_V000:
1003 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
1005 case SMESH_Block::ID_V100:
1006 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
1008 case SMESH_Block::ID_V110:
1009 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
1011 case SMESH_Block::ID_V010:
1012 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
1014 case SMESH_Block::ID_Ex00:
1015 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
1017 case SMESH_Block::ID_Ex10:
1018 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
1020 case SMESH_Block::ID_E0y0:
1021 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
1023 case SMESH_Block::ID_E1y0:
1024 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
1026 case SMESH_Block::ID_Fxy0:
1027 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1030 aSSID=SMESH_Block::ID_NONE;
1031 myErrorStatus->myName=10; // Can not find supporting shape ID
1032 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
1037 //=======================================================================
1038 //function : MakeBlock
1040 //=======================================================================
1041 void StdMeshers_Penta_3D::MakeBlock()
1044 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1046 TopoDS_Vertex aV000, aV001;
1048 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1049 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1050 TopTools_ListIteratorOfListOfShape aIt;
1052 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1054 // 0. Find triangulated face aFTr
1055 SMDSAbs_ElementType aElementType;
1056 SMESH_Mesh* pMesh=GetMesh();
1060 for (i=1; i<=iNbF; ++i) {
1061 const TopoDS_Shape& aF = aM(i);
1062 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1064 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1065 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1066 while(itf->more()) {
1067 const SMDS_MeshElement * pElement = itf->next();
1068 aElementType = pElement->GetType();
1069 if (aElementType==SMDSAbs_Face) {
1070 iNbNodes = pElement->NbNodes();
1071 if ( iNbNodes==3 || (myCreateQuadratic && iNbNodes==6) ) {
1076 // The current algorithm fails if there is more that one
1077 // face wich contains triangles ...
1078 // In that case, replace return by break to try another
1079 // method (coded in "if (iCnt != 1) { ... }")
1081 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1082 // myErrorStatus=5; // more than one face has triangulation
1094 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1095 // was not reached 'cause it was not called from Hexa_3D ... Now it
1096 // can occurs and in my opinion, it is the most common case.
1099 // The suggested algorithm is the following :
1101 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1102 // then the shape is tologically equivalent to a box
1103 // o In a box, there are three set of four // edges ...
1104 // In the cascade notation, it seems to be the edges
1109 // o For each one of this set, check if the four edges
1110 // have the same number of element.
1111 // o If so, check if the "corresponding" // faces contains
1112 // only quads. It's the faces numbered:
1116 // o If so, check if the opposite edges of each // faces
1117 // have the same number of elements. It is the edges
1119 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1120 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1121 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1122 // o If so, check if the two other faces have the same
1123 // number of elements. It is the faces numbered:
1127 // This test should be improved to test if the nodes
1128 // of the two faces are really "en face".
1129 // o If so, one of the two faces is a candidate to an extrusion,
1130 // It is the faces numbered :
1134 // o Finally, if there is only one candidate, let do the
1135 // extrusion job for the corresponding face
1139 int iNbF = aM.Extent();
1142 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1143 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1144 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1145 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1146 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1147 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1149 int has_only_quad_f1 = 1;
1150 int has_only_quad_f2 = 1;
1151 int has_only_quad_f3 = 1;
1152 int has_only_quad_f4 = 1;
1153 int has_only_quad_f5 = 1;
1154 int has_only_quad_f6 = 1;
1156 for (i=1; i<=iNbF; ++i) {
1158 const TopoDS_Shape& aF = aM(i);
1159 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1160 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1161 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1162 while(itf->more()) {
1163 const SMDS_MeshElement * pElement = itf->next();
1164 aElementType = pElement->GetType();
1165 if (aElementType==SMDSAbs_Face) {
1166 iNbNodes = pElement->NbNodes();
1167 if ( iNbNodes!=4 ) {
1173 if (i==1) has_only_quad_f1 = ok ;
1174 if (i==2) has_only_quad_f2 = ok ;
1175 if (i==3) has_only_quad_f3 = ok ;
1176 if (i==4) has_only_quad_f4 = ok ;
1177 if (i==5) has_only_quad_f5 = ok ;
1178 if (i==6) has_only_quad_f6 = ok ;
1181 TopTools_IndexedMapOfShape aE;
1182 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1183 int iNbE = aE.Extent();
1186 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1187 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1188 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1189 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1190 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1191 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1192 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1193 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1194 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1195 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1196 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1197 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1201 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1202 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1203 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1211 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1212 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1213 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1221 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1222 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1223 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1239 myErrorStatus->myName=5; // more than one face has triangulation
1240 myErrorStatus->myComment="Incorrect input mesh";
1246 // 1. Vetrices V00, V001;
1248 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1249 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1251 // 1.1 Base vertex V000
1252 iNbE = aME.Extent();
1253 if (iNbE!= NB_WALL_FACES ){
1254 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1255 myErrorStatus->myName=7; // too few edges are in base face aFTr
1256 myErrorStatus->myComment=SMESH_Comment("Not a quadrilateral face #")
1257 <<pMesh->GetMeshDS()->ShapeToIndex( aFTr )<<": "<<iNbE<<" edges" ;
1260 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1261 aV000=TopExp::FirstVertex(aE1);
1263 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1264 aIt.Initialize(aLE);
1265 for (; aIt.More(); aIt.Next()) {
1266 const TopoDS_Shape& aEx=aIt.Value();
1269 iNbEV=aMEV.Extent();
1271 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1272 myErrorStatus->myName=7; // too few edges meet in base vertex
1273 myErrorStatus->myComment=SMESH_Comment("3 edges must share vertex #")
1274 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 )<<" but there are "<<iNbEV<<" edges";
1280 for (j=1; j<=iNbEV; ++j) {
1281 const TopoDS_Shape& aEx=aMEV(j);
1282 if (!aME.Contains(aEx)) {
1283 TopoDS_Vertex aV[2];
1285 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1286 TopExp::Vertices(aE, aV[0], aV[1]);
1287 for (i=0; i<2; ++i) {
1288 if (!aV[i].IsSame(aV000)) {
1298 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1299 myErrorStatus->myName=8; // can not find reper V001
1300 myErrorStatus->myComment=SMESH_Comment("Can't find opposite vertex for vertex #")
1301 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 );
1305 //gp_Pnt aP000, aP001;
1307 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1308 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1309 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1310 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1314 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1317 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1318 myErrorStatus->myName=9; // number of shells in source shape !=1
1319 myErrorStatus->myComment=SMESH_Comment("Unexpected nb of shells ")<<iNbE;
1324 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1325 myBlock.Load(aShell, aV000, aV001);
1326 iErr = myBlock.ErrorStatus();
1328 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1329 myErrorStatus=myBlock.GetError(); // SMESHBlock: Load operation failed
1333 //=======================================================================
1334 //function : CheckData
1336 //=======================================================================
1337 void StdMeshers_Penta_3D::CheckData()
1340 int iNbEx[]={8, 12, 6};
1342 TopAbs_ShapeEnum aST;
1343 TopAbs_ShapeEnum aSTEx[]={
1344 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1346 TopTools_IndexedMapOfShape aM;
1348 if (myShape.IsNull()){
1349 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1350 myErrorStatus->myName=2; // null shape
1351 myErrorStatus->myComment="Null shape";
1355 aST=myShape.ShapeType();
1356 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1357 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1358 myErrorStatus->myName=3; // not compatible type of shape
1359 myErrorStatus->myComment=SMESH_Comment("Wrong shape type (TopAbs_ShapeEnum) ")<<aST;
1363 for (i=0; i<3; ++i) {
1365 TopExp::MapShapes(myShape, aSTEx[i], aM);
1368 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1369 myErrorStatus->myName=4; // number of subshape is not compatible
1370 myErrorStatus->myComment="Wrong number of subshapes of a block";
1376 //=======================================================================
1377 //function : LoadIJNodes
1378 //purpose : Load nodes bound to theFace into column (vectors) and rows
1380 // The value of theIJNodes map is a vector of ordered nodes so
1381 // that the 0-the one lies on theBaseEdge.
1382 // The key of theIJNodes map is a normalized parameter of each
1383 // 0-the node on theBaseEdge.
1384 //=======================================================================
1386 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1387 const TopoDS_Face& theFace,
1388 const TopoDS_Edge& theBaseEdge,
1389 SMESHDS_Mesh* theMesh)
1391 // get vertices of theBaseEdge
1392 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1393 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1394 TopExp::Vertices( eFrw, vfb, vlb );
1396 // find the other edges of theFace and orientation of e1
1397 TopoDS_Edge e1, e2, eTop;
1398 bool rev1, CumOri = false;
1399 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1401 for ( ; exp.More(); exp.Next() ) {
1402 if ( ++nbEdges > NB_WALL_FACES ) {
1403 return false; // more than 4 edges in theFace
1405 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1406 if ( theBaseEdge.IsSame( e ))
1408 TopoDS_Vertex vCommon;
1409 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1411 else if ( vCommon.IsSame( vfb )) {
1413 vft = TopExp::LastVertex( e1, CumOri );
1414 rev1 = vfb.IsSame( vft );
1416 vft = TopExp::FirstVertex( e1, CumOri );
1421 if ( nbEdges < NB_WALL_FACES ) {
1422 return false; // less than 4 edges in theFace
1425 // submeshes corresponding to shapes
1426 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1427 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1428 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1429 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1430 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1431 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1432 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1433 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1434 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1435 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1436 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1439 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1440 MESSAGE(" Diff nb of nodes on opposite edges" );
1443 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1444 MESSAGE("Empty submesh of vertex");
1447 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1448 // check quadratic case
1449 if ( myCreateQuadratic ) {
1450 int n1 = sm1->NbNodes()/2;
1451 int n2 = smb->NbNodes()/2;
1452 int n3 = sm1->NbNodes() - n1;
1453 int n4 = smb->NbNodes() - n2;
1454 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1455 if( nf != smFace->NbNodes() ) {
1456 MESSAGE( "Wrong nb face nodes: " <<
1457 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1462 MESSAGE( "Wrong nb face nodes: " <<
1463 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1468 int vsize = sm1->NbNodes() + 2;
1469 int hsize = smb->NbNodes() + 2;
1470 if(myCreateQuadratic) {
1471 vsize = vsize - sm1->NbNodes()/2 -1;
1472 hsize = hsize - smb->NbNodes()/2 -1;
1475 // load nodes from theBaseEdge
1477 set<const SMDS_MeshNode*> loadedNodes;
1478 const SMDS_MeshNode* nullNode = 0;
1480 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1481 nVecf.resize( vsize, nullNode );
1482 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1484 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1485 nVecl.resize( vsize, nullNode );
1486 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1489 BRep_Tool::Range( eFrw, f, l );
1490 double range = l - f;
1491 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1492 const SMDS_MeshNode* node;
1493 while ( nIt->more() ) {
1495 if(myTool->IsMedium(node))
1497 const SMDS_EdgePosition* pos =
1498 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1502 double u = ( pos->GetUParameter() - f ) / range;
1503 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1504 nVec.resize( vsize, nullNode );
1505 loadedNodes.insert( nVec[ 0 ] = node );
1507 if ( theIJNodes.size() != hsize ) {
1508 MESSAGE( "Wrong node positions on theBaseEdge" );
1512 // load nodes from e1
1514 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1515 nIt = sm1->GetNodes();
1516 while ( nIt->more() ) {
1518 if(myTool->IsMedium(node))
1520 const SMDS_EdgePosition* pos =
1521 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1525 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1527 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1528 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1529 int row = rev1 ? vsize - 1 : 0;
1530 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1533 loadedNodes.insert( nVecf[ row ] = u_n->second );
1536 // try to load the rest nodes
1538 // get all faces from theFace
1539 TIDSortedElemSet allFaces, foundFaces;
1540 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1541 while ( eIt->more() ) {
1542 const SMDS_MeshElement* e = eIt->next();
1543 if ( e->GetType() == SMDSAbs_Face )
1544 allFaces.insert( e );
1546 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1547 // the nodes belong to, and between the nodes of the found face,
1548 // look for a not loaded node considering this node to be the next
1549 // in a column of the starting second node. Repeat, starting
1550 // from nodes next to the previous starting nodes in their columns,
1551 // and so on while a face can be found. Then go the the next pair
1552 // of nodes on theBaseEdge.
1553 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1554 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1557 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1560 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1561 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1562 const SMDS_MeshElement* face = 0;
1564 // look for a face by 2 nodes
1565 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1567 int nbFaceNodes = face->NbNodes();
1568 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1569 (myCreateQuadratic && nbFaceNodes>8) ) {
1570 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1573 // look for a not loaded node of the <face>
1575 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1576 eIt = face->nodesIterator() ;
1577 while ( !found && eIt->more() ) {
1578 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1579 if(myTool->IsMedium(node))
1581 found = loadedNodes.insert( node ).second;
1582 if ( !found && node != n1 && node != n2 )
1586 if ( ++row > vsize - 1 ) {
1587 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1590 par_nVec_2->second[ row ] = node;
1591 foundFaces.insert( face );
1593 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1594 n1 = par_nVec_1->second[ row ];
1597 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1598 n3 == par_nVec_1->second[ row ] ) {
1602 MESSAGE( "Not quad mesh, column "<< col );
1607 while ( face && n1 && n2 );
1609 if ( row < vsize - 1 ) {
1610 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1611 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1612 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1613 MESSAGE( "Current node 1: "<< n1);
1614 MESSAGE( "Current node 2: "<< n2);
1615 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1616 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1619 } // loop on columns
1624 //////////////////////////////////////////////////////////////////////////
1626 // StdMeshers_SMESHBlock
1628 //////////////////////////////////////////////////////////////////////////
1630 //=======================================================================
1631 //function : StdMeshers_SMESHBlock
1633 //=======================================================================
1634 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1637 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1640 //=======================================================================
1641 //function : IsForwadEdge
1643 //=======================================================================
1645 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1647 int index = myTBlock.ShapeIndex( theEdgeID );
1648 if ( !myTBlock.IsEdgeID( theEdgeID ))
1651 if ( myIsEdgeForward[ index ] < 0 )
1652 myIsEdgeForward[ index ] =
1653 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1655 return myIsEdgeForward[ index ];
1658 //=======================================================================
1659 //function : ErrorStatus
1661 //=======================================================================
1662 int StdMeshers_SMESHBlock::ErrorStatus() const
1664 return myErrorStatus;
1667 //================================================================================
1669 * \brief Return problem description
1671 //================================================================================
1673 SMESH_ComputeErrorPtr StdMeshers_SMESHBlock::GetError() const
1675 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1676 string & text = err->myComment;
1677 switch ( myErrorStatus ) {
1679 case 3: text = "Internal error of StdMeshers_Penta_3D"; break;
1680 case 4: text = "Can't compute normalized parameters of a point inside a block"; break;
1681 case 5: text = "Can't compute coordinates by normalized parameters inside a block"; break;
1682 case 6: text = "Can't detect block subshapes. Not a block?"; break;
1685 err->myName = myErrorStatus;
1689 //=======================================================================
1692 //=======================================================================
1693 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1695 TopoDS_Vertex aV000, aV001;
1697 Load(theShell, aV000, aV001);
1700 //=======================================================================
1703 //=======================================================================
1704 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1705 const TopoDS_Vertex& theV000,
1706 const TopoDS_Vertex& theV001)
1714 myShapeIDMap.Clear();
1715 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1722 //=======================================================================
1723 //function : ComputeParameters
1725 //=======================================================================
1726 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1729 ComputeParameters(thePnt, myShell, theXYZ);
1732 //=======================================================================
1733 //function : ComputeParameters
1735 //=======================================================================
1736 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1737 const TopoDS_Shape& theShape,
1745 aID = ShapeID(theShape);
1746 if (myErrorStatus) {
1749 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1751 myErrorStatus=4; // problems with computation Parameters
1756 //=======================================================================
1757 //function : ComputeParameters
1759 //=======================================================================
1761 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1762 const TopoDS_Shape& theShape,
1770 aID = ShapeID(theShape);
1771 if (myErrorStatus) {
1774 if ( SMESH_Block::IsEdgeID( aID ))
1775 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1777 myErrorStatus=4; // problems with computation Parameters
1782 //=======================================================================
1785 //=======================================================================
1786 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1791 Point(theParams, aS, aP3D);
1794 //=======================================================================
1797 //=======================================================================
1798 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1799 const TopoDS_Shape& theShape,
1806 gp_XYZ aXYZ(99.,99.,99.);
1809 if (theShape.IsNull()) {
1810 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1814 aID=ShapeID(theShape);
1815 if (myErrorStatus) {
1819 if (SMESH_Block::IsVertexID(aID)) {
1820 bOk = myTBlock.VertexPoint(aID, aXYZ);
1822 else if (SMESH_Block::IsEdgeID(aID)) {
1823 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1826 else if (SMESH_Block::IsFaceID(aID)) {
1827 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1831 myErrorStatus=5; // problems with point computation
1837 //=======================================================================
1838 //function : ShapeID
1840 //=======================================================================
1841 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1846 TopoDS_Shape aSF, aSR;
1849 aSF.Orientation(TopAbs_FORWARD);
1851 aSR.Orientation(TopAbs_REVERSED);
1853 if (myShapeIDMap.Contains(aSF)) {
1854 aID=myShapeIDMap.FindIndex(aSF);
1857 if (myShapeIDMap.Contains(aSR)) {
1858 aID=myShapeIDMap.FindIndex(aSR);
1861 myErrorStatus=2; // unknown shape;
1865 //=======================================================================
1868 //=======================================================================
1869 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1875 aNb=myShapeIDMap.Extent();
1876 if (theID<1 || theID>aNb) {
1877 myErrorStatus=3; // ID is out of range
1878 return myEmptyShape;
1881 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);