router: wip on less intrusive dragged trace optimization

This commit is contained in:
Tomasz Wlostowski 2020-10-09 00:00:12 +02:00
parent b5fa523a11
commit 9bef95418e
4 changed files with 83 additions and 23 deletions

View File

@ -319,7 +319,7 @@ void DRAGGER::dragViaWalkaround( const VIA_HANDLE& aHandle, NODE* aNode, const V
}
void DRAGGER::optimizeAndUpdateDraggedLine( LINE& dragged, const VECTOR2I& aP )
void DRAGGER::optimizeAndUpdateDraggedLine( LINE& dragged, SEG& aDraggedSeg, const VECTOR2I& aP )
{
VECTOR2D lockV;
dragged.ClearLinks();
@ -329,9 +329,24 @@ void DRAGGER::optimizeAndUpdateDraggedLine( LINE& dragged, const VECTOR2I& aP )
if( Settings().GetOptimizeDraggedTrack() )
{
OPTIMIZER::Optimize( &dragged,
OPTIMIZER::MERGE_SEGMENTS | OPTIMIZER::KEEP_TOPOLOGY | OPTIMIZER::PRESERVE_VERTEX,
m_lastNode, lockV );
OPTIMIZER optimizer( m_lastNode );
optimizer.SetEffortLevel( OPTIMIZER::MERGE_SEGMENTS | OPTIMIZER::KEEP_TOPOLOGY );
int startV = dragged.CLine().Find( aDraggedSeg.A );
int endV = dragged.CLine().Find( aDraggedSeg.B );
if ( endV > startV )
{
std::swap(endV, startV);
}
if( startV >= 0 && endV >= 0)
{
optimizer.SetPreserveVertex( aP );
optimizer.SetRestrictVertexRange( startV, endV );
optimizer.Optimize( &dragged );
}
}
m_lastNode->Add( dragged );
@ -405,7 +420,8 @@ bool DRAGGER::dragWalkaround( const VECTOR2I& aP )
if(ok)
{
m_lastNode->Remove( origLine );
optimizeAndUpdateDraggedLine( dragged, aP );
SEG dummy;
optimizeAndUpdateDraggedLine( dragged, dummy, aP );
}
break;
}

View File

@ -104,7 +104,8 @@ private:
bool startDragVia( VIA* aVia );
void dragViaMarkObstacles( const VIA_HANDLE& aHandle, NODE* aNode, const VECTOR2I& aP );
void dragViaWalkaround( const VIA_HANDLE& aHandle, NODE* aNode, const VECTOR2I& aP );
void optimizeAndUpdateDraggedLine( LINE& dragged, const VECTOR2I& aP );
void optimizeAndUpdateDraggedLine( LINE& dragged, SEG& aDraggedSeg, const VECTOR2I& aP );
VIA_HANDLE m_initialVia;
VIA_HANDLE m_draggedVia;

View File

@ -134,8 +134,7 @@ OPTIMIZER::OPTIMIZER( NODE* aWorld ) :
m_world( aWorld ),
m_collisionKindMask( ITEM::ANY_T ),
m_effortLevel( MERGE_SEGMENTS ),
m_keepPostures( false ),
m_restrictAreaActive( false )
m_keepPostures( false )
{
}
@ -322,6 +321,12 @@ bool PRESERVE_VERTEX_CONSTRAINT::Check ( int aVertex1, int aVertex2, LINE* aOrig
}
bool RESTRICT_VERTEX_RANGE_CONSTRAINT::Check ( int aVertex1, int aVertex2, LINE* aOriginLine, const SHAPE_LINE_CHAIN& aCurrentPath, const SHAPE_LINE_CHAIN& aReplacement )
{
return true;
}
// fixme: integrate into SHAPE_LINE_CHAIN, check corner cases against current PointInside implementation
static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP )
{
@ -605,6 +610,24 @@ bool OPTIMIZER::Optimize( LINE* aLine, LINE* aResult )
bool rv = false;
if ( m_effortLevel & PRESERVE_VERTEX )
{
auto c = new PRESERVE_VERTEX_CONSTRAINT( m_world, m_preservedVertex );
AddConstraint( c );
}
if ( m_effortLevel & RESTRICT_VERTEX_RANGE )
{
auto c = new RESTRICT_VERTEX_RANGE_CONSTRAINT( m_world, m_restrictedVertexRange.first, m_restrictedVertexRange.second );
AddConstraint( c );
}
if ( m_effortLevel & KEEP_TOPOLOGY )
{
auto c = new KEEP_TOPOLOGY_CONSTRAINT( m_world );
AddConstraint( c );
}
if( m_effortLevel & MERGE_SEGMENTS )
rv |= mergeFull( aResult );
@ -1017,18 +1040,6 @@ bool OPTIMIZER::Optimize( LINE* aLine, int aEffortLevel, NODE* aWorld, const VEC
opt.SetEffortLevel( aEffortLevel );
opt.SetCollisionMask( -1 );
if ( aEffortLevel & PRESERVE_VERTEX )
{
auto c = new PRESERVE_VERTEX_CONSTRAINT( aWorld, aV );
opt.AddConstraint( c );
}
if ( aEffortLevel & KEEP_TOPOLOGY )
{
auto c = new KEEP_TOPOLOGY_CONSTRAINT( aWorld );
opt.AddConstraint( c );
}
return opt.Optimize( aLine );
}

View File

@ -102,7 +102,9 @@ public:
MERGE_OBTUSE = 0x04,
FANOUT_CLEANUP = 0x08,
KEEP_TOPOLOGY = 0x10,
PRESERVE_VERTEX = 0x20
PRESERVE_VERTEX = 0x20,
RESTRICT_VERTEX_RANGE = 0x40
};
OPTIMIZER( NODE* aWorld );
@ -131,10 +133,22 @@ public:
}
void SetPreserveVertex( const VECTOR2I& aV )
{
m_preservedVertex = aV;
m_effortLevel |= OPTIMIZER::PRESERVE_VERTEX;
}
void SetRestrictVertexRange( int aStart, int aEnd )
{
m_restrictedVertexRange.first = aStart;
m_restrictedVertexRange.second = aEnd;
m_effortLevel |= OPTIMIZER::RESTRICT_VERTEX_RANGE;
}
void SetRestrictArea( const BOX2I& aArea )
{
m_restrictArea = aArea;
m_restrictAreaActive = true;
}
void ClearConstraints();
@ -195,8 +209,10 @@ private:
int m_effortLevel;
bool m_keepPostures;
VECTOR2I m_preservedVertex;
std::pair<int, int> m_restrictedVertexRange;
BOX2I m_restrictArea;
bool m_restrictAreaActive;
};
class OPT_CONSTRAINT
@ -285,6 +301,22 @@ private:
VECTOR2I m_v;
};
class RESTRICT_VERTEX_RANGE_CONSTRAINT: public OPT_CONSTRAINT
{
public:
RESTRICT_VERTEX_RANGE_CONSTRAINT( NODE* aWorld, int aStart, int aEnd ) :
OPT_CONSTRAINT( aWorld ),
m_start( aStart ),
m_end( aEnd )
{};
virtual bool Check ( int aVertex1, int aVertex2, LINE* aOriginLine, const SHAPE_LINE_CHAIN& aCurrentPath, const SHAPE_LINE_CHAIN& aReplacement ) override;
private:
int m_start;
int m_end;
};
};