VirtualStack setProcessor at specified slice error : Argument out of range

Hello,

I need to process a virtual stack with Groovy with the IJ1 library, and I have no clue why the following sample code doesn’t work:

import ij.ImageJ
import ij.IJ
import ij.ImagePlus
import ij.process.*
import ij.ImageStack
import ij.VirtualStack

w = 10
h = 15
n = 25
z = 1 // or any other value...

VirtualStack epsxx = new VirtualStack(w, h, n)
epsxx.setProcessor(new FloatProcessor(w, h), z)

I get this error:

java.lang.IllegalArgumentException: Argument out of range: 1
	at ij.ImageStack.setProcessor(ImageStack.java:296)
	at ij.ImageStack$setProcessor$0.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
	at Script73.run(Script73.groovy:15)
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:303)
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:122)
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:114)
	at javax.script.AbstractScriptEngine.eval(Unknown Source)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:177)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
	at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

IJ.log(epsxx.toString()) returns the correct dimensions.
Is it because there is no backing storage?
Thank you for your help!

What are you trying to accomplish? VirtualStacks are read-only so it does not make sense to call setProcessor() on a VirtualStack. The latest ImageJ daily build (1.51m3) includes an example (duplicated below) that demonstrates how to use the VirtualStack(width,height,slices) constructor.

  // This script creates a virtual stack that 
  // does not use backing storage.
  gd = new GenericDialog("Text Stack");
  gd.addStringField("Title:", "1TB Virtual Stack", 15);
  gd.addNumericField("Width:", 1024, 0, 8, "");
  gd.addNumericField("Height:", 1024, 0, 8, "");
  gd.addNumericField("Slices:", 1024*1024, 0, 8, "");
  gd.showDialog();
  title = gd.getNextString();
  width = gd.getNextNumber();
  height = gd.getNextNumber();
  slices = gd.getNextNumber();
  stack = new VirtualStack(width,height,slices);
  new ImagePlus(title,stack).show();

Thank you for your answer.
Actually I wasn’t aware that virtual stacks are read-only (precisely because they inherit setProcessor() from ImageStack).
Basically, what I’m trying to do is to write processed images in a TIF stack sequentially without loading them into memory, and display the virtual stack at the end of the process. But I can live without that, and append the images to a TIF file on-the-fly and load it as a virtual stack when the process is done.