| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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>();
- }
- }
- }
|