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>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Shell.hxx>
52 #include <TopoDS_Vertex.hxx>
60 typedef map < int, int, less<int> >::iterator \
61 StdMeshers_IteratorOfDataMapOfIntegerInteger;
63 enum { NB_WALL_FACES = 4 };
65 //=======================================================================
66 //function : StdMeshers_Penta_3D
68 //=======================================================================
69 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
70 : myErrorStatus(SMESH_ComputeError::New())
73 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
74 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
78 //=======================================================================
79 //function : ~StdMeshers_Penta_3D
81 //=======================================================================
83 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
87 //=======================================================================
90 //=======================================================================
91 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
92 const TopoDS_Shape& aShape)
94 MESSAGE("StdMeshers_Penta_3D::Compute()");
102 if (!myErrorStatus->IsOK()) {
108 if (!myErrorStatus->IsOK()) {
113 if (!myErrorStatus->IsOK()) {
117 // now unnecessary faces removed, we can load medium nodes
118 SMESH_MesherHelper helper(aMesh);
120 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
124 if (!myErrorStatus->IsOK()) {
131 if (!myErrorStatus->IsOK()) {
140 //=======================================================================
141 //function : MakeNodes
143 //=======================================================================
144 void StdMeshers_Penta_3D::MakeNodes()
147 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
149 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
150 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
151 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
152 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
153 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
157 SMESH_Mesh* pMesh=GetMesh();
159 // 1. Define the sizes of mesh
161 // 1.1 Horizontal size
163 for (i=0; i<aNbSIDs; ++i) {
164 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
165 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
167 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
168 if(!myCreateQuadratic) {
169 iNbN = aSM->NbNodes();
173 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
175 const SMDS_MeshNode* aNode = itn->next();
176 if(myTool->IsMedium(aNode))
183 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
188 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
189 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
191 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
192 if(!myCreateQuadratic) {
193 iNbN = aSM->NbNodes();
197 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
199 const SMDS_MeshNode* aNode = itn->next();
200 if(myTool->IsMedium(aNode))
207 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
209 aSize=myISize*myJSize;
210 myTNodes.resize(aSize);
212 StdMeshers_TNode aTNode;
216 // 2. Fill the repers on base face (Z=0)
219 for (k=0; k<aNbSIDs; ++k) {
221 const TopoDS_Shape& aS = myBlock.Shape(aSID);
222 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
224 const SMDS_MeshNode* aNode = ite->next();
225 if(myTool->IsMedium(aNode))
227 aNodeID=aNode->GetID();
229 aTNode.SetNode(aNode);
230 aTNode.SetShapeSupportID(aSID);
231 aTNode.SetBaseNodeID(aNodeID);
233 if ( SMESH_Block::IsEdgeID (aSID)) {
234 const SMDS_EdgePosition* epos =
235 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
236 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
242 aP3D.SetCoord(aX, aY, aZ);
243 myBlock.ComputeParameters(aP3D, aS, aCoords);
245 iErr = myBlock.ErrorStatus();
247 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
248 "SMESHBlock: ComputeParameters operation failed");
249 myErrorStatus=myBlock.GetError();
252 aTNode.SetNormCoord(aCoords);
259 // 3.1 Fill maps of wall nodes
260 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
261 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
262 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
264 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
265 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
266 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
268 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
269 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
270 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
271 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
272 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
275 myErrorStatus->myName = COMPERR_BAD_INPUT_MESH;
276 myErrorStatus->myComment = SMESH_Comment() <<
277 "Can't find regular quadrangle mesh on a side face #" <<
278 pMesh->GetMeshDS()->ShapeToIndex( myBlock.Shape( wallFaceID[ i ]));
283 // 3.2 find node columns for vertical edges and edge IDs
284 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
285 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
286 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
288 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
289 ShapeSupportID(false, vID, eID);
290 verticEdgeID[ i ] = eID;
292 StdMeshers_TNode& aTNode = myTNodes[ i ];
293 verticEdgeNodes[ i ] = 0;
294 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
295 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
296 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
297 if ( ijNodes.begin()->second[0] == aTNode.Node() )
298 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
299 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
300 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
301 if ( verticEdgeNodes[ i ] )
306 // 3.3 set XYZ of vertices, and initialize of the rest
307 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
308 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
309 if ( SMESH_Block::IsVertexID( id )) {
310 TopoDS_Shape V = myBlock.Shape( id );
311 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
312 const SMDS_MeshNode* n = sm->GetNodes()->next();
313 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
316 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
320 // 4. Fill the rest repers
323 SMESH_Block::TShapeID aSSID, aBNSSID;
324 StdMeshers_TNode aTN;
327 // create top face and find UV for it's corners
328 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
329 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
330 int topfaceID = meshDS->ShapeToIndex(TopFace);
331 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
332 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
333 const SMDS_MeshNode* N = itn->next();
334 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
335 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
336 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
338 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
339 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
340 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
342 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
343 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
344 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
346 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
348 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
350 const StdMeshers_TNode& aBN = myTNodes[j];
351 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
352 iBNID = aBN.BaseNodeID();
353 const gp_XYZ& aBNXYZ = aBN.NormCoord();
354 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
356 // set XYZ on horizontal edges and get node columns of faces:
357 // 2 columns for each face, between which a base node is located
358 vector<const SMDS_MeshNode*>* nColumns[8];
359 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
361 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
362 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
363 nColumns[k*2], nColumns[k*2+1]);
367 // XYZ on the bottom and top faces
368 const SMDS_MeshNode* n = aBN.Node();
369 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
370 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
372 // first create or find a top node, then the rest ones in a column
373 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
375 bIsUpperLayer = (i==(myISize-1));
376 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
377 if ( createNode ) // a base node is inside a top face
379 // set XYZ on vertical edges and faces
380 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
381 // XYZ on a vertical edge
382 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
383 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
384 // XYZ on a face (part 1 from one column)
385 n = (*nColumns[k*2]) [ i ];
386 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
387 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
389 if( bIsUpperLayer ) {
390 tmp1 = myTool->GetNodeUV(TopFace,n);
391 tmp1 = ( 1. - ratio[ k ]) * tmp1;
393 // XYZ on a face (part 2 from other column)
394 n = (*nColumns[k*2+1]) [ i ];
395 xyz.SetCoord( n->X(), n->Y(), n->Z() );
396 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
397 if( bIsUpperLayer ) {
398 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
399 tmp1 += ratio[ k ] * tmp2;
411 // fill current node info
414 // -normalized coordinates
418 aZ=(double)i/(double)(myISize-1);
419 aCoords.SetCoord(aX, aY, aZ);
421 // suporting shape ID
422 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
423 if (!myErrorStatus->IsOK()) {
424 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
428 aTN.SetShapeSupportID(aSSID);
429 aTN.SetNormCoord(aCoords);
430 aTN.SetBaseNodeID(iBNID);
432 if (aSSID!=SMESH_Block::ID_NONE){
433 // try to find the node
434 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
435 FindNodeOnShape(aS, aCoords, i, aTN);
438 // create node and get it id
439 CreateNode (bIsUpperLayer, aCoords, aTN);
441 if ( bIsUpperLayer ) {
442 const SMDS_MeshNode* n = aTN.Node();
443 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
444 // set node on top face:
445 // find UV parameter for this node
447 // UV011+-----+----------+UV111
450 // UV_E0y1+ +node +UV_E1y1
454 // UV001+-----+----------+UV101
457 double u = aCoords.X(), v = aCoords.Y();
458 double u1 = ( 1. - u ), v1 = ( 1. - v );
459 aP.ChangeCoord() = UV_Ex01 * v1;
460 aP.ChangeCoord() += UV_Ex11 * v;
461 aP.ChangeCoord() += UV_E0y1 * u1;
462 aP.ChangeCoord() += UV_E1y1 * u;
463 aP.ChangeCoord() -= UV001 * u1 * v1;
464 aP.ChangeCoord() -= UV101 * u * v1;
465 aP.ChangeCoord() -= UV011 * u1 * v;
466 aP.ChangeCoord() -= UV111 * u * v;
467 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
470 if (!myErrorStatus->IsOK()) {
471 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
481 int iSSID, iBNID, aID;
483 for (i=0; i<myISize; ++i) {
484 printf(" Layer# %d\n", i);
485 for (j=0; j<myJSize; ++j) {
487 const StdMeshers_TNode& aTN=myTNodes[ij];
488 //const StdMeshers_TNode& aTN=aTNodes[ij];
489 const gp_XYZ& aXYZ=aTN.NormCoord();
490 iSSID=aTN.ShapeSupportID();
491 iBNID=aTN.BaseNodeID();
493 const SMDS_MeshNode* aNode=aTN.Node();
498 printf("*** j:%d BNID#%d iSSID:%d ID:%d { %lf %lf %lf }, { %lf %lf %lf }\n",
499 j, iBNID, iSSID, aID, aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aX, aY, aZ);
508 //=======================================================================
509 //function : FindNodeOnShape
511 //=======================================================================
513 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
514 const gp_XYZ& aParams,
516 StdMeshers_TNode& aTN)
518 double aX, aY, aZ, aD, aTol2, minD;
521 SMESH_Mesh* pMesh = GetMesh();
522 aTol2 = myTol3D*myTol3D;
524 SMDS_MeshNode* pNode = NULL;
526 if ( aS.ShapeType() == TopAbs_FACE ||
527 aS.ShapeType() == TopAbs_EDGE ) {
528 // find a face ID to which aTN belongs to
530 if ( aS.ShapeType() == TopAbs_FACE )
531 faceID = myBlock.ShapeID( aS );
532 else { // edge maybe vertical or top horizontal
533 gp_XYZ aCoord = aParams;
534 if ( aCoord.Z() == 1. )
535 aCoord.SetZ( 0.5 ); // move from top down
537 aCoord.SetX( 0.5 ); // move along X
538 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
540 ASSERT( SMESH_Block::IsFaceID( faceID ));
541 int fIndex = SMESH_Block::ShapeIndex( faceID );
542 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
543 // look for a base node in ijNodes
544 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
545 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
546 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
547 if ( par_nVec->second[ 0 ] == baseNode ) {
548 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
554 myBlock.Point(aParams, aS, aP1);
556 SMDS_NodeIteratorPtr ite=
557 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
559 const SMDS_MeshNode* aNode = ite->next();
560 if(myTool->IsMedium(aNode))
565 aP2.SetCoord(aX, aY, aZ);
566 aD=(double)aP1.SquareDistance(aP2);
567 //printf("** D=%lf ", aD, aTol2);
569 pNode=(SMDS_MeshNode*)aNode;
579 //aTN.SetNode(pNode);
580 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
581 //myErrorStatus=11; // can not find the node;
585 //=======================================================================
586 //function : SetHorizEdgeXYZ
588 //=======================================================================
590 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
592 vector<const SMDS_MeshNode*>*& aCol1,
593 vector<const SMDS_MeshNode*>*& aCol2)
595 // find base and top edges of the face
596 enum { BASE = 0, TOP };
597 vector< int > edgeVec; // 0-base, 1-top
598 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
600 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
601 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
603 double param = aBaseNodeParams.Coord( coord );
607 // look for columns around param
608 StdMeshers_IJNodeMap & ijNodes =
609 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
610 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
611 while ( par_nVec_1->first < param )
613 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
616 if ( par_nVec_1 != ijNodes.begin() ) {
618 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
620 aCol1 = & par_nVec_1->second;
621 aCol2 = & par_nVec_2->second;
625 // this variant is better for cases with curved edges and
626 // different nodes distribution on top and base edges
627 const SMDS_MeshNode* n1 = aCol1->back();
628 const SMDS_MeshNode* n2 = aCol2->back();
629 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
630 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
631 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
634 // this variant is better for other cases
635 // SMESH_MesherHelper helper( *GetMesh() );
636 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
637 // double u1 = helper.GetNodeU( edge, n1 );
638 // double u2 = helper.GetNodeU( edge, n2 );
639 // double u = ( 1. - r ) * u1 + r * u2;
640 // gp_XYZ topNodeParams;
641 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
642 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
644 // myShapeXYZ[ edgeVec[ TOP ]]);
648 myBlock.Block().EdgePoint( edgeVec[ BASE ],
650 myShapeXYZ[ edgeVec[ BASE ]]);
655 //=======================================================================
656 //function : MakeVolumeMesh
658 //=======================================================================
659 void StdMeshers_Penta_3D::MakeVolumeMesh()
661 int i, j, ij, ik, i1, i2, aSSID;
663 SMESH_Mesh* pMesh = GetMesh();
664 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
666 int shapeID = meshDS->ShapeToIndex( myShape );
668 // 1. Set Node In Volume
670 for (i=1; i<ik; ++i){
671 for (j=0; j<myJSize; ++j){
673 const StdMeshers_TNode& aTN = myTNodes[ij];
674 aSSID=aTN.ShapeSupportID();
675 if (aSSID==SMESH_Block::ID_NONE) {
676 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
677 meshDS->SetNodeInVolume(aNode, shapeID);
682 // 2. Make pentahedrons
684 vector<const SMDS_MeshNode*> aN;
686 SMDS_ElemIteratorPtr itf, aItNodes;
688 const TopoDS_Face& aFxy0=
689 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
690 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
691 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
693 itf = aSM0->GetElements();
695 const SMDS_MeshElement* pE0 = itf->next();
697 int nbFaceNodes = pE0->NbNodes();
698 if(myCreateQuadratic)
699 nbFaceNodes = nbFaceNodes/2;
700 if ( aN.size() < nbFaceNodes * 2 )
701 aN.resize( nbFaceNodes * 2 );
704 aItNodes=pE0->nodesIterator();
705 while (aItNodes->more()) {
706 //const SMDS_MeshElement* pNode = aItNodes->next();
707 const SMDS_MeshNode* pNode =
708 static_cast<const SMDS_MeshNode*> (aItNodes->next());
709 if(myTool->IsMedium(pNode))
711 aID0 = pNode->GetID();
712 aJ[k] = GetIndexOnLayer(aID0);
713 if (!myErrorStatus->IsOK()) {
714 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
722 for (i=0; i<ik; ++i) {
725 for(j=0; j<nbFaceNodes; ++j) {
726 ij = i1*myJSize+aJ[j];
727 const StdMeshers_TNode& aTN1 = myTNodes[ij];
728 const SMDS_MeshNode* aN1 = aTN1.Node();
732 const StdMeshers_TNode& aTN2 = myTNodes[ij];
733 const SMDS_MeshNode* aN2 = aTN2.Node();
734 aN[j+nbFaceNodes] = aN2;
736 // check if volume orientation will be ok
738 SMDS_VolumeTool vTool;
739 switch ( nbFaceNodes ) {
741 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
742 aN[3], aN[4], aN[5]);
743 vTool.Set( &tmpVol );
747 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
748 aN[4], aN[5], aN[6], aN[7]);
749 vTool.Set( &tmpVol );
755 forward = vTool.IsForward();
758 SMDS_MeshVolume* aV = 0;
759 switch ( nbFaceNodes ) {
762 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
763 // aN[3], aN[4], aN[5]);
764 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
767 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
768 // aN[3], aN[5], aN[4]);
769 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
774 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
775 // aN[4], aN[5], aN[6], aN[7]);
776 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
777 aN[4], aN[5], aN[6], aN[7]);
780 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
781 // aN[4], aN[7], aN[6], aN[5]);
782 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
783 aN[4], aN[7], aN[6], aN[5]);
789 meshDS->SetMeshElementOnShape(aV, shapeID);
794 //=======================================================================
795 //function : MakeMeshOnFxy1
797 //=======================================================================
798 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
800 int aID0, aJ, aLevel, ij, aNbNodes, k;
802 SMDS_NodeIteratorPtr itn;
803 SMDS_ElemIteratorPtr itf, aItNodes;
804 SMDSAbs_ElementType aElementType;
806 const TopoDS_Face& aFxy0=
807 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
808 const TopoDS_Face& aFxy1=
809 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
811 SMESH_Mesh* pMesh = GetMesh();
812 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
814 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
815 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
816 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
818 // set nodes on aFxy1
820 itn = aSM0->GetNodes();
821 aNbNodes = aSM0->NbNodes();
822 //printf("** aNbNodes=%d\n", aNbNodes);
825 // set elements on aFxy1
826 vector<const SMDS_MeshNode*> aNodes1;
828 itf = aSM0->GetElements();
830 const SMDS_MeshElement* pE0 = itf->next();
831 aElementType = pE0->GetType();
832 if (!aElementType==SMDSAbs_Face) {
835 aNbNodes = pE0->NbNodes();
836 if(myCreateQuadratic)
837 aNbNodes = aNbNodes/2;
838 if ( aNodes1.size() < aNbNodes )
839 aNodes1.resize( aNbNodes );
841 k = aNbNodes-1; // reverse a face
842 aItNodes = pE0->nodesIterator();
843 while (aItNodes->more()) {
844 const SMDS_MeshNode* pNode =
845 static_cast<const SMDS_MeshNode*> (aItNodes->next());
846 if(myTool->IsMedium(pNode))
848 aID0 = pNode->GetID();
849 aJ = GetIndexOnLayer(aID0);
850 if (!myErrorStatus->IsOK()) {
851 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
855 ij = aLevel*myJSize + aJ;
856 const StdMeshers_TNode& aTN1 = myTNodes[ij];
857 const SMDS_MeshNode* aN1 = aTN1.Node();
861 SMDS_MeshFace * face = 0;
862 switch ( aNbNodes ) {
864 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
867 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
872 meshDS->SetMeshElementOnShape(face, aFxy1);
875 // update compute state of top face submesh
876 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
878 // assure that mesh on the top face will be cleaned when it is cleaned
879 // on the bottom face
880 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
881 volSM->SetEventListener( new SMESH_subMeshEventListener(true),
882 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
883 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
886 //=======================================================================
887 //function : ClearMeshOnFxy1
889 //=======================================================================
890 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
892 SMESH_subMesh* aSubMesh;
893 SMESH_Mesh* pMesh=GetMesh();
895 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
896 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
898 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
901 //=======================================================================
902 //function : GetIndexOnLayer
904 //=======================================================================
905 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
908 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
910 aMapIt=myConnectingMap.find(aID);
911 if (aMapIt==myConnectingMap.end()) {
912 myErrorStatus->myName = 200;
913 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
920 //=======================================================================
921 //function : MakeConnectingMap
923 //=======================================================================
924 void StdMeshers_Penta_3D::MakeConnectingMap()
928 for (j=0; j<myJSize; ++j) {
929 const StdMeshers_TNode& aBN=myTNodes[j];
930 aBNID=aBN.BaseNodeID();
931 myConnectingMap[aBNID]=j;
935 //=======================================================================
936 //function : CreateNode
938 //=======================================================================
939 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
940 const gp_XYZ& aParams,
941 StdMeshers_TNode& aTN)
947 SMDS_MeshNode* pNode=NULL;
950 // if (bIsUpperLayer) {
951 // // point on face Fxy1
952 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
953 // myBlock.Point(aParams, aS, aP);
956 // // point inside solid
957 // myBlock.Point(aParams, aP);
960 double u = aParams.X(), v = aParams.Y();
961 double u1 = ( 1. - u ), v1 = ( 1. - v );
962 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
963 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
964 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
965 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
967 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
968 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
969 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
970 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
973 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
976 // iErr=myBlock.ErrorStatus();
978 // myErrorStatus=12; // can not find the node point;
982 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
984 SMESH_Mesh* pMesh = GetMesh();
985 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
987 pNode = pMeshDS->AddNode(aX, aY, aZ);
992 //=======================================================================
993 //function : ShapeSupportID
995 //=======================================================================
996 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
997 const SMESH_Block::TShapeID aBNSSID,
998 SMESH_Block::TShapeID& aSSID)
1001 case SMESH_Block::ID_V000:
1002 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
1004 case SMESH_Block::ID_V100:
1005 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
1007 case SMESH_Block::ID_V110:
1008 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
1010 case SMESH_Block::ID_V010:
1011 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
1013 case SMESH_Block::ID_Ex00:
1014 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
1016 case SMESH_Block::ID_Ex10:
1017 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
1019 case SMESH_Block::ID_E0y0:
1020 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
1022 case SMESH_Block::ID_E1y0:
1023 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
1025 case SMESH_Block::ID_Fxy0:
1026 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1029 aSSID=SMESH_Block::ID_NONE;
1030 myErrorStatus->myName=10; // Can not find supporting shape ID
1031 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
1036 //=======================================================================
1037 //function : MakeBlock
1039 //=======================================================================
1040 void StdMeshers_Penta_3D::MakeBlock()
1043 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1045 TopoDS_Vertex aV000, aV001;
1047 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1048 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1049 TopTools_ListIteratorOfListOfShape aIt;
1051 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1053 // 0. Find triangulated face aFTr
1054 SMDSAbs_ElementType aElementType;
1055 SMESH_Mesh* pMesh=GetMesh();
1059 for (i=1; i<=iNbF; ++i) {
1060 const TopoDS_Shape& aF = aM(i);
1061 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1063 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1064 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1065 while(itf->more()) {
1066 const SMDS_MeshElement * pElement = itf->next();
1067 aElementType = pElement->GetType();
1068 if (aElementType==SMDSAbs_Face) {
1069 iNbNodes = pElement->NbNodes();
1070 if ( iNbNodes==3 || (pElement->IsQuadratic() && iNbNodes==6) ) {
1075 // The current algorithm fails if there is more that one
1076 // face wich contains triangles ...
1077 // In that case, replace return by break to try another
1078 // method (coded in "if (iCnt != 1) { ... }")
1080 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1081 // myErrorStatus=5; // more than one face has triangulation
1093 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1094 // was not reached 'cause it was not called from Hexa_3D ... Now it
1095 // can occurs and in my opinion, it is the most common case.
1098 // The suggested algorithm is the following :
1100 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1101 // then the shape is tologically equivalent to a box
1102 // o In a box, there are three set of four // edges ...
1103 // In the cascade notation, it seems to be the edges
1108 // o For each one of this set, check if the four edges
1109 // have the same number of element.
1110 // o If so, check if the "corresponding" // faces contains
1111 // only quads. It's the faces numbered:
1115 // o If so, check if the opposite edges of each // faces
1116 // have the same number of elements. It is the edges
1118 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1119 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1120 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1121 // o If so, check if the two other faces have the same
1122 // number of elements. It is the faces numbered:
1126 // This test should be improved to test if the nodes
1127 // of the two faces are really "en face".
1128 // o If so, one of the two faces is a candidate to an extrusion,
1129 // It is the faces numbered :
1133 // o Finally, if there is only one candidate, let do the
1134 // extrusion job for the corresponding face
1138 int iNbF = aM.Extent();
1141 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1142 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1143 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1144 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1145 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1146 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1148 int has_only_quad_f1 = 1;
1149 int has_only_quad_f2 = 1;
1150 int has_only_quad_f3 = 1;
1151 int has_only_quad_f4 = 1;
1152 int has_only_quad_f5 = 1;
1153 int has_only_quad_f6 = 1;
1155 for (i=1; i<=iNbF; ++i) {
1157 const TopoDS_Shape& aF = aM(i);
1158 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1159 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1160 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1161 while(itf->more()) {
1162 const SMDS_MeshElement * pElement = itf->next();
1163 aElementType = pElement->GetType();
1164 if (aElementType==SMDSAbs_Face) {
1165 iNbNodes = pElement->NbNodes();
1166 if ( iNbNodes!=4 ) {
1172 if (i==1) has_only_quad_f1 = ok ;
1173 if (i==2) has_only_quad_f2 = ok ;
1174 if (i==3) has_only_quad_f3 = ok ;
1175 if (i==4) has_only_quad_f4 = ok ;
1176 if (i==5) has_only_quad_f5 = ok ;
1177 if (i==6) has_only_quad_f6 = ok ;
1180 TopTools_IndexedMapOfShape aE;
1181 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1182 int iNbE = aE.Extent();
1185 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1186 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1187 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1188 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1189 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1190 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1191 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1192 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1193 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1194 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1195 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1196 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1200 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1201 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1202 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1210 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1211 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1212 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1220 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1221 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1222 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1238 myErrorStatus->myName=5; // more than one face has triangulation
1239 myErrorStatus->myComment="Incorrect input mesh";
1245 // 1. Vetrices V00, V001;
1247 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1248 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1250 // 1.1 Base vertex V000
1251 iNbE = aME.Extent();
1252 if (iNbE!= NB_WALL_FACES ){
1253 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1254 myErrorStatus->myName=7; // too few edges are in base face aFTr
1255 myErrorStatus->myComment=SMESH_Comment("Not a quadrilateral face #")
1256 <<pMesh->GetMeshDS()->ShapeToIndex( aFTr )<<": "<<iNbE<<" edges" ;
1259 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1260 aV000=TopExp::FirstVertex(aE1);
1262 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1263 aIt.Initialize(aLE);
1264 for (; aIt.More(); aIt.Next()) {
1265 const TopoDS_Shape& aEx=aIt.Value();
1268 iNbEV=aMEV.Extent();
1270 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1271 myErrorStatus->myName=7; // too few edges meet in base vertex
1272 myErrorStatus->myComment=SMESH_Comment("3 edges must share vertex #")
1273 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 )<<" but there are "<<iNbEV<<" edges";
1279 for (j=1; j<=iNbEV; ++j) {
1280 const TopoDS_Shape& aEx=aMEV(j);
1281 if (!aME.Contains(aEx)) {
1282 TopoDS_Vertex aV[2];
1284 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1285 TopExp::Vertices(aE, aV[0], aV[1]);
1286 for (i=0; i<2; ++i) {
1287 if (!aV[i].IsSame(aV000)) {
1297 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1298 myErrorStatus->myName=8; // can not find reper V001
1299 myErrorStatus->myComment=SMESH_Comment("Can't find opposite vertex for vertex #")
1300 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 );
1304 //gp_Pnt aP000, aP001;
1306 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1307 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1308 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1309 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1313 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1316 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1317 myErrorStatus->myName=9; // number of shells in source shape !=1
1318 myErrorStatus->myComment=SMESH_Comment("Unexpected nb of shells ")<<iNbE;
1323 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1324 myBlock.Load(aShell, aV000, aV001);
1325 iErr = myBlock.ErrorStatus();
1327 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1328 myErrorStatus=myBlock.GetError(); // SMESHBlock: Load operation failed
1332 //=======================================================================
1333 //function : CheckData
1335 //=======================================================================
1336 void StdMeshers_Penta_3D::CheckData()
1339 int iNbEx[]={8, 12, 6};
1341 TopAbs_ShapeEnum aST;
1342 TopAbs_ShapeEnum aSTEx[]={
1343 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1345 TopTools_IndexedMapOfShape aM;
1347 if (myShape.IsNull()){
1348 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1349 myErrorStatus->myName=2; // null shape
1350 myErrorStatus->myComment="Null shape";
1354 aST=myShape.ShapeType();
1355 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1356 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1357 myErrorStatus->myName=3; // not compatible type of shape
1358 myErrorStatus->myComment=SMESH_Comment("Wrong shape type (TopAbs_ShapeEnum) ")<<aST;
1362 for (i=0; i<3; ++i) {
1364 TopExp::MapShapes(myShape, aSTEx[i], aM);
1367 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1368 myErrorStatus->myName=4; // number of subshape is not compatible
1369 myErrorStatus->myComment="Wrong number of subshapes of a block";
1375 //=======================================================================
1376 //function : LoadIJNodes
1377 //purpose : Load nodes bound to theFace into column (vectors) and rows
1379 // The value of theIJNodes map is a vector of ordered nodes so
1380 // that the 0-the one lies on theBaseEdge.
1381 // The key of theIJNodes map is a normalized parameter of each
1382 // 0-the node on theBaseEdge.
1383 //=======================================================================
1385 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1386 const TopoDS_Face& theFace,
1387 const TopoDS_Edge& theBaseEdge,
1388 SMESHDS_Mesh* theMesh)
1390 // get vertices of theBaseEdge
1391 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1392 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1393 TopExp::Vertices( eFrw, vfb, vlb );
1395 // find the other edges of theFace and orientation of e1
1396 TopoDS_Edge e1, e2, eTop;
1397 bool rev1, CumOri = false;
1398 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1400 for ( ; exp.More(); exp.Next() ) {
1401 if ( ++nbEdges > NB_WALL_FACES ) {
1402 return false; // more than 4 edges in theFace
1404 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1405 if ( theBaseEdge.IsSame( e ))
1407 TopoDS_Vertex vCommon;
1408 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1410 else if ( vCommon.IsSame( vfb )) {
1412 vft = TopExp::LastVertex( e1, CumOri );
1413 rev1 = vfb.IsSame( vft );
1415 vft = TopExp::FirstVertex( e1, CumOri );
1420 if ( nbEdges < NB_WALL_FACES ) {
1421 return false; // less than 4 edges in theFace
1424 // submeshes corresponding to shapes
1425 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1426 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1427 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1428 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1429 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1430 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1431 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1432 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1433 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1434 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1435 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1438 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1439 MESSAGE(" Diff nb of nodes on opposite edges" );
1442 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1443 MESSAGE("Empty submesh of vertex");
1446 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1447 // check quadratic case
1448 if ( myCreateQuadratic ) {
1449 int n1 = sm1->NbNodes()/2;
1450 int n2 = smb->NbNodes()/2;
1451 int n3 = sm1->NbNodes() - n1;
1452 int n4 = smb->NbNodes() - n2;
1453 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1454 if( nf != smFace->NbNodes() ) {
1455 MESSAGE( "Wrong nb face nodes: " <<
1456 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1461 MESSAGE( "Wrong nb face nodes: " <<
1462 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1467 int vsize = sm1->NbNodes() + 2;
1468 int hsize = smb->NbNodes() + 2;
1469 if(myCreateQuadratic) {
1470 vsize = vsize - sm1->NbNodes()/2 -1;
1471 hsize = hsize - smb->NbNodes()/2 -1;
1474 // load nodes from theBaseEdge
1476 set<const SMDS_MeshNode*> loadedNodes;
1477 const SMDS_MeshNode* nullNode = 0;
1479 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1480 nVecf.resize( vsize, nullNode );
1481 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1483 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1484 nVecl.resize( vsize, nullNode );
1485 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1488 BRep_Tool::Range( eFrw, f, l );
1489 double range = l - f;
1490 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1491 const SMDS_MeshNode* node;
1492 while ( nIt->more() ) {
1494 if(myTool->IsMedium(node))
1496 const SMDS_EdgePosition* pos =
1497 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1501 double u = ( pos->GetUParameter() - f ) / range;
1502 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1503 nVec.resize( vsize, nullNode );
1504 loadedNodes.insert( nVec[ 0 ] = node );
1506 if ( theIJNodes.size() != hsize ) {
1507 MESSAGE( "Wrong node positions on theBaseEdge" );
1511 // load nodes from e1
1513 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1514 nIt = sm1->GetNodes();
1515 while ( nIt->more() ) {
1517 if(myTool->IsMedium(node))
1519 const SMDS_EdgePosition* pos =
1520 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1524 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1526 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1527 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1528 int row = rev1 ? vsize - 1 : 0;
1529 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1532 loadedNodes.insert( nVecf[ row ] = u_n->second );
1535 // try to load the rest nodes
1537 // get all faces from theFace
1538 TIDSortedElemSet allFaces, foundFaces;
1539 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1540 while ( eIt->more() ) {
1541 const SMDS_MeshElement* e = eIt->next();
1542 if ( e->GetType() == SMDSAbs_Face )
1543 allFaces.insert( e );
1545 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1546 // the nodes belong to, and between the nodes of the found face,
1547 // look for a not loaded node considering this node to be the next
1548 // in a column of the starting second node. Repeat, starting
1549 // from nodes next to the previous starting nodes in their columns,
1550 // and so on while a face can be found. Then go the the next pair
1551 // of nodes on theBaseEdge.
1552 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1553 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1556 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1559 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1560 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1561 const SMDS_MeshElement* face = 0;
1563 // look for a face by 2 nodes
1564 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1566 int nbFaceNodes = face->NbNodes();
1567 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1568 (myCreateQuadratic && nbFaceNodes>8) ) {
1569 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1572 // look for a not loaded node of the <face>
1574 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1575 eIt = face->nodesIterator() ;
1576 while ( !found && eIt->more() ) {
1577 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1578 if(myTool->IsMedium(node))
1580 found = loadedNodes.insert( node ).second;
1581 if ( !found && node != n1 && node != n2 )
1585 if ( ++row > vsize - 1 ) {
1586 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1589 par_nVec_2->second[ row ] = node;
1590 foundFaces.insert( face );
1592 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1593 n1 = par_nVec_1->second[ row ];
1596 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1597 n3 == par_nVec_1->second[ row ] ) {
1601 MESSAGE( "Not quad mesh, column "<< col );
1606 while ( face && n1 && n2 );
1608 if ( row < vsize - 1 ) {
1609 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1610 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1611 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1612 MESSAGE( "Current node 1: "<< n1);
1613 MESSAGE( "Current node 2: "<< n2);
1614 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1615 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1618 } // loop on columns
1623 //////////////////////////////////////////////////////////////////////////
1625 // StdMeshers_SMESHBlock
1627 //////////////////////////////////////////////////////////////////////////
1629 //=======================================================================
1630 //function : StdMeshers_SMESHBlock
1632 //=======================================================================
1633 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1636 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1639 //=======================================================================
1640 //function : IsForwadEdge
1642 //=======================================================================
1644 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1646 int index = myTBlock.ShapeIndex( theEdgeID );
1647 if ( !myTBlock.IsEdgeID( theEdgeID ))
1650 if ( myIsEdgeForward[ index ] < 0 )
1651 myIsEdgeForward[ index ] =
1652 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1654 return myIsEdgeForward[ index ];
1657 //=======================================================================
1658 //function : ErrorStatus
1660 //=======================================================================
1661 int StdMeshers_SMESHBlock::ErrorStatus() const
1663 return myErrorStatus;
1666 //================================================================================
1668 * \brief Return problem description
1670 //================================================================================
1672 SMESH_ComputeErrorPtr StdMeshers_SMESHBlock::GetError() const
1674 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1675 string & text = err->myComment;
1676 switch ( myErrorStatus ) {
1678 case 3: text = "Internal error of StdMeshers_Penta_3D"; break;
1679 case 4: text = "Can't compute normalized parameters of a point inside a block"; break;
1680 case 5: text = "Can't compute coordinates by normalized parameters inside a block"; break;
1681 case 6: text = "Can't detect block subshapes. Not a block?"; break;
1684 err->myName = myErrorStatus;
1688 //=======================================================================
1691 //=======================================================================
1692 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1694 TopoDS_Vertex aV000, aV001;
1696 Load(theShell, aV000, aV001);
1699 //=======================================================================
1702 //=======================================================================
1703 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1704 const TopoDS_Vertex& theV000,
1705 const TopoDS_Vertex& theV001)
1713 myShapeIDMap.Clear();
1714 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1721 //=======================================================================
1722 //function : ComputeParameters
1724 //=======================================================================
1725 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1728 ComputeParameters(thePnt, myShell, theXYZ);
1731 //=======================================================================
1732 //function : ComputeParameters
1734 //=======================================================================
1735 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1736 const TopoDS_Shape& theShape,
1744 aID = ShapeID(theShape);
1745 if (myErrorStatus) {
1748 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1750 myErrorStatus=4; // problems with computation Parameters
1755 //=======================================================================
1756 //function : ComputeParameters
1758 //=======================================================================
1760 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1761 const TopoDS_Shape& theShape,
1769 aID = ShapeID(theShape);
1770 if (myErrorStatus) {
1773 if ( SMESH_Block::IsEdgeID( aID ))
1774 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1776 myErrorStatus=4; // problems with computation Parameters
1781 //=======================================================================
1784 //=======================================================================
1785 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1790 Point(theParams, aS, aP3D);
1793 //=======================================================================
1796 //=======================================================================
1797 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1798 const TopoDS_Shape& theShape,
1805 gp_XYZ aXYZ(99.,99.,99.);
1808 if (theShape.IsNull()) {
1809 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1813 aID=ShapeID(theShape);
1814 if (myErrorStatus) {
1818 if (SMESH_Block::IsVertexID(aID)) {
1819 bOk = myTBlock.VertexPoint(aID, aXYZ);
1821 else if (SMESH_Block::IsEdgeID(aID)) {
1822 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1825 else if (SMESH_Block::IsFaceID(aID)) {
1826 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1830 myErrorStatus=5; // problems with point computation
1836 //=======================================================================
1837 //function : ShapeID
1839 //=======================================================================
1840 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1845 TopoDS_Shape aSF, aSR;
1848 aSF.Orientation(TopAbs_FORWARD);
1850 aSR.Orientation(TopAbs_REVERSED);
1852 if (myShapeIDMap.Contains(aSF)) {
1853 aID=myShapeIDMap.FindIndex(aSF);
1856 if (myShapeIDMap.Contains(aSR)) {
1857 aID=myShapeIDMap.FindIndex(aSR);
1860 myErrorStatus=2; // unknown shape;
1864 //=======================================================================
1867 //=======================================================================
1868 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1874 aNb=myShapeIDMap.Extent();
1875 if (theID<1 || theID>aNb) {
1876 myErrorStatus=3; // ID is out of range
1877 return myEmptyShape;
1880 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);