Dynamic Updates

Primitives support dynamic updates to their position and other per-position data via Set and SetPartial methods.

Primitives that are defined by a single position, such as ModelPrimitive, provide a Position property, which gets and sets the primitive's position. Primitives that are defined by a list of positions, such as PolylinePrimitive and PointBatchPrimitive, provide both Set and SetPartial methods to update either all of their positions or a subset of them.

Use a Set method to update all of the positions in a primitive. The primitive's old positions will be replaced with the positions passed to Set. The code below shows how to update a polyline with surface points using Set. Perhaps the polyline represents a range ring around an object. When the object moves, the range ring needs to also move, so all of its positions are updated.

[C#] Copy Code
IAgStkGraphicsSurfaceShapesResult shape = manager.Initializers.SurfaceShapes.ComputeCircleCartographic("Earth", ref center, 20000);
Array positions = shape.Positions;
line.Set(ref positions);

Tip: If you plan on calling a Set method frequently, initialize the primitive with SetHint.Frequent as described in the Set Hint Performance Overview.

Use a SetPartial method to update a subset of positions in a primitive. For example, if one point batch primitive represents thousands of objects and only a few dozen move at a time, use SetPartial to update just those positions instead of calling Set to update all of the positions. To call SetPartial, the primitive must be initialized with SetHint.Partial. See the Set Hint Performance Overview.

SetPartial takes a collection of positions. In addition, SetPartial also takes a collection of indices that maps the corresponding position from the position's collection to a position already in the primitive. The following example creates a point batch with 10 positions then updates 4 of the positions with SetPartial.

[C#] Copy Code
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;

Array positions = new object[]
{
     6500000, 0, 0,
     6600000, 0, 0,
     6700000, 0, 0,
     6800000, 0, 0,
     6900000, 0, 0,
     7000000, 0, 0,
     7100000, 0, 0,
     7200000, 0, 0,
     7300000, 0, 0,
     7400000, 0, 0
};

IAgStkGraphicsPointBatchPrimitive batch = manager.Initializers.PointBatchPrimitive.InitializeWithSetHint(AgEStkGraphicsSetHint.eStkGraphicsSetHintPartial);
batch.Set(ref positions);
batch.PixelSize = 5;
manager.Primitives.Add((IAgStkGraphicsPrimitive)batch);

//
// Modify 4 positions with SetPartial
//
Array newPositions = new object[]
{
     8000000, 0, 0,
     8100000, 0, 0,
     8200000, 0, 0,
     8300000, 0, 0
};

Array indices = new object[]
{
     3,6,8,9
};

batch.SetPartialWithIndicesOrder(ref newPositions, ref indices, AgEStkGraphicsIndicesOrderHint.eStkGraphicsIndicesOrderHintSortedAscending);

The indices allow random access updates to positions in the primitives. The indices do not need to be consecutive nor do they need to be sorted, although if you can easily provide positions sorted in ascending order, pass IndicesOrderHint.SortedAscending for best performance.

STK Programming Interface 11.0.1