STK Components for Java 2018 r4

## Dynamic Updates |

Primitives support dynamic updates to their position and other per-position data via set and setPartial methods.

Updating Primitives

Primitives that are defined by a single position, such as
ModelPrimitive, provide a
**Position** (get / set) property,
to get and set 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 given positions. The code below shows how to update a polyline with surface points using set. Suppose the polyline represents a range ring around an object. When the object moves, the range ring must also move, so we must update all of its positions.

Java

```
CentralBody earth = CentralBodiesFacet.getFromContext().getEarth();
SurfaceShapesResult shape = SurfaceShapes.computeCircleCartographic(earth, center, 20000.0);
line.set(shape.getPositions());
```

Tip |
---|

If you plan on calling a set method frequently, initialize the primitive with SetHint.FREQUENT, as described in the Set Hint topic. |

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. In order to call setPartial methods, the primitive must be initialized with SetHint.PARTIAL. See the Set Hint topic for more information.

setPartial methods take a collection of positions, plus a collection of indices that maps the corresponding position to a position already in the primitive. The following example creates a point batch with 10 positions then updates 4 of the positions:

Java

ArrayList<Cartesian> originalPositions = new ArrayList<Cartesian>(); originalPositions.add(new Cartesian(6500000.0, 0.0, 0.0)); originalPositions.add(new Cartesian(6600000.0, 0.0, 0.0)); originalPositions.add(new Cartesian(6700000.0, 0.0, 0.0)); originalPositions.add(new Cartesian(6800000.0, 0.0, 0.0)); originalPositions.add(new Cartesian(6900000.0, 0.0, 0.0)); originalPositions.add(new Cartesian(7000000.0, 0.0, 0.0)); originalPositions.add(new Cartesian(7100000.0, 0.0, 0.0)); originalPositions.add(new Cartesian(7200000.0, 0.0, 0.0)); originalPositions.add(new Cartesian(7300000.0, 0.0, 0.0)); originalPositions.add(new Cartesian(7400000.0, 0.0, 0.0)); PointBatchPrimitive batch = new PointBatchPrimitive(SetHint.PARTIAL); batch.set(originalPositions); batch.setPixelSize(5.0f); SceneManager.getPrimitives().add(batch); // Modify 4 positions with SetPartial ArrayList<Cartesian> newPositions = new ArrayList<Cartesian>(); newPositions.add(new Cartesian(8000000.0, 0.0, 0.0)); newPositions.add(new Cartesian(8100000.0, 0.0, 0.0)); newPositions.add(new Cartesian(8200000.0, 0.0, 0.0)); newPositions.add(new Cartesian(8300000.0, 0.0, 0.0)); ArrayList<Integer> indices = new ArrayList<Integer>(); indices.add(3); indices.add(6); indices.add(8); indices.add(9); batch.setPartial(newPositions, indices, IndicesOrderHint.SORTED_ASCENDING);

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. However, if you can easily provide positions sorted in ascending order, pass IndicesOrderHint.SORTED_ASCENDING for best performance.