Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/components/Viewer/Options/AttributeSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
attributeRangesPerTarget,
attributeRequestParams,
useAttributeRangeBounds,
useSelectedAttributeColorMap,
useSeriesTimeStepCommit,
} from "@ogw_front/composables/attribute_selector";
import type { AttributeItem, AttributeName } from "@geode/opengeodeweb-viewer/schema_types";
Expand Down Expand Up @@ -64,6 +65,7 @@ let rangesName: AttributeName | undefined = undefined;
let rangesLoading: Promise<void> = Promise.resolve();

const groupTargetIds = useBatchGroup(() => dataId);
const colorMaps = useSelectedAttributeColorMap(() => dataId, attributeName, attributeColorMap);

const currentAttribute = computed<AttributeInfo | undefined>(() =>
attributes.value.find((attr) => attr.attribute_name === attributeName.value),
Expand Down Expand Up @@ -158,10 +160,11 @@ async function getGroupAttributes(targetIds: DataId[]): Promise<void> {

async function initGroupAttribute(name: AttributeName, item: AttributeItem): Promise<void> {
await loadRanges(name);
const colorMap = await colorMaps.resolveColorMap(name);
if (attributeName.value !== name) {
return;
}
emit("update:attributeColorMap", attributeColorMap.value ?? "batlow");
emit("update:attributeColorMap", colorMap);
emit("ranges_per_data", attributeRangesPerTarget(rangesPerTarget.value, item));
}

Expand Down Expand Up @@ -204,9 +207,7 @@ watch([attributeName, attributeItem, currentAttribute], async () => {
if (groupTargetIds.value) {
return;
}
if (attributeColorMap.value === undefined) {
attributeColorMap.value = "batlow";
}
await colorMaps.ensureColorMap();
if (attributeNoDataColor.value === undefined) {
attributeNoDataColor.value = DEFAULT_NO_DATA_COLOR;
}
Expand Down
8 changes: 6 additions & 2 deletions app/components/Viewer/Options/ColorMapPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import type {
AttributeRangeMaximum,
AttributeRangeMinimum,
} from "@geode/opengeodeweb-viewer/schema_types";
import { drawCanvasForPreset, getPresetsWithCurrentAtTop } from "@ogw_front/utils/colormap";
import {
DEFAULT_COLORMAP,
drawCanvasForPreset,
getPresetsWithCurrentAtTop,
} from "@ogw_front/utils/colormap";
import type { AttributeColorMap } from "@ogw_front/types/attribute";
import ColorMapList from "./ColorMapList.vue";
import type { ColorMapPreset } from "@ogw_front/types/props/viewer/options";
Expand All @@ -16,7 +20,7 @@ interface Props {
const { max, min } = defineProps<Props>();

const selectedPresetName = defineModel<AttributeColorMap>("selectedPresetName", {
default: "batlow",
default: DEFAULT_COLORMAP,
});

const menuOpen = ref<boolean>(false);
Expand Down
3 changes: 2 additions & 1 deletion app/composables/attribute_coloring_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
} from "@ogw_front/types/attribute";
import { type AttributeInfo, getAttributeRange } from "@ogw_front/utils/attributes";
import { type AttributeSchemas, fetchAttributeRange } from "@ogw_front/utils/attribute_range";
import { DEFAULT_COLORMAP } from "@ogw_front/utils/colormap";
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import type { JsonRpcSchema } from "@ogw_shared/utils/types";
import type { ModelComponentId } from "@ogw_front/types/identifiers";
Expand Down Expand Up @@ -98,7 +99,7 @@ function useAttributeColoringStyle(colorings: Ref<AttributeColoring[]>): Attribu
const currentColormap = computed((): AttributeColorMap => {
const [coloring] = colorings.value;
if (!coloring) {
return "batlow";
return DEFAULT_COLORMAP;
}
return String(coloring.read("ColorMap"));
});
Expand Down
80 changes: 75 additions & 5 deletions app/composables/attribute_selector.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import type {
AttributeColorMap,
AttributeTimeStep,
AttributeTimeValue,
ValidAttributeRange,
} from "@ogw_front/types/attribute";
import type {
AttributeItem,
AttributeName,
AttributeRangeMaximum,
AttributeRangeMinimum,
} from "@geode/opengeodeweb-viewer/schema_types";
import type {
AttributeTimeStep,
AttributeTimeValue,
ValidAttributeRange,
} from "@ogw_front/types/attribute";
import type { Count, Title } from "@ogw_front/types/ui";
import type { AttributeRangeInfo } from "@ogw_front/utils/attribute_range";
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types";
import type { ModelComponentId } from "@ogw_front/types/identifiers";
import type { NonEmptyArray } from "@ogw_front/utils/arrays";
import { defaultAttributeColorMap } from "@ogw_front/utils/colormap";
import { getAttributeRange } from "@ogw_front/utils/attributes";
import { useDataStore } from "@ogw_front/stores/data";

// The minimum and maximum of an attribute range: each one is clamped by the other
function useAttributeRangeBounds(attributeRange: Ref<(number | undefined)[]>): {
Expand Down Expand Up @@ -123,6 +127,70 @@ function attributeRequestParams(
return { id: dataId, component_ids: componentIds };
}

// Resolves the default colormap of an attribute from its data's geode object type
function useColorMapResolver(
dataId: () => DataId,
): (attributeName: AttributeName | undefined) => Promise<AttributeColorMap> {
const dataStore = useDataStore();
let cachedId: DataId | undefined = undefined;
let cachedType: GeodeObjectType | undefined = undefined;

async function resolveObjectType(): Promise<GeodeObjectType | undefined> {
const requestedId = dataId();
if (cachedId === requestedId) {
return cachedType;
}
try {
const dataItem = await dataStore.item(requestedId);
if (requestedId === dataId()) {
cachedType = dataItem.geode_object_type;
cachedId = requestedId;
}
return dataItem.geode_object_type;
} catch {
return undefined;
}
}

return async (attributeName) => {
const objectType = await resolveObjectType();
return defaultAttributeColorMap(objectType, attributeName);
};
}

// Resolves and fills the default colormap of the selected attribute when none is stored yet
function useSelectedAttributeColorMap(
dataId: () => DataId,
attributeName: Readonly<Ref<AttributeName | undefined>>,
attributeColorMap: Ref<AttributeColorMap | undefined>,
): {
resolveColorMap: (name: AttributeName) => Promise<AttributeColorMap>;
ensureColorMap: () => Promise<void>;
} {
const defaultColorMapFor = useColorMapResolver(dataId);

async function resolveColorMap(name: AttributeName): Promise<AttributeColorMap> {
if (attributeColorMap.value !== undefined) {
return attributeColorMap.value;
}
const colorMap = await defaultColorMapFor(name);
return colorMap;
}

async function ensureColorMap(): Promise<void> {
const selectedName = attributeName.value;
if (attributeColorMap.value !== undefined || selectedName === undefined) {
return;
}
const defaultColorMap = await defaultColorMapFor(selectedName);
if (attributeName.value === selectedName && attributeColorMap.value === undefined) {
attributeColorMap.value = defaultColorMap;
}
}

return { resolveColorMap, ensureColorMap };
}

export type { AttributeInfo } from "@ogw_front/utils/attributes";
export {
type AttributeItemOption,
Expand All @@ -131,5 +199,7 @@ export {
attributeRequestParams,
attributeRangesPerTarget,
useAttributeRangeBounds,
useColorMapResolver,
useSelectedAttributeColorMap,
useSeriesTimeStepCommit,
Comment thread
SpliiT marked this conversation as resolved.
Resolved
};
9 changes: 5 additions & 4 deletions app/composables/physical_property_coloring.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import type { AttributeColorMap, ColoringType } from "@ogw_front/types/attribute";
import type {
ComponentType,
ElementType,
} from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
import type { ModelComponentId, ModelId } from "@ogw_front/types/identifiers";
import { type NonEmptyArray, isNonEmpty } from "@ogw_front/utils/arrays";
import type { AttributeName } from "@geode/opengeodeweb-viewer/schema_types";
import type { ColoringType } from "@ogw_front/types/attribute";
import type { PhysicalPropertyNode } from "@ogw_front/utils/physical_properties_tree";
import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types";
import { useColorMapResolver } from "@ogw_front/composables/attribute_selector";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";

// The colormap the attribute selector starts with
const DEFAULT_COLOR_MAP: AttributeColorMap = "batlow";
// The coloring a component goes back to when the property coloring is removed
const CONSTANT_COLORING: ColoringType = "constant";

Expand Down Expand Up @@ -104,6 +103,7 @@ export function usePhysicalPropertyColoring(modelId: ModelId): {
} {
const dataStyleStore = useDataStyleStore();
const hybridViewerStore = useHybridViewerStore();
const defaultColorMapFor = useColorMapResolver(() => modelId);

function nodeMethods(node: PhysicalPropertyNode): ColoringMethods | undefined {
return coloringMethods(dataStyleStore, node.component_type, node.element_type);
Expand Down Expand Up @@ -132,12 +132,13 @@ export function usePhysicalPropertyColoring(modelId: ModelId): {
await methods.setActiveColoring(modelId, componentIds, CONSTANT_COLORING);
} else if (node.coloring !== undefined) {
const { item, minimum, maximum } = node.coloring;
const colorMap = await defaultColorMapFor(node.attribute_name);
await methods.setAttribute(modelId, componentIds, {
name: node.attribute_name,
item,
minimum,
maximum,
colorMap: DEFAULT_COLOR_MAP,
colorMap,
});
await methods.setActiveColoring(modelId, componentIds, node.element_type);
}
Expand Down
29 changes: 26 additions & 3 deletions app/utils/colormap.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
// oxlint-disable unicorn/prefer-export-from
import { IMPLICIT_ATTRIBUTE_NAME, isImplicitModelType } from "@ogw_front/utils/implicit_model";
import type { AttributeColorMap } from "@ogw_front/types/attribute";
import type { AttributeName } from "@geode/opengeodeweb-viewer/schema_types";
import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types";
import type { Pixels } from "@ogw_front/types/ui";
import colormaps from "@ogw_front/assets/colormaps.json";

import type { AttributeColorMap } from "@ogw_front/types/attribute";
import { newInstance as vtkColorTransferFunction } from "@kitware/vtk.js/Rendering/Core/ColorTransferFunction";

const DEFAULT_COLORMAP: AttributeColorMap = "batlow";
const IMPLICIT_COLORMAP: AttributeColorMap = "implicit";

function defaultAttributeColorMap(
geodeObjectType: GeodeObjectType | undefined,
attributeName: AttributeName | undefined,
): AttributeColorMap {
if (isImplicitModelType(geodeObjectType) && attributeName === IMPLICIT_ATTRIBUTE_NAME) {
return IMPLICIT_COLORMAP;
}
return DEFAULT_COLORMAP;
}

interface ColormapPreset {
readonly Name: AttributeColorMap;
readonly RGBPoints: readonly number[];
Expand Down Expand Up @@ -104,6 +119,14 @@ function drawCanvasForPreset(
ctx.putImageData(imageData, 0, 0);
}

export { drawCanvasForPreset, getRGBPointsFromPreset, getPresetByName, getPresetsWithCurrentAtTop };
export {
DEFAULT_COLORMAP,
IMPLICIT_COLORMAP,
defaultAttributeColorMap,
drawCanvasForPreset,
getPresetByName,
getPresetsWithCurrentAtTop,
getRGBPointsFromPreset,
};

export { default as colormaps } from "@ogw_front/assets/colormaps.json";
15 changes: 15 additions & 0 deletions app/utils/implicit_model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { AttributeName } from "@geode/opengeodeweb-viewer/schema_types";
import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types";

// The vertex attribute holding the implicit function of an implicit model
const IMPLICIT_ATTRIBUTE_NAME: AttributeName = "geode_implicit_attribute";
const IMPLICIT_MODEL_TYPES: ReadonlySet<GeodeObjectType> = new Set([
"ImplicitStructuralModel",
"ImplicitCrossSection",
]);

function isImplicitModelType(geodeObjectType: GeodeObjectType | undefined): boolean {
return geodeObjectType !== undefined && IMPLICIT_MODEL_TYPES.has(geodeObjectType);
}

export { IMPLICIT_ATTRIBUTE_NAME, isImplicitModelType };
4 changes: 4 additions & 0 deletions app/utils/import_item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { type LegacyDataId, fromLegacyDataId } from "@ogw_front/utils/legacy_data_id";
import { type NewDataItem, useDataStore } from "@ogw_front/stores/data";
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import { isImplicitModelType } from "@ogw_front/utils/implicit_model";
import { isModel } from "@ogw_front/utils/viewer_object_type";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useFeedbackStore } from "@ogw_front/stores/feedback";
Expand Down Expand Up @@ -35,6 +36,9 @@ async function applyStyleWhenReady(item: NewDataItem, ready: Promise<unknown>):
if (!(await useDataStore().fetchIsViewable(item.data_id))) {
return undefined;
}
if (isImplicitModelType(item.geode_object_type)) {
await useDataStyleStore().applyImplicitDefaultStyle(item.data_id, item.geode_object_type);
}
return useDataStyleStore().applyDefaultStyle(item.data_id);
Comment thread
SpliiT marked this conversation as resolved.
Resolved
}

Expand Down
Loading
Loading