opt snapshot drawer

This commit is contained in:
tongchenfei
2021-03-11 16:27:51 +08:00
parent ec866667ef
commit 2592333494
3 changed files with 125 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
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;
@@ -16,7 +17,9 @@ 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;
@@ -158,14 +161,127 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
List< CloudRoadData > allDatumsList = new ArrayList<>();
prepareData( data.getAllList(), allDatumsList );
Map< String, String > newMarkersCaches = new ArrayMap<>( allDatumsList.size() );
Map< String, IMogoMarker > newMarkersCaches = new ArrayMap<>( allDatumsList.size() );
for ( CloudRoadData cloudRoadData : allDatumsList ) {
cloudKeyCache.remove( cloudRoadData.getUniqueKey() );
newMarkersCaches.put( cloudRoadData.getUniqueKey(), cloudRoadData.getUniqueKey() );
SimpleHandlerThreadPool.getInstance().post( cloudRoadData );
// cloudKeyCache.remove( cloudRoadData.getUniqueKey() );
// newMarkersCaches.put( cloudRoadData.getUniqueKey(), cloudRoadData.getUniqueKey() );
// SimpleHandlerThreadPool.getInstance().post( cloudRoadData );
renderSnapshotOneFrame(cloudRoadData,newMarkersCaches);
}
SimpleHandlerThreadPool.getInstance().removeDirtyMarker( cloudKeyCache.values() );
cloudKeyCache = newMarkersCaches;
sendMessage(MSG_REMOVE_DIRTY_MARKERS,mAdasRecognizedMarkersCaches);
mAdasRecognizedMarkersCaches = newMarkersCaches;
// SimpleHandlerThreadPool.getInstance().removeDirtyMarker( cloudKeyCache.values() );
// cloudKeyCache = newMarkersCaches;
}
private final Map< String, Boolean > mIsMatchStatusCache = new ArrayMap<>();
private Map< String, IMogoMarker > mAdasRecognizedMarkersCaches = new HashMap<>();
public boolean hasCached( String uniqueKey ) {
return mAdasRecognizedMarkersCaches.containsKey( uniqueKey );
}
/**
* 绘制某个物体的一个数据
*
* @param recognizedListResult
* @param newAdasRecognizedMarkersCaches
*/
private void renderSnapshotOneFrame(CloudRoadData recognizedListResult, Map< String, IMogoMarker > newAdasRecognizedMarkersCaches ) {
// 暂时只显示车辆
if ( !isCarType( recognizedListResult.getType() ) ) {
return;
}
String uniqueKey = recognizedListResult.getUniqueKey();
if ( TextUtils.isEmpty( uniqueKey ) ) {
return;
}
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 );
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( uniqueKey );
CloudRoadData lastPosition = mLastPositions.put( uniqueKey, recognizedListResult );
if ( marker == null || marker.isDestroyed() ) {
marker = drawSnapshotDataMarker( recognizedListResult );
if ( marker == null ) {
return;
}
}
newAdasRecognizedMarkersCaches.put( uniqueKey, marker );
if ( lastPosition != null ) {
long interval = computeAnimDuration( lastPosition.getSystemTime(), recognizedListResult.getSystemTime(), lastPosition.getSatelliteTime(), recognizedListResult.getSatelliteTime() );
MovingPoint startPoint = new MovingPoint();
startPoint.point = new MogoLatLng( lastPosition.getWgslat(), lastPosition.getWgslon() );
startPoint.marker = marker;
startPoint.delay = 0L;
startPoint.angle = ( float ) lastPosition.getHeading();
long cost = System.currentTimeMillis() - start;
final MovingPoint endPoint = new MovingPoint();
endPoint.point = new MogoLatLng( recognizedListResult.getWgslat(), recognizedListResult.getWgslon() );
endPoint.marker = marker;
endPoint.angle = ( float ) recognizedListResult.getHeading();
interval -= cost;
endPoint.delay = interval;
// method 1
final IMogoMarker renderRef = marker;
final long intervalRef = interval;
SimpleHandlerThreadPool.getInstance().postRender( () -> {
renderRef.addDynamicAnchorPosition( endPoint.point, intervalRef );
} );
// method 2
// List< MovingPoint > points = interpolate( startPoint, endPoint, interval );
// Message msg = new Message();
// MovingPoints obj = new MovingPoints();
// obj.points = points;
// msg.obj = obj;
// msg.what = MSG_MOVE_POINTS;
// mRenderThreadHandler.sendMessage( msg );
// Logger.d( TAG, "anim duration: %s, points size = %s", interval, points.size() );
} else {
marker.setRotateAngle( ( ( float ) recognizedListResult.getHeading() ) );
marker.setPosition( recognizedListResult.getWgslat(), recognizedListResult.getWgslon() );
}
SpeedData obj = new SpeedData();
obj.context = mContext;
obj.marker = marker;
obj.speed = recognizedListResult.getSpeed();
SimpleHandlerThreadPool.getInstance().postRender(obj::showSpeed);
}
/**