private void CreateMeshAssets() { Directory.CreateDirectory(meshPath); List <SubObject> subObjects = model.subObjects; for (int i = 0; i < subObjects.Count; i++) { float progress = (i / (float)subObjects.Count); string meshCount = "(" + (i + 1) + "/" + subObjects.Count + ")"; ShowProgress("Creating mesh " + meshCount, progress); KeyValuePair <Mesh, int[]> pair = new GeometryParser(subObjects[i].bspData).GetMeshAndTextureIndices(); Mesh mesh = pair.Key; subObjects[i].mesh = pair.Key; subObjects[i].textureIndices = pair.Value; string assetPath = GetMeshPath(subObjects[i].submodelName); Mesh existing = AssetDatabase.LoadAssetAtPath <Mesh>(assetPath); if (!(existing != null && existing.triangles.Length == mesh.triangles.Length && existing.vertexCount == mesh.vertexCount && existing.subMeshCount == mesh.subMeshCount && existing.uv.Length == mesh.uv.Length && existing.normals.Length == mesh.normals.Length)) { AssetDatabase.CreateAsset(subObjects[i].mesh, assetPath); } } AssetDatabase.SaveAssets(); }
/// <summary> /// Attempts to convert to a Geometry from the given object. /// </summary> /// <returns> /// The Geometry which was constructed. /// </returns> /// <exception cref="NotSupportedException"> /// A NotSupportedException is thrown if the example object is null or is not a valid type /// which can be converted to a Geometry. /// </exception> /// <param name="context"> The ITypeDescriptorContext for this call. </param> /// <param name="culture"> The requested CultureInfo. Note that conversion uses "en-US" rather than this parameter. </param> /// <param name="value"> The object to convert to an instance of Geometry. </param> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string source) { return(GeometryParser.ParseGeometry(source)); } throw GetConvertFromException(value); }
public void QuadGridCellToPolygonPointListTest4() { var parser = new GeometryParser(2); List <(int, int)> pts = parser.QuadGridCellToPolygonPointList(2, 3, Direction.Left); Assert.IsTrue(pts.Contains((4, 6))); Assert.IsTrue(pts.Contains((4, 8))); Assert.IsTrue(pts.Contains((5, 7))); }
public override ShapeViewModel DeserializeNode(Telerik.Windows.Diagrams.Core.IShape shape, Telerik.Windows.Diagrams.Core.SerializationInfo info) { ShapeViewModel model = new ShapeViewModel() { Geometry = GeometryParser.GetGeometry(info["MyGeometry"].ToString()) }; return(model); }
public override ShapeViewModel DeserializeNode(IShape shape, SerializationInfo info) { ShapeViewModel model = new ShapeViewModel() { Geometry = GeometryParser.GetGeometry(info["MyGeometry"].ToString()) }; return(model); }
private void RadDiagram_ShapeDeserialized(object sender, ShapeSerializationRoutedEventArgs e) { var shape = e.Shape as RadDiagramShape; if (shape != null) { shape.Geometry = GeometryParser.GetGeometry(e.SerializationInfo["MyGeometry"].ToString()); shape.Content = e.SerializationInfo["DataContent"].ToString(); } }
/// <summary> /// Constructor /// </summary> public ShapeParser(CssStyleCascade cssStyleCascade, BrushParser brushParser, GeometryParser geometryParser, Clipping clipping) { this.cssStyleCascade = cssStyleCascade; this.brushParser = brushParser; this.geometryParser = geometryParser; this.clipping = clipping; }
public void ToPolygonPointList_TriangleUnit_Test3() { var parser = new GeometryParser(2); var tri = new Pattern.Core.System.DiagridSystem.TriangleUnit(1, 1, 2, Direction.Left); List <(int, int)> pts = parser.ToPolygonPointList(tri); Assert.IsTrue(pts.Contains((1, 1).Multiply(2))); Assert.IsTrue(pts.Contains((0, 0).Multiply(2))); Assert.IsTrue(pts.Contains((-1, 1).Multiply(2))); }
public void AnotherGeometryParserTest() { var input = new List <uint> { 9, 7796, 3462 }; var output = GeometryParser.ParseGeometry(input, Tile.GeomType.Point, 0, 0, 256 / 4096); Assert.IsTrue(output.ToList().Count == 1); Assert.IsTrue(output.ToList()[0].Points[0].X == 3898); Assert.IsTrue(output.ToList()[0].Points[0].Y == 1731); }
public void ToPolygonPointList_DiagridUnit_Test1() { var parser = new GeometryParser(2); var dia = new Pattern.Core.System.DiagridSystem.DiagridUnit(1, 1, 2); List <(int, int)> pts = parser.ToPolygonPointList(dia); Assert.IsTrue(pts.Contains((1, 1).Multiply(2))); Assert.IsTrue(pts.Contains((3, 1).Multiply(2))); Assert.IsTrue(pts.Contains((2, 2).Multiply(2))); Assert.IsTrue(pts.Contains((2, 0).Multiply(2))); }
public void ToPolygonPointList_SquareUnit_Test1() { var parser = new GeometryParser(2); var tri = new Pattern.Core.System.SquareGridSystem.SquareUnit(1, 1, 2); List <(int, int)> pts = parser.ToPolygonPointList(tri); Assert.IsTrue(pts.Contains((2, 2))); Assert.IsTrue(pts.Contains((6, 2))); Assert.IsTrue(pts.Contains((6, 6))); Assert.IsTrue(pts.Contains((2, 6))); }
public IPath CreatePath(string data) { Path result = new Path(factory); using (var ctx = result.Open()) { GeometryParser parser = new GeometryParser(result, ctx); parser.Parse(data); return(result); } }
/// <summary> /// Parse a single SVG shape /// </summary> public GraphicVisual Parse(XElement shape, XNamespace svgNamespace, Matrix currentTransformationMatrix, CssStyleCascade cssStyleCascade, Dictionary <string, XElement> globalDefinitions) { GraphicVisual graphicVisual = null; cssStyleCascade.PushStyles(shape); var transform = cssStyleCascade.GetPropertyFromTop("transform"); if (!string.IsNullOrEmpty(transform)) { var transformMatrix = TransformMatrixParser.GetTransformMatrix(transform); currentTransformationMatrix = transformMatrix * currentTransformationMatrix; } var geometry = GeometryParser.Parse(shape, currentTransformationMatrix); if (geometry != null) { var graphicPath = new GraphicPath(); graphicPath.Geometry = geometry; graphicVisual = graphicPath; this.svgNamespace = svgNamespace; this.globalDefinitions = globalDefinitions; this.currentTransformationMatrix = currentTransformationMatrix; this.cssStyleCascade = cssStyleCascade; SetFillAndStroke(shape, graphicPath); if (Clipping.IsClipPathSet(cssStyleCascade)) { // shapes don't support clipping, create a group around it var group = new GraphicGroup(); graphicVisual = group; group.Childreen.Add(graphicPath); Clipping.SetClipPath(group, currentTransformationMatrix, cssStyleCascade, globalDefinitions); } cssStyleCascade.Pop(); } return(graphicVisual); }
/// <summary> /// Parse an SVG given as XElement root /// </summary> public GraphicVisual ParseRoot(XElement root) { var nameSpaceAttributes = root.Attributes().Where(a => a.IsNamespaceDeclaration); var defaultNamespaceAttribute = root.Attributes().Where(a => a.IsNamespaceDeclaration && a.Name.Namespace == XNamespace.None).FirstOrDefault(); XNamespace defaultNamespace = defaultNamespaceAttribute.Value; Matrix currentTransformationMatrix = Matrix.Identity; cssStyleCascade = new CssStyleCascade(root); var svgViewBox = new SvgViewBox { ViewBox = new Rect(0, 0, 100, 100), Align = "none", Slice = "meet" }; cssStyleCascade.PushViewBox(svgViewBox); doubleParser = new DoubleParser(cssStyleCascade); ReadGlobalDefinitions(root); var brushParser = new BrushParser(defaultNamespace, cssStyleCascade, globalDefinitions, doubleParser); var geometryParser = new GeometryParser(doubleParser); var geometryTextParser = new GeometryTextParser(cssStyleCascade, doubleParser); clipping = new Clipping(cssStyleCascade, globalDefinitions, geometryParser, geometryTextParser); shapeParser = new ShapeParser(cssStyleCascade, brushParser, geometryParser, clipping); textParser = new TextParser(cssStyleCascade, doubleParser, brushParser, clipping); GraphicVisual visual = ParseSVG(root, currentTransformationMatrix, true); visual = OptimizeVisual.Optimize(visual); return(visual); }
internal static object INTERNAL_ConvertFromString(string pathAsString) { return(GeometryParser.ParseGeometry(pathAsString)); }
private static void ExportGeometry(FixedContentEditor editor, FixedContentEditor filledEditor, Geometry geometry, bool isConnection = false) { // We need two editors because there might be filled and not filled figures. #if WPF var pathGeometry = geometry as PathGeometry; #else var pathGeometry = GeometryParser.GetGeometry(geometry.ToString()) as PathGeometry; #endif if (pathGeometry != null) { var path = new G.PathGeometry(); var filledPath = new G.PathGeometry(); for (int i = 0; i < pathGeometry.Figures.Count; i++) { var figure = pathGeometry.Figures[i]; var newFigure = new G.PathFigure(); newFigure.StartPoint = figure.StartPoint; newFigure.IsClosed = figure.IsClosed; foreach (var segment in figure.Segments) { var arc = segment as ArcSegment; if (arc != null) { var newS = new G.ArcSegment(); newS.Point = arc.Point; newS.RadiusX = arc.Size.Width; newS.RadiusY = arc.Size.Height; newS.RotationAngle = arc.RotationAngle; // why new enum ? if (arc.SweepDirection == SweepDirection.Clockwise) { newS.SweepDirection = G.SweepDirection.Clockwise; } else { newS.SweepDirection = G.SweepDirection.Counterclockwise; } newS.IsLargeArc = arc.IsLargeArc; newFigure.Segments.Add(newS); continue; } var bezier = segment as BezierSegment; if (bezier != null) { var newS = new G.BezierSegment(); newS.Point1 = bezier.Point1; newS.Point2 = bezier.Point2; newS.Point3 = bezier.Point3; newFigure.StartPoint = newFigure.StartPoint; newFigure.Segments.Add(newS); continue; } var polyLine = segment as PolyLineSegment; if (polyLine != null) { foreach (var point in polyLine.Points) { var newS = new G.LineSegment(); newS.Point = point; newFigure.Segments.Add(newS); } continue; } var line = segment as LineSegment; if (line != null) { var newS = new G.LineSegment(); newS.Point = line.Point; newFigure.Segments.Add(newS); continue; } var quadraticBezier = segment as QuadraticBezierSegment; if (quadraticBezier != null) { var newS = new G.QuadraticBezierSegment(); newS.Point1 = quadraticBezier.Point1; newS.Point2 = quadraticBezier.Point2; newFigure.Segments.Add(newS); continue; } } #if SILVERLIGHT if (isConnection) { var realGeometry = geometry as PathGeometry; if (realGeometry != null && realGeometry.Figures.Count > i) { if (realGeometry.Figures[i].IsFilled) { filledPath.Figures.Add(newFigure); } else { path.Figures.Add(newFigure); } continue; } } #endif if (figure.IsFilled) { filledPath.Figures.Add(newFigure); } else { path.Figures.Add(newFigure); } } // why new enum ? if (pathGeometry.FillRule == FillRule.EvenOdd) { path.FillRule = G.FillRule.EvenOdd; filledPath.FillRule = G.FillRule.EvenOdd; } else { path.FillRule = G.FillRule.Nonzero; filledPath.FillRule = G.FillRule.Nonzero; } if (filledPath.Figures.Count > 0) { filledEditor.DrawPath(filledPath); } if (path.Figures.Count > 0) { editor.DrawPath(path); } } }
/// <summary> /// 큰 diagridUnit에 pixel이 들어갈 수록 높은 점수를 받는다. /// </summary> /// <param name="grid"></param> /// <param name="intension"></param> public double EstimateInclusionScore(RectangleFrameDiagrid grid, IntensionLayer intension, GeometryParser parser) { var handler = new GeoHandler(); List <List <(int, int)> > all = parser.ToPolygonPointList(grid); double width = all.SelectMany(n => n).Max(n => n.Item1); double height = all.SelectMany(n => n).Max(n => n.Item2); List <Pixel> pixels = intension.GetPixels(width, height); var diagridUnits = grid.DiagridUnits; var inspections = diagridUnits .Select(n => new { pointList = parser.ToPolygonPointList(n), mag = n.Magnification }) .Select(n => new { pts = n.pointList.Select(k => new Point(k.Item1, k.Item2)), mag = n.mag }) .Select(n => new { polygon = new Polygon(n.pts), mag = n.mag }) .ToList(); double total = 0; foreach (var inspect in inspections) { var inclusions = pixels .Where(n => handler.PointInPolygon(new Point(n.PixelCenterX, n.PixelCenterY), inspect.polygon) == PointPositionWithPolygon.Inside) .ToList(); double score = inclusions .Select(n => (int)n.Val) .Sum(); double weightedScore = score * inspect.mag; total += weightedScore; } return(total); }