-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make surface contour levels configurable #3469
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
Changes from 13 commits
fb3db10
b44dcdc
5051378
120e560
bd498ea
669662f
c48386c
15caa05
8583693
61a6cff
d04101f
40fa0e9
6700eb5
98aebc5
fc5e118
1ac97ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,17 @@ function SurfaceTrace(scene, surface, uid) { | |
this.surface = surface; | ||
this.data = null; | ||
this.showContour = [false, false, false]; | ||
this.contourStart = [null, null, null]; | ||
this.contourEnd = [null, null, null]; | ||
this.contourSize = [0, 0, 0]; | ||
this.contourLocations = [[], [], []]; | ||
this.contourRelative = [0, 0]; // note: only available on x & y not z. | ||
this.minValues = [Infinity, Infinity, Infinity]; | ||
this.maxValues = [-Infinity, -Infinity, -Infinity]; | ||
this.dataScaleX = 1.0; | ||
this.dataScaleY = 1.0; | ||
this.refineData = true; | ||
this._interpolatedZ = false; | ||
this.objectOffset = [0, 0, 0]; | ||
} | ||
|
||
var proto = SurfaceTrace.prototype; | ||
|
@@ -349,19 +354,99 @@ proto.refineCoords = function(coords) { | |
} | ||
}; | ||
|
||
function insertIfNewLevel(arr, newValue) { | ||
var found = false; | ||
for(var k = 0; k < arr.length; k++) { | ||
if(newValue === arr[k]) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
if(found === false) arr.push(newValue); | ||
} | ||
|
||
proto.setContourLevels = function() { | ||
var nlevels = [[], [], []]; | ||
var newLevels = [[], [], []]; | ||
var useNewLevels = [false, false, false]; | ||
var needsUpdate = false; | ||
|
||
for(var i = 0; i < 3; ++i) { | ||
var i, j, value; | ||
|
||
for(i = 0; i < 3; ++i) { | ||
if(this.showContour[i]) { | ||
needsUpdate = true; | ||
nlevels[i] = this.scene.contourLevels[i]; | ||
|
||
if(i < 2) { | ||
var ratios = Array.isArray(this.contourRelative[i]) ? | ||
this.contourRelative[i] : [this.contourRelative[i]]; | ||
|
||
for(var k = 0; k < ratios.length; k++) { | ||
var ratio = ratios[k]; | ||
if(ratio !== 0) { | ||
|
||
var len = (i === 0) ? | ||
this.data.z[0].length : | ||
this.data._ylength; | ||
|
||
for(var q = (ratio < 1) ? 1 : 0; q < len; q++) { | ||
|
||
var here = (i === 0) ? | ||
this.getXat(q, 0) * this.scene.dataScale[i] : | ||
this.getYat(0, q) * this.scene.dataScale[i]; | ||
|
||
if(ratio < 1) { | ||
var prev = (i === 0) ? | ||
this.getXat(q - 1, 0) * this.scene.dataScale[i] : | ||
this.getYat(0, q - 1) * this.scene.dataScale[i]; | ||
|
||
value = here * ratio + prev * (1 - ratio); | ||
} else { | ||
value = here; | ||
} | ||
|
||
insertIfNewLevel(newLevels[i], value); | ||
useNewLevels[i] = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
var locations = this.contourLocations[i]; | ||
if(locations !== false) useNewLevels[i] = true; | ||
if(locations.length) { | ||
for(j = 0; j < locations.length; j++) { | ||
value = locations[j] * this.scene.dataScale[i]; | ||
|
||
insertIfNewLevel(newLevels[i], value); | ||
} | ||
} | ||
|
||
if( | ||
this.contourSize[i] > 0 && | ||
this.contourStart[i] !== null && | ||
this.contourEnd[i] !== null && | ||
this.contourEnd[i] > this.contourStart[i] | ||
) { | ||
useNewLevels[i] = true; | ||
|
||
for(j = this.contourStart[i]; j < this.contourEnd[i]; j += this.contourSize[i]) { | ||
value = j * this.scene.dataScale[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tried re-using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that on a different branch. Also wanted to add |
||
|
||
insertIfNewLevel(newLevels[i], value); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
if(needsUpdate) { | ||
this.surface.update({ levels: nlevels }); | ||
var allLevels = [[], [], []]; | ||
for(i = 0; i < 3; ++i) { | ||
if(this.showContour[i]) { | ||
allLevels[i] = useNewLevels[i] ? newLevels[i] : this.scene.contourLevels[i]; | ||
} | ||
} | ||
this.surface.update({ levels: allLevels }); | ||
} | ||
}; | ||
|
||
|
@@ -456,15 +541,15 @@ proto.update = function(data) { | |
} | ||
|
||
for(i = 0; i < 3; i++) { | ||
data._objectOffset[i] = 0.5 * (this.minValues[i] + this.maxValues[i]); | ||
this.objectOffset[i] = 0.5 * (this.minValues[i] + this.maxValues[i]); | ||
} | ||
|
||
for(i = 0; i < 3; i++) { | ||
for(j = 0; j < xlen; j++) { | ||
for(k = 0; k < ylen; k++) { | ||
v = rawCoords[i][j][k]; | ||
if(v !== null && v !== undefined) { | ||
rawCoords[i][j][k] -= data._objectOffset[i]; | ||
rawCoords[i][j][k] -= this.objectOffset[i]; | ||
} | ||
} | ||
} | ||
|
@@ -564,8 +649,22 @@ proto.update = function(data) { | |
surface.highlightTint[i] = params.contourTint[i] = 1; | ||
} | ||
params.contourWidth[i] = contourParams.width; | ||
|
||
this.contourStart[i] = contourParams.start; | ||
this.contourEnd[i] = contourParams.end; | ||
this.contourSize[i] = contourParams.size; | ||
|
||
this.contourLocations[i] = contourParams.locations; | ||
if(i < 2) this.contourRelative[i] = contourParams.relative; | ||
} else { | ||
this.showContour[i] = false; | ||
|
||
this.contourStart[i] = null; | ||
this.contourEnd[i] = null; | ||
this.contourSize[i] = 0; | ||
|
||
this.contourLocations[i] = []; | ||
if(i < 2) this.contourRelative[i] = 0; | ||
} | ||
|
||
if(contourParams.highlight) { | ||
|
@@ -579,11 +678,7 @@ proto.update = function(data) { | |
params.vertexColor = true; | ||
} | ||
|
||
params.objectOffset = [ | ||
data._objectOffset[0], | ||
data._objectOffset[1], | ||
data._objectOffset[2] | ||
]; | ||
params.objectOffset = this.objectOffset; | ||
|
||
params.coords = coords; | ||
surface.update(params); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"type": "surface", | ||
"contours": { | ||
"x": { "show": true, "relative": 1 }, | ||
"y": { "show": true, "relative": 1 }, | ||
"z": { "show": false } | ||
}, | ||
"x": [0, 0.25, 0.5, 0.75, 1], | ||
"y": [0, 0.25, 0.5, 0.75, 1], | ||
"z": [ | ||
[0, 1, 0, 1, 0], | ||
[1, 0, 1, 0, 1], | ||
[0, 1, 0, 1, 0], | ||
[1, 0, 1, 0, 1], | ||
[0, 1, 0, 1, 0] | ||
] | ||
}, | ||
{ | ||
"type": "surface", | ||
"contours": { | ||
"x": { "show": true, "relative": 0.5 }, | ||
"y": { "show": true, "relative": 0.5 }, | ||
"z": { "show": false } | ||
}, | ||
"x": [1.5, 1.75, 2, 2.25, 2.5], | ||
"y": [0, 0.25, 0.5, 0.75, 1], | ||
"z": [ | ||
[0, 1, 0, 1, 0], | ||
[1, 0, 1, 0, 1], | ||
[0, 1, 0, 1, 0], | ||
[1, 0, 1, 0, 1], | ||
[0, 1, 0, 1, 0] | ||
] | ||
}, | ||
{ | ||
"type": "surface", | ||
"contours": { | ||
"x": { "show": true }, | ||
"y": { "show": true }, | ||
"z": { "show": false } | ||
}, | ||
"x": [0, 0.25, 0.5, 0.75, 1], | ||
"y": [1.5, 1.75, 2, 2.25, 2.5], | ||
"z": [ | ||
[0, 1, 0, 1, 0], | ||
[1, 0, 1, 0, 1], | ||
[0, 1, 0, 1, 0], | ||
[1, 0, 1, 0, 1], | ||
[0, 1, 0, 1, 0] | ||
] | ||
}, | ||
{ | ||
"type": "surface", | ||
"contours": { | ||
"x": { "show": true, "relative": [0.25, 0.75] }, | ||
"y": { "show": true, "relative": [0.333, 0.666] }, | ||
"z": { "show": false } | ||
}, | ||
"x": [1.5, 1.75, 2, 2.25, 2.5], | ||
"y": [1.5, 1.75, 2, 2.25, 2.5], | ||
"z": [ | ||
[0, 1, 0, 1, 0], | ||
[1, 0, 1, 0, 1], | ||
[0, 1, 0, 1, 0], | ||
[1, 0, 1, 0, 1], | ||
[0, 1, 0, 1, 0] | ||
] | ||
} | ||
], | ||
"layout": { | ||
"title": "Surface contours on or between all x & y data points", | ||
"width": 900, | ||
"height": 600, | ||
"scene": { | ||
"xaxis": { "nticks": 12 }, | ||
"yaxis": { "nticks": 12 }, | ||
"zaxis": { "nticks": 12 }, | ||
"camera": { | ||
"eye": { "x": 1, "y": 0, "z": 0.75 }, | ||
"center": { "x": 0, "y": 0, "z": 0 } | ||
}, | ||
"aspectratio": { | ||
"x": 1, | ||
"y": 1, | ||
"z": 0.2 | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need
locations
andrelative
to ✅ this feature?I would prefer making
surface
on-par withcontour
to start.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Let's put this on 1.47.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped those features in 98aebc5 as
surface
code is already pretty complicated for us to maintain.