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 enum { NB_WALL_FACES = 4 };
68 //=======================================================================
69 //function : StdMeshers_Penta_3D
71 //=======================================================================
72 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
76 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
77 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
81 //=======================================================================
82 //function : ~StdMeshers_Penta_3D
84 //=======================================================================
86 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
92 //=======================================================================
95 //=======================================================================
96 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
97 const TopoDS_Shape& aShape)
99 MESSAGE("StdMeshers_Penta_3D::Compute()");
113 myTool = new SMESH_MesherHelper(aMesh);
114 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
119 delete myTool; myTool = 0;
125 delete myTool; myTool = 0;
131 delete myTool; myTool = 0;
139 delete myTool; myTool = 0;
145 delete myTool; myTool = 0;
149 //=======================================================================
150 //function : MakeNodes
152 //=======================================================================
153 void StdMeshers_Penta_3D::MakeNodes()
158 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
160 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
161 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
162 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
163 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
164 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
168 SMESH_Mesh* pMesh=GetMesh();
170 // 1. Define the sizes of mesh
172 // 1.1 Horizontal size
174 for (i=0; i<aNbSIDs; ++i) {
175 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
176 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
178 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
179 if(!myCreateQuadratic) {
180 iNbN = aSM->NbNodes();
184 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
186 const SMDS_MeshNode* aNode = itn->next();
187 if(myTool->IsMedium(aNode))
194 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
199 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
200 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
202 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
203 if(!myCreateQuadratic) {
204 iNbN = aSM->NbNodes();
208 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
210 const SMDS_MeshNode* aNode = itn->next();
211 if(myTool->IsMedium(aNode))
218 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
220 aSize=myISize*myJSize;
221 myTNodes.resize(aSize);
223 StdMeshers_TNode aTNode;
227 // 2. Fill the repers on base face (Z=0)
230 for (k=0; k<aNbSIDs; ++k) {
232 const TopoDS_Shape& aS = myBlock.Shape(aSID);
233 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
235 const SMDS_MeshNode* aNode = ite->next();
236 if(myTool->IsMedium(aNode))
238 aNodeID=aNode->GetID();
240 aTNode.SetNode(aNode);
241 aTNode.SetShapeSupportID(aSID);
242 aTNode.SetBaseNodeID(aNodeID);
244 if ( SMESH_Block::IsEdgeID (aSID)) {
245 const SMDS_EdgePosition* epos =
246 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
247 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
253 aP3D.SetCoord(aX, aY, aZ);
254 myBlock.ComputeParameters(aP3D, aS, aCoords);
256 iErr = myBlock.ErrorStatus();
258 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
259 "SMESHBlock: ComputeParameters operation failed");
260 myErrorStatus=101; // SMESHBlock: ComputeParameters operation failed
263 aTNode.SetNormCoord(aCoords);
270 // 3.1 Fill maps of wall nodes
271 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
272 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
273 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
275 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
276 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
277 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
279 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
280 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
281 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
282 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
283 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
286 myErrorStatus = i + 1;
287 MESSAGE(" Cant LoadIJNodes() from a wall face " << myErrorStatus );
292 // 3.2 find node columns for vertical edges and edge IDs
293 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
294 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
295 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
297 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
298 ShapeSupportID(false, vID, eID);
299 verticEdgeID[ i ] = eID;
301 StdMeshers_TNode& aTNode = myTNodes[ i ];
302 verticEdgeNodes[ i ] = 0;
303 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
304 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
305 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
306 if ( ijNodes.begin()->second[0] == aTNode.Node() )
307 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
308 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
309 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
310 if ( verticEdgeNodes[ i ] )
315 // 3.3 set XYZ of vertices, and initialize of the rest
316 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
317 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
318 if ( SMESH_Block::IsVertexID( id )) {
319 TopoDS_Shape V = myBlock.Shape( id );
320 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
321 const SMDS_MeshNode* n = sm->GetNodes()->next();
322 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
325 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
329 // 4. Fill the rest repers
332 SMESH_Block::TShapeID aSSID, aBNSSID;
333 StdMeshers_TNode aTN;
336 // create top face and find UV for it's corners
337 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
338 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
339 int topfaceID = meshDS->ShapeToIndex(TopFace);
340 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
341 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
342 const SMDS_MeshNode* N = itn->next();
343 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
344 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
345 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
347 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
348 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
349 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
351 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
352 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
353 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
355 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
357 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
359 const StdMeshers_TNode& aBN = myTNodes[j];
360 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
361 iBNID = aBN.BaseNodeID();
362 const gp_XYZ& aBNXYZ = aBN.NormCoord();
363 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
365 // set XYZ on horizontal edges and get node columns of faces:
366 // 2 columns for each face, between which a base node is located
367 vector<const SMDS_MeshNode*>* nColumns[8];
368 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
370 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
371 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
372 nColumns[k*2], nColumns[k*2+1]);
376 // XYZ on the bottom and top faces
377 const SMDS_MeshNode* n = aBN.Node();
378 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
379 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
381 // first create or find a top node, then the rest ones in a column
382 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
384 bIsUpperLayer = (i==(myISize-1));
385 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
386 if ( createNode ) // a base node is inside a top face
388 // set XYZ on vertical edges and faces
389 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
390 // XYZ on a vertical edge
391 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
392 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
393 // XYZ on a face (part 1 from one column)
394 n = (*nColumns[k*2]) [ i ];
395 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
396 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
398 if( bIsUpperLayer ) {
399 tmp1 = myTool->GetNodeUV(TopFace,n);
400 tmp1 = ( 1. - ratio[ k ]) * tmp1;
402 // XYZ on a face (part 2 from other column)
403 n = (*nColumns[k*2+1]) [ i ];
404 xyz.SetCoord( n->X(), n->Y(), n->Z() );
405 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
406 if( bIsUpperLayer ) {
407 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
408 tmp1 += ratio[ k ] * tmp2;
420 // fill current node info
423 // -normalized coordinates
427 aZ=(double)i/(double)(myISize-1);
428 aCoords.SetCoord(aX, aY, aZ);
430 // suporting shape ID
431 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
433 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
437 aTN.SetShapeSupportID(aSSID);
438 aTN.SetNormCoord(aCoords);
439 aTN.SetBaseNodeID(iBNID);
441 if (aSSID!=SMESH_Block::ID_NONE){
442 // try to find the node
443 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
444 FindNodeOnShape(aS, aCoords, i, aTN);
447 // create node and get it id
448 CreateNode (bIsUpperLayer, aCoords, aTN);
450 if ( bIsUpperLayer ) {
451 const SMDS_MeshNode* n = aTN.Node();
452 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
453 // set node on top face:
454 // find UV parameter for this node
456 // UV011+-----+----------+UV111
459 // UV_E0y1+ +node +UV_E1y1
463 // UV001+-----+----------+UV101
466 double u = aCoords.X(), v = aCoords.Y();
467 double u1 = ( 1. - u ), v1 = ( 1. - v );
468 aP.ChangeCoord() = UV_Ex01 * v1;
469 aP.ChangeCoord() += UV_Ex11 * v;
470 aP.ChangeCoord() += UV_E0y1 * u1;
471 aP.ChangeCoord() += UV_E1y1 * u;
472 aP.ChangeCoord() -= UV001 * u1 * v1;
473 aP.ChangeCoord() -= UV101 * u * v1;
474 aP.ChangeCoord() -= UV011 * u1 * v;
475 aP.ChangeCoord() -= UV111 * u * v;
476 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
480 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
490 int iSSID, iBNID, aID;
492 for (i=0; i<myISize; ++i) {
493 printf(" Layer# %d\n", i);
494 for (j=0; j<myJSize; ++j) {
496 const StdMeshers_TNode& aTN=myTNodes[ij];
497 //const StdMeshers_TNode& aTN=aTNodes[ij];
498 const gp_XYZ& aXYZ=aTN.NormCoord();
499 iSSID=aTN.ShapeSupportID();
500 iBNID=aTN.BaseNodeID();
502 const SMDS_MeshNode* aNode=aTN.Node();
507 printf("*** j:%d BNID#%d iSSID:%d ID:%d { %lf %lf %lf }, { %lf %lf %lf }\n",
508 j, iBNID, iSSID, aID, aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aX, aY, aZ);
517 //=======================================================================
518 //function : FindNodeOnShape
520 //=======================================================================
522 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
523 const gp_XYZ& aParams,
525 StdMeshers_TNode& aTN)
529 double aX, aY, aZ, aD, aTol2, minD;
532 SMESH_Mesh* pMesh = GetMesh();
533 aTol2 = myTol3D*myTol3D;
535 SMDS_MeshNode* pNode = NULL;
537 if ( aS.ShapeType() == TopAbs_FACE ||
538 aS.ShapeType() == TopAbs_EDGE ) {
539 // find a face ID to which aTN belongs to
541 if ( aS.ShapeType() == TopAbs_FACE )
542 faceID = myBlock.ShapeID( aS );
543 else { // edge maybe vertical or top horizontal
544 gp_XYZ aCoord = aParams;
545 if ( aCoord.Z() == 1. )
546 aCoord.SetZ( 0.5 ); // move from top down
548 aCoord.SetX( 0.5 ); // move along X
549 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
551 ASSERT( SMESH_Block::IsFaceID( faceID ));
552 int fIndex = SMESH_Block::ShapeIndex( faceID );
553 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
554 // look for a base node in ijNodes
555 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
556 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
557 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
558 if ( par_nVec->second[ 0 ] == baseNode ) {
559 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
565 myBlock.Point(aParams, aS, aP1);
567 SMDS_NodeIteratorPtr ite=
568 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
570 const SMDS_MeshNode* aNode = ite->next();
571 if(myTool->IsMedium(aNode))
576 aP2.SetCoord(aX, aY, aZ);
577 aD=(double)aP1.SquareDistance(aP2);
578 //printf("** D=%lf ", aD, aTol2);
580 pNode=(SMDS_MeshNode*)aNode;
590 //aTN.SetNode(pNode);
591 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
592 //myErrorStatus=11; // can not find the node;
596 //=======================================================================
597 //function : SetHorizEdgeXYZ
599 //=======================================================================
601 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
603 vector<const SMDS_MeshNode*>*& aCol1,
604 vector<const SMDS_MeshNode*>*& aCol2)
606 // find base and top edges of the face
607 enum { BASE = 0, TOP };
608 vector< int > edgeVec; // 0-base, 1-top
609 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
611 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
612 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
614 double param = aBaseNodeParams.Coord( coord );
618 // look for columns around param
619 StdMeshers_IJNodeMap & ijNodes =
620 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
621 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
622 while ( par_nVec_1->first < param )
624 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
627 if ( par_nVec_1 != ijNodes.begin() ) {
629 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
631 aCol1 = & par_nVec_1->second;
632 aCol2 = & par_nVec_2->second;
636 // this variant is better for cases with curved edges and
637 // different nodes distribution on top and base edges
638 const SMDS_MeshNode* n1 = aCol1->back();
639 const SMDS_MeshNode* n2 = aCol2->back();
640 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
641 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
642 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
645 // this variant is better for other cases
646 // SMESH_MesherHelper helper( *GetMesh() );
647 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
648 // double u1 = helper.GetNodeU( edge, n1 );
649 // double u2 = helper.GetNodeU( edge, n2 );
650 // double u = ( 1. - r ) * u1 + r * u2;
651 // gp_XYZ topNodeParams;
652 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
653 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
655 // myShapeXYZ[ edgeVec[ TOP ]]);
659 myBlock.Block().EdgePoint( edgeVec[ BASE ],
661 myShapeXYZ[ edgeVec[ BASE ]]);
666 //=======================================================================
667 //function : MakeVolumeMesh
669 //=======================================================================
670 void StdMeshers_Penta_3D::MakeVolumeMesh()
674 int i, j, ij, ik, i1, i2, aSSID;
676 SMESH_Mesh* pMesh = GetMesh();
677 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
679 int shapeID = meshDS->ShapeToIndex( myShape );
681 // 1. Set Node In Volume
683 for (i=1; i<ik; ++i){
684 for (j=0; j<myJSize; ++j){
686 const StdMeshers_TNode& aTN = myTNodes[ij];
687 aSSID=aTN.ShapeSupportID();
688 if (aSSID==SMESH_Block::ID_NONE) {
689 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
690 meshDS->SetNodeInVolume(aNode, shapeID);
695 // 2. Make pentahedrons
697 vector<const SMDS_MeshNode*> aN;
699 SMDS_ElemIteratorPtr itf, aItNodes;
701 const TopoDS_Face& aFxy0=
702 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
703 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
704 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
706 itf = aSM0->GetElements();
708 const SMDS_MeshElement* pE0 = itf->next();
710 int nbFaceNodes = pE0->NbNodes();
711 if(myCreateQuadratic)
712 nbFaceNodes = nbFaceNodes/2;
713 if ( aN.size() < nbFaceNodes * 2 )
714 aN.resize( nbFaceNodes * 2 );
717 aItNodes=pE0->nodesIterator();
718 while (aItNodes->more()) {
719 //const SMDS_MeshElement* pNode = aItNodes->next();
720 const SMDS_MeshNode* pNode =
721 static_cast<const SMDS_MeshNode*> (aItNodes->next());
722 if(myTool->IsMedium(pNode))
724 aID0 = pNode->GetID();
725 aJ[k] = GetIndexOnLayer(aID0);
727 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
735 for (i=0; i<ik; ++i) {
738 for(j=0; j<nbFaceNodes; ++j) {
739 ij = i1*myJSize+aJ[j];
740 const StdMeshers_TNode& aTN1 = myTNodes[ij];
741 const SMDS_MeshNode* aN1 = aTN1.Node();
745 const StdMeshers_TNode& aTN2 = myTNodes[ij];
746 const SMDS_MeshNode* aN2 = aTN2.Node();
747 aN[j+nbFaceNodes] = aN2;
749 // check if volume orientation will be ok
751 SMDS_VolumeTool vTool;
752 switch ( nbFaceNodes ) {
754 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
755 aN[3], aN[4], aN[5]);
756 vTool.Set( &tmpVol );
760 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
761 aN[4], aN[5], aN[6], aN[7]);
762 vTool.Set( &tmpVol );
768 forward = vTool.IsForward();
771 SMDS_MeshVolume* aV = 0;
772 switch ( nbFaceNodes ) {
775 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
776 // aN[3], aN[4], aN[5]);
777 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
780 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
781 // aN[3], aN[5], aN[4]);
782 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
787 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
788 // aN[4], aN[5], aN[6], aN[7]);
789 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
790 aN[4], aN[5], aN[6], aN[7]);
793 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
794 // aN[4], aN[7], aN[6], aN[5]);
795 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
796 aN[4], aN[7], aN[6], aN[5]);
802 meshDS->SetMeshElementOnShape(aV, shapeID);
807 //=======================================================================
808 //function : MakeMeshOnFxy1
810 //=======================================================================
811 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
815 int aID0, aJ, aLevel, ij, aNbNodes, k;
817 SMDS_NodeIteratorPtr itn;
818 SMDS_ElemIteratorPtr itf, aItNodes;
819 SMDSAbs_ElementType aElementType;
821 const TopoDS_Face& aFxy0=
822 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
823 const TopoDS_Face& aFxy1=
824 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
825 SMESH_MesherHelper faceHelper( *GetMesh() );
826 faceHelper.IsQuadraticSubMesh(aFxy1);
828 SMESH_Mesh* pMesh = GetMesh();
829 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
831 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
832 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
834 // set nodes on aFxy1
836 itn = aSM0->GetNodes();
837 aNbNodes = aSM0->NbNodes();
838 //printf("** aNbNodes=%d\n", aNbNodes);
841 // set elements on aFxy1
842 vector<const SMDS_MeshNode*> aNodes1;
844 itf = aSM0->GetElements();
846 const SMDS_MeshElement* pE0 = itf->next();
847 aElementType = pE0->GetType();
848 if (!aElementType==SMDSAbs_Face) {
851 aNbNodes = pE0->NbNodes();
852 if(myCreateQuadratic)
853 aNbNodes = aNbNodes/2;
854 if ( aNodes1.size() < aNbNodes )
855 aNodes1.resize( aNbNodes );
857 k = aNbNodes-1; // reverse a face
858 aItNodes = pE0->nodesIterator();
859 while (aItNodes->more()) {
860 //const SMDS_MeshElement* pNode = aItNodes->next();
861 const SMDS_MeshNode* pNode =
862 static_cast<const SMDS_MeshNode*> (aItNodes->next());
863 if(myTool->IsMedium(pNode))
865 aID0 = pNode->GetID();
866 aJ = GetIndexOnLayer(aID0);
868 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
872 ij = aLevel*myJSize + aJ;
873 const StdMeshers_TNode& aTN1 = myTNodes[ij];
874 const SMDS_MeshNode* aN1 = aTN1.Node();
878 SMDS_MeshFace * face = 0;
879 switch ( aNbNodes ) {
881 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
884 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
889 meshDS->SetMeshElementOnShape(face, aFxy1);
893 //=======================================================================
894 //function : ClearMeshOnFxy1
896 //=======================================================================
897 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
901 SMESH_subMesh* aSubMesh;
902 SMESH_Mesh* pMesh=GetMesh();
904 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
905 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
907 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
910 //=======================================================================
911 //function : GetIndexOnLayer
913 //=======================================================================
914 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
919 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
921 aMapIt=myConnectingMap.find(aID);
922 if (aMapIt==myConnectingMap.end()) {
930 //=======================================================================
931 //function : MakeConnectingMap
933 //=======================================================================
934 void StdMeshers_Penta_3D::MakeConnectingMap()
938 for (j=0; j<myJSize; ++j) {
939 const StdMeshers_TNode& aBN=myTNodes[j];
940 aBNID=aBN.BaseNodeID();
941 myConnectingMap[aBNID]=j;
945 //=======================================================================
946 //function : CreateNode
948 //=======================================================================
949 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
950 const gp_XYZ& aParams,
951 StdMeshers_TNode& aTN)
960 SMDS_MeshNode* pNode=NULL;
963 // if (bIsUpperLayer) {
964 // // point on face Fxy1
965 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
966 // myBlock.Point(aParams, aS, aP);
969 // // point inside solid
970 // myBlock.Point(aParams, aP);
973 double u = aParams.X(), v = aParams.Y();
974 double u1 = ( 1. - u ), v1 = ( 1. - v );
975 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
976 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
977 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
978 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
980 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
981 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
982 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
983 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
986 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
989 // iErr=myBlock.ErrorStatus();
991 // myErrorStatus=12; // can not find the node point;
995 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
997 SMESH_Mesh* pMesh = GetMesh();
998 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
1000 pNode = pMeshDS->AddNode(aX, aY, aZ);
1005 //=======================================================================
1006 //function : ShapeSupportID
1008 //=======================================================================
1009 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
1010 const SMESH_Block::TShapeID aBNSSID,
1011 SMESH_Block::TShapeID& aSSID)
1016 case SMESH_Block::ID_V000:
1017 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
1019 case SMESH_Block::ID_V100:
1020 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
1022 case SMESH_Block::ID_V110:
1023 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
1025 case SMESH_Block::ID_V010:
1026 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
1028 case SMESH_Block::ID_Ex00:
1029 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
1031 case SMESH_Block::ID_Ex10:
1032 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
1034 case SMESH_Block::ID_E0y0:
1035 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
1037 case SMESH_Block::ID_E1y0:
1038 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
1040 case SMESH_Block::ID_Fxy0:
1041 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1044 aSSID=SMESH_Block::ID_NONE;
1045 myErrorStatus=10; // Can not find supporting shape ID
1050 //=======================================================================
1051 //function : MakeBlock
1053 //=======================================================================
1054 void StdMeshers_Penta_3D::MakeBlock()
1059 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1061 TopoDS_Vertex aV000, aV001;
1063 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1064 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1065 TopTools_ListIteratorOfListOfShape aIt;
1067 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1069 // 0. Find triangulated face aFTr
1070 SMDSAbs_ElementType aElementType;
1071 SMESH_Mesh* pMesh=GetMesh();
1075 for (i=1; i<=iNbF; ++i) {
1076 const TopoDS_Shape& aF = aM(i);
1077 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1079 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1080 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1081 while(itf->more()) {
1082 const SMDS_MeshElement * pElement = itf->next();
1083 aElementType = pElement->GetType();
1084 if (aElementType==SMDSAbs_Face) {
1085 iNbNodes = pElement->NbNodes();
1086 if ( iNbNodes==3 || (myCreateQuadratic && iNbNodes==6) ) {
1091 // The current algorithm fails if there is more that one
1092 // face wich contains triangles ...
1093 // In that case, replace return by break to try another
1094 // method (coded in "if (iCnt != 1) { ... }")
1096 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1097 // myErrorStatus=5; // more than one face has triangulation
1109 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1110 // was not reached 'cause it was not called from Hexa_3D ... Now it
1111 // can occurs and in my opinion, it is the most common case.
1114 // The suggested algorithm is the following :
1116 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1117 // then the shape is tologically equivalent to a box
1118 // o In a box, there are three set of four // edges ...
1119 // In the cascade notation, it seems to be the edges
1124 // o For each one of this set, check if the four edges
1125 // have the same number of element.
1126 // o If so, check if the "corresponding" // faces contains
1127 // only quads. It's the faces numbered:
1131 // o If so, check if the opposite edges of each // faces
1132 // have the same number of elements. It is the edges
1134 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1135 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1136 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1137 // o If so, check if the two other faces have the same
1138 // number of elements. It is the faces numbered:
1142 // This test should be improved to test if the nodes
1143 // of the two faces are really "en face".
1144 // o If so, one of the two faces is a candidate to an extrusion,
1145 // It is the faces numbered :
1149 // o Finally, if there is only one candidate, let do the
1150 // extrusion job for the corresponding face
1154 int iNbF = aM.Extent();
1157 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1158 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1159 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1160 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1161 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1162 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1164 int has_only_quad_f1 = 1;
1165 int has_only_quad_f2 = 1;
1166 int has_only_quad_f3 = 1;
1167 int has_only_quad_f4 = 1;
1168 int has_only_quad_f5 = 1;
1169 int has_only_quad_f6 = 1;
1171 for (i=1; i<=iNbF; ++i) {
1173 const TopoDS_Shape& aF = aM(i);
1174 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1175 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1176 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1177 while(itf->more()) {
1178 const SMDS_MeshElement * pElement = itf->next();
1179 aElementType = pElement->GetType();
1180 if (aElementType==SMDSAbs_Face) {
1181 iNbNodes = pElement->NbNodes();
1182 if ( iNbNodes!=4 ) {
1188 if (i==1) has_only_quad_f1 = ok ;
1189 if (i==2) has_only_quad_f2 = ok ;
1190 if (i==3) has_only_quad_f3 = ok ;
1191 if (i==4) has_only_quad_f4 = ok ;
1192 if (i==5) has_only_quad_f5 = ok ;
1193 if (i==6) has_only_quad_f6 = ok ;
1196 TopTools_IndexedMapOfShape aE;
1197 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1198 int iNbE = aE.Extent();
1201 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1202 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1203 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1204 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1205 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1206 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1207 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1208 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1209 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1210 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1211 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1212 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1216 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1217 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1218 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1226 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1227 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1228 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1236 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1237 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1238 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1254 myErrorStatus=5; // more than one face has triangulation
1260 // 1. Vetrices V00, V001;
1262 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1263 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1265 // 1.1 Base vertex V000
1266 iNbE = aME.Extent();
1267 if (iNbE!= NB_WALL_FACES ){
1268 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1269 myErrorStatus=7; // too few edges are in base face aFTr
1272 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1273 aV000=TopExp::FirstVertex(aE1);
1275 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1276 aIt.Initialize(aLE);
1277 for (; aIt.More(); aIt.Next()) {
1278 const TopoDS_Shape& aEx=aIt.Value();
1281 iNbEV=aMEV.Extent();
1283 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1284 myErrorStatus=7; // too few edges meet in base vertex
1290 for (j=1; j<=iNbEV; ++j) {
1291 const TopoDS_Shape& aEx=aMEV(j);
1292 if (!aME.Contains(aEx)) {
1293 TopoDS_Vertex aV[2];
1295 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1296 TopExp::Vertices(aE, aV[0], aV[1]);
1297 for (i=0; i<2; ++i) {
1298 if (!aV[i].IsSame(aV000)) {
1308 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1309 myErrorStatus=8; // can not find reper V001
1313 //gp_Pnt aP000, aP001;
1315 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1316 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1317 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1318 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1322 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1325 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1326 myErrorStatus=9; // number of shells in source shape !=1
1331 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1332 myBlock.Load(aShell, aV000, aV001);
1333 iErr = myBlock.ErrorStatus();
1335 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1336 myErrorStatus=100; // SMESHBlock: Load operation failed
1340 //=======================================================================
1341 //function : CheckData
1343 //=======================================================================
1344 void StdMeshers_Penta_3D::CheckData()
1349 int iNbEx[]={8, 12, 6};
1351 TopAbs_ShapeEnum aST;
1352 TopAbs_ShapeEnum aSTEx[]={
1353 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1355 TopTools_IndexedMapOfShape aM;
1357 if (myShape.IsNull()){
1358 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1359 myErrorStatus=2; // null shape
1363 aST=myShape.ShapeType();
1364 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1365 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1366 myErrorStatus=3; // not compatible type of shape
1370 for (i=0; i<3; ++i) {
1372 TopExp::MapShapes(myShape, aSTEx[i], aM);
1375 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1376 myErrorStatus=4; // number of subshape is not compatible
1382 //=======================================================================
1383 //function : LoadIJNodes
1384 //purpose : Load nodes bound to theFace into column (vectors) and rows
1386 // The value of theIJNodes map is a vector of ordered nodes so
1387 // that the 0-the one lies on theBaseEdge.
1388 // The key of theIJNodes map is a normalized parameter of each
1389 // 0-the node on theBaseEdge.
1390 //=======================================================================
1392 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1393 const TopoDS_Face& theFace,
1394 const TopoDS_Edge& theBaseEdge,
1395 SMESHDS_Mesh* theMesh)
1397 // get vertices of theBaseEdge
1398 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1399 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1400 TopExp::Vertices( eFrw, vfb, vlb );
1402 // find the other edges of theFace and orientation of e1
1403 TopoDS_Edge e1, e2, eTop;
1404 bool rev1, CumOri = false;
1405 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1407 for ( ; exp.More(); exp.Next() ) {
1408 if ( ++nbEdges > NB_WALL_FACES ) {
1409 return false; // more than 4 edges in theFace
1411 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1412 if ( theBaseEdge.IsSame( e ))
1414 TopoDS_Vertex vCommon;
1415 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1417 else if ( vCommon.IsSame( vfb )) {
1419 vft = TopExp::LastVertex( e1, CumOri );
1420 rev1 = vfb.IsSame( vft );
1422 vft = TopExp::FirstVertex( e1, CumOri );
1427 if ( nbEdges < NB_WALL_FACES ) {
1428 return false; // less than 4 edges in theFace
1431 // submeshes corresponding to shapes
1432 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1433 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1434 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1435 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1436 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1437 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1438 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1439 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1440 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1441 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1442 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1445 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1446 MESSAGE(" Diff nb of nodes on opposite edges" );
1449 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1450 MESSAGE("Empty submesh of vertex");
1453 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1454 // check quadratic case
1455 if ( myCreateQuadratic ) {
1456 int n1 = sm1->NbNodes()/2;
1457 int n2 = smb->NbNodes()/2;
1458 int n3 = sm1->NbNodes() - n1;
1459 int n4 = smb->NbNodes() - n2;
1460 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1461 if( nf != smFace->NbNodes() ) {
1462 MESSAGE( "Wrong nb face nodes: " <<
1463 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1468 MESSAGE( "Wrong nb face nodes: " <<
1469 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1474 int vsize = sm1->NbNodes() + 2;
1475 int hsize = smb->NbNodes() + 2;
1476 if(myCreateQuadratic) {
1477 vsize = vsize - sm1->NbNodes()/2 -1;
1478 hsize = hsize - smb->NbNodes()/2 -1;
1481 // load nodes from theBaseEdge
1483 set<const SMDS_MeshNode*> loadedNodes;
1484 const SMDS_MeshNode* nullNode = 0;
1486 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1487 nVecf.resize( vsize, nullNode );
1488 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1490 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1491 nVecl.resize( vsize, nullNode );
1492 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1495 BRep_Tool::Range( eFrw, f, l );
1496 double range = l - f;
1497 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1498 const SMDS_MeshNode* node;
1499 while ( nIt->more() ) {
1501 if(myTool->IsMedium(node))
1503 const SMDS_EdgePosition* pos =
1504 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1508 double u = ( pos->GetUParameter() - f ) / range;
1509 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1510 nVec.resize( vsize, nullNode );
1511 loadedNodes.insert( nVec[ 0 ] = node );
1513 if ( theIJNodes.size() != hsize ) {
1514 MESSAGE( "Wrong node positions on theBaseEdge" );
1518 // load nodes from e1
1520 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1521 nIt = sm1->GetNodes();
1522 while ( nIt->more() ) {
1524 if(myTool->IsMedium(node))
1526 const SMDS_EdgePosition* pos =
1527 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1531 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1533 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1534 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1535 int row = rev1 ? vsize - 1 : 0;
1536 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1539 loadedNodes.insert( nVecf[ row ] = u_n->second );
1542 // try to load the rest nodes
1544 // get all faces from theFace
1545 map<int,const SMDS_MeshElement*> allFaces, foundFaces;
1546 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1547 while ( eIt->more() ) {
1548 const SMDS_MeshElement* e = eIt->next();
1549 if ( e->GetType() == SMDSAbs_Face )
1550 allFaces.insert( make_pair(e->GetID(),e) );
1552 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1553 // the nodes belong to, and between the nodes of the found face,
1554 // look for a not loaded node considering this node to be the next
1555 // in a column of the starting second node. Repeat, starting
1556 // from nodes next to the previous starting nodes in their columns,
1557 // and so on while a face can be found. Then go the the next pair
1558 // of nodes on theBaseEdge.
1559 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1560 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1563 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1566 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1567 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1568 const SMDS_MeshElement* face = 0;
1570 // look for a face by 2 nodes
1571 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1573 int nbFaceNodes = face->NbNodes();
1574 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1575 (myCreateQuadratic && nbFaceNodes>8) ) {
1576 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1579 // look for a not loaded node of the <face>
1581 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1582 eIt = face->nodesIterator() ;
1583 while ( !found && eIt->more() ) {
1584 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1585 if(myTool->IsMedium(node))
1587 found = loadedNodes.insert( node ).second;
1588 if ( !found && node != n1 && node != n2 )
1592 if ( ++row > vsize - 1 ) {
1593 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1596 par_nVec_2->second[ row ] = node;
1597 foundFaces.insert( make_pair(face->GetID(),face) );
1599 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1600 n1 = par_nVec_1->second[ row ];
1603 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1604 n3 == par_nVec_1->second[ row ] ) {
1608 MESSAGE( "Not quad mesh, column "<< col );
1613 while ( face && n1 && n2 );
1615 if ( row < vsize - 1 ) {
1616 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1617 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1618 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1619 MESSAGE( "Current node 1: "<< n1);
1620 MESSAGE( "Current node 2: "<< n2);
1621 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1622 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1625 } // loop on columns
1630 //////////////////////////////////////////////////////////////////////////
1632 // StdMeshers_SMESHBlock
1634 //////////////////////////////////////////////////////////////////////////
1636 //=======================================================================
1637 //function : StdMeshers_SMESHBlock
1639 //=======================================================================
1640 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1643 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1646 //=======================================================================
1647 //function : IsForwadEdge
1649 //=======================================================================
1651 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1653 int index = myTBlock.ShapeIndex( theEdgeID );
1654 if ( !myTBlock.IsEdgeID( theEdgeID ))
1657 if ( myIsEdgeForward[ index ] < 0 )
1658 myIsEdgeForward[ index ] =
1659 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1661 return myIsEdgeForward[ index ];
1664 //=======================================================================
1665 //function : ErrorStatus
1667 //=======================================================================
1668 int StdMeshers_SMESHBlock::ErrorStatus() const
1670 return myErrorStatus;
1673 //=======================================================================
1676 //=======================================================================
1677 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1679 TopoDS_Vertex aV000, aV001;
1681 Load(theShell, aV000, aV001);
1684 //=======================================================================
1687 //=======================================================================
1688 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1689 const TopoDS_Vertex& theV000,
1690 const TopoDS_Vertex& theV001)
1698 myShapeIDMap.Clear();
1699 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1706 //=======================================================================
1707 //function : ComputeParameters
1709 //=======================================================================
1710 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1713 ComputeParameters(thePnt, myShell, theXYZ);
1716 //=======================================================================
1717 //function : ComputeParameters
1719 //=======================================================================
1720 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1721 const TopoDS_Shape& theShape,
1729 aID = ShapeID(theShape);
1730 if (myErrorStatus) {
1733 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1735 myErrorStatus=4; // problems with computation Parameters
1740 //=======================================================================
1741 //function : ComputeParameters
1743 //=======================================================================
1745 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1746 const TopoDS_Shape& theShape,
1754 aID = ShapeID(theShape);
1755 if (myErrorStatus) {
1758 if ( SMESH_Block::IsEdgeID( aID ))
1759 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1761 myErrorStatus=4; // problems with computation Parameters
1766 //=======================================================================
1769 //=======================================================================
1770 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1775 Point(theParams, aS, aP3D);
1778 //=======================================================================
1781 //=======================================================================
1782 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1783 const TopoDS_Shape& theShape,
1790 gp_XYZ aXYZ(99.,99.,99.);
1793 if (theShape.IsNull()) {
1794 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1798 aID=ShapeID(theShape);
1799 if (myErrorStatus) {
1803 if (SMESH_Block::IsVertexID(aID)) {
1804 bOk = myTBlock.VertexPoint(aID, aXYZ);
1806 else if (SMESH_Block::IsEdgeID(aID)) {
1807 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1810 else if (SMESH_Block::IsFaceID(aID)) {
1811 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1815 myErrorStatus=4; // problems with point computation
1821 //=======================================================================
1822 //function : ShapeID
1824 //=======================================================================
1825 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1830 TopoDS_Shape aSF, aSR;
1833 aSF.Orientation(TopAbs_FORWARD);
1835 aSR.Orientation(TopAbs_REVERSED);
1837 if (myShapeIDMap.Contains(aSF)) {
1838 aID=myShapeIDMap.FindIndex(aSF);
1841 if (myShapeIDMap.Contains(aSR)) {
1842 aID=myShapeIDMap.FindIndex(aSR);
1845 myErrorStatus=2; // unknown shape;
1849 //=======================================================================
1852 //=======================================================================
1853 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1859 aNb=myShapeIDMap.Extent();
1860 if (theID<1 || theID>aNb) {
1861 myErrorStatus=3; // ID is out of range
1862 return myEmptyShape;
1865 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);