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_MeshEditor.hxx"
39 #include "SMESH_subMesh.hxx"
40 #include "SMESH_subMeshEventListener.hxx"
42 #include <BRepTools.hxx>
43 #include <BRepTools_WireExplorer.hxx>
44 #include <BRep_Tool.hxx>
45 #include <TopAbs_ShapeEnum.hxx>
47 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
50 #include <TopTools_ListIteratorOfListOfShape.hxx>
51 #include <TopTools_ListOfShape.hxx>
52 #include <TopTools_MapOfShape.hxx>
54 #include <TopoDS_Edge.hxx>
55 #include <TopoDS_Shell.hxx>
56 #include <TopoDS_Vertex.hxx>
58 #include <BRepTools.hxx>
59 #include <BRepTools_WireExplorer.hxx>
60 #include <TopTools_MapOfShape.hxx>
67 typedef map < int, int, less<int> >::iterator \
68 StdMeshers_IteratorOfDataMapOfIntegerInteger;
70 enum { NB_WALL_FACES = 4 };
72 //=======================================================================
73 //function : StdMeshers_Penta_3D
75 //=======================================================================
76 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
80 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
81 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
85 //=======================================================================
86 //function : ~StdMeshers_Penta_3D
88 //=======================================================================
90 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
96 //=======================================================================
99 //=======================================================================
100 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
101 const TopoDS_Shape& aShape)
103 MESSAGE("StdMeshers_Penta_3D::Compute()");
117 myTool = new SMESH_MesherHelper(aMesh);
118 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
123 delete myTool; myTool = 0;
129 delete myTool; myTool = 0;
135 delete myTool; myTool = 0;
143 delete myTool; myTool = 0;
149 delete myTool; myTool = 0;
153 //=======================================================================
154 //function : MakeNodes
156 //=======================================================================
157 void StdMeshers_Penta_3D::MakeNodes()
162 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
164 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
165 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
166 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
167 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
168 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
172 SMESH_Mesh* pMesh=GetMesh();
174 // 1. Define the sizes of mesh
176 // 1.1 Horizontal size
178 for (i=0; i<aNbSIDs; ++i) {
179 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
180 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
182 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
183 if(!myCreateQuadratic) {
184 iNbN = aSM->NbNodes();
188 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
190 const SMDS_MeshNode* aNode = itn->next();
191 if(myTool->IsMedium(aNode))
198 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
203 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
204 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
206 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
207 if(!myCreateQuadratic) {
208 iNbN = aSM->NbNodes();
212 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
214 const SMDS_MeshNode* aNode = itn->next();
215 if(myTool->IsMedium(aNode))
222 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
224 aSize=myISize*myJSize;
225 myTNodes.resize(aSize);
227 StdMeshers_TNode aTNode;
231 // 2. Fill the repers on base face (Z=0)
234 for (k=0; k<aNbSIDs; ++k) {
236 const TopoDS_Shape& aS = myBlock.Shape(aSID);
237 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
239 const SMDS_MeshNode* aNode = ite->next();
240 if(myTool->IsMedium(aNode))
242 aNodeID=aNode->GetID();
244 aTNode.SetNode(aNode);
245 aTNode.SetShapeSupportID(aSID);
246 aTNode.SetBaseNodeID(aNodeID);
248 if ( SMESH_Block::IsEdgeID (aSID)) {
249 const SMDS_EdgePosition* epos =
250 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
251 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
257 aP3D.SetCoord(aX, aY, aZ);
258 myBlock.ComputeParameters(aP3D, aS, aCoords);
260 iErr = myBlock.ErrorStatus();
262 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
263 "SMESHBlock: ComputeParameters operation failed");
264 myErrorStatus=101; // SMESHBlock: ComputeParameters operation failed
267 aTNode.SetNormCoord(aCoords);
274 // 3.1 Fill maps of wall nodes
275 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
276 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
277 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
279 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
280 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
281 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
283 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
284 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
285 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
286 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
287 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
290 myErrorStatus = i + 1;
291 MESSAGE(" Cant LoadIJNodes() from a wall face " << myErrorStatus );
296 // 3.2 find node columns for vertical edges and edge IDs
297 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
298 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
299 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
301 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
302 ShapeSupportID(false, vID, eID);
303 verticEdgeID[ i ] = eID;
305 StdMeshers_TNode& aTNode = myTNodes[ i ];
306 verticEdgeNodes[ i ] = 0;
307 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
308 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
309 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
310 if ( ijNodes.begin()->second[0] == aTNode.Node() )
311 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
312 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
313 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
314 if ( verticEdgeNodes[ i ] )
319 // 3.3 set XYZ of vertices, and initialize of the rest
320 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
321 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
322 if ( SMESH_Block::IsVertexID( id )) {
323 TopoDS_Shape V = myBlock.Shape( id );
324 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
325 const SMDS_MeshNode* n = sm->GetNodes()->next();
326 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
329 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
333 // 4. Fill the rest repers
336 SMESH_Block::TShapeID aSSID, aBNSSID;
337 StdMeshers_TNode aTN;
340 // create top face and find UV for it's corners
341 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
342 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
343 int topfaceID = meshDS->ShapeToIndex(TopFace);
344 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
345 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
346 const SMDS_MeshNode* N = itn->next();
347 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
348 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
349 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
351 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
352 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
353 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
355 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
356 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
357 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
359 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
361 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
363 const StdMeshers_TNode& aBN = myTNodes[j];
364 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
365 iBNID = aBN.BaseNodeID();
366 const gp_XYZ& aBNXYZ = aBN.NormCoord();
367 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
369 // set XYZ on horizontal edges and get node columns of faces:
370 // 2 columns for each face, between which a base node is located
371 vector<const SMDS_MeshNode*>* nColumns[8];
372 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
374 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
375 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
376 nColumns[k*2], nColumns[k*2+1]);
380 // XYZ on the bottom and top faces
381 const SMDS_MeshNode* n = aBN.Node();
382 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
383 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
385 // first create or find a top node, then the rest ones in a column
386 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
388 bIsUpperLayer = (i==(myISize-1));
389 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
390 if ( createNode ) // a base node is inside a top face
392 // set XYZ on vertical edges and faces
393 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
394 // XYZ on a vertical edge
395 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
396 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
397 // XYZ on a face (part 1 from one column)
398 n = (*nColumns[k*2]) [ i ];
399 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
400 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
402 if( bIsUpperLayer ) {
403 tmp1 = myTool->GetNodeUV(TopFace,n);
404 tmp1 = ( 1. - ratio[ k ]) * tmp1;
406 // XYZ on a face (part 2 from other column)
407 n = (*nColumns[k*2+1]) [ i ];
408 xyz.SetCoord( n->X(), n->Y(), n->Z() );
409 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
410 if( bIsUpperLayer ) {
411 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
412 tmp1 += ratio[ k ] * tmp2;
424 // fill current node info
427 // -normalized coordinates
431 aZ=(double)i/(double)(myISize-1);
432 aCoords.SetCoord(aX, aY, aZ);
434 // suporting shape ID
435 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
437 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
441 aTN.SetShapeSupportID(aSSID);
442 aTN.SetNormCoord(aCoords);
443 aTN.SetBaseNodeID(iBNID);
445 if (aSSID!=SMESH_Block::ID_NONE){
446 // try to find the node
447 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
448 FindNodeOnShape(aS, aCoords, i, aTN);
451 // create node and get it id
452 CreateNode (bIsUpperLayer, aCoords, aTN);
454 if ( bIsUpperLayer ) {
455 const SMDS_MeshNode* n = aTN.Node();
456 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
457 // set node on top face:
458 // find UV parameter for this node
460 // UV011+-----+----------+UV111
463 // UV_E0y1+ +node +UV_E1y1
467 // UV001+-----+----------+UV101
470 double u = aCoords.X(), v = aCoords.Y();
471 double u1 = ( 1. - u ), v1 = ( 1. - v );
472 aP.ChangeCoord() = UV_Ex01 * v1;
473 aP.ChangeCoord() += UV_Ex11 * v;
474 aP.ChangeCoord() += UV_E0y1 * u1;
475 aP.ChangeCoord() += UV_E1y1 * u;
476 aP.ChangeCoord() -= UV001 * u1 * v1;
477 aP.ChangeCoord() -= UV101 * u * v1;
478 aP.ChangeCoord() -= UV011 * u1 * v;
479 aP.ChangeCoord() -= UV111 * u * v;
480 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
484 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
494 int iSSID, iBNID, aID;
496 for (i=0; i<myISize; ++i) {
497 printf(" Layer# %d\n", i);
498 for (j=0; j<myJSize; ++j) {
500 const StdMeshers_TNode& aTN=myTNodes[ij];
501 //const StdMeshers_TNode& aTN=aTNodes[ij];
502 const gp_XYZ& aXYZ=aTN.NormCoord();
503 iSSID=aTN.ShapeSupportID();
504 iBNID=aTN.BaseNodeID();
506 const SMDS_MeshNode* aNode=aTN.Node();
511 printf("*** j:%d BNID#%d iSSID:%d ID:%d { %lf %lf %lf }, { %lf %lf %lf }\n",
512 j, iBNID, iSSID, aID, aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aX, aY, aZ);
521 //=======================================================================
522 //function : FindNodeOnShape
524 //=======================================================================
526 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
527 const gp_XYZ& aParams,
529 StdMeshers_TNode& aTN)
533 double aX, aY, aZ, aD, aTol2, minD;
536 SMESH_Mesh* pMesh = GetMesh();
537 aTol2 = myTol3D*myTol3D;
539 SMDS_MeshNode* pNode = NULL;
541 if ( aS.ShapeType() == TopAbs_FACE ||
542 aS.ShapeType() == TopAbs_EDGE ) {
543 // find a face ID to which aTN belongs to
545 if ( aS.ShapeType() == TopAbs_FACE )
546 faceID = myBlock.ShapeID( aS );
547 else { // edge maybe vertical or top horizontal
548 gp_XYZ aCoord = aParams;
549 if ( aCoord.Z() == 1. )
550 aCoord.SetZ( 0.5 ); // move from top down
552 aCoord.SetX( 0.5 ); // move along X
553 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
555 ASSERT( SMESH_Block::IsFaceID( faceID ));
556 int fIndex = SMESH_Block::ShapeIndex( faceID );
557 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
558 // look for a base node in ijNodes
559 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
560 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
561 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
562 if ( par_nVec->second[ 0 ] == baseNode ) {
563 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
569 myBlock.Point(aParams, aS, aP1);
571 SMDS_NodeIteratorPtr ite=
572 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
574 const SMDS_MeshNode* aNode = ite->next();
575 if(myTool->IsMedium(aNode))
580 aP2.SetCoord(aX, aY, aZ);
581 aD=(double)aP1.SquareDistance(aP2);
582 //printf("** D=%lf ", aD, aTol2);
584 pNode=(SMDS_MeshNode*)aNode;
594 //aTN.SetNode(pNode);
595 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
596 //myErrorStatus=11; // can not find the node;
600 //=======================================================================
601 //function : SetHorizEdgeXYZ
603 //=======================================================================
605 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
607 vector<const SMDS_MeshNode*>*& aCol1,
608 vector<const SMDS_MeshNode*>*& aCol2)
610 // find base and top edges of the face
611 enum { BASE = 0, TOP };
612 vector< int > edgeVec; // 0-base, 1-top
613 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
615 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
616 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
618 double param = aBaseNodeParams.Coord( coord );
622 // look for columns around param
623 StdMeshers_IJNodeMap & ijNodes =
624 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
625 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
626 while ( par_nVec_1->first < param )
628 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
631 if ( par_nVec_1 != ijNodes.begin() ) {
633 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
635 aCol1 = & par_nVec_1->second;
636 aCol2 = & par_nVec_2->second;
640 // this variant is better for cases with curved edges and
641 // different nodes distribution on top and base edges
642 const SMDS_MeshNode* n1 = aCol1->back();
643 const SMDS_MeshNode* n2 = aCol2->back();
644 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
645 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
646 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
649 // this variant is better for other cases
650 // SMESH_MesherHelper helper( *GetMesh() );
651 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
652 // double u1 = helper.GetNodeU( edge, n1 );
653 // double u2 = helper.GetNodeU( edge, n2 );
654 // double u = ( 1. - r ) * u1 + r * u2;
655 // gp_XYZ topNodeParams;
656 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
657 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
659 // myShapeXYZ[ edgeVec[ TOP ]]);
663 myBlock.Block().EdgePoint( edgeVec[ BASE ],
665 myShapeXYZ[ edgeVec[ BASE ]]);
670 //=======================================================================
671 //function : MakeVolumeMesh
673 //=======================================================================
674 void StdMeshers_Penta_3D::MakeVolumeMesh()
678 int i, j, ij, ik, i1, i2, aSSID;
680 SMESH_Mesh* pMesh = GetMesh();
681 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
683 int shapeID = meshDS->ShapeToIndex( myShape );
685 // 1. Set Node In Volume
687 for (i=1; i<ik; ++i){
688 for (j=0; j<myJSize; ++j){
690 const StdMeshers_TNode& aTN = myTNodes[ij];
691 aSSID=aTN.ShapeSupportID();
692 if (aSSID==SMESH_Block::ID_NONE) {
693 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
694 meshDS->SetNodeInVolume(aNode, shapeID);
699 // 2. Make pentahedrons
701 vector<const SMDS_MeshNode*> aN;
703 SMDS_ElemIteratorPtr itf, aItNodes;
705 const TopoDS_Face& aFxy0=
706 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
707 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
708 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
710 itf = aSM0->GetElements();
712 const SMDS_MeshElement* pE0 = itf->next();
714 int nbFaceNodes = pE0->NbNodes();
715 if(myCreateQuadratic)
716 nbFaceNodes = nbFaceNodes/2;
717 if ( aN.size() < nbFaceNodes * 2 )
718 aN.resize( nbFaceNodes * 2 );
721 aItNodes=pE0->nodesIterator();
722 while (aItNodes->more()) {
723 //const SMDS_MeshElement* pNode = aItNodes->next();
724 const SMDS_MeshNode* pNode =
725 static_cast<const SMDS_MeshNode*> (aItNodes->next());
726 if(myTool->IsMedium(pNode))
728 aID0 = pNode->GetID();
729 aJ[k] = GetIndexOnLayer(aID0);
731 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
739 for (i=0; i<ik; ++i) {
742 for(j=0; j<nbFaceNodes; ++j) {
743 ij = i1*myJSize+aJ[j];
744 const StdMeshers_TNode& aTN1 = myTNodes[ij];
745 const SMDS_MeshNode* aN1 = aTN1.Node();
749 const StdMeshers_TNode& aTN2 = myTNodes[ij];
750 const SMDS_MeshNode* aN2 = aTN2.Node();
751 aN[j+nbFaceNodes] = aN2;
753 // check if volume orientation will be ok
755 SMDS_VolumeTool vTool;
756 switch ( nbFaceNodes ) {
758 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
759 aN[3], aN[4], aN[5]);
760 vTool.Set( &tmpVol );
764 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
765 aN[4], aN[5], aN[6], aN[7]);
766 vTool.Set( &tmpVol );
772 forward = vTool.IsForward();
775 SMDS_MeshVolume* aV = 0;
776 switch ( nbFaceNodes ) {
779 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
780 // aN[3], aN[4], aN[5]);
781 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
784 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
785 // aN[3], aN[5], aN[4]);
786 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
791 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
792 // aN[4], aN[5], aN[6], aN[7]);
793 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
794 aN[4], aN[5], aN[6], aN[7]);
797 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
798 // aN[4], aN[7], aN[6], aN[5]);
799 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
800 aN[4], aN[7], aN[6], aN[5]);
806 meshDS->SetMeshElementOnShape(aV, shapeID);
811 //=======================================================================
812 //function : MakeMeshOnFxy1
814 //=======================================================================
815 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
819 int aID0, aJ, aLevel, ij, aNbNodes, k;
821 SMDS_NodeIteratorPtr itn;
822 SMDS_ElemIteratorPtr itf, aItNodes;
823 SMDSAbs_ElementType aElementType;
825 const TopoDS_Face& aFxy0=
826 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
827 const TopoDS_Face& aFxy1=
828 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
829 SMESH_MesherHelper faceHelper( *GetMesh() );
830 faceHelper.IsQuadraticSubMesh(aFxy1);
832 SMESH_Mesh* pMesh = GetMesh();
833 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
835 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
836 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
837 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
839 // set nodes on aFxy1
841 itn = aSM0->GetNodes();
842 aNbNodes = aSM0->NbNodes();
843 //printf("** aNbNodes=%d\n", aNbNodes);
846 // set elements on aFxy1
847 vector<const SMDS_MeshNode*> aNodes1;
849 itf = aSM0->GetElements();
851 const SMDS_MeshElement* pE0 = itf->next();
852 aElementType = pE0->GetType();
853 if (!aElementType==SMDSAbs_Face) {
856 aNbNodes = pE0->NbNodes();
857 if(myCreateQuadratic)
858 aNbNodes = aNbNodes/2;
859 if ( aNodes1.size() < aNbNodes )
860 aNodes1.resize( aNbNodes );
862 k = aNbNodes-1; // reverse a face
863 aItNodes = pE0->nodesIterator();
864 while (aItNodes->more()) {
865 //const SMDS_MeshElement* pNode = aItNodes->next();
866 const SMDS_MeshNode* pNode =
867 static_cast<const SMDS_MeshNode*> (aItNodes->next());
868 if(myTool->IsMedium(pNode))
870 aID0 = pNode->GetID();
871 aJ = GetIndexOnLayer(aID0);
873 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
877 ij = aLevel*myJSize + aJ;
878 const StdMeshers_TNode& aTN1 = myTNodes[ij];
879 const SMDS_MeshNode* aN1 = aTN1.Node();
883 SMDS_MeshFace * face = 0;
884 switch ( aNbNodes ) {
886 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
889 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
894 meshDS->SetMeshElementOnShape(face, aFxy1);
897 // update compute state of top face submesh
898 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
900 // assure that mesh on the top face will be cleaned when it is cleaned
901 // on the bottom face
902 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
903 volSM->SetEventListener( new SMESH_subMeshEventListener(true),
904 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
905 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
908 //=======================================================================
909 //function : ClearMeshOnFxy1
911 //=======================================================================
912 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
916 SMESH_subMesh* aSubMesh;
917 SMESH_Mesh* pMesh=GetMesh();
919 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
920 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
922 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
925 //=======================================================================
926 //function : GetIndexOnLayer
928 //=======================================================================
929 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
934 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
936 aMapIt=myConnectingMap.find(aID);
937 if (aMapIt==myConnectingMap.end()) {
945 //=======================================================================
946 //function : MakeConnectingMap
948 //=======================================================================
949 void StdMeshers_Penta_3D::MakeConnectingMap()
953 for (j=0; j<myJSize; ++j) {
954 const StdMeshers_TNode& aBN=myTNodes[j];
955 aBNID=aBN.BaseNodeID();
956 myConnectingMap[aBNID]=j;
960 //=======================================================================
961 //function : CreateNode
963 //=======================================================================
964 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
965 const gp_XYZ& aParams,
966 StdMeshers_TNode& aTN)
975 SMDS_MeshNode* pNode=NULL;
978 // if (bIsUpperLayer) {
979 // // point on face Fxy1
980 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
981 // myBlock.Point(aParams, aS, aP);
984 // // point inside solid
985 // myBlock.Point(aParams, aP);
988 double u = aParams.X(), v = aParams.Y();
989 double u1 = ( 1. - u ), v1 = ( 1. - v );
990 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
991 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
992 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
993 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
995 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
996 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
997 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
998 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
1001 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
1004 // iErr=myBlock.ErrorStatus();
1006 // myErrorStatus=12; // can not find the node point;
1010 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
1012 SMESH_Mesh* pMesh = GetMesh();
1013 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
1015 pNode = pMeshDS->AddNode(aX, aY, aZ);
1020 //=======================================================================
1021 //function : ShapeSupportID
1023 //=======================================================================
1024 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
1025 const SMESH_Block::TShapeID aBNSSID,
1026 SMESH_Block::TShapeID& aSSID)
1031 case SMESH_Block::ID_V000:
1032 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
1034 case SMESH_Block::ID_V100:
1035 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
1037 case SMESH_Block::ID_V110:
1038 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
1040 case SMESH_Block::ID_V010:
1041 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
1043 case SMESH_Block::ID_Ex00:
1044 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
1046 case SMESH_Block::ID_Ex10:
1047 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
1049 case SMESH_Block::ID_E0y0:
1050 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
1052 case SMESH_Block::ID_E1y0:
1053 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
1055 case SMESH_Block::ID_Fxy0:
1056 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1059 aSSID=SMESH_Block::ID_NONE;
1060 myErrorStatus=10; // Can not find supporting shape ID
1065 //=======================================================================
1066 //function : MakeBlock
1068 //=======================================================================
1069 void StdMeshers_Penta_3D::MakeBlock()
1074 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1076 TopoDS_Vertex aV000, aV001;
1078 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1079 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1080 TopTools_ListIteratorOfListOfShape aIt;
1082 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1084 // 0. Find triangulated face aFTr
1085 SMDSAbs_ElementType aElementType;
1086 SMESH_Mesh* pMesh=GetMesh();
1090 for (i=1; i<=iNbF; ++i) {
1091 const TopoDS_Shape& aF = aM(i);
1092 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1094 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1095 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1096 while(itf->more()) {
1097 const SMDS_MeshElement * pElement = itf->next();
1098 aElementType = pElement->GetType();
1099 if (aElementType==SMDSAbs_Face) {
1100 iNbNodes = pElement->NbNodes();
1101 if ( iNbNodes==3 || (myCreateQuadratic && iNbNodes==6) ) {
1106 // The current algorithm fails if there is more that one
1107 // face wich contains triangles ...
1108 // In that case, replace return by break to try another
1109 // method (coded in "if (iCnt != 1) { ... }")
1111 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1112 // myErrorStatus=5; // more than one face has triangulation
1124 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1125 // was not reached 'cause it was not called from Hexa_3D ... Now it
1126 // can occurs and in my opinion, it is the most common case.
1129 // The suggested algorithm is the following :
1131 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1132 // then the shape is tologically equivalent to a box
1133 // o In a box, there are three set of four // edges ...
1134 // In the cascade notation, it seems to be the edges
1139 // o For each one of this set, check if the four edges
1140 // have the same number of element.
1141 // o If so, check if the "corresponding" // faces contains
1142 // only quads. It's the faces numbered:
1146 // o If so, check if the opposite edges of each // faces
1147 // have the same number of elements. It is the edges
1149 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1150 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1151 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1152 // o If so, check if the two other faces have the same
1153 // number of elements. It is the faces numbered:
1157 // This test should be improved to test if the nodes
1158 // of the two faces are really "en face".
1159 // o If so, one of the two faces is a candidate to an extrusion,
1160 // It is the faces numbered :
1164 // o Finally, if there is only one candidate, let do the
1165 // extrusion job for the corresponding face
1169 int iNbF = aM.Extent();
1172 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1173 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1174 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1175 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1176 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1177 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1179 int has_only_quad_f1 = 1;
1180 int has_only_quad_f2 = 1;
1181 int has_only_quad_f3 = 1;
1182 int has_only_quad_f4 = 1;
1183 int has_only_quad_f5 = 1;
1184 int has_only_quad_f6 = 1;
1186 for (i=1; i<=iNbF; ++i) {
1188 const TopoDS_Shape& aF = aM(i);
1189 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1190 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1191 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1192 while(itf->more()) {
1193 const SMDS_MeshElement * pElement = itf->next();
1194 aElementType = pElement->GetType();
1195 if (aElementType==SMDSAbs_Face) {
1196 iNbNodes = pElement->NbNodes();
1197 if ( iNbNodes!=4 ) {
1203 if (i==1) has_only_quad_f1 = ok ;
1204 if (i==2) has_only_quad_f2 = ok ;
1205 if (i==3) has_only_quad_f3 = ok ;
1206 if (i==4) has_only_quad_f4 = ok ;
1207 if (i==5) has_only_quad_f5 = ok ;
1208 if (i==6) has_only_quad_f6 = ok ;
1211 TopTools_IndexedMapOfShape aE;
1212 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1213 int iNbE = aE.Extent();
1216 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1217 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1218 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1219 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1220 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1221 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1222 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1223 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1224 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1225 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1226 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1227 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1231 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1232 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1233 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1241 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1242 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1243 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1251 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1252 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1253 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1269 myErrorStatus=5; // more than one face has triangulation
1275 // 1. Vetrices V00, V001;
1277 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1278 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1280 // 1.1 Base vertex V000
1281 iNbE = aME.Extent();
1282 if (iNbE!= NB_WALL_FACES ){
1283 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1284 myErrorStatus=7; // too few edges are in base face aFTr
1287 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1288 aV000=TopExp::FirstVertex(aE1);
1290 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1291 aIt.Initialize(aLE);
1292 for (; aIt.More(); aIt.Next()) {
1293 const TopoDS_Shape& aEx=aIt.Value();
1296 iNbEV=aMEV.Extent();
1298 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1299 myErrorStatus=7; // too few edges meet in base vertex
1305 for (j=1; j<=iNbEV; ++j) {
1306 const TopoDS_Shape& aEx=aMEV(j);
1307 if (!aME.Contains(aEx)) {
1308 TopoDS_Vertex aV[2];
1310 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1311 TopExp::Vertices(aE, aV[0], aV[1]);
1312 for (i=0; i<2; ++i) {
1313 if (!aV[i].IsSame(aV000)) {
1323 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1324 myErrorStatus=8; // can not find reper V001
1328 //gp_Pnt aP000, aP001;
1330 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1331 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1332 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1333 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1337 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1340 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1341 myErrorStatus=9; // number of shells in source shape !=1
1346 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1347 myBlock.Load(aShell, aV000, aV001);
1348 iErr = myBlock.ErrorStatus();
1350 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1351 myErrorStatus=100; // SMESHBlock: Load operation failed
1355 //=======================================================================
1356 //function : CheckData
1358 //=======================================================================
1359 void StdMeshers_Penta_3D::CheckData()
1364 int iNbEx[]={8, 12, 6};
1366 TopAbs_ShapeEnum aST;
1367 TopAbs_ShapeEnum aSTEx[]={
1368 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1370 TopTools_IndexedMapOfShape aM;
1372 if (myShape.IsNull()){
1373 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1374 myErrorStatus=2; // null shape
1378 aST=myShape.ShapeType();
1379 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1380 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1381 myErrorStatus=3; // not compatible type of shape
1385 for (i=0; i<3; ++i) {
1387 TopExp::MapShapes(myShape, aSTEx[i], aM);
1390 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1391 myErrorStatus=4; // number of subshape is not compatible
1397 //=======================================================================
1398 //function : LoadIJNodes
1399 //purpose : Load nodes bound to theFace into column (vectors) and rows
1401 // The value of theIJNodes map is a vector of ordered nodes so
1402 // that the 0-the one lies on theBaseEdge.
1403 // The key of theIJNodes map is a normalized parameter of each
1404 // 0-the node on theBaseEdge.
1405 //=======================================================================
1407 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1408 const TopoDS_Face& theFace,
1409 const TopoDS_Edge& theBaseEdge,
1410 SMESHDS_Mesh* theMesh)
1412 // get vertices of theBaseEdge
1413 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1414 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1415 TopExp::Vertices( eFrw, vfb, vlb );
1417 // find the other edges of theFace and orientation of e1
1418 TopoDS_Edge e1, e2, eTop;
1419 bool rev1, CumOri = false;
1420 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1422 for ( ; exp.More(); exp.Next() ) {
1423 if ( ++nbEdges > NB_WALL_FACES ) {
1424 return false; // more than 4 edges in theFace
1426 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1427 if ( theBaseEdge.IsSame( e ))
1429 TopoDS_Vertex vCommon;
1430 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1432 else if ( vCommon.IsSame( vfb )) {
1434 vft = TopExp::LastVertex( e1, CumOri );
1435 rev1 = vfb.IsSame( vft );
1437 vft = TopExp::FirstVertex( e1, CumOri );
1442 if ( nbEdges < NB_WALL_FACES ) {
1443 return false; // less than 4 edges in theFace
1446 // submeshes corresponding to shapes
1447 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1448 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1449 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1450 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1451 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1452 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1453 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1454 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1455 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1456 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1457 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1460 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1461 MESSAGE(" Diff nb of nodes on opposite edges" );
1464 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1465 MESSAGE("Empty submesh of vertex");
1468 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1469 // check quadratic case
1470 if ( myCreateQuadratic ) {
1471 int n1 = sm1->NbNodes()/2;
1472 int n2 = smb->NbNodes()/2;
1473 int n3 = sm1->NbNodes() - n1;
1474 int n4 = smb->NbNodes() - n2;
1475 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1476 if( nf != smFace->NbNodes() ) {
1477 MESSAGE( "Wrong nb face nodes: " <<
1478 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1483 MESSAGE( "Wrong nb face nodes: " <<
1484 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1489 int vsize = sm1->NbNodes() + 2;
1490 int hsize = smb->NbNodes() + 2;
1491 if(myCreateQuadratic) {
1492 vsize = vsize - sm1->NbNodes()/2 -1;
1493 hsize = hsize - smb->NbNodes()/2 -1;
1496 // load nodes from theBaseEdge
1498 set<const SMDS_MeshNode*> loadedNodes;
1499 const SMDS_MeshNode* nullNode = 0;
1501 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1502 nVecf.resize( vsize, nullNode );
1503 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1505 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1506 nVecl.resize( vsize, nullNode );
1507 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1510 BRep_Tool::Range( eFrw, f, l );
1511 double range = l - f;
1512 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1513 const SMDS_MeshNode* node;
1514 while ( nIt->more() ) {
1516 if(myTool->IsMedium(node))
1518 const SMDS_EdgePosition* pos =
1519 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1523 double u = ( pos->GetUParameter() - f ) / range;
1524 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1525 nVec.resize( vsize, nullNode );
1526 loadedNodes.insert( nVec[ 0 ] = node );
1528 if ( theIJNodes.size() != hsize ) {
1529 MESSAGE( "Wrong node positions on theBaseEdge" );
1533 // load nodes from e1
1535 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1536 nIt = sm1->GetNodes();
1537 while ( nIt->more() ) {
1539 if(myTool->IsMedium(node))
1541 const SMDS_EdgePosition* pos =
1542 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1546 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1548 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1549 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1550 int row = rev1 ? vsize - 1 : 0;
1551 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1554 loadedNodes.insert( nVecf[ row ] = u_n->second );
1557 // try to load the rest nodes
1559 // get all faces from theFace
1560 map<int,const SMDS_MeshElement*> allFaces, foundFaces;
1561 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1562 while ( eIt->more() ) {
1563 const SMDS_MeshElement* e = eIt->next();
1564 if ( e->GetType() == SMDSAbs_Face )
1565 allFaces.insert( make_pair(e->GetID(),e) );
1567 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1568 // the nodes belong to, and between the nodes of the found face,
1569 // look for a not loaded node considering this node to be the next
1570 // in a column of the starting second node. Repeat, starting
1571 // from nodes next to the previous starting nodes in their columns,
1572 // and so on while a face can be found. Then go the the next pair
1573 // of nodes on theBaseEdge.
1574 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1575 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1578 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1581 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1582 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1583 const SMDS_MeshElement* face = 0;
1585 // look for a face by 2 nodes
1586 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1588 int nbFaceNodes = face->NbNodes();
1589 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1590 (myCreateQuadratic && nbFaceNodes>8) ) {
1591 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1594 // look for a not loaded node of the <face>
1596 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1597 eIt = face->nodesIterator() ;
1598 while ( !found && eIt->more() ) {
1599 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1600 if(myTool->IsMedium(node))
1602 found = loadedNodes.insert( node ).second;
1603 if ( !found && node != n1 && node != n2 )
1607 if ( ++row > vsize - 1 ) {
1608 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1611 par_nVec_2->second[ row ] = node;
1612 foundFaces.insert( make_pair(face->GetID(),face) );
1614 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1615 n1 = par_nVec_1->second[ row ];
1618 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1619 n3 == par_nVec_1->second[ row ] ) {
1623 MESSAGE( "Not quad mesh, column "<< col );
1628 while ( face && n1 && n2 );
1630 if ( row < vsize - 1 ) {
1631 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1632 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1633 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1634 MESSAGE( "Current node 1: "<< n1);
1635 MESSAGE( "Current node 2: "<< n2);
1636 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1637 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1640 } // loop on columns
1645 //////////////////////////////////////////////////////////////////////////
1647 // StdMeshers_SMESHBlock
1649 //////////////////////////////////////////////////////////////////////////
1651 //=======================================================================
1652 //function : StdMeshers_SMESHBlock
1654 //=======================================================================
1655 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1658 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1661 //=======================================================================
1662 //function : IsForwadEdge
1664 //=======================================================================
1666 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1668 int index = myTBlock.ShapeIndex( theEdgeID );
1669 if ( !myTBlock.IsEdgeID( theEdgeID ))
1672 if ( myIsEdgeForward[ index ] < 0 )
1673 myIsEdgeForward[ index ] =
1674 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1676 return myIsEdgeForward[ index ];
1679 //=======================================================================
1680 //function : ErrorStatus
1682 //=======================================================================
1683 int StdMeshers_SMESHBlock::ErrorStatus() const
1685 return myErrorStatus;
1688 //=======================================================================
1691 //=======================================================================
1692 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1694 TopoDS_Vertex aV000, aV001;
1696 Load(theShell, aV000, aV001);
1699 //=======================================================================
1702 //=======================================================================
1703 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1704 const TopoDS_Vertex& theV000,
1705 const TopoDS_Vertex& theV001)
1713 myShapeIDMap.Clear();
1714 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1721 //=======================================================================
1722 //function : ComputeParameters
1724 //=======================================================================
1725 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1728 ComputeParameters(thePnt, myShell, theXYZ);
1731 //=======================================================================
1732 //function : ComputeParameters
1734 //=======================================================================
1735 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1736 const TopoDS_Shape& theShape,
1744 aID = ShapeID(theShape);
1745 if (myErrorStatus) {
1748 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1750 myErrorStatus=4; // problems with computation Parameters
1755 //=======================================================================
1756 //function : ComputeParameters
1758 //=======================================================================
1760 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1761 const TopoDS_Shape& theShape,
1769 aID = ShapeID(theShape);
1770 if (myErrorStatus) {
1773 if ( SMESH_Block::IsEdgeID( aID ))
1774 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1776 myErrorStatus=4; // problems with computation Parameters
1781 //=======================================================================
1784 //=======================================================================
1785 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1790 Point(theParams, aS, aP3D);
1793 //=======================================================================
1796 //=======================================================================
1797 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1798 const TopoDS_Shape& theShape,
1805 gp_XYZ aXYZ(99.,99.,99.);
1808 if (theShape.IsNull()) {
1809 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1813 aID=ShapeID(theShape);
1814 if (myErrorStatus) {
1818 if (SMESH_Block::IsVertexID(aID)) {
1819 bOk = myTBlock.VertexPoint(aID, aXYZ);
1821 else if (SMESH_Block::IsEdgeID(aID)) {
1822 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1825 else if (SMESH_Block::IsFaceID(aID)) {
1826 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1830 myErrorStatus=4; // problems with point computation
1836 //=======================================================================
1837 //function : ShapeID
1839 //=======================================================================
1840 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1845 TopoDS_Shape aSF, aSR;
1848 aSF.Orientation(TopAbs_FORWARD);
1850 aSR.Orientation(TopAbs_REVERSED);
1852 if (myShapeIDMap.Contains(aSF)) {
1853 aID=myShapeIDMap.FindIndex(aSF);
1856 if (myShapeIDMap.Contains(aSR)) {
1857 aID=myShapeIDMap.FindIndex(aSR);
1860 myErrorStatus=2; // unknown shape;
1864 //=======================================================================
1867 //=======================================================================
1868 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1874 aNb=myShapeIDMap.Extent();
1875 if (theID<1 || theID>aNb) {
1876 myErrorStatus=3; // ID is out of range
1877 return myEmptyShape;
1880 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);