Browse Source

factored-out marker-action

Alexander Rose 5 years ago
parent
commit
8d0f7a2dc7

+ 1 - 1
src/mol-canvas3d/canvas3d.ts

@@ -17,7 +17,7 @@ import { Representation } from '../mol-repr/representation';
 import Scene from '../mol-gl/scene';
 import { GraphicsRenderVariant } from '../mol-gl/webgl/render-item';
 import { PickingId } from '../mol-geo/geometry/picking';
-import { MarkerAction } from '../mol-geo/geometry/marker-data';
+import { MarkerAction } from '../mol-util/marker-action';
 import { Loci, EmptyLoci, isEmptyLoci } from '../mol-model/loci';
 import { Camera } from './camera';
 import { ParamDefinition as PD } from '../mol-util/param-definition';

+ 0 - 51
src/mol-geo/geometry/marker-data.ts

@@ -13,57 +13,6 @@ export type MarkerData = {
     uMarkerTexDim: ValueCell<Vec2>
 }
 
-export enum MarkerAction {
-    Highlight,
-    RemoveHighlight,
-    Select,
-    Deselect,
-    Toggle,
-    Clear
-}
-
-export function applyMarkerAction(array: Uint8Array, start: number, end: number, action: MarkerAction) {
-    let changed = false
-    for (let i = start; i < end; ++i) {
-        let v = array[i]
-        switch (action) {
-            case MarkerAction.Highlight:
-                if (v % 2 === 0) {
-                    v += 1
-                }
-                break
-            case MarkerAction.RemoveHighlight:
-                if (v % 2 !== 0) {
-                    v -= 1
-                }
-                break
-            case MarkerAction.Select:
-                if (v < 2) v += 2
-                // v += 2
-                break
-            case MarkerAction.Deselect:
-                // if (v >= 2) {
-                //     v -= 2
-                // }
-                v = v % 2
-                break
-            case MarkerAction.Toggle:
-                if (v >= 2) {
-                    v -= 2
-                } else {
-                    v += 2
-                }
-                break
-            case MarkerAction.Clear:
-                v = 0
-                break
-        }
-        changed = array[i] !== v || changed
-        array[i] = v
-    }
-    return changed
-}
-
 export function createMarkers(count: number, markerData?: MarkerData): MarkerData {
     const markers = createTextureImage(Math.max(1, count), 1, Uint8Array, markerData && markerData.tMarker.ref.value.array)
     if (markerData) {

+ 1 - 1
src/mol-plugin/behavior/dynamic/representation.ts

@@ -5,7 +5,7 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { MarkerAction } from '../../../mol-geo/geometry/marker-data';
+import { MarkerAction } from '../../../mol-util/marker-action';
 import { PluginContext } from '../../../mol-plugin/context';
 import { labelFirst } from '../../../mol-theme/label';
 import { PluginBehavior } from '../behavior';

+ 8 - 13
src/mol-plugin/ui/sequence.tsx

@@ -13,7 +13,7 @@ import { PluginStateObject as SO } from '../state/objects';
 import { Interaction } from '../util/interaction';
 import { OrderedSet, Interval } from '../../mol-data/int';
 import { Loci } from '../../mol-model/loci';
-import { applyMarkerAction, MarkerAction } from '../../mol-geo/geometry/marker-data';
+import { applyMarkerAction, MarkerAction } from '../../mol-util/marker-action';
 import { ButtonsType, ModifiersKeys, getButtons, getModifiers } from '../../mol-util/input/input-observer';
 
 function getStructureSeqKey(structureSeq: StructureSeq) {
@@ -87,6 +87,7 @@ function createQuery(entityId: string, label_seq_id: number) {
     });
 }
 
+/** Zero-indexed */
 function getSeqIdInterval(location: StructureElement): Interval {
     const { unit, element } = location
     const { model } = unit
@@ -94,16 +95,16 @@ function getSeqIdInterval(location: StructureElement): Interval {
         case Unit.Kind.Atomic:
             const residueIndex = model.atomicHierarchy.residueAtomSegments.index[element]
             const seqId = model.atomicHierarchy.residues.label_seq_id.value(residueIndex)
-            return Interval.ofSingleton(seqId)
+            return Interval.ofSingleton(seqId - 1)
         case Unit.Kind.Spheres:
             return Interval.ofRange(
-                model.coarseHierarchy.spheres.seq_id_begin.value(element),
-                model.coarseHierarchy.spheres.seq_id_end.value(element)
+                model.coarseHierarchy.spheres.seq_id_begin.value(element) - 1,
+                model.coarseHierarchy.spheres.seq_id_end.value(element) - 1
             )
         case Unit.Kind.Gaussians:
             return Interval.ofRange(
-                model.coarseHierarchy.gaussians.seq_id_begin.value(element),
-                model.coarseHierarchy.gaussians.seq_id_end.value(element)
+                model.coarseHierarchy.gaussians.seq_id_begin.value(element) - 1,
+                model.coarseHierarchy.gaussians.seq_id_end.value(element) - 1
             )
     }
 }
@@ -132,13 +133,7 @@ function eachResidue(loci: Loci, structureSeq: StructureSeq, apply: (interval: I
 function markResidue(loci: Loci, structureSeq: StructureSeq, array: Uint8Array, action: MarkerAction) {
     const { structure, seq } = structureSeq
     return eachResidue(loci, { structure , seq }, (i: Interval) => {
-        let changed = false
-        OrderedSet.forEach(i, (v: number) => {
-            const start = Interval.start(i) - 1
-            const end = Interval.end(i) - 1
-            if (applyMarkerAction(array, start, end, action)) changed = true
-        })
-        return changed
+        return applyMarkerAction(array, i, action)
     })
 }
 

+ 1 - 1
src/mol-plugin/util/interaction.ts

@@ -9,7 +9,7 @@ import { Loci as ModelLoci, EmptyLoci } from '../../mol-model/loci';
 import { ModifiersKeys, ButtonsType } from '../../mol-util/input/input-observer';
 import { Representation } from '../../mol-repr/representation';
 import { StructureElement } from '../../mol-model/structure';
-import { MarkerAction } from '../../mol-geo/geometry/marker-data';
+import { MarkerAction } from '../../mol-util/marker-action';
 import { StructureElementSelectionManager } from './structure-element-selection';
 import { PluginContext } from '../context';
 

+ 1 - 1
src/mol-repr/representation.ts

@@ -13,7 +13,7 @@ import { Subject } from 'rxjs';
 import { GraphicsRenderObject } from '../mol-gl/render-object';
 import { Task } from '../mol-task';
 import { PickingId } from '../mol-geo/geometry/picking';
-import { MarkerAction } from '../mol-geo/geometry/marker-data';
+import { MarkerAction } from '../mol-util/marker-action';
 import { Loci as ModelLoci, EmptyLoci, isEmptyLoci } from '../mol-model/loci';
 import { Overpaint } from '../mol-theme/overpaint';
 import { Transparency } from '../mol-theme/transparency';

+ 2 - 1
src/mol-repr/shape/representation.ts

@@ -14,7 +14,8 @@ import { LocationIterator } from '../../mol-geo/util/location-iterator';
 import { VisualUpdateState } from '../util';
 import { ShapeGroupColorTheme } from '../../mol-theme/color/shape-group';
 import { ShapeGroupSizeTheme } from '../../mol-theme/size/shape-group';
-import { createMarkers, MarkerAction } from '../../mol-geo/geometry/marker-data';
+import { createMarkers } from '../../mol-geo/geometry/marker-data';
+import { MarkerAction } from '../../mol-util/marker-action';
 import { ValueCell } from '../../mol-util';
 import { createColors } from '../../mol-geo/geometry/color-data';
 import { createSizes } from '../../mol-geo/geometry/size-data';

+ 1 - 1
src/mol-repr/structure/complex-representation.ts

@@ -15,7 +15,7 @@ import { createEmptyTheme, Theme } from '../../mol-theme/theme';
 import { Task } from '../../mol-task';
 import { PickingId } from '../../mol-geo/geometry/picking';
 import { EmptyLoci, Loci } from '../../mol-model/loci';
-import { MarkerAction } from '../../mol-geo/geometry/marker-data';
+import { MarkerAction } from '../../mol-util/marker-action';
 
 export function ComplexRepresentation<P extends StructureParams>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, P>, visualCtor: (materialId: number) => ComplexVisual<P>): StructureRepresentation<P> {
     let version = 0

+ 1 - 1
src/mol-repr/structure/complex-visual.ts

@@ -23,7 +23,7 @@ import { ColorTheme } from '../../mol-theme/color';
 import { ValueCell, deepEqual } from '../../mol-util';
 import { createSizes } from '../../mol-geo/geometry/size-data';
 import { createColors } from '../../mol-geo/geometry/color-data';
-import { MarkerAction } from '../../mol-geo/geometry/marker-data';
+import { MarkerAction } from '../../mol-util/marker-action';
 import { Mat4 } from '../../mol-math/linear-algebra';
 import { Overpaint } from '../../mol-theme/overpaint';
 import { Transparency } from '../../mol-theme/transparency';

+ 1 - 1
src/mol-repr/structure/units-representation.ts

@@ -18,7 +18,7 @@ import { createEmptyTheme, Theme } from '../../mol-theme/theme';
 import { Task } from '../../mol-task';
 import { PickingId } from '../../mol-geo/geometry/picking';
 import { Loci, EmptyLoci, isEmptyLoci } from '../../mol-model/loci';
-import { MarkerAction } from '../../mol-geo/geometry/marker-data';
+import { MarkerAction } from '../../mol-util/marker-action';
 
 export const UnitsParams = {
     ...StructureParams,

+ 2 - 1
src/mol-repr/structure/units-visual.ts

@@ -19,7 +19,8 @@ import { Loci, isEveryLoci, EmptyLoci } from '../../mol-model/loci';
 import { Interval } from '../../mol-data/int';
 import { VisualUpdateState } from '../util';
 import { ColorTheme } from '../../mol-theme/color';
-import { createMarkers, MarkerAction } from '../../mol-geo/geometry/marker-data';
+import { createMarkers } from '../../mol-geo/geometry/marker-data';
+import { MarkerAction } from '../../mol-util/marker-action';
 import { ValueCell, deepEqual } from '../../mol-util';
 import { createSizes } from '../../mol-geo/geometry/size-data';
 import { createColors } from '../../mol-geo/geometry/color-data';

+ 2 - 4
src/mol-repr/visual.ts

@@ -8,7 +8,7 @@ import { RuntimeContext } from '../mol-task'
 import { GraphicsRenderObject } from '../mol-gl/render-object'
 import { PickingId } from '../mol-geo/geometry/picking';
 import { Loci, isEmptyLoci } from '../mol-model/loci';
-import { MarkerAction, applyMarkerAction } from '../mol-geo/geometry/marker-data';
+import { MarkerAction, applyMarkerAction } from '../mol-util/marker-action';
 import { ParamDefinition as PD } from '../mol-util/param-definition';
 import { WebGLContext } from '../mol-gl/webgl/context';
 import { Theme } from '../mol-theme/theme';
@@ -65,9 +65,7 @@ namespace Visual {
         const { tMarker } = renderObject.values
 
         function apply(interval: Interval) {
-            const start = Interval.start(interval)
-            const end = Interval.end(interval)
-            return applyMarkerAction(tMarker.ref.value.array, start, end, action)
+            return applyMarkerAction(tMarker.ref.value.array, interval, action)
         }
 
         const changed = lociApply(loci, apply)

+ 1 - 1
src/mol-repr/volume/representation.ts

@@ -20,7 +20,7 @@ import { ColorTheme } from '../../mol-theme/color';
 import { ValueCell } from '../../mol-util';
 import { createSizes } from '../../mol-geo/geometry/size-data';
 import { createColors } from '../../mol-geo/geometry/color-data';
-import { MarkerAction } from '../../mol-geo/geometry/marker-data';
+import { MarkerAction } from '../../mol-util/marker-action';
 import { Mat4 } from '../../mol-math/linear-algebra';
 import { Overpaint } from '../../mol-theme/overpaint';
 import { Transparency } from '../../mol-theme/transparency';

+ 60 - 0
src/mol-util/marker-action.ts

@@ -0,0 +1,60 @@
+import { OrderedSet } from '../mol-data/int';
+
+/**
+ * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ */
+
+export enum MarkerAction {
+    Highlight,
+    RemoveHighlight,
+    Select,
+    Deselect,
+    Toggle,
+    Clear
+}
+
+export function applyMarkerAction(array: Uint8Array, set: OrderedSet, action: MarkerAction) {
+    let changed = false;
+    OrderedSet.forEach(set, i => {
+        let v = array[i];
+        switch (action) {
+            case MarkerAction.Highlight:
+                if (v % 2 === 0) {
+                    v += 1;
+                }
+                break;
+            case MarkerAction.RemoveHighlight:
+                if (v % 2 !== 0) {
+                    v -= 1;
+                }
+                break;
+            case MarkerAction.Select:
+                if (v < 2)
+                    v += 2;
+                // v += 2
+                break;
+            case MarkerAction.Deselect:
+                // if (v >= 2) {
+                //     v -= 2
+                // }
+                v = v % 2;
+                break;
+            case MarkerAction.Toggle:
+                if (v >= 2) {
+                    v -= 2;
+                }
+                else {
+                    v += 2;
+                }
+                break;
+            case MarkerAction.Clear:
+                v = 0;
+                break;
+        }
+        changed = array[i] !== v || changed;
+        array[i] = v;
+    })
+    return changed;
+}

+ 1 - 1
src/tests/browser/render-shape.ts

@@ -9,7 +9,7 @@ import { resizeCanvas } from '../../mol-canvas3d/util';
 import { Representation } from '../../mol-repr/representation';
 import { Canvas3D } from '../../mol-canvas3d/canvas3d';
 import { labelFirst } from '../../mol-theme/label';
-import { MarkerAction } from '../../mol-geo/geometry/marker-data';
+import { MarkerAction } from '../../mol-util/marker-action';
 import { EveryLoci } from '../../mol-model/loci';
 import { RuntimeContext, Progress } from '../../mol-task';
 import { Mesh } from '../../mol-geo/geometry/mesh/mesh';