55
55
import bdv .spimdata .SequenceDescriptionMinimal ;
56
56
import bdv .spimdata .SpimDataMinimal ;
57
57
import bdv .spimdata .XmlIoSpimDataMinimal ;
58
+ import bdv .img .imagestack .ImageStackImageLoader ;
59
+ import bdv .img .n5 .N5ImageLoader ;
60
+ import bdv .img .virtualstack .VirtualStackImageLoader ;
58
61
import fiji .util .gui .GenericDialogPlus ;
59
62
import ij .IJ ;
60
63
import ij .ImageJ ;
63
66
import ij .gui .DialogListener ;
64
67
import ij .gui .GenericDialog ;
65
68
import mpicbg .spim .data .generic .sequence .BasicViewSetup ;
69
+ import mpicbg .spim .data .generic .sequence .TypedBasicImgLoader ;
66
70
import mpicbg .spim .data .registration .ViewRegistration ;
67
71
import mpicbg .spim .data .registration .ViewRegistrations ;
68
72
import mpicbg .spim .data .sequence .Channel ;
@@ -139,19 +143,44 @@ public void run()
139
143
progressWriter .out ().println ( "starting export..." );
140
144
141
145
// create ImgLoader wrapping the image
142
- final ImagePlusImgLoader < ? > imgLoader ;
143
- switch ( imp .getType () )
146
+ final TypedBasicImgLoader < ? > imgLoader ;
147
+ final Runnable clearCache ;
148
+ final boolean isVirtual = imp .getStack () != null && imp .getStack ().isVirtual ();
149
+ if ( isVirtual )
144
150
{
145
- case ImagePlus .GRAY8 :
146
- imgLoader = ImagePlusImgLoader .createGray8 ( imp , params .minMaxOption , params .rangeMin , params .rangeMax );
147
- break ;
148
- case ImagePlus .GRAY16 :
149
- imgLoader = ImagePlusImgLoader .createGray16 ( imp , params .minMaxOption , params .rangeMin , params .rangeMax );
150
- break ;
151
- case ImagePlus .GRAY32 :
152
- default :
153
- imgLoader = ImagePlusImgLoader .createGray32 ( imp , params .minMaxOption , params .rangeMin , params .rangeMax );
154
- break ;
151
+ final VirtualStackImageLoader < ?, ?, ? > il ;
152
+ switch ( imp .getType () )
153
+ {
154
+ case ImagePlus .GRAY8 :
155
+ il = VirtualStackImageLoader .createUnsignedByteInstance ( imp );
156
+ break ;
157
+ case ImagePlus .GRAY16 :
158
+ il = VirtualStackImageLoader .createUnsignedShortInstance ( imp );
159
+ break ;
160
+ case ImagePlus .GRAY32 :
161
+ default :
162
+ il = VirtualStackImageLoader .createFloatInstance ( imp );
163
+ break ;
164
+ }
165
+ imgLoader = il ;
166
+ clearCache = il .getCacheControl ()::clearCache ;
167
+ }
168
+ else
169
+ {
170
+ switch ( imp .getType () )
171
+ {
172
+ case ImagePlus .GRAY8 :
173
+ imgLoader = ImageStackImageLoader .createUnsignedByteInstance ( imp );
174
+ break ;
175
+ case ImagePlus .GRAY16 :
176
+ imgLoader = ImageStackImageLoader .createUnsignedShortInstance ( imp );
177
+ break ;
178
+ case ImagePlus .GRAY32 :
179
+ default :
180
+ imgLoader = ImageStackImageLoader .createFloatInstance ( imp );
181
+ break ;
182
+ }
183
+ clearCache = () -> {};
155
184
}
156
185
157
186
final int numTimepoints = imp .getNFrames ();
@@ -174,8 +203,7 @@ public void run()
174
203
timepoints .add ( new TimePoint ( t ) );
175
204
final SequenceDescriptionMinimal seq = new SequenceDescriptionMinimal ( new TimePoints ( timepoints ), setups , imgLoader , null );
176
205
177
- Map < Integer , ExportMipmapInfo > perSetupExportMipmapInfo ;
178
- perSetupExportMipmapInfo = new HashMap <>();
206
+ final Map < Integer , ExportMipmapInfo > perSetupExportMipmapInfo = new HashMap <>();
179
207
final ExportMipmapInfo mipmapInfo = params .setMipmapManual
180
208
? new ExportMipmapInfo ( params .resolutions , params .subdivisions )
181
209
: autoMipmapSettings ;
@@ -189,7 +217,6 @@ public void run()
189
217
// required for all original planes contributing to a "plane of
190
218
// blocks" at the current level. If this is more than 1/4 of
191
219
// available memory, use the loopback image.
192
- final boolean isVirtual = imp .getStack ().isVirtual ();
193
220
final long planeSizeInBytes = imp .getWidth () * imp .getHeight () * imp .getBytesPerPixel ();
194
221
final long ijMaxMemory = IJ .maxMemory ();
195
222
final int numCellCreatorThreads = Math .max ( 1 , PluginHelper .numThreads () - 1 );
@@ -228,7 +255,7 @@ public void afterEachPlane( final boolean usedLoopBack )
228
255
final long actuallyFree = max - total + free ;
229
256
230
257
if ( actuallyFree < max / 2 )
231
- imgLoader . clearCache ();
258
+ clearCache . run ();
232
259
}
233
260
}
234
261
@@ -291,12 +318,6 @@ protected static class Parameters
291
318
292
319
final File hdf5File ;
293
320
294
- final MinMaxOption minMaxOption ;
295
-
296
- final double rangeMin ;
297
-
298
- final double rangeMax ;
299
-
300
321
final boolean deflate ;
301
322
302
323
final boolean split ;
@@ -308,17 +329,14 @@ protected static class Parameters
308
329
public Parameters (
309
330
final boolean setMipmapManual , final int [][] resolutions , final int [][] subdivisions ,
310
331
final File seqFile , final File hdf5File ,
311
- final MinMaxOption minMaxOption , final double rangeMin , final double rangeMax , final boolean deflate ,
332
+ final boolean deflate ,
312
333
final boolean split , final int timepointsPerPartition , final int setupsPerPartition )
313
334
{
314
335
this .setMipmapManual = setMipmapManual ;
315
336
this .resolutions = resolutions ;
316
337
this .subdivisions = subdivisions ;
317
338
this .seqFile = seqFile ;
318
339
this .hdf5File = hdf5File ;
319
- this .minMaxOption = minMaxOption ;
320
- this .rangeMin = rangeMin ;
321
- this .rangeMax = rangeMax ;
322
340
this .deflate = deflate ;
323
341
this .split = split ;
324
342
this .timepointsPerPartition = timepointsPerPartition ;
@@ -332,12 +350,6 @@ public Parameters(
332
350
333
351
static String lastChunkSizes = "{32,32,4}, {16,16,8}, {8,8,8}" ;
334
352
335
- static int lastMinMaxChoice = 2 ;
336
-
337
- static double lastMin = 0 ;
338
-
339
- static double lastMax = 65535 ;
340
-
341
353
static boolean lastSplit = false ;
342
354
343
355
static int lastTimepointsPerPartition = 0 ;
@@ -350,12 +362,6 @@ public Parameters(
350
362
351
363
protected Parameters getParameters ( final double impMin , final double impMax , final ExportMipmapInfo autoMipmapSettings )
352
364
{
353
- if ( lastMinMaxChoice == 0 ) // use ImageJs...
354
- {
355
- lastMin = impMin ;
356
- lastMax = impMax ;
357
- }
358
-
359
365
while ( true )
360
366
{
361
367
final GenericDialogPlus gd = new GenericDialogPlus ( "Export for BigDataViewer" );
@@ -367,15 +373,6 @@ protected Parameters getParameters( final double impMin, final double impMax, fi
367
373
gd .addStringField ( "Hdf5_chunk_sizes" , lastChunkSizes , 25 );
368
374
final TextField tfChunkSizes = ( TextField ) gd .getStringFields ().lastElement ();
369
375
370
- gd .addMessage ( "" );
371
- final String [] minMaxChoices = new String [] { "Use ImageJ's current min/max setting" , "Compute min/max of the (hyper-)stack" , "Use values specified below" };
372
- gd .addChoice ( "Value_range" , minMaxChoices , minMaxChoices [ lastMinMaxChoice ] );
373
- final Choice cMinMaxChoices = (Choice ) gd .getChoices ().lastElement ();
374
- gd .addNumericField ( "Min" , lastMin , 0 );
375
- final TextField tfMin = (TextField ) gd .getNumericFields ().lastElement ();
376
- gd .addNumericField ( "Max" , lastMax , 0 );
377
- final TextField tfMax = (TextField ) gd .getNumericFields ().lastElement ();
378
-
379
376
gd .addMessage ( "" );
380
377
gd .addCheckbox ( "split_hdf5" , lastSplit );
381
378
final Checkbox cSplit = ( Checkbox ) gd .getCheckboxes ().lastElement ();
@@ -390,59 +387,37 @@ protected Parameters getParameters( final double impMin, final double impMax, fi
390
387
gd .addMessage ( "" );
391
388
PluginHelper .addSaveAsFileField ( gd , "Export_path" , lastExportPath , 25 );
392
389
393
- // gd.addMessage( "" );
394
- // gd.addMessage( "This Plugin is developed by Tobias Pietzsch ([email protected] )\n" );
395
- // Bead_Registration.addHyperLinkListener( ( MultiLineLabel ) gd.getMessage(), "mailto:[email protected] " );
396
-
397
390
final String autoSubsampling = ProposeMipmaps .getArrayString ( autoMipmapSettings .getExportResolutions () );
398
391
final String autoChunkSizes = ProposeMipmaps .getArrayString ( autoMipmapSettings .getSubdivisions () );
399
- gd .addDialogListener ( new DialogListener ()
400
- {
401
- @ Override
402
- public boolean dialogItemChanged ( final GenericDialog dialog , final AWTEvent e )
392
+ gd .addDialogListener ( ( dialog , e ) -> {
393
+ gd .getNextBoolean ();
394
+ gd .getNextString ();
395
+ gd .getNextString ();
396
+ gd .getNextBoolean ();
397
+ gd .getNextNumber ();
398
+ gd .getNextNumber ();
399
+ gd .getNextBoolean ();
400
+ gd .getNextString ();
401
+ if ( e instanceof ItemEvent && e .getID () == ItemEvent .ITEM_STATE_CHANGED && e .getSource () == cManualMipmap )
403
402
{
404
- gd .getNextBoolean ();
405
- gd .getNextString ();
406
- gd .getNextString ();
407
- gd .getNextChoiceIndex ();
408
- gd .getNextNumber ();
409
- gd .getNextNumber ();
410
- gd .getNextBoolean ();
411
- gd .getNextNumber ();
412
- gd .getNextNumber ();
413
- gd .getNextBoolean ();
414
- gd .getNextString ();
415
- if ( e instanceof ItemEvent && e .getID () == ItemEvent .ITEM_STATE_CHANGED && e .getSource () == cMinMaxChoices )
403
+ final boolean useManual = cManualMipmap .getState ();
404
+ tfSubsampling .setEnabled ( useManual );
405
+ tfChunkSizes .setEnabled ( useManual );
406
+ if ( !useManual )
416
407
{
417
- final boolean enable = cMinMaxChoices .getSelectedIndex () == 2 ;
418
- tfMin .setEnabled ( enable );
419
- tfMax .setEnabled ( enable );
408
+ tfSubsampling .setText ( autoSubsampling );
409
+ tfChunkSizes .setText ( autoChunkSizes );
420
410
}
421
- else if ( e instanceof ItemEvent && e .getID () == ItemEvent .ITEM_STATE_CHANGED && e .getSource () == cManualMipmap )
422
- {
423
- final boolean useManual = cManualMipmap .getState ();
424
- tfSubsampling .setEnabled ( useManual );
425
- tfChunkSizes .setEnabled ( useManual );
426
- if ( !useManual )
427
- {
428
- tfSubsampling .setText ( autoSubsampling );
429
- tfChunkSizes .setText ( autoChunkSizes );
430
- }
431
- }
432
- else if ( e instanceof ItemEvent && e .getID () == ItemEvent .ITEM_STATE_CHANGED && e .getSource () == cSplit )
433
- {
434
- final boolean split = cSplit .getState ();
435
- tfSplitTimepoints .setEnabled ( split );
436
- tfSplitSetups .setEnabled ( split );
437
- }
438
- return true ;
439
411
}
412
+ else if ( e instanceof ItemEvent && e .getID () == ItemEvent .ITEM_STATE_CHANGED && e .getSource () == cSplit )
413
+ {
414
+ final boolean split = cSplit .getState ();
415
+ tfSplitTimepoints .setEnabled ( split );
416
+ tfSplitSetups .setEnabled ( split );
417
+ }
418
+ return true ;
440
419
} );
441
420
442
- final boolean enable = lastMinMaxChoice == 2 ;
443
- tfMin .setEnabled ( enable );
444
- tfMax .setEnabled ( enable );
445
-
446
421
tfSubsampling .setEnabled ( lastSetMipmapManual );
447
422
tfChunkSizes .setEnabled ( lastSetMipmapManual );
448
423
if ( !lastSetMipmapManual )
@@ -461,9 +436,6 @@ else if ( e instanceof ItemEvent && e.getID() == ItemEvent.ITEM_STATE_CHANGED &&
461
436
lastSetMipmapManual = gd .getNextBoolean ();
462
437
lastSubsampling = gd .getNextString ();
463
438
lastChunkSizes = gd .getNextString ();
464
- lastMinMaxChoice = gd .getNextChoiceIndex ();
465
- lastMin = gd .getNextNumber ();
466
- lastMax = gd .getNextNumber ();
467
439
lastSplit = gd .getNextBoolean ();
468
440
lastTimepointsPerPartition = ( int ) gd .getNextNumber ();
469
441
lastSetupsPerPartition = ( int ) gd .getNextNumber ();
@@ -489,14 +461,6 @@ else if ( resolutions.length != subdivisions.length )
489
461
continue ;
490
462
}
491
463
492
- final MinMaxOption minMaxOption ;
493
- if ( lastMinMaxChoice == 0 )
494
- minMaxOption = MinMaxOption .TAKE_FROM_IMAGEPROCESSOR ;
495
- else if ( lastMinMaxChoice == 1 )
496
- minMaxOption = MinMaxOption .COMPUTE ;
497
- else
498
- minMaxOption = MinMaxOption .SET ;
499
-
500
464
String seqFilename = lastExportPath ;
501
465
if ( !seqFilename .endsWith ( ".xml" ) )
502
466
seqFilename += ".xml" ;
@@ -510,6 +474,7 @@ else if ( lastMinMaxChoice == 1 )
510
474
final String hdf5Filename = seqFilename .substring ( 0 , seqFilename .length () - 4 ) + ".h5" ;
511
475
final File hdf5File = new File ( hdf5Filename );
512
476
513
- return new Parameters ( lastSetMipmapManual , resolutions , subdivisions , seqFile , hdf5File , minMaxOption , lastMin , lastMax , lastDeflate , lastSplit , lastTimepointsPerPartition , lastSetupsPerPartition ); }
477
+ return new Parameters ( lastSetMipmapManual , resolutions , subdivisions , seqFile , hdf5File , lastDeflate , lastSplit , lastTimepointsPerPartition , lastSetupsPerPartition );
478
+ }
514
479
}
515
480
}
0 commit comments