router: wip on less intrusive dragged trace optimization
This commit is contained in:
parent
b5fa523a11
commit
9bef95418e
|
@ -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;
|
VECTOR2D lockV;
|
||||||
dragged.ClearLinks();
|
dragged.ClearLinks();
|
||||||
|
@ -329,9 +329,24 @@ void DRAGGER::optimizeAndUpdateDraggedLine( LINE& dragged, const VECTOR2I& aP )
|
||||||
|
|
||||||
if( Settings().GetOptimizeDraggedTrack() )
|
if( Settings().GetOptimizeDraggedTrack() )
|
||||||
{
|
{
|
||||||
OPTIMIZER::Optimize( &dragged,
|
OPTIMIZER optimizer( m_lastNode );
|
||||||
OPTIMIZER::MERGE_SEGMENTS | OPTIMIZER::KEEP_TOPOLOGY | OPTIMIZER::PRESERVE_VERTEX,
|
|
||||||
m_lastNode, lockV );
|
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 );
|
m_lastNode->Add( dragged );
|
||||||
|
@ -405,7 +420,8 @@ bool DRAGGER::dragWalkaround( const VECTOR2I& aP )
|
||||||
if(ok)
|
if(ok)
|
||||||
{
|
{
|
||||||
m_lastNode->Remove( origLine );
|
m_lastNode->Remove( origLine );
|
||||||
optimizeAndUpdateDraggedLine( dragged, aP );
|
SEG dummy;
|
||||||
|
optimizeAndUpdateDraggedLine( dragged, dummy, aP );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,8 @@ private:
|
||||||
bool startDragVia( VIA* aVia );
|
bool startDragVia( VIA* aVia );
|
||||||
void dragViaMarkObstacles( const VIA_HANDLE& aHandle, NODE* aNode, const VECTOR2I& aP );
|
void dragViaMarkObstacles( const VIA_HANDLE& aHandle, NODE* aNode, const VECTOR2I& aP );
|
||||||
void dragViaWalkaround( 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_initialVia;
|
||||||
VIA_HANDLE m_draggedVia;
|
VIA_HANDLE m_draggedVia;
|
||||||
|
|
|
@ -134,8 +134,7 @@ OPTIMIZER::OPTIMIZER( NODE* aWorld ) :
|
||||||
m_world( aWorld ),
|
m_world( aWorld ),
|
||||||
m_collisionKindMask( ITEM::ANY_T ),
|
m_collisionKindMask( ITEM::ANY_T ),
|
||||||
m_effortLevel( MERGE_SEGMENTS ),
|
m_effortLevel( MERGE_SEGMENTS ),
|
||||||
m_keepPostures( false ),
|
m_keepPostures( false )
|
||||||
m_restrictAreaActive( 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
|
// fixme: integrate into SHAPE_LINE_CHAIN, check corner cases against current PointInside implementation
|
||||||
static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP )
|
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;
|
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 )
|
if( m_effortLevel & MERGE_SEGMENTS )
|
||||||
rv |= mergeFull( aResult );
|
rv |= mergeFull( aResult );
|
||||||
|
|
||||||
|
@ -1017,18 +1040,6 @@ bool OPTIMIZER::Optimize( LINE* aLine, int aEffortLevel, NODE* aWorld, const VEC
|
||||||
opt.SetEffortLevel( aEffortLevel );
|
opt.SetEffortLevel( aEffortLevel );
|
||||||
opt.SetCollisionMask( -1 );
|
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 );
|
return opt.Optimize( aLine );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,9 @@ public:
|
||||||
MERGE_OBTUSE = 0x04,
|
MERGE_OBTUSE = 0x04,
|
||||||
FANOUT_CLEANUP = 0x08,
|
FANOUT_CLEANUP = 0x08,
|
||||||
KEEP_TOPOLOGY = 0x10,
|
KEEP_TOPOLOGY = 0x10,
|
||||||
PRESERVE_VERTEX = 0x20
|
PRESERVE_VERTEX = 0x20,
|
||||||
|
RESTRICT_VERTEX_RANGE = 0x40
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
OPTIMIZER( NODE* aWorld );
|
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 )
|
void SetRestrictArea( const BOX2I& aArea )
|
||||||
{
|
{
|
||||||
m_restrictArea = aArea;
|
m_restrictArea = aArea;
|
||||||
m_restrictAreaActive = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearConstraints();
|
void ClearConstraints();
|
||||||
|
@ -195,8 +209,10 @@ private:
|
||||||
int m_effortLevel;
|
int m_effortLevel;
|
||||||
bool m_keepPostures;
|
bool m_keepPostures;
|
||||||
|
|
||||||
|
|
||||||
|
VECTOR2I m_preservedVertex;
|
||||||
|
std::pair<int, int> m_restrictedVertexRange;
|
||||||
BOX2I m_restrictArea;
|
BOX2I m_restrictArea;
|
||||||
bool m_restrictAreaActive;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class OPT_CONSTRAINT
|
class OPT_CONSTRAINT
|
||||||
|
@ -285,6 +301,22 @@ private:
|
||||||
VECTOR2I m_v;
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue