-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a transfer function shader widget (#582)
* feat: transfer function widget * refactor: fix linting warnings * refactor: TF uses uint64 as number, not string * chore: cleanup TODO and comments * refactor: clean up transfer function code a little * fix: TF control points didn't always make it to JSON * refactor: clearer comments and update loop * fix: no longer able to place control points on top of eachother * fix: can grab control points in TF that are close in X by breaking ties with Y * fix: bind remove TF point to shift+dblclick You could accidentally remove points trying to move them before * feat: clearer name of TF input value * feat: Python control over transfer function shader contro * docs: fix typo in python docs * test (Python): shader control transfer function test * fix: user can't specify transfer function points outside input range * docs: transfer function UI control * docs: code comment on transfer functions * chore: format and lint * chore(python): format * refactor(in progress): store control points in abs value * refactor(progress): transfer functino * progress(refactor): tf refactor * progress(refactor): tf refactor * progress(refactor): fix all type errors in tf file * progress(refactor): fix type errors * refactor(progress): fix more type errors * fix(tests): remove unused imports * tests(fix): browser test whole TF * fix: transfer function correct interpolation * fix: dynamic transfer function size and correct GPU control * feat: remove range and size as TF params Instead they are computed based on input * fix: parse shader directive for new TF * fix: JSON state parsing and saving for new TF * fix: new TF runs, but UI control is broken * fix: remove accidental log * fix: control points display in correct position in UI * fix: find control point near cursor in new TF * fix: moving control points and setting color * fix: correct number of lines * fix: display UI panel texture for TF * fix: render data from TF texture * fix: remove fixed size TF texture * fix: link UI to JSON for control points * fix: remove temps and TODOs * fix: handle control point range for 0 and 1 points * fix: test * fix: unused code * fix: can no longer lose control of point that you were trying to move * fix: compute range after removing a point * refactor: clearer range update * fix: tf UI has correct texture indicator * feat: default intensity for transfer functions * fix: don't crash on window[0] === window[1] in TF UI panel * fix: userIntensity always overwrites default * docs: update transfer function docs * tests: fix a test for TFs with uint64 data * feat: use non-interpolated value in TF for consistency and efficiency * fix: tests * Python(fix): fix transfer function control input * docs: fix formatting * Python: format * fix: remove accidental test change * refactor: clarifications * docs: while inverted windows are not supported, remove from docs * fix: correctly draw lines with a points beside window, one left, one right * feat: a little bit cleaner interaction with TF UI window * refactor: clarify the transfer function lines drawing
- Loading branch information
1 parent
3b2a8a3
commit f805b54
Showing
19 changed files
with
3,289 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google Inc. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { describe, it, expect } from "vitest"; | ||
import { createGriddedRectangleArray } from "#src/webgl/rectangle_grid_buffer.js"; | ||
|
||
describe("createGriddedRectangleArray", () => { | ||
it("creates a set of two squares for grid size=2 and rectangle width&height=2", () => { | ||
const result = createGriddedRectangleArray(2, -1, 1, 1, -1); | ||
expect(result).toEqual( | ||
new Float32Array([ | ||
-1, 1, 0, 1, 0, -1 /* triangle in top right for first grid */, -1, 1, 0, | ||
-1, -1, -1 /* triangle in bottom left for first grid */, 0, 1, 1, 1, 1, | ||
-1 /* triangle in top right for second grid */, 0, 1, 1, -1, 0, | ||
-1 /* triangle in bottom left for second grid */, | ||
]), | ||
); | ||
const resultReverse = createGriddedRectangleArray(2, 1, -1, -1, 1); | ||
expect(resultReverse).toEqual( | ||
new Float32Array([ | ||
1, -1, 0, -1, 0, 1 /* triangle in top right for first grid */, 1, -1, 0, | ||
1, 1, 1 /* triangle in bottom left for first grid */, 0, -1, -1, -1, -1, | ||
1 /* triangle in top right for second grid */, 0, -1, -1, 1, 0, | ||
1 /* triangle in bottom left for second grid */, | ||
]), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google Inc. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { getMemoizedBuffer } from "#src/webgl/buffer.js"; | ||
import type { GL } from "#src/webgl/context.js"; | ||
import { VERTICES_PER_QUAD } from "#src/webgl/quad.js"; | ||
|
||
/** | ||
* Create a Float32Array of vertices gridded in a rectangle | ||
* Only grids along the x-axis are created, the y-axis is assumed to be the same for all grids | ||
*/ | ||
export function createGriddedRectangleArray( | ||
numGrids: number, | ||
startX = -1, | ||
endX = 1, | ||
startY = 1, | ||
endY = -1, | ||
): Float32Array { | ||
const result = new Float32Array(numGrids * VERTICES_PER_QUAD * 2); | ||
const step = (endX - startX) / numGrids; | ||
let currentx = startX; | ||
for (let i = 0; i < numGrids; ++i) { | ||
const index = i * VERTICES_PER_QUAD * 2; | ||
|
||
// Triangle 1 - top-left, top-right, bottom-right | ||
result[index] = currentx; // top-left x | ||
result[index + 1] = startY; // top-left y | ||
result[index + 2] = currentx + step; // top-right x | ||
result[index + 3] = startY; // top-right y | ||
result[index + 4] = currentx + step; // bottom-right x | ||
result[index + 5] = endY; // bottom-right y | ||
|
||
// Triangle 2 - top-left, bottom-right, bottom-left | ||
result[index + 6] = currentx; // top-left x | ||
result[index + 7] = startY; // top-left y | ||
result[index + 8] = currentx + step; // bottom-right x | ||
result[index + 9] = endY; // bottom-right y | ||
result[index + 10] = currentx; // bottom-left x | ||
result[index + 11] = endY; // bottom-left y | ||
currentx += step; | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Get a buffer of vertices representing a rectangle that is gridded | ||
* along the x dimension, useful for drawing grids, such as a lookup table / heatmap | ||
*/ | ||
export function getGriddedRectangleBuffer( | ||
gl: GL, | ||
numGrids: number, | ||
startX = -1, | ||
endX = 1, | ||
startY = 1, | ||
endY = -1, | ||
) { | ||
return getMemoizedBuffer( | ||
gl, | ||
WebGL2RenderingContext.ARRAY_BUFFER, | ||
createGriddedRectangleArray, | ||
numGrids, | ||
startX, | ||
endX, | ||
startY, | ||
endY, | ||
).value; | ||
} |
Oops, something went wrong.