From d546c0d1c45d8162d856da59bc69c4d73fc0458d Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sat, 17 Nov 2018 09:10:35 -0800 Subject: [PATCH] added repr.groupCount --- src/mol-geo/util/location-iterator.ts | 6 ++++-- src/mol-repr/representation.ts | 18 +++++++++++++++++- src/mol-repr/shape/representation.ts | 4 +++- .../structure/complex-representation.ts | 3 +++ src/mol-repr/structure/complex-visual.ts | 1 + src/mol-repr/structure/units-representation.ts | 7 +++++++ src/mol-repr/structure/units-visual.ts | 1 + src/mol-repr/volume/representation.ts | 4 ++++ 8 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/mol-geo/util/location-iterator.ts b/src/mol-geo/util/location-iterator.ts index 16c351709..8c43501c1 100644 --- a/src/mol-geo/util/location-iterator.ts +++ b/src/mol-geo/util/location-iterator.ts @@ -28,6 +28,7 @@ export interface LocationIterator extends Iterator<LocationValue> { readonly isNextNewInstance: boolean readonly groupCount: number readonly instanceCount: number + readonly count: number /** If true, may have multiple units per instance; if false one unit per instance */ readonly isComplex: boolean move(): LocationValue @@ -55,8 +56,9 @@ export function LocationIterator(groupCount: number, instanceCount: number, getL return { get hasNext () { return hasNext }, get isNextNewInstance () { return isNextNewInstance }, - get groupCount () { return groupCount }, - get instanceCount () { return instanceCount }, + groupCount, + instanceCount, + count: groupCount * instanceCount, isComplex, move() { if (hasNext) { diff --git a/src/mol-repr/representation.ts b/src/mol-repr/representation.ts index d271a2f35..f2c8b683f 100644 --- a/src/mol-repr/representation.ts +++ b/src/mol-repr/representation.ts @@ -81,6 +81,8 @@ export { Representation } interface Representation<D, P extends PD.Params = {}> { readonly label: string readonly updated: Subject<number> + /** Number of addressable groups in all visuals of the representation */ + readonly groupCount: number readonly renderObjects: ReadonlyArray<RenderObject> readonly props: Readonly<PD.Values<P>> readonly params: Readonly<P> @@ -94,7 +96,7 @@ interface Representation<D, P extends PD.Params = {}> { namespace Representation { export type Any = Representation<any> export const Empty: Any = { - label: '', renderObjects: [], props: {}, params: {}, updated: new Subject(), + label: '', groupCount: 0, renderObjects: [], props: {}, params: {}, updated: new Subject(), createOrUpdate: () => Task.constant('', undefined), getLoci: () => EmptyLoci, mark: () => false, @@ -122,6 +124,18 @@ namespace Representation { return { label, updated, + get groupCount() { + let groupCount = 0 + if (currentProps) { + const { visuals } = currentProps + for (let i = 0, il = reprList.length; i < il; ++i) { + if (!visuals || visuals.includes(reprMap[i])) { + groupCount += reprList[i].groupCount + } + } + } + return groupCount + }, get renderObjects() { const renderObjects: RenderObject[] = [] if (currentProps) { @@ -200,6 +214,8 @@ export interface VisualContext { } export interface Visual<D, P extends PD.Params> { + /** Number of addressable groups in all instances of the visual */ + readonly groupCount: number readonly renderObject: RenderObject | undefined createOrUpdate: (ctx: VisualContext, theme: Theme, props?: Partial<PD.Values<P>>, data?: D) => Promise<void> getLoci: (pickingId: PickingId) => Loci diff --git a/src/mol-repr/shape/representation.ts b/src/mol-repr/shape/representation.ts index c8e7ac8db..7908459ac 100644 --- a/src/mol-repr/shape/representation.ts +++ b/src/mol-repr/shape/representation.ts @@ -38,6 +38,7 @@ export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentatio let _shape: Shape let currentProps: PD.Values<P> = PD.getDefaultValues(ShapeParams) as PD.Values<P> let currentParams: P + let locationIt: LocationIterator function createOrUpdate(ctx: RepresentationContext, props: Partial<PD.Values<P>> = {}, shape?: Shape) { currentProps = Object.assign({}, currentProps, props) @@ -49,7 +50,7 @@ export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentatio if (!_shape) return const mesh = _shape.mesh - const locationIt = ShapeGroupIterator.fromShape(_shape) + locationIt = ShapeGroupIterator.fromShape(_shape) const theme = createTheme(ctx, currentProps, {}) const transform = createIdentityTransform() @@ -65,6 +66,7 @@ export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentatio return { label: 'Shape mesh', updated, + get groupCount () { return locationIt ? locationIt.count : 0 }, get renderObjects () { return renderObjects }, get params () { return currentParams }, get props () { return currentProps }, diff --git a/src/mol-repr/structure/complex-representation.ts b/src/mol-repr/structure/complex-representation.ts index 816f84d4d..fc6253b81 100644 --- a/src/mol-repr/structure/complex-representation.ts +++ b/src/mol-repr/structure/complex-representation.ts @@ -65,6 +65,9 @@ export function ComplexRepresentation<P extends StructureParams>(label: string, return { label, + get groupCount() { + return visual ? visual.groupCount : 0 + }, get renderObjects() { return visual && visual.renderObject ? [ visual.renderObject ] : [] }, diff --git a/src/mol-repr/structure/complex-visual.ts b/src/mol-repr/structure/complex-visual.ts index ffccd126b..4e39ce449 100644 --- a/src/mol-repr/structure/complex-visual.ts +++ b/src/mol-repr/structure/complex-visual.ts @@ -122,6 +122,7 @@ export function ComplexVisual<P extends ComplexParams>(builder: ComplexVisualGeo } return { + get groupCount() { return locationIt ? locationIt.count : 0 }, get renderObject () { return renderObject }, async createOrUpdate(ctx: VisualContext, theme: Theme, props: Partial<PD.Values<P>> = {}, structure?: Structure) { if (!structure && !currentStructure) { diff --git a/src/mol-repr/structure/units-representation.ts b/src/mol-repr/structure/units-representation.ts index 84aed6c3d..abd56451a 100644 --- a/src/mol-repr/structure/units-representation.ts +++ b/src/mol-repr/structure/units-representation.ts @@ -161,6 +161,13 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, getPar return { label, + get groupCount() { + let groupCount = 0 + visuals.forEach(({ visual }) => { + if (visual.renderObject) groupCount += visual.groupCount + }) + return groupCount + }, get renderObjects() { const renderObjects: RenderObject[] = [] visuals.forEach(({ visual }) => { diff --git a/src/mol-repr/structure/units-visual.ts b/src/mol-repr/structure/units-visual.ts index abb5dccb5..e0f4ba605 100644 --- a/src/mol-repr/structure/units-visual.ts +++ b/src/mol-repr/structure/units-visual.ts @@ -146,6 +146,7 @@ export function UnitsVisual<P extends UnitsParams>(builder: UnitsVisualGeometryB } return { + get groupCount() { return locationIt ? locationIt.count : 0 }, get renderObject () { return renderObject }, async createOrUpdate(ctx: VisualContext, theme: Theme, props: Partial<PD.Values<P>> = {}, structureGroup?: StructureGroup) { if (structureGroup) currentStructure = structureGroup.structure diff --git a/src/mol-repr/volume/representation.ts b/src/mol-repr/volume/representation.ts index 075c02c8a..85a467af2 100644 --- a/src/mol-repr/volume/representation.ts +++ b/src/mol-repr/volume/representation.ts @@ -76,6 +76,7 @@ export function VolumeVisual<P extends VolumeParams>(builder: VolumeVisualGeomet } return { + get groupCount() { return locationIt ? locationIt.count : 0 }, get renderObject () { return renderObject }, async createOrUpdate(ctx: VisualContext, theme: Theme, props: Partial<PD.Values<P>> = {}, volume?: VolumeData) { if (!volume && !currentVolume) { @@ -204,6 +205,9 @@ export function VolumeRepresentation<P extends VolumeParams>(label: string, getP return { label, + get groupCount() { + return visual ? visual.groupCount : 0 + }, get renderObjects() { return visual && visual.renderObject ? [ visual.renderObject ] : [] }, -- GitLab