private void DelaunayRefine(int scenario) { var sw = new Stopwatch(); sw.Start(); Random rng = new Random(); BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0); int size = 50; Geometry.Vector[] points; if (scenario == 1) { points = box.RandomPointsInside(rng, size); } else if (scenario == 2) { points = new Geometry.Vector[] { new Geometry.Vector(10, -9.5), new Geometry.Vector(0, -9.5), new Geometry.Vector(2, -0.5), new Geometry.Vector(8, -0.5) //new Geometry.Vector(4.5,-0.5), //new Geometry.Vector(5.5,-0.5) }; } else { points = new Geometry.Vector[] { new Geometry.Vector(10, -6), new Geometry.Vector(10, -2), new Geometry.Vector(0, -6), //new Geometry.Vector(0, -6) }; } VertexCollection verts = new VertexCollection(points); MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts); faces.Quadrangulate(); faces = faces.Refine(0.5); //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces); //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries(); CurveCollection edges = faces.ExtractFaceBoundaries(); VertexGeometryCollection geometry = new VertexGeometryCollection(); foreach (var edge in edges) { var region = new PlanarRegion(edge); geometry.Add(region); region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128)); geometry.Add(edge); edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0)); } geometry.Add(new Cloud(verts.ExtractPoints())); sw.Stop(); MeshingTimeText.Text = "Completed: " + faces.Count + " faces in " + sw.Elapsed; DelaunayCanvas.Geometry = geometry; }
/// <summary> /// Regenerate the contents of this canvas based on the bound /// Geometry collection. /// </summary> public void RefreshContents() { Children.Clear(); VertexGeometryCollection geometry = Geometry; //BoundingBox bBox = new BoundingBox(geometry); //if (ProportionalThickness) scaleFactor = bBox.MaxSize; if (geometry != null) { //Brush fillBrush = new SolidColorBrush(Color.FromArgb(64, 255, 0, 0)); foreach (FB.VertexGeometry shape in geometry) { AddContents(shape); } } /*if (ScaleToFit) * { * //Width = bBox.SizeX; * //Height = bBox.SizeY; * //RenderTransform = new TranslateTransform(-bBox.MinX, bBox.MaxY); * }*/ }
private void AddWidePath(VertexGeometryCollection geometry, IWidePath path) { if (path.Spine != null) { geometry.Add(path.Spine); } if (path.RightEdge != null) { geometry.Add(path.RightEdge); } if (path.LeftEdge != null) { geometry.Add(path.LeftEdge); } if (path.StartCapRight != null) { geometry.Add(path.StartCapRight); } if (path.StartCapLeft != null) { geometry.Add(path.StartCapLeft); } if (path.EndCapRight != null) { geometry.Add(path.EndCapRight); } if (path.EndCapLeft != null) { geometry.Add(path.EndCapLeft); } }
private void VoronoiButton_Click(object sender, RoutedEventArgs e) { Random rng = null; if (VoronoiSeedBox.Text.IsNumeric()) { int seed = int.Parse(VoronoiSeedBox.Text); rng = new Random(seed); } else { rng = new Random(); } BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0); int size = 500; Geometry.Vector[] points = box.RandomPointsInside(rng, size); VertexCollection verts = new VertexCollection(points); MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts, null, box, false); Dictionary <Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces); MeshFaceCollection outFaces = new MeshFaceCollection(voronoi.Values); PolyLine rect = PolyLine.Rectangle(0, -10, 10, 0); outFaces = outFaces.TrimToPolygonXY(rect.Vertices); outFaces = outFaces.TrimToPolygonXY(rect.Vertices); //Test duplicate edges VertexGeometryCollection geometry = new VertexGeometryCollection(outFaces.ExtractFaceBoundaries()); //ShapeCollection geometry = faces.ExtractFaceBoundaries(); geometry.Add(new Cloud(verts.ExtractPoints())); VoronoiCanvas.Geometry = geometry; }
private void DelaunayButton_Click(object sender, RoutedEventArgs e) { Random rng = new Random(); BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0); int size = 100; Geometry.Vector[] points = box.RandomPointsInside(rng, size); VertexCollection verts = new VertexCollection(points); MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts); faces.Quadrangulate(); //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces); //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries(); CurveCollection edges = faces.ExtractFaceBoundaries(); VertexGeometryCollection geometry = new VertexGeometryCollection(); foreach (var edge in edges) { var region = new PlanarRegion(edge); geometry.Add(region); region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128)); geometry.Add(edge); edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0)); } geometry.Add(new Cloud(verts.ExtractPoints())); DelaunayCanvas.Geometry = geometry; }
public void CollectionContainingHorizontalLineBoundingBoxShouldEnclose() { var line = new Line(0, 0, 10, 0); var vGCol = new VertexGeometryCollection(line); var bBox = vGCol.BoundingBox; Assert.AreEqual(10, bBox.SizeX); Assert.AreEqual(0, bBox.SizeY); }
/// <summary> /// Convert a collection of Nucleus geometry into a collection of RhinoCommon geometry /// </summary> /// <param name="geometry"></param> /// <returns></returns> public static IList <RC.GeometryBase> Convert(VertexGeometryCollection geometry) { var result = new List <RC.GeometryBase>(); foreach (var vG in geometry) { result.Add(Convert(vG)); } return(result); }
/// <summary> /// Convert a collection of rhino geometry to a VertexGeometryCollection /// </summary> /// <param name="geometry"></param> /// <returns></returns> public static VertexGeometryCollection Convert(IList <RC.GeometryBase> geometry) { var result = new VertexGeometryCollection(); foreach (var item in geometry) { var subRes = Convert(item); result.Add(subRes); } return(result); }
/// <summary> /// Get a collection of the geometric objects whose vertices are connected to this node /// </summary> /// <returns></returns> public VertexGeometryCollection GetConnectedGeometry() { var result = new VertexGeometryCollection(); foreach (Vertex v in Vertices) { if (v.Owner != null) { result.Add(v.Owner); } } return(result); }
public MainWindow() { InitializeComponent(); GenerateSpider(); Geometry.Line line = new Geometry.Line(0, 0, 1000, 1000); //GeometryVisualiserDialog.ShowDialog(line); VertexGeometry arc = new Geometry.Arc(new Circle(30, new Geometry.Vector(-50, -50))); //GeometryVisualiserDialog.ShowDialog(arc); VertexGeometryCollection coll = new VertexGeometryCollection(line, arc); GeometryVisualiserDialog.ShowDialog(coll); }
private void DXFLoadButton_Click(object sender, RoutedEventArgs e) { var openDialog = new OpenFileDialog(); openDialog.Title = "Select .DXF file to open"; openDialog.Filter = "AutoCAD DXF File (*.dxf)|*dxf"; if (openDialog.ShowDialog(this) == true) { var dxfReader = new DXFReader(); VertexGeometryCollection geometry = dxfReader.ReadDXF(openDialog.FileName); GeometryLayerTable layers = geometry.Layered(); DXFCanvas.ViewBounds = new BoundingBox(geometry); DXFCanvas.Layers = layers; LayerBox.ItemsSource = layers; } }
public override VertexGeometryCollection EnterGeometry(string prompt = "Enter geometry", Type geometryType = null) { GetObject gO = new GetObject(); if (geometryType == typeof(Curve)) { gO.GeometryFilter = ObjectType.Curve; } else if (geometryType == typeof(Surface)) { gO.GeometryFilter = ObjectType.Surface | ObjectType.Mesh; } else if (geometryType == typeof(Point)) { gO.GeometryFilter = ObjectType.Point; } else { gO.GeometryFilter = ObjectType.Curve | ObjectType.Surface | ObjectType.Point | ObjectType.Mesh; //TODO: Support others } gO.SetCommandPrompt(prompt); if (gO.GetMultiple(1, 0) == GetResult.Cancel) { throw new OperationCanceledException("Operation cancelled by user"); } VertexGeometryCollection result = new VertexGeometryCollection(); foreach (ObjRef objRef in gO.Objects()) { try { VertexGeometry shape = FromRC.Convert(objRef); if (shape != null) { result.Add(shape); } } catch (NotImplementedException) { Core.PrintLine(objRef.Geometry()?.GetType().Name + "s not supported!"); } } return(result); }
private void AnalysisMeshButton_Click(object sender, RoutedEventArgs e) { Random rng = new Random(); BoundingBox box = new BoundingBox(1, 9, -9, -1, 0, 0); int size = 100; //Geometry.Vector[] points = box.RandomPointsInside(rng, size); //VertexCollection verts = new VertexCollection(points); VertexCollection verts = new VertexCollection(); //verts.Add(new Vertex(1, -1)); int divs = 5; for (int i = 0; i <= divs; i++) { for (int j = 0; j <= divs; j++) { Geometry.Vector pt = new Geometry.Vector(box.X.ValueAt(((double)i) / divs), box.Y.ValueAt(((double)j) / divs)); verts.Add(new Vertex(pt)); } } MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts); faces.Quadrangulate(); //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces); //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries(); CurveCollection edges = faces.ExtractFaceBoundaries(); VertexGeometryCollection geometry = new VertexGeometryCollection(); foreach (var edge in edges) { var region = new PlanarRegion(edge); geometry.Add(region); region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128)); geometry.Add(edge); edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0)); } geometry.Add(new Cloud(verts.ExtractPoints())); DelaunayCanvas.Geometry = geometry; }
/// <summary> /// Read a DXF and convert it into native Nucleus geometry types. /// </summary> /// <param name="doc">The document to read from</param> /// <returns></returns> private VertexGeometryCollection ReadDXF(DxfDocument doc) { VertexGeometryCollection result = new VertexGeometryCollection(); double scale = 1.0; if (doc.DrawingVariables.InsUnits == netDxf.Units.DrawingUnits.Millimeters) { scale = 0.001; } else if (doc.DrawingVariables.InsUnits == netDxf.Units.DrawingUnits.Centimeters) { scale = 0.01; } FromDXF.ConversionScaling = scale; // Hatches foreach (netDxf.Entities.Hatch hatch in doc.Hatches) { result.AddRange(FromDXF.Convert(hatch)); } // Lines foreach (netDxf.Entities.Line line in doc.Lines) { result.Add(FromDXF.Convert(line)); } // Polylines foreach (netDxf.Entities.LwPolyline pLine in doc.LwPolylines) { result.Add(FromDXF.Convert(pLine)); } foreach (netDxf.Entities.Polyline pLine in doc.Polylines) { result.Add(FromDXF.Convert(pLine)); } // Arcs foreach (netDxf.Entities.Arc arc in doc.Arcs) { result.Add(FromDXF.Convert(arc)); } foreach (netDxf.Entities.Circle circle in doc.Circles) { result.Add(FromDXF.Convert(circle)); } // Splines foreach (netDxf.Entities.Spline spline in doc.Splines) { result.Add(FromDXF.Convert(spline)); } // Points foreach (netDxf.Entities.Point point in doc.Points) { result.Add(FromDXF.Convert(point)); } //TODO: Meshes foreach (netDxf.Entities.Mesh mesh in doc.Meshes) { result.Add(FromDXF.Convert(mesh)); } // Text foreach (netDxf.Entities.Text text in doc.Texts) { result.Add(FromDXF.Convert(text)); } foreach (netDxf.Entities.MText text in doc.MTexts) { result.Add(FromDXF.Convert(text)); } // Block inserts foreach (netDxf.Entities.Insert insert in doc.Inserts) { // Explode: // Note: There is some commented-out code in the library to do this: // see: https://netdxf.codeplex.com/SourceControl/latest#netDxf/Entities/Insert.cs // TODO: Review and improve? Vector translation = FromDXF.Convert(insert.Position); Transform transform = FromDXF.Convert(insert.GetTransformation(netDxf.Units.DrawingUnits.Meters)); foreach (netDxf.Entities.EntityObject entity in insert.Block.Entities) { VertexGeometry shape = FromDXF.Convert(entity); if (shape != null) { shape.Transform(transform); shape.Move(translation); result.Add(shape); } } } return(result); }
public GeometryVisualiserDialog(object visualise) : this() { VertexGeometryCollection geometry = new VertexGeometryCollection(); if (_StorePath.Exists) { try { Stream stream = new FileStream(_StorePath, FileMode.Open, FileAccess.Read, FileShare.Read); stream.Seek(0, SeekOrigin.Begin); IFormatter formatter = new BinaryFormatter(); formatter.Binder = new CustomSerializationBinder(); var storedGeo = formatter.Deserialize(stream) as VertexGeometryCollection; stream.Close(); if (storedGeo != null) { geometry.AddRange(storedGeo); } } catch { } } if (visualise is MeshFace) { visualise = new MeshFaceCollection((MeshFace)visualise); } //else if (visualise is Mesh) visualise = ((Mesh)visualise).Faces; if (visualise is IList <VertexGeometry> ) { geometry.TryAddRange((IList <VertexGeometry>)visualise); } else if (visualise is IList <Curve> ) { geometry.TryAddRange((IList <Curve>)visualise); } else if (visualise is IList <PlanarRegion> ) { geometry.TryAddRange((IList <PlanarRegion>)visualise); } else if (visualise is VertexGeometry) { geometry.TryAdd((VertexGeometry)visualise); } else if (visualise is MeshFaceCollection) { var faces = (MeshFaceCollection)visualise; CurveCollection edges = faces.ExtractFaceBoundaries(); foreach (var edge in edges) { var region = new PlanarRegion(edge); geometry.Add(region); region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128)); geometry.Add(edge); edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0)); } } else if (visualise is IList <Vertex> ) { var verts = (IList <Vertex>)visualise; var cloud = new Cloud(verts.GetPositions()); geometry.Add(cloud); } else if (visualise is IList <Geometry.Vector> ) { var v = (IList <Geometry.Vector>)visualise; var cloud = new Cloud(v); geometry.Add(cloud); } else if (visualise is MeshDivisionEdge) { var mDE = (MeshDivisionEdge)visualise; var line = new Geometry.Line(mDE.Start, mDE.End); geometry.Add(line); if (mDE.Vertices != null && mDE.Vertices.Count > 0) { var cloud = new Cloud(mDE.Vertices.GetPositions()); geometry.Add(cloud); } } else if (visualise is IList <MeshDivisionEdge> ) { foreach (var mDC in (IList <MeshDivisionEdge>)visualise) { var mDE = (MeshDivisionEdge)visualise; var line = new Geometry.Line(mDE.Start, mDE.End); geometry.Add(line); if (mDE.Vertices != null && mDE.Vertices.Count > 0) { var cloud = new Cloud(mDE.Vertices.GetPositions()); geometry.Add(cloud); } } } else if (visualise is IWidePath) { IWidePath path = (IWidePath)visualise; AddWidePath(geometry, path); } else if (visualise is IList <IWidePath> ) { foreach (var path in (IList <IWidePath>)visualise) { AddWidePath(geometry, path); } } // TODO: Convert other types to vertexgeometry BoundingBox bBox = geometry.BoundingBox; /*MinX.Text = bBox.MinX.ToString(); * MaxX.Text = bBox.MaxX.ToString(); * MinY.Text = bBox.MinY.ToString(); * MaxY.Text = bBox.MaxY.ToString();*/ Canvas.CurveThickness = 0.005 * bBox.SizeVector.Magnitude(); Canvas.PointDiameter = 0.01 * bBox.SizeVector.Magnitude(); Canvas.DefaultBrush = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)); //Canvas.FillBrush = new SolidColorBrush(Color.FromArgb(64, 0, 0, 0)); Canvas.Geometry = geometry; /*var xDivs = bBox.X.ReasonableDivisions(10); * var yDivs = bBox.Y.ReasonableDivisions(10); * * foreach (double x in xDivs) * { * var line = new Geometry.Line(x, bBox.MinY - 10, x, bBox.MaxY + 10); * line.Attributes = new GeometryAttributes(Rendering.Colour.Green, 0.1); * Canvas.AddContents(line); * }*/ }