internal IEnumerable<Point> Calculate(){ if (BoundingBox.Width==0) FillBoundingBoxWithSites(); Cdt cdt = new Cdt(cites, null,null); cdt.Run(); var triangles = cdt.GetTriangles(); foreach (var triangle in triangles) AddVoronoiCite(triangle); return voronoiSiteTree.GetAllLeaves(); }
/// <summary> /// Does one iterations in which a miniminum spanning tree is /// determined on the delaunay triangulation and finally the tree is exanded to resolve the overlaps. /// </summary> /// <param name="nodePositions"></param> /// <param name="nodeSizes"></param> /// <param name="scanlinePhase"></param> /// <returns></returns> bool OneIteration(Point[] nodePositions, Size[] nodeSizes, bool scanlinePhase) { var cdt = new Cdt(nodePositions.Select((p, index) => Tuple.Create(p, (object) index))); cdt.Run(); var siteIndex = new Dictionary<CdtSite, int>(); for (int i = 0; i < nodePositions.Length; i++) siteIndex[cdt.PointsToSites[nodePositions[i]]] = i; int numCrossings = 0; List<Tuple<int, int, double, double, double>> proximityEdges = new List<Tuple<int, int, double, double, double>>(); foreach (var site in cdt.PointsToSites.Values) foreach (var edge in site.Edges) { Point point1 = edge.upperSite.Point; Point point2 = edge.lowerSite.Point; var nodeId1 = siteIndex[edge.upperSite]; var nodeId2 = siteIndex[edge.lowerSite]; Debug.Assert(ApproximateComparer.Close(point1, nodePositions[nodeId1])); Debug.Assert(ApproximateComparer.Close(point2, nodePositions[nodeId2])); var tuple = GetIdealEdgeLength(nodeId1, nodeId2, point1, point2, nodeSizes, _overlapForLayers); proximityEdges.Add(tuple); if (tuple.Item3 > 1) numCrossings++; } if (numCrossings == 0 || scanlinePhase) { int additionalCrossings = FindProximityEdgesWithSweepLine(proximityEdges, nodeSizes, nodePositions); if (numCrossings == 0 && additionalCrossings == 0) { // if(nodeSizes.Length>100) // ShowAndMoveBoxesRemoveLater(null, proximityEdges, nodeSizes, nodePositions, -1); return false; } if (numCrossings == 0 && !scanlinePhase) return false; } var treeEdges = MstOnDelaunayTriangulation.GetMstOnTuple(proximityEdges, nodePositions.Length); int rootId = treeEdges.First().Item1; // if (nodeSizes.Length > 100) // ShowAndMoveBoxesRemoveLater(treeEdges, proximityEdges, nodeSizes, nodePositions, rootId); MoveNodePositions(treeEdges, nodePositions, rootId); return true; }
static void Triangulation(bool reverseX) { #if DEBUG DisplayGeometryGraph.SetShowFunctions(); #endif int r = reverseX ? -1 : 1; IEnumerable<Point> points = Points().Select(p => new Point(r*p.X, p.Y)); var poly = (Polyline) RussiaPolyline.GetTestPolyline().ScaleFromOrigin(1, 1); var cdt = new Cdt(null, new[] {poly}, null); cdt.Run(); #if DEBUG CdtSweeper.ShowFront(cdt.GetTriangles(), null, null, null); #endif }
public void InitCdt() { InitSegmentTree(); for (int i = 0; i < fixedRectangles.Length; i++) { Point p = Round( fixedRectangles[i].Center ); var node = new TreeNode { isFixed = true, rectId = i, rect = fixedRectangles[i], sitePoint = p, type = SiteType.RectFixed }; if (nodeLabelsFixed != null) { node.label = nodeLabelsFixed[i]; } pointToTreeNode[p] = node; _rectNodesRtree.Add(node.rect, node); _fixedRectanglesTree.Add(fixedRectangles[i], node); } for (int i = 0; i < moveableRectangles.Length; i++) { Point p = Round(moveableRectangles[i].Center); var node = new TreeNode { isFixed = false, rectId = i, rect = moveableRectangles[i], sitePoint = p, type = SiteType.RectMoveable }; if (nodeLabelsMoveable != null) { node.label = nodeLabelsMoveable[i]; } pointToTreeNode[p] = node; _rectNodesRtree.Add(node.rect, node); _moveableRectanglesTree.Add(moveableRectangles[i], node); } var sites = pointToTreeNode.Keys.ToList(); //AddSitesForBoxSegmentOverlaps(sites); cdt = new Cdt(sites, null, null); cdt.Run(); }
static void TestTriangulationOnPolys() { FileStream stream = File.Open("polys", FileMode.Open); var bformatter = new BinaryFormatter(); var polys = (Polyline[]) bformatter.Deserialize(stream); stream.Close(); var cdt = new Cdt(null, polys, null); cdt.Run(); }
static void TestTriangulationOnSmallGraph(ArgsParser.ArgsParser parser) { var polyline = new Polyline( new Point(20.8211097717285, 40.9088821411133), new Point(21.4894065856934, 46.6845321655273), new Point(22.9755554199219, 41.3355484008789), new Point(20.8211097717285, 40.9088821411133)); var polylines = new List<Polyline>(); polylines.Add(polyline); var points = new List<Point>(); var centroid = new Point(21.7620239257813, 42.9763209025065); points.Add(centroid); var testCdt = new Cdt(points, polylines, null); testCdt.Run(); }
/// <summary> /// /// </summary> public static void Test() { #if DEBUG && !SILVERLIGHT && !SHARPKIT int count = 100; var random = new Random(3); var points = new List<Point>(); for (int i = 0; i < count; i++) points.Add(20 * new Point(random.NextDouble(), random.NextDouble())); var cdt = new Cdt(points, null, null); cdt.Run(); var ret = GetMstOnCdt(cdt, e => (e.lowerSite.Point - e.upperSite.Point).Length); var l = new List<DebugCurve>(); foreach(var s in cdt.PointsToSites.Values) foreach (var e in s.Edges) { l.Add(new DebugCurve(100, 0.1, "black", new LineSegment(e.lowerSite.Point, e.upperSite.Point))); } foreach (var e in ret) { l.Add(new DebugCurve(100, 0.12, "red", new LineSegment(e.lowerSite.Point, e.upperSite.Point))); } LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(l); #endif }
private void TesselateUnderShape(Shape shape) { var polys=new List<Polyline>(shape.Children.Select(sh=>(Polyline)sh.BoundaryCurve)); polys.Add(shape.BoundaryCurve as Polyline); var cdt=new Cdt(shapesToInnerPoints[shape], polys,null); cdt.Run(); Set<CdtTriangle> triangles=cdt.GetTriangles(); cdt.SetInEdges(); CleanUpTriangles(shape, ref triangles,cdt); foreach(var t in triangles){ AddTriangleToCanvas(t); } }
static Cdt GetConstrainedDelaunayTriangulation(IEnumerable<Polyline> obstacles) { var constrainedDelaunayTriangulation = new Cdt(null, obstacles, null); constrainedDelaunayTriangulation.Run(); return constrainedDelaunayTriangulation; }
public void TestRepeatedSite() { //in this method the triangulation is such that a repeated site appears in EdgeEvent var stream = File.Open("polys", FileMode.Open); var bformatter = new BinaryFormatter(); var polys = (Polyline[])bformatter.Deserialize(stream); stream.Close(); var cdt = new Cdt(null, polys, null); cdt.Run(); TestTriangles(cdt.GetTriangles()); }
void Triangulate(int n, double size) { var random = new Random(n); var w = n * size; var cdt = new Cdt(PointsForCdt(random, n, w), null, SegmentsForCdt(w).ToList()); cdt.Run(); #if DEBUG&&TEST_MSAGL CdtSweeper.ShowFront(cdt.GetTriangles(), null, null,null); #endif }
public void SmallTriangulation() { #if DEBUG&& TEST_MSAGL GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions(); #endif var cdt = new Cdt(Points(), null, new []{new SymmetricTuple<Point>(new Point(109,202),new Point(506,135) ), new SymmetricTuple<Point>(new Point(139,96),new Point(452,96) )}.ToList()); cdt.Run(); }
bool DoSingleIteration(int currentIteration, ref bool scanlinePhase) { List<Tuple<Point, object>> sites = nodePositions.Select((p, index) => new Tuple<Point, object>(p, index)).ToList(); var triangulation = new Cdt(sites); triangulation.Run(); List<Tuple<int, int, double, double>> proximityEdgesWithDistance; int numCrossings = GetProximityEdgesWithDistance(_nodes, triangulation, nodeSizes, out proximityEdgesWithDistance); if (scanlinePhase || numCrossings == 0) { scanlinePhase = true; numCrossings = CompleteProximityGraphWithRTree(ref numCrossings, proximityEdgesWithDistance); } #if DEBUG int realCrossings = CountCrossingsWithRTree(nodeSizes); crossingsOverTime.Add(realCrossings); if (currentIteration%10 == 0) Console.WriteLine("Scanline: {0}, Crossings: {1}", scanlinePhase, numCrossings); #endif if (numCrossings == 0) return true; AddStressFromProximityEdges(StressSolver, proximityEdgesWithDistance); List<Point> newPositions = StressSolver.IterateAll(); ShowCurrentMovementVectors(currentIteration, nodeSizes, nodePositions, newPositions, proximityEdgesWithDistance, null); UpdatePointsAndBoxes(newPositions); //clear the data structures StressSolver.ClearVotings(); #if DEBUG for (int i = 0; i < nodePositions.Length; i++) { trajectories[i].AddPoint(newPositions[i]); } #endif return false; }