tweak cube clamp param

This commit is contained in:
Alexander Rose
2022-11-08 22:28:47 -08:00
parent 842824057b
commit 3667092327
2 changed files with 16 additions and 7 deletions

View File

@@ -14,7 +14,7 @@ import { ModelFormat } from '../format';
import { CustomProperties } from '../../mol-model/custom-property';
import { clamp } from '../../mol-math/interpolate';
export function volumeFromCube(source: CubeFile, params?: { dataIndex?: number, label?: string, entryId?: string, clampMin?: number, clampMax?: number }): Task<Volume> {
export function volumeFromCube(source: CubeFile, params?: { dataIndex?: number, label?: string, entryId?: string, clamp?: { min: number, max: number } }): Task<Volume> {
return Task.create<Volume>('Create Volume', async () => {
const { header, values: sourceValues } = source;
const space = Tensor.Space(header.dim, [0, 1, 2], Float64Array);
@@ -26,8 +26,7 @@ export function volumeFromCube(source: CubeFile, params?: { dataIndex?: number,
// get every nth value from the source values
const [h, k, l] = header.dim;
const nth = (params?.dataIndex || 0) + 1;
const clampMin = params?.clampMin || -Infinity;
const clampMax = params?.clampMax || -Infinity;
const { min, max } = params?.clamp || { min: -Infinity, max: Infinity };
let o = 0, s = 0;
@@ -35,7 +34,7 @@ export function volumeFromCube(source: CubeFile, params?: { dataIndex?: number,
for (let u = 0; u < h; u++) {
for (let v = 0; v < k; v++) {
for (let w = 0; w < l; w++) {
values[o++] = clamp(sourceValues[s], clampMin, clampMax);
values[o++] = clamp(sourceValues[s], min, max);
s += nth;
}
}

View File

@@ -88,14 +88,24 @@ const VolumeFromCube = PluginStateTransform.BuiltIn({
return {
dataIndex,
entryId: PD.Text(''),
clampMin: PD.Numeric(-1024),
clampMax: PD.Numeric(1024),
clamp: PD.MappedStatic('off', {
'off': PD.EmptyGroup(),
'on': PD.Group({
min: PD.Numeric(-1024),
max: PD.Numeric(1024),
})
}, { cycle: true })
};
}
})({
apply({ a, params }) {
return Task.create('Create volume from Cube', async ctx => {
const volume = await volumeFromCube(a.data, { ...params, label: a.data.name || a.label }).runInContext(ctx);
const volume = await volumeFromCube(a.data, {
dataIndex: params.dataIndex,
label: a.data.name || a.label,
entryId: params.entryId,
clamp: params.clamp.name === 'on' ? params.clamp.params : undefined,
}).runInContext(ctx);
const props = { label: volume.label || 'Volume', description: `Volume ${a.data.header.dim[0]}\u00D7${a.data.header.dim[1]}\u00D7${a.data.header.dim[2]}` };
return new SO.Volume.Data(volume, props);
});