1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SMESH StdMeshers_Penta_3D implementaion of SMESH idl descriptions
23 // File : StdMeshers_Penta_3D.cxx
26 #include "StdMeshers_Penta_3D.hxx"
28 #include "utilities.h"
29 #include "Utils_ExceptHandlers.hxx"
31 #include "SMDS_EdgePosition.hxx"
32 #include "SMDS_MeshElement.hxx"
33 #include "SMDS_VolumeOfNodes.hxx"
34 #include "SMDS_VolumeTool.hxx"
35 #include "SMESHDS_SubMesh.hxx"
36 #include "SMESH_Mesh.hxx"
37 #include "SMESH_MesherHelper.hxx"
38 #include "SMESH_subMesh.hxx"
39 #include "SMESH_subMeshEventListener.hxx"
40 #include "SMESH_Comment.hxx"
42 #include <BRep_Tool.hxx>
44 #include <TopExp_Explorer.hxx>
45 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
47 #include <TopTools_ListIteratorOfListOfShape.hxx>
48 #include <TopTools_ListOfShape.hxx>
49 #include <TopTools_SequenceOfShape.hxx>
50 #include <TopTools_MapOfShape.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Shell.hxx>
54 #include <TopoDS_Vertex.hxx>
62 typedef map < int, int, less<int> >::iterator \
63 StdMeshers_IteratorOfDataMapOfIntegerInteger;
65 enum { NB_WALL_FACES = 4 };
67 //=======================================================================
68 //function : StdMeshers_Penta_3D
70 //=======================================================================
71 StdMeshers_Penta_3D::StdMeshers_Penta_3D()
72 : myErrorStatus(SMESH_ComputeError::New())
75 myWallNodesMaps.resize( SMESH_Block::NbFaces() );
76 myShapeXYZ.resize( SMESH_Block::NbSubShapes() );
80 //=======================================================================
81 //function : ~StdMeshers_Penta_3D
83 //=======================================================================
85 StdMeshers_Penta_3D::~StdMeshers_Penta_3D()
89 //=======================================================================
92 //=======================================================================
93 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
94 const TopoDS_Shape& aShape)
96 MESSAGE("StdMeshers_Penta_3D::Compute()");
104 if (!myErrorStatus->IsOK()) {
110 if (!myErrorStatus->IsOK()) {
115 if (!myErrorStatus->IsOK()) {
119 // now unnecessary faces removed, we can load medium nodes
120 SMESH_MesherHelper helper(aMesh);
122 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
126 if (!myErrorStatus->IsOK()) {
133 if (!myErrorStatus->IsOK()) {
142 //=======================================================================
143 //function : MakeNodes
145 //=======================================================================
146 void StdMeshers_Penta_3D::MakeNodes()
149 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
151 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
152 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
153 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
154 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
155 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
159 SMESH_Mesh* pMesh=GetMesh();
161 // 1. Define the sizes of mesh
163 // 1.1 Horizontal size
165 for (i=0; i<aNbSIDs; ++i) {
166 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
167 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
169 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
170 if(!myCreateQuadratic) {
171 iNbN = aSM->NbNodes();
175 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
177 const SMDS_MeshNode* aNode = itn->next();
178 if(myTool->IsMedium(aNode))
185 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
190 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
191 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
193 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
194 if(!myCreateQuadratic) {
195 iNbN = aSM->NbNodes();
199 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
201 const SMDS_MeshNode* aNode = itn->next();
202 if(myTool->IsMedium(aNode))
209 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
211 aSize=myISize*myJSize;
212 myTNodes.resize(aSize);
214 StdMeshers_TNode aTNode;
218 // 2. Fill the repers on base face (Z=0)
221 for (k=0; k<aNbSIDs; ++k) {
223 const TopoDS_Shape& aS = myBlock.Shape(aSID);
224 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
226 const SMDS_MeshNode* aNode = ite->next();
227 if(myTool->IsMedium(aNode))
229 aNodeID=aNode->GetID();
231 aTNode.SetNode(aNode);
232 aTNode.SetShapeSupportID(aSID);
233 aTNode.SetBaseNodeID(aNodeID);
235 if ( SMESH_Block::IsEdgeID (aSID)) {
236 const SMDS_EdgePosition* epos =
237 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition().get());
238 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
244 aP3D.SetCoord(aX, aY, aZ);
245 myBlock.ComputeParameters(aP3D, aS, aCoords);
247 iErr = myBlock.ErrorStatus();
249 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
250 "SMESHBlock: ComputeParameters operation failed");
251 myErrorStatus=myBlock.GetError();
254 aTNode.SetNormCoord(aCoords);
261 // 3.1 Fill maps of wall nodes
262 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
263 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
264 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
266 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
267 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
268 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
270 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
271 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
272 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
273 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
274 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
277 myErrorStatus->myName = COMPERR_BAD_INPUT_MESH;
278 myErrorStatus->myComment = SMESH_Comment() <<
279 "Can't find regular quadrangle mesh on a side face #" <<
280 pMesh->GetMeshDS()->ShapeToIndex( myBlock.Shape( wallFaceID[ i ]));
285 // 3.2 find node columns for vertical edges and edge IDs
286 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
287 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
288 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
290 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
291 ShapeSupportID(false, vID, eID);
292 verticEdgeID[ i ] = eID;
294 StdMeshers_TNode& aTNode = myTNodes[ i ];
295 verticEdgeNodes[ i ] = 0;
296 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
297 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
298 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
299 if ( ijNodes.begin()->second[0] == aTNode.Node() )
300 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
301 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
302 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
303 if ( verticEdgeNodes[ i ] )
308 // 3.3 set XYZ of vertices, and initialize of the rest
309 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
310 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
311 if ( SMESH_Block::IsVertexID( id )) {
312 TopoDS_Shape V = myBlock.Shape( id );
313 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
314 const SMDS_MeshNode* n = sm->GetNodes()->next();
315 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
318 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
322 // 4. Fill the rest repers
325 SMESH_Block::TShapeID aSSID, aBNSSID;
326 StdMeshers_TNode aTN;
329 // create top face and find UV for it's corners
330 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
331 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
332 int topfaceID = meshDS->ShapeToIndex(TopFace);
333 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
334 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
335 const SMDS_MeshNode* N = itn->next();
336 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
337 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
338 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
340 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
341 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
342 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
344 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
345 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
346 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
348 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
350 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
352 const StdMeshers_TNode& aBN = myTNodes[j];
353 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
354 iBNID = aBN.BaseNodeID();
355 const gp_XYZ& aBNXYZ = aBN.NormCoord();
356 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
358 // set XYZ on horizontal edges and get node columns of faces:
359 // 2 columns for each face, between which a base node is located
360 vector<const SMDS_MeshNode*>* nColumns[8];
361 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
363 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
364 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
365 nColumns[k*2], nColumns[k*2+1]);
369 // XYZ on the bottom and top faces
370 const SMDS_MeshNode* n = aBN.Node();
371 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
372 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
374 // first create or find a top node, then the rest ones in a column
375 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
377 bIsUpperLayer = (i==(myISize-1));
378 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
379 if ( createNode ) // a base node is inside a top face
381 // set XYZ on vertical edges and faces
382 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
383 // XYZ on a vertical edge
384 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
385 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
386 // XYZ on a face (part 1 from one column)
387 n = (*nColumns[k*2]) [ i ];
388 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
389 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
391 if( bIsUpperLayer ) {
392 tmp1 = myTool->GetNodeUV(TopFace,n);
393 tmp1 = ( 1. - ratio[ k ]) * tmp1;
395 // XYZ on a face (part 2 from other column)
396 n = (*nColumns[k*2+1]) [ i ];
397 xyz.SetCoord( n->X(), n->Y(), n->Z() );
398 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
399 if( bIsUpperLayer ) {
400 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
401 tmp1 += ratio[ k ] * tmp2;
413 // fill current node info
416 // -normalized coordinates
420 aZ=(double)i/(double)(myISize-1);
421 aCoords.SetCoord(aX, aY, aZ);
423 // suporting shape ID
424 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
425 if (!myErrorStatus->IsOK()) {
426 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
430 aTN.SetShapeSupportID(aSSID);
431 aTN.SetNormCoord(aCoords);
432 aTN.SetBaseNodeID(iBNID);
434 if (aSSID!=SMESH_Block::ID_NONE){
435 // try to find the node
436 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
437 FindNodeOnShape(aS, aCoords, i, aTN);
440 // create node and get its id
441 CreateNode (bIsUpperLayer, aCoords, aTN);
443 if ( bIsUpperLayer ) {
444 const SMDS_MeshNode* n = aTN.Node();
445 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
446 // set node on top face:
447 // find UV parameter for this node
449 // UV011+-----+----------+UV111
452 // UV_E0y1+ +node +UV_E1y1
456 // UV001+-----+----------+UV101
459 double u = aCoords.X(), v = aCoords.Y();
460 double u1 = ( 1. - u ), v1 = ( 1. - v );
461 aP.ChangeCoord() = UV_Ex01 * v1;
462 aP.ChangeCoord() += UV_Ex11 * v;
463 aP.ChangeCoord() += UV_E0y1 * u1;
464 aP.ChangeCoord() += UV_E1y1 * u;
465 aP.ChangeCoord() -= UV001 * u1 * v1;
466 aP.ChangeCoord() -= UV101 * u * v1;
467 aP.ChangeCoord() -= UV011 * u1 * v;
468 aP.ChangeCoord() -= UV111 * u * v;
469 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
472 if (!myErrorStatus->IsOK()) {
473 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
483 //=======================================================================
484 //function : FindNodeOnShape
486 //=======================================================================
488 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
489 const gp_XYZ& aParams,
491 StdMeshers_TNode& aTN)
493 double aX, aY, aZ, aD, aTol2, minD;
496 SMESH_Mesh* pMesh = GetMesh();
497 aTol2 = myTol3D*myTol3D;
499 SMDS_MeshNode* pNode = NULL;
501 if ( aS.ShapeType() == TopAbs_FACE ||
502 aS.ShapeType() == TopAbs_EDGE ) {
503 // find a face ID to which aTN belongs to
505 if ( aS.ShapeType() == TopAbs_FACE )
506 faceID = myBlock.ShapeID( aS );
507 else { // edge maybe vertical or top horizontal
508 gp_XYZ aCoord = aParams;
509 if ( aCoord.Z() == 1. )
510 aCoord.SetZ( 0.5 ); // move from top down
512 aCoord.SetX( 0.5 ); // move along X
513 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
515 ASSERT( SMESH_Block::IsFaceID( faceID ));
516 int fIndex = SMESH_Block::ShapeIndex( faceID );
517 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
518 // look for a base node in ijNodes
519 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
520 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
521 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
522 if ( par_nVec->second[ 0 ] == baseNode ) {
523 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
529 myBlock.Point(aParams, aS, aP1);
531 SMDS_NodeIteratorPtr ite=
532 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
534 const SMDS_MeshNode* aNode = ite->next();
535 if(myTool->IsMedium(aNode))
540 aP2.SetCoord(aX, aY, aZ);
541 aD=(double)aP1.SquareDistance(aP2);
542 //printf("** D=%lf ", aD, aTol2);
544 pNode=(SMDS_MeshNode*)aNode;
554 //aTN.SetNode(pNode);
555 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
556 //myErrorStatus=11; // can not find the node;
560 //=======================================================================
561 //function : SetHorizEdgeXYZ
563 //=======================================================================
565 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
567 vector<const SMDS_MeshNode*>*& aCol1,
568 vector<const SMDS_MeshNode*>*& aCol2)
570 // find base and top edges of the face
571 enum { BASE = 0, TOP };
572 vector< int > edgeVec; // 0-base, 1-top
573 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
575 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
576 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
578 double param = aBaseNodeParams.Coord( coord );
582 // look for columns around param
583 StdMeshers_IJNodeMap & ijNodes =
584 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
585 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
586 while ( par_nVec_1->first < param )
588 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
591 if ( par_nVec_1 != ijNodes.begin() ) {
593 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
595 aCol1 = & par_nVec_1->second;
596 aCol2 = & par_nVec_2->second;
600 // this variant is better for cases with curved edges and
601 // different nodes distribution on top and base edges
602 const SMDS_MeshNode* n1 = aCol1->back();
603 const SMDS_MeshNode* n2 = aCol2->back();
604 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
605 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
606 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
609 // this variant is better for other cases
610 // SMESH_MesherHelper helper( *GetMesh() );
611 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
612 // double u1 = helper.GetNodeU( edge, n1 );
613 // double u2 = helper.GetNodeU( edge, n2 );
614 // double u = ( 1. - r ) * u1 + r * u2;
615 // gp_XYZ topNodeParams;
616 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
617 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
619 // myShapeXYZ[ edgeVec[ TOP ]]);
623 myBlock.Block().EdgePoint( edgeVec[ BASE ],
625 myShapeXYZ[ edgeVec[ BASE ]]);
630 //=======================================================================
631 //function : MakeVolumeMesh
633 //=======================================================================
634 void StdMeshers_Penta_3D::MakeVolumeMesh()
636 int i, j, ij, ik, i1, i2, aSSID;
638 SMESH_Mesh* pMesh = GetMesh();
639 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
641 int shapeID = meshDS->ShapeToIndex( myShape );
643 // 1. Set Node In Volume
645 for (i=1; i<ik; ++i){
646 for (j=0; j<myJSize; ++j){
648 const StdMeshers_TNode& aTN = myTNodes[ij];
649 aSSID=aTN.ShapeSupportID();
650 if (aSSID==SMESH_Block::ID_NONE) {
651 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
652 meshDS->SetNodeInVolume(aNode, shapeID);
657 // 2. Make pentahedrons
659 vector<const SMDS_MeshNode*> aN;
661 SMDS_ElemIteratorPtr itf, aItNodes;
663 const TopoDS_Face& aFxy0=
664 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
665 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
666 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
668 itf = aSM0->GetElements();
670 const SMDS_MeshElement* pE0 = itf->next();
672 int nbFaceNodes = pE0->NbNodes();
673 if(myCreateQuadratic)
674 nbFaceNodes = nbFaceNodes/2;
675 if ( aN.size() < nbFaceNodes * 2 )
676 aN.resize( nbFaceNodes * 2 );
679 aItNodes=pE0->nodesIterator();
680 while (aItNodes->more()) {
681 //const SMDS_MeshElement* pNode = aItNodes->next();
682 const SMDS_MeshNode* pNode =
683 static_cast<const SMDS_MeshNode*> (aItNodes->next());
684 if(myTool->IsMedium(pNode))
686 aID0 = pNode->GetID();
687 aJ[k] = GetIndexOnLayer(aID0);
688 if (!myErrorStatus->IsOK()) {
689 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
697 for (i=0; i<ik; ++i) {
700 for(j=0; j<nbFaceNodes; ++j) {
701 ij = i1*myJSize+aJ[j];
702 const StdMeshers_TNode& aTN1 = myTNodes[ij];
703 const SMDS_MeshNode* aN1 = aTN1.Node();
707 const StdMeshers_TNode& aTN2 = myTNodes[ij];
708 const SMDS_MeshNode* aN2 = aTN2.Node();
709 aN[j+nbFaceNodes] = aN2;
711 // check if volume orientation will be ok
713 SMDS_VolumeTool vTool;
714 switch ( nbFaceNodes ) {
716 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
717 aN[3], aN[4], aN[5]);
718 vTool.Set( &tmpVol );
722 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
723 aN[4], aN[5], aN[6], aN[7]);
724 vTool.Set( &tmpVol );
730 forward = vTool.IsForward();
733 SMDS_MeshVolume* aV = 0;
734 switch ( nbFaceNodes ) {
737 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
738 // aN[3], aN[4], aN[5]);
739 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
742 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
743 // aN[3], aN[5], aN[4]);
744 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
749 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
750 // aN[4], aN[5], aN[6], aN[7]);
751 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
752 aN[4], aN[5], aN[6], aN[7]);
755 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
756 // aN[4], aN[7], aN[6], aN[5]);
757 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
758 aN[4], aN[7], aN[6], aN[5]);
764 meshDS->SetMeshElementOnShape(aV, shapeID);
769 //=======================================================================
770 //function : MakeMeshOnFxy1
772 //=======================================================================
773 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
775 int aID0, aJ, aLevel, ij, aNbNodes, k;
777 SMDS_NodeIteratorPtr itn;
778 SMDS_ElemIteratorPtr itf, aItNodes;
779 SMDSAbs_ElementType aElementType;
781 const TopoDS_Face& aFxy0=
782 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
783 const TopoDS_Face& aFxy1=
784 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
786 SMESH_Mesh* pMesh = GetMesh();
787 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
789 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
790 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
791 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
793 // set nodes on aFxy1
795 itn = aSM0->GetNodes();
796 aNbNodes = aSM0->NbNodes();
797 //printf("** aNbNodes=%d\n", aNbNodes);
798 myTool->SetSubShape( aFxy1 ); // to set medium nodes to aFxy1
800 // set elements on aFxy1
801 vector<const SMDS_MeshNode*> aNodes1;
803 itf = aSM0->GetElements();
805 const SMDS_MeshElement* pE0 = itf->next();
806 aElementType = pE0->GetType();
807 if (!aElementType==SMDSAbs_Face) {
810 aNbNodes = pE0->NbNodes();
811 if(myCreateQuadratic)
812 aNbNodes = aNbNodes/2;
813 if ( aNodes1.size() < aNbNodes )
814 aNodes1.resize( aNbNodes );
816 k = aNbNodes-1; // reverse a face
817 aItNodes = pE0->nodesIterator();
818 while (aItNodes->more()) {
819 const SMDS_MeshNode* pNode =
820 static_cast<const SMDS_MeshNode*> (aItNodes->next());
821 if(myTool->IsMedium(pNode))
823 aID0 = pNode->GetID();
824 aJ = GetIndexOnLayer(aID0);
825 if (!myErrorStatus->IsOK()) {
826 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
830 ij = aLevel*myJSize + aJ;
831 const StdMeshers_TNode& aTN1 = myTNodes[ij];
832 const SMDS_MeshNode* aN1 = aTN1.Node();
836 SMDS_MeshFace * face = 0;
837 switch ( aNbNodes ) {
839 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
842 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
847 meshDS->SetMeshElementOnShape(face, aFxy1);
849 myTool->SetSubShape( myShape );
851 // update compute state of top face submesh
852 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
854 // assure that mesh on the top face will be cleaned when it is cleaned
855 // on the bottom face
856 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
857 volSM->SetEventListener( new SMESH_subMeshEventListener(true),
858 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
859 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
862 //=======================================================================
863 //function : ClearMeshOnFxy1
865 //=======================================================================
866 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
868 SMESH_subMesh* aSubMesh;
869 SMESH_Mesh* pMesh=GetMesh();
871 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
872 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
874 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
877 //=======================================================================
878 //function : GetIndexOnLayer
880 //=======================================================================
881 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
884 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
886 aMapIt=myConnectingMap.find(aID);
887 if (aMapIt==myConnectingMap.end()) {
888 myErrorStatus->myName = 200;
889 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
896 //=======================================================================
897 //function : MakeConnectingMap
899 //=======================================================================
900 void StdMeshers_Penta_3D::MakeConnectingMap()
904 for (j=0; j<myJSize; ++j) {
905 const StdMeshers_TNode& aBN=myTNodes[j];
906 aBNID=aBN.BaseNodeID();
907 myConnectingMap[aBNID]=j;
911 //=======================================================================
912 //function : CreateNode
914 //=======================================================================
915 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
916 const gp_XYZ& aParams,
917 StdMeshers_TNode& aTN)
923 SMDS_MeshNode* pNode=NULL;
926 // if (bIsUpperLayer) {
927 // // point on face Fxy1
928 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
929 // myBlock.Point(aParams, aS, aP);
932 // // point inside solid
933 // myBlock.Point(aParams, aP);
936 double u = aParams.X(), v = aParams.Y();
937 double u1 = ( 1. - u ), v1 = ( 1. - v );
938 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
939 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
940 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
941 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
943 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
944 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
945 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
946 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
949 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
952 // iErr=myBlock.ErrorStatus();
954 // myErrorStatus=12; // can not find the node point;
958 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
960 SMESH_Mesh* pMesh = GetMesh();
961 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
963 pNode = pMeshDS->AddNode(aX, aY, aZ);
968 //=======================================================================
969 //function : ShapeSupportID
971 //=======================================================================
972 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
973 const SMESH_Block::TShapeID aBNSSID,
974 SMESH_Block::TShapeID& aSSID)
977 case SMESH_Block::ID_V000:
978 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
980 case SMESH_Block::ID_V100:
981 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
983 case SMESH_Block::ID_V110:
984 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
986 case SMESH_Block::ID_V010:
987 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
989 case SMESH_Block::ID_Ex00:
990 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
992 case SMESH_Block::ID_Ex10:
993 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
995 case SMESH_Block::ID_E0y0:
996 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
998 case SMESH_Block::ID_E1y0:
999 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
1001 case SMESH_Block::ID_Fxy0:
1002 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1005 aSSID=SMESH_Block::ID_NONE;
1006 myErrorStatus->myName=10; // Can not find supporting shape ID
1007 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
1012 //=======================================================================
1013 //function : MakeBlock
1015 //=======================================================================
1016 void StdMeshers_Penta_3D::MakeBlock()
1019 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1021 TopoDS_Vertex aV000, aV001;
1023 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1024 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1025 TopTools_ListIteratorOfListOfShape aIt;
1027 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1029 // 0. Find triangulated face aFTr
1030 SMDSAbs_ElementType aElementType;
1031 SMESH_Mesh* pMesh=GetMesh();
1035 for (i=1; i<=iNbF; ++i) {
1036 const TopoDS_Shape& aF = aM(i);
1037 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1039 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1040 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1041 while(itf->more()) {
1042 const SMDS_MeshElement * pElement = itf->next();
1043 aElementType = pElement->GetType();
1044 if (aElementType==SMDSAbs_Face) {
1045 iNbNodes = pElement->NbNodes();
1046 if ( iNbNodes==3 || (pElement->IsQuadratic() && iNbNodes==6) ) {
1051 // The current algorithm fails if there is more that one
1052 // face wich contains triangles ...
1053 // In that case, replace return by break to try another
1054 // method (coded in "if (iCnt != 1) { ... }")
1056 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1057 // myErrorStatus=5; // more than one face has triangulation
1069 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1070 // was not reached 'cause it was not called from Hexa_3D ... Now it
1071 // can occurs and in my opinion, it is the most common case.
1074 // The suggested algorithm is the following :
1076 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1077 // then the shape is tologically equivalent to a box
1078 // o In a box, there are three set of four // edges ...
1079 // In the cascade notation, it seems to be the edges
1084 // o For each one of this set, check if the four edges
1085 // have the same number of element.
1086 // o If so, check if the "corresponding" // faces contains
1087 // only quads. It's the faces numbered:
1091 // o If so, check if the opposite edges of each // faces
1092 // have the same number of elements. It is the edges
1094 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1095 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1096 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1097 // o If so, check if the two other faces have the same
1098 // number of elements. It is the faces numbered:
1102 // This test should be improved to test if the nodes
1103 // of the two faces are really "en face".
1104 // o If so, one of the two faces is a candidate to an extrusion,
1105 // It is the faces numbered :
1109 // o Finally, if there is only one candidate, let do the
1110 // extrusion job for the corresponding face
1114 int iNbF = aM.Extent();
1117 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1118 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1119 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1120 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1121 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1122 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1124 int has_only_quad_f1 = 1;
1125 int has_only_quad_f2 = 1;
1126 int has_only_quad_f3 = 1;
1127 int has_only_quad_f4 = 1;
1128 int has_only_quad_f5 = 1;
1129 int has_only_quad_f6 = 1;
1131 for (i=1; i<=iNbF; ++i) {
1133 const TopoDS_Shape& aF = aM(i);
1134 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1135 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1136 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1137 while(itf->more()) {
1138 const SMDS_MeshElement * pElement = itf->next();
1139 aElementType = pElement->GetType();
1140 if (aElementType==SMDSAbs_Face) {
1141 iNbNodes = pElement->NbNodes();
1142 if ( iNbNodes!=4 ) {
1148 if (i==1) has_only_quad_f1 = ok ;
1149 if (i==2) has_only_quad_f2 = ok ;
1150 if (i==3) has_only_quad_f3 = ok ;
1151 if (i==4) has_only_quad_f4 = ok ;
1152 if (i==5) has_only_quad_f5 = ok ;
1153 if (i==6) has_only_quad_f6 = ok ;
1156 TopTools_IndexedMapOfShape aE;
1157 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1158 int iNbE = aE.Extent();
1161 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1162 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1163 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1164 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1165 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1166 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1167 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1168 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1169 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1170 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1171 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1172 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1176 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1177 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1178 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1186 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1187 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1188 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1196 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1197 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1198 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1214 myErrorStatus->myName=5; // more than one face has triangulation
1215 myErrorStatus->myComment="Incorrect input mesh";
1221 // 1. Vetrices V00, V001;
1223 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1224 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1226 // 1.1 Base vertex V000
1227 iNbE = aME.Extent();
1228 if (iNbE!= NB_WALL_FACES ){
1229 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1230 myErrorStatus->myName=7; // too few edges are in base face aFTr
1231 myErrorStatus->myComment=SMESH_Comment("Not a quadrilateral face #")
1232 <<pMesh->GetMeshDS()->ShapeToIndex( aFTr )<<": "<<iNbE<<" edges" ;
1235 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1236 aV000=TopExp::FirstVertex(aE1);
1238 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1239 aIt.Initialize(aLE);
1240 for (; aIt.More(); aIt.Next()) {
1241 const TopoDS_Shape& aEx=aIt.Value();
1244 iNbEV=aMEV.Extent();
1246 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1247 myErrorStatus->myName=7; // too few edges meet in base vertex
1248 myErrorStatus->myComment=SMESH_Comment("3 edges must share vertex #")
1249 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 )<<" but there are "<<iNbEV<<" edges";
1255 for (j=1; j<=iNbEV; ++j) {
1256 const TopoDS_Shape& aEx=aMEV(j);
1257 if (!aME.Contains(aEx)) {
1258 TopoDS_Vertex aV[2];
1260 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1261 TopExp::Vertices(aE, aV[0], aV[1]);
1262 for (i=0; i<2; ++i) {
1263 if (!aV[i].IsSame(aV000)) {
1273 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1274 myErrorStatus->myName=8; // can not find reper V001
1275 myErrorStatus->myComment=SMESH_Comment("Can't find opposite vertex for vertex #")
1276 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 );
1280 //gp_Pnt aP000, aP001;
1282 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1283 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1284 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1285 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1289 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1292 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1293 myErrorStatus->myName=9; // number of shells in source shape !=1
1294 myErrorStatus->myComment=SMESH_Comment("Unexpected nb of shells ")<<iNbE;
1299 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1300 myBlock.Load(aShell, aV000, aV001);
1301 iErr = myBlock.ErrorStatus();
1303 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1304 myErrorStatus=myBlock.GetError(); // SMESHBlock: Load operation failed
1308 //=======================================================================
1309 //function : CheckData
1311 //=======================================================================
1312 void StdMeshers_Penta_3D::CheckData()
1315 int iNbEx[]={8, 12, 6};
1317 TopAbs_ShapeEnum aST;
1318 TopAbs_ShapeEnum aSTEx[]={
1319 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1321 TopTools_IndexedMapOfShape aM;
1323 if (myShape.IsNull()){
1324 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1325 myErrorStatus->myName=2; // null shape
1326 myErrorStatus->myComment="Null shape";
1330 aST=myShape.ShapeType();
1331 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1332 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1333 myErrorStatus->myName=3; // not compatible type of shape
1334 myErrorStatus->myComment=SMESH_Comment("Wrong shape type (TopAbs_ShapeEnum) ")<<aST;
1338 for (i=0; i<3; ++i) {
1340 TopExp::MapShapes(myShape, aSTEx[i], aM);
1343 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1344 myErrorStatus->myName=4; // number of subshape is not compatible
1345 myErrorStatus->myComment="Wrong number of subshapes of a block";
1351 //=======================================================================
1352 //function : LoadIJNodes
1353 //purpose : Load nodes bound to theFace into column (vectors) and rows
1355 // The value of theIJNodes map is a vector of ordered nodes so
1356 // that the 0-the one lies on theBaseEdge.
1357 // The key of theIJNodes map is a normalized parameter of each
1358 // 0-the node on theBaseEdge.
1359 //=======================================================================
1361 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1362 const TopoDS_Face& theFace,
1363 const TopoDS_Edge& theBaseEdge,
1364 SMESHDS_Mesh* theMesh)
1366 // get vertices of theBaseEdge
1367 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1368 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1369 TopExp::Vertices( eFrw, vfb, vlb );
1371 // find the other edges of theFace and orientation of e1
1372 TopoDS_Edge e1, e2, eTop;
1373 bool rev1, CumOri = false;
1374 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1376 for ( ; exp.More(); exp.Next() ) {
1377 if ( ++nbEdges > NB_WALL_FACES ) {
1378 return false; // more than 4 edges in theFace
1380 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1381 if ( theBaseEdge.IsSame( e ))
1383 TopoDS_Vertex vCommon;
1384 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1386 else if ( vCommon.IsSame( vfb )) {
1388 vft = TopExp::LastVertex( e1, CumOri );
1389 rev1 = vfb.IsSame( vft );
1391 vft = TopExp::FirstVertex( e1, CumOri );
1396 if ( nbEdges < NB_WALL_FACES ) {
1397 return false; // less than 4 edges in theFace
1400 // submeshes corresponding to shapes
1401 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1402 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1403 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1404 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1405 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1406 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1407 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1408 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1409 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1410 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1411 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1414 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1415 MESSAGE(" Diff nb of nodes on opposite edges" );
1418 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1419 MESSAGE("Empty submesh of vertex");
1422 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1423 // check quadratic case
1424 if ( myCreateQuadratic ) {
1425 int n1 = sm1->NbNodes()/2;
1426 int n2 = smb->NbNodes()/2;
1427 int n3 = sm1->NbNodes() - n1;
1428 int n4 = smb->NbNodes() - n2;
1429 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1430 if( nf != smFace->NbNodes() ) {
1431 MESSAGE( "Wrong nb face nodes: " <<
1432 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1437 MESSAGE( "Wrong nb face nodes: " <<
1438 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1443 int vsize = sm1->NbNodes() + 2;
1444 int hsize = smb->NbNodes() + 2;
1445 if(myCreateQuadratic) {
1446 vsize = vsize - sm1->NbNodes()/2 -1;
1447 hsize = hsize - smb->NbNodes()/2 -1;
1450 // load nodes from theBaseEdge
1452 set<const SMDS_MeshNode*> loadedNodes;
1453 const SMDS_MeshNode* nullNode = 0;
1455 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1456 nVecf.resize( vsize, nullNode );
1457 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1459 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1460 nVecl.resize( vsize, nullNode );
1461 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1464 BRep_Tool::Range( eFrw, f, l );
1465 double range = l - f;
1466 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1467 const SMDS_MeshNode* node;
1468 while ( nIt->more() ) {
1470 if(myTool->IsMedium(node))
1472 const SMDS_EdgePosition* pos =
1473 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1477 double u = ( pos->GetUParameter() - f ) / range;
1478 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1479 nVec.resize( vsize, nullNode );
1480 loadedNodes.insert( nVec[ 0 ] = node );
1482 if ( theIJNodes.size() != hsize ) {
1483 MESSAGE( "Wrong node positions on theBaseEdge" );
1487 // load nodes from e1
1489 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1490 nIt = sm1->GetNodes();
1491 while ( nIt->more() ) {
1493 if(myTool->IsMedium(node))
1495 const SMDS_EdgePosition* pos =
1496 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1500 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1502 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1503 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1504 int row = rev1 ? vsize - 1 : 0;
1505 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1508 loadedNodes.insert( nVecf[ row ] = u_n->second );
1511 // try to load the rest nodes
1513 // get all faces from theFace
1514 TIDSortedElemSet allFaces, foundFaces;
1515 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1516 while ( eIt->more() ) {
1517 const SMDS_MeshElement* e = eIt->next();
1518 if ( e->GetType() == SMDSAbs_Face )
1519 allFaces.insert( e );
1521 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1522 // the nodes belong to, and between the nodes of the found face,
1523 // look for a not loaded node considering this node to be the next
1524 // in a column of the starting second node. Repeat, starting
1525 // from nodes next to the previous starting nodes in their columns,
1526 // and so on while a face can be found. Then go the the next pair
1527 // of nodes on theBaseEdge.
1528 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1529 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1532 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1535 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1536 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1537 const SMDS_MeshElement* face = 0;
1539 // look for a face by 2 nodes
1540 face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1542 int nbFaceNodes = face->NbNodes();
1543 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1544 (myCreateQuadratic && nbFaceNodes>8) ) {
1545 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1548 // look for a not loaded node of the <face>
1550 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1551 eIt = face->nodesIterator() ;
1552 while ( !found && eIt->more() ) {
1553 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1554 if(myTool->IsMedium(node))
1556 found = loadedNodes.insert( node ).second;
1557 if ( !found && node != n1 && node != n2 )
1561 if ( ++row > vsize - 1 ) {
1562 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1565 par_nVec_2->second[ row ] = node;
1566 foundFaces.insert( face );
1568 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1569 n1 = par_nVec_1->second[ row ];
1572 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1573 n3 == par_nVec_1->second[ row ] ) {
1577 MESSAGE( "Not quad mesh, column "<< col );
1582 while ( face && n1 && n2 );
1584 if ( row < vsize - 1 ) {
1585 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1586 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1587 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1588 MESSAGE( "Current node 1: "<< n1);
1589 MESSAGE( "Current node 2: "<< n2);
1590 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1591 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1594 } // loop on columns
1599 //////////////////////////////////////////////////////////////////////////
1601 // StdMeshers_SMESHBlock
1603 //////////////////////////////////////////////////////////////////////////
1605 //=======================================================================
1606 //function : StdMeshers_SMESHBlock
1608 //=======================================================================
1609 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1612 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1615 //=======================================================================
1616 //function : IsForwadEdge
1618 //=======================================================================
1620 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1622 int index = myTBlock.ShapeIndex( theEdgeID );
1623 if ( !myTBlock.IsEdgeID( theEdgeID ))
1626 if ( myIsEdgeForward[ index ] < 0 )
1627 myIsEdgeForward[ index ] =
1628 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1630 return myIsEdgeForward[ index ];
1633 //=======================================================================
1634 //function : ErrorStatus
1636 //=======================================================================
1637 int StdMeshers_SMESHBlock::ErrorStatus() const
1639 return myErrorStatus;
1642 //================================================================================
1644 * \brief Return problem description
1646 //================================================================================
1648 SMESH_ComputeErrorPtr StdMeshers_SMESHBlock::GetError() const
1650 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1651 string & text = err->myComment;
1652 switch ( myErrorStatus ) {
1654 case 3: text = "Internal error of StdMeshers_Penta_3D"; break;
1655 case 4: text = "Can't compute normalized parameters of a point inside a block"; break;
1656 case 5: text = "Can't compute coordinates by normalized parameters inside a block"; break;
1657 case 6: text = "Can't detect block subshapes. Not a block?"; break;
1660 err->myName = myErrorStatus;
1664 //=======================================================================
1667 //=======================================================================
1668 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1670 TopoDS_Vertex aV000, aV001;
1672 Load(theShell, aV000, aV001);
1675 //=======================================================================
1678 //=======================================================================
1679 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1680 const TopoDS_Vertex& theV000,
1681 const TopoDS_Vertex& theV001)
1689 myShapeIDMap.Clear();
1690 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1697 //=======================================================================
1698 //function : ComputeParameters
1700 //=======================================================================
1701 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1704 ComputeParameters(thePnt, myShell, theXYZ);
1707 //=======================================================================
1708 //function : ComputeParameters
1710 //=======================================================================
1711 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1712 const TopoDS_Shape& theShape,
1720 aID = ShapeID(theShape);
1721 if (myErrorStatus) {
1724 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1726 myErrorStatus=4; // problems with computation Parameters
1731 //=======================================================================
1732 //function : ComputeParameters
1734 //=======================================================================
1736 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1737 const TopoDS_Shape& theShape,
1745 aID = ShapeID(theShape);
1746 if (myErrorStatus) {
1749 if ( SMESH_Block::IsEdgeID( aID ))
1750 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1752 myErrorStatus=4; // problems with computation Parameters
1757 //=======================================================================
1760 //=======================================================================
1761 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams, gp_Pnt& aP3D)
1765 Point(theParams, aS, aP3D);
1768 //=======================================================================
1771 //=======================================================================
1772 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1773 const TopoDS_Shape& theShape,
1780 gp_XYZ aXYZ(99.,99.,99.);
1783 if (theShape.IsNull()) {
1784 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1788 aID=ShapeID(theShape);
1789 if (myErrorStatus) {
1793 if (SMESH_Block::IsVertexID(aID)) {
1794 bOk = myTBlock.VertexPoint(aID, aXYZ);
1796 else if (SMESH_Block::IsEdgeID(aID)) {
1797 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1800 else if (SMESH_Block::IsFaceID(aID)) {
1801 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1805 myErrorStatus=5; // problems with point computation
1811 //=======================================================================
1812 //function : ShapeID
1814 //=======================================================================
1815 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1820 TopoDS_Shape aSF, aSR;
1823 aSF.Orientation(TopAbs_FORWARD);
1825 aSR.Orientation(TopAbs_REVERSED);
1827 if (myShapeIDMap.Contains(aSF)) {
1828 aID=myShapeIDMap.FindIndex(aSF);
1831 if (myShapeIDMap.Contains(aSR)) {
1832 aID=myShapeIDMap.FindIndex(aSR);
1835 myErrorStatus=2; // unknown shape;
1839 //=======================================================================
1842 //=======================================================================
1843 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1849 aNb=myShapeIDMap.Extent();
1850 if (theID<1 || theID>aNb) {
1851 myErrorStatus=3; // ID is out of range
1852 return myEmptyShape;
1855 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);
1860 //=======================================================================
1861 //function : Evaluate
1863 //=======================================================================
1864 bool StdMeshers_Penta_3D::Evaluate(SMESH_Mesh& aMesh,
1865 const TopoDS_Shape& aShape,
1866 MapShapeNbElems& aResMap)
1868 MESSAGE("StdMeshers_Penta_3D::Evaluate()");
1870 // find face contains only triangles
1871 vector < SMESH_subMesh * >meshFaces;
1872 TopTools_SequenceOfShape aFaces;
1873 int NumBase = 0, i = 0;
1874 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
1876 aFaces.Append(exp.Current());
1877 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
1878 meshFaces.push_back(aSubMesh);
1879 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i]);
1880 if( anIt == aResMap.end() ) {
1884 std::vector<int> aVec = (*anIt).second;
1885 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1886 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1887 if( nbtri>0 && nbqua==0 ) {
1893 std::vector<int> aResVec(SMDSEntity_Last);
1894 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1895 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1896 aResMap.insert(std::make_pair(sm,aResVec));
1897 myErrorStatus->myName = COMPERR_ALGO_FAILED;
1898 myErrorStatus->myComment = "Submesh can not be evaluated";
1902 // find number of 1d elems for base face
1904 TopTools_MapOfShape Edges1;
1905 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1906 Edges1.Add(exp.Current());
1907 SMESH_subMesh *sm = aMesh.GetSubMesh(exp.Current());
1909 MapShapeNbElemsItr anIt = aResMap.find(sm);
1910 if( anIt == aResMap.end() ) continue;
1911 std::vector<int> aVec = (*anIt).second;
1912 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1915 // find face opposite to base face
1917 for(i=1; i<=6; i++) {
1918 if(i==NumBase) continue;
1919 bool IsOpposite = true;
1920 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1921 if( Edges1.Contains(exp.Current()) ) {
1931 // find number of 2d elems on side faces
1933 for(i=1; i<=6; i++) {
1934 if( i==OppNum || i==NumBase ) continue;
1935 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1936 if( anIt == aResMap.end() ) continue;
1937 std::vector<int> aVec = (*anIt).second;
1938 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1941 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1942 std::vector<int> aVec = (*anIt).second;
1943 int nb2d_face0 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1944 int nb0d_face0 = aVec[SMDSEntity_Node];
1946 anIt = aResMap.find( meshFaces[OppNum-1] );
1947 for(i=SMDSEntity_Node; i<SMDSEntity_Last; i++)
1948 (*anIt).second[i] = aVec[i];
1950 SMESH_MesherHelper aTool (aMesh);
1951 bool _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
1953 std::vector<int> aResVec(SMDSEntity_Last);
1954 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1955 if(_quadraticMesh) {
1956 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0 * ( nb2d/nb1d );
1957 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 );
1960 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1961 aResVec[SMDSEntity_Penta] = nb2d_face0 * ( nb2d/nb1d );
1963 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1964 aResMap.insert(std::make_pair(sm,aResVec));