Hi Walter,
On Wed, 3 Apr 2013, Walter de Back wrote:
> I'm using the Transfer Function in the 3D Viewer plugin to render my
> objects as opaque multicolored objects. Since I do want to this for
> many image stacks, I have automatized my pipeline using macros. The
> only step that I cannot seem to script is changing the transfer
> function. Hence my question:
>
> Is there a way to set the Transfer Function automatically by script or
> macro?
Not using a macro. It would be relatively hard anyway, since the extension
mechanism for macro functions is pretty cumbersome to use, hence the way
3D Viewer supports macros is by offering static methods that can be called
using the call() macro function (this also addresses the problem diverging
macro API vs Java API would pose). The current call() implementation
actually only allows Strings to be passed around.
What you *could* do is to extend the 3D Viewer to have an additional
static method, something like this:
/* in ij3d.ImageJ3DViewer */
public static void setLUTs(String bigRGBArray) {
String[] stringArray = bigRGBArray.split("[ \t\n]+");
int[][] array = new int[4][stringArray.length / 4];
for (int i = 0; i < array.length; i++) {
array[0][i] = Integer.parseInt(stringArray[4 * i]);
array[1][i] = Integer.parseInt(stringArray[4 * i + 1]);
array[2][i] = Integer.parseInt(stringArray[4 * i + 2]);
array[3][i] = Integer.parseInt(stringArray[4 * i + 3]);
}
univ.getSelected().setLUTs(array[0], array[1], array[2], array[3]);
}
Of course, this code was written in my text editor and never tested. It
would be called like this:
call("ij3d.ImageJ3DViewer.setLUTs", longArrayOfInterlavedRGBA);
A better approach is, however, to call a javascript snippet from your
macro, via the eval("script", ...) macro function. Something like this:
importClass(Packages.ij3d.ImageJ3DViewer);
r = [ ... ];
g = [ ... ];
b = [ ... ];
a = [ ... ];
universe = ImageJ3DViewer.getUniv();
selected = universe.getSelected();
selected.setLUTs(r, g, b, a);
You would have to construct that snippet as a string from the macro to
transport the array values there, though.
Good luck!
Johannes
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html