Skip to main content

Calculate inside pixel coordinates of a primitive

Please note these forums are being decommissioned and use the new and improved forums at
3 replies [Last post]
Joined: 2007-08-16

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();
Transform3D t3d02 = new Transform3D();
Transform3D t3d03 = new Transform3D();

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) {
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

screenshot01.png193.23 KB

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-11-16

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?).

Joined: 2007-08-16

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…

Joined: 2004-11-16

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.