1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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
23 // SMESH StdMeshers_Penta_3D implementaion of SMESH idl descriptions
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_Comment.hxx"
38 #include "SMESH_Mesh.hxx"
39 #include "SMESH_MeshAlgos.hxx"
40 #include "SMESH_MesherHelper.hxx"
41 #include "SMESH_subMesh.hxx"
42 #include "SMESH_subMeshEventListener.hxx"
44 #include <BRep_Tool.hxx>
46 #include <TopExp_Explorer.hxx>
47 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <TopTools_ListIteratorOfListOfShape.hxx>
50 #include <TopTools_ListOfShape.hxx>
51 #include <TopTools_SequenceOfShape.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()
74 : myErrorStatus(SMESH_ComputeError::New())
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()
91 //=======================================================================
94 //=======================================================================
95 bool StdMeshers_Penta_3D::Compute(SMESH_Mesh& aMesh,
96 const TopoDS_Shape& aShape)
98 MESSAGE("StdMeshers_Penta_3D::Compute()");
106 if (!myErrorStatus->IsOK()) {
112 if (!myErrorStatus->IsOK()) {
117 if (!myErrorStatus->IsOK()) {
121 // now unnecessary faces removed, we can load medium nodes
122 SMESH_MesherHelper helper(aMesh);
124 myCreateQuadratic = myTool->IsQuadraticSubMesh(aShape);
128 if (!myErrorStatus->IsOK()) {
135 if (!myErrorStatus->IsOK()) {
144 //=======================================================================
145 //function : MakeNodes
147 //=======================================================================
148 void StdMeshers_Penta_3D::MakeNodes()
151 int i, j, k, ij, iNbN, aNodeID, aSize, iErr;
153 SMESH_Block::TShapeID aSID, aSIDs[aNbSIDs]={
154 SMESH_Block::ID_V000, SMESH_Block::ID_V100,
155 SMESH_Block::ID_V110, SMESH_Block::ID_V010,
156 SMESH_Block::ID_Ex00, SMESH_Block::ID_E1y0,
157 SMESH_Block::ID_Ex10, SMESH_Block::ID_E0y0,
161 SMESH_Mesh* pMesh=GetMesh();
163 // 1. Define the sizes of mesh
165 // 1.1 Horizontal size
167 for (i=0; i<aNbSIDs; ++i) {
168 const TopoDS_Shape& aS = myBlock.Shape(aSIDs[i]);
169 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
171 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
172 if(!myCreateQuadratic) {
173 iNbN = aSM->NbNodes();
177 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
179 const SMDS_MeshNode* aNode = itn->next();
180 if(myTool->IsMedium(aNode))
187 //printf("*** Horizontal: number of nodes summary=%d\n", myJSize);
192 const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_E00z);
193 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aS);
195 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
196 if(!myCreateQuadratic) {
197 iNbN = aSM->NbNodes();
201 SMDS_NodeIteratorPtr itn = aSM->GetNodes();
203 const SMDS_MeshNode* aNode = itn->next();
204 if(myTool->IsMedium(aNode))
211 //printf("*** Vertical: number of nodes on edges and vertices=%d\n", myISize);
213 aSize=myISize*myJSize;
214 myTNodes.resize(aSize);
216 StdMeshers_TNode aTNode;
220 // 2. Fill the repers on base face (Z=0)
223 for (k=0; k<aNbSIDs; ++k) {
225 const TopoDS_Shape& aS = myBlock.Shape(aSID);
226 SMDS_NodeIteratorPtr ite = pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
228 const SMDS_MeshNode* aNode = ite->next();
229 if(myTool->IsMedium(aNode))
231 aNodeID=aNode->GetID();
233 aTNode.SetNode(aNode);
234 aTNode.SetShapeSupportID(aSID);
235 aTNode.SetBaseNodeID(aNodeID);
237 if ( SMESH_Block::IsEdgeID (aSID)) {
238 const SMDS_EdgePosition* epos =
239 static_cast<const SMDS_EdgePosition*>(aNode->GetPosition());
240 myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords );
246 aP3D.SetCoord(aX, aY, aZ);
247 myBlock.ComputeParameters(aP3D, aS, aCoords);
249 iErr = myBlock.ErrorStatus();
251 MESSAGE("StdMeshers_Penta_3D::MakeNodes()," <<
252 "SMESHBlock: ComputeParameters operation failed");
253 myErrorStatus=myBlock.GetError();
256 aTNode.SetNormCoord(aCoords);
263 // 3.1 Fill maps of wall nodes
264 SMESH_Block::TShapeID wallFaceID[ NB_WALL_FACES ] = {
265 SMESH_Block::ID_Fx0z, SMESH_Block::ID_Fx1z,
266 SMESH_Block::ID_F0yz, SMESH_Block::ID_F1yz
268 SMESH_Block::TShapeID baseEdgeID[ NB_WALL_FACES ] = {
269 SMESH_Block::ID_Ex00, SMESH_Block::ID_Ex10,
270 SMESH_Block::ID_E0y0, SMESH_Block::ID_E1y0
272 for ( i = 0; i < NB_WALL_FACES ; ++i ) {
273 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ i ]);
274 bool ok = LoadIJNodes (myWallNodesMaps[ fIndex ],
275 TopoDS::Face( myBlock.Shape( wallFaceID[ i ] )),
276 TopoDS::Edge( myBlock.Shape( baseEdgeID[ i ] )),
279 myErrorStatus->myName = COMPERR_BAD_INPUT_MESH;
280 myErrorStatus->myComment = SMESH_Comment() <<
281 "Can't find regular quadrangle mesh on a side face #" <<
282 pMesh->GetMeshDS()->ShapeToIndex( myBlock.Shape( wallFaceID[ i ]));
287 // 3.2 find node columns for vertical edges and edge IDs
288 vector<const SMDS_MeshNode*> * verticEdgeNodes[ NB_WALL_FACES ];
289 SMESH_Block::TShapeID verticEdgeID [ NB_WALL_FACES ];
290 for ( i = 0; i < NB_WALL_FACES ; ++i ) { // 4 first base nodes are nodes on vertices
292 SMESH_Block::TShapeID eID, vID = aSIDs[ i ];
293 ShapeSupportID(false, vID, eID);
294 verticEdgeID[ i ] = eID;
296 StdMeshers_TNode& aTNode = myTNodes[ i ];
297 verticEdgeNodes[ i ] = 0;
298 for ( j = 0; j < NB_WALL_FACES ; ++j ) { // loop on 4 wall faces
299 int fIndex = SMESH_Block::ShapeIndex( wallFaceID[ j ]);
300 StdMeshers_IJNodeMap & ijNodes= myWallNodesMaps[ fIndex ];
301 if ( ijNodes.begin()->second[0] == aTNode.Node() )
302 verticEdgeNodes[ i ] = & ijNodes.begin()->second;
303 else if ( ijNodes.rbegin()->second[0] == aTNode.Node() )
304 verticEdgeNodes[ i ] = & ijNodes.rbegin()->second;
305 if ( verticEdgeNodes[ i ] )
310 // 3.3 set XYZ of vertices, and initialize of the rest
311 SMESHDS_Mesh* aMesh = GetMesh()->GetMeshDS();
312 for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id ) {
313 if ( SMESH_Block::IsVertexID( id )) {
314 TopoDS_Shape V = myBlock.Shape( id );
315 SMESHDS_SubMesh* sm = aMesh->MeshElements( V );
316 const SMDS_MeshNode* n = sm->GetNodes()->next();
317 myShapeXYZ[ id ].SetCoord( n->X(), n->Y(), n->Z() );
320 myShapeXYZ[ id ].SetCoord( 0., 0., 0. );
324 // 4. Fill the rest repers
327 SMESH_Block::TShapeID aSSID, aBNSSID;
328 StdMeshers_TNode aTN;
331 // create top face and find UV for it's corners
332 const TopoDS_Face& TopFace = TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
333 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
334 int topfaceID = meshDS->ShapeToIndex(TopFace);
335 const TopoDS_Vertex& v001 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V001));
336 SMDS_NodeIteratorPtr itn = pMesh->GetSubMeshContaining(v001)->GetSubMeshDS()->GetNodes();
337 const SMDS_MeshNode* N = itn->next();
338 gp_XY UV001 = myTool->GetNodeUV(TopFace,N);
339 const TopoDS_Vertex& v101 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V101));
340 itn = pMesh->GetSubMeshContaining(v101)->GetSubMeshDS()->GetNodes();
342 gp_XY UV101 = myTool->GetNodeUV(TopFace,N);
343 const TopoDS_Vertex& v011 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V011));
344 itn = pMesh->GetSubMeshContaining(v011)->GetSubMeshDS()->GetNodes();
346 gp_XY UV011 = myTool->GetNodeUV(TopFace,N);
347 const TopoDS_Vertex& v111 = TopoDS::Vertex(myBlock.Shape(SMESH_Block::ID_V111));
348 itn = pMesh->GetSubMeshContaining(v111)->GetSubMeshDS()->GetNodes();
350 gp_XY UV111 = myTool->GetNodeUV(TopFace,N);
352 for (j=0; j<myJSize; ++j) { // loop on all nodes of the base face (ID_Fxy0)
354 const StdMeshers_TNode& aBN = myTNodes[j];
355 aBNSSID = (SMESH_Block::TShapeID)aBN.ShapeSupportID();
356 iBNID = aBN.BaseNodeID();
357 const gp_XYZ& aBNXYZ = aBN.NormCoord();
358 bool createNode = ( aBNSSID == SMESH_Block::ID_Fxy0 ); // if base node is inside a bottom face
360 // set XYZ on horizontal edges and get node columns of faces:
361 // 2 columns for each face, between which a base node is located
362 vector<const SMDS_MeshNode*>* nColumns[8];
363 double ratio[ NB_WALL_FACES ]; // base node position between columns [0.-1.]
365 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
366 ratio[ k ] = SetHorizEdgeXYZ (aBNXYZ, wallFaceID[ k ],
367 nColumns[k*2], nColumns[k*2+1]);
371 // XYZ on the bottom and top faces
372 const SMDS_MeshNode* n = aBN.Node();
373 myShapeXYZ[ SMESH_Block::ID_Fxy0 ].SetCoord( n->X(), n->Y(), n->Z() );
374 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( 0., 0., 0. );
376 // first create or find a top node, then the rest ones in a column
377 for (i=myISize-1; i>0; --i) // vertical loop, from top to bottom
379 bIsUpperLayer = (i==(myISize-1));
380 gp_XY UV_Ex01, UV_Ex11, UV_E0y1, UV_E1y1;
381 if ( createNode ) // a base node is inside a top face
383 // set XYZ on vertical edges and faces
384 for ( k = 0; k < NB_WALL_FACES ; ++k ) {
385 // XYZ on a vertical edge
386 const SMDS_MeshNode* n = (*verticEdgeNodes[ k ]) [ i ];
387 myShapeXYZ[ verticEdgeID[ k ] ].SetCoord( n->X(), n->Y(), n->Z() );
388 // XYZ on a face (part 1 from one column)
389 n = (*nColumns[k*2]) [ i ];
390 gp_XYZ xyz( n->X(), n->Y(), n->Z() );
391 myShapeXYZ[ wallFaceID[ k ]] = ( 1. - ratio[ k ]) * xyz;
393 if( bIsUpperLayer ) {
394 tmp1 = myTool->GetNodeUV(TopFace,n);
395 tmp1 = ( 1. - ratio[ k ]) * tmp1;
397 // XYZ on a face (part 2 from other column)
398 n = (*nColumns[k*2+1]) [ i ];
399 xyz.SetCoord( n->X(), n->Y(), n->Z() );
400 myShapeXYZ[ wallFaceID[ k ]] += ratio[ k ] * xyz;
401 if( bIsUpperLayer ) {
402 gp_XY tmp2 = myTool->GetNodeUV(TopFace,n);
403 tmp1 += ratio[ k ] * tmp2;
415 // fill current node info
418 // -normalized coordinates
422 aZ=(double)i/(double)(myISize-1);
423 aCoords.SetCoord(aX, aY, aZ);
425 // suporting shape ID
426 ShapeSupportID(bIsUpperLayer, aBNSSID, aSSID);
427 if (!myErrorStatus->IsOK()) {
428 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
432 aTN.SetShapeSupportID(aSSID);
433 aTN.SetNormCoord(aCoords);
434 aTN.SetBaseNodeID(iBNID);
436 if (aSSID!=SMESH_Block::ID_NONE){
437 // try to find the node
438 const TopoDS_Shape& aS=myBlock.Shape((int)aSSID);
439 FindNodeOnShape(aS, aCoords, i, aTN);
442 // create node and get its id
443 CreateNode (bIsUpperLayer, aCoords, aTN);
445 if ( bIsUpperLayer ) {
446 const SMDS_MeshNode* n = aTN.Node();
447 myShapeXYZ[ SMESH_Block::ID_Fxy1 ].SetCoord( n->X(), n->Y(), n->Z() );
448 // set node on top face:
449 // find UV parameter for this node
451 // UV011+-----+----------+UV111
454 // UV_E0y1+ +node +UV_E1y1
458 // UV001+-----+----------+UV101
461 double u = aCoords.X(), v = aCoords.Y();
462 double u1 = ( 1. - u ), v1 = ( 1. - v );
463 aP.ChangeCoord() = UV_Ex01 * v1;
464 aP.ChangeCoord() += UV_Ex11 * v;
465 aP.ChangeCoord() += UV_E0y1 * u1;
466 aP.ChangeCoord() += UV_E1y1 * u;
467 aP.ChangeCoord() -= UV001 * u1 * v1;
468 aP.ChangeCoord() -= UV101 * u * v1;
469 aP.ChangeCoord() -= UV011 * u1 * v;
470 aP.ChangeCoord() -= UV111 * u * v;
471 meshDS->SetNodeOnFace((SMDS_MeshNode*)n, topfaceID, aP.X(), aP.Y());
474 if (!myErrorStatus->IsOK()) {
475 MESSAGE("StdMeshers_Penta_3D::MakeNodes() ");
485 //=======================================================================
486 //function : FindNodeOnShape
488 //=======================================================================
490 void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
491 const gp_XYZ& aParams,
493 StdMeshers_TNode& aTN)
495 double aX, aY, aZ, aD, aTol2, minD;
498 SMESH_Mesh* pMesh = GetMesh();
499 aTol2 = myTol3D*myTol3D;
501 SMDS_MeshNode* pNode = NULL;
503 if ( aS.ShapeType() == TopAbs_FACE ||
504 aS.ShapeType() == TopAbs_EDGE ) {
505 // find a face ID to which aTN belongs to
507 if ( aS.ShapeType() == TopAbs_FACE )
508 faceID = myBlock.ShapeID( aS );
509 else { // edge maybe vertical or top horizontal
510 gp_XYZ aCoord = aParams;
511 if ( aCoord.Z() == 1. )
512 aCoord.SetZ( 0.5 ); // move from top down
514 aCoord.SetX( 0.5 ); // move along X
515 faceID = SMESH_Block::GetShapeIDByParams( aCoord );
517 ASSERT( SMESH_Block::IsFaceID( faceID ));
518 int fIndex = SMESH_Block::ShapeIndex( faceID );
519 StdMeshers_IJNodeMap & ijNodes = myWallNodesMaps[ fIndex ];
520 // look for a base node in ijNodes
521 const SMDS_MeshNode* baseNode = pMesh->GetMeshDS()->FindNode( aTN.BaseNodeID() );
522 StdMeshers_IJNodeMap::const_iterator par_nVec = ijNodes.begin();
523 for ( ; par_nVec != ijNodes.end(); par_nVec++ )
524 if ( par_nVec->second[ 0 ] == baseNode ) {
525 pNode = (SMDS_MeshNode*)par_nVec->second.at( z );
531 myBlock.Point(aParams, aS, aP1);
533 SMDS_NodeIteratorPtr ite=
534 pMesh->GetSubMeshContaining(aS)->GetSubMeshDS()->GetNodes();
536 const SMDS_MeshNode* aNode = ite->next();
537 if(myTool->IsMedium(aNode))
542 aP2.SetCoord(aX, aY, aZ);
543 aD=(double)aP1.SquareDistance(aP2);
544 //printf("** D=%lf ", aD, aTol2);
546 pNode=(SMDS_MeshNode*)aNode;
556 //aTN.SetNode(pNode);
557 //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
558 //myErrorStatus=11; // can not find the node;
562 //=======================================================================
563 //function : SetHorizEdgeXYZ
565 //=======================================================================
567 double StdMeshers_Penta_3D::SetHorizEdgeXYZ(const gp_XYZ& aBaseNodeParams,
569 vector<const SMDS_MeshNode*>*& aCol1,
570 vector<const SMDS_MeshNode*>*& aCol2)
572 // find base and top edges of the face
573 enum { BASE = 0, TOP };
574 vector< int > edgeVec; // 0-base, 1-top
575 SMESH_Block::GetFaceEdgesIDs( aFaceID, edgeVec );
577 int coord = SMESH_Block::GetCoordIndOnEdge( edgeVec[ BASE ] );
578 bool isForward = myBlock.IsForwadEdge( edgeVec[ BASE ] );
580 double param = aBaseNodeParams.Coord( coord );
584 // look for columns around param
585 StdMeshers_IJNodeMap & ijNodes =
586 myWallNodesMaps[ SMESH_Block::ShapeIndex( aFaceID )];
587 StdMeshers_IJNodeMap::iterator par_nVec_1 = ijNodes.begin();
588 while ( par_nVec_1->first < param )
590 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
593 if ( par_nVec_1 != ijNodes.begin() ) {
595 r = ( param - par_nVec_1->first ) / ( par_nVec_2->first - par_nVec_1->first );
597 aCol1 = & par_nVec_1->second;
598 aCol2 = & par_nVec_2->second;
602 // this variant is better for cases with curved edges and
603 // different nodes distribution on top and base edges
604 const SMDS_MeshNode* n1 = aCol1->back();
605 const SMDS_MeshNode* n2 = aCol2->back();
606 gp_XYZ xyz1( n1->X(), n1->Y(), n1->Z() );
607 gp_XYZ xyz2( n2->X(), n2->Y(), n2->Z() );
608 myShapeXYZ[ edgeVec[ 1 ] ] = ( 1. - r ) * xyz1 + r * xyz2;
611 // this variant is better for other cases
612 // SMESH_MesherHelper helper( *GetMesh() );
613 // const TopoDS_Edge & edge = TopoDS::Edge( myBlock.Shape( edgeVec[ TOP ]));
614 // double u1 = helper.GetNodeU( edge, n1 );
615 // double u2 = helper.GetNodeU( edge, n2 );
616 // double u = ( 1. - r ) * u1 + r * u2;
617 // gp_XYZ topNodeParams;
618 // myBlock.Block().EdgeParameters( edgeVec[ TOP ], u, topNodeParams );
619 // myBlock.Block().EdgePoint( edgeVec[ TOP ],
621 // myShapeXYZ[ edgeVec[ TOP ]]);
625 myBlock.Block().EdgePoint( edgeVec[ BASE ],
627 myShapeXYZ[ edgeVec[ BASE ]]);
632 //=======================================================================
633 //function : MakeVolumeMesh
635 //=======================================================================
636 void StdMeshers_Penta_3D::MakeVolumeMesh()
638 int i, j, ij, ik, i1, i2, aSSID;
640 SMESH_Mesh* pMesh = GetMesh();
641 SMESHDS_Mesh* meshDS = pMesh->GetMeshDS();
643 int shapeID = meshDS->ShapeToIndex( myShape );
645 // 1. Set Node In Volume
647 for (i=1; i<ik; ++i){
648 for (j=0; j<myJSize; ++j){
650 const StdMeshers_TNode& aTN = myTNodes[ij];
651 aSSID=aTN.ShapeSupportID();
652 if (aSSID==SMESH_Block::ID_NONE) {
653 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aTN.Node();
654 meshDS->SetNodeInVolume(aNode, shapeID);
659 // 2. Make pentahedrons
661 vector<const SMDS_MeshNode*> aN;
663 SMDS_ElemIteratorPtr itf, aItNodes;
665 const TopoDS_Face& aFxy0=
666 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
667 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
668 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
670 itf = aSM0->GetElements();
672 const SMDS_MeshElement* pE0 = itf->next();
674 int nbFaceNodes = pE0->NbNodes();
675 if(myCreateQuadratic)
676 nbFaceNodes = nbFaceNodes/2;
677 if ( (int) aN.size() < nbFaceNodes * 2 )
678 aN.resize( nbFaceNodes * 2 );
680 for ( k=0; k<nbFaceNodes; ++k ) {
681 const SMDS_MeshNode* pNode = pE0->GetNode(k);
682 // if(myTool->IsMedium(pNode))
684 aID0 = pNode->GetID();
685 aJ[k] = GetIndexOnLayer(aID0);
686 if (!myErrorStatus->IsOK()) {
687 MESSAGE("StdMeshers_Penta_3D::MakeVolumeMesh");
693 for (i=0; i<ik; ++i) {
696 for(j=0; j<nbFaceNodes; ++j) {
697 ij = i1*myJSize+aJ[j];
698 const StdMeshers_TNode& aTN1 = myTNodes[ij];
699 const SMDS_MeshNode* aN1 = aTN1.Node();
703 const StdMeshers_TNode& aTN2 = myTNodes[ij];
704 const SMDS_MeshNode* aN2 = aTN2.Node();
705 aN[j+nbFaceNodes] = aN2;
707 // check if volume orientation will be ok
709 SMDS_VolumeTool vTool;
710 switch ( nbFaceNodes ) {
712 SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
713 aN[3], aN[4], aN[5]);
714 vTool.Set( &tmpVol );
718 SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
719 aN[4], aN[5], aN[6], aN[7]);
720 vTool.Set( &tmpVol );
726 forward = vTool.IsForward();
729 SMDS_MeshVolume* aV = 0;
730 switch ( nbFaceNodes ) {
733 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
734 // aN[3], aN[4], aN[5]);
735 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3], aN[4], aN[5]);
738 //aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
739 // aN[3], aN[5], aN[4]);
740 aV = myTool->AddVolume(aN[0], aN[2], aN[1], aN[3], aN[5], aN[4]);
745 //aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
746 // aN[4], aN[5], aN[6], aN[7]);
747 aV = myTool->AddVolume(aN[0], aN[1], aN[2], aN[3],
748 aN[4], aN[5], aN[6], aN[7]);
751 //aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
752 // aN[4], aN[7], aN[6], aN[5]);
753 aV = myTool->AddVolume(aN[0], aN[3], aN[2], aN[1],
754 aN[4], aN[7], aN[6], aN[5]);
760 meshDS->SetMeshElementOnShape(aV, shapeID);
765 //=======================================================================
766 //function : MakeMeshOnFxy1
768 //=======================================================================
769 void StdMeshers_Penta_3D::MakeMeshOnFxy1()
771 int aID0, aJ, aLevel, ij, aNbNodes, k;
773 SMDS_NodeIteratorPtr itn;
774 SMDS_ElemIteratorPtr itf, aItNodes;
775 SMDSAbs_ElementType aElementType;
777 const TopoDS_Face& aFxy0=
778 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy0));
779 const TopoDS_Face& aFxy1=
780 TopoDS::Face(myBlock.Shape(SMESH_Block::ID_Fxy1));
782 SMESH_Mesh* pMesh = GetMesh();
783 SMESHDS_Mesh * meshDS = pMesh->GetMeshDS();
785 SMESH_subMesh *aSubMesh1 = pMesh->GetSubMeshContaining(aFxy1);
786 SMESH_subMesh *aSubMesh0 = pMesh->GetSubMeshContaining(aFxy0);
787 SMESHDS_SubMesh *aSM0 = aSubMesh0->GetSubMeshDS();
789 // set nodes on aFxy1
791 itn = aSM0->GetNodes();
792 aNbNodes = aSM0->NbNodes();
793 //printf("** aNbNodes=%d\n", aNbNodes);
794 myTool->SetSubShape( aFxy1 ); // to set medium nodes to aFxy1
796 // set elements on aFxy1
797 vector<const SMDS_MeshNode*> aNodes1;
799 itf = aSM0->GetElements();
801 const SMDS_MeshElement* pE0 = itf->next();
802 aElementType = pE0->GetType();
803 if (!aElementType==SMDSAbs_Face) {
806 aNbNodes = pE0->NbNodes();
807 if(myCreateQuadratic)
808 aNbNodes = aNbNodes/2;
809 if ( (int) aNodes1.size() < aNbNodes )
810 aNodes1.resize( aNbNodes );
812 k = aNbNodes-1; // reverse a face
813 aItNodes = pE0->nodesIterator();
814 while (aItNodes->more()) {
815 const SMDS_MeshNode* pNode =
816 static_cast<const SMDS_MeshNode*> (aItNodes->next());
817 if(myTool->IsMedium(pNode))
819 aID0 = pNode->GetID();
820 aJ = GetIndexOnLayer(aID0);
821 if (!myErrorStatus->IsOK()) {
822 MESSAGE("StdMeshers_Penta_3D::MakeMeshOnFxy1() ");
826 ij = aLevel*myJSize + aJ;
827 const StdMeshers_TNode& aTN1 = myTNodes[ij];
828 const SMDS_MeshNode* aN1 = aTN1.Node();
832 SMDS_MeshFace * face = 0;
833 switch ( aNbNodes ) {
835 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2]);
838 face = myTool->AddFace(aNodes1[0], aNodes1[1], aNodes1[2], aNodes1[3]);
843 meshDS->SetMeshElementOnShape(face, aFxy1);
845 myTool->SetSubShape( myShape );
847 // update compute state of top face submesh
848 aSubMesh1->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
850 // assure that mesh on the top face will be cleaned when it is cleaned
851 // on the bottom face
852 SMESH_subMesh* volSM = pMesh->GetSubMesh( myTool->GetSubShape() );
853 volSM->SetEventListener( new SMESH_subMeshEventListener(true, // deletable by SMESH_subMesh
854 "StdMeshers_Penta_3D"),
855 SMESH_subMeshEventListenerData::MakeData( aSubMesh1 ),
856 aSubMesh0 ); // translate CLEAN event of aSubMesh0 to aSubMesh1
859 //=======================================================================
860 //function : ClearMeshOnFxy1
862 //=======================================================================
863 void StdMeshers_Penta_3D::ClearMeshOnFxy1()
865 SMESH_subMesh* aSubMesh;
866 SMESH_Mesh* pMesh=GetMesh();
868 const TopoDS_Shape& aFxy1=myBlock.Shape(SMESH_Block::ID_Fxy1);
869 aSubMesh = pMesh->GetSubMeshContaining(aFxy1);
871 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
874 //=======================================================================
875 //function : GetIndexOnLayer
877 //=======================================================================
878 int StdMeshers_Penta_3D::GetIndexOnLayer(const int aID)
881 StdMeshers_IteratorOfDataMapOfIntegerInteger aMapIt;
883 aMapIt=myConnectingMap.find(aID);
884 if (aMapIt==myConnectingMap.end()) {
885 myErrorStatus->myName = 200;
886 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
893 //=======================================================================
894 //function : MakeConnectingMap
896 //=======================================================================
897 void StdMeshers_Penta_3D::MakeConnectingMap()
901 for (j=0; j<myJSize; ++j) {
902 const StdMeshers_TNode& aBN=myTNodes[j];
903 aBNID=aBN.BaseNodeID();
904 myConnectingMap[aBNID]=j;
908 //=======================================================================
909 //function : CreateNode
911 //=======================================================================
912 void StdMeshers_Penta_3D::CreateNode(const bool bIsUpperLayer,
913 const gp_XYZ& aParams,
914 StdMeshers_TNode& aTN)
920 SMDS_MeshNode* pNode=NULL;
923 // if (bIsUpperLayer) {
924 // // point on face Fxy1
925 // const TopoDS_Shape& aS=myBlock.Shape(SMESH_Block::ID_Fxy1);
926 // myBlock.Point(aParams, aS, aP);
929 // // point inside solid
930 // myBlock.Point(aParams, aP);
933 double u = aParams.X(), v = aParams.Y();
934 double u1 = ( 1. - u ), v1 = ( 1. - v );
935 aP.ChangeCoord() = myShapeXYZ[ SMESH_Block::ID_Ex01 ] * v1;
936 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_Ex11 ] * v;
937 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E0y1 ] * u1;
938 aP.ChangeCoord() += myShapeXYZ[ SMESH_Block::ID_E1y1 ] * u;
940 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V001 ] * u1 * v1;
941 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V101 ] * u * v1;
942 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V011 ] * u1 * v;
943 aP.ChangeCoord() -= myShapeXYZ[ SMESH_Block::ID_V111 ] * u * v;
946 SMESH_Block::ShellPoint( aParams, myShapeXYZ, aP.ChangeCoord() );
949 // iErr=myBlock.ErrorStatus();
951 // myErrorStatus=12; // can not find the node point;
955 aX=aP.X(); aY=aP.Y(); aZ=aP.Z();
957 SMESH_Mesh* pMesh = GetMesh();
958 SMESHDS_Mesh* pMeshDS = pMesh->GetMeshDS();
960 pNode = pMeshDS->AddNode(aX, aY, aZ);
965 //=======================================================================
966 //function : ShapeSupportID
968 //=======================================================================
969 void StdMeshers_Penta_3D::ShapeSupportID(const bool bIsUpperLayer,
970 const SMESH_Block::TShapeID aBNSSID,
971 SMESH_Block::TShapeID& aSSID)
974 case SMESH_Block::ID_V000:
975 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V001 : SMESH_Block::ID_E00z;
977 case SMESH_Block::ID_V100:
978 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V101 : SMESH_Block::ID_E10z;
980 case SMESH_Block::ID_V110:
981 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V111 : SMESH_Block::ID_E11z;
983 case SMESH_Block::ID_V010:
984 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_V011 : SMESH_Block::ID_E01z;
986 case SMESH_Block::ID_Ex00:
987 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex01 : SMESH_Block::ID_Fx0z;
989 case SMESH_Block::ID_Ex10:
990 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_Ex11 : SMESH_Block::ID_Fx1z;
992 case SMESH_Block::ID_E0y0:
993 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E0y1 : SMESH_Block::ID_F0yz;
995 case SMESH_Block::ID_E1y0:
996 aSSID=(bIsUpperLayer) ? SMESH_Block::ID_E1y1 : SMESH_Block::ID_F1yz;
998 case SMESH_Block::ID_Fxy0:
999 aSSID=SMESH_Block::ID_NONE;//(bIsUpperLayer) ? Shape_ID_Fxy1 : Shape_ID_NONE;
1002 aSSID=SMESH_Block::ID_NONE;
1003 myErrorStatus->myName=10; // Can not find supporting shape ID
1004 myErrorStatus->myComment = "Internal error of StdMeshers_Penta_3D";
1009 //=======================================================================
1010 //function : MakeBlock
1012 //=======================================================================
1013 void StdMeshers_Penta_3D::MakeBlock()
1016 int i, j, iNbEV, iNbE, iErr, iCnt, iNbNodes, iNbF;
1018 TopoDS_Vertex aV000, aV001;
1020 TopTools_IndexedDataMapOfShapeListOfShape aMVES;
1021 TopTools_IndexedMapOfShape aME ,aMEV, aM;
1022 TopTools_ListIteratorOfListOfShape aIt;
1024 TopExp::MapShapes(myShape, TopAbs_FACE, aM);
1026 // 0. Find triangulated face aFTr
1027 SMDSAbs_ElementType aElementType;
1028 SMESH_Mesh* pMesh=GetMesh();
1032 for (i=1; i<=iNbF; ++i) {
1033 const TopoDS_Shape& aF = aM(i);
1034 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1036 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1037 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1038 while(itf->more()) {
1039 const SMDS_MeshElement * pElement = itf->next();
1040 aElementType = pElement->GetType();
1041 if (aElementType==SMDSAbs_Face) {
1042 iNbNodes = pElement->NbNodes();
1043 if ( iNbNodes==3 || (pElement->IsQuadratic() && iNbNodes==6) ) {
1048 // The current algorithm fails if there is more that one
1049 // face wich contains triangles ...
1050 // In that case, replace return by break to try another
1051 // method (coded in "if (iCnt != 1) { ... }")
1053 // MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1054 // myErrorStatus=5; // more than one face has triangulation
1066 // The current algorithm fails if "iCnt != 1", the case "iCnt == 0"
1067 // was not reached 'cause it was not called from Hexa_3D ... Now it
1068 // can occurs and in my opinion, it is the most common case.
1071 // The suggested algorithm is the following :
1073 // o Check that nb_of_faces == 6 and nb_of_edges == 12
1074 // then the shape is tologically equivalent to a box
1075 // o In a box, there are three set of four // edges ...
1076 // In the cascade notation, it seems to be the edges
1081 // o For each one of this set, check if the four edges
1082 // have the same number of element.
1083 // o If so, check if the "corresponding" // faces contains
1084 // only quads. It's the faces numbered:
1088 // o If so, check if the opposite edges of each // faces
1089 // have the same number of elements. It is the edges
1091 // - 2 and 4, 6 and 8, 9 and 10, 11 and 12
1092 // - 1 and 3, 5 and 7, 9 and 11, 10 and 12
1093 // - 1 and 5, 3 and 7, 4 and 8, 2 and 6
1094 // o If so, check if the two other faces have the same
1095 // number of elements. It is the faces numbered:
1099 // This test should be improved to test if the nodes
1100 // of the two faces are really "en face".
1101 // o If so, one of the two faces is a candidate to an extrusion,
1102 // It is the faces numbered :
1106 // o Finally, if there is only one candidate, let do the
1107 // extrusion job for the corresponding face
1111 int iNbF = aM.Extent();
1114 int nb_f1 = pMesh->GetSubMeshContaining(aM(1))->GetSubMeshDS()->NbElements();
1115 int nb_f2 = pMesh->GetSubMeshContaining(aM(2))->GetSubMeshDS()->NbElements();
1116 int nb_f3 = pMesh->GetSubMeshContaining(aM(3))->GetSubMeshDS()->NbElements();
1117 int nb_f4 = pMesh->GetSubMeshContaining(aM(4))->GetSubMeshDS()->NbElements();
1118 int nb_f5 = pMesh->GetSubMeshContaining(aM(5))->GetSubMeshDS()->NbElements();
1119 int nb_f6 = pMesh->GetSubMeshContaining(aM(6))->GetSubMeshDS()->NbElements();
1121 int has_only_quad_f1 = 1;
1122 int has_only_quad_f2 = 1;
1123 int has_only_quad_f3 = 1;
1124 int has_only_quad_f4 = 1;
1125 int has_only_quad_f5 = 1;
1126 int has_only_quad_f6 = 1;
1128 for (i=1; i<=iNbF; ++i) {
1130 const TopoDS_Shape& aF = aM(i);
1131 SMESH_subMesh *aSubMesh = pMesh->GetSubMeshContaining(aF);
1132 SMESHDS_SubMesh *aSM = aSubMesh->GetSubMeshDS();
1133 SMDS_ElemIteratorPtr itf = aSM->GetElements();
1134 while(itf->more()) {
1135 const SMDS_MeshElement * pElement = itf->next();
1136 aElementType = pElement->GetType();
1137 if (aElementType==SMDSAbs_Face) {
1138 iNbNodes = pElement->NbNodes();
1139 if ( iNbNodes!=4 ) {
1145 if (i==1) has_only_quad_f1 = ok ;
1146 if (i==2) has_only_quad_f2 = ok ;
1147 if (i==3) has_only_quad_f3 = ok ;
1148 if (i==4) has_only_quad_f4 = ok ;
1149 if (i==5) has_only_quad_f5 = ok ;
1150 if (i==6) has_only_quad_f6 = ok ;
1153 TopTools_IndexedMapOfShape aE;
1154 TopExp::MapShapes(myShape, TopAbs_EDGE, aE);
1155 int iNbE = aE.Extent();
1158 int nb_e01 = pMesh->GetSubMeshContaining(aE(1))->GetSubMeshDS()->NbElements();
1159 int nb_e02 = pMesh->GetSubMeshContaining(aE(2))->GetSubMeshDS()->NbElements();
1160 int nb_e03 = pMesh->GetSubMeshContaining(aE(3))->GetSubMeshDS()->NbElements();
1161 int nb_e04 = pMesh->GetSubMeshContaining(aE(4))->GetSubMeshDS()->NbElements();
1162 int nb_e05 = pMesh->GetSubMeshContaining(aE(5))->GetSubMeshDS()->NbElements();
1163 int nb_e06 = pMesh->GetSubMeshContaining(aE(6))->GetSubMeshDS()->NbElements();
1164 int nb_e07 = pMesh->GetSubMeshContaining(aE(7))->GetSubMeshDS()->NbElements();
1165 int nb_e08 = pMesh->GetSubMeshContaining(aE(8))->GetSubMeshDS()->NbElements();
1166 int nb_e09 = pMesh->GetSubMeshContaining(aE(9))->GetSubMeshDS()->NbElements();
1167 int nb_e10 = pMesh->GetSubMeshContaining(aE(10))->GetSubMeshDS()->NbElements();
1168 int nb_e11 = pMesh->GetSubMeshContaining(aE(11))->GetSubMeshDS()->NbElements();
1169 int nb_e12 = pMesh->GetSubMeshContaining(aE(12))->GetSubMeshDS()->NbElements();
1173 if ( (nb_e01==nb_e03) && (nb_e03==nb_e05) && (nb_e05==nb_e07) ) {
1174 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f3 && has_only_quad_f4 ) {
1175 if ( (nb_e09==nb_e10) && (nb_e08==nb_e06) && (nb_e11==nb_e12) && (nb_e04==nb_e02) ) {
1183 if ( (nb_e02==nb_e04) && (nb_e04==nb_e06) && (nb_e06==nb_e08) ) {
1184 if ( has_only_quad_f1 && has_only_quad_f2 && has_only_quad_f5 && has_only_quad_f6 ) {
1185 if ( (nb_e01==nb_e03) && (nb_e10==nb_e12) && (nb_e05==nb_e07) && (nb_e09==nb_e11) ) {
1193 if ( (nb_e09==nb_e10) && (nb_e10==nb_e11) && (nb_e11==nb_e12) ) {
1194 if ( has_only_quad_f3 && has_only_quad_f4 && has_only_quad_f5 && has_only_quad_f6 ) {
1195 if ( (nb_e01==nb_e05) && (nb_e02==nb_e06) && (nb_e03==nb_e07) && (nb_e04==nb_e08) ) {
1211 myErrorStatus->myName=5; // more than one face has triangulation
1212 myErrorStatus->myComment="Incorrect input mesh";
1218 // 1. Vetrices V00, V001;
1220 TopExp::MapShapes(aFTr, TopAbs_EDGE, aME);
1221 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVES);
1223 // 1.1 Base vertex V000
1224 iNbE = aME.Extent();
1225 if (iNbE!= NB_WALL_FACES ){
1226 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1227 myErrorStatus->myName=7; // too few edges are in base face aFTr
1228 myErrorStatus->myComment=SMESH_Comment("Not a quadrilateral face #")
1229 <<pMesh->GetMeshDS()->ShapeToIndex( aFTr )<<": "<<iNbE<<" edges" ;
1232 const TopoDS_Edge& aE1=TopoDS::Edge(aME(1));
1233 aV000=TopExp::FirstVertex(aE1);
1235 const TopTools_ListOfShape& aLE=aMVES.FindFromKey(aV000);
1236 aIt.Initialize(aLE);
1237 for (; aIt.More(); aIt.Next()) {
1238 const TopoDS_Shape& aEx=aIt.Value();
1241 iNbEV=aMEV.Extent();
1243 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1244 myErrorStatus->myName=7; // too few edges meet in base vertex
1245 myErrorStatus->myComment=SMESH_Comment("3 edges must share vertex #")
1246 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 )<<" but there are "<<iNbEV<<" edges";
1252 for (j=1; j<=iNbEV; ++j) {
1253 const TopoDS_Shape& aEx=aMEV(j);
1254 if (!aME.Contains(aEx)) {
1255 TopoDS_Vertex aV[2];
1257 const TopoDS_Edge& aE=TopoDS::Edge(aEx);
1258 TopExp::Vertices(aE, aV[0], aV[1]);
1259 for (i=0; i<2; ++i) {
1260 if (!aV[i].IsSame(aV000)) {
1270 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1271 myErrorStatus->myName=8; // can not find reper V001
1272 myErrorStatus->myComment=SMESH_Comment("Can't find opposite vertex for vertex #")
1273 <<pMesh->GetMeshDS()->ShapeToIndex( aV000 );
1277 //gp_Pnt aP000, aP001;
1279 //aP000=BRep_Tool::Pnt(TopoDS::Vertex(aV000));
1280 //printf("*** aP000 { %lf, %lf, %lf }\n", aP000.X(), aP000.Y(), aP000.Z());
1281 //aP001=BRep_Tool::Pnt(TopoDS::Vertex(aV001));
1282 //printf("*** aP001 { %lf, %lf, %lf }\n", aP001.X(), aP001.Y(), aP001.Z());
1286 TopExp::MapShapes(myShape, TopAbs_SHELL, aME);
1289 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1290 myErrorStatus->myName=9; // number of shells in source shape !=1
1291 myErrorStatus->myComment=SMESH_Comment("Unexpected nb of shells ")<<iNbE;
1296 const TopoDS_Shell& aShell=TopoDS::Shell(aME(1));
1297 myBlock.Load(aShell, aV000, aV001);
1298 iErr = myBlock.ErrorStatus();
1300 MESSAGE("StdMeshers_Penta_3D::MakeBlock() ");
1301 myErrorStatus=myBlock.GetError(); // SMESHBlock: Load operation failed
1305 //=======================================================================
1306 //function : CheckData
1308 //=======================================================================
1309 void StdMeshers_Penta_3D::CheckData()
1312 int iNbEx[]={8, 12, 6};
1314 TopAbs_ShapeEnum aST;
1315 TopAbs_ShapeEnum aSTEx[]={
1316 TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE
1318 TopTools_IndexedMapOfShape aM;
1320 if (myShape.IsNull()){
1321 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1322 myErrorStatus->myName=2; // null shape
1323 myErrorStatus->myComment="Null shape";
1327 aST=myShape.ShapeType();
1328 if (!(aST==TopAbs_SOLID || aST==TopAbs_SHELL)) {
1329 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1330 myErrorStatus->myName=3; // not compatible type of shape
1331 myErrorStatus->myComment=SMESH_Comment("Wrong shape type (TopAbs_ShapeEnum) ")<<aST;
1335 for (i=0; i<3; ++i) {
1337 TopExp::MapShapes(myShape, aSTEx[i], aM);
1340 MESSAGE("StdMeshers_Penta_3D::CheckData() ");
1341 myErrorStatus->myName=4; // number of sub-shape is not compatible
1342 myErrorStatus->myComment="Wrong number of sub-shapes of a block";
1348 //=======================================================================
1349 //function : LoadIJNodes
1350 //purpose : Load nodes bound to theFace into column (vectors) and rows
1352 // The value of theIJNodes map is a vector of ordered nodes so
1353 // that the 0-the one lies on theBaseEdge.
1354 // The key of theIJNodes map is a normalized parameter of each
1355 // 0-the node on theBaseEdge.
1356 //=======================================================================
1358 bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes,
1359 const TopoDS_Face& theFace,
1360 const TopoDS_Edge& theBaseEdge,
1361 SMESHDS_Mesh* theMesh)
1363 // get vertices of theBaseEdge
1364 TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
1365 TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
1366 TopExp::Vertices( eFrw, vfb, vlb );
1368 // find the other edges of theFace and orientation of e1
1369 TopoDS_Edge e1, e2, eTop;
1370 bool rev1, CumOri = false;
1371 TopExp_Explorer exp( theFace, TopAbs_EDGE );
1373 for ( ; exp.More(); exp.Next() ) {
1374 if ( ++nbEdges > NB_WALL_FACES ) {
1375 return false; // more than 4 edges in theFace
1377 TopoDS_Edge e = TopoDS::Edge( exp.Current() );
1378 if ( theBaseEdge.IsSame( e ))
1380 TopoDS_Vertex vCommon;
1381 if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
1383 else if ( vCommon.IsSame( vfb )) {
1385 vft = TopExp::LastVertex( e1, CumOri );
1386 rev1 = vfb.IsSame( vft );
1388 vft = TopExp::FirstVertex( e1, CumOri );
1393 if ( nbEdges < NB_WALL_FACES ) {
1394 return false; // less than 4 edges in theFace
1397 // submeshes corresponding to shapes
1398 SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
1399 SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
1400 SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
1401 SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
1402 SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
1403 SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
1404 SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
1405 SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
1406 if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
1407 MESSAGE( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
1408 sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
1411 if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
1412 MESSAGE(" Diff nb of nodes on opposite edges" );
1415 if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
1416 MESSAGE("Empty submesh of vertex");
1419 if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
1420 // check quadratic case
1421 if ( myCreateQuadratic ) {
1422 int n1 = sm1->NbNodes()/2;
1423 int n2 = smb->NbNodes()/2;
1424 int n3 = sm1->NbNodes() - n1;
1425 int n4 = smb->NbNodes() - n2;
1426 int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
1427 if( nf != smFace->NbNodes() ) {
1428 MESSAGE( "Wrong nb face nodes: " <<
1429 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1434 MESSAGE( "Wrong nb face nodes: " <<
1435 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
1440 int vsize = sm1->NbNodes() + 2;
1441 int hsize = smb->NbNodes() + 2;
1442 if(myCreateQuadratic) {
1443 vsize = vsize - sm1->NbNodes()/2 -1;
1444 hsize = hsize - smb->NbNodes()/2 -1;
1447 // load nodes from theBaseEdge
1449 set<const SMDS_MeshNode*> loadedNodes;
1450 const SMDS_MeshNode* nullNode = 0;
1452 vector<const SMDS_MeshNode*> & nVecf = theIJNodes[ 0.];
1453 nVecf.resize( vsize, nullNode );
1454 loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1456 vector<const SMDS_MeshNode*> & nVecl = theIJNodes[ 1.];
1457 nVecl.resize( vsize, nullNode );
1458 loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1461 BRep_Tool::Range( eFrw, f, l );
1462 double range = l - f;
1463 SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1464 const SMDS_MeshNode* node;
1465 while ( nIt->more() ) {
1467 if(myTool->IsMedium(node))
1469 const SMDS_EdgePosition* pos =
1470 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition() );
1474 double u = ( pos->GetUParameter() - f ) / range;
1475 vector<const SMDS_MeshNode*> & nVec = theIJNodes[ u ];
1476 nVec.resize( vsize, nullNode );
1477 loadedNodes.insert( nVec[ 0 ] = node );
1479 if ( (int) theIJNodes.size() != hsize ) {
1480 MESSAGE( "Wrong node positions on theBaseEdge" );
1484 // load nodes from e1
1486 map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1487 nIt = sm1->GetNodes();
1488 while ( nIt->more() ) {
1490 if(myTool->IsMedium(node))
1492 const SMDS_EdgePosition* pos =
1493 dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition() );
1497 sortedNodes.insert( make_pair( pos->GetUParameter(), node ));
1499 loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1500 map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1501 int row = rev1 ? vsize - 1 : 0;
1502 for ( ; u_n != sortedNodes.end(); u_n++ ) {
1505 loadedNodes.insert( nVecf[ row ] = u_n->second );
1508 // try to load the rest nodes
1510 // get all faces from theFace
1511 TIDSortedElemSet allFaces, foundFaces;
1512 SMDS_ElemIteratorPtr eIt = smFace->GetElements();
1513 while ( eIt->more() ) {
1514 const SMDS_MeshElement* e = eIt->next();
1515 if ( e->GetType() == SMDSAbs_Face )
1516 allFaces.insert( e );
1518 // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1519 // the nodes belong to, and between the nodes of the found face,
1520 // look for a not loaded node considering this node to be the next
1521 // in a column of the starting second node. Repeat, starting
1522 // from nodes next to the previous starting nodes in their columns,
1523 // and so on while a face can be found. Then go the the next pair
1524 // of nodes on theBaseEdge.
1525 StdMeshers_IJNodeMap::iterator par_nVec_1 = theIJNodes.begin();
1526 StdMeshers_IJNodeMap::iterator par_nVec_2 = par_nVec_1;
1529 for ( par_nVec_2++; par_nVec_2 != theIJNodes.end(); par_nVec_1++, par_nVec_2++ ) {
1532 const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1533 const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1534 const SMDS_MeshElement* face = 0;
1536 // look for a face by 2 nodes
1537 face = SMESH_MeshAlgos::FindFaceInSet( n1, n2, allFaces, foundFaces );
1539 int nbFaceNodes = face->NbNodes();
1540 if ( (!myCreateQuadratic && nbFaceNodes>4) ||
1541 (myCreateQuadratic && nbFaceNodes>8) ) {
1542 MESSAGE(" Too many nodes in a face: " << nbFaceNodes );
1545 // look for a not loaded node of the <face>
1547 const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1548 eIt = face->nodesIterator() ;
1549 while ( !found && eIt->more() ) {
1550 node = static_cast<const SMDS_MeshNode*>( eIt->next() );
1551 if(myTool->IsMedium(node))
1553 found = loadedNodes.insert( node ).second;
1554 if ( !found && node != n1 && node != n2 )
1558 if ( ++row > vsize - 1 ) {
1559 MESSAGE( "Too many nodes in column "<< col <<": "<< row+1);
1562 par_nVec_2->second[ row ] = node;
1563 foundFaces.insert( face );
1565 if ( nbFaceNodes==4 || (myCreateQuadratic && nbFaceNodes==8) ) {
1566 n1 = par_nVec_1->second[ row ];
1569 else if ( (nbFaceNodes==3 || (myCreateQuadratic && nbFaceNodes==6) ) &&
1570 n3 == par_nVec_1->second[ row ] ) {
1574 MESSAGE( "Not quad mesh, column "<< col );
1579 while ( face && n1 && n2 );
1581 if ( row < vsize - 1 ) {
1582 MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1583 MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1584 MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1585 MESSAGE( "Current node 1: "<< n1);
1586 MESSAGE( "Current node 2: "<< n2);
1587 MESSAGE( "first base node: "<< theIJNodes.begin()->second[0]);
1588 MESSAGE( "last base node: "<< theIJNodes.rbegin()->second[0]);
1591 } // loop on columns
1596 //////////////////////////////////////////////////////////////////////////
1598 // StdMeshers_SMESHBlock
1600 //////////////////////////////////////////////////////////////////////////
1602 //=======================================================================
1603 //function : StdMeshers_SMESHBlock
1605 //=======================================================================
1606 StdMeshers_SMESHBlock::StdMeshers_SMESHBlock()
1609 myIsEdgeForward.resize( SMESH_Block::NbEdges(), -1 );
1612 //=======================================================================
1613 //function : IsForwadEdge
1615 //=======================================================================
1617 bool StdMeshers_SMESHBlock::IsForwadEdge(const int theEdgeID)
1619 int index = myTBlock.ShapeIndex( theEdgeID );
1620 if ( !myTBlock.IsEdgeID( theEdgeID ))
1623 if ( myIsEdgeForward[ index ] < 0 )
1624 myIsEdgeForward[ index ] =
1625 myTBlock.IsForwardEdge( TopoDS::Edge( Shape( theEdgeID )), myShapeIDMap );
1627 return myIsEdgeForward[ index ];
1630 //=======================================================================
1631 //function : ErrorStatus
1633 //=======================================================================
1634 int StdMeshers_SMESHBlock::ErrorStatus() const
1636 return myErrorStatus;
1639 //================================================================================
1641 * \brief Return problem description
1643 //================================================================================
1645 SMESH_ComputeErrorPtr StdMeshers_SMESHBlock::GetError() const
1647 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New();
1648 string & text = err->myComment;
1649 switch ( myErrorStatus ) {
1651 case 3: text = "Internal error of StdMeshers_Penta_3D"; break;
1652 case 4: text = "Can't compute normalized parameters of a point inside a block"; break;
1653 case 5: text = "Can't compute coordinates by normalized parameters inside a block"; break;
1654 case 6: text = "Can't detect block sub-shapes. Not a block?"; break;
1657 err->myName = myErrorStatus;
1661 //=======================================================================
1664 //=======================================================================
1665 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell)
1667 TopoDS_Vertex aV000, aV001;
1669 Load(theShell, aV000, aV001);
1672 //=======================================================================
1675 //=======================================================================
1676 void StdMeshers_SMESHBlock::Load(const TopoDS_Shell& theShell,
1677 const TopoDS_Vertex& theV000,
1678 const TopoDS_Vertex& theV001)
1686 myShapeIDMap.Clear();
1687 bOk = myTBlock.LoadBlockShapes(myShell, theV000, theV001, myShapeIDMap);
1694 //=======================================================================
1695 //function : ComputeParameters
1697 //=======================================================================
1698 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1701 ComputeParameters(thePnt, myShell, theXYZ);
1704 //=======================================================================
1705 //function : ComputeParameters
1707 //=======================================================================
1708 void StdMeshers_SMESHBlock::ComputeParameters(const gp_Pnt& thePnt,
1709 const TopoDS_Shape& theShape,
1717 aID = ShapeID(theShape);
1718 if (myErrorStatus) {
1721 bOk = myTBlock.ComputeParameters(thePnt, theXYZ, aID);
1723 myErrorStatus=4; // problems with computation Parameters
1728 //=======================================================================
1729 //function : ComputeParameters
1731 //=======================================================================
1733 void StdMeshers_SMESHBlock::ComputeParameters(const double& theU,
1734 const TopoDS_Shape& theShape,
1742 aID = ShapeID(theShape);
1743 if (myErrorStatus) {
1746 if ( SMESH_Block::IsEdgeID( aID ))
1747 bOk = myTBlock.EdgeParameters( aID, theU, theXYZ );
1749 myErrorStatus=4; // problems with computation Parameters
1754 //=======================================================================
1757 //=======================================================================
1758 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams, gp_Pnt& aP3D)
1762 Point(theParams, aS, aP3D);
1765 //=======================================================================
1768 //=======================================================================
1769 void StdMeshers_SMESHBlock::Point(const gp_XYZ& theParams,
1770 const TopoDS_Shape& theShape,
1777 gp_XYZ aXYZ(99.,99.,99.);
1780 if (theShape.IsNull()) {
1781 bOk = myTBlock.ShellPoint(theParams, aXYZ);
1785 aID=ShapeID(theShape);
1786 if (myErrorStatus) {
1790 if (SMESH_Block::IsVertexID(aID)) {
1791 bOk = myTBlock.VertexPoint(aID, aXYZ);
1793 else if (SMESH_Block::IsEdgeID(aID)) {
1794 bOk = myTBlock.EdgePoint(aID, theParams, aXYZ);
1797 else if (SMESH_Block::IsFaceID(aID)) {
1798 bOk = myTBlock.FacePoint(aID, theParams, aXYZ);
1802 myErrorStatus=5; // problems with point computation
1808 //=======================================================================
1809 //function : ShapeID
1811 //=======================================================================
1812 int StdMeshers_SMESHBlock::ShapeID(const TopoDS_Shape& theShape)
1817 TopoDS_Shape aSF, aSR;
1820 aSF.Orientation(TopAbs_FORWARD);
1822 aSR.Orientation(TopAbs_REVERSED);
1824 if (myShapeIDMap.Contains(aSF)) {
1825 aID=myShapeIDMap.FindIndex(aSF);
1828 if (myShapeIDMap.Contains(aSR)) {
1829 aID=myShapeIDMap.FindIndex(aSR);
1832 myErrorStatus=2; // unknown shape;
1836 //=======================================================================
1839 //=======================================================================
1840 const TopoDS_Shape& StdMeshers_SMESHBlock::Shape(const int theID)
1846 aNb=myShapeIDMap.Extent();
1847 if (theID<1 || theID>aNb) {
1848 myErrorStatus=3; // ID is out of range
1849 return myEmptyShape;
1852 const TopoDS_Shape& aS=myShapeIDMap.FindKey(theID);
1857 //=======================================================================
1858 //function : Evaluate
1860 //=======================================================================
1861 bool StdMeshers_Penta_3D::Evaluate(SMESH_Mesh& aMesh,
1862 const TopoDS_Shape& aShape,
1863 MapShapeNbElems& aResMap)
1865 MESSAGE("StdMeshers_Penta_3D::Evaluate()");
1867 // find face contains only triangles
1868 vector < SMESH_subMesh * >meshFaces;
1869 TopTools_SequenceOfShape aFaces;
1870 int NumBase = 0, i = 0;
1871 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
1873 aFaces.Append(exp.Current());
1874 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
1875 meshFaces.push_back(aSubMesh);
1876 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i]);
1877 if( anIt == aResMap.end() ) {
1881 std::vector<int> aVec = (*anIt).second;
1882 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1883 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1884 if( nbtri>0 && nbqua==0 ) {
1890 std::vector<int> aResVec(SMDSEntity_Last);
1891 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1892 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1893 aResMap.insert(std::make_pair(sm,aResVec));
1894 myErrorStatus->myName = COMPERR_ALGO_FAILED;
1895 myErrorStatus->myComment = "Submesh can not be evaluated";
1899 // find number of 1d elems for base face
1901 TopTools_MapOfShape Edges1;
1902 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1903 Edges1.Add(exp.Current());
1904 SMESH_subMesh *sm = aMesh.GetSubMesh(exp.Current());
1906 MapShapeNbElemsItr anIt = aResMap.find(sm);
1907 if( anIt == aResMap.end() ) continue;
1908 std::vector<int> aVec = (*anIt).second;
1909 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1912 // find face opposite to base face
1914 for(i=1; i<=6; i++) {
1915 if(i==NumBase) continue;
1916 bool IsOpposite = true;
1917 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1918 if( Edges1.Contains(exp.Current()) ) {
1928 // find number of 2d elems on side faces
1930 for(i=1; i<=6; i++) {
1931 if( i==OppNum || i==NumBase ) continue;
1932 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1933 if( anIt == aResMap.end() ) continue;
1934 std::vector<int> aVec = (*anIt).second;
1935 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1938 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1939 std::vector<int> aVec = (*anIt).second;
1940 int nb2d_face0 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1941 int nb0d_face0 = aVec[SMDSEntity_Node];
1943 anIt = aResMap.find( meshFaces[OppNum-1] );
1944 for(i=SMDSEntity_Node; i<SMDSEntity_Last; i++)
1945 (*anIt).second[i] = aVec[i];
1947 SMESH_MesherHelper aTool (aMesh);
1948 bool _quadraticMesh = aTool.IsQuadraticSubMesh(aShape);
1950 std::vector<int> aResVec(SMDSEntity_Last);
1951 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1952 if(_quadraticMesh) {
1953 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0 * ( nb2d/nb1d );
1954 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 );
1957 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1958 aResVec[SMDSEntity_Penta] = nb2d_face0 * ( nb2d/nb1d );
1960 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1961 aResMap.insert(std::make_pair(sm,aResVec));