修改绘制感知数据方式为批量更新数据,尝试解决绘制卡顿的问题
Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
@@ -36,8 +36,8 @@ enum class TrafficTypeEnum(
|
||||
TYPE_TRAFFIC_ID_TA_CHE(
|
||||
3,
|
||||
"他车",
|
||||
R.raw.special_vehicle,
|
||||
R.raw.special_vehicle
|
||||
R.raw.othercar,
|
||||
R.raw.othercar
|
||||
),
|
||||
TYPE_TRAFFIC_ID_MOTO(
|
||||
4,
|
||||
|
||||
BIN
core/mogo-core-res/src/main/res/raw/othercar.nt3d
Normal file
BIN
core/mogo-core-res/src/main/res/raw/othercar.nt3d
Normal file
Binary file not shown.
@@ -3,6 +3,7 @@ package com.mogo.map.impl.custom;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
|
||||
import com.mogo.eagle.core.data.traffic.TrafficData;
|
||||
import com.mogo.map.IMogoMap;
|
||||
import com.mogo.map.IMogoUiSettings;
|
||||
import com.mogo.map.impl.custom.marker.AMapInfoWindowAdapter;
|
||||
@@ -21,7 +22,9 @@ import com.zhidaoauto.map.sdk.open.MapAutoApi;
|
||||
import com.zhidaoauto.map.sdk.open.data.MapDataApi;
|
||||
import com.zhidaoauto.map.sdk.open.data.SinglePointRoadInfo;
|
||||
import com.zhidaoauto.map.sdk.open.marker.Marker;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerHelper;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerOptions;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerSimpleData;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MultiPointOverlayOptions;
|
||||
import com.zhidaoauto.map.sdk.open.poyline.Polyline;
|
||||
import com.zhidaoauto.map.sdk.open.poyline.PolylineOptions;
|
||||
@@ -98,6 +101,42 @@ public class AMapWrapper implements IMogoMap {
|
||||
return mogoMarker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBatchMarkerPositon(ArrayList<TrafficData> optionsArrayList) {
|
||||
if (!checkAMap()) {
|
||||
return;
|
||||
}
|
||||
ArrayList<MarkerSimpleData> markerOptionsArrayList = new ArrayList<>();
|
||||
for (TrafficData mogoMarkerOptions : optionsArrayList) {
|
||||
MarkerSimpleData markerOptions = ObjectUtils.fromTrafficData(mogoMarkerOptions);
|
||||
if (markerOptions == null) {
|
||||
Logger.e(TAG, "marker参数为空");
|
||||
break;
|
||||
}
|
||||
markerOptionsArrayList.add(markerOptions);
|
||||
}
|
||||
|
||||
MarkerHelper.INSTANCE.updateBatchMarkerPositon(markerOptionsArrayList,false,8.0f,0,100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPreVehicleModel(int type, int modelRes) {
|
||||
try {
|
||||
MarkerHelper.INSTANCE.addPreVehicleModel(type, modelRes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMarker(String uuidString) {
|
||||
try {
|
||||
MarkerHelper.INSTANCE.removeMarker(uuidString);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<IMogoMarker> addMarkers(String tag, ArrayList<MogoMarkerOptions> options, boolean moveToCenter) {
|
||||
if (!checkAMap()) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.view.View;
|
||||
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.eagle.core.data.map.MogoLocation;
|
||||
import com.mogo.eagle.core.data.traffic.TrafficData;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.overlay.MogoPolylineOptions;
|
||||
import com.mogo.map.search.geo.MogoGeocodeAddress;
|
||||
@@ -26,6 +27,7 @@ import com.zhidaoauto.map.sdk.open.camera.CameraPosition;
|
||||
import com.zhidaoauto.map.sdk.open.marker.BitmapDescriptor;
|
||||
import com.zhidaoauto.map.sdk.open.marker.BitmapDescriptorFactory;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerOptions;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerSimpleData;
|
||||
import com.zhidaoauto.map.sdk.open.poyline.PolylineOptions;
|
||||
import com.zhidaoauto.map.sdk.open.query.GeocodeAddress;
|
||||
import com.zhidaoauto.map.sdk.open.query.GeocodeQuery;
|
||||
@@ -69,22 +71,6 @@ public class ObjectUtils {
|
||||
}
|
||||
}
|
||||
|
||||
// 吸附到路边
|
||||
// if ( opt.isMatchOnRoadSide() ) {
|
||||
// double coors[] = new double[]{opt.getLongitude(), opt.getLatitude()};
|
||||
// if ( !opt.isGps() ) {
|
||||
// coors = CoordinateUtils.transformGcj02toWgs84( opt.getLatitude(), opt.getLongitude() );
|
||||
// opt.gps( true );
|
||||
// }
|
||||
// if ( coors != null ) {
|
||||
// SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad( ( ( float ) coors[0] ), ( ( float ) coors[1] ), ( ( float ) opt.getRotate() ), true, true );
|
||||
// double data[] = PointInterpolatorUtil.mergeToRoad( coors[0], coors[1], singlePointRoadInfo.getCoords() );
|
||||
// if ( data != null ) {
|
||||
// opt.longitude( data[0] ).latitude( data[1] );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.setGps(opt.isGps())
|
||||
.position(new LonLatPoint(opt.getLongitude(), opt.getLatitude()))
|
||||
@@ -98,13 +84,14 @@ public class ObjectUtils {
|
||||
.infoWindowEnable(opt.isInifoWindowEnable())
|
||||
.scale(opt.getScale())
|
||||
.alpha(opt.getAlpha())
|
||||
// .draggable( opt.isDraggable() )
|
||||
.setInfoWindowOffset(opt.getOffsetX(), opt.getOffsetY())
|
||||
.zIndex(opt.getzIndex());
|
||||
|
||||
try {
|
||||
Color.parseColor(opt.getAnchorColor());
|
||||
markerOptions.anchorColor(opt.getAnchorColor());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
markerOptions.vrEnable(opt.is3DMode());
|
||||
if (!TextUtils.isEmpty(opt.getResName())) {
|
||||
@@ -127,6 +114,24 @@ public class ObjectUtils {
|
||||
return markerOptions;
|
||||
}
|
||||
|
||||
public static MarkerSimpleData fromTrafficData(TrafficData trafficData) {
|
||||
if (trafficData == null) {
|
||||
return null;
|
||||
}
|
||||
MarkerSimpleData markerOptions = null;
|
||||
try {
|
||||
markerOptions = new MarkerSimpleData();
|
||||
markerOptions.setId(Long.parseLong(trafficData.getUuid()));
|
||||
markerOptions.setMarkerType(trafficData.getType().getType());
|
||||
markerOptions.setRotateAngle((float) trafficData.getHeading());
|
||||
markerOptions.setLat(trafficData.getLat());
|
||||
markerOptions.setLon(trafficData.getLon());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return markerOptions;
|
||||
}
|
||||
|
||||
private static BitmapDescriptor getBitmapDescriptorFromMogo(MogoMarkerOptions options) {
|
||||
if (options == null) {
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mogo.map;
|
||||
|
||||
import com.mogo.eagle.core.data.traffic.TrafficData;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.overlay.IMogoPolyline;
|
||||
@@ -39,6 +40,29 @@ public interface IMogoMap {
|
||||
*/
|
||||
IMogoMarker addMarker( String tag, MogoMarkerOptions options );
|
||||
|
||||
|
||||
/**
|
||||
* 批量更新锚点位置
|
||||
*
|
||||
* @param optionsArrayList 锚点集合
|
||||
*/
|
||||
void updateBatchMarkerPositon(ArrayList<TrafficData> optionsArrayList);
|
||||
|
||||
/**
|
||||
* 添加感知使用到的3d模型
|
||||
*
|
||||
* @param type
|
||||
* @param modelRes
|
||||
*/
|
||||
void addPreVehicleModel(int type, int modelRes);
|
||||
|
||||
/**
|
||||
* 要移除的感知数据uuid
|
||||
*
|
||||
* @param uuidString
|
||||
*/
|
||||
void removeMarker(String uuidString);
|
||||
|
||||
/**
|
||||
* 在地图上添一组图片标记(marker)对象,并设置是否改变地图状态以至于所有的marker对象都在当前地图可视区域范围内显示。
|
||||
*
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.map.marker;
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.eagle.core.data.traffic.TrafficData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -34,6 +35,26 @@ public interface IMogoMarkerManager {
|
||||
*/
|
||||
List< IMogoMarker > addMarkers( String tag, ArrayList< MogoMarkerOptions > options, boolean moveToCenter );
|
||||
|
||||
/**
|
||||
* 批量更新锚点位置
|
||||
* @param optionsArrayList 锚点集合
|
||||
*/
|
||||
void updateBatchMarkerPosition(ArrayList<TrafficData> optionsArrayList);
|
||||
|
||||
/**
|
||||
* 添加感知使用到的3d模型
|
||||
* @param type
|
||||
* @param modelRes
|
||||
*/
|
||||
void addPreVehicleModel(int type,int modelRes);
|
||||
|
||||
/**
|
||||
* 要移除的感知数据uuid
|
||||
*
|
||||
* @param uuidString
|
||||
*/
|
||||
void removeMarker(String uuidString);
|
||||
|
||||
/**
|
||||
* 移除某一个类型、某个模块的 markers
|
||||
*
|
||||
|
||||
@@ -20,6 +20,9 @@ import java.util.Observable;
|
||||
*/
|
||||
public class MogoMarkerOptions extends Observable {
|
||||
|
||||
// marker 唯一标记
|
||||
private String uuid;
|
||||
private int markerType;
|
||||
private double latitude;
|
||||
private double longitude;
|
||||
// 设置 Marker覆盖物 的标题
|
||||
@@ -94,7 +97,23 @@ public class MogoMarkerOptions extends Observable {
|
||||
*/
|
||||
private boolean mMatchOnRoadSide = true;
|
||||
|
||||
public MogoMarkerOptions matchOnRoadSide( boolean matchOnRoadSide ) {
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public int getMarkerType() {
|
||||
return markerType;
|
||||
}
|
||||
|
||||
public void setMarkerType(int markerType) {
|
||||
this.markerType = markerType;
|
||||
}
|
||||
|
||||
public MogoMarkerOptions matchOnRoadSide(boolean matchOnRoadSide ) {
|
||||
this.mMatchOnRoadSide = matchOnRoadSide;
|
||||
return this;
|
||||
}
|
||||
@@ -404,7 +423,9 @@ public class MogoMarkerOptions extends Observable {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MogoMarkerOptions{" +
|
||||
"latitude=" + latitude +
|
||||
"uuid='" + uuid + '\'' +
|
||||
", markerType=" + markerType +
|
||||
", latitude=" + latitude +
|
||||
", longitude=" + longitude +
|
||||
", title='" + title + '\'' +
|
||||
", snippet='" + snippet + '\'' +
|
||||
@@ -416,7 +437,7 @@ public class MogoMarkerOptions extends Observable {
|
||||
", visible=" + visible +
|
||||
", inifoWindowEnable=" + inifoWindowEnable +
|
||||
", alpha=" + alpha +
|
||||
" ,scale=" + scale+
|
||||
", scale=" + scale +
|
||||
", isGps=" + isGps +
|
||||
", u=" + u +
|
||||
", v=" + v +
|
||||
@@ -424,6 +445,16 @@ public class MogoMarkerOptions extends Observable {
|
||||
", offsetX=" + offsetX +
|
||||
", offsetY=" + offsetY +
|
||||
", zIndex=" + zIndex +
|
||||
", mIconView=" + mIconView +
|
||||
", mOwner='" + mOwner + '\'' +
|
||||
", mObject=" + mObject +
|
||||
", mAutoManager=" + mAutoManager +
|
||||
", mIcon3DRes=" + mIcon3DRes +
|
||||
", mAnchorColor='" + mAnchorColor + '\'' +
|
||||
", mIs3DMode=" + mIs3DMode +
|
||||
", mIsControlAngle=" + mIsControlAngle +
|
||||
", mResName='" + mResName + '\'' +
|
||||
", mMatchOnRoadSide=" + mMatchOnRoadSide +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.map;
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.eagle.core.data.traffic.TrafficData;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
@@ -51,6 +52,7 @@ public class MogoMarkerManager implements IMogoMarkerManager {
|
||||
try {
|
||||
return MogoMap.getInstance().getMogoMap().addMarker( tag, options );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -60,10 +62,38 @@ public class MogoMarkerManager implements IMogoMarkerManager {
|
||||
try {
|
||||
return MogoMap.getInstance().getMogoMap().addMarkers( tag, options, moveToCenter );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBatchMarkerPosition(ArrayList<TrafficData> optionsArrayList) {
|
||||
try {
|
||||
MogoMap.getInstance().getMogoMap().updateBatchMarkerPositon(optionsArrayList);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPreVehicleModel(int type, int modelRes) {
|
||||
try {
|
||||
MogoMap.getInstance().getMogoMap().addPreVehicleModel(type, modelRes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMarker(String uuidString) {
|
||||
try {
|
||||
MogoMap.getInstance().getMogoMap().removeMarker(uuidString);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeMarkers( String tag ) {
|
||||
|
||||
@@ -1,46 +1,42 @@
|
||||
package com.mogo.module.common.drawer;
|
||||
|
||||
import static com.mogo.cloud.socket.entity.SocketDownDataHelper.FROM_ADAS;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.eagle.core.data.enums.TrafficTypeEnum;
|
||||
import com.mogo.eagle.core.data.traffic.TrafficData;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.constants.AdasRecognizedType;
|
||||
import com.mogo.module.common.constants.DataTypes;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author xiaoyuzhou
|
||||
* @date 2021/10/19 10:45 上午
|
||||
* 域控制器识别信息绘制
|
||||
*/
|
||||
public class IdentifyDataDrawer extends BaseDrawer {
|
||||
|
||||
public class IdentifyDataDrawer {
|
||||
private static final String TAG = "IdentifyDataDrawer";
|
||||
|
||||
protected final Context mContext;
|
||||
private static volatile IdentifyDataDrawer sInstance;
|
||||
|
||||
/**
|
||||
* 上一帧数据的缓存
|
||||
*/
|
||||
private static Map<String, IMogoMarker> mMarkersCaches = new ConcurrentHashMap<>();
|
||||
private static ConcurrentHashMap<String, TrafficData> mMarkersCaches = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 最后一帧数据的缓存
|
||||
* 已经感知不到的脏数据
|
||||
*/
|
||||
private final Map<String, TrafficData> mLastPositions = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, TrafficData> mDirtyPositions = new ConcurrentHashMap<>();
|
||||
|
||||
private IdentifyDataDrawer() {
|
||||
super();
|
||||
mContext = AbsMogoApplication.getApp();
|
||||
addPreVehicleModel();
|
||||
}
|
||||
|
||||
public static IdentifyDataDrawer getInstance() {
|
||||
@@ -63,8 +59,7 @@ public class IdentifyDataDrawer extends BaseDrawer {
|
||||
*
|
||||
* @param resultList adas感知融合数据
|
||||
*/
|
||||
public void renderAdasRecognizedResult(List<TrafficData> resultList) {
|
||||
final long start = System.nanoTime();
|
||||
public void renderAdasRecognizedResult(ArrayList<TrafficData> resultList) {
|
||||
if (resultList == null || resultList.isEmpty() || !DebugConfig.isUseAdasRecognize()) {
|
||||
clearOldMarker();
|
||||
return;
|
||||
@@ -76,95 +71,33 @@ public class IdentifyDataDrawer extends BaseDrawer {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, IMogoMarker> newAdasRecognizedMarkersCaches = new ConcurrentHashMap<>();
|
||||
List<TrafficData> newDiffSet = new ArrayList<>();
|
||||
for (TrafficData recognizedListResult : resultList) {
|
||||
// 循环将集合中的数据提取记录
|
||||
ArrayList<String> trafficDataUuidList = new ArrayList<>();
|
||||
for (TrafficData trafficData : resultList) {
|
||||
trafficDataUuidList.add(trafficData.getUuid());
|
||||
}
|
||||
|
||||
if (isUselessValue(recognizedListResult)) {
|
||||
continue;
|
||||
}
|
||||
if (AdasRecognizedType.valueFrom(recognizedListResult.getType().getType()) == AdasRecognizedType.classIdUnKnow) {
|
||||
continue;
|
||||
}
|
||||
// 复用之前存在的 marker
|
||||
String uniqueKey = recognizedListResult.getUuid();
|
||||
IMogoMarker marker = mMarkersCaches.remove(uniqueKey);
|
||||
if (marker != null && !marker.isDestroyed()) {
|
||||
//Log.d(TAG, "发现缓存marker id : " + uniqueKey);
|
||||
updateCacheMarkerRes(marker, recognizedListResult);
|
||||
renderAdasOneFrame(marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
|
||||
} else {
|
||||
// 新增添加进差集
|
||||
newDiffSet.add(recognizedListResult);
|
||||
// 找出上一针数据中已经不在本次数据中存在的数据
|
||||
for (String uuid : mMarkersCaches.keySet()) {
|
||||
if (!trafficDataUuidList.contains(uuid)) {
|
||||
mDirtyPositions.put(uuid, mMarkersCaches.get(uuid));
|
||||
}
|
||||
}
|
||||
removeUselessMarker(mMarkersCaches);
|
||||
removeUselessLastRecord();
|
||||
int newDiffSetSize = newDiffSet.size();
|
||||
// Log.d(TAG, "原数据量 : " + resultList.size() + " 新增marker数量 : " + newDiffSetSize);
|
||||
// 复用过期 marker
|
||||
if (newDiffSetSize > 0) {
|
||||
for (int i = 0; i < newDiffSetSize; i++) {
|
||||
TrafficData recognizedListResult = newDiffSet.get(i);
|
||||
if (AdasRecognizedType.valueFrom(recognizedListResult.getType().getType()) == AdasRecognizedType.classIdUnKnow) {
|
||||
continue;
|
||||
}
|
||||
String uniqueKey = recognizedListResult.getUuid();
|
||||
IMogoMarker marker = drawAdasRecognizedDataMarker(recognizedListResult);
|
||||
if (marker == null) {
|
||||
continue;
|
||||
}
|
||||
//Log.d(TAG, "新增marker id : " + uniqueKey);
|
||||
renderAdasOneFrame(marker, uniqueKey, recognizedListResult, newAdasRecognizedMarkersCaches);
|
||||
}
|
||||
}
|
||||
mMarkersCaches.clear();
|
||||
mMarkersCaches = newAdasRecognizedMarkersCaches;
|
||||
// Log.d(TAG, "ADAS数据延时绘制 render 接收数据 -> 处理结束 " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)) + "ms");
|
||||
}
|
||||
|
||||
/**
|
||||
* todo 后面涉及到此类变化的数据均改动
|
||||
* 更新缓存Marker的资源
|
||||
*
|
||||
* @param marker
|
||||
* @param recognizedListResult
|
||||
*/
|
||||
private void updateCacheMarkerRes(IMogoMarker marker, TrafficData recognizedListResult) {
|
||||
// 获取3D资源文件
|
||||
int resId = getModelRes(recognizedListResult.getType().getType());
|
||||
String resIdVal = resId + "";
|
||||
// 查询缓存中是否存在
|
||||
String resName = mMarkerCachesResMd5Values.get(resIdVal);
|
||||
// 缓存存在直接试用,节省内存
|
||||
if (!TextUtils.isEmpty(resName)) {
|
||||
if (!TextUtils.equals(resName, marker.getMarkerResName())) {
|
||||
marker.use3DResource(resName);
|
||||
}
|
||||
} else {
|
||||
// 缓存不存在,取出名称进行缓存
|
||||
resName = marker.use3DResource(resId);
|
||||
mMarkerCachesResMd5Values.put(resIdVal, resName);
|
||||
}
|
||||
}
|
||||
// // 移除脏数据
|
||||
// for (String uuid : mDirtyPositions.keySet()) {
|
||||
// MogoApisHandler.getInstance().getApis()
|
||||
// .getMapServiceApi()
|
||||
// .getMarkerManager(mContext)
|
||||
// .removeMarker(uuid);
|
||||
// }
|
||||
|
||||
// 绘制新数据
|
||||
MogoApisHandler.getInstance().getApis()
|
||||
.getMapServiceApi()
|
||||
.getMarkerManager(mContext)
|
||||
.updateBatchMarkerPosition(resultList);
|
||||
|
||||
/**
|
||||
* // todo 最好重新设计一个数据结构,用于多线程数据过期失效的场景,参见redis数据过期
|
||||
* 移除工控机长时间没有下发的数据
|
||||
*/
|
||||
private void removeUselessLastRecord() {
|
||||
if (mLastPositions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Iterator<TrafficData> iterator = mLastPositions.values().iterator();
|
||||
// Log.d(TAG, "EmArrow removeUselessLastRecord size : " + mLastPositions.size());
|
||||
while (iterator.hasNext()) {
|
||||
TrafficData result = iterator.next();
|
||||
long internal = result.getSatelliteTime() - getCurSatelliteTime();
|
||||
if (internal > 3000) { //防止帧率过低导致误删除上一个节点对象,从而出现跳跃现象
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,74 +110,10 @@ public class IdentifyDataDrawer extends BaseDrawer {
|
||||
if (recognizedListResult == null) {
|
||||
return true;
|
||||
}
|
||||
if (nonRenderType(recognizedListResult.getType().getType())) {
|
||||
return true;
|
||||
}
|
||||
String uniqueKey = recognizedListResult.getUuid();
|
||||
return TextUtils.isEmpty(uniqueKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制某个物体的一个数据
|
||||
*
|
||||
* @param recognizedListResult {@link TrafficData}
|
||||
* @param newAdasRecognizedMarkersCaches 缓存集合
|
||||
*/
|
||||
private void renderAdasOneFrame(IMogoMarker marker,
|
||||
String uniqueKey,
|
||||
TrafficData recognizedListResult,
|
||||
Map<String, IMogoMarker> newAdasRecognizedMarkersCaches) {
|
||||
final long start = System.nanoTime();
|
||||
TrafficData lastPosition = mLastPositions.remove(uniqueKey);
|
||||
mLastPositions.put(uniqueKey, recognizedListResult);
|
||||
long interval = 45;
|
||||
if (lastPosition != null) {
|
||||
interval = computeAnimDuration(lastPosition.getSatelliteTime(), recognizedListResult.getSatelliteTime());
|
||||
}
|
||||
final MogoLatLng renderLoc = new MogoLatLng(recognizedListResult.getLat(), recognizedListResult.getLon());
|
||||
long cost = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
|
||||
//Log.d(TAG, "ADAS动画数据 cost : " + cost);
|
||||
final long intervalRef = interval - cost;
|
||||
//Log.d(TAG, "ADAS动画数据 最终赋值 : " + intervalRef + " 两帧间隔 : " + interval + " uuid : " + recognizedListResult.getUuid());
|
||||
|
||||
marker.addDynamicAnchorPosition(renderLoc, (float) recognizedListResult.getHeading(), intervalRef);
|
||||
String carColor = getModelRenderColor(recognizedListResult.getType().getType(), FROM_ADAS, recognizedListResult.getThreatLevel());
|
||||
marker.setAnchorColor(carColor);
|
||||
|
||||
newAdasRecognizedMarkersCaches.put(uniqueKey, marker);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个新 marker
|
||||
*
|
||||
* @param recognizedListResult {@link TrafficData}
|
||||
* @return {@link IMogoMarker}
|
||||
*/
|
||||
private IMogoMarker drawAdasRecognizedDataMarker(TrafficData recognizedListResult) {
|
||||
if (recognizedListResult == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int resId = getModelRes(recognizedListResult.getType().getType());
|
||||
String resIdVal = resId + "";
|
||||
|
||||
String carColor = getModelRenderColor(recognizedListResult.getType().getType(), FROM_ADAS, recognizedListResult.getThreatLevel());
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.owner(DataTypes.TYPE_MARKER_ADAS)
|
||||
.anchor(0.5f, 0.5f)
|
||||
.set3DMode(true)
|
||||
.gps(true)
|
||||
.anchorColor(carColor)
|
||||
.controlAngle(true)
|
||||
.resName(mMarkerCachesResMd5Values.get(resIdVal))
|
||||
.icon3DRes(resId)
|
||||
.rotate((float) recognizedListResult.getHeading())
|
||||
.position(new MogoLatLng(recognizedListResult.getLat(), recognizedListResult.getLon()));
|
||||
IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager(mContext).addMarker(DataTypes.TYPE_MARKER_ADAS, options);
|
||||
cacheMarkerIconResMd5Val(resIdVal, marker);
|
||||
return marker;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除旧的 marker 数据
|
||||
*/
|
||||
@@ -252,6 +121,45 @@ public class IdentifyDataDrawer extends BaseDrawer {
|
||||
if (mMarkersCaches != null) {
|
||||
mMarkersCaches.clear();
|
||||
}
|
||||
mLastPositions.clear();
|
||||
}
|
||||
|
||||
private void addPreVehicleModel() {
|
||||
MogoApisHandler.getInstance().getApis()
|
||||
.getMapServiceApi()
|
||||
.getMarkerManager(mContext)
|
||||
.addPreVehicleModel(TrafficTypeEnum.TYPE_TRAFFIC_ID_WEI_ZHI.getType(),
|
||||
TrafficTypeEnum.TYPE_TRAFFIC_ID_WEI_ZHI.getTraffic3DIconId());
|
||||
MogoApisHandler.getInstance().getApis()
|
||||
.getMapServiceApi()
|
||||
.getMarkerManager(mContext)
|
||||
.addPreVehicleModel(TrafficTypeEnum.TYPE_TRAFFIC_ID_PEOPLE.getType(),
|
||||
TrafficTypeEnum.TYPE_TRAFFIC_ID_PEOPLE.getTraffic3DIconId());
|
||||
MogoApisHandler.getInstance().getApis()
|
||||
.getMapServiceApi()
|
||||
.getMarkerManager(mContext)
|
||||
.addPreVehicleModel(TrafficTypeEnum.TYPE_TRAFFIC_ID_BICYCLE.getType(),
|
||||
TrafficTypeEnum.TYPE_TRAFFIC_ID_BICYCLE.getTraffic3DIconId());
|
||||
MogoApisHandler.getInstance().getApis()
|
||||
.getMapServiceApi()
|
||||
.getMarkerManager(mContext)
|
||||
.addPreVehicleModel(TrafficTypeEnum.TYPE_TRAFFIC_ID_TA_CHE.getType(),
|
||||
TrafficTypeEnum.TYPE_TRAFFIC_ID_TA_CHE.getTraffic3DIconId());
|
||||
MogoApisHandler.getInstance().getApis()
|
||||
.getMapServiceApi()
|
||||
.getMarkerManager(mContext)
|
||||
.addPreVehicleModel(TrafficTypeEnum.TYPE_TRAFFIC_ID_MOTO.getType(),
|
||||
TrafficTypeEnum.TYPE_TRAFFIC_ID_MOTO.getTraffic3DIconId());
|
||||
MogoApisHandler.getInstance().getApis()
|
||||
.getMapServiceApi()
|
||||
.getMarkerManager(mContext)
|
||||
.addPreVehicleModel(TrafficTypeEnum.TYPE_TRAFFIC_ID_BUS.getType(),
|
||||
TrafficTypeEnum.TYPE_TRAFFIC_ID_BUS.getTraffic3DIconId());
|
||||
MogoApisHandler.getInstance().getApis()
|
||||
.getMapServiceApi()
|
||||
.getMarkerManager(mContext)
|
||||
.addPreVehicleModel(TrafficTypeEnum.TYPE_TRAFFIC_ID_TRUCK.getType(),
|
||||
TrafficTypeEnum.TYPE_TRAFFIC_ID_TRUCK.getTraffic3DIconId());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -900,7 +900,7 @@ public class MockIntentHandler implements IntentHandler {
|
||||
}
|
||||
}
|
||||
|
||||
List<TrafficData> trafficData = new ArrayList<>();
|
||||
ArrayList<TrafficData> trafficData = new ArrayList<>();
|
||||
for (BufferedReader reader : readers) {
|
||||
String line = reader.readLine();
|
||||
TrafficData adasRecognizedResult = GsonUtil.objectFromJson(line, TrafficData.class);
|
||||
@@ -936,7 +936,7 @@ public class MockIntentHandler implements IntentHandler {
|
||||
}
|
||||
}
|
||||
|
||||
List<TrafficData> trafficData = new ArrayList<>();
|
||||
ArrayList<TrafficData> trafficData = new ArrayList<>();
|
||||
for (BufferedReader reader : readers2) {
|
||||
String line = reader.readLine();
|
||||
TrafficData adasRecognizedResult = GsonUtil.objectFromJson(line, TrafficData.class);
|
||||
|
||||
Reference in New Issue
Block a user