Please review any and all PUBLIC repositories, groups and associate files. These allow anyone on the Internet to access without authentication. Repository and group owners are responsible for their content and permission settings. Go to your project(s), click on Settings > General and expand the "Visibility, project features, permissions" to change this setting.

DIS reference logs updated

parent 053700de
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package PduStreamTools;
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All
* rights reserved. This work is licensed under the BSD open source license,
* available at https://www.movesinstitute.org/licenses/bsd.html
*
*/
import static PduStreamTools.RecorderBase64.COMMENT_MARKER;
import static PduStreamTools.RecorderBase64.START_COMMENT_MARKER;
import static PduStreamTools.RecorderBase64.STOP_COMMENT_MARKER;
import com.google.common.primitives.Longs;
import edu.nps.moves.dis7.EntityStatePdu;
import edu.nps.moves.dis7.Pdu;
import edu.nps.moves.dis7.enumerations.DISPDUType;
import edu.nps.moves.dis7.util.PduFactory;
import java.io.*;
import java.net.DatagramPacket;
......@@ -27,14 +18,17 @@ import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.file.Path;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Pattern;
/**
* PlayerPlainText.java created on Mar 2, 2020 MOVES Institute Naval Postgraduate
* School, Monterey, CA, USA www.nps.edu
*
* @author Mike Bailey, jmbailey@nps.edu
* @author Tobias Brennenstuhl, tobias.brennenstuhl.gy@nps.edu
*/
public class PlayerPlainText {
private Path disLogDirectory;
......@@ -78,26 +72,13 @@ public class PlayerPlainText {
Arrays.sort(fs, (f1, f2) -> {
return f1.getName().compareTo(f2.getName());
});
dsock = new DatagramSocket();
// -------------------- Begin Variables for Position Interpolator
//Test external SourceCode
CreateX3dInterpolators x3dInterpolators = new CreateX3dInterpolators();
CreateX3dLineSet x3dLineSet = new CreateX3dLineSet();
X3DCreateInterpolators x3dInterpolators = new X3DCreateInterpolators();
X3DCreateLineSet x3dLineSet = new X3DCreateLineSet();
byte[] globalByteBufferForX3dInterPolators = null;
// Boolean firstTimeStamp = true;
// int firstLocalTimeStamp = 0;
//
// double firstLocalX = 0;
// double firstLocalY = 0;
// double firstLocalZ = 0;
//
// LinkedHashMap<Double, Coordinates> testMap = new LinkedHashMap<>();
//
// //Setting up a NumberFormatter for limitting the decimal count to 3
// NumberFormat coordinateNumberFormat = NumberFormat.getInstance(new Locale("en", "US"));
// coordinateNumberFormat.setMaximumFractionDigits(3);
// -------------------- End Variables for Position Interpolator
for (File f : fs) {
......@@ -160,7 +141,7 @@ public class PlayerPlainText {
int tempInt = Integer.parseInt(tempString);
arr[x] = tempInt;
}
// Credit: https://stackoverflow.com/questions/1086054/how-to-convert-int-to-byte
......@@ -218,9 +199,6 @@ public class PlayerPlainText {
//Therefore a shortBuffer is created where only every forth value is stored.
//it must be done with modulo instead of testing for "0" because a "0" could be there as value and not as padding
byte[] bufferShort = new byte[byteBuffer2.array().length / 4];
int bufferShortCounter = 0;
for (int i = 1; i < byteBuffer2.array().length; i++) {
......@@ -235,76 +213,12 @@ public class PlayerPlainText {
}
DatagramPacket packet = new DatagramPacket(bufferShort, bufferShort.length, addr, port);
globalByteBufferForX3dInterPolators = new byte[byteBuffer2.array().length / 4];
globalByteBufferForX3dInterPolators = bufferShort.clone();
dsock.send(packet);
//PDU Factory
// PduFactory pduFactory = new PduFactory();
// Pdu localPdu = null;
//
// if (arr[2] == 1) {
//
// localPdu = pduFactory.createPdu(bufferShort);
//
// // ToDO figure out how to do this! makeEntityStatePDU
// EntityStatePdu localEspdu = pduFactory.makeEntityStatePdu();
// //Put all the data we need into the localEspdu
// ByteBuffer espduBuffer = ByteBuffer.wrap(bufferShort);
// localEspdu.unmarshal(espduBuffer);
//
// double localTimeStamp = 0;
// double localX = 0;
// double localY = 0;
// double localZ = 0;
//
// double localPhi = 0;
// double localPsi = 0;
// double localTheta = 0;
//
// //Store the first timestamp to subtract it from all others
// //Same with X,Y,Z to create a local coordiante system
// if (firstTimeStamp) {
//
// firstLocalTimeStamp = localPdu.getTimestamp();
// localTimeStamp = localPdu.getTimestamp();
// firstLocalX = localEspdu.getEntityLocation().getX();
// firstLocalY = localEspdu.getEntityLocation().getY();
// firstLocalZ = localEspdu.getEntityLocation().getZ();
//
// firstTimeStamp = false;
// }
//
// localTimeStamp = localPdu.getTimestamp();
// localX = localEspdu.getEntityLocation().getX();
// localY = localEspdu.getEntityLocation().getY();
// localZ = localEspdu.getEntityLocation().getZ();
// localPhi = localEspdu.getEntityOrientation().getPhi();
// localPsi = localEspdu.getEntityOrientation().getPsi();
// localTheta = localEspdu.getEntityOrientation().getTheta();
//
// localTimeStamp = localTimeStamp - firstLocalTimeStamp;
// localX = localX - firstLocalX;
// localY = localY - firstLocalY;
// localZ = localZ - firstLocalZ;
//
// //Divide TimeStamp by 1,300,000 to get something close to a second per Unit.
// //According to the DIS standard one tick is 3600/(2^31) seconds ~ 1.6764 µs
// //1,300,000 was derived from a stream that is 61 seconds long. The number was adjusted to get a timesensor with 61 seconds
// //ToDo find the real conversion between TimeStampDelta and seconds
// localTimeStamp = localTimeStamp / 1300000;
//
// //Only add to stream if it is an ESPDU
// //ToDo: Add support for multiple Entities
// if ((localPdu.getPduType() != null) && (localPdu.getPduType() == DISPDUType.ENTITY_STATE)) {
//
// testMap.put((double) localTimeStamp, new Coordinates(localX, localY, localZ, localPhi, localPsi, localTheta));
//
// }
//
// }
x3dInterpolators.addPointsToMap(globalByteBufferForX3dInterPolators);
x3dLineSet.addPointsToMap(globalByteBufferForX3dInterPolators);
pduCount++;
......@@ -320,168 +234,10 @@ public class PlayerPlainText {
line = brdr.readLine();
}
brdr.close();
//
// //Compression of the testMap.
// //Remove all collinear points.
// Compressor regression = new Compressor(testMap);
//
// TreeMap<Double, Coordinates> returnMap = new TreeMap<>();
//
// //To turn of the compression just comment the next line out and the very next in.
// returnMap = regression.doCompression();
// //returnMap.putAll(testMap);
//
//
// //Writing all values from the KeyMap to a proper Position Interpolator String
// System.out.println("Writing Position and Rotation Interpolator");
// Set<Double> keys = returnMap.keySet();
// //Set<Double> keys = tempKeyKeyValueSetPositionInterPolator.keySet();
// String positionKey = "key = '";
// String positionKeyValue = "keyValue = '";
// String positionInterpolatorToCopy = "<PositionInterpolator DEF='EntityPosition' ";
//
// String orientationKeyX = "key = '";
// String orientationKeyValueX = "keyValue = '";
// String orientationInterpolatorToCopyX = "<OrientationInterpolator DEF='EntityOrientationX' ";
//
// String orientationKeyY = "key = '";
// String orientationKeyValueY = "keyValue = '";
// String orientationInterpolatorToCopyY = "<OrientationInterpolator DEF='EntityOrientationY' ";
//
// String orientationKeyZ = "key = '";
// String orientationKeyValueZ = "keyValue = '";
// String orientationInterpolatorToCopyZ = "<OrientationInterpolator DEF='EntityOrientationZ' ";
//
// //Find highest time to do the normalization
// double lastTimeStamp = 0;
//
// for (Double k : keys) {
//
// if (k > lastTimeStamp) {
//
// lastTimeStamp = k;
//
// }
// }
//
// //Normalize all times in the set
// var keyKeyValueSetPositionInterpolator = new LinkedHashMap<Double, String>();
//
// var keyKeyValueSetOrientationInterpolatorX = new LinkedHashMap<Double, String>();
// var keyKeyValueSetOrientationInterpolatorY = new LinkedHashMap<Double, String>();
// var keyKeyValueSetOrientationInterpolatorZ = new LinkedHashMap<Double, String>();
//
// for (Double k : keys) {
//
// String localCoordinateString;
// String localOrientationStringX;
// String localOrientationStringY;
// String localOrientationStringZ;
//
// double tempX = returnMap.get(k).getX();
// double tempY = returnMap.get(k).getY();
// double tempZ = returnMap.get(k).getZ();
//
// double tempPhi = returnMap.get(k).getPhi()/6.28;
// double tempPsi = returnMap.get(k).getPsi()/6.28;
// double tempTheta = returnMap.get(k).getTheta()/6.28;
//
// localCoordinateString = " " + coordinateNumberFormat.format(tempX) + " " + coordinateNumberFormat.format(tempY) + " " + coordinateNumberFormat.format(tempZ);
// localOrientationStringX = " 1 0 0 " + coordinateNumberFormat.format(tempPhi);
// localOrientationStringY = " 0 1 0 " + coordinateNumberFormat.format(tempPsi);
// localOrientationStringZ = " 0 0 1 " + coordinateNumberFormat.format(tempTheta);
//
// keyKeyValueSetPositionInterpolator.put(k / lastTimeStamp, localCoordinateString);
// keyKeyValueSetOrientationInterpolatorX.put(k / lastTimeStamp, localOrientationStringX);
// keyKeyValueSetOrientationInterpolatorY.put(k / lastTimeStamp, localOrientationStringY);
// keyKeyValueSetOrientationInterpolatorZ.put(k / lastTimeStamp, localOrientationStringZ);
//
// }
//
// keys = keyKeyValueSetPositionInterpolator.keySet();
//
// //Setting up the timeSensor
// //Only one timeSensor for both interpolators is needed
// String timeSensor = "<TimeSensor DEF='PduStreamClock' cycleInterval='";
//
// timeSensor += lastTimeStamp;
//
// timeSensor += "' loop = 'true'/>";
//
// //Printing the timeSensor to the console
// System.out.println(timeSensor);
//
// //Setting up PositionInterpolator and OrientationInterpolator
// for (Double k : keys) {
// //System.out.println("Time: " + k + " Position (x,y,z) " + keyKeyValueSetPositionInterpolator.get(k));
//
// //PositionInterpolator
// positionKey += coordinateNumberFormat.format(k) + " ";
// positionKeyValue += keyKeyValueSetPositionInterpolator.get(k) + " ";
//
// //OrientationInterpolator for X
// orientationKeyX += coordinateNumberFormat.format(k) + " ";
// orientationKeyValueX += keyKeyValueSetOrientationInterpolatorX.get(k) + " ";
//
// //OrientationInterpolator for Y
// orientationKeyY += coordinateNumberFormat.format(k) + " ";
// orientationKeyValueY += keyKeyValueSetOrientationInterpolatorY.get(k) + " ";
//
// //OrientationInterpolator for Z
// orientationKeyZ += coordinateNumberFormat.format(k) + " ";
// orientationKeyValueZ += keyKeyValueSetOrientationInterpolatorZ.get(k) + " ";
//
// }
// positionKey += "' ";
// positionKeyValue += "' ";
//
// orientationKeyX += "' ";
// orientationKeyValueX += "' ";
//
// orientationKeyY += "' ";
// orientationKeyValueY += "' ";
//
// orientationKeyZ += "' ";
// orientationKeyValueZ += "' ";
//
// //PositionInterpolator
// positionInterpolatorToCopy += positionKey + "\n";
// positionInterpolatorToCopy += positionKeyValue;
// positionInterpolatorToCopy += "/>";
//
// //PositionInterpolator for X
// orientationInterpolatorToCopyX += orientationKeyX + "\n";
// orientationInterpolatorToCopyX += orientationKeyValueX;
// orientationInterpolatorToCopyX += "/>";
//
// //PositionInterpolator for Y
// orientationInterpolatorToCopyY += orientationKeyY + "\n";
// orientationInterpolatorToCopyY += orientationKeyValueY;
// orientationInterpolatorToCopyY += "/>";
//
// //PositionInterpolator for Z
// orientationInterpolatorToCopyZ += orientationKeyY + "\n";
// orientationInterpolatorToCopyZ += orientationKeyValueZ;
// orientationInterpolatorToCopyZ += "/>";
//
// //Printing PositionInterpolator to the console
// System.out.println(positionInterpolatorToCopy);
//
// //Printing OrientationInterpolator for X to the console
// System.out.println(orientationInterpolatorToCopyX);
//
// //Printing OrientationInterpolator for Y to the console
// System.out.println(orientationInterpolatorToCopyY);
//
// //Printing OrientationInterpolator for Z to the console
// System.out.println(orientationInterpolatorToCopyZ);
x3dInterpolators.makeX3dInterpolator();
x3dLineSet.makeX3dLineSet();
x3dInterpolators.makeX3dInterpolator();
x3dLineSet.makeX3dLineSet();
}
} catch (Exception ex) {
System.err.println("Exception reading/writing pdus: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage());
......
Future Work:
- add support for multiple entities
- connect to Framework that autogenerates nodes (instead of string output)
- add ANT build script for Unit-Testing
\ No newline at end of file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package PduStreamTools;
import com.google.common.primitives.Longs;
......@@ -22,6 +17,13 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
/**
* RecorderPlainText.java created on Mar 2, 2020 MOVES Institute Naval Postgraduate
* School, Monterey, CA, USA www.nps.edu
*
* @author Mike Bailey, jmbailey@nps.edu
* @author Tobias Brennenstuhl, tobias.brennenstuhl.gy@nps.edu
*/
public class RecorderPlainText implements PduReceiver
{
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package PduStreamTools;
/**
* This class is a holder for coordinates and angles of ESPDUs to store them in
* HashMaps
*
* @author Tobias Brennenstuhl
* @author Tobias Brennenstuhl @ NPS
*/
public class Coordinates {
public class X3DCoordinates {
private double x;
private double y;
......@@ -20,7 +15,7 @@ public class Coordinates {
private double psi;
private double theta;
public Coordinates(double x, double y, double z, double phi, double psi, double theta) {
public X3DCoordinates(double x, double y, double z, double phi, double psi, double theta) {
this.setX(x);
this.setY(y);
this.setZ(z);
......@@ -30,7 +25,7 @@ public class Coordinates {
}
public Coordinates() {
public X3DCoordinates() {
this.setX(0.0);
this.setY(0.0);
this.setZ(0.0);
......
......@@ -22,7 +22,7 @@ import java.util.logging.Logger;
*
* @author Tobias Brennenstuhl @ NPS
*/
public class CreateX3dInterpolators {
public class X3DCreateInterpolators {
private byte[] bufferShort;
......@@ -33,14 +33,17 @@ public class CreateX3dInterpolators {
private double firstLocalX = 0;
private double firstLocalY = 0;
private double firstLocalZ = 0;
private double firstLocalPhi = 0;
private double firstLocalPsi = 0;
private double firstLocalTheta = 0;
private LinkedHashMap<Double, Coordinates> testMap = new LinkedHashMap<>();
private LinkedHashMap<Double, X3DCoordinates> testMap = new LinkedHashMap<>();
//Setting up a NumberFormatter for limitting the decimal count to 3
private NumberFormat coordinateNumberFormat = NumberFormat.getInstance(new Locale("en", "US"));
// -------------------- End Variables for Position Interpolator
public CreateX3dInterpolators() {
public X3DCreateInterpolators() {
//3 significant digits equals milimeter position accuracy and 0.001 radians = 0.0572963266634555‬ degrees
coordinateNumberFormat.setMaximumFractionDigits(3);
......@@ -52,71 +55,71 @@ public class CreateX3dInterpolators {
this.bufferShort = localBufferShort.clone();
if (bufferShort[2] == 1) {
//PDU Factory
PduFactory pduFactory = new PduFactory();
Pdu localPdu = null;
localPdu = pduFactory.createPdu(bufferShort);
// ToDO figure out how to do this! makeEntityStatePDU
EntityStatePdu localEspdu = pduFactory.makeEntityStatePdu();
//Put all the data we need into the localEspdu
ByteBuffer espduBuffer = ByteBuffer.wrap(bufferShort);
try {
localEspdu.unmarshal(espduBuffer);
} catch (Exception ex) {
Logger.getLogger(CreateX3dInterpolators.class.getName()).log(Level.SEVERE, null, ex);
}
double localTimeStamp = 0;
double localX = 0;
double localY = 0;
double localZ = 0;
double localPhi = 0;
double localPsi = 0;
double localTheta = 0;
//PDU Factory
PduFactory pduFactory = new PduFactory();
Pdu localPdu = null;
//Store the first timestamp to subtract it from all others
//Same with X,Y,Z to create a local coordiante system
if (firstTimeStamp) {
localPdu = pduFactory.createPdu(bufferShort);
firstLocalTimeStamp = localPdu.getTimestamp();
localTimeStamp = localPdu.getTimestamp();
firstLocalX = localEspdu.getEntityLocation().getX();
firstLocalY = localEspdu.getEntityLocation().getZ();
firstLocalZ = -1*localEspdu.getEntityLocation().getY();
// ToDO figure out how to do this! makeEntityStatePDU
EntityStatePdu localEspdu = pduFactory.makeEntityStatePdu();
//Put all the data we need into the localEspdu
ByteBuffer espduBuffer = ByteBuffer.wrap(bufferShort);
try {
localEspdu.unmarshal(espduBuffer);
} catch (Exception ex) {
Logger.getLogger(X3DCreateInterpolators.class.getName()).log(Level.SEVERE, null, ex);
}
firstTimeStamp = false;
}
double localTimeStamp = 0;
double localX = 0;
double localY = 0;
double localZ = 0;
localTimeStamp = localPdu.getTimestamp();
localX = localEspdu.getEntityLocation().getX();
localY = localEspdu.getEntityLocation().getZ();
localZ = -1*localEspdu.getEntityLocation().getY();
localPhi = localEspdu.getEntityOrientation().getPhi();
localPsi = localEspdu.getEntityOrientation().getPsi();
localTheta = localEspdu.getEntityOrientation().getTheta();
double localPhi = 0;
double localPsi = 0;
double localTheta = 0;
localTimeStamp = localTimeStamp - firstLocalTimeStamp;
localX = localX - firstLocalX;
localY = localY - firstLocalY;
localZ = localZ - firstLocalZ;
//Store the first timestamp to subtract it from all others
//Same with X,Y,Z to create a local coordiante system
if (firstTimeStamp) {
//Divide TimeStamp by 1,300,000 to get something close to a second per Unit.
//According to the DIS standard one tick is 3600/(2^31) seconds ~ 1.6764 µs
//1,300,000 was derived from a stream that is 61 seconds long. The number was adjusted to get a timesensor with 61 seconds
//ToDo find the real conversion between TimeStampDelta and seconds
localTimeStamp = localTimeStamp / 1300000;
firstLocalTimeStamp = localPdu.getTimestamp();
localTimeStamp = localPdu.getTimestamp();
firstLocalX = localEspdu.getEntityLocation().getX();
firstLocalY = localEspdu.getEntityLocation().getZ();
firstLocalZ = -1 * localEspdu.getEntityLocation().getY();
//Only add to stream if it is an ESPDU
//ToDo: Add support for multiple Entities
if ((localPdu.getPduType() != null) && (localPdu.getPduType() == DISPDUType.ENTITY_STATE)) {
firstTimeStamp = false;
}
testMap.put((double) localTimeStamp, new Coordinates(localX, localY, localZ, localPhi, localPsi, localTheta));
localTimeStamp = localPdu.getTimestamp();
localX = localEspdu.getEntityLocation().getX();
localY = localEspdu.getEntityLocation().getZ();
localZ = -1 * localEspdu.getEntityLocation().getY();
localPhi = localEspdu.getEntityOrientation().getPhi();
localPsi = localEspdu.getEntityOrientation().getPsi();
localTheta = localEspdu.getEntityOrientation().getTheta();
localTimeStamp = localTimeStamp - firstLocalTimeStamp;
localX = localX - firstLocalX;
localY = localY - firstLocalY;
localZ = localZ - firstLocalZ;
//Divide TimeStamp by 1,300,000 to get something close to a second per Unit.
//According to the DIS standard one tick is 3600/(2^31) seconds ~ 1.6764 µs
//1,100,000 was derived from a stream that is 83 seconds long. The number was adjusted to get a timesensor with 83 seconds
//ToDo find the real conversion between TimeStampDelta and seconds
localTimeStamp = localTimeStamp / 1100000;
//Only add to stream if it is an ESPDU
//ToDo: Add support for multiple Entities
if ((localPdu.getPduType() != null) && (localPdu.getPduType() == DISPDUType.ENTITY_STATE)) {
testMap.put((double) localTimeStamp, new X3DCoordinates(localX, localY, localZ, localPhi, localPsi, localTheta));
}
}
}
}
......@@ -125,16 +128,16 @@ public class CreateX3dInterpolators {
//Compression of the testMap.
//Remove all collinear points.
SlidingWindowCompression slidingWindowCompression = new SlidingWindowCompression(testMap);
X3DSlidingWindowCompression slidingWindowCompression = new X3DSlidingWindowCompression(testMap);
TreeMap<Double, Coordinates> returnMap = new TreeMap<>();
TreeMap<Double, X3DCoordinates> returnMap = new TreeMap<>();
//To turn of the compression just comment the next line out and the very next in.
returnMap = slidingWindowCompression.doSlidingWindow();
//returnMap.putAll(testMap);
//Writing all values from the KeyMap to a proper Position Interpolator String
System.out.println("Writing Position and Rotation Interpolator");
System.out.println("Writing Position and Orientation Interpolator:");
Set<Double> keys = returnMap.keySet();
//Set<Double> keys = tempKeyKeyValueSetPositionInterPolator.keySet();
String positionKey = "key = '";
......@@ -152,7 +155,12 @@ public class CreateX3dInterpolators {
String orientationKeyZ = "key = '";
String orientationKeyValueZ = "keyValue = '";
String orientationInterpolatorToCopyZ = "<OrientationInterpolator DEF='EntityOrientationZ' ";
String waypointInterpolatorWayPoints = "value = '";
String waypointInterpolatorLegDurations = "value = '";
String waypointInterpolatorWayPointsToCopy = "<fieldValue name='waypoints' ";
String waypointInterpolatorLegDurationsToCopy = "<fieldValue name='legDurations' ";
//Find highest time to do the normalization
double lastTimeStamp = 0;
......@@ -171,13 +179,18 @@ public class CreateX3dInterpolators {
var keyKeyValueSetOrientationInterpolatorX = new LinkedHashMap<Double, String>();
var keyKeyValueSetOrientationInterpolatorY = new LinkedHashMap<Double, String>();
var keyKeyValueSetOrientationInterpolatorZ = new LinkedHashMap<Double, String>();
var waypointInterpolatorValueSet = new LinkedHashMap<Double, String>();
double kLegduration = 0;
for (Double k : keys) {
String localCoordinateString;
String localOrientationStringX;
String localOrientationStringY;
String localOrientationStringZ;
String localWaypointInterpolator;