Skip to content

Commit

Permalink
find or create volseg entry draft code
Browse files Browse the repository at this point in the history
  • Loading branch information
aliaksei-chareshneu committed Jun 27, 2024
1 parent 6d7bb23 commit b74c0b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function entryParam(entries: string[] = []) {
customEntryId: ParamDefinition.Text('', { hideIf: p => p.entryId !== '__custom__', description: 'Entry identifier, including the source prefix, e.g. "emd-1832"' }),
}, { isFlat: true });
}
type LoadVolsegParamValues = ParamDefinition.Values<ReturnType<typeof createLoadVolsegParams>>;
export type LoadVolsegParamValues = ParamDefinition.Values<ReturnType<typeof createLoadVolsegParams>>;
type RawDataKind = 'volume' | 'segmentation' | 'mesh' | 'primitive';

export function createVolsegEntryParams(plugin?: PluginContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { PluginContext } from 'molstar/lib/mol-plugin/context';
import { StateAction } from 'molstar/lib/mol-state';
import { Task } from 'molstar/lib/mol-task';
import { DEFAULT_VOLSEG_SERVER, VolumeApiV2 } from './volseg-api/api';
import { GEOMETRIC_SEGMENTATION_NODE_TAG, MESH_SEGMENTATION_NODE_TAG, LATTICE_SEGMENTATION_NODE_TAG, VOLUME_NODE_TAG, VolsegEntryData, VolsegEntryParamValues, createLoadVolsegParams } from './entry-root';
import { GEOMETRIC_SEGMENTATION_NODE_TAG, MESH_SEGMENTATION_NODE_TAG, LATTICE_SEGMENTATION_NODE_TAG, VOLUME_NODE_TAG, VolsegEntryData, VolsegEntryParamValues, createLoadVolsegParams, VolsegEntry, LoadVolsegParamValues } from './entry-root';
import { VolsegGlobalState } from './global-state';
import { createEntryId } from './helpers';
import { createEntryId, isDefined } from './helpers';
import { ProjectGeometricSegmentationData, ProjectGeometricSegmentationDataParamsValues, ProjectMeshData, ProjectMeshSegmentationDataParamsValues, ProjectSegmentationData, ProjectLatticeSegmentationDataParamsValues, ProjectVolumeData, VolsegEntryFromRoot, VolsegGlobalStateFromRoot, VolsegStateFromEntry } from './transformers';
import { VolsegUI } from './ui';
import { createSegmentKey, getSegmentLabelsFromDescriptions } from './volseg-api/utils';
import { actionShowSegments } from '../../common';
import { Source, actionShowSegments, findNodesByRef } from '../../common';

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


export async function findOrCreateVolsegEntry(entryId: string, source: string, plugin: PluginContext) {
const nodes = plugin.state.data.selectQ(q => q.ofType(VolsegEntry)).map(cell => cell?.obj).filter(isDefined);
const targetNode = nodes.find(n => n.data.entryId === entryId && n.data.source === source);
debugger;
if (targetNode) {
// TODO: return selector?
// return targetNode;
const n = findNodesByRef(plugin, targetNode.data.ref);
const nn = findNodesByRef(plugin, n.transform.ref);
console.log(nn);
debugger;
return nn;
}
else {
const entryParams = {
serverUrl: plugin?.config.get(VolsegVolumeServerConfig.DefaultServer) ?? DEFAULT_VOLSEG_SERVER,
source: source as Source,
entryId: entryId
};
// const entryParams: LoadVolsegParamValues = {
// serverUrl: defaultVolumeServer,
// source: SourceChoice.PDSelect(),
// entryId: ParamDefinition.Text('emd-1832', { description: 'Entry identifier, including the source prefix, e.g. "emd-1832"' }),
// };
debugger;
const entryNode = await plugin.state.data.build().toRoot().apply(VolsegEntryFromRoot, entryParams).commit();
return entryNode;
}
}

export const LoadVolseg = StateAction.build({
display: { name: 'Load Volume & Segmentation' },
from: SO.Root,
Expand All @@ -93,7 +123,6 @@ export const LoadVolseg = StateAction.build({
if (!globalStateNode) {
await state.build().toRoot().apply(VolsegGlobalStateFromRoot, {}, { state: { isGhost: !DEBUGGING } }).commit();
}

const entryNode = await state.build().toRoot().apply(VolsegEntryFromRoot, entryParams).commit();
await state.build().to(entryNode).apply(VolsegStateFromEntry, {}, { state: { isGhost: !DEBUGGING } }).commit();
if (entryNode.data) {
Expand All @@ -114,7 +143,8 @@ export const LoadVolseg = StateAction.build({
if (result) {
const isovalue = result.isovalue.kind === 'relative' ? result.isovalue.relativeValue : result.isovalue.absoluteValue;
updatedChannelsData.push(
{ channelId: result.channelId, volumeIsovalueKind: result.isovalue.kind, volumeIsovalueValue: isovalue, volumeType: result.volumeType, volumeOpacity: result.opacity,
{
channelId: result.channelId, volumeIsovalueKind: result.isovalue.kind, volumeIsovalueValue: isovalue, volumeType: result.volumeType, volumeOpacity: result.opacity,
label: result.label,
color: result.color
}
Expand Down

0 comments on commit b74c0b5

Please sign in to comment.