First we create a constructor which takes the image and saves it in a variable.
Grid3D image;
public PointsCloudMaker(Grid3D image) {
this.image = image;
}
After having created a Constructor, we determine a method which creates a Point-Cloud from the given image.
public ArrayList<PointND> getPoints(int id)
The initial variable in this method is the Image size ([0]=x, [1]=y, [2]=z).
int [] size = image.getSize();
Then we walk over the x, y, z variables and use a mask on the i and i+1 values every single step.
for (int k=0; k <size[2]; k++){ for (int j=0; j <size[1]; j++){ for (int i=0; i <size[0]-1; i++){ float one = image.getAtIndex(i, j, k); float two = image.getAtIndex(i+1, j, k); } }}
If the variables "one" and "two" have different values we have to test on what position the point supposed to be placed (i or i+1). In the case that the point is not “null” it will be saved in the ArrayList “points”.
if (one != two) {
PointND point = null;
if (one == id){
point = new PointND(General.voxelToWorld(new int [] {i,j,k}, image.getSpacing(), image.getOrigin()));
}
if (two == id){
point = new PointND(General.voxelToWorld(new int [] {i+1,j,k}, image.getSpacing(), image.getOrigin()));
}
if (point != null) points.add(point);
}
Finally we return the Point-Cloud!
return points;