1 // SMESH StdMeshers_Penta_3D implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : StdMeshers_Penta_3D.cxx
27 #include "StdMeshers_Penta_3D.hxx"
29 #include "utilities.h"
30 #include "Utils_ExceptHandlers.hxx"
32 #include "SMDS_EdgePosition.hxx"
33 #include "SMDS_MeshElement.hxx"
34 #include "SMDS_VolumeOfNodes.hxx"
35 #include "SMDS_VolumeTool.hxx"
36 #include "SMESHDS_SubMesh.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_subMesh.hxx"
39 #include "SMESH_MeshEditor.hxx"
41 #include <BRep_Tool.hxx>
42 #include <TopAbs_ShapeEnum.hxx>
44 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
45 #include <TopTools_IndexedMapOfShape.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>
54 #include <BRepTools.hxx>
55 #include <BRepTools_WireExplorer.hxx>
56 #include <TopTools_MapOfShape.hxx>
63 typedef map < int, int, less<int> >::iterator \
64 StdMeshers_IteratorOfDataMapOfIntegerInteger;
66 //=======================================================================
67 //function : StdMeshers_Penta_3D
69 //=======================================================================
70 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
74 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
75 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
79 //=======================================================================
80 //function : ~StdMeshers_Penta_3D
82 //=======================================================================
84 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
90 //=======================================================================
93 //=======================================================================
94 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
95 const TopoDS_Shape& aShape)
97 MESSAGE("StdMeshers_Penta_3D::Compute()");
111 myTool = new SMESH_MesherHelper(aMesh);
112 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
117 delete myTool; myTool = 0;
123 delete myTool; myTool = 0;
129 delete myTool; myTool = 0;
137 delete myTool; myTool = 0;
143 delete myTool; myTool = 0;
147 //=======================================================================
148 //function : MakeNodes
150 //=======================================================================
151 void StdMeshers_Penta_3D::MakeNodes()
156 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
158 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
159 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
160 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
161 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
162 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
166 SMESH_Mesh* pMesh=GetMesh();
168 // 1. Define the sizes of mesh
170 // 1.1 Horizontal size
172 for (i=0; i<aNbSIDs; ++i) {
173 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
174 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
176 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
177 if(!myCreateQuadratic) {
178 iNbN = aSM->NbNodes();
182 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
184 const SMDS_MeshNode* aNode = itn->next();
185 if(myTool->IsMedium(aNode))
192 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
197 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
198 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
200 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
201 if(!myCreateQuadratic) {
202 iNbN = aSM->NbNodes();
206 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
208 const SMDS_MeshNode* aNode = itn->next();
209 if(myTool->IsMedium(aNode))
216 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
218 aSize=myISize*myJSize;
219 myTNodes.resize(aSize);
221 StdMeshers_TNode aTNode;
225 // 2. Fill the repers on base face (Z=0)
228 for (k=0; k<aNbSIDs; ++k) {
230 const TopoDS_Shape& aS = myBlock.Shape(aSID);
231 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
233 const SMDS_MeshNode* aNode = ite->next();
234 if(myTool->IsMedium(aNode))
236 aNodeID=aNode->GetID();
238 aTNode.SetNode(aNode);
239 aTNode.SetShapeSupportID(aSID);
240 aTNode.SetBaseNodeID(aNodeID);
242 if ( SMESH_Block::IsEdgeID (aSID)) {
243 const SMDS_EdgePosition* epos =
244 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
245 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
251 aP3D.SetCoord(aX, aY, aZ);
252 myBlock.ComputeParameters(aP3D, aS, aCoords);
254 iErr = myBlock.ErrorStatus();
256 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
257 "SMESHBlock: ComputeParameters operation failed");
258 myErrorStatus=101; // SMESHBlock: ComputeParameters operation failed
261 aTNode.SetNormCoord(aCoords);
270 int iShapeSupportID, iBaseNodeID;
272 //printf("\n\n*** Base Face\n");
274 for (j=0; j<myJSize; ++j) {
276 const StdMeshers_TNode& aTNode=myTNodes[ij];
277 iShapeSupportID=aTNode.ShapeSupportID();
278 iBaseNodeID=aTNode.BaseNodeID();
279 const gp_XYZ& aXYZ=aTNode.NormCoord();
280 printf("*** j:%d bID#%d iSS:%d { %lf %lf %lf }\n",
281 j, iBaseNodeID, iShapeSupportID, aXYZ.X(), aXYZ.Y(), aXYZ.Z());
288 // 3. Finding of Z-layers
289 // vector<double> aZL(myISize);
290 // vector<double>::iterator aItZL1, aItZL2 ;
292 // const TopoDS_Shape& aE00z=myBlock.Shape(SMESH_Block::ID_E00z);
293 // SMDS_NodeIteratorPtr aItaE00z =
294 // pMesh->GetSubMeshContaining(aE00z)->GetSubMeshDS()->GetNodes();
298 // while (aItaE00z->more()) {
299 // const SMDS_MeshNode* aNode=aItaE00z->next();
300 // const SMDS_EdgePosition* epos =
301 // static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
302 // myBlock.ComputeParameters( epos->GetUParameter(), aE00z, aCoords );
303 // iErr=myBlock.ErrorStatus();
305 // MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
306 // "SMESHBlock: ComputeParameters operation failed");
307 // myErrorStatus=101; // SMESHBlock: ComputeParameters operation failed
310 // aZL[i]=aCoords.Z();
315 // aItZL1=aZL.begin();
318 // // Sorting the layers
319 // sort(aItZL1, aItZL2);
322 printf("** \n\n Layers begin\n");
323 for(i=0, aItZL=aItZL1; aItZL!=aItZL2; ++aItZL, ++i) {
324 printf(" #%d : %lf\n", i, *aItZL);
326 printf("** Layers end\n");
332 // 3.1 Fill maps of wall nodes
333 SMESH_Block::TShapeID wallFaceID[4] = {
334 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
335 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
337 SMESH_Block::TShapeID baseEdgeID[4] = {
338 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
339 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
341 for ( i = 0; i < 4; ++i ) {
342 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
343 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
344 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
345 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
348 myErrorStatus = i + 1;
349 MESSAGE(" Cant LoadIJNodes() from a wall face " << myErrorStatus );
354 // 3.2 find node columns for vertical edges and edge IDs
355 vector<const SMDS_MeshNode*> * verticEdgeNodes[ 4 ];
356 SMESH_Block::TShapeID verticEdgeID [ 4 ];
357 for ( i = 0; i < 4; ++i ) { // 4 first base nodes are nodes on vertices
359 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
360 ShapeSupportID(false, vID, eID);
361 verticEdgeID[ i ] = eID;
363 StdMeshers_TNode& aTNode = myTNodes[ i ];
364 verticEdgeNodes[ i ] = 0;
365 for ( j = 0; j < 4; ++j ) { // loop on 4 wall faces
366 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
367 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
368 if ( ijNodes.begin()->second[0] == aTNode.Node() )
369 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
370 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
371 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
372 if ( verticEdgeNodes[ i ] )
377 // 3.3 set XYZ of vertices, and initialize of the rest
378 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
379 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
380 if ( SMESH_Block::IsVertexID( id )) {
381 TopoDS_Shape V = myBlock.Shape( id );
382 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
383 const SMDS_MeshNode* n = sm->GetNodes()->next();
384 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
387 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
391 // 4. Fill the rest repers
394 SMESH_Block::TShapeID aSSID, aBNSSID;
395 StdMeshers_TNode aTN;
398 // create top face and find UV for it's corners
399 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
400 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
401 int topfaceID = meshDS->ShapeToIndex(TopFace);
402 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
403 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
404 const SMDS_MeshNode* N = itn->next();
405 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
406 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
407 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
409 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
410 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
411 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
413 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
414 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
415 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
417 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
419 for (j=0; j<myJSize; ++j) {
421 const StdMeshers_TNode& aBN = myTNodes[j];
422 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
423 iBNID = aBN.BaseNodeID();
424 const gp_XYZ& aBNXYZ = aBN.NormCoord();
425 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 );
427 // set XYZ on horizontal edges and get node columns of faces:
428 // 2 columns for each face, between which a base node is located
429 vector<const SMDS_MeshNode*>* nColumns[8];
430 double ratio[4]; // base node position between columns [0.-1.]
432 for ( k = 0; k < 4; ++k ) {
433 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
434 nColumns[k*2], nColumns[k*2+1]);
438 // XYZ on the bottom and top faces
439 const SMDS_MeshNode* n = aBN.Node();
440 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
441 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
443 // first create or find a top node, then the rest ones in a column
444 for (i=myISize-1; i>0; --i) {
445 bIsUpperLayer = (i==(myISize-1));
446 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
448 // set XYZ on vertical edges and faces
449 for ( k = 0; k < 4; ++k ) {
450 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
451 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
453 n = (*nColumns[k*2]) [ i ];
456 tmp1 = myTool->GetNodeUV(TopFace,n);
457 tmp1 = ( 1. - ratio[ k ]) * tmp1;
459 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
460 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
461 n = (*nColumns[k*2+1]) [ i ];
462 xyz.SetCoord( n->X(), n->Y(), n->Z() );
463 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
465 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
466 tmp1 += ratio[ k ] * tmp2;
478 // fill current node info
481 // -normalized coordinates
485 aZ=(double)i/(double)(myISize-1);
486 aCoords.SetCoord(aX, aY, aZ);
488 // suporting shape ID
489 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
491 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
495 aTN.SetShapeSupportID(aSSID);
496 aTN.SetNormCoord(aCoords);
497 aTN.SetBaseNodeID(iBNID);
499 if (aSSID!=SMESH_Block::ID_NONE){
500 // try to find the node
501 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
502 FindNodeOnShape(aS, aCoords, i, aTN);
505 // create node and get it id
506 CreateNode (bIsUpperLayer, aCoords, aTN);
508 if ( bIsUpperLayer ) {
509 const SMDS_MeshNode* n = aTN.Node();
510 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
511 // set node on top face:
512 // find UV parameter for this node
514 // UV011+-----+----------+UV111
517 // UV_E0y1+ +node +UV_E1y1
521 // UV001+-----+----------+UV101
524 double u = aCoords.X(), v = aCoords.Y();
525 double u1 = ( 1. - u ), v1 = ( 1. - v );
526 aP.ChangeCoord() = UV_Ex01 * v1;
527 aP.ChangeCoord() += UV_Ex11 * v;
528 aP.ChangeCoord() += UV_E0y1 * u1;
529 aP.ChangeCoord() += UV_E1y1 * u;
530 aP.ChangeCoord() -= UV001 * u1 * v1;
531 aP.ChangeCoord() -= UV101 * u * v1;
532 aP.ChangeCoord() -= UV011 * u1 * v;
533 aP.ChangeCoord() -= UV111 * u * v;
534 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
538 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
548 int iSSID, iBNID, aID;
550 for (i=0; i<myISize; ++i) {
551 printf(" Layer# %d\n", i);
552 for (j=0; j<myJSize; ++j) {
554 const StdMeshers_TNode& aTN=myTNodes[ij];
555 //const StdMeshers_TNode& aTN=aTNodes[ij];
556 const gp_XYZ& aXYZ=aTN.NormCoord();
557 iSSID=aTN.ShapeSupportID();
558 iBNID=aTN.BaseNodeID();
560 const SMDS_MeshNode* aNode=aTN.Node();
565 printf("*** j:%d BNID#%d iSSID:%d ID:%d { %lf %lf %lf }, { %lf %lf %lf }\n",
566 j, iBNID, iSSID, aID, aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aX, aY, aZ);
575 //=======================================================================
576 //function : FindNodeOnShape
578 //=======================================================================
580 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
581 const gp_XYZ& aParams,
583 StdMeshers_TNode& aTN)
587 double aX, aY, aZ, aD, aTol2, minD;
590 SMESH_Mesh* pMesh = GetMesh();
591 aTol2 = myTol3D*myTol3D;
593 SMDS_MeshNode* pNode = NULL;
595 if ( aS.ShapeType() == TopAbs_FACE ||
596 aS.ShapeType() == TopAbs_EDGE ) {
597 // find a face ID to which aTN belongs to
599 if ( aS.ShapeType() == TopAbs_FACE )
600 faceID = myBlock.ShapeID( aS );
601 else { // edge maybe vertical or top horizontal
602 gp_XYZ aCoord = aParams;
603 if ( aCoord.Z() == 1. )
604 aCoord.SetZ( 0.5 ); // move from top down
606 aCoord.SetX( 0.5 ); // move along X
607 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
609 ASSERT( SMESH_Block::IsFaceID( faceID ));
610 int fIndex = SMESH_Block::ShapeIndex( faceID );
611 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
612 // look for a base node in ijNodes
613 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
614 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
615 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
616 if ( par_nVec->second[ 0 ] == baseNode ) {
617 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
623 myBlock.Point(aParams, aS, aP1);
625 SMDS_NodeIteratorPtr ite=
626 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
628 const SMDS_MeshNode* aNode = ite->next();
629 if(myTool->IsMedium(aNode))
634 aP2.SetCoord(aX, aY, aZ);
635 aD=(double)aP1.SquareDistance(aP2);
636 //printf("** D=%lf ", aD, aTol2);
638 pNode=(SMDS_MeshNode*)aNode;
648 //aTN.SetNode(pNode);
649 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
650 //myErrorStatus=11; // can not find the node;
654 //=======================================================================
655 //function : SetHorizEdgeXYZ
657 //=======================================================================
659 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
661 vector<const SMDS_MeshNode*>*& aCol1,
662 vector<const SMDS_MeshNode*>*& aCol2)
664 // find base and top edges of the face
665 vector< int > edgeVec; // 0-base, 1-top
666 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
668 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ 0 ] );
669 double param = aBaseNodeParams.Coord( coord );
670 if ( !myBlock.IsForwadEdge( edgeVec[ 0 ] ))
673 // look for columns around param
674 StdMeshers_IJNodeMap & ijNodes =
675 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
676 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
677 while ( par_nVec_1->first < param )
679 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
682 if ( par_nVec_1 != ijNodes.begin() ) {
684 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
686 aCol1 = & par_nVec_1->second;
687 aCol2 = & par_nVec_2->second;
690 const SMDS_MeshNode* n1 = aCol1->front();
691 const SMDS_MeshNode* n2 = aCol2->front();
692 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() ), xyz2( n2->X(), n2->Y(), n2->Z() );
693 myShapeXYZ[ edgeVec[ 0 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
698 xyz1.SetCoord( n1->X(), n1->Y(), n1->Z() );
699 xyz2.SetCoord( n2->X(), n2->Y(), n2->Z() );
700 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
706 //=======================================================================
707 //function : MakeVolumeMesh
709 //=======================================================================
710 void StdMeshers_Penta_3D::MakeVolumeMesh()
714 int i, j, ij, ik, i1, i2, aSSID;
716 SMESH_Mesh* pMesh = GetMesh();
717 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
719 int shapeID = meshDS->ShapeToIndex( myShape );
721 // 1. Set Node In Volume
723 for (i=1; i<ik; ++i){
724 for (j=0; j<myJSize; ++j){
726 const StdMeshers_TNode& aTN = myTNodes[ij];
727 aSSID=aTN.ShapeSupportID();
728 if (aSSID==SMESH_Block::ID_NONE) {
729 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
730 meshDS->SetNodeInVolume(aNode, shapeID);
735 // 2. Make pentahedrons
737 vector<const SMDS_MeshNode*> aN;
739 SMDS_ElemIteratorPtr itf, aItNodes;
741 const TopoDS_Face& aFxy0=
742 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
743 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
744 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
746 itf = aSM0->GetElements();
748 const SMDS_MeshElement* pE0 = itf->next();
750 int nbFaceNodes = pE0->NbNodes();
751 if(myCreateQuadratic)
752 nbFaceNodes = nbFaceNodes/2;
753 if ( aN.size() < nbFaceNodes * 2 )
754 aN.resize( nbFaceNodes * 2 );
757 aItNodes=pE0->nodesIterator();
758 while (aItNodes->more()) {
759 //const SMDS_MeshElement* pNode = aItNodes->next();
760 const SMDS_MeshNode* pNode =
761 static_cast<const SMDS_MeshNode*> (aItNodes->next());
762 if(myTool->IsMedium(pNode))
764 aID0 = pNode->GetID();
765 aJ[k] = GetIndexOnLayer(aID0);
767 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
775 for (i=0; i<ik; ++i) {
778 for(j=0; j<nbFaceNodes; ++j) {
779 ij = i1*myJSize+aJ[j];
780 const StdMeshers_TNode& aTN1 = myTNodes[ij];
781 const SMDS_MeshNode* aN1 = aTN1.Node();
785 const StdMeshers_TNode& aTN2 = myTNodes[ij];
786 const SMDS_MeshNode* aN2 = aTN2.Node();
787 aN[j+nbFaceNodes] = aN2;
789 // check if volume orientation will be ok
791 SMDS_VolumeTool vTool;
792 switch ( nbFaceNodes ) {
794 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
795 aN[3], aN[4], aN[5]);
796 vTool.Set( &tmpVol );
800 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
801 aN[4], aN[5], aN[6], aN[7]);
802 vTool.Set( &tmpVol );
808 forward = vTool.IsForward();
811 SMDS_MeshVolume* aV = 0;
812 switch ( nbFaceNodes ) {
815 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
816 // aN[3], aN[4], aN[5]);
817 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
820 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
821 // aN[3], aN[5], aN[4]);
822 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
827 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
828 // aN[4], aN[5], aN[6], aN[7]);
829 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
830 aN[4], aN[5], aN[6], aN[7]);
833 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
834 // aN[4], aN[7], aN[6], aN[5]);
835 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
836 aN[4], aN[7], aN[6], aN[5]);
842 meshDS->SetMeshElementOnShape(aV, shapeID);
847 //=======================================================================
848 //function : MakeMeshOnFxy1
850 //=======================================================================
851 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
855 int aID0, aJ, aLevel, ij, aNbNodes, k;
857 SMDS_NodeIteratorPtr itn;
858 SMDS_ElemIteratorPtr itf, aItNodes;
859 SMDSAbs_ElementType aElementType;
861 const TopoDS_Face& aFxy0=
862 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
863 const TopoDS_Face& aFxy1=
864 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
866 SMESH_Mesh* pMesh = GetMesh();
867 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
869 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
870 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
872 // set nodes on aFxy1
874 itn = aSM0->GetNodes();
875 aNbNodes = aSM0->NbNodes();
876 //printf("** aNbNodes=%d\n", aNbNodes);
879 // set elements on aFxy1
880 vector<const SMDS_MeshNode*> aNodes1;
882 itf = aSM0->GetElements();
884 const SMDS_MeshElement* pE0 = itf->next();
885 aElementType = pE0->GetType();
886 if (!aElementType==SMDSAbs_Face) {
889 aNbNodes = pE0->NbNodes();
890 if(myCreateQuadratic)
891 aNbNodes = aNbNodes/2;
892 // if (aNbNodes!=3) {
895 if ( aNodes1.size() < aNbNodes )
896 aNodes1.resize( aNbNodes );
898 k = aNbNodes-1; // reverse a face
899 aItNodes = pE0->nodesIterator();
900 while (aItNodes->more()) {
901 //const SMDS_MeshElement* pNode = aItNodes->next();
902 const SMDS_MeshNode* pNode =
903 static_cast<const SMDS_MeshNode*> (aItNodes->next());
904 if(myTool->IsMedium(pNode))
906 aID0 = pNode->GetID();
907 aJ = GetIndexOnLayer(aID0);
909 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
913 ij = aLevel*myJSize + aJ;
914 const StdMeshers_TNode& aTN1 = myTNodes[ij];
915 const SMDS_MeshNode* aN1 = aTN1.Node();
919 SMDS_MeshFace * face = 0;
920 switch ( aNbNodes ) {
922 //face = meshDS->AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
923 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
926 //face = meshDS->AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
927 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
932 meshDS->SetMeshElementOnShape(face, aFxy1);
936 //=======================================================================
937 //function : ClearMeshOnFxy1
939 //=======================================================================
940 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
944 SMESH_subMesh* aSubMesh;
945 SMESH_Mesh* pMesh=GetMesh();
947 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
948 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
950 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
953 //=======================================================================
954 //function : GetIndexOnLayer
956 //=======================================================================
957 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
962 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
964 aMapIt=myConnectingMap.find(aID);
965 if (aMapIt==myConnectingMap.end()) {
973 //=======================================================================
974 //function : MakeConnectingMap
976 //=======================================================================
977 void StdMeshers_Penta_3D::MakeConnectingMap()
981 for (j=0; j<myJSize; ++j) {
982 const StdMeshers_TNode& aBN=myTNodes[j];
983 aBNID=aBN.BaseNodeID();
984 myConnectingMap[aBNID]=j;
988 //=======================================================================
989 //function : CreateNode
991 //=======================================================================
992 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
993 const gp_XYZ& aParams,
994 StdMeshers_TNode& aTN)
1003 SMDS_MeshNode* pNode=NULL;
1006 // if (bIsUpperLayer) {
1007 // // point on face Fxy1
1008 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
1009 // myBlock.Point(aParams, aS, aP);
1012 // // point inside solid
1013 // myBlock.Point(aParams, aP);
1015 if (bIsUpperLayer) {
1016 double u = aParams.X(), v = aParams.Y();
1017 double u1 = ( 1. - u ), v1 = ( 1. - v );
1018 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
1019 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
1020 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
1021 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
1023 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
1024 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
1025 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
1026 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
1029 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
1032 // iErr=myBlock.ErrorStatus();
1034 // myErrorStatus=12; // can not find the node point;
1038 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
1040 SMESH_Mesh* pMesh = GetMesh();
1041 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
1043 pNode = pMeshDS->AddNode(aX, aY, aZ);
1048 //=======================================================================
1049 //function : ShapeSupportID
1051 //=======================================================================
1052 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
1053 const SMESH_Block::TShapeID aBNSSID,
1054 SMESH_Block::TShapeID& aSSID)
1059 case SMESH_Block::ID_V000:
1060 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
1062 case SMESH_Block::ID_V100:
1063 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
1065 case SMESH_Block::ID_V110:
1066 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
1068 case SMESH_Block::ID_V010:
1069 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
1071 case SMESH_Block::ID_Ex00:
1072 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
1074 case SMESH_Block::ID_Ex10:
1075 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
1077 case SMESH_Block::ID_E0y0:
1078 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
1080 case SMESH_Block::ID_E1y0:
1081 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
1083 case SMESH_Block::ID_Fxy0:
1084 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1087 aSSID=SMESH_Block::ID_NONE;
1088 myErrorStatus=10; // Can not find supporting shape ID
1093 //=======================================================================
1094 //function : MakeBlock
1096 //=======================================================================
1097 void StdMeshers_Penta_3D::MakeBlock()
1102 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1104 TopoDS_Vertex aV000, aV001;
1106 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1107 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1108 TopTools_ListIteratorOfListOfShape aIt;
1110 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1112 // 0. Find triangulated face aFTr
1113 SMDSAbs_ElementType aElementType;
1114 SMESH_Mesh* pMesh=GetMesh();
1118 for (i=1; i<=iNbF; ++i) {
1119 const TopoDS_Shape& aF = aM(i);
1120 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1122 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1123 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1124 while(itf->more()) {
1125 const SMDS_MeshElement * pElement = itf->next();
1126 aElementType = pElement->GetType();
1127 if (aElementType==SMDSAbs_Face) {
1128 iNbNodes = pElement->NbNodes();
1129 if ( iNbNodes==3 || (myCreateQuadratic && iNbNodes==6) ) {
1134 // The current algorithm fails if there is more that one
1135 // face wich contains triangles ...
1136 // In that case, replace return by break to try another
1137 // method (coded in "if (iCnt != 1) { ... }")
1139 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1140 // myErrorStatus=5; // more than one face has triangulation
1152 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1153 // was not reached 'cause it was not called from Hexa_3D ... Now it
1154 // can occurs and in my opinion, it is the most common case.
1157 // The suggested algorithm is the following :
1159 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1160 // then the shape is tologically equivalent to a box
1161 // o In a box, there are three set of four // edges ...
1162 // In the cascade notation, it seems to be the edges
1167 // o For each one of this set, check if the four edges
1168 // have the same number of element.
1169 // o If so, check if the "corresponding" // faces contains
1170 // only quads. It's the faces numbered:
1174 // o If so, check if the opposite edges of each // faces
1175 // have the same number of elements. It is the edges
1177 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1178 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1179 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1180 // o If so, check if the two other faces have the same
1181 // number of elements. It is the faces numbered:
1185 // This test should be improved to test if the nodes
1186 // of the two faces are really "en face".
1187 // o If so, one of the two faces is a candidate to an extrusion,
1188 // It is the faces numbered :
1192 // o Finally, if there is only one candidate, let do the
1193 // extrusion job for the corresponding face
1197 int iNbF = aM.Extent();
1200 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1201 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1202 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1203 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1204 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1205 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1207 int has_only_quad_f1 = 1;
1208 int has_only_quad_f2 = 1;
1209 int has_only_quad_f3 = 1;
1210 int has_only_quad_f4 = 1;
1211 int has_only_quad_f5 = 1;
1212 int has_only_quad_f6 = 1;
1214 for (i=1; i<=iNbF; ++i) {
1216 const TopoDS_Shape& aF = aM(i);
1217 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1218 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1219 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1220 while(itf->more()) {
1221 const SMDS_MeshElement * pElement = itf->next();
1222 aElementType = pElement->GetType();
1223 if (aElementType==SMDSAbs_Face) {
1224 iNbNodes = pElement->NbNodes();
1225 if ( iNbNodes!=4 ) {
1231 if (i==1) has_only_quad_f1 = ok ;
1232 if (i==2) has_only_quad_f2 = ok ;
1233 if (i==3) has_only_quad_f3 = ok ;
1234 if (i==4) has_only_quad_f4 = ok ;
1235 if (i==5) has_only_quad_f5 = ok ;
1236 if (i==6) has_only_quad_f6 = ok ;
1239 TopTools_IndexedMapOfShape aE;
1240 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1241 int iNbE = aE.Extent();
1244 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1245 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1246 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1247 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1248 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1249 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1250 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1251 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1252 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1253 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1254 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1255 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1259 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1260 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1261 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1269 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1270 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1271 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1279 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1280 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1281 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1297 myErrorStatus=5; // more than one face has triangulation
1303 // 1. Vetrices V00, V001;
1305 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1306 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1308 // 1.1 Base vertex V000
1309 iNbE = aME.Extent();
1311 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1312 myErrorStatus=7; // too few edges are in base face aFTr
1315 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1316 aV000=TopExp::FirstVertex(aE1);
1318 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1319 aIt.Initialize(aLE);
1320 for (; aIt.More(); aIt.Next()) {
1321 const TopoDS_Shape& aEx=aIt.Value();
1324 iNbEV=aMEV.Extent();
1326 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1327 myErrorStatus=7; // too few edges meet in base vertex
1333 for (j=1; j<=iNbEV; ++j) {
1334 const TopoDS_Shape& aEx=aMEV(j);
1335 if (!aME.Contains(aEx)) {
1336 TopoDS_Vertex aV[2];
1338 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1339 TopExp::Vertices(aE, aV[0], aV[1]);
1340 for (i=0; i<2; ++i) {
1341 if (!aV[i].IsSame(aV000)) {
1351 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1352 myErrorStatus=8; // can not find reper V001
1356 //gp_Pnt aP000, aP001;
1358 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1359 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1360 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1361 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1365 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1368 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1369 myErrorStatus=9; // number of shells in source shape !=1
1374 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1375 myBlock.Load(aShell, aV000, aV001);
1376 iErr = myBlock.ErrorStatus();
1378 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1379 myErrorStatus=100; // SMESHBlock: Load operation failed
1383 //=======================================================================
1384 //function : CheckData
1386 //=======================================================================
1387 void StdMeshers_Penta_3D::CheckData()
1392 int iNbEx[]={8, 12, 6};
1394 TopAbs_ShapeEnum aST;
1395 TopAbs_ShapeEnum aSTEx[]={
1396 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1398 TopTools_IndexedMapOfShape aM;
1400 if (myShape.IsNull()){
1401 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1402 myErrorStatus=2; // null shape
1406 aST=myShape.ShapeType();
1407 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1408 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1409 myErrorStatus=3; // not compatible type of shape
1413 for (i=0; i<3; ++i) {
1415 TopExp::MapShapes(myShape, aSTEx[i], aM);
1418 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1419 myErrorStatus=4; // number of subshape is not compatible
1425 //=======================================================================
1426 //function : LoadIJNodes
1427 //purpose : Load nodes bound to theFace into column (vectors) and rows
1429 // The value of theIJNodes map is a vector of ordered nodes so
1430 // that the 0-the one lies on theBaseEdge.
1431 // The key of theIJNodes map is a normalized parameter of each
1432 // 0-the node on theBaseEdge.
1433 //=======================================================================
1435 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1436 const TopoDS_Face& theFace,
1437 const TopoDS_Edge& theBaseEdge,
1438 SMESHDS_Mesh* theMesh)
1440 // get vertices of theBaseEdge
1441 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1442 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1443 TopExp::Vertices( eFrw, vfb, vlb );
1445 // find the other edges of theFace and orientation of e1
1446 TopoDS_Edge e1, e2, eTop;
1447 bool rev1, CumOri = false;
1448 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1450 for ( ; exp.More(); exp.Next() ) {
1451 if ( ++nbEdges > 4 ) {
1452 return false; // more than 4 edges in theFace
1454 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1455 if ( theBaseEdge.IsSame( e ))
1457 TopoDS_Vertex vCommon;
1458 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1460 else if ( vCommon.IsSame( vfb )) {
1462 vft = TopExp::LastVertex( e1, CumOri );
1463 rev1 = vfb.IsSame( vft );
1465 vft = TopExp::FirstVertex( e1, CumOri );
1470 if ( nbEdges < 4 ) {
1471 return false; // less than 4 edges in theFace
1474 // submeshes corresponding to shapes
1475 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1476 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1477 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1478 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1479 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1480 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1481 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1482 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1483 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1484 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1485 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1488 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1489 MESSAGE(" Diff nb of nodes on opposite edges" );
1492 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1493 MESSAGE("Empty submesh of vertex");
1496 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1497 // check quadratic case
1498 if ( myCreateQuadratic ) {
1499 int n1 = sm1->NbNodes()/2;
1500 int n2 = smb->NbNodes()/2;
1501 int n3 = sm1->NbNodes() - n1;
1502 int n4 = smb->NbNodes() - n2;
1503 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1504 if( nf != smFace->NbNodes() ) {
1505 MESSAGE( "Wrong nb face nodes: " <<
1506 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1511 MESSAGE( "Wrong nb face nodes: " <<
1512 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1517 int vsize = sm1->NbNodes() + 2;
1518 int hsize = smb->NbNodes() + 2;
1519 if(myCreateQuadratic) {
1520 vsize = vsize - sm1->NbNodes()/2 -1;
1521 hsize = hsize - smb->NbNodes()/2 -1;
1524 // load nodes from theBaseEdge
1526 set<const SMDS_MeshNode*> loadedNodes;
1527 const SMDS_MeshNode* nullNode = 0;
1529 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1530 nVecf.resize( vsize, nullNode );
1531 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1533 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1534 nVecl.resize( vsize, nullNode );
1535 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1538 BRep_Tool::Range( eFrw, f, l );
1539 double range = l - f;
1540 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1541 const SMDS_MeshNode* node;
1542 while ( nIt->more() ) {
1544 if(myTool->IsMedium(node))
1546 const SMDS_EdgePosition* pos =
1547 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1551 double u = ( pos->GetUParameter() - f ) / range;
1552 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1553 nVec.resize( vsize, nullNode );
1554 loadedNodes.insert( nVec[ 0 ] = node );
1556 if ( theIJNodes.size() != hsize ) {
1557 MESSAGE( "Wrong node positions on theBaseEdge" );
1561 // load nodes from e1
1563 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1564 nIt = sm1->GetNodes();
1565 while ( nIt->more() ) {
1567 if(myTool->IsMedium(node))
1569 const SMDS_EdgePosition* pos =
1570 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1574 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1576 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1577 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1578 int row = rev1 ? vsize - 1 : 0;
1579 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1582 loadedNodes.insert( nVecf[ row ] = u_n->second );
1585 // try to load the rest nodes
1587 // get all faces from theFace
1588 map<int,const SMDS_MeshElement*> allFaces, foundFaces;
1589 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1590 while ( eIt->more() ) {
1591 const SMDS_MeshElement* e = eIt->next();
1592 if ( e->GetType() == SMDSAbs_Face )
1593 allFaces.insert( make_pair(e->GetID(),e) );
1595 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1596 // the nodes belong to, and between the nodes of the found face,
1597 // look for a not loaded node considering this node to be the next
1598 // in a column of the starting second node. Repeat, starting
1599 // from nodes next to the previous starting nodes in their columns,
1600 // and so on while a face can be found. Then go the the next pair
1601 // of nodes on theBaseEdge.
1602 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1603 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1606 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1609 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1610 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1611 const SMDS_MeshElement* face = 0;
1613 // look for a face by 2 nodes
1614 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1616 int nbFaceNodes = face->NbNodes();
1617 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1618 (myCreateQuadratic && nbFaceNodes>8) ) {
1619 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1622 // look for a not loaded node of the <face>
1624 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1625 eIt = face->nodesIterator() ;
1626 while ( !found && eIt->more() ) {
1627 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1628 if(myTool->IsMedium(node))
1630 found = loadedNodes.insert( node ).second;
1631 if ( !found && node != n1 && node != n2 )
1635 if ( ++row > vsize - 1 ) {
1636 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1639 par_nVec_2->second[ row ] = node;
1640 foundFaces.insert( make_pair(face->GetID(),face) );
1642 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1643 n1 = par_nVec_1->second[ row ];
1646 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1647 n3 == par_nVec_1->second[ row ] ) {
1651 MESSAGE( "Not quad mesh, column "<< col );
1656 while ( face && n1 && n2 );
1658 if ( row < vsize - 1 ) {
1659 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1660 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1661 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1662 MESSAGE( "Current node 1: "<< n1);
1663 MESSAGE( "Current node 2: "<< n2);
1664 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1665 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1668 } // loop on columns
1673 //////////////////////////////////////////////////////////////////////////
1675 // StdMeshers_SMESHBlock
1677 //////////////////////////////////////////////////////////////////////////
1679 //=======================================================================
1680 //function : StdMeshers_SMESHBlock
1682 //=======================================================================
1683 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1686 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1689 //=======================================================================
1690 //function : IsForwadEdge
1692 //=======================================================================
1694 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1696 int index = myTBlock.ShapeIndex( theEdgeID );
1697 if ( !myTBlock.IsEdgeID( theEdgeID ))
1700 if ( myIsEdgeForward[ index ] < 0 )
1701 myIsEdgeForward[ index ] =
1702 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1704 return myIsEdgeForward[ index ];
1707 //=======================================================================
1708 //function : ErrorStatus
1710 //=======================================================================
1711 int StdMeshers_SMESHBlock::ErrorStatus() const
1713 return myErrorStatus;
1716 //=======================================================================
1719 //=======================================================================
1720 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1722 TopoDS_Vertex aV000, aV001;
1724 Load(theShell, aV000, aV001);
1727 //=======================================================================
1730 //=======================================================================
1731 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1732 const TopoDS_Vertex& theV000,
1733 const TopoDS_Vertex& theV001)
1741 myShapeIDMap.Clear();
1742 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1749 //=======================================================================
1750 //function : ComputeParameters
1752 //=======================================================================
1753 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1756 ComputeParameters(thePnt, myShell, theXYZ);
1759 //=======================================================================
1760 //function : ComputeParameters
1762 //=======================================================================
1763 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1764 const TopoDS_Shape& theShape,
1772 aID = ShapeID(theShape);
1773 if (myErrorStatus) {
1776 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1778 myErrorStatus=4; // problems with computation Parameters
1783 //=======================================================================
1784 //function : ComputeParameters
1786 //=======================================================================
1788 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1789 const TopoDS_Shape& theShape,
1797 aID = ShapeID(theShape);
1798 if (myErrorStatus) {
1801 if ( SMESH_Block::IsEdgeID( aID ))
1802 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1804 myErrorStatus=4; // problems with computation Parameters
1809 //=======================================================================
1812 //=======================================================================
1813 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1818 Point(theParams, aS, aP3D);
1821 //=======================================================================
1824 //=======================================================================
1825 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1826 const TopoDS_Shape& theShape,
1833 gp_XYZ aXYZ(99.,99.,99.);
1836 if (theShape.IsNull()) {
1837 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1841 aID=ShapeID(theShape);
1842 if (myErrorStatus) {
1846 if (SMESH_Block::IsVertexID(aID)) {
1847 bOk = myTBlock.VertexPoint(aID, aXYZ);
1849 else if (SMESH_Block::IsEdgeID(aID)) {
1850 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1853 else if (SMESH_Block::IsFaceID(aID)) {
1854 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1858 myErrorStatus=4; // problems with point computation
1864 //=======================================================================
1865 //function : ShapeID
1867 //=======================================================================
1868 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1873 TopoDS_Shape aSF, aSR;
1876 aSF.Orientation(TopAbs_FORWARD);
1878 aSR.Orientation(TopAbs_REVERSED);
1880 if (myShapeIDMap.Contains(aSF)) {
1881 aID=myShapeIDMap.FindIndex(aSF);
1884 if (myShapeIDMap.Contains(aSR)) {
1885 aID=myShapeIDMap.FindIndex(aSR);
1888 myErrorStatus=2; // unknown shape;
1892 //=======================================================================
1895 //=======================================================================
1896 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1902 aNb=myShapeIDMap.Extent();
1903 if (theID<1 || theID>aNb) {
1904 myErrorStatus=3; // ID is out of range
1905 return myEmptyShape;
1908 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);