1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
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
22 // SMESH StdMeshers_Penta_3D implementaion of SMESH idl descriptions
23 // File : StdMeshers_Penta_3D.cxx
26 #include "StdMeshers_Penta_3D.hxx"
28 #include "utilities.h"
29 #include "Utils_ExceptHandlers.hxx"
31 #include "SMDS_EdgePosition.hxx"
32 #include "SMDS_MeshElement.hxx"
33 #include "SMDS_VolumeOfNodes.hxx"
34 #include "SMDS_VolumeTool.hxx"
35 #include "SMESHDS_SubMesh.hxx"
36 #include "SMESH_Mesh.hxx"
37 #include "SMESH_MesherHelper.hxx"
38 #include "SMESH_subMesh.hxx"
39 #include "SMESH_subMeshEventListener.hxx"
40 #include "SMESH_Comment.hxx"
42 #include <BRep_Tool.hxx>
44 #include <TopExp_Explorer.hxx>
45 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
47 #include <TopTools_ListIteratorOfListOfShape.hxx>
48 #include <TopTools_ListOfShape.hxx>
49 #include <TopTools_SequenceOfShape.hxx>
50 #include <TopTools_MapOfShape.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Shell.hxx>
54 #include <TopoDS_Vertex.hxx>
62 typedef map < int, int, less<int> >::iterator \
63 StdMeshers_IteratorOfDataMapOfIntegerInteger;
65 enum { NB_WALL_FACES = 4 };
67 //=======================================================================
68 //function : StdMeshers_Penta_3D
70 //=======================================================================
71 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
72 : myErrorStatus(SMESH_ComputeError::New())
75 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
76 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
80 //=======================================================================
81 //function : ~StdMeshers_Penta_3D
83 //=======================================================================
85 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
89 //=======================================================================
92 //=======================================================================
93 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
94 const TopoDS_Shape& aShape)
96 MESSAGE("StdMeshers_Penta_3D::Compute()");
104 if (!myErrorStatus->IsOK()) {
110 if (!myErrorStatus->IsOK()) {
115 if (!myErrorStatus->IsOK()) {
119 // now unnecessary faces removed, we can load medium nodes
120 SMESH_MesherHelper helper(aMesh);
122 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
126 if (!myErrorStatus->IsOK()) {
133 if (!myErrorStatus->IsOK()) {
142 //=======================================================================
143 //function : MakeNodes
145 //=======================================================================
146 void StdMeshers_Penta_3D::MakeNodes()
149 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
151 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
152 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
153 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
154 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
155 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
159 SMESH_Mesh* pMesh=GetMesh();
161 // 1. Define the sizes of mesh
163 // 1.1 Horizontal size
165 for (i=0; i<aNbSIDs; ++i) {
166 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
167 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
169 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
170 if(!myCreateQuadratic) {
171 iNbN = aSM->NbNodes();
175 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
177 const SMDS_MeshNode* aNode = itn->next();
178 if(myTool->IsMedium(aNode))
185 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
190 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
191 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
193 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
194 if(!myCreateQuadratic) {
195 iNbN = aSM->NbNodes();
199 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
201 const SMDS_MeshNode* aNode = itn->next();
202 if(myTool->IsMedium(aNode))
209 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
211 aSize=myISize*myJSize;
212 myTNodes.resize(aSize);
214 StdMeshers_TNode aTNode;
218 // 2. Fill the repers on base face (Z=0)
221 for (k=0; k<aNbSIDs; ++k) {
223 const TopoDS_Shape& aS = myBlock.Shape(aSID);
224 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
226 const SMDS_MeshNode* aNode = ite->next();
227 if(myTool->IsMedium(aNode))
229 aNodeID=aNode->GetID();
231 aTNode.SetNode(aNode);
232 aTNode.SetShapeSupportID(aSID);
233 aTNode.SetBaseNodeID(aNodeID);
235 if ( SMESH_Block::IsEdgeID (aSID)) {
236 const SMDS_EdgePosition* epos =
237 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
238 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
244 aP3D.SetCoord(aX, aY, aZ);
245 myBlock.ComputeParameters(aP3D, aS, aCoords);
247 iErr = myBlock.ErrorStatus();
249 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
250 "SMESHBlock: ComputeParameters operation failed");
251 myErrorStatus=myBlock.GetError();
254 aTNode.SetNormCoord(aCoords);
261 // 3.1 Fill maps of wall nodes
262 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
263 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
264 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
266 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
267 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
268 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
270 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
271 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
272 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
273 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
274 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
277 myErrorStatus->myName = COMPERR_BAD_INPUT_MESH;
278 myErrorStatus->myComment = SMESH_Comment() <<
279 "Can't find regular quadrangle mesh on a side face #" <<
280 pMesh->GetMeshDS()->ShapeToIndex( myBlock.Shape( wallFaceID[ i ]));
285 // 3.2 find node columns for vertical edges and edge IDs
286 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
287 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
288 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
290 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
291 ShapeSupportID(false, vID, eID);
292 verticEdgeID[ i ] = eID;
294 StdMeshers_TNode& aTNode = myTNodes[ i ];
295 verticEdgeNodes[ i ] = 0;
296 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
297 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
298 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
299 if ( ijNodes.begin()->second[0] == aTNode.Node() )
300 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
301 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
302 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
303 if ( verticEdgeNodes[ i ] )
308 // 3.3 set XYZ of vertices, and initialize of the rest
309 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
310 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
311 if ( SMESH_Block::IsVertexID( id )) {
312 TopoDS_Shape V = myBlock.Shape( id );
313 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
314 const SMDS_MeshNode* n = sm->GetNodes()->next();
315 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
318 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
322 // 4. Fill the rest repers
325 SMESH_Block::TShapeID aSSID, aBNSSID;
326 StdMeshers_TNode aTN;
329 // create top face and find UV for it's corners
330 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
331 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
332 int topfaceID = meshDS->ShapeToIndex(TopFace);
333 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
334 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
335 const SMDS_MeshNode* N = itn->next();
336 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
337 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
338 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
340 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
341 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
342 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
344 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
345 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
346 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
348 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
350 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
352 const StdMeshers_TNode& aBN = myTNodes[j];
353 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
354 iBNID = aBN.BaseNodeID();
355 const gp_XYZ& aBNXYZ = aBN.NormCoord();
356 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
358 // set XYZ on horizontal edges and get node columns of faces:
359 // 2 columns for each face, between which a base node is located
360 vector<const SMDS_MeshNode*>* nColumns[8];
361 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
363 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
364 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
365 nColumns[k*2], nColumns[k*2+1]);
369 // XYZ on the bottom and top faces
370 const SMDS_MeshNode* n = aBN.Node();
371 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
372 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
374 // first create or find a top node, then the rest ones in a column
375 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
377 bIsUpperLayer = (i==(myISize-1));
378 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
379 if ( createNode ) // a base node is inside a top face
381 // set XYZ on vertical edges and faces
382 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
383 // XYZ on a vertical edge
384 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
385 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
386 // XYZ on a face (part 1 from one column)
387 n = (*nColumns[k*2]) [ i ];
388 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
389 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
391 if( bIsUpperLayer ) {
392 tmp1 = myTool->GetNodeUV(TopFace,n);
393 tmp1 = ( 1. - ratio[ k ]) * tmp1;
395 // XYZ on a face (part 2 from other column)
396 n = (*nColumns[k*2+1]) [ i ];
397 xyz.SetCoord( n->X(), n->Y(), n->Z() );
398 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
399 if( bIsUpperLayer ) {
400 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
401 tmp1 += ratio[ k ] * tmp2;
413 // fill current node info
416 // -normalized coordinates
420 aZ=(double)i/(double)(myISize-1);
421 aCoords.SetCoord(aX, aY, aZ);
423 // suporting shape ID
424 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
425 if (!myErrorStatus->IsOK()) {
426 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
430 aTN.SetShapeSupportID(aSSID);
431 aTN.SetNormCoord(aCoords);
432 aTN.SetBaseNodeID(iBNID);
434 if (aSSID!=SMESH_Block::ID_NONE){
435 // try to find the node
436 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
437 FindNodeOnShape(aS, aCoords, i, aTN);
440 // create node and get it id
441 CreateNode (bIsUpperLayer, aCoords, aTN);
443 if ( bIsUpperLayer ) {
444 const SMDS_MeshNode* n = aTN.Node();
445 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
446 // set node on top face:
447 // find UV parameter for this node
449 // UV011+-----+----------+UV111
452 // UV_E0y1+ +node +UV_E1y1
456 // UV001+-----+----------+UV101
459 double u = aCoords.X(), v = aCoords.Y();
460 double u1 = ( 1. - u ), v1 = ( 1. - v );
461 aP.ChangeCoord() = UV_Ex01 * v1;
462 aP.ChangeCoord() += UV_Ex11 * v;
463 aP.ChangeCoord() += UV_E0y1 * u1;
464 aP.ChangeCoord() += UV_E1y1 * u;
465 aP.ChangeCoord() -= UV001 * u1 * v1;
466 aP.ChangeCoord() -= UV101 * u * v1;
467 aP.ChangeCoord() -= UV011 * u1 * v;
468 aP.ChangeCoord() -= UV111 * u * v;
469 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
472 if (!myErrorStatus->IsOK()) {
473 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
483 int iSSID, iBNID, aID;
485 for (i=0; i<myISize; ++i) {
486 printf(" Layer# %d\n", i);
487 for (j=0; j<myJSize; ++j) {
489 const StdMeshers_TNode& aTN=myTNodes[ij];
490 //const StdMeshers_TNode& aTN=aTNodes[ij];
491 const gp_XYZ& aXYZ=aTN.NormCoord();
492 iSSID=aTN.ShapeSupportID();
493 iBNID=aTN.BaseNodeID();
495 const SMDS_MeshNode* aNode=aTN.Node();
500 printf("*** j:%d BNID#%d iSSID:%d ID:%d { %lf %lf %lf }, { %lf %lf %lf }\n",
501 j, iBNID, iSSID, aID, aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aX, aY, aZ);
510 //=======================================================================
511 //function : FindNodeOnShape
513 //=======================================================================
515 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
516 const gp_XYZ& aParams,
518 StdMeshers_TNode& aTN)
520 double aX, aY, aZ, aD, aTol2, minD;
523 SMESH_Mesh* pMesh = GetMesh();
524 aTol2 = myTol3D*myTol3D;
526 SMDS_MeshNode* pNode = NULL;
528 if ( aS.ShapeType() == TopAbs_FACE ||
529 aS.ShapeType() == TopAbs_EDGE ) {
530 // find a face ID to which aTN belongs to
532 if ( aS.ShapeType() == TopAbs_FACE )
533 faceID = myBlock.ShapeID( aS );
534 else { // edge maybe vertical or top horizontal
535 gp_XYZ aCoord = aParams;
536 if ( aCoord.Z() == 1. )
537 aCoord.SetZ( 0.5 ); // move from top down
539 aCoord.SetX( 0.5 ); // move along X
540 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
542 ASSERT( SMESH_Block::IsFaceID( faceID ));
543 int fIndex = SMESH_Block::ShapeIndex( faceID );
544 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
545 // look for a base node in ijNodes
546 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
547 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
548 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
549 if ( par_nVec->second[ 0 ] == baseNode ) {
550 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
556 myBlock.Point(aParams, aS, aP1);
558 SMDS_NodeIteratorPtr ite=
559 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
561 const SMDS_MeshNode* aNode = ite->next();
562 if(myTool->IsMedium(aNode))
567 aP2.SetCoord(aX, aY, aZ);
568 aD=(double)aP1.SquareDistance(aP2);
569 //printf("** D=%lf ", aD, aTol2);
571 pNode=(SMDS_MeshNode*)aNode;
581 //aTN.SetNode(pNode);
582 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
583 //myErrorStatus=11; // can not find the node;
587 //=======================================================================
588 //function : SetHorizEdgeXYZ
590 //=======================================================================
592 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
594 vector<const SMDS_MeshNode*>*& aCol1,
595 vector<const SMDS_MeshNode*>*& aCol2)
597 // find base and top edges of the face
598 enum { BASE = 0, TOP };
599 vector< int > edgeVec; // 0-base, 1-top
600 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
602 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
603 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
605 double param = aBaseNodeParams.Coord( coord );
609 // look for columns around param
610 StdMeshers_IJNodeMap & ijNodes =
611 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
612 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
613 while ( par_nVec_1->first < param )
615 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
618 if ( par_nVec_1 != ijNodes.begin() ) {
620 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
622 aCol1 = & par_nVec_1->second;
623 aCol2 = & par_nVec_2->second;
627 // this variant is better for cases with curved edges and
628 // different nodes distribution on top and base edges
629 const SMDS_MeshNode* n1 = aCol1->back();
630 const SMDS_MeshNode* n2 = aCol2->back();
631 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
632 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
633 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
636 // this variant is better for other cases
637 // SMESH_MesherHelper helper( *GetMesh() );
638 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
639 // double u1 = helper.GetNodeU( edge, n1 );
640 // double u2 = helper.GetNodeU( edge, n2 );
641 // double u = ( 1. - r ) * u1 + r * u2;
642 // gp_XYZ topNodeParams;
643 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
644 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
646 // myShapeXYZ[ edgeVec[ TOP ]]);
650 myBlock.Block().EdgePoint( edgeVec[ BASE ],
652 myShapeXYZ[ edgeVec[ BASE ]]);
657 //=======================================================================
658 //function : MakeVolumeMesh
660 //=======================================================================
661 void StdMeshers_Penta_3D::MakeVolumeMesh()
663 int i, j, ij, ik, i1, i2, aSSID;
665 SMESH_Mesh* pMesh = GetMesh();
666 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
668 int shapeID = meshDS->ShapeToIndex( myShape );
670 // 1. Set Node In Volume
672 for (i=1; i<ik; ++i){
673 for (j=0; j<myJSize; ++j){
675 const StdMeshers_TNode& aTN = myTNodes[ij];
676 aSSID=aTN.ShapeSupportID();
677 if (aSSID==SMESH_Block::ID_NONE) {
678 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
679 meshDS->SetNodeInVolume(aNode, shapeID);
684 // 2. Make pentahedrons
686 vector<const SMDS_MeshNode*> aN;
688 SMDS_ElemIteratorPtr itf, aItNodes;
690 const TopoDS_Face& aFxy0=
691 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
692 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
693 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
695 itf = aSM0->GetElements();
697 const SMDS_MeshElement* pE0 = itf->next();
699 int nbFaceNodes = pE0->NbNodes();
700 if(myCreateQuadratic)
701 nbFaceNodes = nbFaceNodes/2;
702 if ( aN.size() < nbFaceNodes * 2 )
703 aN.resize( nbFaceNodes * 2 );
706 aItNodes=pE0->nodesIterator();
707 while (aItNodes->more()) {
708 //const SMDS_MeshElement* pNode = aItNodes->next();
709 const SMDS_MeshNode* pNode =
710 static_cast<const SMDS_MeshNode*> (aItNodes->next());
711 if(myTool->IsMedium(pNode))
713 aID0 = pNode->GetID();
714 aJ[k] = GetIndexOnLayer(aID0);
715 if (!myErrorStatus->IsOK()) {
716 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
724 for (i=0; i<ik; ++i) {
727 for(j=0; j<nbFaceNodes; ++j) {
728 ij = i1*myJSize+aJ[j];
729 const StdMeshers_TNode& aTN1 = myTNodes[ij];
730 const SMDS_MeshNode* aN1 = aTN1.Node();
734 const StdMeshers_TNode& aTN2 = myTNodes[ij];
735 const SMDS_MeshNode* aN2 = aTN2.Node();
736 aN[j+nbFaceNodes] = aN2;
738 // check if volume orientation will be ok
740 SMDS_VolumeTool vTool;
741 switch ( nbFaceNodes ) {
743 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
744 aN[3], aN[4], aN[5]);
745 vTool.Set( &tmpVol );
749 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
750 aN[4], aN[5], aN[6], aN[7]);
751 vTool.Set( &tmpVol );
757 forward = vTool.IsForward();
760 SMDS_MeshVolume* aV = 0;
761 switch ( nbFaceNodes ) {
764 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
765 // aN[3], aN[4], aN[5]);
766 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
769 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
770 // aN[3], aN[5], aN[4]);
771 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
776 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
777 // aN[4], aN[5], aN[6], aN[7]);
778 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
779 aN[4], aN[5], aN[6], aN[7]);
782 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
783 // aN[4], aN[7], aN[6], aN[5]);
784 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
785 aN[4], aN[7], aN[6], aN[5]);
791 meshDS->SetMeshElementOnShape(aV, shapeID);
796 //=======================================================================
797 //function : MakeMeshOnFxy1
799 //=======================================================================
800 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
802 int aID0, aJ, aLevel, ij, aNbNodes, k;
804 SMDS_NodeIteratorPtr itn;
805 SMDS_ElemIteratorPtr itf, aItNodes;
806 SMDSAbs_ElementType aElementType;
808 const TopoDS_Face& aFxy0=
809 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
810 const TopoDS_Face& aFxy1=
811 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
813 SMESH_Mesh* pMesh = GetMesh();
814 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
816 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
817 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
818 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
820 // set nodes on aFxy1
822 itn = aSM0->GetNodes();
823 aNbNodes = aSM0->NbNodes();
824 //printf("** aNbNodes=%d\n", aNbNodes);
827 // set elements on aFxy1
828 vector<const SMDS_MeshNode*> aNodes1;
830 itf = aSM0->GetElements();
832 const SMDS_MeshElement* pE0 = itf->next();
833 aElementType = pE0->GetType();
834 if (!aElementType==SMDSAbs_Face) {
837 aNbNodes = pE0->NbNodes();
838 if(myCreateQuadratic)
839 aNbNodes = aNbNodes/2;
840 if ( aNodes1.size() < aNbNodes )
841 aNodes1.resize( aNbNodes );
843 k = aNbNodes-1; // reverse a face
844 aItNodes = pE0->nodesIterator();
845 while (aItNodes->more()) {
846 const SMDS_MeshNode* pNode =
847 static_cast<const SMDS_MeshNode*> (aItNodes->next());
848 if(myTool->IsMedium(pNode))
850 aID0 = pNode->GetID();
851 aJ = GetIndexOnLayer(aID0);
852 if (!myErrorStatus->IsOK()) {
853 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
857 ij = aLevel*myJSize + aJ;
858 const StdMeshers_TNode& aTN1 = myTNodes[ij];
859 const SMDS_MeshNode* aN1 = aTN1.Node();
863 SMDS_MeshFace * face = 0;
864 switch ( aNbNodes ) {
866 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
869 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
874 meshDS->SetMeshElementOnShape(face, aFxy1);
877 // update compute state of top face submesh
878 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
880 // assure that mesh on the top face will be cleaned when it is cleaned
881 // on the bottom face
882 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
883 volSM->SetEventListener( new SMESH_subMeshEventListener(true),
884 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
885 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
888 //=======================================================================
889 //function : ClearMeshOnFxy1
891 //=======================================================================
892 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
894 SMESH_subMesh* aSubMesh;
895 SMESH_Mesh* pMesh=GetMesh();
897 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
898 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
900 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
903 //=======================================================================
904 //function : GetIndexOnLayer
906 //=======================================================================
907 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
910 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
912 aMapIt=myConnectingMap.find(aID);
913 if (aMapIt==myConnectingMap.end()) {
914 myErrorStatus->myName = 200;
915 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
922 //=======================================================================
923 //function : MakeConnectingMap
925 //=======================================================================
926 void StdMeshers_Penta_3D::MakeConnectingMap()
930 for (j=0; j<myJSize; ++j) {
931 const StdMeshers_TNode& aBN=myTNodes[j];
932 aBNID=aBN.BaseNodeID();
933 myConnectingMap[aBNID]=j;
937 //=======================================================================
938 //function : CreateNode
940 //=======================================================================
941 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
942 const gp_XYZ& aParams,
943 StdMeshers_TNode& aTN)
949 SMDS_MeshNode* pNode=NULL;
952 // if (bIsUpperLayer) {
953 // // point on face Fxy1
954 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
955 // myBlock.Point(aParams, aS, aP);
958 // // point inside solid
959 // myBlock.Point(aParams, aP);
962 double u = aParams.X(), v = aParams.Y();
963 double u1 = ( 1. - u ), v1 = ( 1. - v );
964 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
965 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
966 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
967 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
969 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
970 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
971 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
972 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
975 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
978 // iErr=myBlock.ErrorStatus();
980 // myErrorStatus=12; // can not find the node point;
984 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
986 SMESH_Mesh* pMesh = GetMesh();
987 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
989 pNode = pMeshDS->AddNode(aX, aY, aZ);
994 //=======================================================================
995 //function : ShapeSupportID
997 //=======================================================================
998 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
999 const SMESH_Block::TShapeID aBNSSID,
1000 SMESH_Block::TShapeID& aSSID)
1003 case SMESH_Block::ID_V000:
1004 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
1006 case SMESH_Block::ID_V100:
1007 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
1009 case SMESH_Block::ID_V110:
1010 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
1012 case SMESH_Block::ID_V010:
1013 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
1015 case SMESH_Block::ID_Ex00:
1016 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
1018 case SMESH_Block::ID_Ex10:
1019 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
1021 case SMESH_Block::ID_E0y0:
1022 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
1024 case SMESH_Block::ID_E1y0:
1025 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
1027 case SMESH_Block::ID_Fxy0:
1028 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1031 aSSID=SMESH_Block::ID_NONE;
1032 myErrorStatus->myName=10; // Can not find supporting shape ID
1033 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
1038 //=======================================================================
1039 //function : MakeBlock
1041 //=======================================================================
1042 void StdMeshers_Penta_3D::MakeBlock()
1045 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1047 TopoDS_Vertex aV000, aV001;
1049 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1050 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1051 TopTools_ListIteratorOfListOfShape aIt;
1053 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1055 // 0. Find triangulated face aFTr
1056 SMDSAbs_ElementType aElementType;
1057 SMESH_Mesh* pMesh=GetMesh();
1061 for (i=1; i<=iNbF; ++i) {
1062 const TopoDS_Shape& aF = aM(i);
1063 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1065 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1066 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1067 while(itf->more()) {
1068 const SMDS_MeshElement * pElement = itf->next();
1069 aElementType = pElement->GetType();
1070 if (aElementType==SMDSAbs_Face) {
1071 iNbNodes = pElement->NbNodes();
1072 if ( iNbNodes==3 || (pElement->IsQuadratic() && iNbNodes==6) ) {
1077 // The current algorithm fails if there is more that one
1078 // face wich contains triangles ...
1079 // In that case, replace return by break to try another
1080 // method (coded in "if (iCnt != 1) { ... }")
1082 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1083 // myErrorStatus=5; // more than one face has triangulation
1095 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1096 // was not reached 'cause it was not called from Hexa_3D ... Now it
1097 // can occurs and in my opinion, it is the most common case.
1100 // The suggested algorithm is the following :
1102 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1103 // then the shape is tologically equivalent to a box
1104 // o In a box, there are three set of four // edges ...
1105 // In the cascade notation, it seems to be the edges
1110 // o For each one of this set, check if the four edges
1111 // have the same number of element.
1112 // o If so, check if the "corresponding" // faces contains
1113 // only quads. It's the faces numbered:
1117 // o If so, check if the opposite edges of each // faces
1118 // have the same number of elements. It is the edges
1120 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1121 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1122 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1123 // o If so, check if the two other faces have the same
1124 // number of elements. It is the faces numbered:
1128 // This test should be improved to test if the nodes
1129 // of the two faces are really "en face".
1130 // o If so, one of the two faces is a candidate to an extrusion,
1131 // It is the faces numbered :
1135 // o Finally, if there is only one candidate, let do the
1136 // extrusion job for the corresponding face
1140 int iNbF = aM.Extent();
1143 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1144 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1145 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1146 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1147 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1148 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1150 int has_only_quad_f1 = 1;
1151 int has_only_quad_f2 = 1;
1152 int has_only_quad_f3 = 1;
1153 int has_only_quad_f4 = 1;
1154 int has_only_quad_f5 = 1;
1155 int has_only_quad_f6 = 1;
1157 for (i=1; i<=iNbF; ++i) {
1159 const TopoDS_Shape& aF = aM(i);
1160 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1161 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1162 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1163 while(itf->more()) {
1164 const SMDS_MeshElement * pElement = itf->next();
1165 aElementType = pElement->GetType();
1166 if (aElementType==SMDSAbs_Face) {
1167 iNbNodes = pElement->NbNodes();
1168 if ( iNbNodes!=4 ) {
1174 if (i==1) has_only_quad_f1 = ok ;
1175 if (i==2) has_only_quad_f2 = ok ;
1176 if (i==3) has_only_quad_f3 = ok ;
1177 if (i==4) has_only_quad_f4 = ok ;
1178 if (i==5) has_only_quad_f5 = ok ;
1179 if (i==6) has_only_quad_f6 = ok ;
1182 TopTools_IndexedMapOfShape aE;
1183 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1184 int iNbE = aE.Extent();
1187 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1188 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1189 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1190 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1191 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1192 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1193 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1194 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1195 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1196 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1197 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1198 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1202 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1203 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1204 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1212 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1213 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1214 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1222 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1223 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1224 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1240 myErrorStatus->myName=5; // more than one face has triangulation
1241 myErrorStatus->myComment="Incorrect input mesh";
1247 // 1. Vetrices V00, V001;
1249 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1250 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1252 // 1.1 Base vertex V000
1253 iNbE = aME.Extent();
1254 if (iNbE!= NB_WALL_FACES ){
1255 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1256 myErrorStatus->myName=7; // too few edges are in base face aFTr
1257 myErrorStatus->myComment=SMESH_Comment("Not a quadrilateral face #")
1258 <<pMesh->GetMeshDS()->ShapeToIndex( aFTr )<<": "<<iNbE<<" edges" ;
1261 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1262 aV000=TopExp::FirstVertex(aE1);
1264 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1265 aIt.Initialize(aLE);
1266 for (; aIt.More(); aIt.Next()) {
1267 const TopoDS_Shape& aEx=aIt.Value();
1270 iNbEV=aMEV.Extent();
1272 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1273 myErrorStatus->myName=7; // too few edges meet in base vertex
1274 myErrorStatus->myComment=SMESH_Comment("3 edges must share vertex #")
1275 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 )<<" but there are "<<iNbEV<<" edges";
1281 for (j=1; j<=iNbEV; ++j) {
1282 const TopoDS_Shape& aEx=aMEV(j);
1283 if (!aME.Contains(aEx)) {
1284 TopoDS_Vertex aV[2];
1286 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1287 TopExp::Vertices(aE, aV[0], aV[1]);
1288 for (i=0; i<2; ++i) {
1289 if (!aV[i].IsSame(aV000)) {
1299 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1300 myErrorStatus->myName=8; // can not find reper V001
1301 myErrorStatus->myComment=SMESH_Comment("Can't find opposite vertex for vertex #")
1302 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 );
1306 //gp_Pnt aP000, aP001;
1308 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1309 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1310 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1311 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1315 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1318 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1319 myErrorStatus->myName=9; // number of shells in source shape !=1
1320 myErrorStatus->myComment=SMESH_Comment("Unexpected nb of shells ")<<iNbE;
1325 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1326 myBlock.Load(aShell, aV000, aV001);
1327 iErr = myBlock.ErrorStatus();
1329 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1330 myErrorStatus=myBlock.GetError(); // SMESHBlock: Load operation failed
1334 //=======================================================================
1335 //function : CheckData
1337 //=======================================================================
1338 void StdMeshers_Penta_3D::CheckData()
1341 int iNbEx[]={8, 12, 6};
1343 TopAbs_ShapeEnum aST;
1344 TopAbs_ShapeEnum aSTEx[]={
1345 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1347 TopTools_IndexedMapOfShape aM;
1349 if (myShape.IsNull()){
1350 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1351 myErrorStatus->myName=2; // null shape
1352 myErrorStatus->myComment="Null shape";
1356 aST=myShape.ShapeType();
1357 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1358 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1359 myErrorStatus->myName=3; // not compatible type of shape
1360 myErrorStatus->myComment=SMESH_Comment("Wrong shape type (TopAbs_ShapeEnum) ")<<aST;
1364 for (i=0; i<3; ++i) {
1366 TopExp::MapShapes(myShape, aSTEx[i], aM);
1369 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1370 myErrorStatus->myName=4; // number of subshape is not compatible
1371 myErrorStatus->myComment="Wrong number of subshapes of a block";
1377 //=======================================================================
1378 //function : LoadIJNodes
1379 //purpose : Load nodes bound to theFace into column (vectors) and rows
1381 // The value of theIJNodes map is a vector of ordered nodes so
1382 // that the 0-the one lies on theBaseEdge.
1383 // The key of theIJNodes map is a normalized parameter of each
1384 // 0-the node on theBaseEdge.
1385 //=======================================================================
1387 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1388 const TopoDS_Face& theFace,
1389 const TopoDS_Edge& theBaseEdge,
1390 SMESHDS_Mesh* theMesh)
1392 // get vertices of theBaseEdge
1393 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1394 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1395 TopExp::Vertices( eFrw, vfb, vlb );
1397 // find the other edges of theFace and orientation of e1
1398 TopoDS_Edge e1, e2, eTop;
1399 bool rev1, CumOri = false;
1400 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1402 for ( ; exp.More(); exp.Next() ) {
1403 if ( ++nbEdges > NB_WALL_FACES ) {
1404 return false; // more than 4 edges in theFace
1406 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1407 if ( theBaseEdge.IsSame( e ))
1409 TopoDS_Vertex vCommon;
1410 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1412 else if ( vCommon.IsSame( vfb )) {
1414 vft = TopExp::LastVertex( e1, CumOri );
1415 rev1 = vfb.IsSame( vft );
1417 vft = TopExp::FirstVertex( e1, CumOri );
1422 if ( nbEdges < NB_WALL_FACES ) {
1423 return false; // less than 4 edges in theFace
1426 // submeshes corresponding to shapes
1427 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1428 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1429 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1430 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1431 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1432 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1433 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1434 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1435 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1436 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1437 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1440 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1441 MESSAGE(" Diff nb of nodes on opposite edges" );
1444 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1445 MESSAGE("Empty submesh of vertex");
1448 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1449 // check quadratic case
1450 if ( myCreateQuadratic ) {
1451 int n1 = sm1->NbNodes()/2;
1452 int n2 = smb->NbNodes()/2;
1453 int n3 = sm1->NbNodes() - n1;
1454 int n4 = smb->NbNodes() - n2;
1455 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1456 if( nf != smFace->NbNodes() ) {
1457 MESSAGE( "Wrong nb face nodes: " <<
1458 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1463 MESSAGE( "Wrong nb face nodes: " <<
1464 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1469 int vsize = sm1->NbNodes() + 2;
1470 int hsize = smb->NbNodes() + 2;
1471 if(myCreateQuadratic) {
1472 vsize = vsize - sm1->NbNodes()/2 -1;
1473 hsize = hsize - smb->NbNodes()/2 -1;
1476 // load nodes from theBaseEdge
1478 set<const SMDS_MeshNode*> loadedNodes;
1479 const SMDS_MeshNode* nullNode = 0;
1481 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1482 nVecf.resize( vsize, nullNode );
1483 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1485 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1486 nVecl.resize( vsize, nullNode );
1487 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1490 BRep_Tool::Range( eFrw, f, l );
1491 double range = l - f;
1492 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1493 const SMDS_MeshNode* node;
1494 while ( nIt->more() ) {
1496 if(myTool->IsMedium(node))
1498 const SMDS_EdgePosition* pos =
1499 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1503 double u = ( pos->GetUParameter() - f ) / range;
1504 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1505 nVec.resize( vsize, nullNode );
1506 loadedNodes.insert( nVec[ 0 ] = node );
1508 if ( theIJNodes.size() != hsize ) {
1509 MESSAGE( "Wrong node positions on theBaseEdge" );
1513 // load nodes from e1
1515 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1516 nIt = sm1->GetNodes();
1517 while ( nIt->more() ) {
1519 if(myTool->IsMedium(node))
1521 const SMDS_EdgePosition* pos =
1522 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1526 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1528 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1529 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1530 int row = rev1 ? vsize - 1 : 0;
1531 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1534 loadedNodes.insert( nVecf[ row ] = u_n->second );
1537 // try to load the rest nodes
1539 // get all faces from theFace
1540 TIDSortedElemSet allFaces, foundFaces;
1541 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1542 while ( eIt->more() ) {
1543 const SMDS_MeshElement* e = eIt->next();
1544 if ( e->GetType() == SMDSAbs_Face )
1545 allFaces.insert( e );
1547 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1548 // the nodes belong to, and between the nodes of the found face,
1549 // look for a not loaded node considering this node to be the next
1550 // in a column of the starting second node. Repeat, starting
1551 // from nodes next to the previous starting nodes in their columns,
1552 // and so on while a face can be found. Then go the the next pair
1553 // of nodes on theBaseEdge.
1554 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1555 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1558 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1561 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1562 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1563 const SMDS_MeshElement* face = 0;
1565 // look for a face by 2 nodes
1566 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1568 int nbFaceNodes = face->NbNodes();
1569 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1570 (myCreateQuadratic && nbFaceNodes>8) ) {
1571 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1574 // look for a not loaded node of the <face>
1576 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1577 eIt = face->nodesIterator() ;
1578 while ( !found && eIt->more() ) {
1579 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1580 if(myTool->IsMedium(node))
1582 found = loadedNodes.insert( node ).second;
1583 if ( !found && node != n1 && node != n2 )
1587 if ( ++row > vsize - 1 ) {
1588 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1591 par_nVec_2->second[ row ] = node;
1592 foundFaces.insert( face );
1594 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1595 n1 = par_nVec_1->second[ row ];
1598 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1599 n3 == par_nVec_1->second[ row ] ) {
1603 MESSAGE( "Not quad mesh, column "<< col );
1608 while ( face && n1 && n2 );
1610 if ( row < vsize - 1 ) {
1611 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1612 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1613 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1614 MESSAGE( "Current node 1: "<< n1);
1615 MESSAGE( "Current node 2: "<< n2);
1616 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1617 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1620 } // loop on columns
1625 //////////////////////////////////////////////////////////////////////////
1627 // StdMeshers_SMESHBlock
1629 //////////////////////////////////////////////////////////////////////////
1631 //=======================================================================
1632 //function : StdMeshers_SMESHBlock
1634 //=======================================================================
1635 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1638 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1641 //=======================================================================
1642 //function : IsForwadEdge
1644 //=======================================================================
1646 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1648 int index = myTBlock.ShapeIndex( theEdgeID );
1649 if ( !myTBlock.IsEdgeID( theEdgeID ))
1652 if ( myIsEdgeForward[ index ] < 0 )
1653 myIsEdgeForward[ index ] =
1654 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1656 return myIsEdgeForward[ index ];
1659 //=======================================================================
1660 //function : ErrorStatus
1662 //=======================================================================
1663 int StdMeshers_SMESHBlock::ErrorStatus() const
1665 return myErrorStatus;
1668 //================================================================================
1670 * \brief Return problem description
1672 //================================================================================
1674 SMESH_ComputeErrorPtr StdMeshers_SMESHBlock::GetError() const
1676 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1677 string & text = err->myComment;
1678 switch ( myErrorStatus ) {
1680 case 3: text = "Internal error of StdMeshers_Penta_3D"; break;
1681 case 4: text = "Can't compute normalized parameters of a point inside a block"; break;
1682 case 5: text = "Can't compute coordinates by normalized parameters inside a block"; break;
1683 case 6: text = "Can't detect block subshapes. Not a block?"; break;
1686 err->myName = myErrorStatus;
1690 //=======================================================================
1693 //=======================================================================
1694 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1696 TopoDS_Vertex aV000, aV001;
1698 Load(theShell, aV000, aV001);
1701 //=======================================================================
1704 //=======================================================================
1705 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1706 const TopoDS_Vertex& theV000,
1707 const TopoDS_Vertex& theV001)
1715 myShapeIDMap.Clear();
1716 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1723 //=======================================================================
1724 //function : ComputeParameters
1726 //=======================================================================
1727 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1730 ComputeParameters(thePnt, myShell, theXYZ);
1733 //=======================================================================
1734 //function : ComputeParameters
1736 //=======================================================================
1737 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1738 const TopoDS_Shape& theShape,
1746 aID = ShapeID(theShape);
1747 if (myErrorStatus) {
1750 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1752 myErrorStatus=4; // problems with computation Parameters
1757 //=======================================================================
1758 //function : ComputeParameters
1760 //=======================================================================
1762 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1763 const TopoDS_Shape& theShape,
1771 aID = ShapeID(theShape);
1772 if (myErrorStatus) {
1775 if ( SMESH_Block::IsEdgeID( aID ))
1776 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1778 myErrorStatus=4; // problems with computation Parameters
1783 //=======================================================================
1786 //=======================================================================
1787 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1792 Point(theParams, aS, aP3D);
1795 //=======================================================================
1798 //=======================================================================
1799 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1800 const TopoDS_Shape& theShape,
1807 gp_XYZ aXYZ(99.,99.,99.);
1810 if (theShape.IsNull()) {
1811 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1815 aID=ShapeID(theShape);
1816 if (myErrorStatus) {
1820 if (SMESH_Block::IsVertexID(aID)) {
1821 bOk = myTBlock.VertexPoint(aID, aXYZ);
1823 else if (SMESH_Block::IsEdgeID(aID)) {
1824 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1827 else if (SMESH_Block::IsFaceID(aID)) {
1828 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1832 myErrorStatus=5; // problems with point computation
1838 //=======================================================================
1839 //function : ShapeID
1841 //=======================================================================
1842 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1847 TopoDS_Shape aSF, aSR;
1850 aSF.Orientation(TopAbs_FORWARD);
1852 aSR.Orientation(TopAbs_REVERSED);
1854 if (myShapeIDMap.Contains(aSF)) {
1855 aID=myShapeIDMap.FindIndex(aSF);
1858 if (myShapeIDMap.Contains(aSR)) {
1859 aID=myShapeIDMap.FindIndex(aSR);
1862 myErrorStatus=2; // unknown shape;
1866 //=======================================================================
1869 //=======================================================================
1870 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1876 aNb=myShapeIDMap.Extent();
1877 if (theID<1 || theID>aNb) {
1878 myErrorStatus=3; // ID is out of range
1879 return myEmptyShape;
1882 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);
1887 //=======================================================================
1888 //function : Evaluate
1890 //=======================================================================
1891 bool StdMeshers_Penta_3D::Evaluate(SMESH_Mesh& aMesh,
1892 const TopoDS_Shape& aShape,
1893 MapShapeNbElems& aResMap)
1895 MESSAGE("StdMeshers_Penta_3D::Evaluate()");
1897 // find face contains only triangles
1898 vector < SMESH_subMesh * >meshFaces;
1899 TopTools_SequenceOfShape aFaces;
1900 int NumBase = 0, i = 0;
1901 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
1903 aFaces.Append(exp.Current());
1904 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
1905 meshFaces.push_back(aSubMesh);
1906 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i]);
1907 if( anIt == aResMap.end() ) {
1911 std::vector<int> aVec = (*anIt).second;
1912 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1913 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1914 if( nbtri>0 && nbqua==0 ) {
1920 std::vector<int> aResVec(SMDSEntity_Last);
1921 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1922 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1923 aResMap.insert(std::make_pair(sm,aResVec));
1924 myErrorStatus->myName = COMPERR_ALGO_FAILED;
1925 myErrorStatus->myComment = "Submesh can not be evaluated";
1929 // find number of 1d elems for base face
1931 TopTools_MapOfShape Edges1;
1932 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1933 Edges1.Add(exp.Current());
1934 SMESH_subMesh *sm = aMesh.GetSubMesh(exp.Current());
1936 MapShapeNbElemsItr anIt = aResMap.find(sm);
1937 if( anIt == aResMap.end() ) continue;
1938 std::vector<int> aVec = (*anIt).second;
1939 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1942 // find face opposite to base face
1944 for(i=1; i<=6; i++) {
1945 if(i==NumBase) continue;
1946 bool IsOpposite = true;
1947 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1948 if( Edges1.Contains(exp.Current()) ) {
1958 // find number of 2d elems on side faces
1960 for(i=1; i<=6; i++) {
1961 if( i==OppNum || i==NumBase ) continue;
1962 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1963 if( anIt == aResMap.end() ) continue;
1964 std::vector<int> aVec = (*anIt).second;
1965 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1968 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1969 std::vector<int> aVec = (*anIt).second;
1970 int nb2d_face0 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1971 int nb0d_face0 = aVec[SMDSEntity_Node];
1973 anIt = aResMap.find( meshFaces[OppNum-1] );
1974 for(i=SMDSEntity_Node; i<SMDSEntity_Last; i++)
1975 (*anIt).second[i] = aVec[i];
1977 SMESH_MesherHelper aTool (aMesh);
1978 bool _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
1980 std::vector<int> aResVec(SMDSEntity_Last);
1981 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1982 if(_quadraticMesh) {
1983 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0 * ( nb2d/nb1d );
1984 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 );
1987 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1988 aResVec[SMDSEntity_Penta] = nb2d_face0 * ( nb2d/nb1d );
1990 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1991 aResMap.insert(std::make_pair(sm,aResVec));