Skip to content
Snippets Groups Projects
Commit b70b57f7 authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin: use color strips for Color and ColorScale controls

parents b5433d65 d7f53329
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ import { transformPositionArray } from 'mol-geo/util'; ...@@ -21,6 +21,7 @@ import { transformPositionArray } from 'mol-geo/util';
import { calculateBoundingSphere } from 'mol-gl/renderable/util'; import { calculateBoundingSphere } from 'mol-gl/renderable/util';
import { Theme } from 'mol-theme/theme'; import { Theme } from 'mol-theme/theme';
import { RenderableState } from 'mol-gl/renderable'; import { RenderableState } from 'mol-gl/renderable';
import { ColorListOptions, ColorListName } from 'mol-util/color/scale';
const VolumeBox = Box() const VolumeBox = Box()
const RenderModeOptions = [['isosurface', 'Isosurface'], ['volume', 'Volume']] as [string, string][] const RenderModeOptions = [['isosurface', 'Isosurface'], ['volume', 'Volume']] as [string, string][]
...@@ -73,6 +74,7 @@ export namespace DirectVolume { ...@@ -73,6 +74,7 @@ export namespace DirectVolume {
isoValue: PD.Numeric(0.22, { min: -1, max: 1, step: 0.01 }), isoValue: PD.Numeric(0.22, { min: -1, max: 1, step: 0.01 }),
renderMode: PD.Select('isosurface', RenderModeOptions), renderMode: PD.Select('isosurface', RenderModeOptions),
controlPoints: PD.LineGraph([Vec2.create(0.19, 0.1), Vec2.create(0.2, 0.5), Vec2.create(0.21, 0.1), Vec2.create(0.4, 0.3)]), controlPoints: PD.LineGraph([Vec2.create(0.19, 0.1), Vec2.create(0.2, 0.5), Vec2.create(0.21, 0.1), Vec2.create(0.4, 0.3)]),
list: PD.ColorScale<ColorListName>('RdYlBu', ColorListOptions),
} }
export type Params = typeof Params export type Params = typeof Params
...@@ -89,7 +91,7 @@ export namespace DirectVolume { ...@@ -89,7 +91,7 @@ export namespace DirectVolume {
const boundingSphere = getBoundingSphere(gridDimension.ref.value, gridTransform.ref.value, transform.aTransform.ref.value, transform.instanceCount.ref.value) const boundingSphere = getBoundingSphere(gridDimension.ref.value, gridTransform.ref.value, transform.aTransform.ref.value, transform.instanceCount.ref.value)
const controlPoints = getControlPointsFromVec2Array(props.controlPoints) const controlPoints = getControlPointsFromVec2Array(props.controlPoints)
const transferTex = createTransferFunctionTexture(controlPoints) const transferTex = createTransferFunctionTexture(controlPoints, props.list)
const maxSteps = Math.ceil(Vec3.magnitude(gridDimension.ref.value)) * 2 * 5 const maxSteps = Math.ceil(Vec3.magnitude(gridDimension.ref.value)) * 2 * 5
...@@ -126,7 +128,7 @@ export namespace DirectVolume { ...@@ -126,7 +128,7 @@ export namespace DirectVolume {
ValueCell.updateIfChanged(values.dRenderMode, props.renderMode) ValueCell.updateIfChanged(values.dRenderMode, props.renderMode)
const controlPoints = getControlPointsFromVec2Array(props.controlPoints) const controlPoints = getControlPointsFromVec2Array(props.controlPoints)
createTransferFunctionTexture(controlPoints, values.tTransferTex) createTransferFunctionTexture(controlPoints, props.list, values.tTransferTex)
} }
export function updateBoundingSphere(values: DirectVolumeValues, directVolume: DirectVolume) { export function updateBoundingSphere(values: DirectVolumeValues, directVolume: DirectVolume) {
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
import { TextureImage } from 'mol-gl/renderable/util'; import { TextureImage } from 'mol-gl/renderable/util';
import { spline } from 'mol-math/interpolate'; import { spline } from 'mol-math/interpolate';
import { ColorScale } from 'mol-util/color'; import { ColorScale, Color } from 'mol-util/color';
import { ColorMatplotlib } from 'mol-util/color/tables';
import { ValueCell } from 'mol-util'; import { ValueCell } from 'mol-util';
import { Vec2 } from 'mol-math/linear-algebra'; import { Vec2 } from 'mol-math/linear-algebra';
import { ColorListName } from 'mol-util/color/scale';
export interface ControlPoint { x: number, alpha: number } export interface ControlPoint { x: number, alpha: number }
...@@ -24,8 +24,7 @@ export function getControlPointsFromVec2Array(array: Vec2[]): ControlPoint[] { ...@@ -24,8 +24,7 @@ export function getControlPointsFromVec2Array(array: Vec2[]): ControlPoint[] {
return array.map(v => ({ x: v[0], alpha: v[1] })) return array.map(v => ({ x: v[0], alpha: v[1] }))
} }
// TODO move core function to mol-canvas3d/color export function createTransferFunctionTexture(controlPoints: ControlPoint[], listOrName: Color[] | ColorListName, texture?: ValueCell<TextureImage<Uint8Array>>): ValueCell<TextureImage<Uint8Array>> {
export function createTransferFunctionTexture(controlPoints: ControlPoint[], texture?: ValueCell<TextureImage<Uint8Array>>): ValueCell<TextureImage<Uint8Array>> {
const cp = [ const cp = [
{ x: 0, alpha: 0 }, { x: 0, alpha: 0 },
{ x: 0, alpha: 0 }, { x: 0, alpha: 0 },
...@@ -33,10 +32,7 @@ export function createTransferFunctionTexture(controlPoints: ControlPoint[], tex ...@@ -33,10 +32,7 @@ export function createTransferFunctionTexture(controlPoints: ControlPoint[], tex
{ x: 1, alpha: 0 }, { x: 1, alpha: 0 },
{ x: 1, alpha: 0 }, { x: 1, alpha: 0 },
] ]
const scale = ColorScale.create({ const scale = ColorScale.create({ domain: [0, 1], listOrName })
domain: [0, 1],
listOrName: ColorMatplotlib.viridis
})
const n = 256 const n = 256
const array = texture ? texture.ref.value.array : new Uint8Array(n * 4) const array = texture ? texture.ref.value.array : new Uint8Array(n * 4)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment