forked from Unity-Technologies/Robotics-Nav2-SLAM-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoseTrailVisualizer.cs
57 lines (51 loc) · 1.67 KB
/
PoseTrailVisualizer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using RosMessageTypes.Geometry; // Generated message classes
using Unity.Robotics.Visualizations; // Visualizations
using Unity.Robotics.ROSTCPConnector.ROSGeometry; // Coordinate space utilities
using UnityEngine;
public class PoseTrailVisualizer : HistoryDrawingVisualizer<PoseStampedMsg>
{
[SerializeField]
Color m_Color = Color.white;
[SerializeField]
float m_Thickness = 0.1f;
[SerializeField]
string m_Label = "";
public override Action CreateGUI(IEnumerable<Tuple<PoseStampedMsg, MessageMetadata>> messages)
{
return () =>
{
var count = 0;
foreach (var (message, meta) in messages)
{
GUILayout.Label($"Goal #{count}:");
message.pose.GUI();
count++;
}
};
}
public override void Draw(Drawing3d drawing, IEnumerable<Tuple<PoseStampedMsg, MessageMetadata>> messages)
{
var firstPass = true;
var prevPoint = Vector3.zero;
var color = Color.white;
var label = "";
foreach (var (msg, meta) in messages)
{
var point = msg.pose.position.From<FLU>();
if (firstPass)
{
color = VisualizationUtils.SelectColor(m_Color, meta);
label = VisualizationUtils.SelectLabel(m_Label, meta);
firstPass = false;
}
else
{
drawing.DrawLine(prevPoint, point, color, m_Thickness);
}
prevPoint = point;
}
drawing.DrawLabel(label, prevPoint, color);
}
}