@@ -16,6 +16,7 @@ use bevy::{
16
16
sprite:: Anchor ,
17
17
tasks:: { AsyncComputeTaskPool , Task } ,
18
18
} ;
19
+ use egui:: Color32 ;
19
20
use futures_lite:: future;
20
21
21
22
use nalgebra:: Matrix4 ;
@@ -85,9 +86,9 @@ pub enum IMCEvent {
85
86
output : ClassifierOutput ,
86
87
} ,
87
88
88
- SetBackgroundColour {
89
+ SetBackgroundOpacity {
89
90
entity : Entity ,
90
- colour : Colour ,
91
+ opacity : f32 ,
91
92
} ,
92
93
93
94
SetHistogramScale {
@@ -117,9 +118,9 @@ fn handle_imc_event(
117
118
118
119
//load_imc(mcd, &mut commands, &mut textures, &thread_pool);
119
120
}
120
- IMCEvent :: SetBackgroundColour { entity, colour } => {
121
+ IMCEvent :: SetBackgroundOpacity { entity, opacity } => {
121
122
if let Ok ( mut imc) = q_imc. get_mut ( * entity) {
122
- imc. background_colour = colour . clone ( ) ;
123
+ imc. background_alpha = * opacity ;
123
124
}
124
125
}
125
126
IMCEvent :: SetHistogramScale { entity, scale } => {
@@ -1139,7 +1140,7 @@ fn load_imc(
1139
1140
. insert ( IMCDataset {
1140
1141
mcd,
1141
1142
histogram_scale : HistogramScale :: None ,
1142
- background_colour : Colour :: Bevy ( Color :: BLACK ) ,
1143
+ background_alpha : 1.0 ,
1143
1144
panoramas,
1144
1145
acquisitions : acquisition_entities. into_iter ( ) . collect ( ) ,
1145
1146
} )
@@ -1185,7 +1186,7 @@ pub struct IMCDataset {
1185
1186
1186
1187
// Settings
1187
1188
histogram_scale : HistogramScale ,
1188
- background_colour : Colour ,
1189
+ background_alpha : f32 ,
1189
1190
1190
1191
pub panoramas : Vec < Entity > ,
1191
1192
pub acquisitions : HashMap < u16 , Entity > ,
@@ -1199,8 +1200,8 @@ impl IMCDataset {
1199
1200
. unwrap_or ( "Unknown name" )
1200
1201
}
1201
1202
1202
- pub fn background_colour ( & self ) -> & Colour {
1203
- & self . background_colour
1203
+ pub fn background_alpha ( & self ) -> f32 {
1204
+ self . background_alpha
1204
1205
}
1205
1206
pub fn histogram_scale ( & self ) -> & HistogramScale {
1206
1207
& self . histogram_scale
@@ -1357,87 +1358,110 @@ fn generate_histogram(
1357
1358
}
1358
1359
}
1359
1360
1361
+ // This needs rethinking. Ideally want to generate the mixture between the various
1360
1362
fn image_control_changed (
1361
- q_control : Query < ( & ImageControl , & Children ) , Changed < ImageControl > > ,
1363
+ q_imc : Query < ( & IMCDataset , & Children , ChangeTrackers < IMCDataset > ) > ,
1364
+ q_control : Query < ( & ImageControl , & Children , ChangeTrackers < ImageControl > ) > ,
1362
1365
q_acquisition : Query < & Handle < Image > , With < Acquisition > > ,
1363
1366
q_acquisition_images : Query < & AcquisitionChannelImage > ,
1364
1367
channel_data : Res < Assets < ChannelImage > > ,
1365
1368
mut textures : ResMut < Assets < Image > > ,
1366
1369
) {
1367
- for ( control, children) in q_control. iter ( ) {
1368
- // Check each AcquisitionChannelImage (child of ImageControl)
1369
- for child in children. iter ( ) {
1370
- if let Ok ( acq_channel_image) = q_acquisition_images. get ( * child) {
1371
- if let Ok ( image) = q_acquisition. get ( acq_channel_image. acquisition_entity ) {
1372
- if let Some ( image) = textures. get_mut ( image) {
1373
- match & acq_channel_image. data {
1374
- Some ( data) => {
1375
- if let Some ( channel_image) = channel_data. get ( data) {
1376
- for ( index, intensity) in
1377
- channel_image. intensities ( ) . iter ( ) . enumerate ( )
1378
- {
1379
- let intensity = ( ( intensity - control. colour_domain . 0 )
1380
- / ( control. colour_domain . 1 - control. colour_domain . 0 )
1381
- * 255.0 )
1382
- as u8 ;
1383
-
1384
- match control. image_update_type {
1385
- ImageUpdateType :: Red => {
1386
- image. data [ index * 4 ] = intensity;
1387
- }
1388
- ImageUpdateType :: Green => {
1389
- image. data [ index * 4 + 1 ] = intensity;
1390
- }
1391
- ImageUpdateType :: Blue => {
1392
- image. data [ index * 4 + 2 ] = intensity;
1393
- }
1394
- ImageUpdateType :: All => {
1395
- image. data [ index * 4 ] = intensity;
1396
- image. data [ index * 4 + 1 ] = intensity;
1397
- image. data [ index * 4 + 2 ] = intensity;
1398
- }
1399
- }
1370
+ for ( imc, children, imc_tracker) in q_imc. iter ( ) {
1371
+ let requires_update = imc_tracker. is_changed ( ) ;
1400
1372
1401
- // let intensity = image.data[index * 4 + 2]
1402
- // .max(image.data[index * 4 + 1])
1403
- // .max(image.data[index * 4]);
1404
- // let alpha = match intensity {
1405
- // 0..=25 => intensity * 10,
1406
- // _ => 255,
1407
- // };
1373
+ for ( control_index, ( control, children, control_tracker) ) in q_control. iter ( ) . enumerate ( ) {
1374
+ // Check each AcquisitionChannelImage (child of ImageControl)
1408
1375
1409
- // image.data[index * 4 + 3] = alpha;
1410
- image. data [ index * 4 + 3 ] = 255 ;
1411
- }
1412
- }
1413
- }
1414
- None => {
1415
- // There is no data associated with this acquisition, so remove the previous data
1416
- for chunk in image. data . chunks_mut ( 4 ) {
1417
- match control. image_update_type {
1418
- ImageUpdateType :: Red => {
1419
- chunk[ 0 ] = 0 ;
1420
- }
1421
- ImageUpdateType :: Green => {
1422
- chunk[ 1 ] = 0 ;
1423
- }
1424
- ImageUpdateType :: Blue => {
1425
- chunk[ 2 ] = 0 ;
1426
- }
1427
- ImageUpdateType :: All => {
1428
- chunk[ 0 ] = 0 ;
1429
- chunk[ 1 ] = 0 ;
1430
- chunk[ 2 ] = 0 ;
1431
- }
1432
- }
1376
+ if control_tracker. is_changed ( ) || requires_update {
1377
+ info ! (
1378
+ "Channel image updated => recalculating | {:?}" ,
1379
+ imc. background_alpha( )
1380
+ ) ;
1433
1381
1434
- let intensity = chunk[ 2 ] . max ( chunk[ 1 ] . max ( chunk[ 0 ] ) ) ;
1435
- let alpha = match intensity {
1436
- 0 ..=25 => intensity * 10 ,
1437
- _ => 255 ,
1438
- } ;
1382
+ for child in children. iter ( ) {
1383
+ if let Ok ( acq_channel_image) = q_acquisition_images. get ( * child) {
1384
+ if let Ok ( image) = q_acquisition. get ( acq_channel_image. acquisition_entity ) {
1385
+ if let Some ( image) = textures. get_mut ( image) {
1386
+ match & acq_channel_image. data {
1387
+ Some ( data) => {
1388
+ if let Some ( channel_image) = channel_data. get ( data) {
1389
+ for ( index, intensity) in
1390
+ channel_image. intensities ( ) . iter ( ) . enumerate ( )
1391
+ {
1392
+ if control_index == 0 {
1393
+ image. data [ index * 4 + 3 ] =
1394
+ ( imc. background_alpha ( ) * 255.0 ) as u8 ;
1395
+ }
1396
+
1397
+ let intensity = ( ( intensity
1398
+ - control. colour_domain . 0 )
1399
+ / ( control. colour_domain . 1
1400
+ - control. colour_domain . 0 )
1401
+ * 255.0 )
1402
+ as u8 ;
1403
+
1404
+ if intensity > 0 {
1405
+ match control. image_update_type {
1406
+ ImageUpdateType :: Red => {
1407
+ image. data [ index * 4 ] = intensity;
1408
+ }
1409
+ ImageUpdateType :: Green => {
1410
+ image. data [ index * 4 + 1 ] = intensity;
1411
+ }
1412
+ ImageUpdateType :: Blue => {
1413
+ image. data [ index * 4 + 2 ] = intensity;
1414
+ }
1415
+ ImageUpdateType :: All => {
1416
+ image. data [ index * 4 ] = intensity;
1417
+ image. data [ index * 4 + 1 ] = intensity;
1418
+ image. data [ index * 4 + 2 ] = intensity;
1419
+ }
1420
+ }
1439
1421
1440
- chunk[ 3 ] = alpha;
1422
+ // let intensity = image.data[index * 4 + 2]
1423
+ // .max(image.data[index * 4 + 1])
1424
+ // .max(image.data[index * 4]);
1425
+ // let alpha = match intensity {
1426
+ // 0..=25 => intensity * 10,
1427
+ // _ => 255,
1428
+ // };
1429
+
1430
+ // image.data[index * 4 + 3] = alpha;
1431
+ image. data [ index * 4 + 3 ] = 255 ;
1432
+ }
1433
+ }
1434
+ }
1435
+ }
1436
+ None => {
1437
+ // // There is no data associated with this acquisition, so remove the previous data
1438
+ // for chunk in image.data.chunks_mut(4) {
1439
+ // match control.image_update_type {
1440
+ // ImageUpdateType::Red => {
1441
+ // chunk[0] = 0;
1442
+ // }
1443
+ // ImageUpdateType::Green => {
1444
+ // chunk[1] = 0;
1445
+ // }
1446
+ // ImageUpdateType::Blue => {
1447
+ // chunk[2] = 0;
1448
+ // }
1449
+ // ImageUpdateType::All => {
1450
+ // chunk[0] = 0;
1451
+ // chunk[1] = 0;
1452
+ // chunk[2] = 0;
1453
+ // }
1454
+ // }
1455
+
1456
+ // let intensity = chunk[2].max(chunk[1].max(chunk[0]));
1457
+ // let alpha = match intensity {
1458
+ // 0..=25 => intensity * 10,
1459
+ // _ => 255,
1460
+ // };
1461
+
1462
+ // chunk[3] = alpha;
1463
+ // }
1464
+ }
1441
1465
}
1442
1466
}
1443
1467
}
0 commit comments