From 6d9c41b98b2039234e62d7863410307dfaa119a1 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sat, 17 Nov 2018 14:22:50 -0800 Subject: [PATCH] repr updateState fixes; added sizeAspectRatio param for links --- .../representation/ball-and-stick.ts | 3 ++- .../visual/carbohydrate-link-cylinder.ts | 6 ++++-- .../visual/carbohydrate-symbol-mesh.ts | 5 ++++- .../carbohydrate-terminal-link-cylinder.ts | 6 ++++-- .../visual/cross-link-restraint-cylinder.ts | 13 ++++++++---- .../structure/visual/element-sphere.ts | 5 ++++- .../visual/inter-unit-link-cylinder.ts | 13 ++++++++---- .../visual/intra-unit-link-cylinder.ts | 21 ++++++++++++------- .../structure/visual/nucleotide-block-mesh.ts | 7 ++++++- .../visual/polymer-backbone-cylinder.ts | 12 +++++++---- .../visual/polymer-direction-wedge.ts | 7 ++++++- .../structure/visual/polymer-gap-cylinder.ts | 5 ++++- .../structure/visual/polymer-trace-mesh.ts | 1 + 13 files changed, 74 insertions(+), 30 deletions(-) diff --git a/src/mol-repr/structure/representation/ball-and-stick.ts b/src/mol-repr/structure/representation/ball-and-stick.ts index d28d47897..4ea997482 100644 --- a/src/mol-repr/structure/representation/ball-and-stick.ts +++ b/src/mol-repr/structure/representation/ball-and-stick.ts @@ -30,7 +30,8 @@ export const BallAndStickParams = { ...IntraUnitLinkParams, ...InterUnitLinkParams, unitKinds: PD.MultiSelect<UnitKind>(['atomic'], UnitKindOptions), - sizeFactor: PD.Numeric(0.2, { min: 0.01, max: 10, step: 0.01 }), + sizeFactor: PD.Numeric(0.3, { min: 0.01, max: 10, step: 0.01 }), + sizeAspectRatio: PD.Numeric(2/3, { min: 0.01, max: 3, step: 0.01 }), colorTheme: PD.Mapped('polymer-index', BuiltInColorThemeOptions, name => PD.Group((BuiltInColorThemes as { [k: string]: ColorTheme.Provider<any> })[name].getParams({}))), visuals: PD.MultiSelect<BallAndStickVisualName>(['element-sphere', 'intra-link', 'inter-link'], BallAndStickVisualOptions), } diff --git a/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts b/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts index 05d5a04b0..a85dddd51 100644 --- a/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts +++ b/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts @@ -51,7 +51,6 @@ async function createCarbohydrateLinkCylinderMesh(ctx: VisualContext, structure: export const CarbohydrateLinkParams = { ...UnitsMeshParams, ...LinkCylinderParams, - detail: PD.Numeric(0, { min: 0, max: 3, step: 1 }), linkSizeFactor: PD.Numeric(0.3, { min: 0, max: 3, step: 0.01 }), } export type CarbohydrateLinkParams = typeof CarbohydrateLinkParams @@ -64,7 +63,10 @@ export function CarbohydrateLinkVisual(): ComplexVisual<CarbohydrateLinkParams> getLoci: getLinkLoci, mark: markLink, setUpdateState: (state: VisualUpdateState, newProps: PD.Values<CarbohydrateLinkParams>, currentProps: PD.Values<CarbohydrateLinkParams>) => { - state.createGeometry = newProps.radialSegments !== currentProps.radialSegments + state.createGeometry = ( + newProps.linkSizeFactor !== currentProps.linkSizeFactor || + newProps.radialSegments !== currentProps.radialSegments + ) } }) } diff --git a/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts b/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts index 7a5acbf59..9a42ca5f7 100644 --- a/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts +++ b/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts @@ -159,7 +159,10 @@ export function CarbohydrateSymbolVisual(): ComplexVisual<CarbohydrateSymbolPara getLoci: getCarbohydrateLoci, mark: markCarbohydrate, setUpdateState: (state: VisualUpdateState, newProps: PD.Values<CarbohydrateSymbolParams>, currentProps: PD.Values<CarbohydrateSymbolParams>) => { - state.createGeometry = newProps.detail !== currentProps.detail + state.createGeometry = ( + newProps.sizeFactor !== currentProps.sizeFactor || + newProps.detail !== currentProps.detail + ) } }) } diff --git a/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts b/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts index 7d594fd78..3c4d57853 100644 --- a/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts +++ b/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts @@ -61,7 +61,6 @@ async function createCarbohydrateTerminalLinkCylinderMesh(ctx: VisualContext, st export const CarbohydrateTerminalLinkParams = { ...UnitsMeshParams, ...LinkCylinderParams, - detail: PD.Numeric(0, { min: 0, max: 3, step: 1 }), linkSizeFactor: PD.Numeric(0.3, { min: 0, max: 3, step: 0.01 }), } export type CarbohydrateTerminalLinkParams = typeof CarbohydrateTerminalLinkParams @@ -74,7 +73,10 @@ export function CarbohydrateTerminalLinkVisual(): ComplexVisual<CarbohydrateTerm getLoci: getTerminalLinkLoci, mark: markTerminalLink, setUpdateState: (state: VisualUpdateState, newProps: PD.Values<CarbohydrateTerminalLinkParams>, currentProps: PD.Values<CarbohydrateTerminalLinkParams>) => { - state.createGeometry = newProps.radialSegments !== currentProps.radialSegments + state.createGeometry = ( + newProps.linkSizeFactor !== currentProps.linkSizeFactor || + newProps.radialSegments !== currentProps.radialSegments + ) } }) } diff --git a/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts b/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts index 1b1d06ea8..bd1733ea4 100644 --- a/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts +++ b/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts @@ -7,7 +7,7 @@ import { Link, Structure, StructureElement } from 'mol-model/structure'; import { ComplexVisual } from '../representation'; import { VisualUpdateState } from '../../util'; -import { LinkCylinderProps, createLinkCylinderMesh, LinkCylinderParams } from './util/link'; +import { createLinkCylinderMesh, LinkCylinderParams } from './util/link'; import { Vec3 } from 'mol-math/linear-algebra'; import { Loci, EmptyLoci } from 'mol-model/loci'; import { ComplexMeshVisual, ComplexMeshParams } from '../complex-visual'; @@ -21,10 +21,11 @@ import { PickingId } from 'mol-geo/geometry/picking'; import { VisualContext } from 'mol-repr/representation'; import { Theme } from 'mol-theme/theme'; -async function createCrossLinkRestraintCylinderMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: LinkCylinderProps, mesh?: Mesh) { +async function createCrossLinkRestraintCylinderMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: PD.Values<CrossLinkRestraintParams>, mesh?: Mesh) { const crossLinks = structure.crossLinkRestraints if (!crossLinks.count) return Mesh.createEmpty(mesh) + const { sizeFactor } = props const location = StructureElement.create() @@ -43,7 +44,7 @@ async function createCrossLinkRestraintCylinderMesh(ctx: VisualContext, structur const b = crossLinks.pairs[edgeIndex] location.unit = b.unitA location.element = b.unitA.elements[b.indexA] - return theme.size.size(location) + return theme.size.size(location) * sizeFactor } } @@ -53,6 +54,7 @@ async function createCrossLinkRestraintCylinderMesh(ctx: VisualContext, structur export const CrossLinkRestraintParams = { ...ComplexMeshParams, ...LinkCylinderParams, + sizeFactor: PD.Numeric(1, { min: 0, max: 10, step: 0.1 }), } export type CrossLinkRestraintParams = typeof CrossLinkRestraintParams @@ -64,7 +66,10 @@ export function CrossLinkRestraintVisual(): ComplexVisual<CrossLinkRestraintPara getLoci: getLinkLoci, mark: markLink, setUpdateState: (state: VisualUpdateState, newProps: PD.Values<CrossLinkRestraintParams>, currentProps: PD.Values<CrossLinkRestraintParams>) => { - state.createGeometry = newProps.radialSegments !== currentProps.radialSegments + state.createGeometry = ( + newProps.sizeFactor !== currentProps.sizeFactor || + newProps.radialSegments !== currentProps.radialSegments + ) } }) } diff --git a/src/mol-repr/structure/visual/element-sphere.ts b/src/mol-repr/structure/visual/element-sphere.ts index 8f8002230..50c2abc39 100644 --- a/src/mol-repr/structure/visual/element-sphere.ts +++ b/src/mol-repr/structure/visual/element-sphere.ts @@ -28,7 +28,10 @@ export function ElementSphereVisual(): UnitsVisual<ElementSphereParams> { getLoci: getElementLoci, mark: markElement, setUpdateState: (state: VisualUpdateState, newProps: PD.Values<ElementSphereParams>, currentProps: PD.Values<ElementSphereParams>) => { - state.createGeometry = newProps.detail !== currentProps.detail + state.createGeometry = ( + newProps.sizeFactor !== currentProps.sizeFactor || + newProps.detail !== currentProps.detail + ) } }) } \ No newline at end of file diff --git a/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts b/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts index f85233d35..4a04144b4 100644 --- a/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts +++ b/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts @@ -53,7 +53,8 @@ async function createInterUnitLinkCylinderMesh(ctx: VisualContext, structure: St export const InterUnitLinkParams = { ...ComplexMeshParams, ...LinkCylinderParams, - sizeFactor: PD.Numeric(0.2, { min: 0, max: 10, step: 0.01 }), + sizeFactor: PD.Numeric(0.3, { min: 0, max: 10, step: 0.01 }), + sizeAspectRatio: PD.Numeric(2/3, { min: 0, max: 3, step: 0.01 }), } export type InterUnitLinkParams = typeof InterUnitLinkParams @@ -65,9 +66,13 @@ export function InterUnitLinkVisual(): ComplexVisual<InterUnitLinkParams> { getLoci: getLinkLoci, mark: markLink, setUpdateState: (state: VisualUpdateState, newProps: PD.Values<InterUnitLinkParams>, currentProps: PD.Values<InterUnitLinkParams>) => { - if (newProps.linkScale !== currentProps.linkScale) state.createGeometry = true - if (newProps.linkSpacing !== currentProps.linkSpacing) state.createGeometry = true - if (newProps.radialSegments !== currentProps.radialSegments) state.createGeometry = true + state.createGeometry = ( + newProps.sizeFactor !== currentProps.sizeFactor || + newProps.sizeAspectRatio !== currentProps.sizeAspectRatio || + newProps.radialSegments !== currentProps.radialSegments || + newProps.linkScale !== currentProps.linkScale || + newProps.linkSpacing !== currentProps.linkSpacing + ) } }) } diff --git a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts index 5efdb9cbd..0467f0d5c 100644 --- a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts +++ b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts @@ -8,7 +8,7 @@ import { Unit, Link, StructureElement, Structure } from 'mol-model/structure'; import { UnitsVisual } from '../representation'; import { VisualUpdateState } from '../../util'; -import { LinkCylinderProps, createLinkCylinderMesh, LinkIterator, LinkCylinderParams } from './util/link'; +import { createLinkCylinderMesh, LinkIterator, LinkCylinderParams } from './util/link'; import { Vec3 } from 'mol-math/linear-algebra'; import { Loci, EmptyLoci } from 'mol-model/loci'; import { UnitsMeshVisual, UnitsMeshParams, StructureGroup } from '../units-visual'; @@ -29,7 +29,7 @@ async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, s const links = unit.links const { edgeCount, a, b, edgeProps, offset } = links const { order: _order, flags: _flags } = edgeProps - const { sizeFactor } = props + const { sizeFactor, sizeAspectRatio } = props if (!edgeCount) return Mesh.createEmpty(mesh) @@ -57,7 +57,7 @@ async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, s flags: (edgeIndex: number) => BitFlags.create(_flags[edgeIndex]), radius: (edgeIndex: number) => { location.element = elements[a[edgeIndex]] - return theme.size.size(location) * sizeFactor + return theme.size.size(location) * sizeFactor * sizeAspectRatio } } @@ -67,7 +67,8 @@ async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, s export const IntraUnitLinkParams = { ...UnitsMeshParams, ...LinkCylinderParams, - sizeFactor: PD.Numeric(0.2, { min: 0, max: 10, step: 0.01 }), + sizeFactor: PD.Numeric(0.3, { min: 0, max: 10, step: 0.01 }), + sizeAspectRatio: PD.Numeric(2/3, { min: 0, max: 3, step: 0.01 }), } export type IntraUnitLinkParams = typeof IntraUnitLinkParams @@ -78,10 +79,14 @@ export function IntraUnitLinkVisual(): UnitsVisual<IntraUnitLinkParams> { createLocationIterator: LinkIterator.fromGroup, getLoci: getLinkLoci, mark: markLink, - setUpdateState: (state: VisualUpdateState, newProps: LinkCylinderProps, currentProps: LinkCylinderProps) => { - if (newProps.linkScale !== currentProps.linkScale) state.createGeometry = true - if (newProps.linkSpacing !== currentProps.linkSpacing) state.createGeometry = true - if (newProps.radialSegments !== currentProps.radialSegments) state.createGeometry = true + setUpdateState: (state: VisualUpdateState, newProps: PD.Values<IntraUnitLinkParams>, currentProps: PD.Values<IntraUnitLinkParams>) => { + state.createGeometry = ( + newProps.sizeFactor !== currentProps.sizeFactor || + newProps.sizeAspectRatio !== currentProps.sizeAspectRatio || + newProps.radialSegments !== currentProps.radialSegments || + newProps.linkScale !== currentProps.linkScale || + newProps.linkSpacing !== currentProps.linkSpacing + ) } }) } diff --git a/src/mol-repr/structure/visual/nucleotide-block-mesh.ts b/src/mol-repr/structure/visual/nucleotide-block-mesh.ts index e208a134b..8e5188611 100644 --- a/src/mol-repr/structure/visual/nucleotide-block-mesh.ts +++ b/src/mol-repr/structure/visual/nucleotide-block-mesh.ts @@ -19,6 +19,7 @@ import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder'; import { addCylinder } from 'mol-geo/geometry/mesh/builder/cylinder'; import { VisualContext } from 'mol-repr/representation'; import { Theme } from 'mol-theme/theme'; +import { VisualUpdateState } from 'mol-repr/util'; const p1 = Vec3.zero() const p2 = Vec3.zero() @@ -132,6 +133,10 @@ export function NucleotideBlockVisual(): UnitsVisual<NucleotideBlockParams> { createLocationIterator: NucleotideLocationIterator.fromGroup, getLoci: getNucleotideElementLoci, mark: markNucleotideElement, - setUpdateState: () => {} + setUpdateState: (state: VisualUpdateState, newProps: PD.Values<NucleotideBlockParams>, currentProps: PD.Values<NucleotideBlockParams>) => { + state.createGeometry = ( + newProps.sizeFactor !== currentProps.sizeFactor + ) + } }) } \ No newline at end of file diff --git a/src/mol-repr/structure/visual/polymer-backbone-cylinder.ts b/src/mol-repr/structure/visual/polymer-backbone-cylinder.ts index 62777f8bc..2e27f6e0a 100644 --- a/src/mol-repr/structure/visual/polymer-backbone-cylinder.ts +++ b/src/mol-repr/structure/visual/polymer-backbone-cylinder.ts @@ -21,6 +21,7 @@ import { VisualContext } from 'mol-repr/representation'; import { Theme } from 'mol-theme/theme'; export const PolymerBackboneCylinderParams = { + sizeFactor: PD.Numeric(0.3, { min: 0, max: 10, step: 0.01 }), radialSegments: PD.Numeric(16, { min: 3, max: 56, step: 1 }), } export const DefaultPolymerBackboneCylinderProps = PD.getDefaultValues(PolymerBackboneCylinderParams) @@ -30,7 +31,7 @@ async function createPolymerBackboneCylinderMesh(ctx: VisualContext, unit: Unit, const polymerElementCount = unit.polymerElements.length if (!polymerElementCount) return Mesh.createEmpty(mesh) - const { radialSegments } = props + const { radialSegments, sizeFactor } = props const vertexCountEstimate = radialSegments * 2 * polymerElementCount * 2 const builder = MeshBuilder.create(vertexCountEstimate, vertexCountEstimate / 10, mesh) @@ -48,11 +49,11 @@ async function createPolymerBackboneCylinderMesh(ctx: VisualContext, unit: Unit, pos(centerA.element, pA) pos(centerB.element, pB) - cylinderProps.radiusTop = cylinderProps.radiusBottom = theme.size.size(centerA) + cylinderProps.radiusTop = cylinderProps.radiusBottom = theme.size.size(centerA) * sizeFactor builder.setGroup(OrderedSet.indexOf(elements, centerA.element)) addCylinder(builder, pA, pB, 0.5, cylinderProps) - cylinderProps.radiusTop = cylinderProps.radiusBottom = theme.size.size(centerB) + cylinderProps.radiusTop = cylinderProps.radiusBottom = theme.size.size(centerB) * sizeFactor builder.setGroup(OrderedSet.indexOf(elements, centerB.element)) addCylinder(builder, pB, pA, 0.5, cylinderProps) @@ -80,7 +81,10 @@ export function PolymerBackboneVisual(): UnitsVisual<PolymerBackboneParams> { getLoci: getElementLoci, mark: markElement, setUpdateState: (state: VisualUpdateState, newProps: PD.Values<PolymerBackboneParams>, currentProps: PD.Values<PolymerBackboneParams>) => { - state.createGeometry = newProps.radialSegments !== currentProps.radialSegments + state.createGeometry = ( + newProps.sizeFactor !== currentProps.sizeFactor || + newProps.radialSegments !== currentProps.radialSegments + ) } }) } \ No newline at end of file diff --git a/src/mol-repr/structure/visual/polymer-direction-wedge.ts b/src/mol-repr/structure/visual/polymer-direction-wedge.ts index 852fdbda7..786ba2992 100644 --- a/src/mol-repr/structure/visual/polymer-direction-wedge.ts +++ b/src/mol-repr/structure/visual/polymer-direction-wedge.ts @@ -16,6 +16,7 @@ import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder'; import { VisualContext } from 'mol-repr/representation'; import { Theme } from 'mol-theme/theme'; +import { VisualUpdateState } from 'mol-repr/util'; const t = Mat4.identity() const sVec = Vec3.zero() @@ -101,6 +102,10 @@ export function PolymerDirectionVisual(): UnitsVisual<PolymerDirectionParams> { createLocationIterator: PolymerLocationIterator.fromGroup, getLoci: getPolymerElementLoci, mark: markPolymerElement, - setUpdateState: () => {} + setUpdateState: (state: VisualUpdateState, newProps: PD.Values<PolymerDirectionParams>, currentProps: PD.Values<PolymerDirectionParams>) => { + state.createGeometry = ( + newProps.sizeFactor !== currentProps.sizeFactor + ) + } }) } \ No newline at end of file diff --git a/src/mol-repr/structure/visual/polymer-gap-cylinder.ts b/src/mol-repr/structure/visual/polymer-gap-cylinder.ts index 7b74e19ec..818837ce1 100644 --- a/src/mol-repr/structure/visual/polymer-gap-cylinder.ts +++ b/src/mol-repr/structure/visual/polymer-gap-cylinder.ts @@ -96,7 +96,10 @@ export function PolymerGapVisual(): UnitsVisual<PolymerGapParams> { getLoci: getPolymerGapElementLoci, mark: markPolymerGapElement, setUpdateState: (state: VisualUpdateState, newProps: PD.Values<PolymerGapParams>, currentProps: PD.Values<PolymerGapParams>) => { - state.createGeometry = newProps.radialSegments !== currentProps.radialSegments + state.createGeometry = ( + newProps.sizeFactor !== currentProps.sizeFactor || + newProps.radialSegments !== currentProps.radialSegments + ) } }) } \ No newline at end of file diff --git a/src/mol-repr/structure/visual/polymer-trace-mesh.ts b/src/mol-repr/structure/visual/polymer-trace-mesh.ts index e4eaad776..65d6b070e 100644 --- a/src/mol-repr/structure/visual/polymer-trace-mesh.ts +++ b/src/mol-repr/structure/visual/polymer-trace-mesh.ts @@ -101,6 +101,7 @@ export function PolymerTraceVisual(): UnitsVisual<PolymerTraceParams> { mark: markPolymerElement, setUpdateState: (state: VisualUpdateState, newProps: PD.Values<PolymerTraceParams>, currentProps: PD.Values<PolymerTraceParams>) => { state.createGeometry = ( + newProps.sizeFactor !== currentProps.sizeFactor || newProps.linearSegments !== currentProps.linearSegments || newProps.radialSegments !== currentProps.radialSegments || newProps.aspectRatio !== currentProps.aspectRatio || -- GitLab