Skip to content

Commit b74c0b5

Browse files
find or create volseg entry draft code
1 parent 6d7bb23 commit b74c0b5

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

molstar-extension/src/extensions/volumes-and-segmentations/entry-root.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function entryParam(entries: string[] = []) {
7171
customEntryId: ParamDefinition.Text('', { hideIf: p => p.entryId !== '__custom__', description: 'Entry identifier, including the source prefix, e.g. "emd-1832"' }),
7272
}, { isFlat: true });
7373
}
74-
type LoadVolsegParamValues = ParamDefinition.Values<ReturnType<typeof createLoadVolsegParams>>;
74+
export type LoadVolsegParamValues = ParamDefinition.Values<ReturnType<typeof createLoadVolsegParams>>;
7575
type RawDataKind = 'volume' | 'segmentation' | 'mesh' | 'primitive';
7676

7777
export function createVolsegEntryParams(plugin?: PluginContext) {

molstar-extension/src/extensions/volumes-and-segmentations/index.ts

+35-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { PluginContext } from 'molstar/lib/mol-plugin/context';
1212
import { StateAction } from 'molstar/lib/mol-state';
1313
import { Task } from 'molstar/lib/mol-task';
1414
import { DEFAULT_VOLSEG_SERVER, VolumeApiV2 } from './volseg-api/api';
15-
import { GEOMETRIC_SEGMENTATION_NODE_TAG, MESH_SEGMENTATION_NODE_TAG, LATTICE_SEGMENTATION_NODE_TAG, VOLUME_NODE_TAG, VolsegEntryData, VolsegEntryParamValues, createLoadVolsegParams } from './entry-root';
15+
import { GEOMETRIC_SEGMENTATION_NODE_TAG, MESH_SEGMENTATION_NODE_TAG, LATTICE_SEGMENTATION_NODE_TAG, VOLUME_NODE_TAG, VolsegEntryData, VolsegEntryParamValues, createLoadVolsegParams, VolsegEntry, LoadVolsegParamValues } from './entry-root';
1616
import { VolsegGlobalState } from './global-state';
17-
import { createEntryId } from './helpers';
17+
import { createEntryId, isDefined } from './helpers';
1818
import { ProjectGeometricSegmentationData, ProjectGeometricSegmentationDataParamsValues, ProjectMeshData, ProjectMeshSegmentationDataParamsValues, ProjectSegmentationData, ProjectLatticeSegmentationDataParamsValues, ProjectVolumeData, VolsegEntryFromRoot, VolsegGlobalStateFromRoot, VolsegStateFromEntry } from './transformers';
1919
import { VolsegUI } from './ui';
2020
import { createSegmentKey, getSegmentLabelsFromDescriptions } from './volseg-api/utils';
21-
import { actionShowSegments } from '../../common';
21+
import { Source, actionShowSegments, findNodesByRef } from '../../common';
2222

2323
// const DEBUGGING = typeof window !== 'undefined' ? window?.location?.hostname === 'localhost' || '127.0.0.1' : false;
2424
const DEBUGGING = typeof window !== 'undefined' ? window?.location?.hostname === 'localhost' : false;
@@ -69,6 +69,36 @@ export const Volseg = PluginBehavior.create<{ autoAttach: boolean, showTooltip:
6969
});
7070

7171

72+
export async function findOrCreateVolsegEntry(entryId: string, source: string, plugin: PluginContext) {
73+
const nodes = plugin.state.data.selectQ(q => q.ofType(VolsegEntry)).map(cell => cell?.obj).filter(isDefined);
74+
const targetNode = nodes.find(n => n.data.entryId === entryId && n.data.source === source);
75+
debugger;
76+
if (targetNode) {
77+
// TODO: return selector?
78+
// return targetNode;
79+
const n = findNodesByRef(plugin, targetNode.data.ref);
80+
const nn = findNodesByRef(plugin, n.transform.ref);
81+
console.log(nn);
82+
debugger;
83+
return nn;
84+
}
85+
else {
86+
const entryParams = {
87+
serverUrl: plugin?.config.get(VolsegVolumeServerConfig.DefaultServer) ?? DEFAULT_VOLSEG_SERVER,
88+
source: source as Source,
89+
entryId: entryId
90+
};
91+
// const entryParams: LoadVolsegParamValues = {
92+
// serverUrl: defaultVolumeServer,
93+
// source: SourceChoice.PDSelect(),
94+
// entryId: ParamDefinition.Text('emd-1832', { description: 'Entry identifier, including the source prefix, e.g. "emd-1832"' }),
95+
// };
96+
debugger;
97+
const entryNode = await plugin.state.data.build().toRoot().apply(VolsegEntryFromRoot, entryParams).commit();
98+
return entryNode;
99+
}
100+
}
101+
72102
export const LoadVolseg = StateAction.build({
73103
display: { name: 'Load Volume & Segmentation' },
74104
from: SO.Root,
@@ -93,7 +123,6 @@ export const LoadVolseg = StateAction.build({
93123
if (!globalStateNode) {
94124
await state.build().toRoot().apply(VolsegGlobalStateFromRoot, {}, { state: { isGhost: !DEBUGGING } }).commit();
95125
}
96-
97126
const entryNode = await state.build().toRoot().apply(VolsegEntryFromRoot, entryParams).commit();
98127
await state.build().to(entryNode).apply(VolsegStateFromEntry, {}, { state: { isGhost: !DEBUGGING } }).commit();
99128
if (entryNode.data) {
@@ -114,7 +143,8 @@ export const LoadVolseg = StateAction.build({
114143
if (result) {
115144
const isovalue = result.isovalue.kind === 'relative' ? result.isovalue.relativeValue : result.isovalue.absoluteValue;
116145
updatedChannelsData.push(
117-
{ channelId: result.channelId, volumeIsovalueKind: result.isovalue.kind, volumeIsovalueValue: isovalue, volumeType: result.volumeType, volumeOpacity: result.opacity,
146+
{
147+
channelId: result.channelId, volumeIsovalueKind: result.isovalue.kind, volumeIsovalueValue: isovalue, volumeType: result.volumeType, volumeOpacity: result.opacity,
118148
label: result.label,
119149
color: result.color
120150
}

0 commit comments

Comments
 (0)