[8.0.0][Opt]减少预测渲染的数据

This commit is contained in:
chenfufeng
2025-05-22 14:28:24 +08:00
parent 57a62699be
commit 7bdf1a42f1
2 changed files with 37 additions and 98 deletions

View File

@@ -12,8 +12,9 @@ import com.mogo.eagle.core.function.business.routeoverlay.PredictionOverlayDrawe
import com.mogo.eagle.core.function.business.routeoverlay.PredictionOverlayDrawer2
import com.mogo.eagle.core.function.business.routeoverlay.PredictionOverlayDrawer3
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager.getLocationHeading
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager.getWgs84Lat
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager.getWgs84Lon
import com.mogo.eagle.core.function.call.obu.CallerObuWarningListenerManager
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import com.mogo.map.MogoMap
@@ -85,6 +86,7 @@ class MapIdentifySubscriber private constructor() : IMoGoSubscriber,
val mogoMap = mapInstance.getMogoMap(MogoMap.DEFAULT)
val pointsList: ArrayList<List<MogoLatLng>> = ArrayList()
var arr: DoubleArray?
var point: geometry.Geometry.Point
// 渲染自车
predictionObjects.objsAppList.forEach { preObj ->
val points = ArrayList<MogoLatLng>()
@@ -113,8 +115,14 @@ class MapIdentifySubscriber private constructor() : IMoGoSubscriber,
MogoIdentifyManager.getInstance().updateGps(location2!!, MogoMap.SMALL_PRED_MAP3)
} else {
if (preObj.predictionTrajectoryList.isNullOrEmpty() || mogoMap == null) return@forEach
point = preObj.predictionTrajectoryList[0].trajectoryPointsList[0]
arr = mogoMap.switchData(point.x, point.y, false)
arr?.let { lonLatArr ->
val distance = com.mogo.eagle.core.utilcode.util.LocationUtils.getDistance(getWgs84Lat(), getWgs84Lon(), lonLatArr[1], lonLatArr[0])
if (distance > 25) return@forEach
}
preObj.predictionTrajectoryList[0].trajectoryPointsList.forEachIndexed { index, point ->
if (index % 2 == 0) {// 步长为2减少点
if (index > 9 && index % 2 == 0) {// 步长为2减少点
arr = mogoMap.switchData(point.x, point.y, false)
arr?.let { lonLatArr ->
points.add(MogoLatLng(lonLatArr[1], lonLatArr[0]))

View File

@@ -12,7 +12,6 @@ import androidx.core.util.Pools;
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager;
import com.mogo.eagle.core.function.call.map.CallerMapIdentifyManager;
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager;
@@ -76,19 +75,14 @@ public class PredictionOverlayDrawer {
private class RenderTask implements Runnable {
// 对象池
private final Pools.Pool<MogoLatLng> pools;
private double bearing;
// private final Pools.Pool<MogoLatLng> pools;
private Polyline.Options mPolylineOptions;
private volatile List<List<MogoLatLng>> mPredPointsList;
private final List<LinkedList<MogoLatLng>> mPointsList;
private List<Polyline.Options> mLineOptList;
public RenderTask() {
this.pools = new Pools.SimplePool<>(1000);
this.mPointsList = new ArrayList<>();
// this.pools = new Pools.SimplePool<>(1000);
mPolylineOptions = new Polyline.Options.Builder("pred_overlay", Level.GUIDE_ROUTE_LINE)
.setUseGps(true)
.setWidth(10)
@@ -98,7 +92,6 @@ public class PredictionOverlayDrawer {
public void setPreDataList(List<List<MogoLatLng>> data, double bearing) {
mPredPointsList = data;
this.bearing = bearing;
}
@SuppressLint("LongLogTag")
@@ -108,12 +101,8 @@ public class PredictionOverlayDrawer {
if (overlayManager == null) {
return;
}
List<LinkedList<MogoLatLng>> poiList = mPointsList;
List<LinkedList<MogoLatLng>> ppsList = new ArrayList<>();
boolean isExcept = false;
int total;
poiList.clear();
List<List<MogoLatLng>> routes1 = this.mPredPointsList;
if (mLineOptList == null) {
mLineOptList = new ArrayList<>();
@@ -122,9 +111,8 @@ public class PredictionOverlayDrawer {
if (latLngList == null || (total = latLngList.size()) < 2) {
return;
}
LinkedList<MogoLatLng> pps = null;
ArrayList<MogoLatLng> pps = new ArrayList<>();
try {
pps = new LinkedList<>();
for (int i = 0; i < total; i++) {
MogoLatLng route = null;
try {
@@ -139,97 +127,40 @@ public class PredictionOverlayDrawer {
//数组越界了,结束循环
break;
}
MogoLatLng acquire = pools.acquire();
MogoLatLng acquire;
double latitude = route.getLat();
double longitude = route.getLon();
if (acquire == null) {
acquire = new MogoLatLng(latitude, longitude);
} else {
acquire.lon = longitude;
acquire.lat = latitude;
}
acquire = new MogoLatLng(latitude, longitude);
acquire.acc = 0.0;// 加速度
acquire.speed = 0.0;// 速度
pps.add(acquire);
}
ppsList.add(pps);
MogoLocation location = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84();
double lon = location.getLongitude();
double lat = location.getLatitude();
if (!pps.isEmpty()) {
MogoLatLng top = null;
while (!pps.isEmpty()) {
MogoLatLng first = pps.peek();
if (first == null) {
continue;
}
if (first == top) {
break;
}
lon = location.getLongitude();
lat = location.getLatitude();
long angle = isPointOnCarFront(lon, lat, bearing, first.lon, first.lat);
if (angle >= 90) {
pools.release(first);
pps.poll();
}
top = first;
}
if (pps.isEmpty()) {
isExcept = true;
return;
}
MogoLatLng self = pools.acquire();
if (self == null) {
self = new MogoLatLng(lat, lon);
} else {
self.lat = lat;
self.lon = lon;
}
pps.addFirst(self);
// 线的配置
Polyline.Options.Builder builder;
if (mPolylineOptions == null) {
builder = new Polyline.Options.Builder("pred_overlay", Level.GUIDE_ROUTE_LINE)
.setUseGps(true)
.setWidth(5)
.setIsGradient(true);
} else {
builder = mPolylineOptions.builder();
}
builder.color(Color.rgb(196, 196, 196));
builder.setIsGradient(false);
builder.setLightOn(false);
builder.setIsDottedLine(true);
builder.isShowArrow(false);
builder.points(pps);
builder.setVisible(true);
Polyline.Options options = builder.build();
if (mPolylineOptions == null) {
mPolylineOptions = options;
}
if (FunctionBuildConfig.isDrawPreIdentifyData && CallerMapIdentifyManager.INSTANCE.isPreViewLoaded()) {
overlayManager.showOrUpdateLine(options, SMALL_PRED_MAP);
}
// 线的配置
Polyline.Options.Builder builder;
if (mPolylineOptions == null) {
builder = new Polyline.Options.Builder("pred_overlay", Level.GUIDE_ROUTE_LINE)
.setUseGps(true)
.setWidth(5)
.setIsGradient(true);
} else {
isExcept = true;
builder = mPolylineOptions.builder();
}
builder.color(Color.rgb(196, 196, 196));
builder.setIsGradient(false);
builder.setLightOn(false);
builder.setIsDottedLine(false);
builder.isShowArrow(false);
builder.points(pps);
builder.setVisible(true);
Polyline.Options options = builder.build();
if (mPolylineOptions == null) {
mPolylineOptions = options;
}
if (FunctionBuildConfig.isDrawPreIdentifyData && CallerMapIdentifyManager.INSTANCE.isPreViewLoaded()) {
overlayManager.showOrUpdateLine(options, SMALL_PRED_MAP);
}
poiList.add(pps);
} catch (Throwable t) {
t.printStackTrace();
} finally {
if (isExcept) {
setVisible(false);
}
if (pps != null && !pps.isEmpty()) {
for (int i = 0; i < pps.size(); i++) {
MogoLatLng latLng = pps.get(i);
if (latLng == null) {
continue;
}
pools.release(latLng);
}
}
}
}
}