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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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) ) {
1133 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1134 myErrorStatus=5; // more than one face has triangulation
1143 // 1. Vetrices V00, V001;
1145 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1146 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1148 // 1.1 Base vertex V000
1149 iNbE = aME.Extent();
1151 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1152 myErrorStatus=7; // too few edges are in base face aFTr
1155 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1156 aV000=TopExp::FirstVertex(aE1);
1158 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1159 aIt.Initialize(aLE);
1160 for (; aIt.More(); aIt.Next()) {
1161 const TopoDS_Shape& aEx=aIt.Value();
1164 iNbEV=aMEV.Extent();
1166 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1167 myErrorStatus=7; // too few edges meet in base vertex
1173 for (j=1; j<=iNbEV; ++j) {
1174 const TopoDS_Shape& aEx=aMEV(j);
1175 if (!aME.Contains(aEx)) {
1176 TopoDS_Vertex aV[2];
1178 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1179 TopExp::Vertices(aE, aV[0], aV[1]);
1180 for (i=0; i<2; ++i) {
1181 if (!aV[i].IsSame(aV000)) {
1191 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1192 myErrorStatus=8; // can not find reper V001
1196 //gp_Pnt aP000, aP001;
1198 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1199 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1200 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1201 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1205 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1208 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1209 myErrorStatus=9; // number of shells in source shape !=1
1214 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1215 myBlock.Load(aShell, aV000, aV001);
1216 iErr = myBlock.ErrorStatus();
1218 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1219 myErrorStatus=100; // SMESHBlock: Load operation failed
1223 //=======================================================================
1224 //function : CheckData
1226 //=======================================================================
1227 void StdMeshers_Penta_3D::CheckData()
1232 int iNbEx[]={8, 12, 6};
1234 TopAbs_ShapeEnum aST;
1235 TopAbs_ShapeEnum aSTEx[]={
1236 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1238 TopTools_IndexedMapOfShape aM;
1240 if (myShape.IsNull()){
1241 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1242 myErrorStatus=2; // null shape
1246 aST=myShape.ShapeType();
1247 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1248 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1249 myErrorStatus=3; // not compatible type of shape
1253 for (i=0; i<3; ++i) {
1255 TopExp::MapShapes(myShape, aSTEx[i], aM);
1258 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1259 myErrorStatus=4; // number of subshape is not compatible
1265 //=======================================================================
1266 //function : LoadIJNodes
1267 //purpose : Load nodes bound to theFace into column (vectors) and rows
1269 // The value of theIJNodes map is a vector of ordered nodes so
1270 // that the 0-the one lies on theBaseEdge.
1271 // The key of theIJNodes map is a normalized parameter of each
1272 // 0-the node on theBaseEdge.
1273 //=======================================================================
1275 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1276 const TopoDS_Face& theFace,
1277 const TopoDS_Edge& theBaseEdge,
1278 SMESHDS_Mesh* theMesh)
1280 // get vertices of theBaseEdge
1281 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1282 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1283 TopExp::Vertices( eFrw, vfb, vlb );
1285 // find the other edges of theFace and orientation of e1
1286 TopoDS_Edge e1, e2, eTop;
1287 bool rev1, CumOri = false;
1288 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1290 for ( ; exp.More(); exp.Next() ) {
1291 if ( ++nbEdges > 4 ) {
1292 return false; // more than 4 edges in theFace
1294 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1295 if ( theBaseEdge.IsSame( e ))
1297 TopoDS_Vertex vCommon;
1298 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1300 else if ( vCommon.IsSame( vfb )) {
1302 vft = TopExp::LastVertex( e1, CumOri );
1303 rev1 = vfb.IsSame( vft );
1305 vft = TopExp::FirstVertex( e1, CumOri );
1310 if ( nbEdges < 4 ) {
1311 return false; // less than 4 edges in theFace
1314 // submeshes corresponding to shapes
1315 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1316 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1317 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1318 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1319 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1320 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1321 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1322 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1323 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1324 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1325 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1328 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1329 MESSAGE(" Diff nb of nodes on opposite edges" );
1332 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1333 MESSAGE("Empty submesh of vertex");
1336 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1337 // check quadratic case
1338 if ( myCreateQuadratic ) {
1339 int n1 = sm1->NbNodes()/2;
1340 int n2 = smb->NbNodes()/2;
1341 int n3 = sm1->NbNodes() - n1;
1342 int n4 = smb->NbNodes() - n2;
1343 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1344 if( nf != smFace->NbNodes() ) {
1345 MESSAGE( "Wrong nb face nodes: " <<
1346 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1351 MESSAGE( "Wrong nb face nodes: " <<
1352 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1357 int vsize = sm1->NbNodes() + 2;
1358 int hsize = smb->NbNodes() + 2;
1359 if(myCreateQuadratic) {
1360 vsize = vsize - sm1->NbNodes()/2 -1;
1361 hsize = hsize - smb->NbNodes()/2 -1;
1364 // load nodes from theBaseEdge
1366 set<const SMDS_MeshNode*> loadedNodes;
1367 const SMDS_MeshNode* nullNode = 0;
1369 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1370 nVecf.resize( vsize, nullNode );
1371 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1373 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1374 nVecl.resize( vsize, nullNode );
1375 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1378 BRep_Tool::Range( eFrw, f, l );
1379 double range = l - f;
1380 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1381 const SMDS_MeshNode* node;
1382 while ( nIt->more() ) {
1384 if(myTool->IsMedium(node))
1386 const SMDS_EdgePosition* pos =
1387 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1391 double u = ( pos->GetUParameter() - f ) / range;
1392 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1393 nVec.resize( vsize, nullNode );
1394 loadedNodes.insert( nVec[ 0 ] = node );
1396 if ( theIJNodes.size() != hsize ) {
1397 MESSAGE( "Wrong node positions on theBaseEdge" );
1401 // load nodes from e1
1403 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1404 nIt = sm1->GetNodes();
1405 while ( nIt->more() ) {
1407 if(myTool->IsMedium(node))
1409 const SMDS_EdgePosition* pos =
1410 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1414 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1416 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1417 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1418 int row = rev1 ? vsize - 1 : 0;
1419 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1422 loadedNodes.insert( nVecf[ row ] = u_n->second );
1425 // try to load the rest nodes
1427 // get all faces from theFace
1428 map<int,const SMDS_MeshElement*> allFaces, foundFaces;
1429 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1430 while ( eIt->more() ) {
1431 const SMDS_MeshElement* e = eIt->next();
1432 if ( e->GetType() == SMDSAbs_Face )
1433 allFaces.insert( make_pair(e->GetID(),e) );
1435 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1436 // the nodes belong to, and between the nodes of the found face,
1437 // look for a not loaded node considering this node to be the next
1438 // in a column of the starting second node. Repeat, starting
1439 // from nodes next to the previous starting nodes in their columns,
1440 // and so on while a face can be found. Then go the the next pair
1441 // of nodes on theBaseEdge.
1442 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1443 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1446 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1449 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1450 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1451 const SMDS_MeshElement* face = 0;
1453 // look for a face by 2 nodes
1454 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1456 int nbFaceNodes = face->NbNodes();
1457 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1458 (myCreateQuadratic && nbFaceNodes>8) ) {
1459 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1462 // look for a not loaded node of the <face>
1464 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1465 eIt = face->nodesIterator() ;
1466 while ( !found && eIt->more() ) {
1467 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1468 if(myTool->IsMedium(node))
1470 found = loadedNodes.insert( node ).second;
1471 if ( !found && node != n1 && node != n2 )
1475 if ( ++row > vsize - 1 ) {
1476 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1479 par_nVec_2->second[ row ] = node;
1480 foundFaces.insert( make_pair(face->GetID(),face) );
1482 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1483 n1 = par_nVec_1->second[ row ];
1486 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1487 n3 == par_nVec_1->second[ row ] ) {
1491 MESSAGE( "Not quad mesh, column "<< col );
1496 while ( face && n1 && n2 );
1498 if ( row < vsize - 1 ) {
1499 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1500 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1501 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1502 MESSAGE( "Current node 1: "<< n1);
1503 MESSAGE( "Current node 2: "<< n2);
1504 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1505 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1508 } // loop on columns
1513 //////////////////////////////////////////////////////////////////////////
1515 // StdMeshers_SMESHBlock
1517 //////////////////////////////////////////////////////////////////////////
1519 //=======================================================================
1520 //function : StdMeshers_SMESHBlock
1522 //=======================================================================
1523 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1526 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1529 //=======================================================================
1530 //function : IsForwadEdge
1532 //=======================================================================
1534 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1536 int index = myTBlock.ShapeIndex( theEdgeID );
1537 if ( !myTBlock.IsEdgeID( theEdgeID ))
1540 if ( myIsEdgeForward[ index ] < 0 )
1541 myIsEdgeForward[ index ] =
1542 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1544 return myIsEdgeForward[ index ];
1547 //=======================================================================
1548 //function : ErrorStatus
1550 //=======================================================================
1551 int StdMeshers_SMESHBlock::ErrorStatus() const
1553 return myErrorStatus;
1556 //=======================================================================
1559 //=======================================================================
1560 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1562 TopoDS_Vertex aV000, aV001;
1564 Load(theShell, aV000, aV001);
1567 //=======================================================================
1570 //=======================================================================
1571 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1572 const TopoDS_Vertex& theV000,
1573 const TopoDS_Vertex& theV001)
1581 myShapeIDMap.Clear();
1582 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1589 //=======================================================================
1590 //function : ComputeParameters
1592 //=======================================================================
1593 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1596 ComputeParameters(thePnt, myShell, theXYZ);
1599 //=======================================================================
1600 //function : ComputeParameters
1602 //=======================================================================
1603 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1604 const TopoDS_Shape& theShape,
1612 aID = ShapeID(theShape);
1613 if (myErrorStatus) {
1616 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1618 myErrorStatus=4; // problems with computation Parameters
1623 //=======================================================================
1624 //function : ComputeParameters
1626 //=======================================================================
1628 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1629 const TopoDS_Shape& theShape,
1637 aID = ShapeID(theShape);
1638 if (myErrorStatus) {
1641 if ( SMESH_Block::IsEdgeID( aID ))
1642 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1644 myErrorStatus=4; // problems with computation Parameters
1649 //=======================================================================
1652 //=======================================================================
1653 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1658 Point(theParams, aS, aP3D);
1661 //=======================================================================
1664 //=======================================================================
1665 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1666 const TopoDS_Shape& theShape,
1673 gp_XYZ aXYZ(99.,99.,99.);
1676 if (theShape.IsNull()) {
1677 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1681 aID=ShapeID(theShape);
1682 if (myErrorStatus) {
1686 if (SMESH_Block::IsVertexID(aID)) {
1687 bOk = myTBlock.VertexPoint(aID, aXYZ);
1689 else if (SMESH_Block::IsEdgeID(aID)) {
1690 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1693 else if (SMESH_Block::IsFaceID(aID)) {
1694 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1698 myErrorStatus=4; // problems with point computation
1704 //=======================================================================
1705 //function : ShapeID
1707 //=======================================================================
1708 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1713 TopoDS_Shape aSF, aSR;
1716 aSF.Orientation(TopAbs_FORWARD);
1718 aSR.Orientation(TopAbs_REVERSED);
1720 if (myShapeIDMap.Contains(aSF)) {
1721 aID=myShapeIDMap.FindIndex(aSF);
1724 if (myShapeIDMap.Contains(aSR)) {
1725 aID=myShapeIDMap.FindIndex(aSR);
1728 myErrorStatus=2; // unknown shape;
1732 //=======================================================================
1735 //=======================================================================
1736 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1742 aNb=myShapeIDMap.Extent();
1743 if (theID<1 || theID>aNb) {
1744 myErrorStatus=3; // ID is out of range
1745 return myEmptyShape;
1748 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);