|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import { inject, watch, computed, toRefs } from 'vue'; |
3 | 3 | import type { ReadonlyVec3 } from 'gl-matrix'; |
| 4 | +import { vec3 } from 'gl-matrix'; |
4 | 5 | import { onVTKEvent } from '@/src/composables/onVTKEvent'; |
| 6 | +import { worldPointToIndex } from '@/src/utils/imageSpace'; |
5 | 7 | import { VtkViewContext } from '@/src/components/vtk/context'; |
6 | 8 | import { useCurrentImage } from '@/src/composables/useCurrentImage'; |
7 | 9 | import vtkPointPicker from '@kitware/vtk.js/Rendering/Core/PointPicker'; |
@@ -110,29 +112,54 @@ const getImageSamples = (x: number, y: number) => { |
110 | 112 | pointPicker.pick([x, y, 1.0], view.renderer); |
111 | 113 | if (pointPicker.getActors().length === 0) return undefined; |
112 | 114 |
|
113 | | - const ijk = pointPicker.getPointIJK() as unknown as ReadonlyVec3; |
114 | | - const samples = sampleSet.value.map((item: any) => { |
115 | | - const dims = item.image.getDimensions(); |
116 | | - const scalarData = item.image.getPointData().getScalars(); |
117 | | - const index = dims[0] * dims[1] * ijk[2] + dims[0] * ijk[1] + ijk[0]; |
118 | | - const scalars = scalarData.getTuple(index) as number[]; |
119 | | - const baseInfo = { id: item.id, name: item.name }; |
120 | | -
|
121 | | - if (item.type === 'segmentGroup') { |
122 | | - return { |
123 | | - ...baseInfo, |
124 | | - displayValues: scalars.map( |
125 | | - (v) => item.segments.byValue[v]?.name || 'Background' |
126 | | - ), |
127 | | - }; |
128 | | - } |
129 | | - return { ...baseInfo, displayValues: scalars }; |
130 | | - }); |
131 | | -
|
132 | | - const position = firstToSample.image.indexToWorld(ijk); |
| 115 | + // Get world position from the picked point |
| 116 | + const pickedIjk = pointPicker.getPointIJK() as unknown as ReadonlyVec3; |
| 117 | + const worldPosition = vec3.clone( |
| 118 | + firstToSample.image.indexToWorld(pickedIjk) as vec3 |
| 119 | + ); |
| 120 | +
|
| 121 | + const samples = sampleSet.value |
| 122 | + .map((item: any) => { |
| 123 | + // Convert world position to this specific image's IJK |
| 124 | + const itemIjk = worldPointToIndex(item.image, worldPosition); |
| 125 | + const dims = item.image.getDimensions(); |
| 126 | + const scalarData = item.image.getPointData().getScalars(); |
| 127 | +
|
| 128 | + // Round to nearest integer indices |
| 129 | + const i = Math.round(itemIjk[0]); |
| 130 | + const j = Math.round(itemIjk[1]); |
| 131 | + const k = Math.round(itemIjk[2]); |
| 132 | +
|
| 133 | + // Check bounds |
| 134 | + if ( |
| 135 | + i < 0 || |
| 136 | + j < 0 || |
| 137 | + k < 0 || |
| 138 | + i >= dims[0] || |
| 139 | + j >= dims[1] || |
| 140 | + k >= dims[2] |
| 141 | + ) { |
| 142 | + return null; |
| 143 | + } |
| 144 | +
|
| 145 | + const index = dims[0] * dims[1] * k + dims[0] * j + i; |
| 146 | + const scalars = scalarData.getTuple(index) as number[]; |
| 147 | + const baseInfo = { id: item.id, name: item.name }; |
| 148 | +
|
| 149 | + if (item.type === 'segmentGroup') { |
| 150 | + return { |
| 151 | + ...baseInfo, |
| 152 | + displayValues: scalars.map( |
| 153 | + (v) => item.segments.byValue[v]?.name || 'Background' |
| 154 | + ), |
| 155 | + }; |
| 156 | + } |
| 157 | + return { ...baseInfo, displayValues: scalars }; |
| 158 | + }) |
| 159 | + .filter((s): s is NonNullable<typeof s> => s !== null); |
133 | 160 |
|
134 | 161 | return { |
135 | | - pos: position, |
| 162 | + pos: worldPosition, |
136 | 163 | samples, |
137 | 164 | }; |
138 | 165 | }; |
|
0 commit comments