机器视觉地图绘制点

This commit is contained in:
wangcongtao
2020-10-28 15:51:49 +08:00
parent f951c62d10
commit 37a465f90f
8 changed files with 90 additions and 31 deletions

View File

@@ -1,151 +0,0 @@
package com.mogo.module.service.marker;
import android.content.Context;
import android.graphics.BitmapFactory;
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.service.MarkerServiceHandler;
import com.mogo.module.service.R;
import com.mogo.module.service.ServiceConst;
import com.mogo.service.adas.entity.ADASRecognizedListResult;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public
/**
* @author congtaowang
* @since 2020/10/28
*
* 绘制adas近景识别到的车辆
*/
class AdasRecognizedResultDrawer {
private static volatile AdasRecognizedResultDrawer sInstance;
private Context mContext;
private AdasRecognizedResultDrawer() {
mContext = AbsMogoApplication.getApp();
}
public static AdasRecognizedResultDrawer getInstance() {
if ( sInstance == null ) {
synchronized ( AdasRecognizedResultDrawer.class ) {
if ( sInstance == null ) {
sInstance = new AdasRecognizedResultDrawer();
}
}
}
return sInstance;
}
public synchronized void release() {
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
// adas marker 缓存
private Map< String, IMogoMarker > mAdasRecognizedMarkersCaches = new ConcurrentHashMap<>();
public void renderAdasRecognizedResult( List< ADASRecognizedListResult > resultList ) {
if ( resultList == null || resultList.isEmpty() ) {
MarkerServiceHandler.getApis().getMapServiceApi().getMarkerManager( mContext ).removeMarkers( ServiceConst.TYPE_MARKER_ADAS );
return;
}
purgeAdasRecognizedData( resultList );
for ( ADASRecognizedListResult recognizedListResult : resultList ) {
if ( recognizedListResult == null ) {
continue;
}
IMogoMarker marker = null;
String uniqueKey = recognizedListResult.uuid;
if ( mAdasRecognizedMarkersCaches.containsKey( uniqueKey ) ) {
marker = mAdasRecognizedMarkersCaches.get( uniqueKey );
}
if ( marker == null || marker.isDestroyed() ) {
marker = drawAdasRecognizedDataMarker( recognizedListResult );
mAdasRecognizedMarkersCaches.put( uniqueKey, marker );
}
if ( recognizedListResult.latLonList != null
|| recognizedListResult.latLonList.size() > 1 ) {
List< MogoLatLng > points = new ArrayList<>();
for ( int j = 0; j < recognizedListResult.latLonList.size(); j++ ) {
ADASRecognizedListResult.LatLon latLon = recognizedListResult.latLonList.get( j );
if ( latLon == null ) {
continue;
}
points.add( new MogoLatLng( latLon.lat, latLon.lon ) );
}
if ( points.size() >= 1 ) {
marker.startSmooth( points, 1000 );
} else {
}
}
}
}
/**
* 过滤adas数据中不存在的 marker
*
* @param resultList
*/
private void purgeAdasRecognizedData( List< ADASRecognizedListResult > resultList ) {
if ( resultList == null || resultList.isEmpty() ) {
return;
}
if ( mAdasRecognizedMarkersCaches.isEmpty() ) {
return;
}
Map< String, IMogoMarker > existMarker = new HashMap<>();
for ( ADASRecognizedListResult recognizedListResult : resultList ) {
if ( recognizedListResult == null ) {
continue;
}
String uniqueKey = recognizedListResult.uuid;
if ( mAdasRecognizedMarkersCaches.containsKey( uniqueKey ) ) {
existMarker.put( uniqueKey, mAdasRecognizedMarkersCaches.get( uniqueKey ) );
}
}
if ( !existMarker.isEmpty() ) {
for ( String key : mAdasRecognizedMarkersCaches.keySet() ) {
if ( !existMarker.containsKey( key ) ) {
try {
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( key );
marker.destroy();
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
}
}
private IMogoMarker drawAdasRecognizedDataMarker( ADASRecognizedListResult recognizedListResult ) {
if ( recognizedListResult == null ) {
return null;
}
if ( recognizedListResult.type == AdasRecognizedType.classIdBackground ) {
}
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( ServiceConst.TYPE_MARKER_ADAS )
.icon( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.map_custom_ic_current_location2 ) )
.position( new MogoLatLng( recognizedListResult.latLonList.get( 0 ).lat, recognizedListResult.latLonList.get( 0 ).lon ) );
return MarkerServiceHandler.getMapService().getMarkerManager( mContext ).addMarker( ModuleNames.CARD_TYPE_ROAD_CONDITION, options );
}
}

View File

@@ -1,7 +1,6 @@
package com.mogo.module.service.marker;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.text.TextUtils;
import android.view.animation.LinearInterpolator;
@@ -17,8 +16,8 @@ import com.mogo.map.marker.anim.OnMarkerAnimationListener;
import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.module.common.ModuleNames;
import com.mogo.module.common.api.CallChatApi;
import com.mogo.module.common.entity.CloudLocationInfo;
import com.mogo.module.common.entity.CloudRoadData;
import com.mogo.module.common.drawer.AdasRecognizedResultDrawer;
import com.mogo.module.common.drawer.SnapshotSetDataDrawer;
import com.mogo.module.common.entity.MarkerCarPois;
import com.mogo.module.common.entity.MarkerCardResult;
import com.mogo.module.common.entity.MarkerExploreWay;
@@ -38,7 +37,6 @@ import com.mogo.module.service.network.RefreshModel;
import com.mogo.module.service.utils.ViewUtils;
import com.mogo.module.service.vrmode.VrModeController;
import com.mogo.service.adas.IMogoADASControlStatusChangedListener;
import com.mogo.service.adas.entity.ADASRecognizedListResult;
import com.mogo.service.connection.IMogoOnMessageListener;
import com.mogo.service.connection.IMogoOnWebSocketMessageListener;
import com.mogo.service.connection.WebSocketMsgType;
@@ -57,7 +55,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* author : donghongyu
@@ -162,7 +159,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
if ( data == null ) {
return;
}
SnapshotSetDataDrawer.getInstance().renderSnapshotData( data );
SnapshotSetDataDrawer.getInstance().renderSnapshotData( data, true );
VrModeController.getInstance().renderMogoSnapshotSetData( data );
}

View File

@@ -1,164 +0,0 @@
package com.mogo.module.service.marker;
import android.content.Context;
import android.graphics.BitmapFactory;
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.entity.CloudLocationInfo;
import com.mogo.module.common.entity.CloudRoadData;
import com.mogo.module.common.entity.MogoSnapshotSetData;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.R;
import com.mogo.module.service.ServiceConst;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public
/**
* @author congtaowang
* @since 2020/10/28
*
* 云端数据绘制
*/
class SnapshotSetDataDrawer {
private static volatile SnapshotSetDataDrawer sInstance;
private Context mContext;
private SnapshotSetDataDrawer() {
mContext = AbsMogoApplication.getApp();
}
public static SnapshotSetDataDrawer getInstance() {
if ( sInstance == null ) {
synchronized ( SnapshotSetDataDrawer.class ) {
if ( sInstance == null ) {
sInstance = new SnapshotSetDataDrawer();
}
}
}
return sInstance;
}
public synchronized void release() {
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
// 云端 marker 缓存
private Map< String, IMogoMarker > mCloudSnapshotMarkersCaches = new ConcurrentHashMap<>();
/**
* 其他车辆、rsu 车辆数据
*
* @param data
*/
public void renderSnapshotData( MogoSnapshotSetData data ) {
if ( data == null || data.getAllList() == null || data.getAllList().isEmpty() ) {
return;
}
purgeCloudSnapshotData( data );
for ( CloudRoadData cloudRoadData : data.getAllList() ) {
if ( cloudRoadData == null ) {
continue;
}
if ( cloudRoadData.getDistance() < 50 ) {
// 过滤 adas 识别的车辆
continue;
}
IMogoMarker marker = null;
String uniqueKey = cloudRoadData.getUniqueKey();
if ( mCloudSnapshotMarkersCaches.containsKey( uniqueKey ) ) {
marker = mCloudSnapshotMarkersCaches.get( uniqueKey );
}
if ( marker == null || marker.isDestroyed() ) {
marker = drawSnapshotDataMarker( cloudRoadData );
mCloudSnapshotMarkersCaches.put( uniqueKey, marker );
}
if ( cloudRoadData.getCoordinates() != null
|| cloudRoadData.getCoordinates().size() > 1 ) {
List< MogoLatLng > points = new ArrayList<>();
for ( int j = 0; j < cloudRoadData.getCoordinates().size(); j++ ) {
CloudLocationInfo poi = cloudRoadData.getCoordinates().get( j );
if ( poi == null ) {
continue;
}
double lat = poi.getLat();
double lng = poi.getLon();
points.add( new MogoLatLng( lat, lng ) );
}
if ( points.size() >= 1 ) {
marker.startSmooth( points, 1000 );
} else {
}
}
}
}
/**
* 过滤本次数据中,不存在的 marker
*
* @param data
*/
private void purgeCloudSnapshotData( MogoSnapshotSetData data ) {
if ( data == null || data.getAllList() == null || data.getAllList().isEmpty() ) {
return;
}
if ( mCloudSnapshotMarkersCaches.isEmpty() ) {
return;
}
Map< String, IMogoMarker > existMarker = new HashMap<>();
for ( CloudRoadData cloudRoadData : data.getAllList() ) {
if ( cloudRoadData == null ) {
continue;
}
String uniqueKey = cloudRoadData.getUniqueKey();
if ( mCloudSnapshotMarkersCaches.containsKey( uniqueKey ) ) {
existMarker.put( uniqueKey, mCloudSnapshotMarkersCaches.get( uniqueKey ) );
}
}
if ( !existMarker.isEmpty() ) {
for ( String key : mCloudSnapshotMarkersCaches.keySet() ) {
if ( !existMarker.containsKey( key ) ) {
try {
IMogoMarker marker = mCloudSnapshotMarkersCaches.remove( key );
marker.destroy();
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
}
}
private IMogoMarker drawSnapshotDataMarker( CloudRoadData data ) {
if ( data == null ) {
return null;
}
if ( data.getType() == AdasRecognizedType.classIdBackground ) {
}
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( ServiceConst.TYPE_MARKER_CLOUD_DATA )
.icon( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.map_custom_ic_current_location2 ) )
.position( new MogoLatLng( data.getLat(), data.getLon() ) );
return MarkerServiceHandler.getMapService().getMarkerManager( mContext ).addMarker( ModuleNames.CARD_TYPE_ROAD_CONDITION, options );
}
}