1 // Copyright (C) 2007-2010 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
23 // SMESH StdMeshers_Penta_3D implementaion of SMESH idl descriptions
24 // File : StdMeshers_Penta_3D.cxx
27 #include "StdMeshers_Penta_3D.hxx"
29 #include "utilities.h"
30 #include "Utils_ExceptHandlers.hxx"
32 #include "SMDS_EdgePosition.hxx"
33 #include "SMDS_MeshElement.hxx"
34 #include "SMDS_VolumeOfNodes.hxx"
35 #include "SMDS_VolumeTool.hxx"
36 #include "SMESHDS_SubMesh.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_MesherHelper.hxx"
39 #include "SMESH_subMesh.hxx"
40 #include "SMESH_subMeshEventListener.hxx"
41 #include "SMESH_Comment.hxx"
43 #include <BRep_Tool.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <TopTools_ListIteratorOfListOfShape.hxx>
49 #include <TopTools_ListOfShape.hxx>
50 #include <TopTools_SequenceOfShape.hxx>
51 #include <TopTools_MapOfShape.hxx>
53 #include <TopoDS_Edge.hxx>
54 #include <TopoDS_Shell.hxx>
55 #include <TopoDS_Vertex.hxx>
63 typedef map < int, int, less<int> >::iterator \
64 StdMeshers_IteratorOfDataMapOfIntegerInteger;
66 enum { NB_WALL_FACES = 4 };
68 //=======================================================================
69 //function : StdMeshers_Penta_3D
71 //=======================================================================
72 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
73 : myErrorStatus(SMESH_ComputeError::New())
76 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
77 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
81 //=======================================================================
82 //function : ~StdMeshers_Penta_3D
84 //=======================================================================
86 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
90 //=======================================================================
93 //=======================================================================
94 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
95 const TopoDS_Shape& aShape)
97 MESSAGE("StdMeshers_Penta_3D::Compute()");
105 if (!myErrorStatus->IsOK()) {
111 if (!myErrorStatus->IsOK()) {
116 if (!myErrorStatus->IsOK()) {
120 // now unnecessary faces removed, we can load medium nodes
121 SMESH_MesherHelper helper(aMesh);
123 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
127 if (!myErrorStatus->IsOK()) {
134 if (!myErrorStatus->IsOK()) {
143 //=======================================================================
144 //function : MakeNodes
146 //=======================================================================
147 void StdMeshers_Penta_3D::MakeNodes()
150 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
152 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
153 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
154 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
155 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
156 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
160 SMESH_Mesh* pMesh=GetMesh();
162 // 1. Define the sizes of mesh
164 // 1.1 Horizontal size
166 for (i=0; i<aNbSIDs; ++i) {
167 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
168 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
170 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
171 if(!myCreateQuadratic) {
172 iNbN = aSM->NbNodes();
176 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
178 const SMDS_MeshNode* aNode = itn->next();
179 if(myTool->IsMedium(aNode))
186 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
191 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
192 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
194 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
195 if(!myCreateQuadratic) {
196 iNbN = aSM->NbNodes();
200 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
202 const SMDS_MeshNode* aNode = itn->next();
203 if(myTool->IsMedium(aNode))
210 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
212 aSize=myISize*myJSize;
213 myTNodes.resize(aSize);
215 StdMeshers_TNode aTNode;
219 // 2. Fill the repers on base face (Z=0)
222 for (k=0; k<aNbSIDs; ++k) {
224 const TopoDS_Shape& aS = myBlock.Shape(aSID);
225 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
227 const SMDS_MeshNode* aNode = ite->next();
228 if(myTool->IsMedium(aNode))
230 aNodeID=aNode->GetID();
232 aTNode.SetNode(aNode);
233 aTNode.SetShapeSupportID(aSID);
234 aTNode.SetBaseNodeID(aNodeID);
236 if ( SMESH_Block::IsEdgeID (aSID)) {
237 const SMDS_EdgePosition* epos =
238 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
239 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
245 aP3D.SetCoord(aX, aY, aZ);
246 myBlock.ComputeParameters(aP3D, aS, aCoords);
248 iErr = myBlock.ErrorStatus();
250 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
251 "SMESHBlock: ComputeParameters operation failed");
252 myErrorStatus=myBlock.GetError();
255 aTNode.SetNormCoord(aCoords);
262 // 3.1 Fill maps of wall nodes
263 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
264 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
265 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
267 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
268 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
269 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
271 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
272 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
273 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
274 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
275 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
278 myErrorStatus->myName = COMPERR_BAD_INPUT_MESH;
279 myErrorStatus->myComment = SMESH_Comment() <<
280 "Can't find regular quadrangle mesh on a side face #" <<
281 pMesh->GetMeshDS()->ShapeToIndex( myBlock.Shape( wallFaceID[ i ]));
286 // 3.2 find node columns for vertical edges and edge IDs
287 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
288 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
289 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
291 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
292 ShapeSupportID(false, vID, eID);
293 verticEdgeID[ i ] = eID;
295 StdMeshers_TNode& aTNode = myTNodes[ i ];
296 verticEdgeNodes[ i ] = 0;
297 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
298 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
299 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
300 if ( ijNodes.begin()->second[0] == aTNode.Node() )
301 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
302 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
303 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
304 if ( verticEdgeNodes[ i ] )
309 // 3.3 set XYZ of vertices, and initialize of the rest
310 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
311 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
312 if ( SMESH_Block::IsVertexID( id )) {
313 TopoDS_Shape V = myBlock.Shape( id );
314 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
315 const SMDS_MeshNode* n = sm->GetNodes()->next();
316 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
319 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
323 // 4. Fill the rest repers
326 SMESH_Block::TShapeID aSSID, aBNSSID;
327 StdMeshers_TNode aTN;
330 // create top face and find UV for it's corners
331 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
332 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
333 int topfaceID = meshDS->ShapeToIndex(TopFace);
334 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
335 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
336 const SMDS_MeshNode* N = itn->next();
337 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
338 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
339 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
341 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
342 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
343 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
345 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
346 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
347 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
349 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
351 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
353 const StdMeshers_TNode& aBN = myTNodes[j];
354 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
355 iBNID = aBN.BaseNodeID();
356 const gp_XYZ& aBNXYZ = aBN.NormCoord();
357 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
359 // set XYZ on horizontal edges and get node columns of faces:
360 // 2 columns for each face, between which a base node is located
361 vector<const SMDS_MeshNode*>* nColumns[8];
362 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
364 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
365 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
366 nColumns[k*2], nColumns[k*2+1]);
370 // XYZ on the bottom and top faces
371 const SMDS_MeshNode* n = aBN.Node();
372 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
373 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
375 // first create or find a top node, then the rest ones in a column
376 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
378 bIsUpperLayer = (i==(myISize-1));
379 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
380 if ( createNode ) // a base node is inside a top face
382 // set XYZ on vertical edges and faces
383 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
384 // XYZ on a vertical edge
385 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
386 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
387 // XYZ on a face (part 1 from one column)
388 n = (*nColumns[k*2]) [ i ];
389 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
390 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
392 if( bIsUpperLayer ) {
393 tmp1 = myTool->GetNodeUV(TopFace,n);
394 tmp1 = ( 1. - ratio[ k ]) * tmp1;
396 // XYZ on a face (part 2 from other column)
397 n = (*nColumns[k*2+1]) [ i ];
398 xyz.SetCoord( n->X(), n->Y(), n->Z() );
399 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
400 if( bIsUpperLayer ) {
401 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
402 tmp1 += ratio[ k ] * tmp2;
414 // fill current node info
417 // -normalized coordinates
421 aZ=(double)i/(double)(myISize-1);
422 aCoords.SetCoord(aX, aY, aZ);
424 // suporting shape ID
425 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
426 if (!myErrorStatus->IsOK()) {
427 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
431 aTN.SetShapeSupportID(aSSID);
432 aTN.SetNormCoord(aCoords);
433 aTN.SetBaseNodeID(iBNID);
435 if (aSSID!=SMESH_Block::ID_NONE){
436 // try to find the node
437 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
438 FindNodeOnShape(aS, aCoords, i, aTN);
441 // create node and get its id
442 CreateNode (bIsUpperLayer, aCoords, aTN);
444 if ( bIsUpperLayer ) {
445 const SMDS_MeshNode* n = aTN.Node();
446 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
447 // set node on top face:
448 // find UV parameter for this node
450 // UV011+-----+----------+UV111
453 // UV_E0y1+ +node +UV_E1y1
457 // UV001+-----+----------+UV101
460 double u = aCoords.X(), v = aCoords.Y();
461 double u1 = ( 1. - u ), v1 = ( 1. - v );
462 aP.ChangeCoord() = UV_Ex01 * v1;
463 aP.ChangeCoord() += UV_Ex11 * v;
464 aP.ChangeCoord() += UV_E0y1 * u1;
465 aP.ChangeCoord() += UV_E1y1 * u;
466 aP.ChangeCoord() -= UV001 * u1 * v1;
467 aP.ChangeCoord() -= UV101 * u * v1;
468 aP.ChangeCoord() -= UV011 * u1 * v;
469 aP.ChangeCoord() -= UV111 * u * v;
470 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
473 if (!myErrorStatus->IsOK()) {
474 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
484 //=======================================================================
485 //function : FindNodeOnShape
487 //=======================================================================
489 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
490 const gp_XYZ& aParams,
492 StdMeshers_TNode& aTN)
494 double aX, aY, aZ, aD, aTol2, minD;
497 SMESH_Mesh* pMesh = GetMesh();
498 aTol2 = myTol3D*myTol3D;
500 SMDS_MeshNode* pNode = NULL;
502 if ( aS.ShapeType() == TopAbs_FACE ||
503 aS.ShapeType() == TopAbs_EDGE ) {
504 // find a face ID to which aTN belongs to
506 if ( aS.ShapeType() == TopAbs_FACE )
507 faceID = myBlock.ShapeID( aS );
508 else { // edge maybe vertical or top horizontal
509 gp_XYZ aCoord = aParams;
510 if ( aCoord.Z() == 1. )
511 aCoord.SetZ( 0.5 ); // move from top down
513 aCoord.SetX( 0.5 ); // move along X
514 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
516 ASSERT( SMESH_Block::IsFaceID( faceID ));
517 int fIndex = SMESH_Block::ShapeIndex( faceID );
518 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
519 // look for a base node in ijNodes
520 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
521 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
522 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
523 if ( par_nVec->second[ 0 ] == baseNode ) {
524 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
530 myBlock.Point(aParams, aS, aP1);
532 SMDS_NodeIteratorPtr ite=
533 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
535 const SMDS_MeshNode* aNode = ite->next();
536 if(myTool->IsMedium(aNode))
541 aP2.SetCoord(aX, aY, aZ);
542 aD=(double)aP1.SquareDistance(aP2);
543 //printf("** D=%lf ", aD, aTol2);
545 pNode=(SMDS_MeshNode*)aNode;
555 //aTN.SetNode(pNode);
556 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
557 //myErrorStatus=11; // can not find the node;
561 //=======================================================================
562 //function : SetHorizEdgeXYZ
564 //=======================================================================
566 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
568 vector<const SMDS_MeshNode*>*& aCol1,
569 vector<const SMDS_MeshNode*>*& aCol2)
571 // find base and top edges of the face
572 enum { BASE = 0, TOP };
573 vector< int > edgeVec; // 0-base, 1-top
574 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
576 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
577 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
579 double param = aBaseNodeParams.Coord( coord );
583 // look for columns around param
584 StdMeshers_IJNodeMap & ijNodes =
585 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
586 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
587 while ( par_nVec_1->first < param )
589 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
592 if ( par_nVec_1 != ijNodes.begin() ) {
594 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
596 aCol1 = & par_nVec_1->second;
597 aCol2 = & par_nVec_2->second;
601 // this variant is better for cases with curved edges and
602 // different nodes distribution on top and base edges
603 const SMDS_MeshNode* n1 = aCol1->back();
604 const SMDS_MeshNode* n2 = aCol2->back();
605 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
606 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
607 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
610 // this variant is better for other cases
611 // SMESH_MesherHelper helper( *GetMesh() );
612 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
613 // double u1 = helper.GetNodeU( edge, n1 );
614 // double u2 = helper.GetNodeU( edge, n2 );
615 // double u = ( 1. - r ) * u1 + r * u2;
616 // gp_XYZ topNodeParams;
617 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
618 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
620 // myShapeXYZ[ edgeVec[ TOP ]]);
624 myBlock.Block().EdgePoint( edgeVec[ BASE ],
626 myShapeXYZ[ edgeVec[ BASE ]]);
631 //=======================================================================
632 //function : MakeVolumeMesh
634 //=======================================================================
635 void StdMeshers_Penta_3D::MakeVolumeMesh()
637 int i, j, ij, ik, i1, i2, aSSID;
639 SMESH_Mesh* pMesh = GetMesh();
640 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
642 int shapeID = meshDS->ShapeToIndex( myShape );
644 // 1. Set Node In Volume
646 for (i=1; i<ik; ++i){
647 for (j=0; j<myJSize; ++j){
649 const StdMeshers_TNode& aTN = myTNodes[ij];
650 aSSID=aTN.ShapeSupportID();
651 if (aSSID==SMESH_Block::ID_NONE) {
652 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
653 meshDS->SetNodeInVolume(aNode, shapeID);
658 // 2. Make pentahedrons
660 vector<const SMDS_MeshNode*> aN;
662 SMDS_ElemIteratorPtr itf, aItNodes;
664 const TopoDS_Face& aFxy0=
665 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
666 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
667 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
669 itf = aSM0->GetElements();
671 const SMDS_MeshElement* pE0 = itf->next();
673 int nbFaceNodes = pE0->NbNodes();
674 if(myCreateQuadratic)
675 nbFaceNodes = nbFaceNodes/2;
676 if ( aN.size() < nbFaceNodes * 2 )
677 aN.resize( nbFaceNodes * 2 );
679 for ( k=0; k<nbFaceNodes; ++k ) {
680 const SMDS_MeshNode* pNode = pE0->GetNode(k);
681 // if(myTool->IsMedium(pNode))
683 aID0 = pNode->GetID();
684 aJ[k] = GetIndexOnLayer(aID0);
685 if (!myErrorStatus->IsOK()) {
686 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
692 for (i=0; i<ik; ++i) {
695 for(j=0; j<nbFaceNodes; ++j) {
696 ij = i1*myJSize+aJ[j];
697 const StdMeshers_TNode& aTN1 = myTNodes[ij];
698 const SMDS_MeshNode* aN1 = aTN1.Node();
702 const StdMeshers_TNode& aTN2 = myTNodes[ij];
703 const SMDS_MeshNode* aN2 = aTN2.Node();
704 aN[j+nbFaceNodes] = aN2;
706 // check if volume orientation will be ok
708 SMDS_VolumeTool vTool;
709 switch ( nbFaceNodes ) {
711 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
712 aN[3], aN[4], aN[5]);
713 vTool.Set( &tmpVol );
717 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
718 aN[4], aN[5], aN[6], aN[7]);
719 vTool.Set( &tmpVol );
725 forward = vTool.IsForward();
728 SMDS_MeshVolume* aV = 0;
729 switch ( nbFaceNodes ) {
732 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
733 // aN[3], aN[4], aN[5]);
734 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
737 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
738 // aN[3], aN[5], aN[4]);
739 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
744 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
745 // aN[4], aN[5], aN[6], aN[7]);
746 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
747 aN[4], aN[5], aN[6], aN[7]);
750 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
751 // aN[4], aN[7], aN[6], aN[5]);
752 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
753 aN[4], aN[7], aN[6], aN[5]);
759 meshDS->SetMeshElementOnShape(aV, shapeID);
764 //=======================================================================
765 //function : MakeMeshOnFxy1
767 //=======================================================================
768 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
770 int aID0, aJ, aLevel, ij, aNbNodes, k;
772 SMDS_NodeIteratorPtr itn;
773 SMDS_ElemIteratorPtr itf, aItNodes;
774 SMDSAbs_ElementType aElementType;
776 const TopoDS_Face& aFxy0=
777 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
778 const TopoDS_Face& aFxy1=
779 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
781 SMESH_Mesh* pMesh = GetMesh();
782 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
784 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
785 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
786 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
788 // set nodes on aFxy1
790 itn = aSM0->GetNodes();
791 aNbNodes = aSM0->NbNodes();
792 //printf("** aNbNodes=%d\n", aNbNodes);
793 myTool->SetSubShape( aFxy1 ); // to set medium nodes to aFxy1
795 // set elements on aFxy1
796 vector<const SMDS_MeshNode*> aNodes1;
798 itf = aSM0->GetElements();
800 const SMDS_MeshElement* pE0 = itf->next();
801 aElementType = pE0->GetType();
802 if (!aElementType==SMDSAbs_Face) {
805 aNbNodes = pE0->NbNodes();
806 if(myCreateQuadratic)
807 aNbNodes = aNbNodes/2;
808 if ( aNodes1.size() < aNbNodes )
809 aNodes1.resize( aNbNodes );
811 k = aNbNodes-1; // reverse a face
812 aItNodes = pE0->nodesIterator();
813 while (aItNodes->more()) {
814 const SMDS_MeshNode* pNode =
815 static_cast<const SMDS_MeshNode*> (aItNodes->next());
816 if(myTool->IsMedium(pNode))
818 aID0 = pNode->GetID();
819 aJ = GetIndexOnLayer(aID0);
820 if (!myErrorStatus->IsOK()) {
821 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
825 ij = aLevel*myJSize + aJ;
826 const StdMeshers_TNode& aTN1 = myTNodes[ij];
827 const SMDS_MeshNode* aN1 = aTN1.Node();
831 SMDS_MeshFace * face = 0;
832 switch ( aNbNodes ) {
834 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
837 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
842 meshDS->SetMeshElementOnShape(face, aFxy1);
844 myTool->SetSubShape( myShape );
846 // update compute state of top face submesh
847 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
849 // assure that mesh on the top face will be cleaned when it is cleaned
850 // on the bottom face
851 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
852 volSM->SetEventListener( new SMESH_subMeshEventListener(true),
853 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
854 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
857 //=======================================================================
858 //function : ClearMeshOnFxy1
860 //=======================================================================
861 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
863 SMESH_subMesh* aSubMesh;
864 SMESH_Mesh* pMesh=GetMesh();
866 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
867 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
869 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
872 //=======================================================================
873 //function : GetIndexOnLayer
875 //=======================================================================
876 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
879 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
881 aMapIt=myConnectingMap.find(aID);
882 if (aMapIt==myConnectingMap.end()) {
883 myErrorStatus->myName = 200;
884 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
891 //=======================================================================
892 //function : MakeConnectingMap
894 //=======================================================================
895 void StdMeshers_Penta_3D::MakeConnectingMap()
899 for (j=0; j<myJSize; ++j) {
900 const StdMeshers_TNode& aBN=myTNodes[j];
901 aBNID=aBN.BaseNodeID();
902 myConnectingMap[aBNID]=j;
906 //=======================================================================
907 //function : CreateNode
909 //=======================================================================
910 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
911 const gp_XYZ& aParams,
912 StdMeshers_TNode& aTN)
918 SMDS_MeshNode* pNode=NULL;
921 // if (bIsUpperLayer) {
922 // // point on face Fxy1
923 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
924 // myBlock.Point(aParams, aS, aP);
927 // // point inside solid
928 // myBlock.Point(aParams, aP);
931 double u = aParams.X(), v = aParams.Y();
932 double u1 = ( 1. - u ), v1 = ( 1. - v );
933 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
934 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
935 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
936 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
938 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
939 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
940 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
941 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
944 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
947 // iErr=myBlock.ErrorStatus();
949 // myErrorStatus=12; // can not find the node point;
953 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
955 SMESH_Mesh* pMesh = GetMesh();
956 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
958 pNode = pMeshDS->AddNode(aX, aY, aZ);
963 //=======================================================================
964 //function : ShapeSupportID
966 //=======================================================================
967 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
968 const SMESH_Block::TShapeID aBNSSID,
969 SMESH_Block::TShapeID& aSSID)
972 case SMESH_Block::ID_V000:
973 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
975 case SMESH_Block::ID_V100:
976 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
978 case SMESH_Block::ID_V110:
979 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
981 case SMESH_Block::ID_V010:
982 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
984 case SMESH_Block::ID_Ex00:
985 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
987 case SMESH_Block::ID_Ex10:
988 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
990 case SMESH_Block::ID_E0y0:
991 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
993 case SMESH_Block::ID_E1y0:
994 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
996 case SMESH_Block::ID_Fxy0:
997 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1000 aSSID=SMESH_Block::ID_NONE;
1001 myErrorStatus->myName=10; // Can not find supporting shape ID
1002 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
1007 //=======================================================================
1008 //function : MakeBlock
1010 //=======================================================================
1011 void StdMeshers_Penta_3D::MakeBlock()
1014 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1016 TopoDS_Vertex aV000, aV001;
1018 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1019 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1020 TopTools_ListIteratorOfListOfShape aIt;
1022 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1024 // 0. Find triangulated face aFTr
1025 SMDSAbs_ElementType aElementType;
1026 SMESH_Mesh* pMesh=GetMesh();
1030 for (i=1; i<=iNbF; ++i) {
1031 const TopoDS_Shape& aF = aM(i);
1032 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1034 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1035 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1036 while(itf->more()) {
1037 const SMDS_MeshElement * pElement = itf->next();
1038 aElementType = pElement->GetType();
1039 if (aElementType==SMDSAbs_Face) {
1040 iNbNodes = pElement->NbNodes();
1041 if ( iNbNodes==3 || (pElement->IsQuadratic() && iNbNodes==6) ) {
1046 // The current algorithm fails if there is more that one
1047 // face wich contains triangles ...
1048 // In that case, replace return by break to try another
1049 // method (coded in "if (iCnt != 1) { ... }")
1051 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1052 // myErrorStatus=5; // more than one face has triangulation
1064 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1065 // was not reached 'cause it was not called from Hexa_3D ... Now it
1066 // can occurs and in my opinion, it is the most common case.
1069 // The suggested algorithm is the following :
1071 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1072 // then the shape is tologically equivalent to a box
1073 // o In a box, there are three set of four // edges ...
1074 // In the cascade notation, it seems to be the edges
1079 // o For each one of this set, check if the four edges
1080 // have the same number of element.
1081 // o If so, check if the "corresponding" // faces contains
1082 // only quads. It's the faces numbered:
1086 // o If so, check if the opposite edges of each // faces
1087 // have the same number of elements. It is the edges
1089 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1090 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1091 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1092 // o If so, check if the two other faces have the same
1093 // number of elements. It is the faces numbered:
1097 // This test should be improved to test if the nodes
1098 // of the two faces are really "en face".
1099 // o If so, one of the two faces is a candidate to an extrusion,
1100 // It is the faces numbered :
1104 // o Finally, if there is only one candidate, let do the
1105 // extrusion job for the corresponding face
1109 int iNbF = aM.Extent();
1112 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1113 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1114 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1115 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1116 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1117 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1119 int has_only_quad_f1 = 1;
1120 int has_only_quad_f2 = 1;
1121 int has_only_quad_f3 = 1;
1122 int has_only_quad_f4 = 1;
1123 int has_only_quad_f5 = 1;
1124 int has_only_quad_f6 = 1;
1126 for (i=1; i<=iNbF; ++i) {
1128 const TopoDS_Shape& aF = aM(i);
1129 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1130 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1131 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1132 while(itf->more()) {
1133 const SMDS_MeshElement * pElement = itf->next();
1134 aElementType = pElement->GetType();
1135 if (aElementType==SMDSAbs_Face) {
1136 iNbNodes = pElement->NbNodes();
1137 if ( iNbNodes!=4 ) {
1143 if (i==1) has_only_quad_f1 = ok ;
1144 if (i==2) has_only_quad_f2 = ok ;
1145 if (i==3) has_only_quad_f3 = ok ;
1146 if (i==4) has_only_quad_f4 = ok ;
1147 if (i==5) has_only_quad_f5 = ok ;
1148 if (i==6) has_only_quad_f6 = ok ;
1151 TopTools_IndexedMapOfShape aE;
1152 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1153 int iNbE = aE.Extent();
1156 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1157 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1158 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1159 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1160 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1161 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1162 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1163 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1164 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1165 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1166 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1167 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1171 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1172 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1173 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1181 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1182 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1183 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1191 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1192 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1193 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1209 myErrorStatus->myName=5; // more than one face has triangulation
1210 myErrorStatus->myComment="Incorrect input mesh";
1216 // 1. Vetrices V00, V001;
1218 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1219 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1221 // 1.1 Base vertex V000
1222 iNbE = aME.Extent();
1223 if (iNbE!= NB_WALL_FACES ){
1224 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1225 myErrorStatus->myName=7; // too few edges are in base face aFTr
1226 myErrorStatus->myComment=SMESH_Comment("Not a quadrilateral face #")
1227 <<pMesh->GetMeshDS()->ShapeToIndex( aFTr )<<": "<<iNbE<<" edges" ;
1230 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1231 aV000=TopExp::FirstVertex(aE1);
1233 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1234 aIt.Initialize(aLE);
1235 for (; aIt.More(); aIt.Next()) {
1236 const TopoDS_Shape& aEx=aIt.Value();
1239 iNbEV=aMEV.Extent();
1241 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1242 myErrorStatus->myName=7; // too few edges meet in base vertex
1243 myErrorStatus->myComment=SMESH_Comment("3 edges must share vertex #")
1244 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 )<<" but there are "<<iNbEV<<" edges";
1250 for (j=1; j<=iNbEV; ++j) {
1251 const TopoDS_Shape& aEx=aMEV(j);
1252 if (!aME.Contains(aEx)) {
1253 TopoDS_Vertex aV[2];
1255 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1256 TopExp::Vertices(aE, aV[0], aV[1]);
1257 for (i=0; i<2; ++i) {
1258 if (!aV[i].IsSame(aV000)) {
1268 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1269 myErrorStatus->myName=8; // can not find reper V001
1270 myErrorStatus->myComment=SMESH_Comment("Can't find opposite vertex for vertex #")
1271 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 );
1275 //gp_Pnt aP000, aP001;
1277 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1278 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1279 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1280 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1284 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1287 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1288 myErrorStatus->myName=9; // number of shells in source shape !=1
1289 myErrorStatus->myComment=SMESH_Comment("Unexpected nb of shells ")<<iNbE;
1294 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1295 myBlock.Load(aShell, aV000, aV001);
1296 iErr = myBlock.ErrorStatus();
1298 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1299 myErrorStatus=myBlock.GetError(); // SMESHBlock: Load operation failed
1303 //=======================================================================
1304 //function : CheckData
1306 //=======================================================================
1307 void StdMeshers_Penta_3D::CheckData()
1310 int iNbEx[]={8, 12, 6};
1312 TopAbs_ShapeEnum aST;
1313 TopAbs_ShapeEnum aSTEx[]={
1314 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1316 TopTools_IndexedMapOfShape aM;
1318 if (myShape.IsNull()){
1319 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1320 myErrorStatus->myName=2; // null shape
1321 myErrorStatus->myComment="Null shape";
1325 aST=myShape.ShapeType();
1326 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1327 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1328 myErrorStatus->myName=3; // not compatible type of shape
1329 myErrorStatus->myComment=SMESH_Comment("Wrong shape type (TopAbs_ShapeEnum) ")<<aST;
1333 for (i=0; i<3; ++i) {
1335 TopExp::MapShapes(myShape, aSTEx[i], aM);
1338 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1339 myErrorStatus->myName=4; // number of subshape is not compatible
1340 myErrorStatus->myComment="Wrong number of subshapes of a block";
1346 //=======================================================================
1347 //function : LoadIJNodes
1348 //purpose : Load nodes bound to theFace into column (vectors) and rows
1350 // The value of theIJNodes map is a vector of ordered nodes so
1351 // that the 0-the one lies on theBaseEdge.
1352 // The key of theIJNodes map is a normalized parameter of each
1353 // 0-the node on theBaseEdge.
1354 //=======================================================================
1356 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1357 const TopoDS_Face& theFace,
1358 const TopoDS_Edge& theBaseEdge,
1359 SMESHDS_Mesh* theMesh)
1361 // get vertices of theBaseEdge
1362 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1363 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1364 TopExp::Vertices( eFrw, vfb, vlb );
1366 // find the other edges of theFace and orientation of e1
1367 TopoDS_Edge e1, e2, eTop;
1368 bool rev1, CumOri = false;
1369 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1371 for ( ; exp.More(); exp.Next() ) {
1372 if ( ++nbEdges > NB_WALL_FACES ) {
1373 return false; // more than 4 edges in theFace
1375 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1376 if ( theBaseEdge.IsSame( e ))
1378 TopoDS_Vertex vCommon;
1379 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1381 else if ( vCommon.IsSame( vfb )) {
1383 vft = TopExp::LastVertex( e1, CumOri );
1384 rev1 = vfb.IsSame( vft );
1386 vft = TopExp::FirstVertex( e1, CumOri );
1391 if ( nbEdges < NB_WALL_FACES ) {
1392 return false; // less than 4 edges in theFace
1395 // submeshes corresponding to shapes
1396 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1397 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1398 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1399 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1400 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1401 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1402 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1403 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1404 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1405 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1406 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1409 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1410 MESSAGE(" Diff nb of nodes on opposite edges" );
1413 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1414 MESSAGE("Empty submesh of vertex");
1417 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1418 // check quadratic case
1419 if ( myCreateQuadratic ) {
1420 int n1 = sm1->NbNodes()/2;
1421 int n2 = smb->NbNodes()/2;
1422 int n3 = sm1->NbNodes() - n1;
1423 int n4 = smb->NbNodes() - n2;
1424 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1425 if( nf != smFace->NbNodes() ) {
1426 MESSAGE( "Wrong nb face nodes: " <<
1427 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1432 MESSAGE( "Wrong nb face nodes: " <<
1433 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1438 int vsize = sm1->NbNodes() + 2;
1439 int hsize = smb->NbNodes() + 2;
1440 if(myCreateQuadratic) {
1441 vsize = vsize - sm1->NbNodes()/2 -1;
1442 hsize = hsize - smb->NbNodes()/2 -1;
1445 // load nodes from theBaseEdge
1447 set<const SMDS_MeshNode*> loadedNodes;
1448 const SMDS_MeshNode* nullNode = 0;
1450 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1451 nVecf.resize( vsize, nullNode );
1452 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1454 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1455 nVecl.resize( vsize, nullNode );
1456 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1459 BRep_Tool::Range( eFrw, f, l );
1460 double range = l - f;
1461 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1462 const SMDS_MeshNode* node;
1463 while ( nIt->more() ) {
1465 if(myTool->IsMedium(node))
1467 const SMDS_EdgePosition* pos =
1468 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1472 double u = ( pos->GetUParameter() - f ) / range;
1473 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1474 nVec.resize( vsize, nullNode );
1475 loadedNodes.insert( nVec[ 0 ] = node );
1477 if ( theIJNodes.size() != hsize ) {
1478 MESSAGE( "Wrong node positions on theBaseEdge" );
1482 // load nodes from e1
1484 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1485 nIt = sm1->GetNodes();
1486 while ( nIt->more() ) {
1488 if(myTool->IsMedium(node))
1490 const SMDS_EdgePosition* pos =
1491 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1495 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1497 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1498 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1499 int row = rev1 ? vsize - 1 : 0;
1500 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1503 loadedNodes.insert( nVecf[ row ] = u_n->second );
1506 // try to load the rest nodes
1508 // get all faces from theFace
1509 TIDSortedElemSet allFaces, foundFaces;
1510 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1511 while ( eIt->more() ) {
1512 const SMDS_MeshElement* e = eIt->next();
1513 if ( e->GetType() == SMDSAbs_Face )
1514 allFaces.insert( e );
1516 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1517 // the nodes belong to, and between the nodes of the found face,
1518 // look for a not loaded node considering this node to be the next
1519 // in a column of the starting second node. Repeat, starting
1520 // from nodes next to the previous starting nodes in their columns,
1521 // and so on while a face can be found. Then go the the next pair
1522 // of nodes on theBaseEdge.
1523 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1524 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1527 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1530 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1531 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1532 const SMDS_MeshElement* face = 0;
1534 // look for a face by 2 nodes
1535 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1537 int nbFaceNodes = face->NbNodes();
1538 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1539 (myCreateQuadratic && nbFaceNodes>8) ) {
1540 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1543 // look for a not loaded node of the <face>
1545 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1546 eIt = face->nodesIterator() ;
1547 while ( !found && eIt->more() ) {
1548 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1549 if(myTool->IsMedium(node))
1551 found = loadedNodes.insert( node ).second;
1552 if ( !found && node != n1 && node != n2 )
1556 if ( ++row > vsize - 1 ) {
1557 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1560 par_nVec_2->second[ row ] = node;
1561 foundFaces.insert( face );
1563 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1564 n1 = par_nVec_1->second[ row ];
1567 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1568 n3 == par_nVec_1->second[ row ] ) {
1572 MESSAGE( "Not quad mesh, column "<< col );
1577 while ( face && n1 && n2 );
1579 if ( row < vsize - 1 ) {
1580 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1581 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1582 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1583 MESSAGE( "Current node 1: "<< n1);
1584 MESSAGE( "Current node 2: "<< n2);
1585 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1586 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1589 } // loop on columns
1594 //////////////////////////////////////////////////////////////////////////
1596 // StdMeshers_SMESHBlock
1598 //////////////////////////////////////////////////////////////////////////
1600 //=======================================================================
1601 //function : StdMeshers_SMESHBlock
1603 //=======================================================================
1604 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1607 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1610 //=======================================================================
1611 //function : IsForwadEdge
1613 //=======================================================================
1615 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1617 int index = myTBlock.ShapeIndex( theEdgeID );
1618 if ( !myTBlock.IsEdgeID( theEdgeID ))
1621 if ( myIsEdgeForward[ index ] < 0 )
1622 myIsEdgeForward[ index ] =
1623 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1625 return myIsEdgeForward[ index ];
1628 //=======================================================================
1629 //function : ErrorStatus
1631 //=======================================================================
1632 int StdMeshers_SMESHBlock::ErrorStatus() const
1634 return myErrorStatus;
1637 //================================================================================
1639 * \brief Return problem description
1641 //================================================================================
1643 SMESH_ComputeErrorPtr StdMeshers_SMESHBlock::GetError() const
1645 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1646 string & text = err->myComment;
1647 switch ( myErrorStatus ) {
1649 case 3: text = "Internal error of StdMeshers_Penta_3D"; break;
1650 case 4: text = "Can't compute normalized parameters of a point inside a block"; break;
1651 case 5: text = "Can't compute coordinates by normalized parameters inside a block"; break;
1652 case 6: text = "Can't detect block subshapes. Not a block?"; break;
1655 err->myName = myErrorStatus;
1659 //=======================================================================
1662 //=======================================================================
1663 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1665 TopoDS_Vertex aV000, aV001;
1667 Load(theShell, aV000, aV001);
1670 //=======================================================================
1673 //=======================================================================
1674 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1675 const TopoDS_Vertex& theV000,
1676 const TopoDS_Vertex& theV001)
1684 myShapeIDMap.Clear();
1685 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1692 //=======================================================================
1693 //function : ComputeParameters
1695 //=======================================================================
1696 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1699 ComputeParameters(thePnt, myShell, theXYZ);
1702 //=======================================================================
1703 //function : ComputeParameters
1705 //=======================================================================
1706 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1707 const TopoDS_Shape& theShape,
1715 aID = ShapeID(theShape);
1716 if (myErrorStatus) {
1719 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1721 myErrorStatus=4; // problems with computation Parameters
1726 //=======================================================================
1727 //function : ComputeParameters
1729 //=======================================================================
1731 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1732 const TopoDS_Shape& theShape,
1740 aID = ShapeID(theShape);
1741 if (myErrorStatus) {
1744 if ( SMESH_Block::IsEdgeID( aID ))
1745 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1747 myErrorStatus=4; // problems with computation Parameters
1752 //=======================================================================
1755 //=======================================================================
1756 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams, gp_Pnt& aP3D)
1760 Point(theParams, aS, aP3D);
1763 //=======================================================================
1766 //=======================================================================
1767 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1768 const TopoDS_Shape& theShape,
1775 gp_XYZ aXYZ(99.,99.,99.);
1778 if (theShape.IsNull()) {
1779 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1783 aID=ShapeID(theShape);
1784 if (myErrorStatus) {
1788 if (SMESH_Block::IsVertexID(aID)) {
1789 bOk = myTBlock.VertexPoint(aID, aXYZ);
1791 else if (SMESH_Block::IsEdgeID(aID)) {
1792 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1795 else if (SMESH_Block::IsFaceID(aID)) {
1796 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1800 myErrorStatus=5; // problems with point computation
1806 //=======================================================================
1807 //function : ShapeID
1809 //=======================================================================
1810 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1815 TopoDS_Shape aSF, aSR;
1818 aSF.Orientation(TopAbs_FORWARD);
1820 aSR.Orientation(TopAbs_REVERSED);
1822 if (myShapeIDMap.Contains(aSF)) {
1823 aID=myShapeIDMap.FindIndex(aSF);
1826 if (myShapeIDMap.Contains(aSR)) {
1827 aID=myShapeIDMap.FindIndex(aSR);
1830 myErrorStatus=2; // unknown shape;
1834 //=======================================================================
1837 //=======================================================================
1838 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1844 aNb=myShapeIDMap.Extent();
1845 if (theID<1 || theID>aNb) {
1846 myErrorStatus=3; // ID is out of range
1847 return myEmptyShape;
1850 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);
1855 //=======================================================================
1856 //function : Evaluate
1858 //=======================================================================
1859 bool StdMeshers_Penta_3D::Evaluate(SMESH_Mesh& aMesh,
1860 const TopoDS_Shape& aShape,
1861 MapShapeNbElems& aResMap)
1863 MESSAGE("StdMeshers_Penta_3D::Evaluate()");
1865 // find face contains only triangles
1866 vector < SMESH_subMesh * >meshFaces;
1867 TopTools_SequenceOfShape aFaces;
1868 int NumBase = 0, i = 0;
1869 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
1871 aFaces.Append(exp.Current());
1872 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
1873 meshFaces.push_back(aSubMesh);
1874 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i]);
1875 if( anIt == aResMap.end() ) {
1879 std::vector<int> aVec = (*anIt).second;
1880 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1881 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1882 if( nbtri>0 && nbqua==0 ) {
1888 std::vector<int> aResVec(SMDSEntity_Last);
1889 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1890 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1891 aResMap.insert(std::make_pair(sm,aResVec));
1892 myErrorStatus->myName = COMPERR_ALGO_FAILED;
1893 myErrorStatus->myComment = "Submesh can not be evaluated";
1897 // find number of 1d elems for base face
1899 TopTools_MapOfShape Edges1;
1900 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1901 Edges1.Add(exp.Current());
1902 SMESH_subMesh *sm = aMesh.GetSubMesh(exp.Current());
1904 MapShapeNbElemsItr anIt = aResMap.find(sm);
1905 if( anIt == aResMap.end() ) continue;
1906 std::vector<int> aVec = (*anIt).second;
1907 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1910 // find face opposite to base face
1912 for(i=1; i<=6; i++) {
1913 if(i==NumBase) continue;
1914 bool IsOpposite = true;
1915 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1916 if( Edges1.Contains(exp.Current()) ) {
1926 // find number of 2d elems on side faces
1928 for(i=1; i<=6; i++) {
1929 if( i==OppNum || i==NumBase ) continue;
1930 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1931 if( anIt == aResMap.end() ) continue;
1932 std::vector<int> aVec = (*anIt).second;
1933 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1936 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1937 std::vector<int> aVec = (*anIt).second;
1938 int nb2d_face0 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1939 int nb0d_face0 = aVec[SMDSEntity_Node];
1941 anIt = aResMap.find( meshFaces[OppNum-1] );
1942 for(i=SMDSEntity_Node; i<SMDSEntity_Last; i++)
1943 (*anIt).second[i] = aVec[i];
1945 SMESH_MesherHelper aTool (aMesh);
1946 bool _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
1948 std::vector<int> aResVec(SMDSEntity_Last);
1949 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1950 if(_quadraticMesh) {
1951 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0 * ( nb2d/nb1d );
1952 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 );
1955 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1956 aResVec[SMDSEntity_Penta] = nb2d_face0 * ( nb2d/nb1d );
1958 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1959 aResMap.insert(std::make_pair(sm,aResVec));