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

Apply styles to photogrammetry #7255

Merged
merged 2 commits into from
Nov 19, 2018
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Change Log
* Added `Scene.clampToHeightMostDetailed`, an asynchronous version of `Scene.clampToHeight` that uses the maximum level of detail for 3D Tiles.
* Added `Scene.invertClassificationSupported` for checking if invert classification is supported.
* Added `computeLineSegmentLineSegmentIntersection` to `Intersections2D`. [#7228](https://github.com/AnalyticalGraphicsInc/Cesium/pull/7228)
* Added the ability to apply styles to 3D Tilesets that don't contain features. [#7255](https://github.com/AnalyticalGraphicsInc/Cesium/pull/7255)

##### Fixes :wrench:
* Fixed issue causing polyline to look wavy depending on the position of the camera [#7209](https://github.com/AnalyticalGraphicsInc/cesium/pull/7209)
Expand Down
11 changes: 10 additions & 1 deletion Source/Scene/Batched3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,17 @@ define([
}
};

var scratchColor = new Color();

Batched3DModel3DTileContent.prototype.applyStyle = function(style) {
this._batchTable.applyStyle(style);
if (this.featuresLength === 0) {
var hasColorStyle = defined(style) && defined(style.color);
var hasShowStyle = defined(style) && defined(style.show);
this._model.color = hasColorStyle ? style.color.evaluateColor(undefined, scratchColor) : Color.WHITE;
this._model.show = hasShowStyle ? style.show.evaluate(undefined) : true;
} else {
this._batchTable.applyStyle(style);
}
};

Batched3DModel3DTileContent.prototype.update = function(tileset, frameState) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ define([
Cesium3DTileBatchTable.prototype.applyStyle = function(style) {
if (!defined(style)) {
this.setAllColor(DEFAULT_COLOR_VALUE);
this.setAllShow(true);
this.setAllShow(DEFAULT_SHOW_VALUE);
return;
}

Expand Down
36 changes: 27 additions & 9 deletions Source/Scene/Expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ define([
} else if (node._value === 'isClass') {
node.evaluate = node._evaluateIsClass;
} else if (node._value === 'getExactClassName') {
node.evaluate = node._evaluategetExactClassName;
node.evaluate = node._evaluateGetExactClassName;
} else if (node._value === 'Boolean') {
node.evaluate = node._evaluateBooleanConversion;
} else if (node._value === 'Number') {
Expand Down Expand Up @@ -900,6 +900,9 @@ define([
}

function evaluateTilesetTime(feature) {
if (!defined(feature)) {
return 0.0;
}
return feature.content.tileset.timeSinceLoad;
}

Expand Down Expand Up @@ -930,6 +933,13 @@ define([
};
}

function getFeatureProperty(feature, name) {
// Returns undefined if the feature is not defined or the property name is not defined for that feature
if (defined(feature)) {
return feature.getProperty(name);
}
}

Node.prototype._evaluateLiteral = function() {
return this._value;
};
Expand Down Expand Up @@ -1046,7 +1056,7 @@ define([
while (match !== null) {
var placeholder = match[0];
var variableName = match[1];
var property = feature.getProperty(variableName);
var property = getFeatureProperty(feature, variableName);
if (!defined(property)) {
property = '';
}
Expand All @@ -1058,7 +1068,7 @@ define([

Node.prototype._evaluateVariable = function(feature) {
// evaluates to undefined if the property name is not defined for that feature
return feature.getProperty(this._value);
return getFeatureProperty(feature, this._value);
};

function checkFeature (ast) {
Expand All @@ -1068,7 +1078,7 @@ define([
// PERFORMANCE_IDEA: Determine if parent property needs to be computed before runtime
Node.prototype._evaluateMemberDot = function(feature) {
if (checkFeature(this._left)) {
return feature.getProperty(this._right.evaluate(feature));
return getFeatureProperty(feature, this._right.evaluate(feature));
}
var property = this._left.evaluate(feature);
if (!defined(property)) {
Expand All @@ -1093,7 +1103,7 @@ define([

Node.prototype._evaluateMemberBrackets = function(feature) {
if (checkFeature(this._left)) {
return feature.getProperty(this._right.evaluate(feature));
return getFeatureProperty(feature, this._right.evaluate(feature));
}
var property = this._left.evaluate(feature);
if (!defined(property)) {
Expand Down Expand Up @@ -1388,15 +1398,23 @@ define([
};

Node.prototype._evaluateIsExactClass = function(feature) {
return feature.isExactClass(this._left.evaluate(feature));
if (defined(feature)) {
return feature.isExactClass(this._left.evaluate(feature));
}
return false;
};

Node.prototype._evaluateIsClass = function(feature) {
return feature.isClass(this._left.evaluate(feature));
if (defined(feature)) {
return feature.isClass(this._left.evaluate(feature));
}
return false;
};

Node.prototype._evaluategetExactClassName = function(feature) {
return feature.getExactClassName();
Node.prototype._evaluateGetExactClassName = function(feature) {
if (defined(feature)) {
return feature.getExactClassName();
}
};

Node.prototype._evaluateBooleanConversion = function(feature) {
Expand Down
18 changes: 18 additions & 0 deletions Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,18 @@ defineSuite([
});
});

it('applies show style to a tileset without features', function() {
return Cesium3DTilesTester.loadTileset(scene, noBatchIdsUrl).then(function(tileset) {
var hideStyle = new Cesium3DTileStyle({show : 'false'});
tileset.style = hideStyle;
expect(tileset.style).toBe(hideStyle);
expect(scene).toRender([0, 0, 0, 255]);

tileset.style = new Cesium3DTileStyle({show : 'true'});
expect(scene).notToRender([0, 0, 0, 255]);
});
});

it('applies style with complex show expression to a tileset', function() {
return Cesium3DTilesTester.loadTileset(scene, withBatchTableUrl).then(function(tileset) {
// Each feature in the b3dm file has an id property from 0 to 9
Expand Down Expand Up @@ -2045,6 +2057,12 @@ defineSuite([
});
});

it('applies color style to tileset without features', function() {
return Cesium3DTilesTester.loadTileset(scene, noBatchIdsUrl).then(function(tileset) {
expectColorStyle(tileset);
});
});

it('applies style when feature properties change', function() {
return Cesium3DTilesTester.loadTileset(scene, withBatchTableUrl).then(function(tileset) {
// Initially, all feature ids are less than 10
Expand Down
30 changes: 30 additions & 0 deletions Specs/Scene/ExpressionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,30 @@ defineSuite([
}).toThrowRuntimeError();
});

it('evaluates variable to undefined if feature is undefined', function() {
var expression = new Expression('${height}');
expect(expression.evaluate(undefined)).toBeUndefined();

expression = new Expression('${vector.x}');
expect(expression.evaluate(undefined)).toBeUndefined();

expression = new Expression('${feature}');
expect(expression.evaluate(undefined)).toBeUndefined();

expression = new Expression('${feature.vector}');
expect(expression.evaluate(undefined)).toBeUndefined();

expression = new Expression('${vector["x"]}');
expect(expression.evaluate(undefined)).toBeUndefined();

expression = new Expression('${feature["vector"]}');
expect(expression.evaluate(undefined)).toBeUndefined();

// Evaluating inside a string is an exception. "" is returned instead of "undefined"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this an exception? It looks like we determine the behavior in the previous test for what do when printing an undefined property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh just an exception in reference to the name of the test "evaluates variable to undefined if feature is undefined"

expression = new Expression('\'${height}\'');
expect(expression.evaluate(undefined)).toBe('');
});

it('evaluates with defines', function() {
var defines = {
halfHeight: '${Height}/2'
Expand Down Expand Up @@ -1493,6 +1517,8 @@ defineSuite([

expression = new Expression('isExactClass("roof")');
expect(expression.evaluate(feature)).toEqual(false);

expect(expression.evaluate(undefined)).toEqual(false);
});

it('throws if isExactClass takes an invalid number of arguments', function() {
Expand All @@ -1513,6 +1539,8 @@ defineSuite([

var expression = new Expression('isClass("door") && isClass("building")');
expect(expression.evaluate(feature)).toEqual(true);

expect(expression.evaluate(undefined)).toEqual(false);
});

it('throws if isClass takes an invalid number of arguments', function() {
Expand All @@ -1530,6 +1558,7 @@ defineSuite([
feature.setClass('door');
var expression = new Expression('getExactClassName()');
expect(expression.evaluate(feature)).toEqual('door');
expect(expression.evaluate(undefined)).toBeUndefined();
});

it('throws if getExactClassName takes an invalid number of arguments', function() {
Expand Down Expand Up @@ -2953,6 +2982,7 @@ defineSuite([
expect(expression.evaluate(feature)).toEqual(0.0);
feature.content.tileset.timeSinceLoad = 1.0;
expect(expression.evaluate(feature)).toEqual(1.0);
expect(expression.evaluate(undefined)).toEqual(0.0);
});

it('gets shader function', function() {
Expand Down