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 <BRepTools.hxx>
44 #include <BRepTools_WireExplorer.hxx>
45 #include <BRep_Tool.hxx>
46 #include <TopAbs_ShapeEnum.hxx>
48 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <TopTools_ListIteratorOfListOfShape.hxx>
52 #include <TopTools_ListOfShape.hxx>
53 #include <TopTools_MapOfShape.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Shell.hxx>
57 #include <TopoDS_Vertex.hxx>
65 typedef map < int, int, less<int> >::iterator \
66 StdMeshers_IteratorOfDataMapOfIntegerInteger;
68 enum { NB_WALL_FACES = 4 };
70 //=======================================================================
71 //function : StdMeshers_Penta_3D
73 //=======================================================================
74 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
75 : myErrorStatus(SMESH_ComputeError::New())
78 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
79 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
83 //=======================================================================
84 //function : ~StdMeshers_Penta_3D
86 //=======================================================================
88 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
92 //=======================================================================
95 //=======================================================================
96 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
97 const TopoDS_Shape& aShape)
99 MESSAGE("StdMeshers_Penta_3D::Compute()");
107 if (!myErrorStatus->IsOK()) {
111 SMESH_MesherHelper helper(aMesh);
113 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
117 if (!myErrorStatus->IsOK()) {
122 if (!myErrorStatus->IsOK()) {
127 if (!myErrorStatus->IsOK()) {
134 if (!myErrorStatus->IsOK()) {
143 //=======================================================================
144 //function : MakeNodes
146 //=======================================================================
147 void StdMeshers_Penta_3D::MakeNodes()
150 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
152 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
153 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
154 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
155 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
156 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
160 SMESH_Mesh* pMesh=GetMesh();
162 // 1. Define the sizes of mesh
164 // 1.1 Horizontal size
166 for (i=0; i<aNbSIDs; ++i) {
167 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
168 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
170 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
171 if(!myCreateQuadratic) {
172 iNbN = aSM->NbNodes();
176 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
178 const SMDS_MeshNode* aNode = itn->next();
179 if(myTool->IsMedium(aNode))
186 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
191 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
192 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
194 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
195 if(!myCreateQuadratic) {
196 iNbN = aSM->NbNodes();
200 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
202 const SMDS_MeshNode* aNode = itn->next();
203 if(myTool->IsMedium(aNode))
210 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
212 aSize=myISize*myJSize;
213 myTNodes.resize(aSize);
215 StdMeshers_TNode aTNode;
219 // 2. Fill the repers on base face (Z=0)
222 for (k=0; k<aNbSIDs; ++k) {
224 const TopoDS_Shape& aS = myBlock.Shape(aSID);
225 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
227 const SMDS_MeshNode* aNode = ite->next();
228 if(myTool->IsMedium(aNode))
230 aNodeID=aNode->GetID();
232 aTNode.SetNode(aNode);
233 aTNode.SetShapeSupportID(aSID);
234 aTNode.SetBaseNodeID(aNodeID);
236 if ( SMESH_Block::IsEdgeID (aSID)) {
237 const SMDS_EdgePosition* epos =
238 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
239 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
245 aP3D.SetCoord(aX, aY, aZ);
246 myBlock.ComputeParameters(aP3D, aS, aCoords);
248 iErr = myBlock.ErrorStatus();
250 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
251 "SMESHBlock: ComputeParameters operation failed");
252 myErrorStatus=myBlock.GetError();
255 aTNode.SetNormCoord(aCoords);
262 // 3.1 Fill maps of wall nodes
263 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
264 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
265 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
267 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
268 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
269 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
271 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
272 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
273 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
274 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
275 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
278 myErrorStatus->myName = COMPERR_BAD_INPUT_MESH;
279 myErrorStatus->myComment = SMESH_Comment() <<
280 "Can't find regular quadrangle mesh on a side face #" <<
281 pMesh->GetMeshDS()->ShapeToIndex( myBlock.Shape( wallFaceID[ i ]));
286 // 3.2 find node columns for vertical edges and edge IDs
287 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
288 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
289 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
291 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
292 ShapeSupportID(false, vID, eID);
293 verticEdgeID[ i ] = eID;
295 StdMeshers_TNode& aTNode = myTNodes[ i ];
296 verticEdgeNodes[ i ] = 0;
297 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
298 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
299 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
300 if ( ijNodes.begin()->second[0] == aTNode.Node() )
301 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
302 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
303 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
304 if ( verticEdgeNodes[ i ] )
309 // 3.3 set XYZ of vertices, and initialize of the rest
310 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
311 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
312 if ( SMESH_Block::IsVertexID( id )) {
313 TopoDS_Shape V = myBlock.Shape( id );
314 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
315 const SMDS_MeshNode* n = sm->GetNodes()->next();
316 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
319 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
323 // 4. Fill the rest repers
326 SMESH_Block::TShapeID aSSID, aBNSSID;
327 StdMeshers_TNode aTN;
330 // create top face and find UV for it's corners
331 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
332 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
333 int topfaceID = meshDS->ShapeToIndex(TopFace);
334 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
335 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
336 const SMDS_MeshNode* N = itn->next();
337 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
338 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
339 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
341 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
342 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
343 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
345 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
346 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
347 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
349 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
351 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
353 const StdMeshers_TNode& aBN = myTNodes[j];
354 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
355 iBNID = aBN.BaseNodeID();
356 const gp_XYZ& aBNXYZ = aBN.NormCoord();
357 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
359 // set XYZ on horizontal edges and get node columns of faces:
360 // 2 columns for each face, between which a base node is located
361 vector<const SMDS_MeshNode*>* nColumns[8];
362 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
364 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
365 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
366 nColumns[k*2], nColumns[k*2+1]);
370 // XYZ on the bottom and top faces
371 const SMDS_MeshNode* n = aBN.Node();
372 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
373 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
375 // first create or find a top node, then the rest ones in a column
376 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
378 bIsUpperLayer = (i==(myISize-1));
379 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
380 if ( createNode ) // a base node is inside a top face
382 // set XYZ on vertical edges and faces
383 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
384 // XYZ on a vertical edge
385 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
386 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
387 // XYZ on a face (part 1 from one column)
388 n = (*nColumns[k*2]) [ i ];
389 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
390 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
392 if( bIsUpperLayer ) {
393 tmp1 = myTool->GetNodeUV(TopFace,n);
394 tmp1 = ( 1. - ratio[ k ]) * tmp1;
396 // XYZ on a face (part 2 from other column)
397 n = (*nColumns[k*2+1]) [ i ];
398 xyz.SetCoord( n->X(), n->Y(), n->Z() );
399 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
400 if( bIsUpperLayer ) {
401 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
402 tmp1 += ratio[ k ] * tmp2;
414 // fill current node info
417 // -normalized coordinates
421 aZ=(double)i/(double)(myISize-1);
422 aCoords.SetCoord(aX, aY, aZ);
424 // suporting shape ID
425 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
426 if (!myErrorStatus->IsOK()) {
427 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
431 aTN.SetShapeSupportID(aSSID);
432 aTN.SetNormCoord(aCoords);
433 aTN.SetBaseNodeID(iBNID);
435 if (aSSID!=SMESH_Block::ID_NONE){
436 // try to find the node
437 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
438 FindNodeOnShape(aS, aCoords, i, aTN);
441 // create node and get it id
442 CreateNode (bIsUpperLayer, aCoords, aTN);
444 if ( bIsUpperLayer ) {
445 const SMDS_MeshNode* n = aTN.Node();
446 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
447 // set node on top face:
448 // find UV parameter for this node
450 // UV011+-----+----------+UV111
453 // UV_E0y1+ +node +UV_E1y1
457 // UV001+-----+----------+UV101
460 double u = aCoords.X(), v = aCoords.Y();
461 double u1 = ( 1. - u ), v1 = ( 1. - v );
462 aP.ChangeCoord() = UV_Ex01 * v1;
463 aP.ChangeCoord() += UV_Ex11 * v;
464 aP.ChangeCoord() += UV_E0y1 * u1;
465 aP.ChangeCoord() += UV_E1y1 * u;
466 aP.ChangeCoord() -= UV001 * u1 * v1;
467 aP.ChangeCoord() -= UV101 * u * v1;
468 aP.ChangeCoord() -= UV011 * u1 * v;
469 aP.ChangeCoord() -= UV111 * u * v;
470 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
473 if (!myErrorStatus->IsOK()) {
474 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
484 int iSSID, iBNID, aID;
486 for (i=0; i<myISize; ++i) {
487 printf(" Layer# %d\n", i);
488 for (j=0; j<myJSize; ++j) {
490 const StdMeshers_TNode& aTN=myTNodes[ij];
491 //const StdMeshers_TNode& aTN=aTNodes[ij];
492 const gp_XYZ& aXYZ=aTN.NormCoord();
493 iSSID=aTN.ShapeSupportID();
494 iBNID=aTN.BaseNodeID();
496 const SMDS_MeshNode* aNode=aTN.Node();
501 printf("*** j:%d BNID#%d iSSID:%d ID:%d { %lf %lf %lf }, { %lf %lf %lf }\n",
502 j, iBNID, iSSID, aID, aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aX, aY, aZ);
511 //=======================================================================
512 //function : FindNodeOnShape
514 //=======================================================================
516 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
517 const gp_XYZ& aParams,
519 StdMeshers_TNode& aTN)
521 double aX, aY, aZ, aD, aTol2, minD;
524 SMESH_Mesh* pMesh = GetMesh();
525 aTol2 = myTol3D*myTol3D;
527 SMDS_MeshNode* pNode = NULL;
529 if ( aS.ShapeType() == TopAbs_FACE ||
530 aS.ShapeType() == TopAbs_EDGE ) {
531 // find a face ID to which aTN belongs to
533 if ( aS.ShapeType() == TopAbs_FACE )
534 faceID = myBlock.ShapeID( aS );
535 else { // edge maybe vertical or top horizontal
536 gp_XYZ aCoord = aParams;
537 if ( aCoord.Z() == 1. )
538 aCoord.SetZ( 0.5 ); // move from top down
540 aCoord.SetX( 0.5 ); // move along X
541 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
543 ASSERT( SMESH_Block::IsFaceID( faceID ));
544 int fIndex = SMESH_Block::ShapeIndex( faceID );
545 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
546 // look for a base node in ijNodes
547 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
548 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
549 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
550 if ( par_nVec->second[ 0 ] == baseNode ) {
551 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
557 myBlock.Point(aParams, aS, aP1);
559 SMDS_NodeIteratorPtr ite=
560 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
562 const SMDS_MeshNode* aNode = ite->next();
563 if(myTool->IsMedium(aNode))
568 aP2.SetCoord(aX, aY, aZ);
569 aD=(double)aP1.SquareDistance(aP2);
570 //printf("** D=%lf ", aD, aTol2);
572 pNode=(SMDS_MeshNode*)aNode;
582 //aTN.SetNode(pNode);
583 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
584 //myErrorStatus=11; // can not find the node;
588 //=======================================================================
589 //function : SetHorizEdgeXYZ
591 //=======================================================================
593 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
595 vector<const SMDS_MeshNode*>*& aCol1,
596 vector<const SMDS_MeshNode*>*& aCol2)
598 // find base and top edges of the face
599 enum { BASE = 0, TOP };
600 vector< int > edgeVec; // 0-base, 1-top
601 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
603 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
604 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
606 double param = aBaseNodeParams.Coord( coord );
610 // look for columns around param
611 StdMeshers_IJNodeMap & ijNodes =
612 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
613 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
614 while ( par_nVec_1->first < param )
616 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
619 if ( par_nVec_1 != ijNodes.begin() ) {
621 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
623 aCol1 = & par_nVec_1->second;
624 aCol2 = & par_nVec_2->second;
628 // this variant is better for cases with curved edges and
629 // different nodes distribution on top and base edges
630 const SMDS_MeshNode* n1 = aCol1->back();
631 const SMDS_MeshNode* n2 = aCol2->back();
632 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
633 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
634 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
637 // this variant is better for other cases
638 // SMESH_MesherHelper helper( *GetMesh() );
639 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
640 // double u1 = helper.GetNodeU( edge, n1 );
641 // double u2 = helper.GetNodeU( edge, n2 );
642 // double u = ( 1. - r ) * u1 + r * u2;
643 // gp_XYZ topNodeParams;
644 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
645 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
647 // myShapeXYZ[ edgeVec[ TOP ]]);
651 myBlock.Block().EdgePoint( edgeVec[ BASE ],
653 myShapeXYZ[ edgeVec[ BASE ]]);
658 //=======================================================================
659 //function : MakeVolumeMesh
661 //=======================================================================
662 void StdMeshers_Penta_3D::MakeVolumeMesh()
664 int i, j, ij, ik, i1, i2, aSSID;
666 SMESH_Mesh* pMesh = GetMesh();
667 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
669 int shapeID = meshDS->ShapeToIndex( myShape );
671 // 1. Set Node In Volume
673 for (i=1; i<ik; ++i){
674 for (j=0; j<myJSize; ++j){
676 const StdMeshers_TNode& aTN = myTNodes[ij];
677 aSSID=aTN.ShapeSupportID();
678 if (aSSID==SMESH_Block::ID_NONE) {
679 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
680 meshDS->SetNodeInVolume(aNode, shapeID);
685 // 2. Make pentahedrons
687 vector<const SMDS_MeshNode*> aN;
689 SMDS_ElemIteratorPtr itf, aItNodes;
691 const TopoDS_Face& aFxy0=
692 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
693 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
694 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
696 itf = aSM0->GetElements();
698 const SMDS_MeshElement* pE0 = itf->next();
700 int nbFaceNodes = pE0->NbNodes();
701 if(myCreateQuadratic)
702 nbFaceNodes = nbFaceNodes/2;
703 if ( aN.size() < nbFaceNodes * 2 )
704 aN.resize( nbFaceNodes * 2 );
707 aItNodes=pE0->nodesIterator();
708 while (aItNodes->more()) {
709 //const SMDS_MeshElement* pNode = aItNodes->next();
710 const SMDS_MeshNode* pNode =
711 static_cast<const SMDS_MeshNode*> (aItNodes->next());
712 if(myTool->IsMedium(pNode))
714 aID0 = pNode->GetID();
715 aJ[k] = GetIndexOnLayer(aID0);
716 if (!myErrorStatus->IsOK()) {
717 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
725 for (i=0; i<ik; ++i) {
728 for(j=0; j<nbFaceNodes; ++j) {
729 ij = i1*myJSize+aJ[j];
730 const StdMeshers_TNode& aTN1 = myTNodes[ij];
731 const SMDS_MeshNode* aN1 = aTN1.Node();
735 const StdMeshers_TNode& aTN2 = myTNodes[ij];
736 const SMDS_MeshNode* aN2 = aTN2.Node();
737 aN[j+nbFaceNodes] = aN2;
739 // check if volume orientation will be ok
741 SMDS_VolumeTool vTool;
742 switch ( nbFaceNodes ) {
744 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
745 aN[3], aN[4], aN[5]);
746 vTool.Set( &tmpVol );
750 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
751 aN[4], aN[5], aN[6], aN[7]);
752 vTool.Set( &tmpVol );
758 forward = vTool.IsForward();
761 SMDS_MeshVolume* aV = 0;
762 switch ( nbFaceNodes ) {
765 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
766 // aN[3], aN[4], aN[5]);
767 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
770 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
771 // aN[3], aN[5], aN[4]);
772 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
777 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
778 // aN[4], aN[5], aN[6], aN[7]);
779 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
780 aN[4], aN[5], aN[6], aN[7]);
783 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
784 // aN[4], aN[7], aN[6], aN[5]);
785 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
786 aN[4], aN[7], aN[6], aN[5]);
792 meshDS->SetMeshElementOnShape(aV, shapeID);
797 //=======================================================================
798 //function : MakeMeshOnFxy1
800 //=======================================================================
801 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
803 int aID0, aJ, aLevel, ij, aNbNodes, k;
805 SMDS_NodeIteratorPtr itn;
806 SMDS_ElemIteratorPtr itf, aItNodes;
807 SMDSAbs_ElementType aElementType;
809 const TopoDS_Face& aFxy0=
810 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
811 const TopoDS_Face& aFxy1=
812 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
813 SMESH_MesherHelper faceHelper( *GetMesh() );
814 faceHelper.IsQuadraticSubMesh(aFxy1);
816 SMESH_Mesh* pMesh = GetMesh();
817 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
819 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
820 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
821 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
823 // set nodes on aFxy1
825 itn = aSM0->GetNodes();
826 aNbNodes = aSM0->NbNodes();
827 //printf("** aNbNodes=%d\n", aNbNodes);
830 // set elements on aFxy1
831 vector<const SMDS_MeshNode*> aNodes1;
833 itf = aSM0->GetElements();
835 const SMDS_MeshElement* pE0 = itf->next();
836 aElementType = pE0->GetType();
837 if (!aElementType==SMDSAbs_Face) {
840 aNbNodes = pE0->NbNodes();
841 if(myCreateQuadratic)
842 aNbNodes = aNbNodes/2;
843 if ( aNodes1.size() < aNbNodes )
844 aNodes1.resize( aNbNodes );
846 k = aNbNodes-1; // reverse a face
847 aItNodes = pE0->nodesIterator();
848 while (aItNodes->more()) {
849 const SMDS_MeshNode* pNode =
850 static_cast<const SMDS_MeshNode*> (aItNodes->next());
851 if(myTool->IsMedium(pNode))
853 aID0 = pNode->GetID();
854 aJ = GetIndexOnLayer(aID0);
855 if (!myErrorStatus->IsOK()) {
856 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
860 ij = aLevel*myJSize + aJ;
861 const StdMeshers_TNode& aTN1 = myTNodes[ij];
862 const SMDS_MeshNode* aN1 = aTN1.Node();
866 SMDS_MeshFace * face = 0;
867 switch ( aNbNodes ) {
869 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
872 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
877 meshDS->SetMeshElementOnShape(face, aFxy1);
880 // update compute state of top face submesh
881 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
883 // assure that mesh on the top face will be cleaned when it is cleaned
884 // on the bottom face
885 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
886 volSM->SetEventListener( new SMESH_subMeshEventListener(true),
887 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
888 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
891 //=======================================================================
892 //function : ClearMeshOnFxy1
894 //=======================================================================
895 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
897 SMESH_subMesh* aSubMesh;
898 SMESH_Mesh* pMesh=GetMesh();
900 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
901 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
903 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
906 //=======================================================================
907 //function : GetIndexOnLayer
909 //=======================================================================
910 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
913 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
915 aMapIt=myConnectingMap.find(aID);
916 if (aMapIt==myConnectingMap.end()) {
917 myErrorStatus->myName = 200;
918 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
925 //=======================================================================
926 //function : MakeConnectingMap
928 //=======================================================================
929 void StdMeshers_Penta_3D::MakeConnectingMap()
933 for (j=0; j<myJSize; ++j) {
934 const StdMeshers_TNode& aBN=myTNodes[j];
935 aBNID=aBN.BaseNodeID();
936 myConnectingMap[aBNID]=j;
940 //=======================================================================
941 //function : CreateNode
943 //=======================================================================
944 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
945 const gp_XYZ& aParams,
946 StdMeshers_TNode& aTN)
952 SMDS_MeshNode* pNode=NULL;
955 // if (bIsUpperLayer) {
956 // // point on face Fxy1
957 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
958 // myBlock.Point(aParams, aS, aP);
961 // // point inside solid
962 // myBlock.Point(aParams, aP);
965 double u = aParams.X(), v = aParams.Y();
966 double u1 = ( 1. - u ), v1 = ( 1. - v );
967 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
968 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
969 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
970 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
972 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
973 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
974 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
975 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
978 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
981 // iErr=myBlock.ErrorStatus();
983 // myErrorStatus=12; // can not find the node point;
987 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
989 SMESH_Mesh* pMesh = GetMesh();
990 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
992 pNode = pMeshDS->AddNode(aX, aY, aZ);
997 //=======================================================================
998 //function : ShapeSupportID
1000 //=======================================================================
1001 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
1002 const SMESH_Block::TShapeID aBNSSID,
1003 SMESH_Block::TShapeID& aSSID)
1006 case SMESH_Block::ID_V000:
1007 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
1009 case SMESH_Block::ID_V100:
1010 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
1012 case SMESH_Block::ID_V110:
1013 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
1015 case SMESH_Block::ID_V010:
1016 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
1018 case SMESH_Block::ID_Ex00:
1019 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
1021 case SMESH_Block::ID_Ex10:
1022 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
1024 case SMESH_Block::ID_E0y0:
1025 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
1027 case SMESH_Block::ID_E1y0:
1028 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
1030 case SMESH_Block::ID_Fxy0:
1031 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1034 aSSID=SMESH_Block::ID_NONE;
1035 myErrorStatus->myName=10; // Can not find supporting shape ID
1036 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
1041 //=======================================================================
1042 //function : MakeBlock
1044 //=======================================================================
1045 void StdMeshers_Penta_3D::MakeBlock()
1048 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1050 TopoDS_Vertex aV000, aV001;
1052 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1053 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1054 TopTools_ListIteratorOfListOfShape aIt;
1056 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1058 // 0. Find triangulated face aFTr
1059 SMDSAbs_ElementType aElementType;
1060 SMESH_Mesh* pMesh=GetMesh();
1064 for (i=1; i<=iNbF; ++i) {
1065 const TopoDS_Shape& aF = aM(i);
1066 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1068 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1069 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1070 while(itf->more()) {
1071 const SMDS_MeshElement * pElement = itf->next();
1072 aElementType = pElement->GetType();
1073 if (aElementType==SMDSAbs_Face) {
1074 iNbNodes = pElement->NbNodes();
1075 if ( iNbNodes==3 || (myCreateQuadratic && iNbNodes==6) ) {
1080 // The current algorithm fails if there is more that one
1081 // face wich contains triangles ...
1082 // In that case, replace return by break to try another
1083 // method (coded in "if (iCnt != 1) { ... }")
1085 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1086 // myErrorStatus=5; // more than one face has triangulation
1098 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1099 // was not reached 'cause it was not called from Hexa_3D ... Now it
1100 // can occurs and in my opinion, it is the most common case.
1103 // The suggested algorithm is the following :
1105 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1106 // then the shape is tologically equivalent to a box
1107 // o In a box, there are three set of four // edges ...
1108 // In the cascade notation, it seems to be the edges
1113 // o For each one of this set, check if the four edges
1114 // have the same number of element.
1115 // o If so, check if the "corresponding" // faces contains
1116 // only quads. It's the faces numbered:
1120 // o If so, check if the opposite edges of each // faces
1121 // have the same number of elements. It is the edges
1123 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1124 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1125 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1126 // o If so, check if the two other faces have the same
1127 // number of elements. It is the faces numbered:
1131 // This test should be improved to test if the nodes
1132 // of the two faces are really "en face".
1133 // o If so, one of the two faces is a candidate to an extrusion,
1134 // It is the faces numbered :
1138 // o Finally, if there is only one candidate, let do the
1139 // extrusion job for the corresponding face
1143 int iNbF = aM.Extent();
1146 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1147 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1148 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1149 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1150 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1151 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1153 int has_only_quad_f1 = 1;
1154 int has_only_quad_f2 = 1;
1155 int has_only_quad_f3 = 1;
1156 int has_only_quad_f4 = 1;
1157 int has_only_quad_f5 = 1;
1158 int has_only_quad_f6 = 1;
1160 for (i=1; i<=iNbF; ++i) {
1162 const TopoDS_Shape& aF = aM(i);
1163 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1164 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1165 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1166 while(itf->more()) {
1167 const SMDS_MeshElement * pElement = itf->next();
1168 aElementType = pElement->GetType();
1169 if (aElementType==SMDSAbs_Face) {
1170 iNbNodes = pElement->NbNodes();
1171 if ( iNbNodes!=4 ) {
1177 if (i==1) has_only_quad_f1 = ok ;
1178 if (i==2) has_only_quad_f2 = ok ;
1179 if (i==3) has_only_quad_f3 = ok ;
1180 if (i==4) has_only_quad_f4 = ok ;
1181 if (i==5) has_only_quad_f5 = ok ;
1182 if (i==6) has_only_quad_f6 = ok ;
1185 TopTools_IndexedMapOfShape aE;
1186 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1187 int iNbE = aE.Extent();
1190 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1191 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1192 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1193 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1194 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1195 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1196 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1197 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1198 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1199 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1200 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1201 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1205 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1206 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1207 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1215 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1216 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1217 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1225 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1226 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1227 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1243 myErrorStatus->myName=5; // more than one face has triangulation
1244 myErrorStatus->myComment="Incorrect input mesh";
1250 // 1. Vetrices V00, V001;
1252 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1253 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1255 // 1.1 Base vertex V000
1256 iNbE = aME.Extent();
1257 if (iNbE!= NB_WALL_FACES ){
1258 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1259 myErrorStatus->myName=7; // too few edges are in base face aFTr
1260 myErrorStatus->myComment=SMESH_Comment("Not a quadrilateral face #")
1261 <<pMesh->GetMeshDS()->ShapeToIndex( aFTr )<<": "<<iNbE<<" edges" ;
1264 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1265 aV000=TopExp::FirstVertex(aE1);
1267 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1268 aIt.Initialize(aLE);
1269 for (; aIt.More(); aIt.Next()) {
1270 const TopoDS_Shape& aEx=aIt.Value();
1273 iNbEV=aMEV.Extent();
1275 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1276 myErrorStatus->myName=7; // too few edges meet in base vertex
1277 myErrorStatus->myComment=SMESH_Comment("3 edges must share vertex #")
1278 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 )<<" but there are "<<iNbEV<<" edges";
1284 for (j=1; j<=iNbEV; ++j) {
1285 const TopoDS_Shape& aEx=aMEV(j);
1286 if (!aME.Contains(aEx)) {
1287 TopoDS_Vertex aV[2];
1289 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1290 TopExp::Vertices(aE, aV[0], aV[1]);
1291 for (i=0; i<2; ++i) {
1292 if (!aV[i].IsSame(aV000)) {
1302 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1303 myErrorStatus->myName=8; // can not find reper V001
1304 myErrorStatus->myComment=SMESH_Comment("Can't find opposite vertex for vertex #")
1305 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 );
1309 //gp_Pnt aP000, aP001;
1311 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1312 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1313 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1314 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1318 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1321 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1322 myErrorStatus->myName=9; // number of shells in source shape !=1
1323 myErrorStatus->myComment=SMESH_Comment("Unexpected nb of shells ")<<iNbE;
1328 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1329 myBlock.Load(aShell, aV000, aV001);
1330 iErr = myBlock.ErrorStatus();
1332 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1333 myErrorStatus=myBlock.GetError(); // SMESHBlock: Load operation failed
1337 //=======================================================================
1338 //function : CheckData
1340 //=======================================================================
1341 void StdMeshers_Penta_3D::CheckData()
1344 int iNbEx[]={8, 12, 6};
1346 TopAbs_ShapeEnum aST;
1347 TopAbs_ShapeEnum aSTEx[]={
1348 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1350 TopTools_IndexedMapOfShape aM;
1352 if (myShape.IsNull()){
1353 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1354 myErrorStatus->myName=2; // null shape
1355 myErrorStatus->myComment="Null shape";
1359 aST=myShape.ShapeType();
1360 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1361 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1362 myErrorStatus->myName=3; // not compatible type of shape
1363 myErrorStatus->myComment=SMESH_Comment("Wrong shape type (TopAbs_ShapeEnum) ")<<aST;
1367 for (i=0; i<3; ++i) {
1369 TopExp::MapShapes(myShape, aSTEx[i], aM);
1372 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1373 myErrorStatus->myName=4; // number of subshape is not compatible
1374 myErrorStatus->myComment="Wrong number of subshapes of a block";
1380 //=======================================================================
1381 //function : LoadIJNodes
1382 //purpose : Load nodes bound to theFace into column (vectors) and rows
1384 // The value of theIJNodes map is a vector of ordered nodes so
1385 // that the 0-the one lies on theBaseEdge.
1386 // The key of theIJNodes map is a normalized parameter of each
1387 // 0-the node on theBaseEdge.
1388 //=======================================================================
1390 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1391 const TopoDS_Face& theFace,
1392 const TopoDS_Edge& theBaseEdge,
1393 SMESHDS_Mesh* theMesh)
1395 // get vertices of theBaseEdge
1396 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1397 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1398 TopExp::Vertices( eFrw, vfb, vlb );
1400 // find the other edges of theFace and orientation of e1
1401 TopoDS_Edge e1, e2, eTop;
1402 bool rev1, CumOri = false;
1403 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1405 for ( ; exp.More(); exp.Next() ) {
1406 if ( ++nbEdges > NB_WALL_FACES ) {
1407 return false; // more than 4 edges in theFace
1409 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1410 if ( theBaseEdge.IsSame( e ))
1412 TopoDS_Vertex vCommon;
1413 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1415 else if ( vCommon.IsSame( vfb )) {
1417 vft = TopExp::LastVertex( e1, CumOri );
1418 rev1 = vfb.IsSame( vft );
1420 vft = TopExp::FirstVertex( e1, CumOri );
1425 if ( nbEdges < NB_WALL_FACES ) {
1426 return false; // less than 4 edges in theFace
1429 // submeshes corresponding to shapes
1430 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1431 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1432 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1433 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1434 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1435 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1436 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1437 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1438 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1439 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1440 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1443 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1444 MESSAGE(" Diff nb of nodes on opposite edges" );
1447 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1448 MESSAGE("Empty submesh of vertex");
1451 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1452 // check quadratic case
1453 if ( myCreateQuadratic ) {
1454 int n1 = sm1->NbNodes()/2;
1455 int n2 = smb->NbNodes()/2;
1456 int n3 = sm1->NbNodes() - n1;
1457 int n4 = smb->NbNodes() - n2;
1458 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1459 if( nf != smFace->NbNodes() ) {
1460 MESSAGE( "Wrong nb face nodes: " <<
1461 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1466 MESSAGE( "Wrong nb face nodes: " <<
1467 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1472 int vsize = sm1->NbNodes() + 2;
1473 int hsize = smb->NbNodes() + 2;
1474 if(myCreateQuadratic) {
1475 vsize = vsize - sm1->NbNodes()/2 -1;
1476 hsize = hsize - smb->NbNodes()/2 -1;
1479 // load nodes from theBaseEdge
1481 set<const SMDS_MeshNode*> loadedNodes;
1482 const SMDS_MeshNode* nullNode = 0;
1484 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1485 nVecf.resize( vsize, nullNode );
1486 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1488 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1489 nVecl.resize( vsize, nullNode );
1490 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1493 BRep_Tool::Range( eFrw, f, l );
1494 double range = l - f;
1495 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1496 const SMDS_MeshNode* node;
1497 while ( nIt->more() ) {
1499 if(myTool->IsMedium(node))
1501 const SMDS_EdgePosition* pos =
1502 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1506 double u = ( pos->GetUParameter() - f ) / range;
1507 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1508 nVec.resize( vsize, nullNode );
1509 loadedNodes.insert( nVec[ 0 ] = node );
1511 if ( theIJNodes.size() != hsize ) {
1512 MESSAGE( "Wrong node positions on theBaseEdge" );
1516 // load nodes from e1
1518 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1519 nIt = sm1->GetNodes();
1520 while ( nIt->more() ) {
1522 if(myTool->IsMedium(node))
1524 const SMDS_EdgePosition* pos =
1525 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1529 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1531 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1532 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1533 int row = rev1 ? vsize - 1 : 0;
1534 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1537 loadedNodes.insert( nVecf[ row ] = u_n->second );
1540 // try to load the rest nodes
1542 // get all faces from theFace
1543 TIDSortedElemSet allFaces, foundFaces;
1544 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1545 while ( eIt->more() ) {
1546 const SMDS_MeshElement* e = eIt->next();
1547 if ( e->GetType() == SMDSAbs_Face )
1548 allFaces.insert( e );
1550 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1551 // the nodes belong to, and between the nodes of the found face,
1552 // look for a not loaded node considering this node to be the next
1553 // in a column of the starting second node. Repeat, starting
1554 // from nodes next to the previous starting nodes in their columns,
1555 // and so on while a face can be found. Then go the the next pair
1556 // of nodes on theBaseEdge.
1557 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1558 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1561 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1564 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1565 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1566 const SMDS_MeshElement* face = 0;
1568 // look for a face by 2 nodes
1569 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1571 int nbFaceNodes = face->NbNodes();
1572 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1573 (myCreateQuadratic && nbFaceNodes>8) ) {
1574 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1577 // look for a not loaded node of the <face>
1579 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1580 eIt = face->nodesIterator() ;
1581 while ( !found && eIt->more() ) {
1582 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1583 if(myTool->IsMedium(node))
1585 found = loadedNodes.insert( node ).second;
1586 if ( !found && node != n1 && node != n2 )
1590 if ( ++row > vsize - 1 ) {
1591 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1594 par_nVec_2->second[ row ] = node;
1595 foundFaces.insert( face );
1597 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1598 n1 = par_nVec_1->second[ row ];
1601 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1602 n3 == par_nVec_1->second[ row ] ) {
1606 MESSAGE( "Not quad mesh, column "<< col );
1611 while ( face && n1 && n2 );
1613 if ( row < vsize - 1 ) {
1614 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1615 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1616 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1617 MESSAGE( "Current node 1: "<< n1);
1618 MESSAGE( "Current node 2: "<< n2);
1619 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1620 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1623 } // loop on columns
1628 //////////////////////////////////////////////////////////////////////////
1630 // StdMeshers_SMESHBlock
1632 //////////////////////////////////////////////////////////////////////////
1634 //=======================================================================
1635 //function : StdMeshers_SMESHBlock
1637 //=======================================================================
1638 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1641 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1644 //=======================================================================
1645 //function : IsForwadEdge
1647 //=======================================================================
1649 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1651 int index = myTBlock.ShapeIndex( theEdgeID );
1652 if ( !myTBlock.IsEdgeID( theEdgeID ))
1655 if ( myIsEdgeForward[ index ] < 0 )
1656 myIsEdgeForward[ index ] =
1657 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1659 return myIsEdgeForward[ index ];
1662 //=======================================================================
1663 //function : ErrorStatus
1665 //=======================================================================
1666 int StdMeshers_SMESHBlock::ErrorStatus() const
1668 return myErrorStatus;
1671 //================================================================================
1673 * \brief Return problem description
1675 //================================================================================
1677 SMESH_ComputeErrorPtr StdMeshers_SMESHBlock::GetError() const
1679 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1680 string & text = err->myComment;
1681 switch ( myErrorStatus ) {
1683 case 3: text = "Internal error of StdMeshers_Penta_3D"; break;
1684 case 4: text = "Can't compute normalized parameters of a point inside a block"; break;
1685 case 5: text = "Can't compute coordinates by normalized parameters inside a block"; break;
1686 case 6: text = "Can't detect block subshapes. Not a block?"; break;
1689 err->myName = myErrorStatus;
1693 //=======================================================================
1696 //=======================================================================
1697 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1699 TopoDS_Vertex aV000, aV001;
1701 Load(theShell, aV000, aV001);
1704 //=======================================================================
1707 //=======================================================================
1708 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1709 const TopoDS_Vertex& theV000,
1710 const TopoDS_Vertex& theV001)
1718 myShapeIDMap.Clear();
1719 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1726 //=======================================================================
1727 //function : ComputeParameters
1729 //=======================================================================
1730 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1733 ComputeParameters(thePnt, myShell, theXYZ);
1736 //=======================================================================
1737 //function : ComputeParameters
1739 //=======================================================================
1740 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1741 const TopoDS_Shape& theShape,
1749 aID = ShapeID(theShape);
1750 if (myErrorStatus) {
1753 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1755 myErrorStatus=4; // problems with computation Parameters
1760 //=======================================================================
1761 //function : ComputeParameters
1763 //=======================================================================
1765 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1766 const TopoDS_Shape& theShape,
1774 aID = ShapeID(theShape);
1775 if (myErrorStatus) {
1778 if ( SMESH_Block::IsEdgeID( aID ))
1779 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1781 myErrorStatus=4; // problems with computation Parameters
1786 //=======================================================================
1789 //=======================================================================
1790 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1795 Point(theParams, aS, aP3D);
1798 //=======================================================================
1801 //=======================================================================
1802 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1803 const TopoDS_Shape& theShape,
1810 gp_XYZ aXYZ(99.,99.,99.);
1813 if (theShape.IsNull()) {
1814 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1818 aID=ShapeID(theShape);
1819 if (myErrorStatus) {
1823 if (SMESH_Block::IsVertexID(aID)) {
1824 bOk = myTBlock.VertexPoint(aID, aXYZ);
1826 else if (SMESH_Block::IsEdgeID(aID)) {
1827 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1830 else if (SMESH_Block::IsFaceID(aID)) {
1831 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1835 myErrorStatus=5; // problems with point computation
1841 //=======================================================================
1842 //function : ShapeID
1844 //=======================================================================
1845 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1850 TopoDS_Shape aSF, aSR;
1853 aSF.Orientation(TopAbs_FORWARD);
1855 aSR.Orientation(TopAbs_REVERSED);
1857 if (myShapeIDMap.Contains(aSF)) {
1858 aID=myShapeIDMap.FindIndex(aSF);
1861 if (myShapeIDMap.Contains(aSR)) {
1862 aID=myShapeIDMap.FindIndex(aSR);
1865 myErrorStatus=2; // unknown shape;
1869 //=======================================================================
1872 //=======================================================================
1873 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1879 aNb=myShapeIDMap.Extent();
1880 if (theID<1 || theID>aNb) {
1881 myErrorStatus=3; // ID is out of range
1882 return myEmptyShape;
1885 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);