Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getTileDataAvailable() handling for terrain providers #2102

Merged
merged 16 commits into from
Sep 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Apps/Sandcastle/gallery/Profile Half Dome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <!-- Use Chrome Frame in IE -->
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Use Viewer to start building new applications or easily embed Cesium into existing applications.">
<meta name="cesium-sandcastle-labels" content="Profiling">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.9/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
"use strict";
//Sandcastle_Begin
var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
url : '//cesiumjs.org/stk-terrain/tilesets/world/tiles'
});

var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;
scene.terrainProvider = cesiumTerrainProviderMeshes;

var setCamera = function() {
var eye = new Cesium.Cartesian3(-2496304.1498512086, -4391818.97382059, 3884176.4503971986);
var target = Cesium.Cartesian3.add(eye, new Cesium.Cartesian3(0.9279518715011381, -0.29488412129953234, -0.22792252890604328), new Cesium.Cartesian3());
var up = new Cesium.Cartesian3(-0.11836693744723503, -0.8130611584421428, 0.5700182635106171);
scene.camera.lookAt(eye, target, up);
};

setCamera();

// Keep updating the camera so it doesn't get pushed above low resolution terrain.
setInterval(setCamera, 1000);
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ Change Log

### 1.2 - 2014-10-01

* Deprecated
* Types implementing the `TerrainProvider` interface should now include the new `getTileDataAvailable` function. The function will be required starting in Cesium 1.04.
* Added a constructor option to `Scene`, `CesiumWidget`, and `Viewer` to disable order independent translucency.
* Eliminated imagery artifacts at some zoom levels due to Mercator reprojection.
* Fixed a bug in `Model` where the wrong animations could be used when the model was created from glTF JSON instead of
a url to a glTF file. [#2078](https://github.com/AnalyticalGraphicsInc/cesium/issues/2078)
* Added support for WKID 102113 (equivalent to 102100) to `ArcGisMapServerImageryProvider`.
* Added `TerrainProvider.getTileDataAvailable` to improve tile loading performance when camera starts near globe.

### 1.1 - 2014-09-02

Expand Down
12 changes: 12 additions & 0 deletions Source/Core/ArcGisImageServerTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,17 @@ define([
return this._levelZeroMaximumGeometricError / (1 << level);
};

/**
* Determines whether data for a tile is available to be loaded.
*
* @param {Number} x The X coordinate of the tile for which to request geometry.
* @param {Number} y The Y coordinate of the tile for which to request geometry.
* @param {Number} level The level of the tile for which to request geometry.
* @returns {Boolean} Undefined if not supported, otherwise true or false.
*/
ArcGisImageServerTerrainProvider.prototype.getTileDataAvailable = function(x, y, level) {
return undefined;
};

return ArcGisImageServerTerrainProvider;
});
22 changes: 22 additions & 0 deletions Source/Core/CesiumTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,5 +635,27 @@ define([
return false;
}

/**
* Determines whether data for a tile is available to be loaded.
*
* @param {Number} x The X coordinate of the tile for which to request geometry.
* @param {Number} y The Y coordinate of the tile for which to request geometry.
* @param {Number} level The level of the tile for which to request geometry.
* @returns {Boolean} Undefined if not supported, otherwise true or false.
*/
CesiumTerrainProvider.prototype.getTileDataAvailable = function(x, y, level) {
var available = this._availableTiles;

if (!available || available.length === 0) {
return undefined;
} else {
if (level >= available.length) {
return false;
}
var levelAvailable = available[level];
return isTileInRange(levelAvailable, x, y);
}
};

return CesiumTerrainProvider;
});
12 changes: 12 additions & 0 deletions Source/Core/EllipsoidTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,17 @@ define([
return this._levelZeroMaximumGeometricError / (1 << level);
};

/**
* Determines whether data for a tile is available to be loaded.
*
* @param {Number} x The X coordinate of the tile for which to request geometry.
* @param {Number} y The Y coordinate of the tile for which to request geometry.
* @param {Number} level The level of the tile for which to request geometry.
* @returns {Boolean} Undefined if not supported, otherwise true or false.
*/
EllipsoidTerrainProvider.prototype.getTileDataAvailable = function(x, y, level) {
return undefined;
};

return EllipsoidTerrainProvider;
});
11 changes: 11 additions & 0 deletions Source/Core/TerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,16 @@ define([
*/
TerrainProvider.prototype.getLevelMaximumGeometricError = DeveloperError.throwInstantiationError;

/**
* Determines whether data for a tile is available to be loaded.
* @function
*
* @param {Number} x The X coordinate of the tile for which to request geometry.
* @param {Number} y The Y coordinate of the tile for which to request geometry.
* @param {Number} level The level of the tile for which to request geometry.
* @returns {Boolean} Undefined if not supported by the terrain provider, otherwise true or false.
*/
TerrainProvider.prototype.getTileDataAvailable = DeveloperError.throwInstantiationError;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change for folks who implemented TerrainProvider, right?

We should provide a default implementation to not break them and perhaps warn if we want to eventually require this. See the Deprecation Guide.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see isDataAvailable below in GlobeSurfaceTile.js. Is that the right place? I would expect to treat this as an abstract base class instead so all users do not need to check for the function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently there are no "base classes" or inheritance in Cesium. TerrainProvider only exists as documentation of an implicit interface, so there are no breaking changes here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. This is still a little sketchy. It's as if we want to document this function as optional so users know they need to check to see if the function exists or we need to start using inheritance of whatever form to avoid this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's as if we want to document this function as optional so users know they need to check to see if the function exists or we need to start using inheritance of whatever form to avoid this.

I believe inheritance would have a performance cost we'd rather not pay. I agree it should be documented as optional, though.


return TerrainProvider;
});
12 changes: 12 additions & 0 deletions Source/Core/VRTheWorldTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,17 @@ define([
return !Rectangle.isEmpty(Rectangle.intersectWith(tileRectangle, rectangle, rectangleScratch));
}

/**
* Determines whether data for a tile is available to be loaded.
*
* @param {Number} x The X coordinate of the tile for which to request geometry.
* @param {Number} y The Y coordinate of the tile for which to request geometry.
* @param {Number} level The level of the tile for which to request geometry.
* @returns {Boolean} Undefined if not supported, otherwise true or false.
*/
VRTheWorldTerrainProvider.prototype.getTileDataAvailable = function(x, y, level) {
return undefined;
};

return VRTheWorldTerrainProvider;
});
16 changes: 14 additions & 2 deletions Source/Scene/GlobeSurfaceTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define([
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
'../Core/deprecationWarning',
'../Core/IntersectionTests',
'../Core/PixelFormat',
'../Core/Rectangle',
Expand All @@ -27,6 +28,7 @@ define([
defaultValue,
defined,
defineProperties,
deprecationWarning,
IntersectionTests,
PixelFormat,
Rectangle,
Expand Down Expand Up @@ -378,7 +380,7 @@ define([
surfaceTile.upsampledTerrain = new TileTerrain(upsampleTileDetails);
}

if (isDataAvailable(tile)) {
if (isDataAvailable(tile, terrainProvider)) {
surfaceTile.loadedTerrain = new TileTerrain();
}

Expand Down Expand Up @@ -618,7 +620,17 @@ define([
}
}

function isDataAvailable(tile) {
function isDataAvailable(tile, terrainProvider) {

if (defined(terrainProvider.getTileDataAvailable)) {
var tileDataAvailable = terrainProvider.getTileDataAvailable(tile.x, tile.y, tile.level);
if (defined(tileDataAvailable)) {
return tileDataAvailable;
}
} else {
deprecationWarning('TerrainProvider.getTileDataAvailable', 'TerrainProviders must now implement the getTileDataAvailable function.');
}

var parent = tile.parent;
if (!defined(parent)) {
// Data is assumed to be available for root tiles.
Expand Down
37 changes: 37 additions & 0 deletions Specs/Core/CesiumTerrainProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,5 +596,42 @@ defineSuite([
}
});
});

it('supports getTileDataAvailable()', function() {
var baseUrl = 'made/up/url';

loadWithXhr.load = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
return loadWithXhr.defaultLoad('Data/CesiumTerrainTileJson/tile.terrain', responseType, method, data, headers, deferred);
};

returnQuantizedMeshTileJson();

var terrainProvider = new CesiumTerrainProvider({
url : baseUrl
});

waitsFor(function() {
return terrainProvider.ready;
});

var loadedData;

runs(function() {
var promise = terrainProvider.requestTileGeometry(0, 0, 0);

when(promise, function(terrainData) {
loadedData = terrainData;
});
});

waitsFor(function() {
return defined(loadedData);
}, 'request to complete');

runs(function() {
expect(terrainProvider.getTileDataAvailable(0, 0, 0)).toBe(true);
expect(terrainProvider.getTileDataAvailable(0, 0, 2)).toBe(false);
});
});
});
});
11 changes: 11 additions & 0 deletions Specs/Core/EllipsoidTerrainProviderSpec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/*global defineSuite*/
defineSuite([
'Core/EllipsoidTerrainProvider',
'Core/TerrainProvider',
'Specs/createContext',
'Specs/destroyContext'
], function(
EllipsoidTerrainProvider,
TerrainProvider,
createContext,
destroyContext) {
"use strict";
Expand All @@ -20,6 +22,10 @@ defineSuite([
destroyContext(context);
});

it('conforms to TerrainProvider interface', function() {
expect(EllipsoidTerrainProvider).toConformToInterface(TerrainProvider);
});

it('requestTileGeometry creates terrain data.', function() {
var terrain = new EllipsoidTerrainProvider();
var terrainData = terrain.requestTileGeometry(0, 0, 0);
Expand All @@ -31,4 +37,9 @@ defineSuite([
expect(provider.errorEvent).toBeDefined();
expect(provider.errorEvent).toBe(provider.errorEvent);
});

it('returns undefined on getTileDataAvailable()', function() {
var provider = new EllipsoidTerrainProvider();
expect(provider.getTileDataAvailable()).toBeUndefined();
});
}, 'WebGL');