Search in sources :

Example 1 with PdfGraphics2D

use of com.itextpdf.awt.PdfGraphics2D in project polyGembler by c-zhou.

the class Haplotyper method run.

@Override
public void run() {
    // TODO Auto-generated method stub
    myLogger.info("Random seed - " + Constants.seed);
    DataEntry[] de = start_pos == null ? DataCollection.readDataEntry(in_zip, scaff) : DataCollection.readDataEntry(in_zip, scaff, start_pos, end_pos);
    // DataEntry[] de = DataCollection.readDataEntry(in_zip, Constants._ploidy_H);
    final HiddenMarkovModel hmm = vbt ? new HiddenMarkovModelVBT(de, seperation, reverse, trainExp, field, founder_hap_coeff) : // new HiddenMarkovModelRST(de, seperation, reverse, trainExp, field, resampling):
    (hmm_file == null ? new HiddenMarkovModelBWT(de, seperation, reverse, trainExp, field, founder_hap_coeff) : new HiddenMarkovModelBWT(de, seperation, reverse, trainExp, field, founder_hap_coeff, hmm_file));
    if (Constants.plot()) {
        Runnable run = new Runnable() {

            public void run() {
                try {
                    hmmf = new HMMFrame();
                    hmmf.clearTabs();
                    if (Constants.showHMM)
                        hmmp = hmmf.addHMMTab(hmm, hmm.de(), new File(out_prefix));
                } catch (Exception e) {
                    Thread t = Thread.currentThread();
                    t.getUncaughtExceptionHandler().uncaughtException(t, e);
                    e.printStackTrace();
                }
            }
        };
        Thread th = new Thread(run);
        th.run();
    }
    if (Constants.plot()) {
        hmmf.pack();
        hmmf.setVisible(true);
    }
    double ll, ll0 = hmm.loglik();
    for (int i = 0; i < max_iter; i++) {
        hmm.train();
        if (Constants.plot())
            hmmp.update();
        ll = hmm.loglik();
        myLogger.info("----------loglik " + ll);
        if (ll < ll0) {
            // throw new RuntimeException("Fatal error!!!");
            myLogger.info("LOGLIK DECREASED!!!");
            // break;
            ll0 = ll;
            continue;
        }
        if (ll0 != Double.NEGATIVE_INFINITY && Math.abs((ll - ll0) / ll0) < Constants.minImprov)
            break;
        ll0 = ll;
    }
    if (Constants.printPlots()) {
        try {
            float width = hmmf.jframe.getSize().width, height = hmmf.jframe.getSize().height;
            Document document = new Document(new Rectangle(width, height));
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(plot_pdf));
            document.open();
            PdfContentByte canvas = writer.getDirectContent();
            PdfTemplate template = canvas.createTemplate(width, height);
            Graphics2D g2d = new PdfGraphics2D(template, width, height);
            hmmf.jframe.paint(g2d);
            g2d.dispose();
            canvas.addTemplate(template, 0, 0);
            document.close();
        } catch (FileNotFoundException | DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    String scaff_str = scaff[0] + (start_pos == null || start_pos[0] == Integer.MIN_VALUE ? "" : "_" + start_pos[0]) + (end_pos == null || end_pos[0] == Integer.MAX_VALUE ? "" : "_" + end_pos[0]);
    for (int i = 1; i < scaff.length; i++) {
        if (scaff_str.length() + scaff[i].length() + 32 <= Constants.MAX_FILE_ID_LENGTH)
            scaff_str += Constants.scaff_collapsed_str + scaff[i] + (start_pos == null || start_pos[i] == Integer.MIN_VALUE ? "" : "_" + start_pos[i]) + (end_pos == null || end_pos[i] == Integer.MAX_VALUE ? "" : "_" + end_pos[i]);
        else {
            scaff_str += Constants.scaff_collapsed_str + "etc" + scaff.length;
            break;
        }
    }
    hmm.write(out_prefix, expr_id, scaff_str, resampling);
}
Also used : Rectangle(com.itextpdf.text.Rectangle) PdfGraphics2D(com.itextpdf.awt.PdfGraphics2D) FileNotFoundException(java.io.FileNotFoundException) Document(com.itextpdf.text.Document) DataEntry(cz1.hmm.data.DataEntry) DocumentException(com.itextpdf.text.DocumentException) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) HiddenMarkovModelBWT(cz1.hmm.model.HiddenMarkovModelBWT) PdfWriter(com.itextpdf.text.pdf.PdfWriter) HiddenMarkovModel(cz1.hmm.model.HiddenMarkovModel) HiddenMarkovModelVBT(cz1.hmm.model.HiddenMarkovModelVBT) HMMFrame(cz1.hmm.swing.HMMFrame) PdfTemplate(com.itextpdf.text.pdf.PdfTemplate) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DocumentException(com.itextpdf.text.DocumentException) PrinterException(java.awt.print.PrinterException) ParseException(org.apache.commons.cli.ParseException) Graphics2D(java.awt.Graphics2D) PdfGraphics2D(com.itextpdf.awt.PdfGraphics2D) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 2 with PdfGraphics2D

