return 0;
int s = volume.getVoxelUnchecked(xp, yp, zp);
if (s == val)
return 0;
LinkedList<Point3D> queue = new LinkedList<Point3D>();
queue.addFirst(new Point3D(xp, yp, zp));
while (queue.isEmpty() == false) {
Point3D p = queue.removeLast();
int x = p.x;
int y = p.y;
int z = p.z;
int pixelIndex = x + y * width;
short[] pixels = volume.getSlice(z);
pixels[pixelIndex] = val;
count++;
if (x < width - 1 && pixels[pixelIndex + 1] == s) {
queue.addFirst(new Point3D(x + 1, y, z));
pixels[pixelIndex + 1] = -1;
}
if (x - 1 >= 0 && pixels[pixelIndex - 1] == s) {
queue.addFirst(new Point3D(x - 1, y, z));
pixels[pixelIndex - 1] = -1;
}
if (y < height - 1 && pixels[pixelIndex + width] == s) {
queue.addFirst(new Point3D(x, y + 1, z));
pixels[pixelIndex + width] = -1;
}
if (y - 1 >= 0 && pixels[pixelIndex - width] == s) {
queue.addFirst(new Point3D(x, y - 1, z));
pixels[pixelIndex - width] = -1;
}
if (z >= 1 && volume.getSlice(z - 1)[pixelIndex] == s) {
queue.addFirst(new Point3D(x, y, z - 1));
volume.getSlice((z - 1))[pixelIndex] = -1;
}
if (z < depth - 1 && volume.getSlice(z + 1)[pixelIndex] == s) {
queue.addFirst(new Point3D(x, y, z + 1));
volume.getSlice((z + 1))[pixelIndex] = -1;
}
}
return count;
}