Path Primitive |
PathPrimitive is similar to PolylinePrimitive, but it is designed for efficient addition and removal of points to either end of the line. Path primitives can be used to visualize things such as orbits, trail lines, lead lines, and drop lines.
See the HowTo for an example that creates drop lines as seen below:
The following example shows how to create a PathPrimitive, add/remove individual points, and add it to the scene:
PathPrimitive path = new PathPrimitive(); // add points to the back of the path path.AddBack(new PathPoint(new Cartesian(10000000, 10000000, 0), SceneManager.Time, Color.Red)); path.AddBack(new PathPoint(new Cartesian(10000000, 11000000, 0), SceneManager.Time, Color.Blue)); path.AddBack(new PathPoint(new Cartesian(10000000, 12000000, 0), SceneManager.Time, Color.Green)); // render path with three points SceneManager.Primitives.Add(path); Scene.Render(); // remove point from the front of the path path.RemoveFront(); // render path with remaining two points Scene.Render();
PathPoints can be added to either end of the path. Each PathPoint can have a different Color, Translucency, OutlineColor, and OutlineTranslucency. When a PathPoint is added to the PathPrimitive, the primitive does not sort the points by any of the properties mentioned above. The order the points were added to the path is the order they are on the line.
Notice that a PathPoint is an immutable object. The properties can only be set at construction time. Another way to create PathPoints is by using a PathPointBuilder, which has all of the same properties as a PathPoint, but they are mutable. It also contains convenience methods for using Cartographic positions. When finished building, a PathPoint can be created using the ToPathPoint method.
PathPrimitive can add a range of PathPoints to the line as well. The following examples show use of PathPointBuilder and adding a range of points.
PathPointBuilder builder = new PathPointBuilder { Position = new Cartesian(10000000, 0, 0), Date = SceneManager.Time, Color = Color.Blue }; List<PathPoint> points = new List<PathPoint>(); for (int i = 0; i < 20; i++) { builder.Position = builder.Position.Add(new Cartesian(100000.0, 0.0, 0.0)); points.Add(builder.ToPathPoint()); } PathPrimitive path = new PathPrimitive(); path.AddRangeToBack(points); SceneManager.Primitives.Add(path); Scene.Render();
PathPrimitive has other appearance properties that are used in the same way as PolylinePrimitive: PolylineType, Width, DisplayOutline, and OutlineWidth.
In addition, the UpdatePolicy property also allows more direct control over updates. Any class that derives from PathPrimitiveUpdatePolicy can dynamically update the primitive when assigned to the UpdatePolicy property. Several commonly used policies are provided. MaximumCountPathPrimitiveUpdatePolicy, will remove a point from the RemoveLocation of the path when the number of points exceeds the MaximumCount. DurationPathPrimitiveUpdatePolicy will remove a point from the RemoveLocation of the path when the time span between the point's Date and the current Time exceeds the Duration. The following code sample shows how to create your own update policy:
public class DistancePathPrimitiveUpdatePolicy : PathPrimitiveUpdatePolicy { public DistancePathPrimitiveUpdatePolicy(int distance, PathPrimitiveRemoveLocation removeLocation) { Distance = distance; RemoveLocation = removeLocation; } public int Distance { get; set; } public PathPrimitiveRemoveLocation RemoveLocation { get; set; } // remove points from the front/back of the line if the computed // distance is greater than the given distance. public override void Update(PathPrimitive pathPrimitive, JulianDate date) { if (RemoveLocation == PathPrimitiveRemoveLocation.RemoveLocationBack) { while ((pathPrimitive.Front().Position - pathPrimitive.Back().Position).Length > Distance) { pathPrimitive.RemoveBack(); } } else { while ((pathPrimitive.Front().Position - pathPrimitive.Back().Position).Length > Distance) { pathPrimitive.RemoveFront(); } } } }
The following code assigns an update policy to a PathPrimitive:
PathPrimitive path = new PathPrimitive { UpdatePolicy = new DistancePathPrimitiveUpdatePolicy(6000000, PathPrimitiveRemoveLocation.RemoveLocationBack) };
For an example that shows how to create a trail line for a satellite, see the HowTo, which includes an example showing how to add a handler to the SceneManagerTimeChanged that will add a new point to the back of the PathPrimitive at every animation update. It also uses a DurationPathPrimitiveUpdatePolicy to remove points from the front of the line. This technique is useful in real-time scenarios where new data is added to the line while older data is removed so as to not clutter the display with irrelevant data.