Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
5a850f69
Commit
5a850f69
authored
3 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
add selfTest, multiple utilities, manual (partial) deep copy of espdu
parent
c73e72de
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/src/OpenDis7Examples/PduTrack.java
+119
-35
119 additions, 35 deletions
examples/src/OpenDis7Examples/PduTrack.java
with
119 additions
and
35 deletions
examples/src/OpenDis7Examples/PduTrack.java
+
119
−
35
View file @
5a850f69
...
@@ -50,9 +50,13 @@ public class PduTrack
...
@@ -50,9 +50,13 @@ public class PduTrack
{
{
private
String
descriptor
=
new
String
();
private
String
descriptor
=
new
String
();
private
ArrayList
<
Pdu
>
pduList
=
new
ArrayList
<>();
private
ArrayList
<
Pdu
>
pduList
=
new
ArrayList
<>();
private
EntityStatePdu
initialEspdu
;
private
EntityStatePdu
latestEspdu
;
private
Vector3Double
initialLocation
;
private
Vector3Double
latestLocation
;
private
ArrayList
<
Vector3Double
>
waypointsList
=
new
ArrayList
<>();
private
ArrayList
<
Vector3Double
>
waypointsList
=
new
ArrayList
<>();
private
ArrayList
<
EulerAngles
>
a
nglesList
=
new
ArrayList
<>();
private
ArrayList
<
EulerAngles
>
eulerA
nglesList
=
new
ArrayList
<>();
/** timelineList in seconds */
/** timelineList in seconds */
private
ArrayList
<
Float
>
timelineList
=
new
ArrayList
<>();
private
ArrayList
<
Float
>
timelineList
=
new
ArrayList
<>();
...
@@ -92,6 +96,34 @@ public class PduTrack
...
@@ -92,6 +96,34 @@ public class PduTrack
return
this
;
return
this
;
}
}
/**
* @return the initialLocation
*/
public
Vector3Double
getInitialLocation
()
{
if
(
initialLocation
==
null
)
{
System
.
out
.
println
(
TRACE_PREFIX
+
"getInitialLocation() not found, isTrackEmpty()="
+
isTrackEmpty
()
+
", returning 0 0 0"
);
return
new
Vector3Double
();
}
return
initialLocation
;
}
/**
* @return the latestLocation
*/
public
Vector3Double
getLatestLocation
()
{
if
(
latestLocation
==
null
)
{
System
.
out
.
println
(
TRACE_PREFIX
+
"getLatestLocation() not found, isTrackEmpty()="
+
isTrackEmpty
()
+
", returning 0 0 0"
);
return
new
Vector3Double
();
}
return
latestLocation
;
}
/**
* @return the pduList
*/
public
ArrayList
<
Pdu
>
getPduList
()
{
return
pduList
;
}
/**
/**
* @return the waypointsList
* @return the waypointsList
*/
*/
...
@@ -99,10 +131,10 @@ public class PduTrack
...
@@ -99,10 +131,10 @@ public class PduTrack
return
waypointsList
;
return
waypointsList
;
}
}
/**
/**
* @return the
a
nglesList
* @return the
eulerA
nglesList
*/
*/
public
ArrayList
<
EulerAngles
>
getAnglesList
()
{
public
ArrayList
<
EulerAngles
>
get
Euler
AnglesList
()
{
return
a
nglesList
;
return
eulerA
nglesList
;
}
}
/**
/**
* Time in seconds corresponding to each PDU
* Time in seconds corresponding to each PDU
...
@@ -118,7 +150,26 @@ public class PduTrack
...
@@ -118,7 +150,26 @@ public class PduTrack
*/
*/
public
PduTrack
addPdu
(
Pdu
newPdu
)
public
PduTrack
addPdu
(
Pdu
newPdu
)
{
{
pduList
.
add
(
newPdu
);
if
(
newPdu
.
getPduType
()
==
DisPduType
.
ENTITY_STATE
)
{
EntityStatePdu
deepCopyEspdu
=
new
EntityStatePdu
();
deepCopyEspdu
.
setEntityID
(((
EntityStatePdu
)
newPdu
).
getEntityID
());
deepCopyEspdu
.
setForceId
(((
EntityStatePdu
)
newPdu
).
getForceId
());
deepCopyEspdu
.
setEntityType
(((
EntityStatePdu
)
newPdu
).
getEntityType
());
deepCopyEspdu
.
setMarking
(((
EntityStatePdu
)
newPdu
).
getMarking
());
deepCopyEspdu
.
setEntityLocation
(((
EntityStatePdu
)
newPdu
).
getEntityLocation
());
deepCopyEspdu
.
setEntityOrientation
(((
EntityStatePdu
)
newPdu
).
getEntityOrientation
());
pduList
.
add
(
deepCopyEspdu
);
if
(
initialLocation
==
null
)
{
initialEspdu
=
deepCopyEspdu
;
// must save object since pduList might contain more than ESPDUs
initialLocation
=
deepCopyEspdu
.
getEntityLocation
();
}
latestEspdu
=
deepCopyEspdu
;
// must save object since pduList might contain more than ESPDUs
latestLocation
=
deepCopyEspdu
.
getEntityLocation
();
}
else
pduList
.
add
(
newPdu
);
// TODO copy() - careful, must be a new object and not a reference
return
this
;
return
this
;
}
}
/**
/**
...
@@ -127,10 +178,14 @@ public class PduTrack
...
@@ -127,10 +178,14 @@ public class PduTrack
*/
*/
public
PduTrack
clearPduLists
()
public
PduTrack
clearPduLists
()
{
{
pduList
.
clear
();
getPduList
().
clear
();
waypointsList
.
clear
();
waypointsList
.
clear
();
anglesList
.
clear
();
eulerAnglesList
.
clear
();
timelineList
.
clear
();
timelineList
.
clear
();
initialEspdu
=
null
;
latestEspdu
=
null
;
initialLocation
=
null
;
latestLocation
=
null
;
return
this
;
return
this
;
}
}
...
@@ -198,6 +253,14 @@ public class PduTrack
...
@@ -198,6 +253,14 @@ public class PduTrack
// https://stackoverflow.com/questions/16252269/how-to-sort-an-arraylist
// https://stackoverflow.com/questions/16252269/how-to-sort-an-arraylist
return
this
;
return
this
;
}
}
/**
* Determine whether any ESPDUs have been received by this track
* @return whether track is empty
*/
public
boolean
isTrackEmpty
()
{
return
(
getEspduCount
()
==
0
);
}
/**
/**
* Compute track duration in timestamp ticks
* Compute track duration in timestamp ticks
* @return duration in timestamp ticks between initial and final ESPDU timestamps in waypointList
* @return duration in timestamp ticks between initial and final ESPDU timestamps in waypointList
...
@@ -205,9 +268,10 @@ public class PduTrack
...
@@ -205,9 +268,10 @@ public class PduTrack
public
int
getEspduCount
()
public
int
getEspduCount
()
{
{
int
counter
=
0
;
int
counter
=
0
;
for
(
Pdu
nextPdu
:
p
duList
)
for
(
Pdu
nextPdu
:
getP
duList
()
)
{
{
counter
+=
1
;
if
(
nextPdu
.
getPduType
()
==
DisPduType
.
ENTITY_STATE
)
counter
+=
1
;
}
}
return
counter
;
return
counter
;
}
}
...
@@ -222,7 +286,7 @@ public class PduTrack
...
@@ -222,7 +286,7 @@ public class PduTrack
int
durationTicks
=
-
1
;
// used if pduList is empty
int
durationTicks
=
-
1
;
// used if pduList is empty
// must skip through pduList since non-ESPDU PDUs may be present
// must skip through pduList since non-ESPDU PDUs may be present
for
(
Pdu
nextPdu
:
p
duList
)
for
(
Pdu
nextPdu
:
getP
duList
()
)
{
{
if
(
nextPdu
.
getPduType
()
==
DisPduType
.
ENTITY_STATE
)
if
(
nextPdu
.
getPduType
()
==
DisPduType
.
ENTITY_STATE
)
{
{
...
@@ -233,7 +297,7 @@ public class PduTrack
...
@@ -233,7 +297,7 @@ public class PduTrack
}
}
if
((
initialTime
>=
0
)
&&
(
finalTime
>=
0
))
if
((
initialTime
>=
0
)
&&
(
finalTime
>=
0
))
durationTicks
=
(
finalTime
-
initialTime
);
durationTicks
=
(
finalTime
-
initialTime
);
if
(
p
duList
.
isEmpty
())
if
(
getP
duList
()
.
isEmpty
())
{
{
System
.
out
.
println
(
TRACE_PREFIX
+
"getTrackDuration() computed illegal duration="
+
durationTicks
+
" due to empty pdu list"
);
System
.
out
.
println
(
TRACE_PREFIX
+
"getTrackDuration() computed illegal duration="
+
durationTicks
+
" due to empty pdu list"
);
}
}
...
@@ -265,26 +329,27 @@ public class PduTrack
...
@@ -265,26 +329,27 @@ public class PduTrack
{
{
// https://stackoverflow.com/questions/6536094/java-arraylist-copy
// https://stackoverflow.com/questions/6536094/java-arraylist-copy
getW
aypointsList
()
.
clear
();
w
aypointsList
.
clear
();
get
AnglesList
()
.
clear
();
euler
AnglesList
.
clear
();
float
clock
=
0.0f
;
float
clock
=
0.0f
;
for
(
Pdu
nextPdu
:
pduList
)
for
(
int
i
=
0
;
i
<
pduList
.
size
();
i
++
)
{
{
Pdu
nextPdu
=
pduList
.
get
(
i
);
if
(
nextPdu
.
getPduType
()
==
DisPduType
.
ENTITY_STATE
)
if
(
nextPdu
.
getPduType
()
==
DisPduType
.
ENTITY_STATE
)
{
{
EntityStatePdu
espdu
=
(
EntityStatePdu
)
nextPdu
;
EntityStatePdu
espdu
=
(
EntityStatePdu
)
nextPdu
;
getW
aypointsList
()
.
add
(
espdu
.
getEntityLocation
());
w
aypointsList
.
add
(
espdu
.
getEntityLocation
());
get
AnglesList
()
.
add
(
espdu
.
getEntityOrientation
());
euler
AnglesList
.
add
(
espdu
.
getEntityOrientation
());
if
(
defaultWaypointInterval
>
0
)
if
(
defaultWaypointInterval
>
0
)
{
{
timelineList
.
add
(
clock
);
timelineList
.
add
(
clock
);
clock
+=
defaultWaypointInterval
;
clock
+=
defaultWaypointInterval
;
}
}
else
else
{
{
timelineList
.
add
(
espdu
.
getTimestamp
()
*
1.0f
);
// TODO convert
timelineList
.
add
(
espdu
.
getTimestamp
()
*
1.0f
);
// TODO convert
}
}
}
}
}
}
return
this
;
return
this
;
...
@@ -326,9 +391,9 @@ public class PduTrack
...
@@ -326,9 +391,9 @@ public class PduTrack
for
(
int
i
=
0
;
i
<
waypointsList
.
size
();
i
++)
for
(
int
i
=
0
;
i
<
waypointsList
.
size
();
i
++)
{
{
Vector3Double
nextPosition
=
waypointsList
.
get
(
i
);
Vector3Double
nextPosition
=
waypointsList
.
get
(
i
);
sb
.
append
(
String
.
valueOf
(
nextPosition
.
getX
())
+
" "
+
sb
.
append
(
String
.
valueOf
(
nextPosition
.
getX
())
).
append
(
" "
)
String
.
valueOf
(
nextPosition
.
getY
())
+
" "
+
.
append
(
String
.
valueOf
(
nextPosition
.
getY
())
).
append
(
" "
)
String
.
valueOf
(
nextPosition
.
getZ
()));
.
append
(
String
.
valueOf
(
nextPosition
.
getZ
()));
if
(
i
<
waypointsList
.
size
()
-
1
)
if
(
i
<
waypointsList
.
size
()
-
1
)
sb
.
append
(
","
);
sb
.
append
(
","
);
}
}
...
@@ -341,7 +406,7 @@ public class PduTrack
...
@@ -341,7 +406,7 @@ public class PduTrack
/**
/**
* @return the wayPointInterval
* @return the wayPointInterval
*/
*/
public
float
getWay
P
ointInterval
()
{
public
float
get
Default
Way
p
ointInterval
()
{
return
defaultWaypointInterval
;
return
defaultWaypointInterval
;
}
}
...
@@ -349,7 +414,7 @@ public class PduTrack
...
@@ -349,7 +414,7 @@ public class PduTrack
* Set uniform waypoint interval (currently for testing)
* Set uniform waypoint interval (currently for testing)
* @param newWaypointInterval the wayPointInterval to set, in seconds, must be greater than zero
* @param newWaypointInterval the wayPointInterval to set, in seconds, must be greater than zero
* @return same object to permit progressive setters */
* @return same object to permit progressive setters */
public
PduTrack
setWaypointInterval
(
float
newWaypointInterval
)
{
public
PduTrack
set
Default
WaypointInterval
(
float
newWaypointInterval
)
{
if
(
newWaypointInterval
>
0.0
)
if
(
newWaypointInterval
>
0.0
)
this
.
defaultWaypointInterval
=
newWaypointInterval
;
this
.
defaultWaypointInterval
=
newWaypointInterval
;
else
else
...
@@ -372,10 +437,29 @@ public class PduTrack
...
@@ -372,10 +437,29 @@ public class PduTrack
return
this
;
return
this
;
}
}
/** Self test to check basic operation, invoked by main() */
/** Self test to check basic operation, invoked by main()
*/
public
void
selfTest
()
public
void
selfTest
()
{
{
// TODO
System
.
out
.
println
(
TRACE_PREFIX
+
"selfTest() start..."
);
PduTrack
pduTrack
=
new
PduTrack
();
pduTrack
.
setDescriptor
(
"PduTrack selfTest()"
);
pduTrack
.
setDefaultWaypointInterval
(
1.0f
);
EntityStatePdu
espdu
=
new
EntityStatePdu
();
espdu
.
setMarking
(
"PduTrack"
);
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
espdu
.
setEntityLocation
(
i
,
i
,
i
);
pduTrack
.
addPdu
(
espdu
);
}
System
.
out
.
println
(
TRACE_PREFIX
+
"getEspduCount()="
+
pduTrack
.
getEspduCount
());
System
.
out
.
println
(
TRACE_PREFIX
+
"getDefaultWaypointInterval()="
+
pduTrack
.
getDefaultWaypointInterval
());
System
.
out
.
println
(
TRACE_PREFIX
+
"getTrackDurationSeconds()="
+
pduTrack
.
getTrackDurationSeconds
());
System
.
out
.
println
(
TRACE_PREFIX
+
"selfTest() complete."
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment