Stack.java
Go to the documentation of this file.00001 package theba.core;
00002
00003 import theba.core.gui.ThebaPrefs;
00004 import theba.core.io.SliceWriter;
00005 import theba.core.io.VolumeReader;
00006 import theba.core.math.Point3D;
00007
00021 public class Stack {
00022 private int width;
00023
00024 private int height;
00025
00026 private int depth;
00027
00028 private boolean writable = false;
00029
00030 private VolumeReader writer;
00031
00032 public VolumeReader getWriter() {
00033 return writer;
00034 }
00035
00036 public void flush() {
00037 writer.flush();
00038 }
00039
00040 public boolean isWritable() {
00041 return writable;
00042 }
00043
00044 public Stack(int w, int h, int d, String fileName) {
00045 width = w;
00046 height = h;
00047 depth = d;
00048 writer = new SliceWriter(fileName, w, h, d, ThebaPrefs.getInstance()
00049 .getInt("cacheSize", 500));
00050 writable = true;
00051 }
00052
00053 public Stack(VolumeReader reader) {
00054 width = reader.getWidth();
00055 height = reader.getHeight();
00056 depth = reader.getDepth();
00057 writer = reader;
00058 }
00059
00069 public void setVoxelUnchecked(int x, int y, int z, int val) {
00070 short[] slice = writer.getSlice(z);
00071 slice[x + y * width] = (short) val;
00072 }
00073
00082 public void setVoxel(int x, int y, int z, int val) {
00083 if (x < 0 || y < 0 || z < 0 || x >= width || y >= height || z >= depth)
00084 return;
00085 short[] slice = writer.getSlice(z);
00086 slice[x + y * width] = (short) val;
00087 }
00088
00098 public short getVoxelUnchecked(int x, int y, int z) {
00099 return writer.getSlice(z)[x + y * width];
00100 }
00101
00110 public short getVoxel(int x, int y, int z) {
00111 if (x < 0 || y < 0 || z < 0 || x >= width || y >= height || z >= depth)
00112 return 0;
00113 short[] slice = writer.getSlice(z);
00114 return slice[x + y * width];
00115 }
00116
00125 public short getVoxel(Point3D p) {
00126 if (p.x < 0 || p.y < 0 || p.z < 0 || p.x >= width || p.y >= height
00127 || p.z >= depth)
00128 return 0;
00129 short[] slice = writer.getSlice(p.z);
00130 return slice[p.x + p.y * width];
00131 }
00132
00133 public short[] getSlice(int z) {
00134 return writer.getSlice(z);
00135 }
00136
00137 public void putSlice(short[] data, int z) {
00138 writer.putSlice(data, z);
00139 }
00140
00141 public int getDepth() {
00142 return depth;
00143 }
00144
00145 public void setDepth(int depth) {
00146 this.depth = depth;
00147 }
00148
00149 public int getHeight() {
00150 return height;
00151 }
00152
00153 public void setHeight(int height) {
00154 this.height = height;
00155 }
00156
00157 public int getWidth() {
00158 return width;
00159 }
00160
00161 public void setWidth(int width) {
00162 this.width = width;
00163 }
00164 }