balabala~~~

This commit is contained in:
wangcongtao
2020-10-30 14:44:07 +08:00
parent b8a9cf80ab
commit 58e0355da7
34 changed files with 452 additions and 133 deletions

View File

@@ -7,21 +7,46 @@ public
* <p>
* 描述
*/
class AdasRecognizedType {
enum AdasRecognizedType {
//背景
public static final int classIdBackground = 0;
classIdBackground( "background",0 ),
//人
public static final int classIdPerson = 1;
classIdPerson( "person",1 ),
//自行车
public static final int classIdBicycle = 2;
classIdBicycle( "bicycle",2 ),
//小轿车
public static final int classIdCar = 3;
classIdCar( "car",3 ),
//摩托车
public static final int classIdMoto = 4;
classIdMoto( "moto",4 ),
//红绿灯
public static final int classIdTrafficSign = 5;
classIdTrafficSign( "traffic_sign",5 ),
//bus
public static final int classIdTrafficBus = 6;
classIdTrafficBus( "traffic_bus",6 ),
//track
public static final int classIdTrafficTruck = 8;
classIdTrafficTruck( "traffic_truck",8 );
AdasRecognizedType( int code ) {
this.code = code;
}
private String res = "";
private int code = -1;
AdasRecognizedType( String res, int code ) {
this.res = res;
this.code = code;
}
public String getRes() {
return res;
}
public static AdasRecognizedType valueFrom( int code ) {
for ( AdasRecognizedType value : AdasRecognizedType.values() ) {
if ( value.code == code ) {
return value;
}
}
return null;
}
}

View File

@@ -0,0 +1,33 @@
package com.mogo.module.common.constants;
public
/**
* @author congtaowang
* @since 2020/10/29
*
* 车模型类型
*/
enum CarModelType {
Other( "other" ),
OtherLeft( "other_left" ),
OtherRight( "other_right" ),
OtherLeftReverse( "other_left_reverse" ),
OtherRightReverse( "other_right_reverse" ),
OtherReverse( "other_reverse" ),
Self( "self" ),
SelfLeft( "self_left" ),
SelfRight( "self_right" );
private String res;
CarModelType( String res ) {
this.res = res;
}
public String getRes() {
return res;
}
}

View File

@@ -0,0 +1,26 @@
package com.mogo.module.common.constants;
public
/**
* @author congtaowang
* @since 2020/10/29
*
* 描述
*/
enum SafeType {
Normal( "安全" ),
SpeedWarm( "注意/超速" ),
DistanceWarm( "注意/保持车距" ),
SpeedDangerous( "危险/严重超速" ),
DistanceDangerous( "危险/距离过近" );
private String msg;
SafeType( String msg ) {
this.msg = msg;
}
public String getMsg() {
return msg;
}
}

View File

@@ -0,0 +1,24 @@
package com.mogo.module.common.constants;
public
/**
* @author congtaowang
* @since 2020/10/29
*
* 描述
*/
enum VisionMode {
Machine( "user" ),
User( "user" );
private String res;
VisionMode( String res ) {
this.res = res;
}
public String getRes() {
return res;
}
}

View File

@@ -3,16 +3,24 @@ package com.mogo.module.common.drawer;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.ModuleNames;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.R;
import com.mogo.module.common.constants.AdasRecognizedType;
import com.mogo.module.common.constants.CarModelType;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.constants.SafeType;
import com.mogo.module.common.constants.VisionMode;
import com.mogo.module.common.drawer.marker.MarkerResourceManager;
import com.mogo.module.common.entity.CloudRoadData;
import com.mogo.service.adas.entity.ADASRecognizedListResult;
import java.util.ArrayList;
@@ -61,7 +69,7 @@ class AdasRecognizedResultDrawer {
// adas marker 缓存
private Map< String, IMogoMarker > mAdasRecognizedMarkersCaches = new ConcurrentHashMap<>();
public void renderAdasRecognizedResult( List< ADASRecognizedListResult > resultList ) {
public void renderAdasRecognizedResult( List< ADASRecognizedListResult > resultList, boolean machineVision, double curSpeed ) {
if ( resultList == null || resultList.isEmpty() ) {
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).removeMarkers( DataTypes.TYPE_MARKER_ADAS );
return;
@@ -80,9 +88,15 @@ class AdasRecognizedResultDrawer {
marker = mAdasRecognizedMarkersCaches.get( uniqueKey );
}
if ( marker == null || marker.isDestroyed() ) {
marker = drawAdasRecognizedDataMarker( recognizedListResult );
marker = drawAdasRecognizedDataMarker( recognizedListResult, machineVision, curSpeed );
if ( marker == null ) {
continue;
}
mAdasRecognizedMarkersCaches.put( uniqueKey, marker );
}
if ( marker.getObject() instanceof MogoLatLng ) {
marker.setPosition( ( ( MogoLatLng ) marker.getObject() ).lat, ( ( MogoLatLng ) marker.getObject() ).lon );
}
List< MogoLatLng > points = new ArrayList<>();
MogoLatLng endLatLon = null;
@@ -108,7 +122,7 @@ class AdasRecognizedResultDrawer {
points.add( endLatLon = new MogoLatLng( latLng.lat, latLon.lon ) );
}
if ( endLatLon != null ) {
marker.setPosition( endLatLon.lat, endLatLon.lon );
marker.setObject( endLatLon );
}
if ( points.size() >= 1 ) {
marker.startSmooth( points, 1 );
@@ -152,19 +166,56 @@ class AdasRecognizedResultDrawer {
}
}
private IMogoMarker drawAdasRecognizedDataMarker( ADASRecognizedListResult recognizedListResult ) {
private IMogoMarker drawAdasRecognizedDataMarker( ADASRecognizedListResult recognizedListResult,
boolean machineVision,
double curSpeed ) {
if ( recognizedListResult == null ) {
return null;
}
if ( recognizedListResult.type == AdasRecognizedType.classIdBackground ) {
}
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( DataTypes.TYPE_MARKER_ADAS )
.gps( true )
.icon( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.module_common_online_car_vr_middle ) )
.icon( inflateView( recognizedListResult, machineVision, curSpeed ) )
.position( new MogoLatLng( recognizedListResult.latLonList.get( 0 ).lat, recognizedListResult.latLonList.get( 0 ).lon ) );
return MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( DataTypes.TYPE_MARKER_ADAS, options );
}
private View inflateView( ADASRecognizedListResult data, boolean machineVision, double curSpeed ) {
View rootView = LayoutInflater.from( AbsMogoApplication.getApp() ).inflate( R.layout.module_commons_layout_car, null );
SafeType safeType = getSafeType( data, curSpeed );
TextView tv = rootView.findViewById( R.id.module_commons_marker_car_speed );
tv.setText( safeType.getMsg() );
ImageView iv = rootView.findViewById( R.id.module_commons_marker_car_model );
iv.setImageResource( MarkerResourceManager.getMarkerDrawableResId(
machineVision ? VisionMode.Machine : VisionMode.User,
AdasRecognizedType.valueFrom( data.type ),
getCarModelType()
) );
return rootView;
}
private SafeType getSafeType( ADASRecognizedListResult data, double curSpeed ) {
if ( data == null ) {
return SafeType.Normal;
}
if ( data.distanceY < 0.5 || data.distanceY < 0.5 ) {
return SafeType.DistanceDangerous;
}
if ( data.speed > curSpeed * 1.5 ) {
return SafeType.SpeedDangerous;
}
if ( data.distanceY < 1 || data.distanceY < 1 ) {
return SafeType.DistanceDangerous;
}
if ( data.speed > curSpeed * 1.1 ) {
return SafeType.DistanceWarm;
}
return SafeType.Normal;
}
private CarModelType getCarModelType() {
return CarModelType.Self;
}
}

View File

@@ -1,22 +1,24 @@
package com.mogo.module.common.drawer;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.network.Utils;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.ModuleNames;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.R;
import com.mogo.module.common.constants.AdasRecognizedType;
import com.mogo.module.common.constants.CarModelType;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.constants.SafeType;
import com.mogo.module.common.constants.VisionMode;
import com.mogo.module.common.drawer.marker.MarkerResourceManager;
import com.mogo.module.common.entity.CloudLocationInfo;
import com.mogo.module.common.entity.CloudRoadData;
import com.mogo.module.common.entity.MogoSnapshotSetData;
@@ -76,39 +78,47 @@ class SnapshotSetDataDrawer {
*
* @param data
*/
public void renderSnapshotData( MogoSnapshotSetData data, boolean filterAdasData ) {
public void renderSnapshotData( MogoSnapshotSetData data,
boolean machineVision ) {
if ( data == null || data.getAllList() == null || data.getAllList().isEmpty() ) {
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( AbsMogoApplication.getApp() ).removeMarkers( DataTypes.TYPE_MARKER_CLOUD_DATA );
return;
}
purgeCloudSnapshotData( data );
for ( CloudRoadData cloudRoadData : data.getAllList() ) {
List< CloudRoadData > allDatumsList = new ArrayList<>();
if ( machineVision ) {
allDatumsList.addAll( data.getAllList() );
allDatumsList.addAll( data.getNearList() );
} else {
allDatumsList.addAll( data.getAllList() );
}
purgeCloudSnapshotData( allDatumsList );
for ( CloudRoadData cloudRoadData : allDatumsList ) {
if ( cloudRoadData == null ) {
continue;
}
if ( filterAdasData && cloudRoadData.getDistance() < 50 ) {
// 过滤 adas 识别的车辆
continue;
}
IMogoMarker marker = null;
String uniqueKey = cloudRoadData.getUniqueKey();
if ( TextUtils.isEmpty( uniqueKey ) || TextUtils.equals( uniqueKey, Utils.getSn() ) ) {
if ( TextUtils.isEmpty( uniqueKey ) ) {
continue;
}
if ( mCloudSnapshotMarkersCaches.containsKey( uniqueKey ) ) {
marker = mCloudSnapshotMarkersCaches.get( uniqueKey );
}
if ( marker == null || marker.isDestroyed() ) {
marker = drawSnapshotDataMarker( cloudRoadData );
marker = drawSnapshotDataMarker( cloudRoadData, machineVision, data.curSpeed );
if ( marker == null ) {
continue;
}
mCloudSnapshotMarkersCaches.put( uniqueKey, marker );
}
if ( marker.getObject() instanceof MogoLatLng ) {
marker.setPosition( ( ( MogoLatLng ) marker.getObject() ).lat, ( ( MogoLatLng ) marker.getObject() ).lon );
}
MogoLatLng endLatLon = null;
List< MogoLatLng > points = new ArrayList<>();
if ( cloudRoadData.getCoordinates() != null
&& cloudRoadData.getCoordinates().size() > 1 ) {
points.add( new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() ) );
for ( int j = 0; j < cloudRoadData.getCoordinates().size(); j++ ) {
CloudLocationInfo poi = cloudRoadData.getCoordinates().get( j );
if ( poi == null ) {
@@ -123,7 +133,7 @@ class SnapshotSetDataDrawer {
points.add( endLatLon = new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() ) );
}
if ( endLatLon != null ) {
marker.setPosition( endLatLon.lat, endLatLon.lon );
marker.setObject( endLatLon );
}
if ( points.size() >= 1 ) {
marker.startSmooth( points, 1 );
@@ -136,15 +146,15 @@ class SnapshotSetDataDrawer {
*
* @param data
*/
private void purgeCloudSnapshotData( MogoSnapshotSetData data ) {
if ( data == null || data.getAllList() == null || data.getAllList().isEmpty() ) {
private void purgeCloudSnapshotData( List< CloudRoadData > data ) {
if ( data == null || data.isEmpty() ) {
return;
}
if ( mCloudSnapshotMarkersCaches.isEmpty() ) {
return;
}
Map< String, IMogoMarker > existMarker = new HashMap<>();
for ( CloudRoadData cloudRoadData : data.getAllList() ) {
for ( CloudRoadData cloudRoadData : data ) {
if ( cloudRoadData == null ) {
continue;
}
@@ -171,27 +181,55 @@ class SnapshotSetDataDrawer {
}
}
private IMogoMarker drawSnapshotDataMarker( CloudRoadData data ) {
private IMogoMarker drawSnapshotDataMarker( CloudRoadData data, boolean machineVision, double curSpeed ) {
if ( data == null ) {
return null;
}
if ( data.getType() == AdasRecognizedType.classIdBackground ) {
}
Logger.d( TAG, "draw marker uniqueKey = %s", data.getUniqueKey() );
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( DataTypes.TYPE_MARKER_CLOUD_DATA )
.icon( inflateView( data ) )
.icon( inflateView( data, machineVision, curSpeed ) )
.gps( true )
.position( new MogoLatLng( data.getLat(), data.getLon() ) );
return MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( DataTypes.TYPE_MARKER_CLOUD_DATA, options );
}
private View inflateView( CloudRoadData data ) {
private View inflateView( CloudRoadData data, boolean machineVision, double curSpeed ) {
View rootView = LayoutInflater.from( AbsMogoApplication.getApp() ).inflate( R.layout.module_commons_layout_car, null );
TextView tv = rootView.findViewById( R.id.tvSn );
tv.setText( data.getUniqueKey() );
SafeType safeType = getSafeType( data, curSpeed );
TextView tv = rootView.findViewById( R.id.module_commons_marker_car_speed );
tv.setText( safeType.getMsg() );
ImageView iv = rootView.findViewById( R.id.module_commons_marker_car_model );
iv.setImageResource( MarkerResourceManager.getMarkerDrawableResId(
machineVision ? VisionMode.Machine : VisionMode.User,
AdasRecognizedType.valueFrom( data.getType() ),
getCarModelType()
) );
return rootView;
}
private SafeType getSafeType( CloudRoadData data, double curSpeed ) {
if ( data == null ) {
return SafeType.Normal;
}
if ( data.getDistance() < 0.5 ) {
return SafeType.DistanceDangerous;
}
if ( data.getSpeed() > curSpeed * 1.5 ) {
return SafeType.SpeedDangerous;
}
if ( data.getDistance() < 1 ) {
return SafeType.DistanceDangerous;
}
if ( data.getSpeed() > curSpeed * 1.1 ) {
return SafeType.DistanceWarm;
}
return SafeType.Normal;
}
private CarModelType getCarModelType() {
// 根据车道、行驶方向等计算出选用哪个车模图片
return CarModelType.Other;
}
}

View File

@@ -1,13 +1,53 @@
package com.mogo.module.common.drawer.marker;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.module.common.R;
import com.mogo.module.common.constants.AdasRecognizedType;
import com.mogo.module.common.constants.CarModelType;
import com.mogo.module.common.constants.VisionMode;
public
/**
* @author congtaowang
* @since 2020/10/29
* <p>
* 描述
* 描述 按照命名规则用字符串拼接成资源名称的方式拿到图片的id避免枚举
*/
class MarkerResourceManager {
/**
* @param mode
* @param adasRecognizedType
* @param type
* @return
*/
public static int getMarkerDrawableResId( VisionMode mode,
AdasRecognizedType adasRecognizedType,
CarModelType type ) {
if ( mode == null ) {
mode = VisionMode.User;
}
if ( adasRecognizedType == null ) {
adasRecognizedType = AdasRecognizedType.classIdCar;
}
if ( type == null ) {
type = CarModelType.Other;
}
if ( mode == VisionMode.Machine ) {
return R.drawable.module_common_online_car_vr_machine_middle;
}
StringBuilder builder = new StringBuilder();
builder.append( "module_commons" )
.append( "_" ).append( mode.getRes() )
.append( "_" ).append( adasRecognizedType.getRes() )
.append( "_" ).append( type.getRes() );
int id = AbsMogoApplication.getApp().getResources().getIdentifier(
builder.toString(),
"drawable",
AbsMogoApplication.getApp().getPackageName() );
return id == 0 ? R.drawable.module_commons_user_car_other : id;
}
}

View File

@@ -24,43 +24,14 @@ class MogoSnapshotSetData implements Parcelable {
//总数据集合
private List<CloudRoadData> allList;
// 近景adas数据
private List<CloudRoadData> nearList;
//红绿灯
private CloudRoadData trafficLight;
protected MogoSnapshotSetData(Parcel in) {
msgId = in.readString();
time = in.readLong();
expire = in.readLong();
allList = in.createTypedArrayList(CloudRoadData.CREATOR);
trafficLight = in.readParcelable(CloudRoadData.class.getClassLoader());
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(msgId);
dest.writeLong(time);
dest.writeLong(expire);
dest.writeTypedList(allList);
dest.writeParcelable(trafficLight, flags);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<MogoSnapshotSetData> CREATOR = new Creator<MogoSnapshotSetData>() {
@Override
public MogoSnapshotSetData createFromParcel(Parcel in) {
return new MogoSnapshotSetData(in);
}
@Override
public MogoSnapshotSetData[] newArray(int size) {
return new MogoSnapshotSetData[size];
}
};
// 自车速度 本地添加
public double curSpeed = 0.0;
@Override
public String toString() {
@@ -112,4 +83,53 @@ class MogoSnapshotSetData implements Parcelable {
public void setTrafficLight(CloudRoadData trafficLight) {
this.trafficLight = trafficLight;
}
public List< CloudRoadData > getNearList() {
return nearList;
}
public void setNearList( List< CloudRoadData > nearList ) {
this.nearList = nearList;
}
public MogoSnapshotSetData() {
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel( Parcel dest, int flags ) {
dest.writeString( this.msgId );
dest.writeLong( this.time );
dest.writeLong( this.expire );
dest.writeTypedList( this.allList );
dest.writeTypedList( this.nearList );
dest.writeParcelable( this.trafficLight, flags );
dest.writeDouble( this.curSpeed );
}
protected MogoSnapshotSetData( Parcel in ) {
this.msgId = in.readString();
this.time = in.readLong();
this.expire = in.readLong();
this.allList = in.createTypedArrayList( CloudRoadData.CREATOR );
this.nearList = in.createTypedArrayList( CloudRoadData.CREATOR );
this.trafficLight = in.readParcelable( CloudRoadData.class.getClassLoader() );
this.curSpeed = in.readDouble();
}
public static final Creator< MogoSnapshotSetData > CREATOR = new Creator< MogoSnapshotSetData >() {
@Override
public MogoSnapshotSetData createFromParcel( Parcel source ) {
return new MogoSnapshotSetData( source );
}
@Override
public MogoSnapshotSetData[] newArray( int size ) {
return new MogoSnapshotSetData[size];
}
};
}

View File

@@ -155,8 +155,8 @@ public class MapCenterPointStrategy {
aimless.put( "d80x", new MapCenterPoint( 0.5D, 0.5D ) );
aimless.put( "em4", new MapCenterPoint( 0.5D, 0.5D ) );
aimless.put( "e8xx", new MapCenterPoint( 0.5D, 0.5D ) );
aimless.put( "f80x", new MapCenterPoint( 0.5D, 0.5D ) );
aimless.put( "f8xx", new MapCenterPoint( 0.5D, 0.5D ) );
aimless.put( "f80x", new MapCenterPoint( 0.5D, 0.8D ) );
aimless.put( "f8xx", new MapCenterPoint( 0.5D, 0.8D ) );
sVrStrategies.put( Scene.AIMLESS, aimless );
}
@@ -206,8 +206,7 @@ public class MapCenterPointStrategy {
}
public static void resetByChangeMode(){
setMapCenterPointByScene( MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController(),
Scene.AIMLESS);
setMapCenterPointByScene( MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController(), Scene.AIMLESS);
}
/**