public void Evaluate(int SpreadMax) { if (this.FPinInput.PinIsChanged || this.FPinInElementCount.PinIsChanged || this.FPinInBoundsMax.PinIsChanged || this.FPinInBoundsMin.PinIsChanged) { double elemcnt; double xmin, xmax, ymin, ymax; this.FPinInElementCount.GetValue(0, out elemcnt); this.FPinInBoundsMin.GetValue2D(0, out xmin, out ymin); this.FPinInBoundsMax.GetValue2D(0, out xmax, out ymax); Rect defbounds = new Rect(ymax, ymin, xmin, xmax); if (!defbounds.Zero) { DefaultQuadTree qt = new DefaultQuadTree(Convert.ToInt32(elemcnt), defbounds); for (int i = 0; i < this.FPinInput.SliceCount; i++) { double x, y; this.FPinInput.GetValue2D(i, out x, out y); qt.Add(new Point2d(x, y)); } List <Rect> bounds = qt.GetAllBounds(); int edgeindex = 0; //Four edges per box output this.FPinOutputEdgeX1.SliceCount = bounds.Count * 4; this.FPinOutputEdgeX2.SliceCount = bounds.Count * 4; this.FPinOutputEdgeY1.SliceCount = bounds.Count * 4; this.FPinOutputEdgeY2.SliceCount = bounds.Count * 4; for (int i = 0; i < bounds.Count; i++) { Edge2d[] edges = bounds[i].Edges; foreach (Edge2d edge in edges) { this.FPinOutputEdgeX1.SetValue(edgeindex, edge.Point1.x); this.FPinOutputEdgeX2.SetValue(edgeindex, edge.Point2.x); this.FPinOutputEdgeY1.SetValue(edgeindex, edge.Point1.y); this.FPinOutputEdgeY2.SetValue(edgeindex, edge.Point2.y); edgeindex++; } } } else { //Invalid bounds this.FPinOutputEdgeX1.SliceCount = 0; this.FPinOutputEdgeX2.SliceCount = 0; this.FPinOutputEdgeY1.SliceCount = 0; this.FPinOutputEdgeY2.SliceCount = 0; } } }
public void Evaluate(int SpreadMax) { if (this.FPinInput.PinIsChanged || this.FPinInElementCount.PinIsChanged || this.FPinInBoundsMax.PinIsChanged || this.FPinInBoundsMin.PinIsChanged) { double elemcnt; double xmin, xmax, ymin, ymax; this.FPinInElementCount.GetValue(0, out elemcnt); this.FPinInBoundsMin.GetValue2D(0, out xmin, out ymin); this.FPinInBoundsMax.GetValue2D(0, out xmax, out ymax); Rect defbounds = new Rect(ymax, ymin, xmin, xmax); if (!defbounds.Zero) { List <Point2d> points = new List <Point2d>(); DefaultQuadTree qt = new DefaultQuadTree(Convert.ToInt32(elemcnt), defbounds); for (int i = 0; i < this.FPinInput.SliceCount; i++) { double x, y; this.FPinInput.GetValue2D(i, out x, out y); Point2d point = new Point2d(x, y); qt.Add(point); points.Add(point); } List <Rect> bounds = qt.GetAllBounds(); this.FPinOutputCenter.SliceCount = bounds.Count; this.FPinOutputHeight.SliceCount = bounds.Count; this.FPinOutputWidth.SliceCount = bounds.Count; for (int i = 0; i < bounds.Count; i++) { Point2d center = bounds[i].Center; this.FPinOutputCenter.SetValue2D(i, center.x, center.y); this.FPinOutputWidth.SetValue(i, bounds[i].Width); this.FPinOutputHeight.SetValue(i, bounds[i].Height); } this.FPinOutputCenterSelected.SliceCount = points.Count; this.FPinOutputHeightSelected.SliceCount = points.Count; this.FPinOutputWidthSelected.SliceCount = points.Count; for (int i = 0; i < points.Count; i++) { Rect bound = qt.FindNodeBounds(points[i]); this.FPinOutputCenterSelected.SetValue2D(i, bound.Center.x, bound.Center.y); this.FPinOutputWidthSelected.SetValue(i, bound.Width); this.FPinOutputHeightSelected.SetValue(i, bound.Height); } } else { //Invalid Bounds, zero this.FPinOutputCenter.SliceCount = 0; this.FPinOutputHeight.SliceCount = 0; this.FPinOutputWidth.SliceCount = 0; } } }