Skip to content

Commit

Permalink
Fix Path visualization.
Browse files Browse the repository at this point in the history
It's only for SampledProperty for now.
  • Loading branch information
mramato committed Aug 15, 2013
1 parent c412d84 commit 7966abc
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Source/DynamicScene/CzmlDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ define([
DynamicEllipsoid.processCzmlPacket,
DynamicCone.processCzmlPacket,
DynamicLabel.processCzmlPacket,
//DynamicPath.processCzmlPacket,
DynamicPath.processCzmlPacket,
DynamicPoint.processCzmlPacket,
DynamicPolygon.processCzmlPacket,
DynamicPolyline.processCzmlPacket,
Expand Down
95 changes: 92 additions & 3 deletions Source/DynamicScene/DynamicPathVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define([
'../Core/Color',
'../Core/Transforms',
'../Core/ReferenceFrame',
'./SampledPositionProperty',
'../Scene/Material',
'../Scene/SceneMode',
'../Scene/PolylineCollection'
Expand All @@ -22,11 +23,99 @@ define([
Color,
Transforms,
ReferenceFrame,
SampledPositionProperty,
Material,
SceneMode,
PolylineCollection) {
"use strict";

function getValueRangeInReferenceFrame(positionProperty, start, stop, currentTime, referenceFrame, maximumStep, result) {
var times = positionProperty._property._times;

if (!defined(start)) {
throw new DeveloperError('start is required');
}

if (!defined(stop)) {
throw new DeveloperError('stop is required');
}

if (!defined(result)) {
result = [];
}

var r = 0;
//Always step exactly on start (but only use it if it exists.)
var tmp;
tmp = positionProperty.getValueInReferenceFrame(start, referenceFrame, result[r]);
if (defined(tmp)) {
result[r++] = tmp;
}

var steppedOnNow = !defined(currentTime) || currentTime.lessThan(start) || currentTime.greaterThan(stop);

//Iterate over all interval times and add the ones that fall in our
//time range. Note that times can contain data outside of
//the intervals range. This is by design for use with interpolation.
var t = 0;
var len = times.length;
var current = times[t];
var loopStop = stop;
var sampling = false;
var sampleStepsToTake;
var sampleStepsTaken;
var sampleStepSize;

while (t < len) {
if (!steppedOnNow && current.greaterThanOrEquals(currentTime)) {
tmp = positionProperty.getValueInReferenceFrame(currentTime, referenceFrame, result[r]);
if (defined(tmp)) {
result[r++] = tmp;
}
steppedOnNow = true;
}
if (current.greaterThan(start) && current.lessThan(loopStop)) {
tmp = positionProperty.getValueInReferenceFrame(current, referenceFrame, result[r]);
if (defined(tmp)) {
result[r++] = tmp;
}
}

if (t < (len - 1)) {
if (!sampling) {
var next = times[t + 1];
var secondsUntilNext = current.getSecondsDifference(next);
sampling = secondsUntilNext > maximumStep;

if (sampling) {
sampleStepsToTake = Math.floor(secondsUntilNext / maximumStep);
sampleStepsTaken = 0;
sampleStepSize = secondsUntilNext / Math.max(sampleStepsToTake, 2);
sampleStepsToTake = Math.max(sampleStepsToTake - 2, 1);
}
}

if (sampling && sampleStepsTaken < sampleStepsToTake) {
current = current.addSeconds(sampleStepSize);
sampleStepsTaken++;
continue;
}
}
sampling = false;
t++;
current = times[t];
}

//Always step exactly on stop (but only use it if it exists.)
tmp = positionProperty.getValueInReferenceFrame(stop, referenceFrame, result[r]);
if (defined(tmp)) {
result[r++] = tmp;
}

result.length = r;
return result;
}

var toFixedScratch = new Matrix3();
var PolylineUpdater = function(scene, referenceFrame) {
this._unusedIndexes = [];
Expand All @@ -53,7 +142,7 @@ define([
}

var positionProperty = dynamicObject.position;
if (!defined(positionProperty)) {
if (!(positionProperty instanceof SampledPositionProperty)) {
return;
}

Expand Down Expand Up @@ -160,7 +249,7 @@ define([
resolution = property.getValue(time);
}

polyline.setPositions(positionProperty._getValueRangeInReferenceFrame(sampleStart, sampleStop, time, this._referenceFrame, resolution, polyline.getPositions()));
polyline.setPositions(getValueRangeInReferenceFrame(positionProperty, sampleStart, sampleStop, time, this._referenceFrame, resolution, polyline.getPositions()));

property = dynamicPath.color;
if (defined(property)) {
Expand Down Expand Up @@ -313,7 +402,7 @@ define([

var frameToVisualize = ReferenceFrame.FIXED;
if (this._scene.mode === SceneMode.SCENE3D) {
frameToVisualize = positionProperty.getReferenceFrame();
frameToVisualize = positionProperty.referenceFrame;
}

var currentUpdater = this._updaters[frameToVisualize];
Expand Down

0 comments on commit 7966abc

Please sign in to comment.