// "Plot 3D Points"
//
// Plots a set of x, y, z points in a tab-delimited text file as a stack.
// Each point is plotted as 4x4x4 cube. Use the Image>Stacks 3D
// Project command to visualize the points in 3D. A sample dataset
// is available at <http://rsbweb.nih.gov/ij/macros/data/xyt-points.txt>.

 macro "Plot 3D Points" {
     size = 4;
     text = File.openAsString("");
     lines=split(text, "\n");
     xmax=0; ymax=0; zmax=0;
     for (i=0; i<lines.length; i++) {
         items=split(lines[i], ",\t");
         x = parseInt(items[0]);
         y = parseInt(items[1]);
         z = parseInt(items[2]);
         if (x>xmax) xmax = x;
         if (y>ymax) ymax = y;
         if (z>zmax) zmax = z;
     }
     setBatchMode(true);
     newImage("3D Plot", "8-bit Black", xmax+10, ymax+10, zmax+size);
     setColor(255, 255, 255);
     for (i=0; i<lines.length; i++) {
         items=split(lines[i], ",\t");
         x = parseInt(items[0]);
         y = parseInt(items[1]);
         z = parseInt(items[2]);
         slice = z+1;
         for (j=0; j<size; j++) {
             setSlice(slice++);
             fillRect(x-size/2, y-size/2, size, size);
         }
     }
     setBatchMode(false);
 }
