Path Primitive

The Path Primitive is similar to the Polyline Primitive, but it is designed for efficient addition and removal of points to either end of the line. The Path Primitive can be used to visualize things such as orbits, trail lines, lead lines, and drop lines.



See the GraphicsHowTo for an example that creates drop lines as seen above.

The following example shows how to create a PathPrimitive, add/remove individual points, and add it to the scene:

[C#] Copy Code
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
IAgStkGraphicsPathPrimitive path = manager.Initializers.PathPrimitive.Initialize();

// add points to the back of the path
Array position = new object[] { 10000000, 10000000, 0 };
path.AddBack(manager.Initializers.PathPoint.InitializeWithDatePositionAndColor(
root.ConversionUtility.NewDate("EpSec", "0"), ref position, Color.Red));
position = new object[] { 10000000, 11000000, 0 };
path.AddBack(manager.Initializers.PathPoint.InitializeWithDatePositionAndColor(
root.ConversionUtility.NewDate("EpSec", "0"), ref position, Color.Blue));
position = new object[] { 10000000, 12000000, 0 };
path.AddBack(manager.Initializers.PathPoint.InitializeWithDatePositionAndColor(
root.ConversionUtility.NewDate("EpSec", "0"), ref position, Color.Green));

// render path with three points
manager.Primitives.Add((IAgStkGraphicsPrimitive)path);
manager.Render();

// remove point from the front of the path
path.RemoveFront();

// render path with remaining two points
manager.Render();

PathPoints can be added to either end of the path. Each PathPoint can have a a different color, translucency, outline color, and outline translucency. When a PathPoint is added to the PathPrimitive, the primitive does not sort the points by any of the properties mentioned above. The order that the points were added to the path is the order that they are on the line.

The PathPrimitive can add a range of PathPoints to the line as well. The following examples show the use of the AddRange method.

[C#] Copy Code
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
IAgStkGraphicsPathPrimitive path = manager.Initializers.PathPrimitive.Initialize();
Array initialPosition = new object[] { 10000000, 0, 0 };
path.AddBack(manager.Initializers.PathPoint.InitializeWithDatePositionAndColor(
root.ConversionUtility.NewDate("EpSec", "0"), ref initialPosition, Color.Blue));

Array points = new object[20];
for (int i = 0; i < 20; i++)
{
     Array position = new object[] { 100000, 0, 0};
     points.SetValue(manager.Initializers.PathPoint.InitializeWithDatePositionAndColor(
     root.ConversionUtility.NewDate("EpSec", "0"), ref position, Color.Blue), i);
}

path.AddRangeToBack(ref points);

manager.Primitives.Add((IAgStkGraphicsPrimitive)path);
manager.Render();

The PathPrimitive has other appearance properties that are used in the same way as the PolylinePrimitive: PolylineType, Width, DisplayOutline, and OutlineWidth.

The PathPrimitive also has a property that allows user-defined updates. Any class that implements the interface PathPrimitiveUpdatePolicy and implements the Update  method can dynamically update the PathPrimitive when assigned to the property. Some built-in update policies are MaximumCountPathPrimitiveUpdatePolicy and DurationPathPrimitiveUpdatePolicy. The MaximumCountPathPrimitiveUpdatePolicy will remove a point from the remove location of the path when the number of points exceeds the maximum count. The DurationPathPrimitiveUpdatePolicy, on the other hand, will remove a point from the remove location of the path when the time span between the point's date and the CurrentTime exceeds the duration. The following code sample shows how a create your own update policy:

[C#] Copy Code
public class DistancePathPrimitiveUpdatePolicy : AgStkGraphicsPathPrimitiveUpdatePolicy
{
     public DistancePathPrimitiveUpdatePolicy(int distance, AgEStkGraphicsPathPrimitiveRemoveLocation removeLocation)
     {
          Distance = distance;
          RemoveLocation = removeLocation;
     }

     public int Distance { get; set; }
     public AgEStkGraphicsPathPrimitiveRemoveLocation RemoveLocation { get; set; }

     // remove points from the front/back of the line if the computed
     // distance is greater than the given distance.
     public void Update(IAgStkGraphicsPathPrimitive PathPrimitive, AGI.STKUtil.IAgDate Date)
     {
          if (RemoveLocation == AgEStkGraphicsPathPrimitiveRemoveLocation.eStkGraphicsRemoveLocationBack)
          {
               while (DistanceBetweenPositions(PathPrimitive.Front().Position, PathPrimitive.Back().Position) > Distance)
               {
                    PathPrimitive.RemoveBack();
               }
          }
          else
          {
               while (DistanceBetweenPositions(PathPrimitive.Front().Position, PathPrimitive.Back().Position) > Distance)
               {
                    PathPrimitive.RemoveFront();
               }
          }
     }

     public int DistanceBetweenPositions(Array position1, Array position2)
     {
          double x1 = (double)position1.GetValue(0);
          double y1 = (double)position1.GetValue(1);
          double z1 = (double)position1.GetValue(2);

          double x2 = (double)position2.GetValue(0);
          double y2 = (double)position2.GetValue(1);
          double z2 = (double)position2.GetValue(2);

          return (int)Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1));
     }
}