Skip to content

Commit 3339556

Browse files
committed
fix(ScalarProbe): calculate position from IJK
Better shortening of long values and layer names
1 parent 1197662 commit 3339556

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

src/components/ProbeView.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script setup lang="ts">
22
import { computed } from 'vue';
3-
import { useProbeStore } from '@/src/store/probe';
43
import { storeToRefs } from 'pinia';
4+
import { useProbeStore } from '@/src/store/probe';
5+
import { shortenNumber } from '@/src/utils';
56
67
const probeStore = useProbeStore();
78
const { probeData } = storeToRefs(probeStore);
@@ -10,13 +11,15 @@ const formattedProbeItems = computed(() => {
1011
if (!probeData.value) return [];
1112
const sampleItems = probeData.value.samples.map((sample) => ({
1213
label: sample.name,
13-
value: sample.displayValue.join(', '),
14+
value: sample.displayValues
15+
.map((item) => (typeof item === 'number' ? shortenNumber(item) : item))
16+
.join(', '),
1417
}));
1518
1619
// Add additional item for Position
1720
const positionItem = {
1821
label: 'Position',
19-
value: probeData.value.pos.map(Math.round).join(', '),
22+
value: Array.from(probeData.value.pos).map(Math.round).join(', '),
2023
};
2124
2225
return [...sampleItems, positionItem];
@@ -30,11 +33,17 @@ const formattedProbeItems = computed(() => {
3033
v-for="(item, index) in formattedProbeItems"
3134
:key="index"
3235
class="d-flex"
36+
style="max-width: 100%"
3337
>
34-
<span class="text-left text-truncate mr-2">
38+
<span
39+
class="text-left text-truncate mr-2 flex-grow-0 flex-shrink-1"
40+
style="min-width: 6rem; max-width: 50%"
41+
>
3542
{{ item.label }}
3643
</span>
37-
<span class="text-right ml-auto font-weight-bold">
44+
<span
45+
class="text-right font-weight-bold text-truncate flex-grow-1 flex-shrink-1"
46+
>
3847
{{ item.value }}
3948
</span>
4049
</div>

src/components/tools/ScalarProbe.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import { inject, watch, computed, toRefs } from 'vue';
3+
import type { ReadonlyVec3 } from 'gl-matrix';
34
import { onVTKEvent } from '@/src/composables/onVTKEvent';
45
import { VtkViewContext } from '@/src/components/vtk/context';
56
import { useCurrentImage } from '@/src/composables/useCurrentImage';
@@ -101,10 +102,13 @@ watch(
101102
);
102103
103104
const getImageSamples = (x: number, y: number) => {
105+
const firstToSample = sampleSet.value[0];
106+
if (!firstToSample) return undefined;
107+
104108
pointPicker.pick([x, y, 1.0], view.renderer);
105109
if (pointPicker.getActors().length === 0) return undefined;
106110
107-
const ijk = pointPicker.getPointIJK();
111+
const ijk = pointPicker.getPointIJK() as unknown as ReadonlyVec3;
108112
const samples = sampleSet.value.map((item: any) => {
109113
const dims = item.image.getDimensions();
110114
const scalarData = item.image.getPointData().getScalars();
@@ -115,16 +119,18 @@ const getImageSamples = (x: number, y: number) => {
115119
if (item.type === 'segmentGroup') {
116120
return {
117121
...baseInfo,
118-
displayValue: scalars.map(
122+
displayValues: scalars.map(
119123
(v) => item.segments.byValue[v]?.name || 'Background'
120124
),
121125
};
122126
}
123-
return { ...baseInfo, displayValue: scalars };
127+
return { ...baseInfo, displayValues: scalars };
124128
});
125129
130+
const position = firstToSample.image.indexToWorld(ijk);
131+
126132
return {
127-
pos: pointPicker.getPickPosition(),
133+
pos: position,
128134
samples,
129135
};
130136
};

src/store/probe.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { ref } from 'vue';
22
import { defineStore } from 'pinia';
3+
import { vec3 } from 'gl-matrix';
34

45
export type ProbeSample = {
56
id: string;
67
name: string;
7-
displayValue: (string | number)[];
8+
displayValues: (string | number)[];
89
};
910

1011
export type ProbeData =
1112
| {
12-
pos: number[];
13+
pos: vec3;
1314
samples: ProbeSample[];
1415
}
1516
| undefined;

src/utils/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,14 @@ export function normalizeForStore<T, K extends keyof T>(objects: T[], key: K) {
283283

284284
return { order, byKey };
285285
}
286+
287+
export function shortenNumber(value: number) {
288+
if (Number.isInteger(value)) {
289+
return value.toString();
290+
}
291+
const abs = Math.abs(value);
292+
if (abs > 0 && abs < 1) {
293+
return value.toExponential(2);
294+
}
295+
return value.toFixed(2);
296+
}

0 commit comments

Comments
 (0)