@@ -158,7 +158,12 @@ export function TrainAiModelFromAnnotationTab({ onClose }: { onClose: () => void
158
158
) ;
159
159
}
160
160
161
- type MagInfoWithAnnotationId = { annotationId : string ; magInfo : MagInfo } ;
161
+ type TrainingAnnotation = {
162
+ annotationId : string ;
163
+ imageDataLayer : string ;
164
+ layerName : string ;
165
+ mag : Vector3 ;
166
+ } ;
162
167
163
168
export function TrainAiModelTab < GenericAnnotation extends APIAnnotation | HybridTracing > ( {
164
169
getMagsForSegmentationLayer,
@@ -174,8 +179,28 @@ export function TrainAiModelTab<GenericAnnotation extends APIAnnotation | Hybrid
174
179
onAddAnnotationsInfos ?: ( newItems : Array < AnnotationInfoForAIJob < APIAnnotation > > ) => void ;
175
180
} ) {
176
181
const [ form ] = Form . useForm ( ) ;
182
+
183
+ const magInfoPerLayer : Array < MagInfo > | null = Form . useWatch ( ( ) => {
184
+ const getIntersectingMags = ( idx : number , annotationId : string , dataset : APIDataset ) => {
185
+ console . log ( "getIntersectingMags" ) ;
186
+ const segmentationLayerName = form . getFieldValue ( [ "trainingAnnotations" , idx , "layerName" ] ) ;
187
+ const imageDataLayerName = form . getFieldValue ( [ "trainingAnnotations" , idx , "imageDataLayer" ] ) ;
188
+ if ( segmentationLayerName != null && imageDataLayerName != null ) {
189
+ return new MagInfo (
190
+ getIntersectingMagList ( annotationId , dataset , segmentationLayerName , imageDataLayerName ) ,
191
+ ) ;
192
+ }
193
+ return new MagInfo ( [ ] ) ;
194
+ } ;
195
+
196
+ return form . getFieldValue ( "trainingAnnotations" ) . map ( ( _ : TrainingAnnotation , idx : number ) => {
197
+ const annotation = annotationInfos [ idx ] . annotation ;
198
+ const annotationId = "id" in annotation ? annotation . id : annotation . annotationId ;
199
+ return getIntersectingMags ( idx , annotationId , annotationInfos [ idx ] . dataset ) ;
200
+ } ) ;
201
+ } , form ) ;
202
+
177
203
const [ useCustomWorkflow , setUseCustomWorkflow ] = React . useState ( false ) ;
178
- const [ mags , setMags ] = useState < MagInfoWithAnnotationId [ ] > ( ) ;
179
204
180
205
const getIntersectingMagList = (
181
206
annotationId : string ,
@@ -195,60 +220,22 @@ export function TrainAiModelTab<GenericAnnotation extends APIAnnotation | Hybrid
195
220
) ;
196
221
} ;
197
222
198
- const getIntersectingMags = (
199
- annotationId : string ,
200
- dataset : APIDataset ,
201
- groundTruthLayerName : string ,
202
- imageDataLayerName : string ,
203
- ) => {
204
- const intersectingMags = getIntersectingMagList (
205
- annotationId ,
206
- dataset ,
207
- groundTruthLayerName ,
208
- imageDataLayerName ,
209
- ) ;
210
- if ( mags == null ) {
211
- return [ { annotationId, magInfo : new MagInfo ( intersectingMags ) } ] ;
212
- } else {
213
- return mags . map ( ( mag ) =>
214
- mag . annotationId === annotationId
215
- ? { annotationId, magInfo : new MagInfo ( intersectingMags ) }
216
- : mag ,
217
- ) ;
218
- }
219
- } ;
220
-
221
- const setIntersectingMags = (
222
- annotationId : string ,
223
- dataset : APIDataset ,
224
- groundTruthLayerName : string ,
225
- imageDataLayerName : string ,
226
- ) =>
227
- setMags ( getIntersectingMags ( annotationId , dataset , groundTruthLayerName , imageDataLayerName ) ) ;
228
-
229
223
const getMagsForColorLayer = ( colorLayers : APIDataLayer [ ] , layerName : string ) => {
230
224
const colorLayer = colorLayers . find ( ( layer ) => layer . name === layerName ) ;
231
225
return colorLayer != null ? getMagInfo ( colorLayer . resolutions ) . getMagList ( ) : null ;
232
226
} ;
233
227
234
228
const getTrainingAnnotations = async ( values : any ) => {
235
229
return Promise . all (
236
- values . trainingAnnotations . map (
237
- async ( trainingAnnotation : {
238
- annotationId : string ;
239
- imageDataLayer : string ;
240
- layerName : string ;
241
- mag : Vector3 ;
242
- } ) => {
243
- const { annotationId, imageDataLayer, layerName, mag } = trainingAnnotation ;
244
- return {
245
- annotationId,
246
- colorLayerName : imageDataLayer ,
247
- segmentationLayerName : layerName ,
248
- mag,
249
- } ;
250
- } ,
251
- ) ,
230
+ values . trainingAnnotations . map ( async ( trainingAnnotation : TrainingAnnotation ) => {
231
+ const { annotationId, imageDataLayer, layerName, mag } = trainingAnnotation ;
232
+ return {
233
+ annotationId,
234
+ colorLayerName : imageDataLayer ,
235
+ segmentationLayerName : layerName ,
236
+ mag,
237
+ } ;
238
+ } ) ,
252
239
) ;
253
240
} ;
254
241
@@ -347,24 +334,7 @@ export function TrainAiModelTab<GenericAnnotation extends APIAnnotation | Hybrid
347
334
const fixedSelectedColorLayer = colorLayers . length === 1 ? colorLayers [ 0 ] : null ;
348
335
const annotationId = "id" in annotation ? annotation . id : annotation . annotationId ;
349
336
350
- const initialMags =
351
- fixedSelectedColorLayer != null && fixedSelectedSegmentationLayer != null
352
- ? getIntersectingMagList (
353
- annotationId ,
354
- dataset ,
355
- fixedSelectedSegmentationLayer . name ,
356
- fixedSelectedColorLayer . name ,
357
- )
358
- : [ ] ;
359
- const initialMagInfo = new MagInfo ( initialMags ) ;
360
-
361
337
const onChangeLayer = ( ) => {
362
- setIntersectingMags (
363
- annotationId ,
364
- dataset ,
365
- form . getFieldValue ( [ "trainingAnnotations" , idx , "layerName" ] ) ,
366
- form . getFieldValue ( [ "trainingAnnotations" , idx , "imageDataLayer" ] ) ,
367
- ) ;
368
338
form . setFieldValue ( [ "trainingAnnotations" , idx , "mag" ] , undefined ) ;
369
339
} ;
370
340
@@ -421,10 +391,9 @@ export function TrainAiModelTab<GenericAnnotation extends APIAnnotation | Hybrid
421
391
< MagSelectionFormItem
422
392
name = { [ "trainingAnnotations" , idx , "mag" ] }
423
393
magInfo = {
424
- mags != null
425
- ? mags . find ( ( magInfoForAnno ) => magInfoForAnno . annotationId === annotationId )
426
- ?. magInfo
427
- : initialMagInfo
394
+ magInfoPerLayer != null && magInfoPerLayer [ idx ] != null
395
+ ? magInfoPerLayer [ idx ]
396
+ : new MagInfo ( [ ] )
428
397
}
429
398
/>
430
399
</ Col >
0 commit comments