TransformTextShapeWithClearanceToPolygon() add optimization for 3D viewer.
This function convert a text shape to a set of polygons for the 3D viewer. Texts shapes are a bit special and can generate a lot of small overlapping polygons. These polygons are now merged before being added to the list of polygons handled by the 3D viewer draw functions. Locally merging polygons is usually not efficient but in this case it can speedup the 3D viewer (up to 10x). Mainly noticeable for silkscreen layers when the "copper" thickness is shown
This commit is contained in:
parent
1d87ed6454
commit
f3bb34779a
|
@ -458,26 +458,36 @@ void FP_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerB
|
||||||
KIFONT::FONT* font = GetDrawFont();
|
KIFONT::FONT* font = GetDrawFont();
|
||||||
int penWidth = GetEffectiveTextPenWidth();
|
int penWidth = GetEffectiveTextPenWidth();
|
||||||
|
|
||||||
|
// Note: this function is mainly used in 3D viewer.
|
||||||
|
// the polygonal shape of a text can have many basic shapes,
|
||||||
|
// so combining these shapes can be very useful to create a final shape
|
||||||
|
// swith a lot less vertices to speedup calculations using this final shape
|
||||||
|
// Simplify shapes is not usually always efficient, but in this case it is.
|
||||||
|
SHAPE_POLY_SET buffer;
|
||||||
|
|
||||||
CALLBACK_GAL callback_gal( empty_opts,
|
CALLBACK_GAL callback_gal( empty_opts,
|
||||||
// Stroke callback
|
// Stroke callback
|
||||||
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
||||||
{
|
{
|
||||||
TransformOvalToPolygon( aCornerBuffer, aPt1, aPt2, penWidth+ ( 2 * aClearance ),
|
TransformOvalToPolygon( buffer, aPt1, aPt2, penWidth+ ( 2 * aClearance ),
|
||||||
aError, ERROR_INSIDE );
|
aError, ERROR_INSIDE );
|
||||||
},
|
},
|
||||||
// Triangulation callback
|
// Triangulation callback
|
||||||
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
||||||
{
|
{
|
||||||
aCornerBuffer.NewOutline();
|
buffer.NewOutline();
|
||||||
|
|
||||||
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
||||||
aCornerBuffer.Append( point.x, point.y );
|
buffer.Append( point.x, point.y );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
TEXT_ATTRIBUTES attrs = GetAttributes();
|
TEXT_ATTRIBUTES attrs = GetAttributes();
|
||||||
attrs.m_Angle = GetDrawRotation();
|
attrs.m_Angle = GetDrawRotation();
|
||||||
|
|
||||||
font->Draw( &callback_gal, GetShownText(), GetTextPos(), attrs );
|
font->Draw( &callback_gal, GetShownText(), GetTextPos(), attrs );
|
||||||
|
|
||||||
|
buffer.Simplify( SHAPE_POLY_SET::PM_FAST );
|
||||||
|
aCornerBuffer.Append( buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -448,26 +448,36 @@ void FP_TEXTBOX::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCorn
|
||||||
KIFONT::FONT* font = GetDrawFont();
|
KIFONT::FONT* font = GetDrawFont();
|
||||||
int penWidth = GetEffectiveTextPenWidth();
|
int penWidth = GetEffectiveTextPenWidth();
|
||||||
|
|
||||||
|
// Note: this function is mainly used in 3D viewer.
|
||||||
|
// the polygonal shape of a text can have many basic shapes,
|
||||||
|
// so combining these shapes can be very useful to create a final shape
|
||||||
|
// swith a lot less vertices to speedup calculations using this final shape
|
||||||
|
// Simplify shapes is not usually always efficient, but in this case it is.
|
||||||
|
SHAPE_POLY_SET buffer;
|
||||||
|
|
||||||
CALLBACK_GAL callback_gal( empty_opts,
|
CALLBACK_GAL callback_gal( empty_opts,
|
||||||
// Stroke callback
|
// Stroke callback
|
||||||
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
||||||
{
|
{
|
||||||
TransformOvalToPolygon( aCornerBuffer, aPt1, aPt2, penWidth + ( 2 * aClearance ),
|
TransformOvalToPolygon( buffer, aPt1, aPt2, penWidth + ( 2 * aClearance ),
|
||||||
aError, ERROR_INSIDE );
|
aError, ERROR_INSIDE );
|
||||||
},
|
},
|
||||||
// Triangulation callback
|
// Triangulation callback
|
||||||
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
||||||
{
|
{
|
||||||
aCornerBuffer.NewOutline();
|
buffer.NewOutline();
|
||||||
|
|
||||||
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
||||||
aCornerBuffer.Append( point.x, point.y );
|
buffer.Append( point.x, point.y );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
TEXT_ATTRIBUTES attrs = GetAttributes();
|
TEXT_ATTRIBUTES attrs = GetAttributes();
|
||||||
attrs.m_Angle = GetDrawRotation();
|
attrs.m_Angle = GetDrawRotation();
|
||||||
|
|
||||||
font->Draw( &callback_gal, GetShownText(), GetDrawPos(), attrs );
|
font->Draw( &callback_gal, GetShownText(), GetDrawPos(), attrs );
|
||||||
|
|
||||||
|
buffer.Simplify( SHAPE_POLY_SET::PM_FAST );
|
||||||
|
aCornerBuffer.Append( buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -292,6 +292,13 @@ void PCB_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCorner
|
||||||
KIFONT::FONT* font = GetDrawFont();
|
KIFONT::FONT* font = GetDrawFont();
|
||||||
int penWidth = GetEffectiveTextPenWidth();
|
int penWidth = GetEffectiveTextPenWidth();
|
||||||
|
|
||||||
|
// Note: this function is mainly used in 3D viewer.
|
||||||
|
// the polygonal shape of a text can have many basic shapes,
|
||||||
|
// so combining these shapes can be very useful to create a final shape
|
||||||
|
// swith a lot less vertices to speedup calculations using this final shape
|
||||||
|
// Simplify shapes is not usually always efficient, but in this case it is.
|
||||||
|
SHAPE_POLY_SET buffer;
|
||||||
|
|
||||||
CALLBACK_GAL callback_gal( empty_opts,
|
CALLBACK_GAL callback_gal( empty_opts,
|
||||||
// Stroke callback
|
// Stroke callback
|
||||||
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
||||||
|
@ -302,13 +309,16 @@ void PCB_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCorner
|
||||||
// Triangulation callback
|
// Triangulation callback
|
||||||
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
||||||
{
|
{
|
||||||
aCornerBuffer.NewOutline();
|
buffer.NewOutline();
|
||||||
|
|
||||||
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
||||||
aCornerBuffer.Append( point.x, point.y );
|
buffer.Append( point.x, point.y );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
font->Draw( &callback_gal, GetShownText(), GetTextPos(), GetAttributes() );
|
font->Draw( &callback_gal, GetShownText(), GetTextPos(), GetAttributes() );
|
||||||
|
|
||||||
|
buffer.Simplify( SHAPE_POLY_SET::PM_FAST );
|
||||||
|
aCornerBuffer.Append( buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -455,23 +455,33 @@ void PCB_TEXTBOX::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCor
|
||||||
KIFONT::FONT* font = GetDrawFont();
|
KIFONT::FONT* font = GetDrawFont();
|
||||||
int penWidth = GetEffectiveTextPenWidth();
|
int penWidth = GetEffectiveTextPenWidth();
|
||||||
|
|
||||||
|
// Note: this function is mainly used in 3D viewer.
|
||||||
|
// the polygonal shape of a text can have many basic shapes,
|
||||||
|
// so combining these shapes can be very useful to create a final shape
|
||||||
|
// swith a lot less vertices to speedup calculations using this final shape
|
||||||
|
// Simplify shapes is not usually always efficient, but in this case it is.
|
||||||
|
SHAPE_POLY_SET buffer;
|
||||||
|
|
||||||
CALLBACK_GAL callback_gal( empty_opts,
|
CALLBACK_GAL callback_gal( empty_opts,
|
||||||
// Stroke callback
|
// Stroke callback
|
||||||
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
||||||
{
|
{
|
||||||
TransformOvalToPolygon( aCornerBuffer, aPt1, aPt2, penWidth+ ( 2 * aClearance ),
|
TransformOvalToPolygon( buffer, aPt1, aPt2, penWidth+ ( 2 * aClearance ),
|
||||||
aError, ERROR_INSIDE );
|
aError, ERROR_INSIDE );
|
||||||
},
|
},
|
||||||
// Triangulation callback
|
// Triangulation callback
|
||||||
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
||||||
{
|
{
|
||||||
aCornerBuffer.NewOutline();
|
buffer.NewOutline();
|
||||||
|
|
||||||
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
|
||||||
aCornerBuffer.Append( point.x, point.y );
|
buffer.Append( point.x, point.y );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
font->Draw( &callback_gal, GetShownText(), GetDrawPos(), GetAttributes() );
|
font->Draw( &callback_gal, GetShownText(), GetDrawPos(), GetAttributes() );
|
||||||
|
|
||||||
|
buffer.Simplify( SHAPE_POLY_SET::PM_FAST );
|
||||||
|
aCornerBuffer.Append( buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue