|
|
@@ -0,0 +1,50 @@
|
|
|
+using System.Linq;
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+/*
|
|
|
+*需要解决的问题:渲染的点过多时App会卡死
|
|
|
+*解决方案:保证点在圆上均匀分布,并剔除多余的点
|
|
|
+*/
|
|
|
+public class PointCorrector {
|
|
|
+ Ellipse ellipse;
|
|
|
+ o0MagneticCalibraterEllipsoidFitting MagCalibrater;
|
|
|
+ public static PointCorrector ins;
|
|
|
+
|
|
|
+ public PointCorrector(
|
|
|
+ Ellipse ellipse,
|
|
|
+ o0MagneticCalibraterEllipsoidFitting MagCalibrater
|
|
|
+ ) {
|
|
|
+ this.ellipse = ellipse;
|
|
|
+ this.MagCalibrater = MagCalibrater;
|
|
|
+ }
|
|
|
+
|
|
|
+ const int correctNeedPointCount = 3600; //需要收集多少点才开始进行剔除
|
|
|
+ int angleDivisionValue = 1; //多少角度分割为1个区间
|
|
|
+ const int angleDivisionValueMax = 6; //最大多少角度分割为1个区间
|
|
|
+ const float angleDivisionValueUpThreshold = 0.9f; //一轮点的剔除后,剩余的点超过百分之几时就加大角度分隔值
|
|
|
+
|
|
|
+ public void Update(Vector3 centerPoint) {
|
|
|
+ List<Vector3> li = this.ellipse.arrayList;
|
|
|
+ if (li.Count > correctNeedPointCount) {
|
|
|
+ HashSet<string> angleSet = new HashSet<string>();
|
|
|
+ li.RemoveAll(p => {
|
|
|
+ Vector3 angle = Quaternion.LookRotation(p - centerPoint, Vector3.up).eulerAngles;
|
|
|
+ string key = Mathf.FloorToInt(angle.x / angleDivisionValue) + "_" + Mathf.FloorToInt(angle.y / angleDivisionValue);
|
|
|
+ if (angleSet.Contains(key)) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ angleSet.Add(key);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Debug.LogWarning("剔除完成:剩余点数:" + li.Count);
|
|
|
+ if (li.Count > correctNeedPointCount * angleDivisionValueUpThreshold) {
|
|
|
+ angleDivisionValue = System.Math.Min(angleDivisionValue + 1, angleDivisionValueMax);
|
|
|
+ Debug.LogWarning("切割值尝试提升,当前值为" + angleDivisionValue);
|
|
|
+ }
|
|
|
+ MagCalibrater.records = li.ToList<Vector3>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|