#include <limits>
#ifdef _DEBUG_
-#define __myDEBUG
+//#define __myDEBUG
//#define __NOT_INVALIDATE_BAD_SMOOTH
#endif
void InvalidateStep( int curStep, bool restoreLength=false );
void ChooseSmooFunction(const set< TGeomID >& concaveVertices,
const TNode2Edge& n2eMap);
- bool Smooth(int& badNb, const int step, const bool isConcaveFace);
+ int Smooth(const int step, const bool isConcaveFace, const bool findBest);
bool SmoothOnEdge(Handle(Geom_Surface)& surface,
const TopoDS_Face& F,
SMESH_MesherHelper& helper);
// Create temporary faces and _LayerEdge's
- dumpFunction(SMESH_Comment("makeLayers_")<<data._index);
+ dumpFunction(SMESH_Comment("makeLayers_")<<data._index);
data._stepSize = Precision::Infinite();
data._stepSizeNodes[0] = 0;
return true; // no shapes needing smoothing
bool moved, improved;
+ vector< _LayerEdge* > badSmooEdges;
SMESH_MesherHelper helper(*_mesh);
Handle(Geom_Surface) surface;
const bool isConcaveFace = data._concaveFaces.count( sInd );
- int step = 0, stepLimit = 5, badNb = 0; moved = true;
- while (( ++step <= stepLimit && moved ) || improved )
+ int step = 0, stepLimit = 5, badNb = 0;
+ while (( ++step <= stepLimit ) || improved )
{
dumpFunction(SMESH_Comment("smooth")<<data._index<<"_Fa"<<sInd
<<"_InfStep"<<nbSteps<<"_"<<step); // debug
int oldBadNb = badNb;
- badNb = 0;
- moved = false;
- if ( step % 2 )
+ badSmooEdges.clear();
+
+ if ( step % 2 ) {
for ( int i = iBeg; i < iEnd; ++i ) // iterate forward
- moved |= data._edges[i]->Smooth( badNb, step, isConcaveFace );
- else
+ if ( data._edges[i]->Smooth( step, isConcaveFace, false ))
+ badSmooEdges.push_back( data._edges[i] );
+ }
+ else {
for ( int i = iEnd-1; i >= iBeg; --i ) // iterate backward
- moved |= data._edges[i]->Smooth( badNb, step, isConcaveFace );
+ if ( data._edges[i]->Smooth( step, isConcaveFace, false ))
+ badSmooEdges.push_back( data._edges[i] );
+ }
+ badNb = badSmooEdges.size();
improved = ( badNb < oldBadNb );
+ if ( !badSmooEdges.empty() && step >= stepLimit / 2 )
+ {
+ // look for the best smooth of _LayerEdge's neighboring badSmooEdges
+ vector<_Simplex> simplices;
+ for ( size_t i = 0; i < badSmooEdges.size(); ++i )
+ {
+ _LayerEdge* ledge = badSmooEdges[i];
+ _Simplex::GetSimplices( ledge->_nodes[0], simplices, data._ignoreFaceIds );
+ for ( size_t iS = 0; iS < simplices.size(); ++iS )
+ {
+ TNode2Edge::iterator n2e = data._n2eMap.find( simplices[iS]._nNext );
+ if ( n2e != data._n2eMap.end()) {
+ _LayerEdge* ledge2 = n2e->second;
+ if ( ledge2->_nodes[0]->getshapeId() == sInd )
+ ledge2->Smooth( step, isConcaveFace, /*findBest=*/true );
+ }
+ }
+ }
+ }
// issue 22576 -- no bad faces but still there are intersections to fix
// if ( improved && badNb == 0 )
// stepLimit = step + 3;
*/
//================================================================================
-bool _LayerEdge::Smooth(int& badNb, const int step, const bool isConcaveFace )
+int _LayerEdge::Smooth(const int step, const bool isConcaveFace, const bool findBest )
{
- bool moved = false;
if ( _simplices.size() < 2 )
- return moved; // _LayerEdge inflated along EDGE or FACE
+ return 0; // _LayerEdge inflated along EDGE or FACE
const gp_XYZ& curPos ( _pos.back() );
const gp_XYZ& prevPos( _pos[ _pos.size()-2 ]);
int nbBad = _simplices.size() - nbOkBefore;
// compute new position for the last _pos using different _funs
- gp_XYZ newPos, bestNewPos;
+ gp_XYZ newPos;
for ( int iFun = -1; iFun < theNbSmooFuns; ++iFun )
{
if ( iFun < 0 )
n->setXYZ( newPos.X(), newPos.Y(), newPos.Z());
_pos.back() = newPos;
- moved = true;
dumpMoveComm( n, _funNames[ iFun < 0 ? smooFunID() : iFun ]);
nbBad = _simplices.size() - nbOkAfter;
continue; // look for a better function
}
- break;
+ if ( !findBest )
+ break;
} // loop on smoothing functions
- badNb += nbBad;
- return moved;
+ return nbBad;
}
//================================================================================