use of maspack.util.Pair in project artisynth_core by artisynth.
the class DicomTextureContent method packRects.
protected Rectangle[] packRects(int nrows, int ncols, int nslices) {
// pack three textures into one
// rows x cols, rows x slices, cols x slices
List<Pair<Integer, Rectangle>> planes = new ArrayList<Pair<Integer, Rectangle>>(3);
planes.add(new Pair<Integer, Rectangle>(COL_ROW_PLANE, new Rectangle(0, 0, ncols, nrows)));
planes.add(new Pair<Integer, Rectangle>(COL_SLICE_PLANE, new Rectangle(0, 0, ncols, nslices)));
planes.add(new Pair<Integer, Rectangle>(ROW_SLICE_PLANE, new Rectangle(0, 0, nrows, nslices)));
// sort by area descending
Collections.sort(planes, new Comparator<Pair<Integer, Rectangle>>() {
@Override
public int compare(Pair<Integer, Rectangle> o1, Pair<Integer, Rectangle> o2) {
int a1 = o1.second().area();
int a2 = o2.second().area();
if (a1 > a2) {
return -1;
} else if (a1 < a2) {
return 1;
}
return 0;
}
});
int totalwidth = 2 * ncols + nrows;
int totalheight = nrows + 2 * nslices;
int maxdim = Math.max(totalwidth, totalheight);
Rectangle[] out = new Rectangle[3];
// tightly pack into rectangle
BinaryTreeRectanglePacker packer = new BinaryTreeRectanglePacker(maxdim, maxdim);
for (int i = 0; i < 3; ++i) {
out[planes.get(i).first] = packer.pack(planes.get(i).second);
}
return out;
}
Aggregations