Skip to content

Commit

Permalink
Merge pull request #547 from AnalyticalGraphicsInc/pathResolution
Browse files Browse the repository at this point in the history
Path visualization improvements
  • Loading branch information
shunter committed Mar 8, 2013
2 parents 3d85e30 + 5d75604 commit bc61450
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -10,6 +10,7 @@ Beta Releases
*
* Added `BoundingSphere.fromCornerPoints`.
* Added `fromArray` and `distance` functions to `Cartesian2`, `Cartesian3`, and `Cartesian4`.
* Added `DynamicPath.resolution` property for setting the maximum step size, in seconds, to take when sampling a position for path visualization.

### b14 - 2013-03-01

Expand Down
15 changes: 15 additions & 0 deletions Source/DynamicScene/DynamicPath.js
Expand Up @@ -56,6 +56,11 @@ function(
* @type DynamicProperty
*/
this.width = undefined;
/**
* A DynamicProperty of type CzmlNumber which determines the maximum step size, in seconds, to take when sampling the position.
* @type DynamicProperty
*/
this.resolution = undefined;
/**
* A DynamicProperty of type CzmlNumber which determines the number of seconds in front of the object to show.
* @type DynamicProperty
Expand Down Expand Up @@ -119,6 +124,15 @@ function(
width.processCzmlIntervals(pathData.width, interval);
}

if (typeof pathData.resolution !== 'undefined') {
var resolution = path.resolution;
if (typeof resolution === 'undefined') {
path.resolution = resolution = new DynamicProperty(CzmlNumber);
pathUpdated = true;
}
resolution.processCzmlIntervals(pathData.resolution, interval);
}

if (typeof pathData.outlineColor !== 'undefined') {
var outlineColor = path.outlineColor;
if (typeof outlineColor === 'undefined') {
Expand Down Expand Up @@ -189,6 +203,7 @@ function(

targetpath.color = defaultValue(targetpath.color, pathToMerge.color);
targetpath.width = defaultValue(targetpath.width, pathToMerge.width);
targetpath.resolution = defaultValue(targetpath.resolution, pathToMerge.resolution);
targetpath.outlineColor = defaultValue(targetpath.outlineColor, pathToMerge.outlineColor);
targetpath.outlineWidth = defaultValue(targetpath.outlineWidth, pathToMerge.outlineWidth);
targetpath.show = defaultValue(targetpath.show, pathToMerge.show);
Expand Down
9 changes: 8 additions & 1 deletion Source/DynamicScene/DynamicPathVisualizer.js
Expand Up @@ -144,7 +144,14 @@ define([
}

polyline.setShow(true);
polyline.setPositions(positionProperty._getValueRangeInReferenceFrame(sampleStart, sampleStop, time, this._referenceFrame, 60.0, polyline.getPositions()));

var resolution = 60.0;
property = dynamicPath.resolution;
if (typeof property !== 'undefined') {
resolution = property.getValue(time);
}

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

property = dynamicPath.color;
if (typeof property !== 'undefined') {
Expand Down
26 changes: 23 additions & 3 deletions Source/DynamicScene/DynamicPositionProperty.js
Expand Up @@ -468,6 +468,12 @@ define([
if (typeof nextInterval !== 'undefined' && stop.greaterThan(nextInterval.start)) {
loopStop = nextInterval.start;
}

var sampling = false;
var sampleStepsToTake;
var sampleStepsTaken;
var sampleStepSize;

var property = interval.data;
var currentInterval = property._intervals.get(0);
var times = currentInterval.data.times;
Expand All @@ -494,12 +500,26 @@ define([
}

if (t < (len - 1)) {
var next = times[t + 1];
if (current.getSecondsDifference(next) > maximumStep) {
current = current.addSeconds(maximumStep);
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];
}
Expand Down
38 changes: 24 additions & 14 deletions Specs/DynamicScene/DynamicPathSpec.js
Expand Up @@ -23,6 +23,7 @@ defineSuite([
rgbaf : [0.1, 0.1, 0.1, 0.1]
},
width : 1.0,
resolution : 23.0,
outlineColor : {
rgbaf : [0.2, 0.2, 0.2, 0.2]
},
Expand All @@ -39,6 +40,7 @@ defineSuite([
expect(dynamicObject.path).toBeDefined();
expect(dynamicObject.path.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1));
expect(dynamicObject.path.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.width);
expect(dynamicObject.path.resolution.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.resolution);
expect(dynamicObject.path.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2));
expect(dynamicObject.path.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.outlineWidth);
expect(dynamicObject.path.leadTime.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.leadTime);
Expand All @@ -54,6 +56,7 @@ defineSuite([
rgbaf : [0.1, 0.1, 0.1, 0.1]
},
width : 1.0,
resolution : 23.0,
outlineColor : {
rgbaf : [0.2, 0.2, 0.2, 0.2]
},
Expand All @@ -73,6 +76,7 @@ defineSuite([
expect(dynamicObject.path).toBeDefined();
expect(dynamicObject.path.color.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1));
expect(dynamicObject.path.width.getValue(validTime)).toEqual(pathPacket.path.width);
expect(dynamicObject.path.resolution.getValue(validTime)).toEqual(pathPacket.path.resolution);
expect(dynamicObject.path.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2));
expect(dynamicObject.path.outlineWidth.getValue(validTime)).toEqual(pathPacket.path.outlineWidth);
expect(dynamicObject.path.leadTime.getValue(validTime)).toEqual(pathPacket.path.leadTime);
Expand Down Expand Up @@ -105,26 +109,29 @@ defineSuite([
objectToMerge.path.show = 5;
objectToMerge.path.leadTime = 6;
objectToMerge.path.trailTime = 7;
objectToMerge.path.resolution = 8;

var targetObject = new DynamicObject('targetObject');
targetObject.path = new DynamicPath();
targetObject.path.color = 8;
targetObject.path.width = 9;
targetObject.path.outlineColor = 10;
targetObject.path.outlineWidth = 11;
targetObject.path.show = 12;
targetObject.path.leadTime = 13;
targetObject.path.trailTime = 14;
targetObject.path.color = 9;
targetObject.path.width = 10;
targetObject.path.outlineColor = 11;
targetObject.path.outlineWidth = 12;
targetObject.path.show = 13;
targetObject.path.leadTime = 14;
targetObject.path.trailTime = 15;
targetObject.path.resolution = 16;

DynamicPath.mergeProperties(targetObject, objectToMerge);

expect(targetObject.path.color).toEqual(8);
expect(targetObject.path.width).toEqual(9);
expect(targetObject.path.outlineColor).toEqual(10);
expect(targetObject.path.outlineWidth).toEqual(11);
expect(targetObject.path.show).toEqual(12);
expect(targetObject.path.leadTime).toEqual(13);
expect(targetObject.path.trailTime).toEqual(14);
expect(targetObject.path.color).toEqual(9);
expect(targetObject.path.width).toEqual(10);
expect(targetObject.path.outlineColor).toEqual(11);
expect(targetObject.path.outlineWidth).toEqual(12);
expect(targetObject.path.show).toEqual(13);
expect(targetObject.path.leadTime).toEqual(14);
expect(targetObject.path.trailTime).toEqual(15);
expect(targetObject.path.resolution).toEqual(16);
});

it('mergeProperties creates and configures an undefined path', function() {
Expand All @@ -137,6 +144,7 @@ defineSuite([
objectToMerge.path.show = 5;
objectToMerge.path.leadTime = 6;
objectToMerge.path.trailTime = 7;
objectToMerge.path.resolution = 8;
var targetObject = new DynamicObject('targetObject');

DynamicPath.mergeProperties(targetObject, objectToMerge);
Expand All @@ -163,6 +171,7 @@ defineSuite([
targetObject.path.show = 5;
targetObject.path.leadTime = 6;
targetObject.path.trailTime = 7;
targetObject.path.resolution = 8;
DynamicPath.mergeProperties(targetObject, objectToMerge);

expect(targetObject.path.color).toEqual(1);
Expand All @@ -172,6 +181,7 @@ defineSuite([
expect(targetObject.path.show).toEqual(5);
expect(targetObject.path.leadTime).toEqual(6);
expect(targetObject.path.trailTime).toEqual(7);
expect(targetObject.path.resolution).toEqual(8);
});

it('undefineProperties works', function() {
Expand Down

0 comments on commit bc61450

Please sign in to comment.