Browse Source

mol-plugin: convert dynamic density streaming to static value

David Sehnal 6 years ago
parent
commit
0dc372dd61

+ 13 - 7
src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts

@@ -19,7 +19,6 @@ import { LRUCache } from 'mol-util/lru-cache';
 import { ParamDefinition as PD } from 'mol-util/param-definition';
 import { urlCombine } from 'mol-util/url';
 import { VolumeServerHeader, VolumeServerInfo } from './model';
-import { CreateVolumeStreamingBehavior } from './transformers';
 import { ButtonsType } from 'mol-util/input/input-observer';
 import { PluginCommands } from 'mol-plugin/command';
 import { StateSelection } from 'mol-state';
@@ -93,7 +92,7 @@ export namespace VolumeStreaming {
 
     export class Behavior extends PluginBehavior.WithSubscribers<Params> {
         private cache = LRUCache.create<ChannelsData>(25);
-        private params: Params = {} as any;
+        public params: Params = {} as any;
         // private ref: string = '';
 
         channels: Channels = {}
@@ -151,19 +150,19 @@ export namespace VolumeStreaming {
         private updateDynamicBox(ref: string, box: Box3D) {
             if (this.params.view.name !== 'selection-box') return;
 
-            const eR = this.params.view.params.radius;
             const state = this.plugin.state.dataState;
-            const update = state.build().to(ref).update(CreateVolumeStreamingBehavior, old => ({
-                ...old,
+            const newParams: Params = {
+                ...this.params,
                 view: {
                     name: 'selection-box' as 'selection-box',
                     params: {
-                        radius: eR,
+                        radius: this.params.view.params.radius,
                         bottomLeft: box.min,
                         topRight: box.max
                     }
                 }
-            }));
+            };
+            const update = state.build().to(ref).update(newParams);
 
             PluginCommands.State.Update.dispatch(this.plugin, { state, tree: update, options: { doNotUpdateCurrent: true } });
         }
@@ -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) {
             super(plugin);
         }

+ 29 - 2
src/mol-plugin/behavior/dynamic/volume-streaming/transformers.ts

@@ -18,6 +18,8 @@ import { VolumeStreaming } from './behavior';
 import { VolumeRepresentation3DHelpers } from 'mol-plugin/state/transforms/representation';
 import { BuiltInVolumeRepresentations } from 'mol-repr/volume/registry';
 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';
 
 export const InitVolumeStreaming = StateAction.build({
@@ -65,6 +67,29 @@ export const InitVolumeStreaming = StateAction.build({
     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 }
 type CreateVolumeStreamingInfo = typeof CreateVolumeStreamingInfo
 const CreateVolumeStreamingInfo = PluginStateTransform.BuiltIn({
@@ -120,11 +145,13 @@ const CreateVolumeStreamingBehavior = PluginStateTransform.BuiltIn({
     apply: ({ a, params }, plugin: PluginContext) => Task.create('Volume streaming', async _ => {
         const behavior = new VolumeStreaming.Behavior(plugin, a.data);
         await behavior.update(params);
-        return new VolumeStreaming(behavior, { label: 'Volume Streaming' });
+        return new VolumeStreaming(behavior, { label: 'Volume Streaming', description: behavior.getDescription() });
     }),
     update({ b, newParams }) {
         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;
         });
     }
 });

+ 4 - 2
src/mol-plugin/index.ts

@@ -14,7 +14,7 @@ import { StateTransforms } from './state/transforms';
 import { PluginBehaviors } from './behavior';
 import { AnimateModelIndex } from './state/animation/built-in';
 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';
 
 export const DefaultPluginSpec: PluginSpec = {
@@ -25,8 +25,10 @@ export const DefaultPluginSpec: PluginSpec = {
         PluginSpec.Action(StateActions.Structure.CreateComplexRepresentation),
         PluginSpec.Action(StateActions.Structure.EnableModelCustomProps),
 
-        // PluginSpec.Action(StateActions.Volume.InitVolumeStreaming),
+        // Volume streaming
         PluginSpec.Action(InitVolumeStreaming),
+        PluginSpec.Action(BoxifyVolumeStreaming),
+        PluginSpec.Action(CreateVolumeStreamingBehavior),
 
         PluginSpec.Action(StateTransforms.Data.Download),
         PluginSpec.Action(StateTransforms.Data.ParseCif),