use of com.itextpdf.awt.PdfGraphics2D in project polyGembler by c-zhou.

the class JfreeChart method print.

public void print(String plot_pdf) {
    try {
        float width = jframe.getSize().width, height = jframe.getSize().height;
        Document document = new Document(new Rectangle(width, height));
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(plot_pdf));
        document.open();
        PdfContentByte canvas = writer.getDirectContent();
        PdfTemplate template = canvas.createTemplate(width, height);
        Graphics2D g2d = new PdfGraphics2D(template, width, height);
        jframe.paint(g2d);
        g2d.dispose();
        canvas.addTemplate(template, 0, 0);
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : PdfWriter(com.itextpdf.text.pdf.PdfWriter) FileOutputStream(java.io.FileOutputStream) DocumentException(com.itextpdf.text.DocumentException) Rectangle(com.itextpdf.text.Rectangle) PdfGraphics2D(com.itextpdf.awt.PdfGraphics2D) FileNotFoundException(java.io.FileNotFoundException) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) Document(com.itextpdf.text.Document) PdfTemplate(com.itextpdf.text.pdf.PdfTemplate) PdfGraphics2D(com.itextpdf.awt.PdfGraphics2D) Graphics2D(java.awt.Graphics2D)

Example 3 with PdfGraphics2D

use of com.itextpdf.awt.PdfGraphics2D in project Zong by Xenoage.

the class PdfPrinter method print.

/**
 * Prints the given {@link Layout} into the given PDF output stream.
 */
public static void print(Layout layout, OutputStream out) {
    Document document = new Document();
    PdfWriter writer = null;
    try {
        writer = PdfWriter.getInstance(document, out);
    } catch (Exception e) {
        handle(warning(Voc.ErrorWhilePrinting));
    }
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    It<Page> pages = it(layout.getPages());
    for (Page page : pages) {
        // create PDF page
        Size2f pageSize = page.getFormat().getSize();
        float width = Units.mmToPx(pageSize.width, 1);
        float height = Units.mmToPx(pageSize.height, 1);
        document.newPage();
        PdfTemplate tp = cb.createTemplate(width, height);
        // fill PDF page
        Graphics2D g2d = new PdfGraphics2D(cb, width, height);
        INSTANCE.log(Companion.remark("Printing page " + pages.getIndex() + "..."));
        LayoutRenderer.paintToCanvas(layout, pages.getIndex(), new AwtCanvas(g2d, pageSize, CanvasFormat.Vector, CanvasDecoration.None, CanvasIntegrity.Perfect));
        // finish page
        g2d.dispose();
        cb.addTemplate(tp, 0, 0);
    }
    document.close();
}
Also used : PdfWriter(com.itextpdf.text.pdf.PdfWriter) Size2f(com.xenoage.utils.math.geom.Size2f) PdfGraphics2D(com.itextpdf.awt.PdfGraphics2D) AwtCanvas(com.xenoage.zong.renderer.awt.canvas.AwtCanvas) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) Page(com.xenoage.zong.layout.Page) Document(com.itextpdf.text.Document) PdfTemplate(com.itextpdf.text.pdf.PdfTemplate) Graphics2D(java.awt.Graphics2D) PdfGraphics2D(com.itextpdf.awt.PdfGraphics2D)

Aggregations

PdfGraphics2D (com.itextpdf.awt.PdfGraphics2D)3 Document (com.itextpdf.text.Document)3 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)3 PdfTemplate (com.itextpdf.text.pdf.PdfTemplate)3 PdfWriter (com.itextpdf.text.pdf.PdfWriter)3 Graphics2D (java.awt.Graphics2D)3 DocumentException (com.itextpdf.text.DocumentException)2 Rectangle (com.itextpdf.text.Rectangle)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 Size2f (com.xenoage.utils.math.geom.Size2f)1 Page (com.xenoage.zong.layout.Page)1 AwtCanvas (com.xenoage.zong.renderer.awt.canvas.AwtCanvas)1 DataEntry (cz1.hmm.data.DataEntry)1 HiddenMarkovModel (cz1.hmm.model.HiddenMarkovModel)1 HiddenMarkovModelBWT (cz1.hmm.model.HiddenMarkovModelBWT)1 HiddenMarkovModelVBT (cz1.hmm.model.HiddenMarkovModelVBT)1 HMMFrame (cz1.hmm.swing.HMMFrame)1 PrinterException (java.awt.print.PrinterException)1 File (java.io.File)1