Browse Source

auto-smooth colors if preferred

Alexander Rose 3 years ago
parent
commit
ba8e9e189f

+ 1 - 0
src/extensions/pdbe/structure-quality-report/color.ts

@@ -79,6 +79,7 @@ export function StructureQualityReportColorTheme(ctx: ThemeDataContext, props: P
     return {
         factory: StructureQualityReportColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color: color,
         props: props,
         description: 'Assigns residue colors according to the number of quality issues or a specific quality issue. Data from wwPDB Validation Report, obtained via PDBe.',

+ 1 - 0
src/extensions/rcsb/validation-report/color/density-fit.ts

@@ -58,6 +58,7 @@ export function DensityFitColorTheme(ctx: ThemeDataContext, props: {}): ColorThe
     return {
         factory: DensityFitColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         contextHash,

+ 1 - 0
src/extensions/rcsb/validation-report/color/geometry-quality.ts

@@ -96,6 +96,7 @@ export function GeometryQualityColorTheme(ctx: ThemeDataContext, props: PD.Value
     return {
         factory: GeometryQualityColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         contextHash,

+ 1 - 0
src/extensions/rcsb/validation-report/color/random-coil-index.ts

@@ -49,6 +49,7 @@ export function RandomCoilIndexColorTheme(ctx: ThemeDataContext, props: {}): Col
     return {
         factory: RandomCoilIndexColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         contextHash,

+ 1 - 0
src/mol-model-props/computed/themes/accessible-surface-area.ts

@@ -64,6 +64,7 @@ export function AccessibleSurfaceAreaColorTheme(ctx: ThemeDataContext, props: PD
     return {
         factory: AccessibleSurfaceAreaColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         contextHash,

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

@@ -54,7 +54,7 @@ interface ComplexVisualBuilder<P extends StructureParams, G extends Geometry> {
     eachLocation(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean, isMarking: boolean): boolean,
     setUpdateState(state: VisualUpdateState, newProps: PD.Values<P>, currentProps: PD.Values<P>, newTheme: Theme, currentTheme: Theme, newStructure: Structure, currentStructure: Structure): void
     mustRecreate?: (structure: Structure, props: PD.Values<P>) => boolean
-    processValues?: (values: RenderObjectValues<G['kind']>, geometry: G, props: PD.Values<P>, webgl?: WebGLContext) => void
+    processValues?: (values: RenderObjectValues<G['kind']>, geometry: G, props: PD.Values<P>, theme: Theme, webgl?: WebGLContext) => void
     dispose?: (geometry: G) => void
 }
 
@@ -202,7 +202,7 @@ export function ComplexVisual<G extends Geometry, P extends StructureParams & Ge
 
     function finalize(ctx: VisualContext) {
         if (renderObject) {
-            processValues?.(renderObject.values, geometry, currentProps, ctx.webgl);
+            processValues?.(renderObject.values, geometry, currentProps, currentTheme, ctx.webgl);
         }
     }
 

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

@@ -60,7 +60,7 @@ interface UnitsVisualBuilder<P extends StructureParams, G extends Geometry> {
     eachLocation(loci: Loci, structureGroup: StructureGroup, apply: (interval: Interval) => boolean, isMarking: boolean): boolean
     setUpdateState(state: VisualUpdateState, newProps: PD.Values<P>, currentProps: PD.Values<P>, newTheme: Theme, currentTheme: Theme, newStructureGroup: StructureGroup, currentStructureGroup: StructureGroup): void
     mustRecreate?: (structureGroup: StructureGroup, props: PD.Values<P>) => boolean
-    processValues?: (values: RenderObjectValues<G['kind']>, geometry: G, props: PD.Values<P>, webgl?: WebGLContext) => void
+    processValues?: (values: RenderObjectValues<G['kind']>, geometry: G, props: PD.Values<P>, theme: Theme, webgl?: WebGLContext) => void
     dispose?: (geometry: G) => void
 }
 
@@ -258,7 +258,7 @@ export function UnitsVisual<G extends Geometry, P extends StructureParams & Geom
 
     function finalize(ctx: VisualContext) {
         if (renderObject) {
-            processValues?.(renderObject.values, geometry, currentProps, ctx.webgl);
+            processValues?.(renderObject.values, geometry, currentProps, currentTheme, ctx.webgl);
         }
     }
 

+ 9 - 9
src/mol-repr/structure/visual/gaussian-surface-mesh.ts

@@ -29,7 +29,7 @@ const SharedParams = {
     ...GaussianDensityParams,
     ignoreHydrogens: PD.Boolean(false),
     tryUseGpu: PD.Boolean(true),
-    smoothColors: PD.Select('off', PD.arrayToOptions(['on', 'off'] as const)),
+    smoothColors: PD.Select('auto', PD.arrayToOptions(['auto', 'on', 'off'] as const)),
 };
 type SharedParams = typeof SharedParams
 
@@ -123,9 +123,9 @@ export function GaussianSurfaceMeshVisual(materialId: number): UnitsVisual<Gauss
         mustRecreate: (structureGroup: StructureGroup, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
             return props.tryUseGpu && !!webgl && suitableForGpu(structureGroup.structure, props, webgl);
         },
-        processValues: (values: MeshValues, geometry: Mesh, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
+        processValues: (values: MeshValues, geometry: Mesh, props: PD.Values<GaussianSurfaceMeshParams>, theme: Theme, webgl?: WebGLContext) => {
             const { resolution } = geometry.meta as GaussianSurfaceMeta;
-            if (props.smoothColors !== 'off' && resolution && webgl) {
+            if ((props.smoothColors === 'on' || (props.smoothColors === 'auto' && theme.color.preferSmoothing)) && resolution && webgl) {
                 applyMeshColorSmoothing(webgl, values, resolution);
             }
         }
@@ -173,9 +173,9 @@ export function StructureGaussianSurfaceMeshVisual(materialId: number): ComplexV
         mustRecreate: (structure: Structure, props: PD.Values<StructureGaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
             return props.tryUseGpu && !!webgl && suitableForGpu(structure, props, webgl);
         },
-        processValues: (values: MeshValues, geometry: Mesh, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
+        processValues: (values: MeshValues, geometry: Mesh, props: PD.Values<GaussianSurfaceMeshParams>, theme: Theme, webgl?: WebGLContext) => {
             const { resolution } = geometry.meta as GaussianSurfaceMeta;
-            if (props.smoothColors !== 'off' && resolution && webgl) {
+            if ((props.smoothColors === 'on' || (props.smoothColors === 'auto' && theme.color.preferSmoothing)) && resolution && webgl) {
                 applyMeshColorSmoothing(webgl, values, resolution);
             }
         }
@@ -236,9 +236,9 @@ export function GaussianSurfaceTextureMeshVisual(materialId: number): UnitsVisua
         mustRecreate: (structureGroup: StructureGroup, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
             return !props.tryUseGpu || !webgl || !suitableForGpu(structureGroup.structure, props, webgl);
         },
-        processValues: (values: TextureMeshValues, geometry: TextureMesh, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
+        processValues: (values: TextureMeshValues, geometry: TextureMesh, props: PD.Values<GaussianSurfaceMeshParams>, theme: Theme, webgl?: WebGLContext) => {
             const { resolution, colorTexture } = geometry.meta as GaussianSurfaceMeta;
-            if (props.smoothColors !== 'off' && resolution && webgl) {
+            if ((props.smoothColors === 'on' || (props.smoothColors === 'auto' && theme.color.preferSmoothing)) && resolution && webgl) {
                 applyTextureMeshColorSmoothing(webgl, values, resolution, colorTexture);
                 (geometry.meta as GaussianSurfaceMeta).colorTexture = values.tColorGrid.ref.value;
             }
@@ -304,9 +304,9 @@ export function StructureGaussianSurfaceTextureMeshVisual(materialId: number): C
         mustRecreate: (structure: Structure, props: PD.Values<StructureGaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
             return !props.tryUseGpu || !webgl || !suitableForGpu(structure, props, webgl);
         },
-        processValues: (values: TextureMeshValues, geometry: TextureMesh, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
+        processValues: (values: TextureMeshValues, geometry: TextureMesh, props: PD.Values<GaussianSurfaceMeshParams>, theme: Theme, webgl?: WebGLContext) => {
             const { resolution, colorTexture } = geometry.meta as GaussianSurfaceMeta;
-            if (props.smoothColors !== 'off' && resolution && webgl) {
+            if ((props.smoothColors === 'on' || (props.smoothColors === 'auto' && theme.color.preferSmoothing)) && resolution && webgl) {
                 applyTextureMeshColorSmoothing(webgl, values, resolution, colorTexture);
                 (geometry.meta as GaussianSurfaceMeta).colorTexture = values.tColorGrid.ref.value;
             }

+ 3 - 3
src/mol-repr/structure/visual/molecular-surface-mesh.ts

@@ -26,7 +26,7 @@ export const MolecularSurfaceMeshParams = {
     ...UnitsMeshParams,
     ...MolecularSurfaceCalculationParams,
     ...CommonSurfaceParams,
-    smoothColors: PD.Select('off', PD.arrayToOptions(['on', 'off'] as const)),
+    smoothColors: PD.Select('auto', PD.arrayToOptions(['auto', 'on', 'off'] as const)),
 };
 export type MolecularSurfaceMeshParams = typeof MolecularSurfaceMeshParams
 
@@ -73,9 +73,9 @@ export function MolecularSurfaceMeshVisual(materialId: number): UnitsVisual<Mole
             if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true;
             if (newProps.smoothColors !== currentProps.smoothColors) state.updateColor = true;
         },
-        processValues: (values: MeshValues, geometry: Mesh, props: PD.Values<MolecularSurfaceMeshParams>, webgl?: WebGLContext) => {
+        processValues: (values: MeshValues, geometry: Mesh, props: PD.Values<MolecularSurfaceMeshParams>, theme: Theme, webgl?: WebGLContext) => {
             const { resolution } = geometry.meta as MolecularSurfaceMeta;
-            if (props.smoothColors !== 'off' && resolution && webgl) {
+            if ((props.smoothColors === 'on' || (props.smoothColors === 'auto' && theme.color.preferSmoothing)) && resolution && webgl) {
                 applyMeshColorSmoothing(webgl, values, resolution);
             }
         },

+ 5 - 2
src/mol-theme/color.ts

@@ -45,9 +45,12 @@ interface ColorTheme<P extends PD.Params> {
     readonly granularity: ColorType
     readonly color: LocationColor
     readonly props: Readonly<PD.Values<P>>
-    // if palette is defined, 24bit RGB color value normalized to interval [0, 1]
-    // is used as index to the colors
+    /**
+     * if palette is defined, 24bit RGB color value normalized to interval [0, 1]
+     * is used as index to the colors
+     */
     readonly palette?: Readonly<ColorTheme.Palette>
+    readonly preferSmoothing?: boolean
     readonly contextHash?: number
     readonly description?: string
     readonly legend?: Readonly<ScaleLegend | TableLegend>

+ 1 - 0
src/mol-theme/color/atom-id.ts

@@ -72,6 +72,7 @@ export function AtomIdColorTheme(ctx: ThemeDataContext, props: PD.Values<AtomIdC
     return {
         factory: AtomIdColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         description: Description,

+ 1 - 0
src/mol-theme/color/element-symbol.ts

@@ -82,6 +82,7 @@ export function ElementSymbolColorTheme(ctx: ThemeDataContext, props: PD.Values<
     return {
         factory: ElementSymbolColorTheme,
         granularity,
+        preferSmoothing: true,
         color,
         props,
         description: Description,

+ 1 - 0
src/mol-theme/color/hydrophobicity.ts

@@ -84,6 +84,7 @@ export function HydrophobicityColorTheme(ctx: ThemeDataContext, props: PD.Values
     return {
         factory: HydrophobicityColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         description: Description,

+ 1 - 0
src/mol-theme/color/illustrative.ts

@@ -47,6 +47,7 @@ export function IllustrativeColorTheme(ctx: ThemeDataContext, props: PD.Values<I
     return {
         factory: IllustrativeColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         description: Description,

+ 1 - 0
src/mol-theme/color/occupancy.ts

@@ -50,6 +50,7 @@ export function OccupancyColorTheme(ctx: ThemeDataContext, props: PD.Values<Occu
     return {
         factory: OccupancyColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         description: Description,

+ 1 - 0
src/mol-theme/color/partial-charge.ts

@@ -48,6 +48,7 @@ export function PartialChargeColorTheme(ctx: ThemeDataContext, props: PD.Values<
     return {
         factory: PartialChargeColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         description: Description,

+ 1 - 0
src/mol-theme/color/residue-name.ts

@@ -119,6 +119,7 @@ export function ResidueNameColorTheme(ctx: ThemeDataContext, props: PD.Values<Re
     return {
         factory: ResidueNameColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         description: Description,

+ 1 - 0
src/mol-theme/color/secondary-structure.ts

@@ -102,6 +102,7 @@ export function SecondaryStructureColorTheme(ctx: ThemeDataContext, props: PD.Va
     return {
         factory: SecondaryStructureColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         contextHash,

+ 1 - 0
src/mol-theme/color/sequence-id.ts

@@ -102,6 +102,7 @@ export function SequenceIdColorTheme(ctx: ThemeDataContext, props: PD.Values<Seq
     return {
         factory: SequenceIdColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         description: Description,

+ 1 - 0
src/mol-theme/color/uncertainty.ts

@@ -54,6 +54,7 @@ export function UncertaintyColorTheme(ctx: ThemeDataContext, props: PD.Values<Un
     return {
         factory: UncertaintyColorTheme,
         granularity: 'group',
+        preferSmoothing: true,
         color,
         props,
         description: Description,