# Calculate inside pixel coordinates of a primitive

Hi!

I have a simple Box with a center point (x, y, z) and dimensions (sizeX, sizeY, sizeZ). For projection into 2D space I need to calculate all pixel (or voxel) coordinates that lie within the bounds of the Box.

Additionally, in 3D-space, the Box may be transformed by an arbitrary Transform3D. This transformation has to be represented in 2D-space, of course.

My current approach is to iterate over the dimensions of the box, ask the Box wether the requested point lies within the untransformed bounds of it or not, then transform this point with the arbitrary Transform3D and add the resulting point to a HashSet.

` Vector3d v3d;`

Set<Point3i> tempSet = new HashSet<Point3i>();

Transform3D t3d01 = new Transform3D();

tgRotationX.getTransform(t3d01);

Transform3D t3d02 = new Transform3D();

tgRotationY.getTransform(t3d02);

Transform3D t3d03 = new Transform3D();

tgRotationZ.getTransform(t3d03);

double xRange = Math.round(sizeX / 2.0);

double yRange = Math.round(sizeY / 2.0);

double zRange = Math.round(sizeZ / 2.0);

for (double i = -xRange; i < xRange; i++) {

for (double j = -yRange; j < yRange; j++) {

for (double k = -zRange; k < zRange; k++) {

if (contains(x + i, y + j, z + k)) {

v3d = new Vector3d(i, j, k);

if (i != 0 || j != 0 || k != 0) {

t3d01.transform(v3d);

t3d02.transform(v3d);

t3d03.transform(v3d);

}

tempSet.add(new Point3i((int) Math.round(v3d.x + x), (int) Math.round(v3d.y + y), (int) Math.round(v3d.z + z)));

}

}

}

The problem with this approach so far is, that using certain rotation angles in the Transform3D result in an under-sampling of the coordinates. Holes in the projection are the consequence.

One temporary solution was to increment the loops with smaller values, e.g. instead of i++ I used i += 0.5. Problem here is, the resulting pixel count does not represent the original volume of the Box anymore. For example a Box of sizeX=12, sizeY=15 and sizeZ=1 would have a volume of 180(mm^3, if you need a unit). The "volume" aka the pixel count of the projection would be around 200-220, depending on the rotation angles…

Does anybody has an idea how to calculate the inside pixel coordinates of a Box with the requirement (Volume of the Box) = (Pixel count of the projection)?

Thank you in advance!

Attachment | Size |
---|---|

screenshot01.png | 193.23 KB |

This won't work, because I need these coordinates for further processing. They aren't just for visualization, I need them also as a starting point for other calculations…

I see. If videcard can do this, then it should be doable in "software rendering" mode I guess... I would look for the algorithm which is used on hardware side to apply Texture3D and implement it in Java. Drop me a line if you find anything.

Just a thought, if I understand you correctly; try to load your CT image and the cube as two Texture3Ds, then apply the textures to a planes and then combine these two planes together (make one of them transparent?).