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>
64 typedef map < int, int, less<int> >::iterator \
65 StdMeshers_IteratorOfDataMapOfIntegerInteger;
67 enum { NB_WALL_FACES = 4 };
69 //=======================================================================
70 //function : StdMeshers_Penta_3D
72 //=======================================================================
73 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
77 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
78 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
82 //=======================================================================
83 //function : ~StdMeshers_Penta_3D
85 //=======================================================================
87 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
93 //=======================================================================
96 //=======================================================================
97 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
98 const TopoDS_Shape& aShape)
100 MESSAGE("StdMeshers_Penta_3D::Compute()");
114 myTool = new SMESH_MesherHelper(aMesh);
115 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
120 delete myTool; myTool = 0;
126 delete myTool; myTool = 0;
132 delete myTool; myTool = 0;
140 delete myTool; myTool = 0;
146 delete myTool; myTool = 0;
150 //=======================================================================
151 //function : MakeNodes
153 //=======================================================================
154 void StdMeshers_Penta_3D::MakeNodes()
159 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
161 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
162 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
163 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
164 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
165 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
169 SMESH_Mesh* pMesh=GetMesh();
171 // 1. Define the sizes of mesh
173 // 1.1 Horizontal size
175 for (i=0; i<aNbSIDs; ++i) {
176 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
177 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
179 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
180 if(!myCreateQuadratic) {
181 iNbN = aSM->NbNodes();
185 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
187 const SMDS_MeshNode* aNode = itn->next();
188 if(myTool->IsMedium(aNode))
195 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
200 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
201 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
203 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
204 if(!myCreateQuadratic) {
205 iNbN = aSM->NbNodes();
209 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
211 const SMDS_MeshNode* aNode = itn->next();
212 if(myTool->IsMedium(aNode))
219 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
221 aSize=myISize*myJSize;
222 myTNodes.resize(aSize);
224 StdMeshers_TNode aTNode;
228 // 2. Fill the repers on base face (Z=0)
231 for (k=0; k<aNbSIDs; ++k) {
233 const TopoDS_Shape& aS = myBlock.Shape(aSID);
234 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
236 const SMDS_MeshNode* aNode = ite->next();
237 if(myTool->IsMedium(aNode))
239 aNodeID=aNode->GetID();
241 aTNode.SetNode(aNode);
242 aTNode.SetShapeSupportID(aSID);
243 aTNode.SetBaseNodeID(aNodeID);
245 if ( SMESH_Block::IsEdgeID (aSID)) {
246 const SMDS_EdgePosition* epos =
247 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
248 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
254 aP3D.SetCoord(aX, aY, aZ);
255 myBlock.ComputeParameters(aP3D, aS, aCoords);
257 iErr = myBlock.ErrorStatus();
259 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
260 "SMESHBlock: ComputeParameters operation failed");
261 myErrorStatus=101; // SMESHBlock: ComputeParameters operation failed
264 aTNode.SetNormCoord(aCoords);
271 // 3.1 Fill maps of wall nodes
272 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
273 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
274 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
276 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
277 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
278 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
280 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
281 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
282 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
283 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
284 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
287 myErrorStatus = i + 1;
288 MESSAGE(" Cant LoadIJNodes() from a wall face " << myErrorStatus );
293 // 3.2 find node columns for vertical edges and edge IDs
294 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
295 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
296 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
298 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
299 ShapeSupportID(false, vID, eID);
300 verticEdgeID[ i ] = eID;
302 StdMeshers_TNode& aTNode = myTNodes[ i ];
303 verticEdgeNodes[ i ] = 0;
304 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
305 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
306 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
307 if ( ijNodes.begin()->second[0] == aTNode.Node() )
308 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
309 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
310 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
311 if ( verticEdgeNodes[ i ] )
316 // 3.3 set XYZ of vertices, and initialize of the rest
317 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
318 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
319 if ( SMESH_Block::IsVertexID( id )) {
320 TopoDS_Shape V = myBlock.Shape( id );
321 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
322 const SMDS_MeshNode* n = sm->GetNodes()->next();
323 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
326 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
330 // 4. Fill the rest repers
333 SMESH_Block::TShapeID aSSID, aBNSSID;
334 StdMeshers_TNode aTN;
337 // create top face and find UV for it's corners
338 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
339 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
340 int topfaceID = meshDS->ShapeToIndex(TopFace);
341 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
342 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
343 const SMDS_MeshNode* N = itn->next();
344 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
345 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
346 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
348 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
349 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
350 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
352 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
353 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
354 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
356 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
358 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
360 const StdMeshers_TNode& aBN = myTNodes[j];
361 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
362 iBNID = aBN.BaseNodeID();
363 const gp_XYZ& aBNXYZ = aBN.NormCoord();
364 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
366 // set XYZ on horizontal edges and get node columns of faces:
367 // 2 columns for each face, between which a base node is located
368 vector<const SMDS_MeshNode*>* nColumns[8];
369 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
371 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
372 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
373 nColumns[k*2], nColumns[k*2+1]);
377 // XYZ on the bottom and top faces
378 const SMDS_MeshNode* n = aBN.Node();
379 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
380 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
382 // first create or find a top node, then the rest ones in a column
383 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
385 bIsUpperLayer = (i==(myISize-1));
386 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
387 if ( createNode ) // a base node is inside a top face
389 // set XYZ on vertical edges and faces
390 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
391 // XYZ on a vertical edge
392 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
393 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
394 // XYZ on a face (part 1 from one column)
395 n = (*nColumns[k*2]) [ i ];
396 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
397 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
399 if( bIsUpperLayer ) {
400 tmp1 = myTool->GetNodeUV(TopFace,n);
401 tmp1 = ( 1. - ratio[ k ]) * tmp1;
403 // XYZ on a face (part 2 from other column)
404 n = (*nColumns[k*2+1]) [ i ];
405 xyz.SetCoord( n->X(), n->Y(), n->Z() );
406 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
407 if( bIsUpperLayer ) {
408 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
409 tmp1 += ratio[ k ] * tmp2;
421 // fill current node info
424 // -normalized coordinates
428 aZ=(double)i/(double)(myISize-1);
429 aCoords.SetCoord(aX, aY, aZ);
431 // suporting shape ID
432 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
434 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
438 aTN.SetShapeSupportID(aSSID);
439 aTN.SetNormCoord(aCoords);
440 aTN.SetBaseNodeID(iBNID);
442 if (aSSID!=SMESH_Block::ID_NONE){
443 // try to find the node
444 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
445 FindNodeOnShape(aS, aCoords, i, aTN);
448 // create node and get it id
449 CreateNode (bIsUpperLayer, aCoords, aTN);
451 if ( bIsUpperLayer ) {
452 const SMDS_MeshNode* n = aTN.Node();
453 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
454 // set node on top face:
455 // find UV parameter for this node
457 // UV011+-----+----------+UV111
460 // UV_E0y1+ +node +UV_E1y1
464 // UV001+-----+----------+UV101
467 double u = aCoords.X(), v = aCoords.Y();
468 double u1 = ( 1. - u ), v1 = ( 1. - v );
469 aP.ChangeCoord() = UV_Ex01 * v1;
470 aP.ChangeCoord() += UV_Ex11 * v;
471 aP.ChangeCoord() += UV_E0y1 * u1;
472 aP.ChangeCoord() += UV_E1y1 * u;
473 aP.ChangeCoord() -= UV001 * u1 * v1;
474 aP.ChangeCoord() -= UV101 * u * v1;
475 aP.ChangeCoord() -= UV011 * u1 * v;
476 aP.ChangeCoord() -= UV111 * u * v;
477 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
481 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
491 int iSSID, iBNID, aID;
493 for (i=0; i<myISize; ++i) {
494 printf(" Layer# %d\n", i);
495 for (j=0; j<myJSize; ++j) {
497 const StdMeshers_TNode& aTN=myTNodes[ij];
498 //const StdMeshers_TNode& aTN=aTNodes[ij];
499 const gp_XYZ& aXYZ=aTN.NormCoord();
500 iSSID=aTN.ShapeSupportID();
501 iBNID=aTN.BaseNodeID();
503 const SMDS_MeshNode* aNode=aTN.Node();
508 printf("*** j:%d BNID#%d iSSID:%d ID:%d { %lf %lf %lf }, { %lf %lf %lf }\n",
509 j, iBNID, iSSID, aID, aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aX, aY, aZ);
518 //=======================================================================
519 //function : FindNodeOnShape
521 //=======================================================================
523 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
524 const gp_XYZ& aParams,
526 StdMeshers_TNode& aTN)
530 double aX, aY, aZ, aD, aTol2, minD;
533 SMESH_Mesh* pMesh = GetMesh();
534 aTol2 = myTol3D*myTol3D;
536 SMDS_MeshNode* pNode = NULL;
538 if ( aS.ShapeType() == TopAbs_FACE ||
539 aS.ShapeType() == TopAbs_EDGE ) {
540 // find a face ID to which aTN belongs to
542 if ( aS.ShapeType() == TopAbs_FACE )
543 faceID = myBlock.ShapeID( aS );
544 else { // edge maybe vertical or top horizontal
545 gp_XYZ aCoord = aParams;
546 if ( aCoord.Z() == 1. )
547 aCoord.SetZ( 0.5 ); // move from top down
549 aCoord.SetX( 0.5 ); // move along X
550 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
552 ASSERT( SMESH_Block::IsFaceID( faceID ));
553 int fIndex = SMESH_Block::ShapeIndex( faceID );
554 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
555 // look for a base node in ijNodes
556 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
557 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
558 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
559 if ( par_nVec->second[ 0 ] == baseNode ) {
560 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
566 myBlock.Point(aParams, aS, aP1);
568 SMDS_NodeIteratorPtr ite=
569 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
571 const SMDS_MeshNode* aNode = ite->next();
572 if(myTool->IsMedium(aNode))
577 aP2.SetCoord(aX, aY, aZ);
578 aD=(double)aP1.SquareDistance(aP2);
579 //printf("** D=%lf ", aD, aTol2);
581 pNode=(SMDS_MeshNode*)aNode;
591 //aTN.SetNode(pNode);
592 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
593 //myErrorStatus=11; // can not find the node;
597 //=======================================================================
598 //function : SetHorizEdgeXYZ
600 //=======================================================================
602 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
604 vector<const SMDS_MeshNode*>*& aCol1,
605 vector<const SMDS_MeshNode*>*& aCol2)
607 // find base and top edges of the face
608 enum { BASE = 0, TOP };
609 vector< int > edgeVec; // 0-base, 1-top
610 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
612 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
613 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
615 double param = aBaseNodeParams.Coord( coord );
619 // look for columns around param
620 StdMeshers_IJNodeMap & ijNodes =
621 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
622 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
623 while ( par_nVec_1->first < param )
625 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
628 if ( par_nVec_1 != ijNodes.begin() ) {
630 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
632 aCol1 = & par_nVec_1->second;
633 aCol2 = & par_nVec_2->second;
637 // this variant is better for cases with curved edges and
638 // different nodes distribution on top and base edges
639 const SMDS_MeshNode* n1 = aCol1->back();
640 const SMDS_MeshNode* n2 = aCol2->back();
641 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
642 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
643 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
646 // this variant is better for other cases
647 // SMESH_MesherHelper helper( *GetMesh() );
648 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
649 // double u1 = helper.GetNodeU( edge, n1 );
650 // double u2 = helper.GetNodeU( edge, n2 );
651 // double u = ( 1. - r ) * u1 + r * u2;
652 // gp_XYZ topNodeParams;
653 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
654 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
656 // myShapeXYZ[ edgeVec[ TOP ]]);
660 myBlock.Block().EdgePoint( edgeVec[ BASE ],
662 myShapeXYZ[ edgeVec[ BASE ]]);
667 //=======================================================================
668 //function : MakeVolumeMesh
670 //=======================================================================
671 void StdMeshers_Penta_3D::MakeVolumeMesh()
675 int i, j, ij, ik, i1, i2, aSSID;
677 SMESH_Mesh* pMesh = GetMesh();
678 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
680 int shapeID = meshDS->ShapeToIndex( myShape );
682 // 1. Set Node In Volume
684 for (i=1; i<ik; ++i){
685 for (j=0; j<myJSize; ++j){
687 const StdMeshers_TNode& aTN = myTNodes[ij];
688 aSSID=aTN.ShapeSupportID();
689 if (aSSID==SMESH_Block::ID_NONE) {
690 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
691 meshDS->SetNodeInVolume(aNode, shapeID);
696 // 2. Make pentahedrons
698 vector<const SMDS_MeshNode*> aN;
700 SMDS_ElemIteratorPtr itf, aItNodes;
702 const TopoDS_Face& aFxy0=
703 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
704 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
705 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
707 itf = aSM0->GetElements();
709 const SMDS_MeshElement* pE0 = itf->next();
711 int nbFaceNodes = pE0->NbNodes();
712 if(myCreateQuadratic)
713 nbFaceNodes = nbFaceNodes/2;
714 if ( aN.size() < nbFaceNodes * 2 )
715 aN.resize( nbFaceNodes * 2 );
718 aItNodes=pE0->nodesIterator();
719 while (aItNodes->more()) {
720 //const SMDS_MeshElement* pNode = aItNodes->next();
721 const SMDS_MeshNode* pNode =
722 static_cast<const SMDS_MeshNode*> (aItNodes->next());
723 if(myTool->IsMedium(pNode))
725 aID0 = pNode->GetID();
726 aJ[k] = GetIndexOnLayer(aID0);
728 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
736 for (i=0; i<ik; ++i) {
739 for(j=0; j<nbFaceNodes; ++j) {
740 ij = i1*myJSize+aJ[j];
741 const StdMeshers_TNode& aTN1 = myTNodes[ij];
742 const SMDS_MeshNode* aN1 = aTN1.Node();
746 const StdMeshers_TNode& aTN2 = myTNodes[ij];
747 const SMDS_MeshNode* aN2 = aTN2.Node();
748 aN[j+nbFaceNodes] = aN2;
750 // check if volume orientation will be ok
752 SMDS_VolumeTool vTool;
753 switch ( nbFaceNodes ) {
755 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
756 aN[3], aN[4], aN[5]);
757 vTool.Set( &tmpVol );
761 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
762 aN[4], aN[5], aN[6], aN[7]);
763 vTool.Set( &tmpVol );
769 forward = vTool.IsForward();
772 SMDS_MeshVolume* aV = 0;
773 switch ( nbFaceNodes ) {
776 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
777 // aN[3], aN[4], aN[5]);
778 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
781 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
782 // aN[3], aN[5], aN[4]);
783 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
788 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
789 // aN[4], aN[5], aN[6], aN[7]);
790 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
791 aN[4], aN[5], aN[6], aN[7]);
794 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
795 // aN[4], aN[7], aN[6], aN[5]);
796 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
797 aN[4], aN[7], aN[6], aN[5]);
803 meshDS->SetMeshElementOnShape(aV, shapeID);
808 //=======================================================================
809 //function : MakeMeshOnFxy1
811 //=======================================================================
812 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
816 int aID0, aJ, aLevel, ij, aNbNodes, k;
818 SMDS_NodeIteratorPtr itn;
819 SMDS_ElemIteratorPtr itf, aItNodes;
820 SMDSAbs_ElementType aElementType;
822 const TopoDS_Face& aFxy0=
823 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
824 const TopoDS_Face& aFxy1=
825 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
826 SMESH_MesherHelper faceHelper( *GetMesh() );
827 faceHelper.IsQuadraticSubMesh(aFxy1);
829 SMESH_Mesh* pMesh = GetMesh();
830 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
832 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
833 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
834 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
836 // set nodes on aFxy1
838 itn = aSM0->GetNodes();
839 aNbNodes = aSM0->NbNodes();
840 //printf("** aNbNodes=%d\n", aNbNodes);
843 // set elements on aFxy1
844 vector<const SMDS_MeshNode*> aNodes1;
846 itf = aSM0->GetElements();
848 const SMDS_MeshElement* pE0 = itf->next();
849 aElementType = pE0->GetType();
850 if (!aElementType==SMDSAbs_Face) {
853 aNbNodes = pE0->NbNodes();
854 if(myCreateQuadratic)
855 aNbNodes = aNbNodes/2;
856 if ( aNodes1.size() < aNbNodes )
857 aNodes1.resize( aNbNodes );
859 k = aNbNodes-1; // reverse a face
860 aItNodes = pE0->nodesIterator();
861 while (aItNodes->more()) {
862 //const SMDS_MeshElement* pNode = aItNodes->next();
863 const SMDS_MeshNode* pNode =
864 static_cast<const SMDS_MeshNode*> (aItNodes->next());
865 if(myTool->IsMedium(pNode))
867 aID0 = pNode->GetID();
868 aJ = GetIndexOnLayer(aID0);
870 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
874 ij = aLevel*myJSize + aJ;
875 const StdMeshers_TNode& aTN1 = myTNodes[ij];
876 const SMDS_MeshNode* aN1 = aTN1.Node();
880 SMDS_MeshFace * face = 0;
881 switch ( aNbNodes ) {
883 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
886 face = faceHelper.AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
891 meshDS->SetMeshElementOnShape(face, aFxy1);
894 // update compute state of top face submesh
895 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
897 // assure that mesh on the top face will be cleaned when it is cleaned
898 // on the bottom face
899 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
900 volSM->SetEventListener( new SMESH_subMeshEventListener(true),
901 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
902 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
905 //=======================================================================
906 //function : ClearMeshOnFxy1
908 //=======================================================================
909 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
913 SMESH_subMesh* aSubMesh;
914 SMESH_Mesh* pMesh=GetMesh();
916 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
917 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
919 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
922 //=======================================================================
923 //function : GetIndexOnLayer
925 //=======================================================================
926 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
931 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
933 aMapIt=myConnectingMap.find(aID);
934 if (aMapIt==myConnectingMap.end()) {
942 //=======================================================================
943 //function : MakeConnectingMap
945 //=======================================================================
946 void StdMeshers_Penta_3D::MakeConnectingMap()
950 for (j=0; j<myJSize; ++j) {
951 const StdMeshers_TNode& aBN=myTNodes[j];
952 aBNID=aBN.BaseNodeID();
953 myConnectingMap[aBNID]=j;
957 //=======================================================================
958 //function : CreateNode
960 //=======================================================================
961 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
962 const gp_XYZ& aParams,
963 StdMeshers_TNode& aTN)
972 SMDS_MeshNode* pNode=NULL;
975 // if (bIsUpperLayer) {
976 // // point on face Fxy1
977 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
978 // myBlock.Point(aParams, aS, aP);
981 // // point inside solid
982 // myBlock.Point(aParams, aP);
985 double u = aParams.X(), v = aParams.Y();
986 double u1 = ( 1. - u ), v1 = ( 1. - v );
987 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
988 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
989 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
990 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
992 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
993 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
994 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
995 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
998 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
1001 // iErr=myBlock.ErrorStatus();
1003 // myErrorStatus=12; // can not find the node point;
1007 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
1009 SMESH_Mesh* pMesh = GetMesh();
1010 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
1012 pNode = pMeshDS->AddNode(aX, aY, aZ);
1017 //=======================================================================
1018 //function : ShapeSupportID
1020 //=======================================================================
1021 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
1022 const SMESH_Block::TShapeID aBNSSID,
1023 SMESH_Block::TShapeID& aSSID)
1028 case SMESH_Block::ID_V000:
1029 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
1031 case SMESH_Block::ID_V100:
1032 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
1034 case SMESH_Block::ID_V110:
1035 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
1037 case SMESH_Block::ID_V010:
1038 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
1040 case SMESH_Block::ID_Ex00:
1041 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
1043 case SMESH_Block::ID_Ex10:
1044 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
1046 case SMESH_Block::ID_E0y0:
1047 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
1049 case SMESH_Block::ID_E1y0:
1050 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
1052 case SMESH_Block::ID_Fxy0:
1053 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1056 aSSID=SMESH_Block::ID_NONE;
1057 myErrorStatus=10; // Can not find supporting shape ID
1062 //=======================================================================
1063 //function : MakeBlock
1065 //=======================================================================
1066 void StdMeshers_Penta_3D::MakeBlock()
1071 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1073 TopoDS_Vertex aV000, aV001;
1075 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1076 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1077 TopTools_ListIteratorOfListOfShape aIt;
1079 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1081 // 0. Find triangulated face aFTr
1082 SMDSAbs_ElementType aElementType;
1083 SMESH_Mesh* pMesh=GetMesh();
1087 for (i=1; i<=iNbF; ++i) {
1088 const TopoDS_Shape& aF = aM(i);
1089 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1091 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1092 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1093 while(itf->more()) {
1094 const SMDS_MeshElement * pElement = itf->next();
1095 aElementType = pElement->GetType();
1096 if (aElementType==SMDSAbs_Face) {
1097 iNbNodes = pElement->NbNodes();
1098 if ( iNbNodes==3 || (myCreateQuadratic && iNbNodes==6) ) {
1103 // The current algorithm fails if there is more that one
1104 // face wich contains triangles ...
1105 // In that case, replace return by break to try another
1106 // method (coded in "if (iCnt != 1) { ... }")
1108 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1109 // myErrorStatus=5; // more than one face has triangulation
1121 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1122 // was not reached 'cause it was not called from Hexa_3D ... Now it
1123 // can occurs and in my opinion, it is the most common case.
1126 // The suggested algorithm is the following :
1128 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1129 // then the shape is tologically equivalent to a box
1130 // o In a box, there are three set of four // edges ...
1131 // In the cascade notation, it seems to be the edges
1136 // o For each one of this set, check if the four edges
1137 // have the same number of element.
1138 // o If so, check if the "corresponding" // faces contains
1139 // only quads. It's the faces numbered:
1143 // o If so, check if the opposite edges of each // faces
1144 // have the same number of elements. It is the edges
1146 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1147 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1148 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1149 // o If so, check if the two other faces have the same
1150 // number of elements. It is the faces numbered:
1154 // This test should be improved to test if the nodes
1155 // of the two faces are really "en face".
1156 // o If so, one of the two faces is a candidate to an extrusion,
1157 // It is the faces numbered :
1161 // o Finally, if there is only one candidate, let do the
1162 // extrusion job for the corresponding face
1166 int iNbF = aM.Extent();
1169 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1170 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1171 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1172 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1173 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1174 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1176 int has_only_quad_f1 = 1;
1177 int has_only_quad_f2 = 1;
1178 int has_only_quad_f3 = 1;
1179 int has_only_quad_f4 = 1;
1180 int has_only_quad_f5 = 1;
1181 int has_only_quad_f6 = 1;
1183 for (i=1; i<=iNbF; ++i) {
1185 const TopoDS_Shape& aF = aM(i);
1186 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1187 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1188 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1189 while(itf->more()) {
1190 const SMDS_MeshElement * pElement = itf->next();
1191 aElementType = pElement->GetType();
1192 if (aElementType==SMDSAbs_Face) {
1193 iNbNodes = pElement->NbNodes();
1194 if ( iNbNodes!=4 ) {
1200 if (i==1) has_only_quad_f1 = ok ;
1201 if (i==2) has_only_quad_f2 = ok ;
1202 if (i==3) has_only_quad_f3 = ok ;
1203 if (i==4) has_only_quad_f4 = ok ;
1204 if (i==5) has_only_quad_f5 = ok ;
1205 if (i==6) has_only_quad_f6 = ok ;
1208 TopTools_IndexedMapOfShape aE;
1209 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1210 int iNbE = aE.Extent();
1213 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1214 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1215 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1216 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1217 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1218 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1219 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1220 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1221 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1222 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1223 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1224 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1228 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1229 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1230 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1238 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1239 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1240 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1248 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1249 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1250 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1266 myErrorStatus=5; // more than one face has triangulation
1272 // 1. Vetrices V00, V001;
1274 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1275 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1277 // 1.1 Base vertex V000
1278 iNbE = aME.Extent();
1279 if (iNbE!= NB_WALL_FACES ){
1280 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1281 myErrorStatus=7; // too few edges are in base face aFTr
1284 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1285 aV000=TopExp::FirstVertex(aE1);
1287 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1288 aIt.Initialize(aLE);
1289 for (; aIt.More(); aIt.Next()) {
1290 const TopoDS_Shape& aEx=aIt.Value();
1293 iNbEV=aMEV.Extent();
1295 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1296 myErrorStatus=7; // too few edges meet in base vertex
1302 for (j=1; j<=iNbEV; ++j) {
1303 const TopoDS_Shape& aEx=aMEV(j);
1304 if (!aME.Contains(aEx)) {
1305 TopoDS_Vertex aV[2];
1307 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1308 TopExp::Vertices(aE, aV[0], aV[1]);
1309 for (i=0; i<2; ++i) {
1310 if (!aV[i].IsSame(aV000)) {
1320 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1321 myErrorStatus=8; // can not find reper V001
1325 //gp_Pnt aP000, aP001;
1327 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1328 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1329 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1330 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1334 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1337 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1338 myErrorStatus=9; // number of shells in source shape !=1
1343 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1344 myBlock.Load(aShell, aV000, aV001);
1345 iErr = myBlock.ErrorStatus();
1347 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1348 myErrorStatus=100; // SMESHBlock: Load operation failed
1352 //=======================================================================
1353 //function : CheckData
1355 //=======================================================================
1356 void StdMeshers_Penta_3D::CheckData()
1361 int iNbEx[]={8, 12, 6};
1363 TopAbs_ShapeEnum aST;
1364 TopAbs_ShapeEnum aSTEx[]={
1365 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1367 TopTools_IndexedMapOfShape aM;
1369 if (myShape.IsNull()){
1370 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1371 myErrorStatus=2; // null shape
1375 aST=myShape.ShapeType();
1376 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1377 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1378 myErrorStatus=3; // not compatible type of shape
1382 for (i=0; i<3; ++i) {
1384 TopExp::MapShapes(myShape, aSTEx[i], aM);
1387 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1388 myErrorStatus=4; // number of subshape is not compatible
1394 //=======================================================================
1395 //function : LoadIJNodes
1396 //purpose : Load nodes bound to theFace into column (vectors) and rows
1398 // The value of theIJNodes map is a vector of ordered nodes so
1399 // that the 0-the one lies on theBaseEdge.
1400 // The key of theIJNodes map is a normalized parameter of each
1401 // 0-the node on theBaseEdge.
1402 //=======================================================================
1404 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1405 const TopoDS_Face& theFace,
1406 const TopoDS_Edge& theBaseEdge,
1407 SMESHDS_Mesh* theMesh)
1409 // get vertices of theBaseEdge
1410 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1411 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1412 TopExp::Vertices( eFrw, vfb, vlb );
1414 // find the other edges of theFace and orientation of e1
1415 TopoDS_Edge e1, e2, eTop;
1416 bool rev1, CumOri = false;
1417 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1419 for ( ; exp.More(); exp.Next() ) {
1420 if ( ++nbEdges > NB_WALL_FACES ) {
1421 return false; // more than 4 edges in theFace
1423 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1424 if ( theBaseEdge.IsSame( e ))
1426 TopoDS_Vertex vCommon;
1427 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1429 else if ( vCommon.IsSame( vfb )) {
1431 vft = TopExp::LastVertex( e1, CumOri );
1432 rev1 = vfb.IsSame( vft );
1434 vft = TopExp::FirstVertex( e1, CumOri );
1439 if ( nbEdges < NB_WALL_FACES ) {
1440 return false; // less than 4 edges in theFace
1443 // submeshes corresponding to shapes
1444 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1445 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1446 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1447 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1448 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1449 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1450 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1451 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1452 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1453 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1454 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1457 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1458 MESSAGE(" Diff nb of nodes on opposite edges" );
1461 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1462 MESSAGE("Empty submesh of vertex");
1465 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1466 // check quadratic case
1467 if ( myCreateQuadratic ) {
1468 int n1 = sm1->NbNodes()/2;
1469 int n2 = smb->NbNodes()/2;
1470 int n3 = sm1->NbNodes() - n1;
1471 int n4 = smb->NbNodes() - n2;
1472 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1473 if( nf != smFace->NbNodes() ) {
1474 MESSAGE( "Wrong nb face nodes: " <<
1475 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1480 MESSAGE( "Wrong nb face nodes: " <<
1481 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1486 int vsize = sm1->NbNodes() + 2;
1487 int hsize = smb->NbNodes() + 2;
1488 if(myCreateQuadratic) {
1489 vsize = vsize - sm1->NbNodes()/2 -1;
1490 hsize = hsize - smb->NbNodes()/2 -1;
1493 // load nodes from theBaseEdge
1495 set<const SMDS_MeshNode*> loadedNodes;
1496 const SMDS_MeshNode* nullNode = 0;
1498 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1499 nVecf.resize( vsize, nullNode );
1500 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1502 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1503 nVecl.resize( vsize, nullNode );
1504 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1507 BRep_Tool::Range( eFrw, f, l );
1508 double range = l - f;
1509 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1510 const SMDS_MeshNode* node;
1511 while ( nIt->more() ) {
1513 if(myTool->IsMedium(node))
1515 const SMDS_EdgePosition* pos =
1516 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1520 double u = ( pos->GetUParameter() - f ) / range;
1521 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1522 nVec.resize( vsize, nullNode );
1523 loadedNodes.insert( nVec[ 0 ] = node );
1525 if ( theIJNodes.size() != hsize ) {
1526 MESSAGE( "Wrong node positions on theBaseEdge" );
1530 // load nodes from e1
1532 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1533 nIt = sm1->GetNodes();
1534 while ( nIt->more() ) {
1536 if(myTool->IsMedium(node))
1538 const SMDS_EdgePosition* pos =
1539 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1543 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1545 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1546 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1547 int row = rev1 ? vsize - 1 : 0;
1548 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1551 loadedNodes.insert( nVecf[ row ] = u_n->second );
1554 // try to load the rest nodes
1556 // get all faces from theFace
1557 TIDSortedElemSet allFaces, foundFaces;
1558 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1559 while ( eIt->more() ) {
1560 const SMDS_MeshElement* e = eIt->next();
1561 if ( e->GetType() == SMDSAbs_Face )
1562 allFaces.insert( e );
1564 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1565 // the nodes belong to, and between the nodes of the found face,
1566 // look for a not loaded node considering this node to be the next
1567 // in a column of the starting second node. Repeat, starting
1568 // from nodes next to the previous starting nodes in their columns,
1569 // and so on while a face can be found. Then go the the next pair
1570 // of nodes on theBaseEdge.
1571 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1572 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1575 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1578 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1579 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1580 const SMDS_MeshElement* face = 0;
1582 // look for a face by 2 nodes
1583 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1585 int nbFaceNodes = face->NbNodes();
1586 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1587 (myCreateQuadratic && nbFaceNodes>8) ) {
1588 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1591 // look for a not loaded node of the <face>
1593 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1594 eIt = face->nodesIterator() ;
1595 while ( !found && eIt->more() ) {
1596 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1597 if(myTool->IsMedium(node))
1599 found = loadedNodes.insert( node ).second;
1600 if ( !found && node != n1 && node != n2 )
1604 if ( ++row > vsize - 1 ) {
1605 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1608 par_nVec_2->second[ row ] = node;
1609 foundFaces.insert( face );
1611 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1612 n1 = par_nVec_1->second[ row ];
1615 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1616 n3 == par_nVec_1->second[ row ] ) {
1620 MESSAGE( "Not quad mesh, column "<< col );
1625 while ( face && n1 && n2 );
1627 if ( row < vsize - 1 ) {
1628 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1629 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1630 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1631 MESSAGE( "Current node 1: "<< n1);
1632 MESSAGE( "Current node 2: "<< n2);
1633 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1634 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1637 } // loop on columns
1642 //////////////////////////////////////////////////////////////////////////
1644 // StdMeshers_SMESHBlock
1646 //////////////////////////////////////////////////////////////////////////
1648 //=======================================================================
1649 //function : StdMeshers_SMESHBlock
1651 //=======================================================================
1652 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1655 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1658 //=======================================================================
1659 //function : IsForwadEdge
1661 //=======================================================================
1663 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1665 int index = myTBlock.ShapeIndex( theEdgeID );
1666 if ( !myTBlock.IsEdgeID( theEdgeID ))
1669 if ( myIsEdgeForward[ index ] < 0 )
1670 myIsEdgeForward[ index ] =
1671 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1673 return myIsEdgeForward[ index ];
1676 //=======================================================================
1677 //function : ErrorStatus
1679 //=======================================================================
1680 int StdMeshers_SMESHBlock::ErrorStatus() const
1682 return myErrorStatus;
1685 //=======================================================================
1688 //=======================================================================
1689 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1691 TopoDS_Vertex aV000, aV001;
1693 Load(theShell, aV000, aV001);
1696 //=======================================================================
1699 //=======================================================================
1700 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1701 const TopoDS_Vertex& theV000,
1702 const TopoDS_Vertex& theV001)
1710 myShapeIDMap.Clear();
1711 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1718 //=======================================================================
1719 //function : ComputeParameters
1721 //=======================================================================
1722 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1725 ComputeParameters(thePnt, myShell, theXYZ);
1728 //=======================================================================
1729 //function : ComputeParameters
1731 //=======================================================================
1732 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1733 const TopoDS_Shape& theShape,
1741 aID = ShapeID(theShape);
1742 if (myErrorStatus) {
1745 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1747 myErrorStatus=4; // problems with computation Parameters
1752 //=======================================================================
1753 //function : ComputeParameters
1755 //=======================================================================
1757 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1758 const TopoDS_Shape& theShape,
1766 aID = ShapeID(theShape);
1767 if (myErrorStatus) {
1770 if ( SMESH_Block::IsEdgeID( aID ))
1771 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1773 myErrorStatus=4; // problems with computation Parameters
1778 //=======================================================================
1781 //=======================================================================
1782 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1787 Point(theParams, aS, aP3D);
1790 //=======================================================================
1793 //=======================================================================
1794 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1795 const TopoDS_Shape& theShape,
1802 gp_XYZ aXYZ(99.,99.,99.);
1805 if (theShape.IsNull()) {
1806 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1810 aID=ShapeID(theShape);
1811 if (myErrorStatus) {
1815 if (SMESH_Block::IsVertexID(aID)) {
1816 bOk = myTBlock.VertexPoint(aID, aXYZ);
1818 else if (SMESH_Block::IsEdgeID(aID)) {
1819 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1822 else if (SMESH_Block::IsFaceID(aID)) {
1823 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1827 myErrorStatus=4; // problems with point computation
1833 //=======================================================================
1834 //function : ShapeID
1836 //=======================================================================
1837 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1842 TopoDS_Shape aSF, aSR;
1845 aSF.Orientation(TopAbs_FORWARD);
1847 aSR.Orientation(TopAbs_REVERSED);
1849 if (myShapeIDMap.Contains(aSF)) {
1850 aID=myShapeIDMap.FindIndex(aSF);
1853 if (myShapeIDMap.Contains(aSR)) {
1854 aID=myShapeIDMap.FindIndex(aSR);
1857 myErrorStatus=2; // unknown shape;
1861 //=======================================================================
1864 //=======================================================================
1865 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1871 aNb=myShapeIDMap.Extent();
1872 if (theID<1 || theID>aNb) {
1873 myErrorStatus=3; // ID is out of range
1874 return myEmptyShape;
1877 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);