1- using GerberLibrary . Core ;
1+ using ArtWork ;
2+ using GerberLibrary . Core ;
3+ using GlmNet ;
24using System ;
35using System . Collections . Generic ;
46using System . Drawing ;
1012
1113namespace Artwork
1214{
15+ using Path = List < ClipperLib . IntPoint > ;
16+ using Paths = List < List < ClipperLib . IntPoint > > ;
17+
1318 public class SolidQuadTreeItem : QuadTreeItem
1419 {
1520 int _x ;
@@ -345,17 +350,16 @@ public void DrawTiling(Settings S, Bitmap MaskBitmap, Graphics G, Color FGColor,
345350 if ( S . Mode == Settings . ArtMode . Tiling )
346351 {
347352 if ( Clear ) G . Clear ( BG ) ;
348- PointF [ ] ThePoints = new PointF [ 3 ] { new PointF ( ) , new PointF ( ) , new PointF ( ) } ;
349353 Pen P = new Pen ( FG , linewidth ) ;
350354 for ( int j = 0 ; j < SubDivPoly . Count ; j ++ )
351355 {
352356 var a = SubDivPoly [ j ] ;
353- for ( int i = 0 ; i < 3 ; i ++ )
357+ PointF [ ] ThePoints = new PointF [ a . Vertices . Count ] ;
358+ for ( int i = 0 ; i < a . Vertices . Count ; i ++ )
354359 {
355- ThePoints [ i ] . X = ( float ) a . Vertices [ i ] . x ;
356- ThePoints [ i ] . Y = ( float ) a . Vertices [ i ] . y ;
360+ ThePoints [ i ] = new PointF ( ( float ) a . Vertices [ i ] . x , ( float ) a . Vertices [ i ] . y ) ;
357361 }
358- G . DrawPolygon ( P , ThePoints ) ;
362+ G . DrawPolygon ( P , ThePoints ) ;
359363 }
360364 }
361365 }
@@ -521,7 +525,7 @@ public int BuildStuff(Bitmap Mask, Settings TheSettings)
521525 }
522526 }
523527 }
524-
528+
525529 Delaunay . Build ( ArtTree , TheSettings . DegreesOff ) ;
526530
527531 var Elapsed = DateTime . Now - rR ;
@@ -565,7 +569,7 @@ public int BuildStuff(Bitmap Mask, Settings TheSettings)
565569 foreach ( var A in SubDivPoly )
566570 {
567571 var M = A . Mid ( ) ;
568- float scaler = 1.0f - ( ( float ) ( M . x - offs ) / width ) * TheSettings . xscalesmallerlevel * 0.01f ;
572+ float scaler = 1.0f - ( ( float ) ( M . x - offs ) / width ) * TheSettings . xscalesmallerlevel * 0.01f ;
569573 //scaler = Math.Max(0, Math.Min(1.0f, scaler));
570574 A . ScaleDown ( TheSettings . scalingMode , scaler ) ;
571575 }
@@ -591,18 +595,80 @@ public int BuildStuff(Bitmap Mask, Settings TheSettings)
591595 }
592596 foreach ( var A in SubDivPoly )
593597 {
594-
598+
595599 if ( A . depth - TheSettings . scalesmallerlevel <= 1 )
596600 {
597601
598602 }
599603 else
600604 {
601605 A . ScaleDown ( TheSettings . scalingMode , ( 1 + scaler * ( 1.0f / ( A . depth - TheSettings . scalesmallerlevel ) ) ) ) ;
602-
606+
603607 }
604608 }
605609 }
610+ if ( TheSettings . distanceToMaskScale != 0 )
611+ {
612+ float scaler = Math . Abs ( TheSettings . distanceToMaskScale ) ;
613+ if ( TheSettings . distanceToMaskScale > 0 )
614+ {
615+ scaler = scaler / 10.0f ;
616+ }
617+ else
618+ {
619+ scaler = - scaler / 10.0f ;
620+ }
621+
622+
623+ float aThresholdLevel = TheSettings . Threshold * 0.01f ;
624+
625+ foreach ( var A in SubDivPoly )
626+ {
627+
628+ var m = A . Mid ( ) ;
629+ float sum = GetPixelSum ( m , Mask , TheSettings . distanceToMaskRange , aThresholdLevel , TheSettings . InvertSource ) ;
630+ //if (sum > 1) sum = 1;
631+ A . ScaleDown ( TheSettings . scalingMode , ( scaler * sum ) ) ;
632+
633+
634+ }
635+ }
636+
637+
638+ if ( TheSettings . MarcelPlating )
639+ {
640+ List < Tiling . Polygon > MarcelShapes = new List < Tiling . Polygon > ( ) ;
641+ foreach ( var A in SubDivPoly )
642+ {
643+
644+
645+ MarcelShape MS = new MarcelShape ( ) ;
646+ MarcelShape MS2 = new MarcelShape ( ) ;
647+
648+ foreach ( var v in A . Vertices )
649+ {
650+ MS2 . Vertices . Add ( new ClipperLib . IntPoint ( ( long ) ( ( v . x + 1000 ) * 1000 ) , ( long ) ( ( v . y + 1000 ) * 1000 ) ) ) ;
651+ }
652+
653+ MS . ShrinkFromShape ( MS2 . Vertices , TheSettings . Gap / 2 + TheSettings . Rounding / 2 ) ;
654+ Paths Ps = new Paths ( ) ;
655+
656+ Ps . AddRange ( MS . BuildOutlines ( TheSettings . Rounding / 2.0f ) ) ;
657+ if ( TheSettings . BallRadius > 0 ) Ps . AddRange ( MS . BuildHoles ( TheSettings . BallRadius ) ) ;
658+
659+ foreach ( var p in Ps )
660+ {
661+ Tiling . Polygon Poly = new Tiling . Polygon ( ) ;
662+ Poly . Vertices . AddRange ( from a in p select new vec2 ( ( a . X ) * 0.001f - 1000 , ( a . Y ) * 0.001f - 1000 ) ) ;
663+ MarcelShapes . Add ( Poly ) ;
664+ }
665+
666+
667+ }
668+ SubDivPoly . Clear ( ) ;
669+ SubDivPoly = MarcelShapes ;
670+ }
671+
606672 var Elapsed = DateTime . Now - rR ;
607673 return ( int ) Elapsed . TotalMilliseconds ;
608674 }
@@ -611,6 +677,58 @@ public int BuildStuff(Bitmap Mask, Settings TheSettings)
611677 return 0 ;
612678 }
613679
680+
681+
682+ private float GetPixelSum ( vec2 m , Bitmap mask , float distanceToMaskRange , float ThresholdLevel , bool invert )
683+ {
684+ float sum = 0 ;
685+ if ( distanceToMaskRange == 0 ) distanceToMaskRange = 0.001f ;
686+ float wrange = distanceToMaskRange * mask . Width * 0.5f ;
687+ float hrange = distanceToMaskRange * mask . Width * 0.5f ;
688+ float total = 0 ;
689+ float [ ] cp = new float [ 40 ] ;
690+ float [ ] sp = new float [ 40 ] ;
691+ for ( int p = 0 ; p < 40 ; p ++ )
692+
693+ {
694+ double P = ( p * Math . PI * 2 ) / 40.0f ;
695+ sp [ p ] = ( float ) Math . Sin ( P ) * wrange ;
696+ cp [ p ] = ( float ) Math . Cos ( P ) * wrange ;
697+ }
698+
699+ for ( int ring = 1 ; ring < 10 ; ring ++ )
700+ {
701+ float RW = ring / 10.0f ;
702+ for ( int p = 0 ; p < 40 ; p ++ )
703+
704+ {
705+ int x = ( int ) ( cp [ p ] * RW + m . x ) ;
706+ int y = ( int ) ( sp [ p ] * RW + m . y ) ;
707+ total ++ ;
708+ if ( x >= 0 && x < mask . Width )
709+ {
710+ if ( y >= 0 && y < mask . Height )
711+ {
712+ var C = mask . GetPixel ( x , y ) ;
713+ bool doit = false ;
714+ if ( invert )
715+ {
716+ doit = C . GetBrightness ( ) > ThresholdLevel ;
717+ }
718+ else
719+ {
720+ doit = C . GetBrightness ( ) < ThresholdLevel ;
721+ }
722+ if ( doit ) sum ++ ;
723+
724+ }
725+ }
726+ }
727+
728+ }
729+
730+ return 1000 * sum / total ;
731+ }
614732 }
615733
616734}
0 commit comments