Search in sources :

Example 1 with BinaryTreeRectanglePacker

use of maspack.util.BinaryTreeRectanglePacker in project artisynth_core by artisynth.

the class TextImageStore method main.

public static void main(String[] args) throws Exception {
    int width = 512;
    int height = 512;
    TextImageStore.DEBUG = true;
    TextImageStore content = new TextImageStore(new BinaryTreeRectanglePacker(width, height), true);
    content.debugFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    content.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 32));
    content.upload("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in lorem suscipit ante lobortis lacinia et a mauris. Mauris at vulputate diam. Quisque eu mattis orci, a molestie nisl. Quisque sed tempor est. Aliquam mattis, enim eu dignissim finibus, sapien purus tempus ante, vel hendrerit ipsum nisl eget mauris. Fusce eu vestibulum ipsum. Cras ac interdum lectus, non ultrices sem. Ut velit mauris, porta id leo at, ornare fermentum sem. Cras ac maximus ex, in sodales ante. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla ac elit ut arcu vulputate congue. Ut lectus ipsum, cursus id nibh sed, consectetur dignissim magna. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec quis nibh sed felis posuere semper vel sed ante.");
    content.upload("The quick brown fox jumps over the lazy dog".toLowerCase());
    content.upload("The quick brown fox jumps over the lazy dog".toUpperCase());
    Font font = new Font(Font.SERIF, Font.BOLD, 64);
    content.setFont(font);
    content.upload("Praesent semper consequat rhoncus. Cras quis massa mauris. Proin maximus iaculis blandit. Quisque sed massa mattis nulla laoreet cursus. Nulla iaculis auctor urna at faucibus. Nulla gravida nulla at mauris gravida, sit amet pellentesque ante aliquam. Ut pulvinar urna vel congue ullamcorper. Cras ac libero a ipsum molestie auctor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nullam non feugiat libero, ut ultrices diam. Morbi sed efficitur lacus. Fusce semper arcu ac varius lacinia. Mauris non mauris facilisis, imperdiet est vitae, luctus urna. Nam dapibus sit amet nibh in lobortis. Vivamus gravida commodo magna, id fringilla quam congue sed. Nullam ut turpis elit.");
    content.upload("The quick brown fox jumps over the lazy dog".toLowerCase());
    content.upload("The quick brown fox jumps over the lazy dog".toUpperCase());
    // // loop through all glyph characters
    // int sc = 0;
    // for (int i=0; i<font.getNumGlyphs (); ++i) {
    // GlyphVector gv = font.createGlyphVector (content.getGraphics
    // ().getFontRenderContext (), new int[]{i});
    // boolean success = content.upload (gv);
    // if (success) {
    // ++sc;
    // }
    // panel.repaint();
    // }
    // System.out.println (sc + " glyphs successfully uploaded");
    content.saveImage("png", new File("tmp/glyphs0.png"));
}
Also used : BinaryTreeRectanglePacker(maspack.util.BinaryTreeRectanglePacker) File(java.io.File) Font(java.awt.Font)

Example 2 with BinaryTreeRectanglePacker

use of maspack.util.BinaryTreeRectanglePacker 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;
}
Also used : ArrayList(java.util.ArrayList) Rectangle(maspack.util.Rectangle) BinaryTreeRectanglePacker(maspack.util.BinaryTreeRectanglePacker) Pair(maspack.util.Pair)

Aggregations

BinaryTreeRectanglePacker (maspack.util.BinaryTreeRectanglePacker)2 Font (java.awt.Font)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Pair (maspack.util.Pair)1 Rectangle (maspack.util.Rectangle)1