优化显示逻辑

This commit is contained in:
wangcongtao
2021-03-16 10:06:48 +08:00
parent 100edfcd54
commit 5e0d18dbc2
21 changed files with 265 additions and 151 deletions

View File

@@ -1,6 +1,7 @@
package com.mogo.module.common.drawer;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
@@ -15,6 +16,7 @@ import com.mogo.module.common.R;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.utils.SimpleHandlerThreadPool;
import com.mogo.realtime.entity.ADASRecognizedResult;
import com.mogo.realtime.entity.CloudRoadData;
import com.mogo.utils.WorkThreadHandler;
import com.mogo.utils.logger.Logger;
@@ -24,6 +26,8 @@ import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import static java.lang.Math.PI;
public
/**
* @author congtaowang
@@ -167,7 +171,10 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
mAdasRecognizedMarkersCaches = newAdasRecognizedMarkersCaches;
}
private final Map< String, Boolean > mIsMatchStatusCache = new ArrayMap<>();
// private final Map< String, Boolean > mIsMatchStatusCache = new ArrayMap<>();
private String markerRes;
private String markerRes2;
/**
* 绘制某个物体的一个数据
@@ -177,7 +184,7 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
*/
private void renderAdasOneFrame( ADASRecognizedResult recognizedListResult, Map< String, IMogoMarker > newAdasRecognizedMarkersCaches ) {
// 暂时只显示车辆
if ( !isCarType( recognizedListResult.type ) ) {
if ( !isRenderType( recognizedListResult.type ) ) {
return;
}
@@ -186,6 +193,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
return;
}
final double lon = recognizedListResult.lon;
final double lat = recognizedListResult.lat;
final long start = System.currentTimeMillis();
double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( recognizedListResult.uuid, recognizedListResult.lon,
@@ -193,31 +202,52 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
recognizedListResult.heading,
true
);
Boolean isMatch = mIsMatchStatusCache.get( uniqueKey );
if ( matchedPoint != null ) {
if ( ( isMatch == null || !isMatch ) ) {
if ( matchedPoint[2] < 0.5 ) {
isMatch = true;
}
} else {
if ( matchedPoint[2] > 1 ) {
isMatch = false;
}
}
if ( isMatch == null ) {
isMatch = false;
}
mIsMatchStatusCache.put( uniqueKey, isMatch );
if ( isMatch ) {
ADASRecognizedResult lastPosition = mLastPositions.remove( uniqueKey );
if ( matchedPoint != null ) {
Logger.d( TAG, "matchPoint %s distance = %s",lineCounter, matchedPoint[2] );
boolean match = matchedPoint[2] < 0.45 && matchedPoint[2] > 0;
if ( lastPosition != null ) {
double _angle = Math.atan2(Math.abs(matchedPoint[0] - lastPosition.lon), Math.abs(matchedPoint[1] - lastPosition.lat)) * (180 / PI);
Logger.d( TAG, "matchPoint %s angel = %s", lineCounter,_angle );
if ( _angle > 22.5 ) {
match = false;
}
}
// mIsMatchStatusCache.put( uniqueKey, match );
if ( match ) {
recognizedListResult.lon = matchedPoint[0];
recognizedListResult.lat = matchedPoint[1];
}
}
mLastPositions.put( uniqueKey, recognizedListResult );
// Boolean isMatch = mIsMatchStatusCache.get( uniqueKey );
// if ( matchedPoint != null ) {
// if ( ( isMatch == null || !isMatch ) ) {
// if ( matchedPoint[2] < 0.5 ) {
// isMatch = true;
// }
// } else {
// if ( matchedPoint[2] > 1 ) {
// isMatch = false;
// }
// }
// if ( isMatch == null ) {
// isMatch = false;
// }
// mIsMatchStatusCache.put( uniqueKey, isMatch );
//
// if ( isMatch ) {
// recognizedListResult.lon = matchedPoint[0];
// recognizedListResult.lat = matchedPoint[1];
// }
// }
Logger.d( "matchRoad", "cost = %s", System.currentTimeMillis() - start );
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( uniqueKey );
ADASRecognizedResult lastPosition = mLastPositions.put( uniqueKey, recognizedListResult );
if ( marker == null || marker.isDestroyed() ) {
marker = drawAdasRecognizedDataMarker( recognizedListResult );
@@ -247,7 +277,40 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
final IMogoMarker renderRef = marker;
final long intervalRef = interval;
SimpleHandlerThreadPool.getInstance().postRender( () -> {
renderRef.addDynamicAnchorPosition( endPoint.point, intervalRef );
renderRef.addDynamicAnchorPosition( endPoint.point, endPoint.angle, intervalRef );
//
// // 原坐标
// MogoMarkerOptions options2 = new MogoMarkerOptions();
// options2.gps( true )
// .position( new MogoLatLng( lat, lon ) )
// .anchor( 0.5f, 0.5f )
// .rotate( endPoint.angle );
// if ( TextUtils.isEmpty( markerRes2 ) ) {
// options2.icon( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.sy ) );
// } else {
// options2.resName( markerRes2 );
// }
// IMogoMarker marker2 = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( TAG, options2 );
// if ( TextUtils.isEmpty( markerRes2 ) ) {
// markerRes2 = marker2.getMarkerResName();
// }
//
// // 匹配坐标
// MogoMarkerOptions options = new MogoMarkerOptions();
// options.gps( true )
// .position( endPoint.point )
// .anchor( 0.5f, 0.5f )
// .rotate( endPoint.angle );
// if ( TextUtils.isEmpty( markerRes ) ) {
// options.icon( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.sr ) );
// } else {
// options.resName( markerRes );
// }
// IMogoMarker marker1 = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( TAG, options );
// if ( TextUtils.isEmpty( markerRes ) ) {
// markerRes = marker1.getMarkerResName();
// }
} );
// method 2
@@ -268,12 +331,14 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
SpeedData obj = new SpeedData();
obj.context = mContext;
obj.marker = marker;
obj.speed = recognizedListResult.speed;
obj.speed = recognizedListResult.speed;//;lineCounter++
msg.obj = obj;
msg.what = MSG_DISPLAY_SPEED;
mRenderThreadHandler.sendMessage( msg );
}
int lineCounter = 0;
/**
* 绘制 marker
*
@@ -286,13 +351,14 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
}
String resIdVal = null;
int resId = getVrModelResId();
int resId = getModelRes( recognizedListResult.type );
resIdVal = resId + "";
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( DataTypes.TYPE_MARKER_ADAS )
.anchor( 0.5f, 0.5f )
.set3DMode( true )
.gps( true )
.anchorColor( getModelRenderColor( CloudRoadData.FROM_ADAS, recognizedListResult.type ) )
.controlAngle( true )
.resName( mMarkerCachesResMd5Values.get( resIdVal ) )
.icon3DRes( resId )
@@ -303,15 +369,6 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
return marker;
}
/**
* 获取 vr 模型资源 id
*
* @return
*/
private int getVrModelResId() {
return R.raw.cargrey;
}
/**
* vr 模式切换
*/

View File

@@ -14,7 +14,9 @@ import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.R;
import com.mogo.module.common.constants.AdasRecognizedType;
import com.mogo.realtime.entity.CloudRoadData;
import com.mogo.utils.WorkThreadHandler;
import java.util.ArrayList;
@@ -103,14 +105,17 @@ class BaseDrawer {
}
/**
* 判断是否是车辆
* 判断是否是绘制内容
*
* @param type
* @return
*/
public boolean isCarType( int type ) {
public boolean isRenderType( int type ) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom( type );
if ( recognizedType == AdasRecognizedType.classIdCar
|| recognizedType == AdasRecognizedType.classIdMoto
|| recognizedType == AdasRecognizedType.classIdBicycle
|| recognizedType == AdasRecognizedType.classIdPerson
|| recognizedType == AdasRecognizedType.classIdTrafficBus
|| recognizedType == AdasRecognizedType.classIdTrafficTruck ) {
return true;
@@ -118,6 +123,53 @@ class BaseDrawer {
return false;
}
/**
* 获取3D锚点模型资源
*
* @param type
* @return
*/
public int getModelRes( int type ) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom( type );
if ( recognizedType == AdasRecognizedType.classIdCar
|| recognizedType == AdasRecognizedType.classIdTrafficBus
|| recognizedType == AdasRecognizedType.classIdTrafficTruck ) {
return R.raw.othercar;
} else if ( recognizedType == AdasRecognizedType.classIdBicycle
|| recognizedType == AdasRecognizedType.classIdMoto ) {
return R.raw.motorbike;
}
return R.raw.people;
}
/**
* @param fromType {@link com.mogo.realtime.entity.CloudRoadData}
* @return
*/
protected String getModelRenderColor( int fromType, int modelType ) {
AdasRecognizedType recognizedType = AdasRecognizedType.valueFrom( modelType );
if ( recognizedType == AdasRecognizedType.classIdCar
|| recognizedType == AdasRecognizedType.classIdTrafficBus
|| recognizedType == AdasRecognizedType.classIdTrafficTruck ) {
if ( fromType == CloudRoadData.FROM_ADAS ) {
// 灰色
return "#D8D8D8FF";
} else if ( fromType == CloudRoadData.FROM_ROAD_UNIT ) {
// 绿色
return "#3FE792FF";
} else {
// 蓝色
return "#5A8DFFFF";
}
} else if ( recognizedType == AdasRecognizedType.classIdBicycle
|| recognizedType == AdasRecognizedType.classIdMoto ) {
// 灰色
return "#D8D8D8FF";
}
// 灰色
return "#D8D8D8FF";
}
private TextView mSpeedView = null;
/**
@@ -215,7 +267,7 @@ class BaseDrawer {
.getMapServiceApi()
.getMapUIController()
.matchRoad( id, lon, lat, angle, true, isRtk );
Log.i("timer-matchRoad", "cost " + (System.currentTimeMillis() - start) + "ms");
Log.i( "timer-matchRoad", "cost " + ( System.currentTimeMillis() - start ) + "ms" );
return matchRoad;
}

View File

@@ -105,7 +105,7 @@ class OnlineCarDrawer {
String sn = MarkerDrawer.getInstance().getPrimaryKeyFromEntity( markerOnlineCar );
IMogoMarker mogoMarker = existCarMap.get( sn );
if ( mogoMarker == null || mogoMarker.isDestroyed() ) {
mogoMarker = MarkerDrawer.getInstance().drawMapMarkerImpl( markerShowEntity, false, MarkerDrawer.MARKER_Z_INDEX_LOW, R.raw.taxi, listener );
mogoMarker = MarkerDrawer.getInstance().drawMapMarkerImpl( markerShowEntity, false, MarkerDrawer.MARKER_Z_INDEX_LOW, R.raw.othercar, listener );
}
if ( mogoMarker != null ) {
mogoMarker.setVisible( true );

View File

@@ -1,7 +1,6 @@
package com.mogo.module.common.drawer;
import android.content.Context;
import android.os.Message;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.view.LayoutInflater;
@@ -17,9 +16,7 @@ import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.R;
import com.mogo.module.common.api.CallChatApi;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.drawer.marker.IMarkerView;
import com.mogo.module.common.utils.SimpleHandlerThreadPool;
import com.mogo.realtime.entity.ADASRecognizedResult;
import com.mogo.realtime.entity.CloudRoadData;
import com.mogo.realtime.entity.MogoSnapshotSetData;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
@@ -189,7 +186,7 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
*/
private void renderSnapshotOneFrame(CloudRoadData recognizedListResult, Map< String, IMogoMarker > newAdasRecognizedMarkersCaches ) {
// 暂时只显示车辆
if ( !isCarType( recognizedListResult.getType() ) ) {
if ( !isRenderType( recognizedListResult.getType() ) ) {
return;
}
@@ -200,33 +197,33 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
final long start = System.currentTimeMillis();
double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( recognizedListResult.getUniqueKey(), recognizedListResult.getWgslon(),
recognizedListResult.getWgslat(),
recognizedListResult.getHeading(),
true
);
Boolean isMatch = mIsMatchStatusCache.get( uniqueKey );
if ( matchedPoint != null ) {
if ( ( isMatch == null || !isMatch ) ) {
if ( matchedPoint[2] < 0.5 ) {
isMatch = true;
}
} else {
if ( matchedPoint[2] > 1 ) {
isMatch = false;
}
}
if ( isMatch == null ) {
isMatch = false;
}
mIsMatchStatusCache.put( uniqueKey, isMatch );
if ( isMatch ) {
recognizedListResult.setWgslon(matchedPoint[0]);
recognizedListResult.setWgslat(matchedPoint[1]);
}
}
Logger.d( "matchRoad", "cost = %s", System.currentTimeMillis() - start );
// double[] matchedPoint = SnapshotSetDataDrawer.getInstance().matchRoad( recognizedListResult.getUniqueKey(), recognizedListResult.getWgslon(),
// recognizedListResult.getWgslat(),
// recognizedListResult.getHeading(),
// true
// );
// Boolean isMatch = mIsMatchStatusCache.get( uniqueKey );
// if ( matchedPoint != null ) {
// if ( ( isMatch == null || !isMatch ) ) {
// if ( matchedPoint[2] < 0.5 ) {
// isMatch = true;
// }
// } else {
// if ( matchedPoint[2] > 1 ) {
// isMatch = false;
// }
// }
// if ( isMatch == null ) {
// isMatch = false;
// }
// mIsMatchStatusCache.put( uniqueKey, isMatch );
//
// if ( isMatch ) {
// recognizedListResult.setWgslon(matchedPoint[0]);
// recognizedListResult.setWgslat(matchedPoint[1]);
// }
// }
// Logger.d( "matchRoad", "cost = %s", System.currentTimeMillis() - start );
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( uniqueKey );
CloudRoadData lastPosition = mLastPositions.put( uniqueKey, recognizedListResult );
@@ -259,7 +256,7 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
final IMogoMarker renderRef = marker;
final long intervalRef = interval;
SimpleHandlerThreadPool.getInstance().postRender( () -> {
renderRef.addDynamicAnchorPosition( endPoint.point, intervalRef );
renderRef.addDynamicAnchorPosition( endPoint.point, endPoint.angle, intervalRef );
} );
// method 2
@@ -350,8 +347,8 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
String resIdVal = null;
if ( MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() ) {
options.set3DMode( true );
options.anchorColor( "#00FF00" );
int resId = getVrModelResId( data );
options.anchorColor( getModelRenderColor( data.getFromType(), data.getType() ) );
int resId = getModelRes( data.getType() );
resIdVal = resId + "";
options.resName( mMarkerCachesResMd5Values.get( resIdVal ) );
options.icon3DRes( resId );
@@ -370,24 +367,6 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
return mMarkerCachesResMd5Values.get( resIdVal );
}
/**
* 获取车辆 3d 模型
*
* @param data 道路数据
* @return 3D车辆模型id
*/
public int getVrModelResId( CloudRoadData data ) {
switch ( data.getFromType() ) {
case CloudRoadData.FROM_ADAS:
return R.raw.cargrey;
case CloudRoadData.FROM_ROAD_UNIT:
return R.raw.cargreen;
case CloudRoadData.FROM_MY_LOCATION:
default:
return R.raw.carblue;
}
}
/**
* 生成 2d marker 资源
*
@@ -456,7 +435,7 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
setChangeCarModeStatus( false );
if ( MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() ) {
marker.getMogoMarkerOptions().set3DMode( true );
int resId = getVrModelResId( cloudRoadData );
int resId = getModelRes( cloudRoadData.getType() );
String resName = get3DCacheId( resId + "" );
if ( TextUtils.isEmpty( resName ) ) {
marker.use3DResource( resId );

View File

@@ -181,7 +181,7 @@ public class SimpleHandlerThreadPool {
// 暂时只显示车辆
if ( TextUtils.isEmpty( cloudRoadData.getSn() ) ) {
if ( !SnapshotSetDataDrawer.getInstance().isCarType( cloudRoadData.getType() ) ) {
if ( !SnapshotSetDataDrawer.getInstance().isRenderType( cloudRoadData.getType() ) ) {
return;
}
}
@@ -288,7 +288,7 @@ public class SimpleHandlerThreadPool {
renderHandler.post( () -> {
// 由于地图现在不支持addDynamicAnchorPosition并发所以工作线程仅做相关计算真正绘制发送到另外一条绘制线程中做
if ( lastPosition != null && !lastPosition.equals( cloudRoadData ) ) {
finalMarker.addDynamicAnchorPosition( new MogoLatLng( cloudRoadData.getWgslat(), cloudRoadData.getWgslon() ), finalInterval );
finalMarker.addDynamicAnchorPosition( new MogoLatLng( cloudRoadData.getWgslat(), cloudRoadData.getWgslon() ),(float)cloudRoadData.getHeading(), finalInterval );
Logger.d( TAG, "anim duration: %s in thread: %s", finalInterval, Thread.currentThread().getName() );
} else {
finalMarker.setRotateAngle( ( float ) cloudRoadData.getHeading() );