public object Clone() { SDMinVertex vertex = new SDMinVertex(); vertex.Weight = this.Weight; vertex.Next = this.Next; vertex.Previous = this.Previous; vertex.PathIndex = this.PathIndex; vertex.PointIndex = this.PointIndex; return(vertex); }
private Polyline simplifyPolylineSDMin(Polyline polyline, double compressionLevel) { polyline = (Polyline)polyline.Clone(); polyline.ReduceSegments(PlanimetryAlgorithms.Tolerance); //are counting vertex weights List <SDMinVertex> weightedVertices = getWeightedVertices(polyline); // find the points of intersection KDTree crossPointIndex = getCrossPointsIndex(polyline); // building codes KDTree vertexIndex = buildVertexIndex(weightedVertices, polyline); List <SDMinVertex> deletedVertices = new List <SDMinVertex>(); int pointCount = polyline.CoordinateCount; int n = 0; while (n < weightedVertices.Count && (double)(pointCount - deletedVertices.Count) / (double)pointCount > compressionLevel) { SDMinVertex currentVertex = weightedVertices[n]; if (currentVertex.Deleted || currentVertex.IsCrossSegmentVertex || currentVertex.Previous == null || currentVertex.Next == null) { n++; continue; } if (checkWeightedVertex(polyline, vertexIndex, currentVertex, crossPointIndex)) { //the top can be removed currentVertex.Previous.Next = currentVertex.Next; currentVertex.Next.Previous = currentVertex.Previous; deletedVertices.Add(currentVertex); vertexIndex.Remove(currentVertex); currentVertex.Deleted = true; n = 0; } else { n++; } } removeVertices(polyline, deletedVertices); return(polyline); }
private SDMinVertex getWeightedVertex(Polyline polyline, int pathIndex, int pointIndex) { SDMinVertex result = new SDMinVertex(); result.PathIndex = pathIndex; result.PointIndex = pointIndex; result.Weight = getVertexWeight(polyline, pathIndex, pointIndex); BoundingRectangle br = new PointD(polyline.Paths[pathIndex].Vertices[pointIndex]).GetBoundingRectangle(); br.Grow(PlanimetryAlgorithms.Tolerance); result.BoundingRectangle = br; return(result); }
private ICoordinate pointOfWeightedVertex(Polyline polyline, SDMinVertex vertex) { return(polyline.Paths[vertex.PathIndex].Vertices[vertex.PointIndex]); }
private bool checkWeightedVertex(Polyline polyline, KDTree vertexIndex, SDMinVertex currentVertex, KDTree crossPointIndex) { // probably not an internal vertex if (currentVertex.Previous == null || currentVertex.Next == null) { return(true); } // top with infinite weight ("do not remove") if (double.IsPositiveInfinity(currentVertex.Weight)) { return(true); } SDMinVertex previous = currentVertex.Previous; SDMinVertex next = currentVertex.Next; // One of the segments formed by the vertex in question may be one of the intersection points. // If so, you can not remove the top, as point of self-intersection, it may be removed. Segment s1 = new Segment(pointOfWeightedVertex(polyline, currentVertex), pointOfWeightedVertex(polyline, previous)); Segment s2 = new Segment(pointOfWeightedVertex(polyline, currentVertex), pointOfWeightedVertex(polyline, next)); List <SDMinCrossPoint> crossPoints = new List <SDMinCrossPoint>(); crossPointIndex.QueryObjectsInRectangle(s1.GetBoundingRectangle(), crossPoints); crossPointIndex.QueryObjectsInRectangle(s2.GetBoundingRectangle(), crossPoints); foreach (SDMinCrossPoint point in crossPoints) { if (PlanimetryAlgorithms.LiesOnSegment(point.Point, s1)) { currentVertex.IsCrossSegmentVertex = true; currentVertex.Previous.IsCrossSegmentVertex = true; return(false); } if (PlanimetryAlgorithms.LiesOnSegment(point.Point, s2)) { currentVertex.IsCrossSegmentVertex = true; currentVertex.Next.IsCrossSegmentVertex = true; return(false); } } //One of the polyline vertices can belong to a triangle, //the apex of which is considered the top. In this case, //the top can not be deleted because will be a new point of self-intersection. Polygon triangle = new Polygon(new ICoordinate[] { pointOfWeightedVertex(polyline, previous), pointOfWeightedVertex(polyline, currentVertex), pointOfWeightedVertex(polyline, next) }); List <SDMinVertex> vertices = new List <SDMinVertex>(); vertexIndex.QueryObjectsInRectangle <SDMinVertex>(triangle.GetBoundingRectangle(), vertices); foreach (SDMinVertex vertex in vertices) { ICoordinate p = pointOfWeightedVertex(polyline, vertex); //point should not be the top of the triangle if (p.ExactEquals(triangle.Contours[0].Vertices[0]) || p.ExactEquals(triangle.Contours[0].Vertices[1]) || p.ExactEquals(triangle.Contours[0].Vertices[2])) { continue; } if (triangle.ContainsPoint(p)) { return(false); } } return(true); }
private List <SDMinVertex> getWeightedVertices(Polyline polyline) { List <SDMinVertex> result = new List <SDMinVertex>(); for (int i = 0; i < polyline.Paths.Count; i++) { for (int j = 0; j < polyline.Paths[i].Vertices.Count; j++) { if (j != 0 && j != polyline.Paths[i].Vertices.Count - 1) { SDMinVertex vertex = getWeightedVertex(polyline, i, j); vertex.Previous = result[result.Count - 1]; vertex.Previous.Next = vertex; result.Add(vertex); } else { SDMinVertex vertex = new SDMinVertex(); vertex.PathIndex = i; vertex.PointIndex = j; BoundingRectangle br = new PointD(polyline.Paths[i].Vertices[j]).GetBoundingRectangle(); br.Grow(PlanimetryAlgorithms.Tolerance); vertex.BoundingRectangle = br; vertex.Weight = double.PositiveInfinity; if (j != 0) { vertex.Previous = result[result.Count - 1]; vertex.Previous.Next = vertex; } result.Add(vertex); } } } Comparison <SDMinVertex> comparision = delegate(SDMinVertex weight1, SDMinVertex weight2) { if (double.IsInfinity(weight1.Weight) && double.IsInfinity(weight2.Weight)) { return(0); } if (double.IsInfinity(weight1.Weight)) { return(1); } if (double.IsInfinity(weight2.Weight)) { return(-1); } if (weight1 == weight2) { return(0); } return(weight1.Weight > weight2.Weight ? 1 : -1); }; // sort list result.Sort(comparision); return(result); }
private ICoordinate pointOfWeightedVertex(Polyline polyline, SDMinVertex vertex) { return polyline.Paths[vertex.PathIndex].Vertices[vertex.PointIndex]; }
private bool checkWeightedVertex(Polyline polyline, KDTree vertexIndex, SDMinVertex currentVertex, KDTree crossPointIndex) { // probably not an internal vertex if (currentVertex.Previous == null || currentVertex.Next == null) return true; // top with infinite weight ("do not remove") if (double.IsPositiveInfinity(currentVertex.Weight)) return true; SDMinVertex previous = currentVertex.Previous; SDMinVertex next = currentVertex.Next; // One of the segments formed by the vertex in question may be one of the intersection points. // If so, you can not remove the top, as point of self-intersection, it may be removed. Segment s1 = new Segment(pointOfWeightedVertex(polyline, currentVertex), pointOfWeightedVertex(polyline, previous)); Segment s2 = new Segment(pointOfWeightedVertex(polyline, currentVertex), pointOfWeightedVertex(polyline, next)); List<SDMinCrossPoint> crossPoints = new List<SDMinCrossPoint>(); crossPointIndex.QueryObjectsInRectangle(s1.GetBoundingRectangle(), crossPoints); crossPointIndex.QueryObjectsInRectangle(s2.GetBoundingRectangle(), crossPoints); foreach (SDMinCrossPoint point in crossPoints) { if (PlanimetryAlgorithms.LiesOnSegment(point.Point, s1)) { currentVertex.IsCrossSegmentVertex = true; currentVertex.Previous.IsCrossSegmentVertex = true; return false; } if(PlanimetryAlgorithms.LiesOnSegment(point.Point, s2)) { currentVertex.IsCrossSegmentVertex = true; currentVertex.Next.IsCrossSegmentVertex = true; return false; } } //One of the polyline vertices can belong to a triangle, //the apex of which is considered the top. In this case, //the top can not be deleted because will be a new point of self-intersection. Polygon triangle = new Polygon(new ICoordinate[] { pointOfWeightedVertex(polyline, previous), pointOfWeightedVertex(polyline, currentVertex), pointOfWeightedVertex(polyline, next) }); List<SDMinVertex> vertices = new List<SDMinVertex>(); vertexIndex.QueryObjectsInRectangle<SDMinVertex>(triangle.GetBoundingRectangle(), vertices); foreach (SDMinVertex vertex in vertices) { ICoordinate p = pointOfWeightedVertex(polyline, vertex); //point should not be the top of the triangle if (p.ExactEquals(triangle.Contours[0].Vertices[0]) || p.ExactEquals(triangle.Contours[0].Vertices[1]) || p.ExactEquals(triangle.Contours[0].Vertices[2])) continue; if (triangle.ContainsPoint(p)) return false; } return true; }
private List<SDMinVertex> getWeightedVertices(Polyline polyline) { List<SDMinVertex> result = new List<SDMinVertex>(); for (int i = 0; i < polyline.Paths.Count; i++) for (int j = 0; j < polyline.Paths[i].Vertices.Count; j++) if (j != 0 && j != polyline.Paths[i].Vertices.Count - 1) { SDMinVertex vertex = getWeightedVertex(polyline, i, j); vertex.Previous = result[result.Count - 1]; vertex.Previous.Next = vertex; result.Add(vertex); } else { SDMinVertex vertex = new SDMinVertex(); vertex.PathIndex = i; vertex.PointIndex = j; BoundingRectangle br = new PointD(polyline.Paths[i].Vertices[j]).GetBoundingRectangle(); br.Grow(PlanimetryAlgorithms.Tolerance); vertex.BoundingRectangle = br; vertex.Weight = double.PositiveInfinity; if (j != 0) { vertex.Previous = result[result.Count - 1]; vertex.Previous.Next = vertex; } result.Add(vertex); } Comparison<SDMinVertex> comparision = delegate(SDMinVertex weight1, SDMinVertex weight2) { if(double.IsInfinity(weight1.Weight) && double.IsInfinity(weight2.Weight)) return 0; if (double.IsInfinity(weight1.Weight)) return 1; if (double.IsInfinity(weight2.Weight)) return -1; if (weight1 == weight2) return 0; return weight1.Weight > weight2.Weight ? 1 : -1; }; // sort list result.Sort(comparision); return result; }
private SDMinVertex getWeightedVertex(Polyline polyline, int pathIndex, int pointIndex) { SDMinVertex result = new SDMinVertex(); result.PathIndex = pathIndex; result.PointIndex = pointIndex; result.Weight = getVertexWeight(polyline, pathIndex, pointIndex); BoundingRectangle br = new PointD(polyline.Paths[pathIndex].Vertices[pointIndex]).GetBoundingRectangle(); br.Grow(PlanimetryAlgorithms.Tolerance); result.BoundingRectangle = br; return result; }
public object Clone() { SDMinVertex vertex = new SDMinVertex(); vertex.Weight = this.Weight; vertex.Next = this.Next; vertex.Previous = this.Previous; vertex.PathIndex = this.PathIndex; vertex.PointIndex = this.PointIndex; return vertex; }