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

mol-plugin: convert dynamic density streaming to static value

parent 958654d6
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,6 @@ import { LRUCache } from 'mol-util/lru-cache'; ...@@ -19,7 +19,6 @@ import { LRUCache } from 'mol-util/lru-cache';
import { ParamDefinition as PD } from 'mol-util/param-definition'; import { ParamDefinition as PD } from 'mol-util/param-definition';
import { urlCombine } from 'mol-util/url'; import { urlCombine } from 'mol-util/url';
import { VolumeServerHeader, VolumeServerInfo } from './model'; import { VolumeServerHeader, VolumeServerInfo } from './model';
import { CreateVolumeStreamingBehavior } from './transformers';
import { ButtonsType } from 'mol-util/input/input-observer'; import { ButtonsType } from 'mol-util/input/input-observer';
import { PluginCommands } from 'mol-plugin/command'; import { PluginCommands } from 'mol-plugin/command';
import { StateSelection } from 'mol-state'; import { StateSelection } from 'mol-state';
...@@ -93,7 +92,7 @@ export namespace VolumeStreaming { ...@@ -93,7 +92,7 @@ export namespace VolumeStreaming {
export class Behavior extends PluginBehavior.WithSubscribers<Params> { export class Behavior extends PluginBehavior.WithSubscribers<Params> {
private cache = LRUCache.create<ChannelsData>(25); private cache = LRUCache.create<ChannelsData>(25);
private params: Params = {} as any; public params: Params = {} as any;
// private ref: string = ''; // private ref: string = '';
channels: Channels = {} channels: Channels = {}
...@@ -151,19 +150,19 @@ export namespace VolumeStreaming { ...@@ -151,19 +150,19 @@ export namespace VolumeStreaming {
private updateDynamicBox(ref: string, box: Box3D) { private updateDynamicBox(ref: string, box: Box3D) {
if (this.params.view.name !== 'selection-box') return; if (this.params.view.name !== 'selection-box') return;
const eR = this.params.view.params.radius;
const state = this.plugin.state.dataState; const state = this.plugin.state.dataState;
const update = state.build().to(ref).update(CreateVolumeStreamingBehavior, old => ({ const newParams: Params = {
...old, ...this.params,
view: { view: {
name: 'selection-box' as 'selection-box', name: 'selection-box' as 'selection-box',
params: { params: {
radius: eR, radius: this.params.view.params.radius,
bottomLeft: box.min, bottomLeft: box.min,
topRight: box.max topRight: box.max
} }
} }
})); };
const update = state.build().to(ref).update(newParams);
PluginCommands.State.Update.dispatch(this.plugin, { state, tree: update, options: { doNotUpdateCurrent: true } }); PluginCommands.State.Update.dispatch(this.plugin, { state, tree: update, options: { doNotUpdateCurrent: true } });
} }
...@@ -251,6 +250,13 @@ export namespace VolumeStreaming { ...@@ -251,6 +250,13 @@ export namespace VolumeStreaming {
}; };
} }
getDescription() {
if (this.params.view.name === 'selection-box') return 'Selection';
if (this.params.view.name === 'box') return 'Static Box';
if (this.params.view.name === 'cell') return 'Cell';
return '';
}
constructor(public plugin: PluginContext, public info: VolumeServerInfo.Data) { constructor(public plugin: PluginContext, public info: VolumeServerInfo.Data) {
super(plugin); super(plugin);
} }
......
...@@ -18,6 +18,8 @@ import { VolumeStreaming } from './behavior'; ...@@ -18,6 +18,8 @@ import { VolumeStreaming } from './behavior';
import { VolumeRepresentation3DHelpers } from 'mol-plugin/state/transforms/representation'; import { VolumeRepresentation3DHelpers } from 'mol-plugin/state/transforms/representation';
import { BuiltInVolumeRepresentations } from 'mol-repr/volume/registry'; import { BuiltInVolumeRepresentations } from 'mol-repr/volume/registry';
import { createTheme } from 'mol-theme/theme'; import { createTheme } from 'mol-theme/theme';
import { Box3D } from 'mol-math/geometry';
import { Vec3 } from 'mol-math/linear-algebra';
// import { PluginContext } from 'mol-plugin/context'; // import { PluginContext } from 'mol-plugin/context';
export const InitVolumeStreaming = StateAction.build({ export const InitVolumeStreaming = StateAction.build({
...@@ -65,6 +67,29 @@ export const InitVolumeStreaming = StateAction.build({ ...@@ -65,6 +67,29 @@ export const InitVolumeStreaming = StateAction.build({
await state.updateTree(behTree).runInContext(taskCtx); await state.updateTree(behTree).runInContext(taskCtx);
})); }));
export const BoxifyVolumeStreaming = StateAction.build({
display: { name: 'Boxify Volume Streaming', description: 'Make the current box permanent.' },
from: VolumeStreaming,
isApplicable: (a) => a.data.params.view.name === 'selection-box'
})(({ a, ref, state }, plugin: PluginContext) => {
const params = a.data.params;
if (params.view.name !== 'selection-box') return;
const box = Box3D.create(Vec3.clone(params.view.params.bottomLeft), Vec3.clone(params.view.params.topRight));
const r = params.view.params.radius;
Box3D.expand(box, box, Vec3.create(r, r, r));
const newParams: VolumeStreaming.Params = {
...params,
view: {
name: 'box' as 'box',
params: {
bottomLeft: box.min,
topRight: box.max
}
}
};
return state.updateTree(state.build().to(ref).update(newParams));
});
export { CreateVolumeStreamingInfo } export { CreateVolumeStreamingInfo }
type CreateVolumeStreamingInfo = typeof CreateVolumeStreamingInfo type CreateVolumeStreamingInfo = typeof CreateVolumeStreamingInfo
const CreateVolumeStreamingInfo = PluginStateTransform.BuiltIn({ const CreateVolumeStreamingInfo = PluginStateTransform.BuiltIn({
...@@ -120,11 +145,13 @@ const CreateVolumeStreamingBehavior = PluginStateTransform.BuiltIn({ ...@@ -120,11 +145,13 @@ const CreateVolumeStreamingBehavior = PluginStateTransform.BuiltIn({
apply: ({ a, params }, plugin: PluginContext) => Task.create('Volume streaming', async _ => { apply: ({ a, params }, plugin: PluginContext) => Task.create('Volume streaming', async _ => {
const behavior = new VolumeStreaming.Behavior(plugin, a.data); const behavior = new VolumeStreaming.Behavior(plugin, a.data);
await behavior.update(params); await behavior.update(params);
return new VolumeStreaming(behavior, { label: 'Volume Streaming' }); return new VolumeStreaming(behavior, { label: 'Volume Streaming', description: behavior.getDescription() });
}), }),
update({ b, newParams }) { update({ b, newParams }) {
return Task.create('Update Volume Streaming', async _ => { return Task.create('Update Volume Streaming', async _ => {
return await b.data.update(newParams) ? StateTransformer.UpdateResult.Updated : StateTransformer.UpdateResult.Unchanged; const ret = await b.data.update(newParams) ? StateTransformer.UpdateResult.Updated : StateTransformer.UpdateResult.Unchanged;
b.description = b.data.getDescription();
return ret;
}); });
} }
}); });
......
...@@ -14,7 +14,7 @@ import { StateTransforms } from './state/transforms'; ...@@ -14,7 +14,7 @@ import { StateTransforms } from './state/transforms';
import { PluginBehaviors } from './behavior'; import { PluginBehaviors } from './behavior';
import { AnimateModelIndex } from './state/animation/built-in'; import { AnimateModelIndex } from './state/animation/built-in';
import { StateActions } from './state/actions'; import { StateActions } from './state/actions';
import { InitVolumeStreaming } from './behavior/dynamic/volume-streaming/transformers'; import { InitVolumeStreaming, BoxifyVolumeStreaming, CreateVolumeStreamingBehavior } from './behavior/dynamic/volume-streaming/transformers';
import { StructureRepresentationInteraction } from './behavior/dynamic/selection/structure-representation-interaction'; import { StructureRepresentationInteraction } from './behavior/dynamic/selection/structure-representation-interaction';
export const DefaultPluginSpec: PluginSpec = { export const DefaultPluginSpec: PluginSpec = {
...@@ -25,8 +25,10 @@ export const DefaultPluginSpec: PluginSpec = { ...@@ -25,8 +25,10 @@ export const DefaultPluginSpec: PluginSpec = {
PluginSpec.Action(StateActions.Structure.CreateComplexRepresentation), PluginSpec.Action(StateActions.Structure.CreateComplexRepresentation),
PluginSpec.Action(StateActions.Structure.EnableModelCustomProps), PluginSpec.Action(StateActions.Structure.EnableModelCustomProps),
// PluginSpec.Action(StateActions.Volume.InitVolumeStreaming), // Volume streaming
PluginSpec.Action(InitVolumeStreaming), PluginSpec.Action(InitVolumeStreaming),
PluginSpec.Action(BoxifyVolumeStreaming),
PluginSpec.Action(CreateVolumeStreamingBehavior),
PluginSpec.Action(StateTransforms.Data.Download), PluginSpec.Action(StateTransforms.Data.Download),
PluginSpec.Action(StateTransforms.Data.ParseCif), PluginSpec.Action(StateTransforms.Data.ParseCif),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment