//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (!(FGeometryIn.IsChanged || FGeometryIn2.IsChanged)) { return; } FGeometryOut.SliceCount = 0; for (int i = 0; i < SpreadMax; i++) { try { PathGeometry geom = PathGeometry.Combine(FGeometryIn[i], FGeometryIn2[i], GeometryCombineMode.Intersect, null); // no intersection: if (geom.Figures == null || geom.Figures.Count == 0) { // FGeometryOut.Add(new PathGeometry()); } else { for (int j = 0; j < geom.Figures.Count; j++) { PathGeometry g = new PathGeometry(); g.Figures = new PathFigureCollection(); g.Figures.Add(geom.Figures[j]); FGeometryOut.Add(g); } } } catch (Exception e) { FLogger.Log(LogType.Error, e.ToString()); FGeometryOut[i] = new PathGeometry(); } } }
public IGeometry Combine(CombineMode mode, IGeometry other) { var otherImplementation = other.import(); var combined = Path.Geometry( Geometry.Factory, sink => Geometry.Combine(otherImplementation, mode.import(), sink)); return(new GeometryImplementation(combined)); }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (!FGeometryIn.IsChanged) { return; } FGeometryOut.SliceCount = FGeometryIn.SliceCount; for (int i = 0; i < FGeometryIn.SliceCount; i++) { var geom = new PathGeometry(); for (int j = 0; j < FGeometryIn[i].SliceCount; j++) { try { geom = PathGeometry.Combine(geom, FGeometryIn[i][j], GeometryCombineMode.Union, null); if (geom.Figures == null || geom.Figures.Count == 0) { FGeometryOut[i] = new PathGeometry(); } var g = new PathGeometry(); for (int k = 0; k < geom.Figures.Count; k++) { g.Figures = new PathFigureCollection(); g.Figures.Add(geom.Figures[k]); // FLogger.Log(LogType.Debug, "uni count" + i.ToString() + " " +j.ToString()); } FGeometryOut[i] = g; } catch (Exception e) { FLogger.Log(LogType.Error, e.ToString()); } } } }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (!(FGeometryIn.IsChanged || FGeometryIn2.IsChanged)) { return; } FGeometryOut.SliceCount = 0; for (int i = 0; i < SpreadMax; i++) { try { PathGeometry geom = PathGeometry.Combine(FGeometryIn[i], FGeometryIn2[i], GeometryCombineMode.Exclude, null); for (int j = 0; j < geom.Figures.Count; j++) { PathGeometry g = new PathGeometry(); g.Figures = new PathFigureCollection(); g.Figures.Add(geom.Figures[j]); FGeometryOut.Add(g); } } catch (Exception e) { } } }
static void Main(string[] args) { List <string> charLines = new List <string>(); DirectoryInfo d = new DirectoryInfo(@"D:\MachineLearning\Document Layout Analysis\Fonts"); List <FileInfo> Files = d.GetFiles("*.ttc").ToList(); // ttf, fon, ttc // 'fon' doesn't work Files.AddRange(d.GetFiles("*.ttf")); foreach (var fontFile in Files) { Uri uri = new Uri(fontFile.FullName); GlyphTypeface glyphTypeface = new GlyphTypeface(uri); foreach (var unicodePair in unicodeChars) { //ScatterplotView view = new ScatterplotView(); //view.Dock = System.Windows.Forms.DockStyle.Fill; //view.LinesVisible = true; int indexUnicode = unicodePair.Key; char unicode = unicodePair.Value; if (!glyphTypeface.CharacterToGlyphMap.ContainsKey(indexUnicode)) { continue; } var geometry = glyphTypeface.GetGlyphOutline( glyphTypeface.CharacterToGlyphMap[indexUnicode], 100, 1); var boundingBox = geometry.Bounds; var stepX = boundingBox.Width / 8; var stepY = boundingBox.Height / 8; var blockArea = stepX * stepY; List <int> data = new List <int>(); var path = geometry.GetFlattenedPathGeometry(); for (int j = 0; j < 8; j++) { for (int i = 0; i < 8; i++) { RectangleGeometry block = new RectangleGeometry( new System.Windows.Rect( new System.Windows.Point(boundingBox.X + i * stepX, boundingBox.Y + j * stepY), new System.Windows.Point(boundingBox.X + (i + 1) * stepX, boundingBox.Y + (j + 1) * stepY))); PathGeometry intersectionGeometry = PathGeometry.Combine(block, path, GeometryCombineMode.Intersect, null); var area = Math.Round(intersectionGeometry.GetArea() / blockArea * 16, 0); data.Add((int)area); } } var dataStr = string.Join(",", data); dataStr += "," + indexUnicode.ToString(); charLines.Add(dataStr); /*var figures = path.Figures.ToList(); * * var segments = figures.Select(f => f.Segments.ToList()).ToList(); * * foreach (var group in segments) * { * foreach (var segment in group) * { * if (segment is PolyLineSegment polyLineSegment) * { * var points = polyLineSegment.Points.ToList(); * var x = points.Select(p => (p.X / (boundingBox.X + boundingBox.Width)) * 8.0).ToArray(); * var y = points.Select(p => -(p.Y / (boundingBox.Height)) * 8.0).ToArray(); * * view.Graph.GraphPane.AddCurve(unicode.ToString(), * x, y, * System.Drawing.Color.Black); * * } * else if (segment is ArcSegment arcSegment) * { * throw new NotImplementedException(); * } * else if (segment is BezierSegment bezierSegment) * { * throw new NotImplementedException(); * } * else if (segment is LineSegment lineSegment) * { * throw new NotImplementedException(); * } * else if (segment is PolyBezierSegment polyBezierSegment) * { * throw new NotImplementedException(); * } * else if (segment is PolyQuadraticBezierSegment polyQuadraticBezierSegment) * { * throw new NotImplementedException(); * } * else if (segment is QuadraticBezierSegment quadraticBezierSegment) * { * throw new NotImplementedException(); * } * else * { * throw new ArgumentException(segment.GetType().ToString()); * } * } * }*/ //view.Graph.GraphPane.AxisChange(); //var f1 = new System.Windows.Forms.Form(); //f1.Width = 1000; //f1.Height = 1000; //f1.Controls.Add(view); //f1.ShowDialog(); } } File.WriteAllLines(@"D:\MachineLearning\Document Layout Analysis\Fonts\chars-train.csv", charLines); }