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"
41 #include "SMESH_Comment.hxx"
43 #include <BRepTools.hxx>
44 #include <BRepTools_WireExplorer.hxx>
45 #include <BRep_Tool.hxx>
46 #include <TopAbs_ShapeEnum.hxx>
48 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <TopTools_ListIteratorOfListOfShape.hxx>
52 #include <TopTools_ListOfShape.hxx>
53 #include <TopTools_MapOfShape.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Shell.hxx>
57 #include <TopoDS_Vertex.hxx>
59 #include <BRepTools.hxx>
60 #include <BRepTools_WireExplorer.hxx>
61 #include <TopTools_MapOfShape.hxx>
68 typedef map < int, int, less<int> >::iterator \
69 StdMeshers_IteratorOfDataMapOfIntegerInteger;
71 enum { NB_WALL_FACES = 4 };
73 //=======================================================================
74 //function : StdMeshers_Penta_3D
76 //=======================================================================
77 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
78 : myErrorStatus(SMESH_ComputeError::New())
81 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
82 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
86 //=======================================================================
87 //function : ~StdMeshers_Penta_3D
89 //=======================================================================
91 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
95 //=======================================================================
98 //=======================================================================
99 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
100 const TopoDS_Shape& aShape)
102 MESSAGE("StdMeshers_Penta_3D::Compute()");
110 if (!myErrorStatus->IsOK()) {
114 SMESH_MesherHelper helper(aMesh);
116 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
120 if (!myErrorStatus->IsOK()) {
125 if (!myErrorStatus->IsOK()) {
130 if (!myErrorStatus->IsOK()) {
137 if (!myErrorStatus->IsOK()) {
146 //=======================================================================
147 //function : MakeNodes
149 //=======================================================================
150 void StdMeshers_Penta_3D::MakeNodes()
153 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
155 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
156 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
157 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
158 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
159 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
163 SMESH_Mesh* pMesh=GetMesh();
165 // 1. Define the sizes of mesh
167 // 1.1 Horizontal size
169 for (i=0; i<aNbSIDs; ++i) {
170 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
171 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
173 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
174 if(!myCreateQuadratic) {
175 iNbN = aSM->NbNodes();
179 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
181 const SMDS_MeshNode* aNode = itn->next();
182 if(myTool->IsMedium(aNode))
189 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
194 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
195 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
197 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
198 if(!myCreateQuadratic) {
199 iNbN = aSM->NbNodes();
203 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
205 const SMDS_MeshNode* aNode = itn->next();
206 if(myTool->IsMedium(aNode))
213 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
215 aSize=myISize*myJSize;
216 myTNodes.resize(aSize);
218 StdMeshers_TNode aTNode;
222 // 2. Fill the repers on base face (Z=0)
225 for (k=0; k<aNbSIDs; ++k) {
227 const TopoDS_Shape& aS = myBlock.Shape(aSID);
228 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
230 const SMDS_MeshNode* aNode = ite->next();
231 if(myTool->IsMedium(aNode))
233 aNodeID=aNode->GetID();
235 aTNode.SetNode(aNode);
236 aTNode.SetShapeSupportID(aSID);
237 aTNode.SetBaseNodeID(aNodeID);
239 if ( SMESH_Block::IsEdgeID (aSID)) {
240 const SMDS_EdgePosition* epos =
241 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
242 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
248 aP3D.SetCoord(aX, aY, aZ);
249 myBlock.ComputeParameters(aP3D, aS, aCoords);
251 iErr = myBlock.ErrorStatus();
253 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
254 "SMESHBlock: ComputeParameters operation failed");
255 myErrorStatus=myBlock.GetError();
258 aTNode.SetNormCoord(aCoords);
265 // 3.1 Fill maps of wall nodes
266 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
267 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
268 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
270 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
271 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
272 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
274 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
275 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
276 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
277 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
278 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
281 myErrorStatus->myName = COMPERR_BAD_INPUT_MESH;
282 myErrorStatus->myComment = SMESH_Comment() <<
283 "Can't find regular quadrangle mesh on a side face #" <<
284 pMesh->GetMeshDS()->ShapeToIndex( myBlock.Shape( wallFaceID[ i ]));
289 // 3.2 find node columns for vertical edges and edge IDs
290 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
291 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
292 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
294 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
295 ShapeSupportID(false, vID, eID);
296 verticEdgeID[ i ] = eID;
298 StdMeshers_TNode& aTNode = myTNodes[ i ];
299 verticEdgeNodes[ i ] = 0;
300 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
301 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
302 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
303 if ( ijNodes.begin()->second[0] == aTNode.Node() )
304 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
305 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
306 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
307 if ( verticEdgeNodes[ i ] )
312 // 3.3 set XYZ of vertices, and initialize of the rest
313 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
314 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
315 if ( SMESH_Block::IsVertexID( id )) {
316 TopoDS_Shape V = myBlock.Shape( id );
317 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
318 const SMDS_MeshNode* n = sm->GetNodes()->next();
319 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
322 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
326 // 4. Fill the rest repers
329 SMESH_Block::TShapeID aSSID, aBNSSID;
330 StdMeshers_TNode aTN;
333 // create top face and find UV for it's corners
334 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
335 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
336 int topfaceID = meshDS->ShapeToIndex(TopFace);
337 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
338 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
339 const SMDS_MeshNode* N = itn->next();
340 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
341 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
342 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
344 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
345 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
346 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
348 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
349 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
350 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
352 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
354 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
356 const StdMeshers_TNode& aBN = myTNodes[j];
357 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
358 iBNID = aBN.BaseNodeID();
359 const gp_XYZ& aBNXYZ = aBN.NormCoord();
360 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
362 // set XYZ on horizontal edges and get node columns of faces:
363 // 2 columns for each face, between which a base node is located
364 vector<const SMDS_MeshNode*>* nColumns[8];
365 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
367 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
368 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
369 nColumns[k*2], nColumns[k*2+1]);
373 // XYZ on the bottom and top faces
374 const SMDS_MeshNode* n = aBN.Node();
375 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
376 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
378 // first create or find a top node, then the rest ones in a column
379 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
381 bIsUpperLayer = (i==(myISize-1));
382 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
383 if ( createNode ) // a base node is inside a top face
385 // set XYZ on vertical edges and faces
386 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
387 // XYZ on a vertical edge
388 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
389 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
390 // XYZ on a face (part 1 from one column)
391 n = (*nColumns[k*2]) [ i ];
392 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
393 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
395 if( bIsUpperLayer ) {
396 tmp1 = myTool->GetNodeUV(TopFace,n);
397 tmp1 = ( 1. - ratio[ k ]) * tmp1;
399 // XYZ on a face (part 2 from other column)
400 n = (*nColumns[k*2+1]) [ i ];
401 xyz.SetCoord( n->X(), n->Y(), n->Z() );
402 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
403 if( bIsUpperLayer ) {
404 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
405 tmp1 += ratio[ k ] * tmp2;
417 // fill current node info
420 // -normalized coordinates
424 aZ=(double)i/(double)(myISize-1);
425 aCoords.SetCoord(aX, aY, aZ);
427 // suporting shape ID
428 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
429 if (!myErrorStatus->IsOK()) {
430 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
434 aTN.SetShapeSupportID(aSSID);
435 aTN.SetNormCoord(aCoords);
436 aTN.SetBaseNodeID(iBNID);
438 if (aSSID!=SMESH_Block::ID_NONE){
439 // try to find the node
440 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
441 FindNodeOnShape(aS, aCoords, i, aTN);
444 // create node and get it id
445 CreateNode (bIsUpperLayer, aCoords, aTN);
447 if ( bIsUpperLayer ) {
448 const SMDS_MeshNode* n = aTN.Node();
449 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
450 // set node on top face:
451 // find UV parameter for this node
453 // UV011+-----+----------+UV111
456 // UV_E0y1+ +node +UV_E1y1
460 // UV001+-----+----------+UV101
463 double u = aCoords.X(), v = aCoords.Y();
464 double u1 = ( 1. - u ), v1 = ( 1. - v );
465 aP.ChangeCoord() = UV_Ex01 * v1;
466 aP.ChangeCoord() += UV_Ex11 * v;
467 aP.ChangeCoord() += UV_E0y1 * u1;
468 aP.ChangeCoord() += UV_E1y1 * u;
469 aP.ChangeCoord() -= UV001 * u1 * v1;
470 aP.ChangeCoord() -= UV101 * u * v1;
471 aP.ChangeCoord() -= UV011 * u1 * v;
472 aP.ChangeCoord() -= UV111 * u * v;
473 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
476 if (!myErrorStatus->IsOK()) {
477 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
487 int iSSID, iBNID, aID;
489 for (i=0; i<myISize; ++i) {
490 printf(" Layer# %d\n", i);
491 for (j=0; j<myJSize; ++j) {
493 const StdMeshers_TNode& aTN=myTNodes[ij];
494 //const StdMeshers_TNode& aTN=aTNodes[ij];
495 const gp_XYZ& aXYZ=aTN.NormCoord();
496 iSSID=aTN.ShapeSupportID();
497 iBNID=aTN.BaseNodeID();
499 const SMDS_MeshNode* aNode=aTN.Node();
504 printf("*** j:%d BNID#%d iSSID:%d ID:%d { %lf %lf %lf }, { %lf %lf %lf }\n",
505 j, iBNID, iSSID, aID, aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aX, aY, aZ);
514 //=======================================================================
515 //function : FindNodeOnShape
517 //=======================================================================
519 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
520 const gp_XYZ& aParams,
522 StdMeshers_TNode& aTN)
524 double aX, aY, aZ, aD, aTol2, minD;
527 SMESH_Mesh* pMesh = GetMesh();
528 aTol2 = myTol3D*myTol3D;
530 SMDS_MeshNode* pNode = NULL;
532 if ( aS.ShapeType() == TopAbs_FACE ||
533 aS.ShapeType() == TopAbs_EDGE ) {
534 // find a face ID to which aTN belongs to
536 if ( aS.ShapeType() == TopAbs_FACE )
537 faceID = myBlock.ShapeID( aS );
538 else { // edge maybe vertical or top horizontal
539 gp_XYZ aCoord = aParams;
540 if ( aCoord.Z() == 1. )
541 aCoord.SetZ( 0.5 ); // move from top down
543 aCoord.SetX( 0.5 ); // move along X
544 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
546 ASSERT( SMESH_Block::IsFaceID( faceID ));
547 int fIndex = SMESH_Block::ShapeIndex( faceID );
548 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
549 // look for a base node in ijNodes
550 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
551 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
552 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
553 if ( par_nVec->second[ 0 ] == baseNode ) {
554 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
560 myBlock.Point(aParams, aS, aP1);
562 SMDS_NodeIteratorPtr ite=
563 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
565 const SMDS_MeshNode* aNode = ite->next();
566 if(myTool->IsMedium(aNode))
571 aP2.SetCoord(aX, aY, aZ);
572 aD=(double)aP1.SquareDistance(aP2);
573 //printf("** D=%lf ", aD, aTol2);
575 pNode=(SMDS_MeshNode*)aNode;
585 //aTN.SetNode(pNode);
586 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
587 //myErrorStatus=11; // can not find the node;
591 //=======================================================================
592 //function : SetHorizEdgeXYZ
594 //=======================================================================
596 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
598 vector<const SMDS_MeshNode*>*& aCol1,
599 vector<const SMDS_MeshNode*>*& aCol2)
601 // find base and top edges of the face
602 enum { BASE = 0, TOP };
603 vector< int > edgeVec; // 0-base, 1-top
604 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
606 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
607 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
609 double param = aBaseNodeParams.Coord( coord );
613 // look for columns around param
614 StdMeshers_IJNodeMap & ijNodes =
615 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
616 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
617 while ( par_nVec_1->first < param )
619 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
622 if ( par_nVec_1 != ijNodes.begin() ) {
624 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
626 aCol1 = & par_nVec_1->second;
627 aCol2 = & par_nVec_2->second;
631 // this variant is better for cases with curved edges and
632 // different nodes distribution on top and base edges
633 const SMDS_MeshNode* n1 = aCol1->back();
634 const SMDS_MeshNode* n2 = aCol2->back();
635 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
636 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
637 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
640 // this variant is better for other cases
641 // SMESH_MesherHelper helper( *GetMesh() );
642 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
643 // double u1 = helper.GetNodeU( edge, n1 );
644 // double u2 = helper.GetNodeU( edge, n2 );
645 // double u = ( 1. - r ) * u1 + r * u2;
646 // gp_XYZ topNodeParams;
647 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
648 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
650 // myShapeXYZ[ edgeVec[ TOP ]]);
654 myBlock.Block().EdgePoint( edgeVec[ BASE ],
656 myShapeXYZ[ edgeVec[ BASE ]]);
661 //=======================================================================
662 //function : MakeVolumeMesh
664 //=======================================================================
665 void StdMeshers_Penta_3D::MakeVolumeMesh()
667 int i, j, ij, ik, i1, i2, aSSID;
669 SMESH_Mesh* pMesh = GetMesh();
670 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
672 int shapeID = meshDS->ShapeToIndex( myShape );
674 // 1. Set Node In Volume
676 for (i=1; i<ik; ++i){
677 for (j=0; j<myJSize; ++j){
679 const StdMeshers_TNode& aTN = myTNodes[ij];
680 aSSID=aTN.ShapeSupportID();
681 if (aSSID==SMESH_Block::ID_NONE) {
682 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
683 meshDS->SetNodeInVolume(aNode, shapeID);
688 // 2. Make pentahedrons
690 vector<const SMDS_MeshNode*> aN;
692 SMDS_ElemIteratorPtr itf, aItNodes;
694 const TopoDS_Face& aFxy0=
695 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
696 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
697 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
699 itf = aSM0->GetElements();
701 const SMDS_MeshElement* pE0 = itf->next();
703 int nbFaceNodes = pE0->NbNodes();
704 if(myCreateQuadratic)
705 nbFaceNodes = nbFaceNodes/2;
706 if ( aN.size() < nbFaceNodes * 2 )
707 aN.resize( nbFaceNodes * 2 );
710 aItNodes=pE0->nodesIterator();
711 while (aItNodes->more()) {
712 //const SMDS_MeshElement* pNode = aItNodes->next();
713 const SMDS_MeshNode* pNode =
714 static_cast<const SMDS_MeshNode*> (aItNodes->next());
715 if(myTool->IsMedium(pNode))
717 aID0 = pNode->GetID();
718 aJ[k] = GetIndexOnLayer(aID0);
719 if (!myErrorStatus->IsOK()) {
720 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
728 for (i=0; i<ik; ++i) {
731 for(j=0; j<nbFaceNodes; ++j) {
732 ij = i1*myJSize+aJ[j];
733 const StdMeshers_TNode& aTN1 = myTNodes[ij];
734 const SMDS_MeshNode* aN1 = aTN1.Node();
738 const StdMeshers_TNode& aTN2 = myTNodes[ij];
739 const SMDS_MeshNode* aN2 = aTN2.Node();
740 aN[j+nbFaceNodes] = aN2;
742 // check if volume orientation will be ok
744 SMDS_VolumeTool vTool;
745 switch ( nbFaceNodes ) {
747 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
748 aN[3], aN[4], aN[5]);
749 vTool.Set( &tmpVol );
753 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
754 aN[4], aN[5], aN[6], aN[7]);
755 vTool.Set( &tmpVol );
761 forward = vTool.IsForward();
764 SMDS_MeshVolume* aV = 0;
765 switch ( nbFaceNodes ) {
768 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
769 // aN[3], aN[4], aN[5]);
770 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
773 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
774 // aN[3], aN[5], aN[4]);
775 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
780 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
781 // aN[4], aN[5], aN[6], aN[7]);
782 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
783 aN[4], aN[5], aN[6], aN[7]);
786 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
787 // aN[4], aN[7], aN[6], aN[5]);
788 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
789 aN[4], aN[7], aN[6], aN[5]);
795 meshDS->SetMeshElementOnShape(aV, shapeID);
800 //=======================================================================
801 //function : MakeMeshOnFxy1
803 //=======================================================================
804 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
806 int aID0, aJ, aLevel, ij, aNbNodes, k;
808 SMDS_NodeIteratorPtr itn;
809 SMDS_ElemIteratorPtr itf, aItNodes;
810 SMDSAbs_ElementType aElementType;
812 const TopoDS_Face& aFxy0=
813 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
814 const TopoDS_Face& aFxy1=
815 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
816 SMESH_MesherHelper faceHelper( *GetMesh() );
817 faceHelper.IsQuadraticSubMesh(aFxy1);
819 SMESH_Mesh* pMesh = GetMesh();
820 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
822 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
823 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
824 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
826 // set nodes on aFxy1
828 itn = aSM0->GetNodes();
829 aNbNodes = aSM0->NbNodes();
830 //printf("** aNbNodes=%d\n", aNbNodes);
833 // set elements on aFxy1
834 vector<const SMDS_MeshNode*> aNodes1;
836 itf = aSM0->GetElements();
838 const SMDS_MeshElement* pE0 = itf->next();
839 aElementType = pE0->GetType();
840 if (!aElementType==SMDSAbs_Face) {
843 aNbNodes = pE0->NbNodes();
844 if(myCreateQuadratic)
845 aNbNodes = aNbNodes/2;
846 if ( aNodes1.size() < aNbNodes )
847 aNodes1.resize( aNbNodes );
849 k = aNbNodes-1; // reverse a face
850 aItNodes = pE0->nodesIterator();
851 while (aItNodes->more()) {
852 const SMDS_MeshNode* pNode =
853 static_cast<const SMDS_MeshNode*> (aItNodes->next());
854 if(myTool->IsMedium(pNode))
856 aID0 = pNode->GetID();
857 aJ = GetIndexOnLayer(aID0);
858 if (!myErrorStatus->IsOK()) {
859 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
863 ij = aLevel*myJSize + aJ;
864 const StdMeshers_TNode& aTN1 = myTNodes[ij];
865 const SMDS_MeshNode* aN1 = aTN1.Node();
869 SMDS_MeshFace * face = 0;
870 switch ( aNbNodes ) {
872 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
875 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
880 meshDS->SetMeshElementOnShape(face, aFxy1);
883 // update compute state of top face submesh
884 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
886 // assure that mesh on the top face will be cleaned when it is cleaned
887 // on the bottom face
888 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
889 volSM->SetEventListener( new SMESH_subMeshEventListener(true),
890 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
891 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
894 //=======================================================================
895 //function : ClearMeshOnFxy1
897 //=======================================================================
898 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
900 SMESH_subMesh* aSubMesh;
901 SMESH_Mesh* pMesh=GetMesh();
903 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
904 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
906 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
909 //=======================================================================
910 //function : GetIndexOnLayer
912 //=======================================================================
913 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
916 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
918 aMapIt=myConnectingMap.find(aID);
919 if (aMapIt==myConnectingMap.end()) {
920 myErrorStatus->myName = 200;
921 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
928 //=======================================================================
929 //function : MakeConnectingMap
931 //=======================================================================
932 void StdMeshers_Penta_3D::MakeConnectingMap()
936 for (j=0; j<myJSize; ++j) {
937 const StdMeshers_TNode& aBN=myTNodes[j];
938 aBNID=aBN.BaseNodeID();
939 myConnectingMap[aBNID]=j;
943 //=======================================================================
944 //function : CreateNode
946 //=======================================================================
947 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
948 const gp_XYZ& aParams,
949 StdMeshers_TNode& aTN)
955 SMDS_MeshNode* pNode=NULL;
958 // if (bIsUpperLayer) {
959 // // point on face Fxy1
960 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
961 // myBlock.Point(aParams, aS, aP);
964 // // point inside solid
965 // myBlock.Point(aParams, aP);
968 double u = aParams.X(), v = aParams.Y();
969 double u1 = ( 1. - u ), v1 = ( 1. - v );
970 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
971 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
972 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
973 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
975 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
976 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
977 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
978 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
981 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
984 // iErr=myBlock.ErrorStatus();
986 // myErrorStatus=12; // can not find the node point;
990 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
992 SMESH_Mesh* pMesh = GetMesh();
993 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
995 pNode = pMeshDS->AddNode(aX, aY, aZ);
1000 //=======================================================================
1001 //function : ShapeSupportID
1003 //=======================================================================
1004 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
1005 const SMESH_Block::TShapeID aBNSSID,
1006 SMESH_Block::TShapeID& aSSID)
1009 case SMESH_Block::ID_V000:
1010 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
1012 case SMESH_Block::ID_V100:
1013 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
1015 case SMESH_Block::ID_V110:
1016 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
1018 case SMESH_Block::ID_V010:
1019 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
1021 case SMESH_Block::ID_Ex00:
1022 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
1024 case SMESH_Block::ID_Ex10:
1025 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
1027 case SMESH_Block::ID_E0y0:
1028 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
1030 case SMESH_Block::ID_E1y0:
1031 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
1033 case SMESH_Block::ID_Fxy0:
1034 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1037 aSSID=SMESH_Block::ID_NONE;
1038 myErrorStatus->myName=10; // Can not find supporting shape ID
1039 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
1044 //=======================================================================
1045 //function : MakeBlock
1047 //=======================================================================
1048 void StdMeshers_Penta_3D::MakeBlock()
1051 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1053 TopoDS_Vertex aV000, aV001;
1055 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1056 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1057 TopTools_ListIteratorOfListOfShape aIt;
1059 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1061 // 0. Find triangulated face aFTr
1062 SMDSAbs_ElementType aElementType;
1063 SMESH_Mesh* pMesh=GetMesh();
1067 for (i=1; i<=iNbF; ++i) {
1068 const TopoDS_Shape& aF = aM(i);
1069 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1071 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1072 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1073 while(itf->more()) {
1074 const SMDS_MeshElement * pElement = itf->next();
1075 aElementType = pElement->GetType();
1076 if (aElementType==SMDSAbs_Face) {
1077 iNbNodes = pElement->NbNodes();
1078 if ( iNbNodes==3 || (myCreateQuadratic && iNbNodes==6) ) {
1083 // The current algorithm fails if there is more that one
1084 // face wich contains triangles ...
1085 // In that case, replace return by break to try another
1086 // method (coded in "if (iCnt != 1) { ... }")
1088 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1089 // myErrorStatus=5; // more than one face has triangulation
1101 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1102 // was not reached 'cause it was not called from Hexa_3D ... Now it
1103 // can occurs and in my opinion, it is the most common case.
1106 // The suggested algorithm is the following :
1108 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1109 // then the shape is tologically equivalent to a box
1110 // o In a box, there are three set of four // edges ...
1111 // In the cascade notation, it seems to be the edges
1116 // o For each one of this set, check if the four edges
1117 // have the same number of element.
1118 // o If so, check if the "corresponding" // faces contains
1119 // only quads. It's the faces numbered:
1123 // o If so, check if the opposite edges of each // faces
1124 // have the same number of elements. It is the edges
1126 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1127 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1128 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1129 // o If so, check if the two other faces have the same
1130 // number of elements. It is the faces numbered:
1134 // This test should be improved to test if the nodes
1135 // of the two faces are really "en face".
1136 // o If so, one of the two faces is a candidate to an extrusion,
1137 // It is the faces numbered :
1141 // o Finally, if there is only one candidate, let do the
1142 // extrusion job for the corresponding face
1146 int iNbF = aM.Extent();
1149 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1150 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1151 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1152 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1153 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1154 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1156 int has_only_quad_f1 = 1;
1157 int has_only_quad_f2 = 1;
1158 int has_only_quad_f3 = 1;
1159 int has_only_quad_f4 = 1;
1160 int has_only_quad_f5 = 1;
1161 int has_only_quad_f6 = 1;
1163 for (i=1; i<=iNbF; ++i) {
1165 const TopoDS_Shape& aF = aM(i);
1166 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1167 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1168 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1169 while(itf->more()) {
1170 const SMDS_MeshElement * pElement = itf->next();
1171 aElementType = pElement->GetType();
1172 if (aElementType==SMDSAbs_Face) {
1173 iNbNodes = pElement->NbNodes();
1174 if ( iNbNodes!=4 ) {
1180 if (i==1) has_only_quad_f1 = ok ;
1181 if (i==2) has_only_quad_f2 = ok ;
1182 if (i==3) has_only_quad_f3 = ok ;
1183 if (i==4) has_only_quad_f4 = ok ;
1184 if (i==5) has_only_quad_f5 = ok ;
1185 if (i==6) has_only_quad_f6 = ok ;
1188 TopTools_IndexedMapOfShape aE;
1189 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1190 int iNbE = aE.Extent();
1193 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1194 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1195 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1196 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1197 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1198 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1199 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1200 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1201 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1202 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1203 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1204 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1208 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1209 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1210 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1218 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1219 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1220 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1228 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1229 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1230 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1246 myErrorStatus->myName=5; // more than one face has triangulation
1247 myErrorStatus->myComment="Incorrect input mesh";
1253 // 1. Vetrices V00, V001;
1255 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1256 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1258 // 1.1 Base vertex V000
1259 iNbE = aME.Extent();
1260 if (iNbE!= NB_WALL_FACES ){
1261 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1262 myErrorStatus->myName=7; // too few edges are in base face aFTr
1263 myErrorStatus->myComment=SMESH_Comment("Not a quadrilateral face #")
1264 <<pMesh->GetMeshDS()->ShapeToIndex( aFTr )<<": "<<iNbE<<" edges" ;
1267 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1268 aV000=TopExp::FirstVertex(aE1);
1270 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1271 aIt.Initialize(aLE);
1272 for (; aIt.More(); aIt.Next()) {
1273 const TopoDS_Shape& aEx=aIt.Value();
1276 iNbEV=aMEV.Extent();
1278 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1279 myErrorStatus->myName=7; // too few edges meet in base vertex
1280 myErrorStatus->myComment=SMESH_Comment("3 edges must share vertex #")
1281 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 )<<" but there are "<<iNbEV<<" edges";
1287 for (j=1; j<=iNbEV; ++j) {
1288 const TopoDS_Shape& aEx=aMEV(j);
1289 if (!aME.Contains(aEx)) {
1290 TopoDS_Vertex aV[2];
1292 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1293 TopExp::Vertices(aE, aV[0], aV[1]);
1294 for (i=0; i<2; ++i) {
1295 if (!aV[i].IsSame(aV000)) {
1305 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1306 myErrorStatus->myName=8; // can not find reper V001
1307 myErrorStatus->myComment=SMESH_Comment("Can't find opposite vertex for vertex #")
1308 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 );
1312 //gp_Pnt aP000, aP001;
1314 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1315 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1316 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1317 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1321 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1324 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1325 myErrorStatus->myName=9; // number of shells in source shape !=1
1326 myErrorStatus->myComment=SMESH_Comment("Unexpected nb of shells ")<<iNbE;
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=myBlock.GetError(); // SMESHBlock: Load operation failed
1340 //=======================================================================
1341 //function : CheckData
1343 //=======================================================================
1344 void StdMeshers_Penta_3D::CheckData()
1347 int iNbEx[]={8, 12, 6};
1349 TopAbs_ShapeEnum aST;
1350 TopAbs_ShapeEnum aSTEx[]={
1351 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1353 TopTools_IndexedMapOfShape aM;
1355 if (myShape.IsNull()){
1356 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1357 myErrorStatus->myName=2; // null shape
1358 myErrorStatus->myComment="Null shape";
1362 aST=myShape.ShapeType();
1363 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1364 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1365 myErrorStatus->myName=3; // not compatible type of shape
1366 myErrorStatus->myComment=SMESH_Comment("Wrong shape type (TopAbs_ShapeEnum) ")<<aST;
1370 for (i=0; i<3; ++i) {
1372 TopExp::MapShapes(myShape, aSTEx[i], aM);
1375 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1376 myErrorStatus->myName=4; // number of subshape is not compatible
1377 myErrorStatus->myComment="Wrong number of subshapes of a block";
1383 //=======================================================================
1384 //function : LoadIJNodes
1385 //purpose : Load nodes bound to theFace into column (vectors) and rows
1387 // The value of theIJNodes map is a vector of ordered nodes so
1388 // that the 0-the one lies on theBaseEdge.
1389 // The key of theIJNodes map is a normalized parameter of each
1390 // 0-the node on theBaseEdge.
1391 //=======================================================================
1393 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1394 const TopoDS_Face& theFace,
1395 const TopoDS_Edge& theBaseEdge,
1396 SMESHDS_Mesh* theMesh)
1398 // get vertices of theBaseEdge
1399 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1400 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1401 TopExp::Vertices( eFrw, vfb, vlb );
1403 // find the other edges of theFace and orientation of e1
1404 TopoDS_Edge e1, e2, eTop;
1405 bool rev1, CumOri = false;
1406 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1408 for ( ; exp.More(); exp.Next() ) {
1409 if ( ++nbEdges > NB_WALL_FACES ) {
1410 return false; // more than 4 edges in theFace
1412 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1413 if ( theBaseEdge.IsSame( e ))
1415 TopoDS_Vertex vCommon;
1416 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1418 else if ( vCommon.IsSame( vfb )) {
1420 vft = TopExp::LastVertex( e1, CumOri );
1421 rev1 = vfb.IsSame( vft );
1423 vft = TopExp::FirstVertex( e1, CumOri );
1428 if ( nbEdges < NB_WALL_FACES ) {
1429 return false; // less than 4 edges in theFace
1432 // submeshes corresponding to shapes
1433 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1434 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1435 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1436 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1437 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1438 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1439 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1440 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1441 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1442 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1443 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1446 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1447 MESSAGE(" Diff nb of nodes on opposite edges" );
1450 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1451 MESSAGE("Empty submesh of vertex");
1454 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1455 // check quadratic case
1456 if ( myCreateQuadratic ) {
1457 int n1 = sm1->NbNodes()/2;
1458 int n2 = smb->NbNodes()/2;
1459 int n3 = sm1->NbNodes() - n1;
1460 int n4 = smb->NbNodes() - n2;
1461 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1462 if( nf != smFace->NbNodes() ) {
1463 MESSAGE( "Wrong nb face nodes: " <<
1464 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1469 MESSAGE( "Wrong nb face nodes: " <<
1470 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1475 int vsize = sm1->NbNodes() + 2;
1476 int hsize = smb->NbNodes() + 2;
1477 if(myCreateQuadratic) {
1478 vsize = vsize - sm1->NbNodes()/2 -1;
1479 hsize = hsize - smb->NbNodes()/2 -1;
1482 // load nodes from theBaseEdge
1484 set<const SMDS_MeshNode*> loadedNodes;
1485 const SMDS_MeshNode* nullNode = 0;
1487 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1488 nVecf.resize( vsize, nullNode );
1489 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1491 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1492 nVecl.resize( vsize, nullNode );
1493 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1496 BRep_Tool::Range( eFrw, f, l );
1497 double range = l - f;
1498 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1499 const SMDS_MeshNode* node;
1500 while ( nIt->more() ) {
1502 if(myTool->IsMedium(node))
1504 const SMDS_EdgePosition* pos =
1505 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1509 double u = ( pos->GetUParameter() - f ) / range;
1510 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1511 nVec.resize( vsize, nullNode );
1512 loadedNodes.insert( nVec[ 0 ] = node );
1514 if ( theIJNodes.size() != hsize ) {
1515 MESSAGE( "Wrong node positions on theBaseEdge" );
1519 // load nodes from e1
1521 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1522 nIt = sm1->GetNodes();
1523 while ( nIt->more() ) {
1525 if(myTool->IsMedium(node))
1527 const SMDS_EdgePosition* pos =
1528 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1532 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1534 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1535 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1536 int row = rev1 ? vsize - 1 : 0;
1537 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1540 loadedNodes.insert( nVecf[ row ] = u_n->second );
1543 // try to load the rest nodes
1545 // get all faces from theFace
1546 TIDSortedElemSet allFaces, foundFaces;
1547 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1548 while ( eIt->more() ) {
1549 const SMDS_MeshElement* e = eIt->next();
1550 if ( e->GetType() == SMDSAbs_Face )
1551 allFaces.insert( e );
1553 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1554 // the nodes belong to, and between the nodes of the found face,
1555 // look for a not loaded node considering this node to be the next
1556 // in a column of the starting second node. Repeat, starting
1557 // from nodes next to the previous starting nodes in their columns,
1558 // and so on while a face can be found. Then go the the next pair
1559 // of nodes on theBaseEdge.
1560 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1561 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1564 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1567 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1568 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1569 const SMDS_MeshElement* face = 0;
1571 // look for a face by 2 nodes
1572 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1574 int nbFaceNodes = face->NbNodes();
1575 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1576 (myCreateQuadratic && nbFaceNodes>8) ) {
1577 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1580 // look for a not loaded node of the <face>
1582 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1583 eIt = face->nodesIterator() ;
1584 while ( !found && eIt->more() ) {
1585 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1586 if(myTool->IsMedium(node))
1588 found = loadedNodes.insert( node ).second;
1589 if ( !found && node != n1 && node != n2 )
1593 if ( ++row > vsize - 1 ) {
1594 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1597 par_nVec_2->second[ row ] = node;
1598 foundFaces.insert( face );
1600 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1601 n1 = par_nVec_1->second[ row ];
1604 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1605 n3 == par_nVec_1->second[ row ] ) {
1609 MESSAGE( "Not quad mesh, column "<< col );
1614 while ( face && n1 && n2 );
1616 if ( row < vsize - 1 ) {
1617 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1618 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1619 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1620 MESSAGE( "Current node 1: "<< n1);
1621 MESSAGE( "Current node 2: "<< n2);
1622 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1623 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1626 } // loop on columns
1631 //////////////////////////////////////////////////////////////////////////
1633 // StdMeshers_SMESHBlock
1635 //////////////////////////////////////////////////////////////////////////
1637 //=======================================================================
1638 //function : StdMeshers_SMESHBlock
1640 //=======================================================================
1641 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1644 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1647 //=======================================================================
1648 //function : IsForwadEdge
1650 //=======================================================================
1652 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1654 int index = myTBlock.ShapeIndex( theEdgeID );
1655 if ( !myTBlock.IsEdgeID( theEdgeID ))
1658 if ( myIsEdgeForward[ index ] < 0 )
1659 myIsEdgeForward[ index ] =
1660 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1662 return myIsEdgeForward[ index ];
1665 //=======================================================================
1666 //function : ErrorStatus
1668 //=======================================================================
1669 int StdMeshers_SMESHBlock::ErrorStatus() const
1671 return myErrorStatus;
1674 //================================================================================
1676 * \brief Return problem description
1678 //================================================================================
1680 SMESH_ComputeErrorPtr StdMeshers_SMESHBlock::GetError() const
1682 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1683 string & text = err->myComment;
1684 switch ( myErrorStatus ) {
1686 case 3: text = "Internal error of StdMeshers_Penta_3D"; break;
1687 case 4: text = "Can't compute normalized parameters of a point inside a block"; break;
1688 case 5: text = "Can't compute coordinates by normalized parameters inside a block"; break;
1689 case 6: text = "Can't detect block subshapes. Not a block?"; break;
1692 err->myName = myErrorStatus;
1696 //=======================================================================
1699 //=======================================================================
1700 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1702 TopoDS_Vertex aV000, aV001;
1704 Load(theShell, aV000, aV001);
1707 //=======================================================================
1710 //=======================================================================
1711 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1712 const TopoDS_Vertex& theV000,
1713 const TopoDS_Vertex& theV001)
1721 myShapeIDMap.Clear();
1722 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1729 //=======================================================================
1730 //function : ComputeParameters
1732 //=======================================================================
1733 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1736 ComputeParameters(thePnt, myShell, theXYZ);
1739 //=======================================================================
1740 //function : ComputeParameters
1742 //=======================================================================
1743 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1744 const TopoDS_Shape& theShape,
1752 aID = ShapeID(theShape);
1753 if (myErrorStatus) {
1756 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1758 myErrorStatus=4; // problems with computation Parameters
1763 //=======================================================================
1764 //function : ComputeParameters
1766 //=======================================================================
1768 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1769 const TopoDS_Shape& theShape,
1777 aID = ShapeID(theShape);
1778 if (myErrorStatus) {
1781 if ( SMESH_Block::IsEdgeID( aID ))
1782 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1784 myErrorStatus=4; // problems with computation Parameters
1789 //=======================================================================
1792 //=======================================================================
1793 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1798 Point(theParams, aS, aP3D);
1801 //=======================================================================
1804 //=======================================================================
1805 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1806 const TopoDS_Shape& theShape,
1813 gp_XYZ aXYZ(99.,99.,99.);
1816 if (theShape.IsNull()) {
1817 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1821 aID=ShapeID(theShape);
1822 if (myErrorStatus) {
1826 if (SMESH_Block::IsVertexID(aID)) {
1827 bOk = myTBlock.VertexPoint(aID, aXYZ);
1829 else if (SMESH_Block::IsEdgeID(aID)) {
1830 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1833 else if (SMESH_Block::IsFaceID(aID)) {
1834 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1838 myErrorStatus=5; // problems with point computation
1844 //=======================================================================
1845 //function : ShapeID
1847 //=======================================================================
1848 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1853 TopoDS_Shape aSF, aSR;
1856 aSF.Orientation(TopAbs_FORWARD);
1858 aSR.Orientation(TopAbs_REVERSED);
1860 if (myShapeIDMap.Contains(aSF)) {
1861 aID=myShapeIDMap.FindIndex(aSF);
1864 if (myShapeIDMap.Contains(aSR)) {
1865 aID=myShapeIDMap.FindIndex(aSR);
1868 myErrorStatus=2; // unknown shape;
1872 //=======================================================================
1875 //=======================================================================
1876 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1882 aNb=myShapeIDMap.Extent();
1883 if (theID<1 || theID>aNb) {
1884 myErrorStatus=3; // ID is out of range
1885 return myEmptyShape;
1888 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);