From ffa6ef36b3173eb574edf89751298bcffd14460d Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 22 Nov 2013 13:16:34 +0000 Subject: [PATCH] http://www.salome-platform.org/forum/forum_10/409159356 Fox testcube2a.py --- src/StdMeshers/StdMeshers_Prism_3D.cxx | 133 +++++++++++++++++++------ src/StdMeshers/StdMeshers_Prism_3D.hxx | 3 +- 2 files changed, 107 insertions(+), 29 deletions(-) diff --git a/src/StdMeshers/StdMeshers_Prism_3D.cxx b/src/StdMeshers/StdMeshers_Prism_3D.cxx index 048b3e7ad..07e9a166d 100644 --- a/src/StdMeshers/StdMeshers_Prism_3D.cxx +++ b/src/StdMeshers/StdMeshers_Prism_3D.cxx @@ -373,6 +373,23 @@ namespace { return nbRemoved; } + //================================================================================ + /*! + * \brief Return and angle between two EDGEs + * \return double - the angle normalized so that + * >~ 0 -> 2.0 + * PI/2 -> 1.0 + * PI -> 0.0 + * -PI/2 -> -1.0 + * <~ 0 -> -2.0 + */ + //================================================================================ + + double normAngle(const TopoDS_Edge & E1, const TopoDS_Edge & E2, const TopoDS_Face & F) + { + return SMESH_MesherHelper::GetAngle( E1, E2, F ) / ( 0.5 * M_PI ); + } + //================================================================================ /*! * Consider continuous straight EDGES as one side - mark them to unite @@ -380,40 +397,80 @@ namespace { //================================================================================ int countNbSides( const Prism_3D::TPrismTopo & thePrism, - vector & nbUnitePerEdge ) + vector & nbUnitePerEdge, + vector< double > & edgeLength) { int nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges int nbSides = nbEdges; + list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin(); std::advance( edgeIt, nbEdges-1 ); TopoDS_Edge prevE = *edgeIt; - bool isPrevStraight = SMESH_Algo::isStraight( prevE ); + // bool isPrevStraight = SMESH_Algo::IsStraight( prevE ); int iPrev = nbEdges - 1; int iUnite = -1; // the first of united EDGEs + // analyse angles between EDGEs + int nbCorners = 0; + vector< bool > isCorner( nbEdges ); edgeIt = thePrism.myBottomEdges.begin(); for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt ) { const TopoDS_Edge& curE = *edgeIt; - const bool isCurStraight = SMESH_Algo::isStraight( curE ); - if ( isPrevStraight && isCurStraight && SMESH_Algo::IsContinuous( prevE, curE )) - { - if ( iUnite < 0 ) - iUnite = iPrev; - nbUnitePerEdge[ iUnite ]++; - nbUnitePerEdge[ iE ] = -1; - --nbSides; - } - else - { - iUnite = -1; - } - prevE = curE; - isPrevStraight = isCurStraight; - iPrev = iE; + edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE ); + + // double normAngle = normAngle( prevE, curE, thePrism.myBottom ); + // isCorner[ iE ] = false; + // if ( normAngle < 2.0 ) + // { + // if ( normAngle < 0.001 ) // straight or obtuse angle + // { + // // unite EDGEs in order not to put a corner of the unit quadrangle at this VERTEX + // if ( iUnite < 0 ) + // iUnite = iPrev; + // nbUnitePerEdge[ iUnite ]++; + // nbUnitePerEdge[ iE ] = -1; + // --nbSides; + // } + // else + // { + // isCorner[ iE ] = true; + // nbCorners++; + // iUnite = -1; + // } + // } + // prevE = curE; + } + + if ( nbCorners > 4 ) + { + // define which of corners to put on a side of the unit quadrangle } + // edgeIt = thePrism.myBottomEdges.begin(); + // for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt ) + // { + // const TopoDS_Edge& curE = *edgeIt; + // edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE ); + + // const bool isCurStraight = SMESH_Algo::IsStraight( curE ); + // if ( isPrevStraight && isCurStraight && SMESH_Algo::IsContinuous( prevE, curE )) + // { + // if ( iUnite < 0 ) + // iUnite = iPrev; + // nbUnitePerEdge[ iUnite ]++; + // nbUnitePerEdge[ iE ] = -1; + // --nbSides; + // } + // else + // { + // iUnite = -1; + // } + // prevE = curE; + // isPrevStraight = isCurStraight; + // iPrev = iE; + // } return nbSides; } @@ -925,7 +982,7 @@ bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism) if ( !computeWalls( thePrism )) return false; - // Analyse mesh and geometry to find block sub-shapes and submeshes + // Analyse mesh and geometry to find all block sub-shapes and submeshes if ( !myBlock.Init( myHelper, thePrism )) return toSM( error( myBlock.GetError())); @@ -1322,7 +1379,7 @@ bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism) SMESH_subMesh* topSM = mesh->GetSubMesh( topE ); SMESH_subMesh* srcSM = botSM; SMESH_subMesh* tgtSM = topSM; - if ( !srcSM->IsMeshComputed() && topSM->IsMeshComputed() ) + if ( !srcSM->IsMeshComputed() && tgtSM->IsMeshComputed() ) std::swap( srcSM, tgtSM ); if ( !srcSM->IsMeshComputed() ) @@ -1333,10 +1390,31 @@ bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism) } srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); + if ( tgtSM->IsMeshComputed() && + tgtSM->GetSubMeshDS()->NbNodes() != srcSM->GetSubMeshDS()->NbNodes() ) + { + // the top EDGE is computed differently than the bottom one, + // try to clear a wrong mesh + bool isAdjFaceMeshed = false; + PShapeIteratorPtr fIt = myHelper->GetAncestors( tgtSM->GetSubShape(), + *mesh, TopAbs_FACE ); + while ( const TopoDS_Shape* f = fIt->next() ) + if (( isAdjFaceMeshed = mesh->GetSubMesh( *f )->IsMeshComputed() )) + break; + if ( isAdjFaceMeshed ) + return toSM( error( TCom("Different nb of segment on logically horizontal edges #") + << shapeID( botE ) << " and #" + << shapeID( topE ) << ": " + << tgtSM->GetSubMeshDS()->NbElements() << " != " + << srcSM->GetSubMeshDS()->NbElements() )); + tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); + } if ( !tgtSM->IsMeshComputed() ) { // compute nodes on VERTEXes - tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE ); + SMESH_subMeshIteratorPtr smIt = tgtSM->getDependsOnIterator(/*includeSelf=*/false); + while ( smIt->more() ) + smIt->next()->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE ); // project segments DBGOUT( "COMPUTE H edge (proj) " << tgtSM->GetId()); projector1D->myHyp.SetSourceEdge( TopoDS::Edge( srcSM->GetSubShape() )); @@ -2264,7 +2342,7 @@ bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper, vector nbUnitePerEdge( nbEdges, 0 ); // -1 means "joined to a previous" // consider continuous straight EDGEs as one side - const int nbSides = countNbSides( thePrism, nbUnitePerEdge ); + const int nbSides = countNbSides( thePrism, nbUnitePerEdge, edgeLength ); list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin(); for ( iE = 0; iE < nbEdges; ++iE, ++edgeIt ) @@ -2283,8 +2361,6 @@ bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper, SHOWYXZ("p2 F " <second.front() )); SHOWYXZ("V First "<