private void SV_ScrollChanged(object sender, ScrollChangedEventArgs e) { HRect.Width = SV.ViewportWidth / Zoom.Value; HRect.Height = SV.ViewportHeight / Zoom.Value; HRect.SetValue(Canvas.LeftProperty, SV.ContentHorizontalOffset / Zoom.Value); HRect.SetValue(Canvas.TopProperty, SV.ContentVerticalOffset / Zoom.Value); }
public void Copy(MeasureDefect measureDefect) { this.DefectAlgorithm.Copy(measureDefect.DefectAlgorithm); this.DefectName = measureDefect.DefectName; this.HRectList.Clear(); foreach (var item in measureDefect.HRectList) { HRect hRect = new HRect(); hRect.Copy(item); this.HRectList.Add(hRect); } this.HCircleList.Clear(); foreach (var item in measureDefect.HCircleList) { HCircle hCircle = new HCircle(); hCircle.Copy(item); this.HCircleList.Add(hCircle); } this.HPolygonList.Clear(); foreach (var item in measureDefect.HPolygonList) { HPolygon hPolygon = new HPolygon(); hPolygon.Copy(item); this.HPolygonList.Add(hPolygon); } this.Id = measureDefect.Id; }
public void Copy(MeasureSize measureSize) { this.SizeAlgorithm = measureSize.SizeAlgorithm; this.HRectList.Clear(); foreach (var item in measureSize.HRectList) { HRect hRect = new HRect(); hRect.Copy(item); this.HRectList.Add(hRect); } }
private static void hrcopy(HRect hr_src, HRect hr_dst) { hpcopy(hr_src.min, hr_dst.min); hpcopy(hr_src.max, hr_dst.max); }
// Method Nearest Neighbor from Andrew Moore's thesis. Numbered // comments are direct quotes from there. Step "SDL" is added to // make the algorithm work correctly. NearestNeighborList solution // courtesy of Bjoern Heckel. public static void nnbr(KDNode kd, HPoint target, HRect hr, float max_dist_sqd, int lev, int K, NearestNeighborList nnl) { // 1. if kd is empty then set dist-sqd to infinity and exit. if (kd == null) { return; } // 2. s := split field of kd int s = lev % K; // 3. pivot := dom-elt field of kd HPoint pivot = kd.k; float pivot_to_target = HPoint.sqrdist(pivot, target); // 4. Cut hr into to sub-hyperrectangles left-hr and right-hr. // The cut plane is through pivot and perpendicular to the s // dimension. HRect left_hr = hr; // optimize by not cloning HRect right_hr = (HRect)hr.clone(); left_hr.max.coord[s] = pivot.coord[s]; right_hr.min.coord[s] = pivot.coord[s]; // 5. target-in-left := target_s <= pivot_s bool target_in_left = target.coord[s] < pivot.coord[s]; KDNode nearer_kd; HRect nearer_hr; KDNode further_kd; HRect further_hr; // 6. if target-in-left then // 6.1. nearer-kd := left field of kd and nearer-hr := left-hr // 6.2. further-kd := right field of kd and further-hr := right-hr if (target_in_left) { nearer_kd = kd.left; nearer_hr = left_hr; further_kd = kd.right; further_hr = right_hr; } // // 7. if not target-in-left then // 7.1. nearer-kd := right field of kd and nearer-hr := right-hr // 7.2. further-kd := left field of kd and further-hr := left-hr else { nearer_kd = kd.right; nearer_hr = right_hr; further_kd = kd.left; further_hr = left_hr; } // 8. Recursively call Nearest Neighbor with paramters // (nearer-kd, target, nearer-hr, max-dist-sqd), storing the // results in nearest and dist-sqd nnbr(nearer_kd, target, nearer_hr, max_dist_sqd, lev + 1, K, nnl); KDNode nearest = (KDNode)nnl.getHighest(); float dist_sqd; if (!nnl.isCapacityReached()) { dist_sqd = float.MaxValue; } else { dist_sqd = nnl.getMaxPriority(); } // 9. max-dist-sqd := minimum of max-dist-sqd and dist-sqd max_dist_sqd = Math.Min(max_dist_sqd, dist_sqd); // 10. A nearer point could only lie in further-kd if there were some // part of further-hr within distance sqrt(max-dist-sqd) of // target. If this is the case then HPoint closest = further_hr.closest(target); if (HPoint.Distance(ref closest, ref target) < Math.Sqrt(max_dist_sqd)) { // 10.1 if (pivot-target)^2 < dist-sqd then if (pivot_to_target < dist_sqd) { // 10.1.1 nearest := (pivot, range-elt field of kd) nearest = kd; // 10.1.2 dist-sqd = (pivot-target)^2 dist_sqd = pivot_to_target; // add to nnl if (!kd.deleted) { nnl.insert(kd, dist_sqd); } // 10.1.3 max-dist-sqd = dist-sqd // max_dist_sqd = dist_sqd; if (nnl.isCapacityReached()) { max_dist_sqd = nnl.getMaxPriority(); } else { max_dist_sqd = float.MaxValue; } } // 10.2 Recursively call Nearest Neighbor with parameters // (further-kd, target, further-hr, max-dist_sqd), // storing results in temp-nearest and temp-dist-sqd nnbr(further_kd, target, further_hr, max_dist_sqd, lev + 1, K, nnl); KDNode temp_nearest = (KDNode)nnl.getHighest(); float temp_dist_sqd = nnl.getMaxPriority(); // 10.3 If tmp-dist-sqd < dist-sqd then if (temp_dist_sqd < dist_sqd) { // 10.3.1 nearest := temp_nearest and dist_sqd := temp_dist_sqd nearest = temp_nearest; dist_sqd = temp_dist_sqd; } } // SDL: otherwise, current point is nearest else if (pivot_to_target < max_dist_sqd) { nearest = kd; dist_sqd = pivot_to_target; } }