Search in sources :

Example 6 with JochrePage

use of com.joliciel.jochre.doc.JochrePage in project jochre by urieli.

the class JochreCorpusImageProcessor method process.

public void process() {
    this.initialiseStream();
    JochreDocument currentDoc = null;
    JochrePage currentPage = null;
    for (JochreImage image : this.getImages()) {
        if (!image.getPage().equals(currentPage)) {
            if (currentPage != null) {
                for (DocumentObserver observer : observers) {
                    observer.onPageComplete(currentPage);
                }
                LOG.debug("completed page: " + currentPage);
            }
        }
        if (!image.getPage().getDocument().equals(currentDoc)) {
            if (currentDoc != null) {
                for (DocumentObserver observer : observers) {
                    observer.onDocumentComplete(currentDoc);
                }
                LOG.debug("completed doc: " + currentDoc);
            }
            currentDoc = image.getPage().getDocument();
            LOG.debug("next doc: " + currentDoc);
            for (DocumentObserver observer : observers) {
                observer.onDocumentStart(currentDoc);
            }
        }
        if (!image.getPage().equals(currentPage)) {
            currentPage = image.getPage();
            LOG.debug("next page: " + currentPage);
            for (DocumentObserver observer : observers) {
                observer.onPageStart(currentPage);
            }
        }
        LOG.debug("next image: " + image);
        for (DocumentObserver observer : observers) {
            observer.onImageStart(image);
        }
        for (DocumentObserver observer : observers) {
            observer.onImageComplete(image);
        }
        LOG.debug("completed image: " + image);
        image.clearMemory();
    }
    if (currentPage != null) {
        for (DocumentObserver observer : observers) {
            observer.onPageComplete(currentPage);
        }
        LOG.debug("completed page: " + currentPage);
    }
    if (currentDoc != null) {
        for (DocumentObserver observer : observers) {
            observer.onDocumentComplete(currentDoc);
        }
        LOG.debug("completed doc: " + currentDoc);
    }
    for (DocumentObserver observer : observers) {
        observer.onAnalysisComplete();
    }
}
Also used : DocumentObserver(com.joliciel.jochre.doc.DocumentObserver) JochreDocument(com.joliciel.jochre.doc.JochreDocument) JochrePage(com.joliciel.jochre.doc.JochrePage)

Example 7 with JochrePage

use of com.joliciel.jochre.doc.JochrePage in project jochre by urieli.

the class TextController method onTimer$startRenderTimer.

@Listen("onTimer = #startRenderTimer")
public void onTimer$startRenderTimer(Event event) {
    try {
        progressBox.setVisible(true);
        if (currentImage != null) {
            Html html = new Html();
            StringWriter out = new StringWriter();
            DocumentObserver textGetter = new TextGetter(out, TextFormat.XHTML);
            textGetter.onImageComplete(currentImage);
            html.setContent(out.toString());
            htmlContent.appendChild(html);
            progressMeter1.setValue(100);
        // progressBox.setVisible(false);
        } else {
            if (currentPageIndex < currentDoc.getPages().size()) {
                JochrePage page = currentDoc.getPages().get(currentPageIndex);
                for (JochreImage image : page.getImages()) {
                    Html html = new Html();
                    StringWriter out = new StringWriter();
                    DocumentObserver textGetter = new TextGetter(out, TextFormat.XHTML);
                    textGetter.onImageComplete(image);
                    out.append("<HR/>");
                    html.setContent(out.toString());
                    htmlContent.appendChild(html);
                }
                page.clearMemory();
                currentPageIndex++;
                double percentComplete = ((double) currentPageIndex / (double) currentDoc.getPages().size()) * 100;
                progressMeter1.setValue(new Double(percentComplete).intValue());
                startRenderTimer.setRunning(true);
            } else {
                progressMeter1.setValue(100);
            // progressBox.setVisible(false);
            }
        }
    } catch (Exception e) {
        LOG.error("Failure in onTimer$startRenderTimer", e);
        throw new RuntimeException(e);
    }
}
Also used : JochreImage(com.joliciel.jochre.graphics.JochreImage) StringWriter(java.io.StringWriter) DocumentObserver(com.joliciel.jochre.doc.DocumentObserver) Html(org.zkoss.zul.Html) JochrePage(com.joliciel.jochre.doc.JochrePage) TextGetter(com.joliciel.jochre.output.TextGetter) Listen(org.zkoss.zk.ui.select.annotation.Listen)

Example 8 with JochrePage

use of com.joliciel.jochre.doc.JochrePage in project jochre by urieli.

the class DocumentController method getDocumentTree.

public TreeModel<TreeNode<DocOrImage>> getDocumentTree() {
    LOG.debug("getDocumentTree2");
    DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
    List<JochreDocument> docs = documentDao.findDocuments();
    List<TreeNode<DocOrImage>> docNodeList = new ArrayList<>();
    for (JochreDocument doc : docs) {
        List<TreeNode<DocOrImage>> imageNodeList = new ArrayList<>();
        for (JochrePage page : doc.getPages()) {
            LOG.debug("page " + page.getIndex());
            for (JochreImage image : page.getImages()) {
                DefaultTreeNode<DocOrImage> imageNode = new DefaultTreeNode<DocumentController.DocOrImage>(new DocOrImage(image));
                imageNodeList.add(imageNode);
                if (imageId == image.getId())
                    currentImage = image;
            }
        // have images?
        }
        boolean open = docId == doc.getId();
        if (open)
            currentDoc = doc;
        DefaultTreeNode<DocOrImage> docNode = new DirectoryTreeNode<DocumentController.DocOrImage>(new DocOrImage(doc), imageNodeList, open);
        docNodeList.add(docNode);
    }
    DefaultTreeNode<DocOrImage> root = new DefaultTreeNode<DocumentController.DocOrImage>(null, docNodeList);
    TreeModel<TreeNode<DocOrImage>> docTree = new DefaultTreeModel<>(root);
    this.reloadDoc();
    this.reloadImage();
    return docTree;
}
Also used : JochreImage(com.joliciel.jochre.graphics.JochreImage) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) ArrayList(java.util.ArrayList) DocumentDao(com.joliciel.jochre.doc.DocumentDao) JochreDocument(com.joliciel.jochre.doc.JochreDocument) DefaultTreeModel(org.zkoss.zul.DefaultTreeModel) JochrePage(com.joliciel.jochre.doc.JochrePage) TreeNode(org.zkoss.zul.TreeNode) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode)

Example 9 with JochrePage

use of com.joliciel.jochre.doc.JochrePage in project jochre by urieli.

the class SplitController method doAfterCompose.

@Override
public void doAfterCompose(Window window) throws Exception {
    super.doAfterCompose(window);
    String pageTitle = Labels.getLabel("splits.title");
    winSplits.getPage().setTitle(pageTitle);
    Session session = Sessions.getCurrent();
    currentUser = (User) session.getAttribute(LoginController.SESSION_JOCHRE_USER);
    if (currentUser == null)
        Executions.sendRedirect("login.zul");
    GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
    shapesToSplit = graphicsDao.findShapesToSplit(jochreSession.getLocale());
    for (Shape shape : shapesToSplit) {
        Row shapeRow = new Row();
        Image shapeImage = new Image();
        org.zkoss.image.Image convertedImage = Images.encode("shape_" + shape.getId() + ".png", shape.getImage());
        shapeImage.setContent(convertedImage);
        shapeImage.setWidth(shape.getImage().getWidth() + "px");
        shapeImage.setHeight((shape.getImage().getHeight()) + "px");
        Cell shapeCell = new Cell();
        Div shapeDiv = new Div();
        shapeDiv.setStyle("position: relative;");
        shapeCell.appendChild(shapeDiv);
        int shapeWidth = shape.getImage().getWidth();
        shapeCell.setWidth((shapeWidth + 100) + "px");
        shapeImage.addEventListener("onClick", new ShapeImageOnClickEventListener(shape, shapeDiv));
        shapeDiv.appendChild(shapeImage);
        for (Split split : shape.getSplits()) {
            Div verticalLine = new Div();
            verticalLine.setWidth("1px");
            verticalLine.setHeight("100px");
            verticalLine.setStyle("position: absolute; top:0px; left: " + split.getPosition() + "px;background-color:RED;");
            verticalLine.setId("shape" + shape.getId() + "split" + split.getPosition());
            verticalLine.addEventListener("onClick", new SplitOnClickEventListener(shape, shapeDiv, verticalLine, split));
            shapeDiv.appendChild(verticalLine);
        }
        shapeRow.appendChild(shapeCell);
        Cell letterCell = new Cell();
        Label letterLabel = new Label();
        letterLabel.setValue(shape.getLetter());
        letterCell.appendChild(letterLabel);
        letterCell.setWidth("100px");
        shapeRow.appendChild(letterCell);
        Cell detailsCell = new Cell();
        Label detailsLabel = new Label();
        JochrePage page = shape.getGroup().getRow().getParagraph().getImage().getPage();
        JochreDocument doc = page.getDocument();
        detailsLabel.setValue(doc.getName() + ", page " + page.getIndex());
        detailsCell.appendChild(detailsLabel);
        shapeRow.appendChild(detailsCell);
        splitGridRows.appendChild(shapeRow);
    }
}
Also used : Shape(com.joliciel.jochre.graphics.Shape) Label(org.zkoss.zul.Label) JochreDocument(com.joliciel.jochre.doc.JochreDocument) Image(org.zkoss.zul.Image) JochrePage(com.joliciel.jochre.doc.JochrePage) Div(org.zkoss.zul.Div) GraphicsDao(com.joliciel.jochre.graphics.GraphicsDao) Row(org.zkoss.zul.Row) Split(com.joliciel.jochre.boundaries.Split) Cell(org.zkoss.zul.Cell) JochreSession(com.joliciel.jochre.JochreSession) Session(org.zkoss.zk.ui.Session)

Example 10 with JochrePage

use of com.joliciel.jochre.doc.JochrePage in project jochre by urieli.

the class SplitCandidateFinderImplTest method testFindSplitCanidates.

@Test
public void testFindSplitCanidates() throws Exception {
    System.setProperty("config.file", "src/test/resources/test.conf");
    ConfigFactory.invalidateCaches();
    Config config = ConfigFactory.load();
    JochreSession jochreSession = new JochreSession(config);
    InputStream imageFileStream = getClass().getResourceAsStream("shape_370454.png");
    assertNotNull(imageFileStream);
    BufferedImage image = ImageIO.read(imageFileStream);
    final JochrePage page = mock(JochrePage.class);
    JochreImage jochreImage = new SourceImage(page, "name", image, jochreSession);
    Shape shape = jochreImage.getShape(0, 0, jochreImage.getWidth() - 1, jochreImage.getHeight() - 1);
    SplitCandidateFinder splitCandidateFinder = new SplitCandidateFinder(jochreSession);
    List<Split> splits = splitCandidateFinder.findSplitCandidates(shape);
    int[] trueSplitPositions = new int[] { 38, 59, 82 };
    boolean[] foundSplit = new boolean[] { false, false, false };
    for (Split splitCandidate : splits) {
        LOG.debug("Split candidate at " + splitCandidate.getPosition());
        for (int i = 0; i < trueSplitPositions.length; i++) {
            int truePos = trueSplitPositions[i];
            int distance = splitCandidate.getPosition() - truePos;
            if (distance < 0)
                distance = 0 - distance;
            if (distance < splitCandidateFinder.getMinDistanceBetweenSplits()) {
                foundSplit[i] = true;
                LOG.debug("Found split: " + truePos + ", distance " + distance);
            }
        }
    }
    for (int i = 0; i < trueSplitPositions.length; i++) {
        assertTrue("didn't find split " + trueSplitPositions[i], foundSplit[i]);
    }
}
Also used : JochreImage(com.joliciel.jochre.graphics.JochreImage) Shape(com.joliciel.jochre.graphics.Shape) SourceImage(com.joliciel.jochre.graphics.SourceImage) Config(com.typesafe.config.Config) InputStream(java.io.InputStream) JochrePage(com.joliciel.jochre.doc.JochrePage) BufferedImage(java.awt.image.BufferedImage) JochreSession(com.joliciel.jochre.JochreSession) Test(org.junit.Test)

Aggregations

JochrePage (com.joliciel.jochre.doc.JochrePage)10 JochreDocument (com.joliciel.jochre.doc.JochreDocument)8 JochreImage (com.joliciel.jochre.graphics.JochreImage)7 Shape (com.joliciel.jochre.graphics.Shape)6 Test (org.junit.Test)5 JochreSession (com.joliciel.jochre.JochreSession)4 GroupOfShapes (com.joliciel.jochre.graphics.GroupOfShapes)4 Paragraph (com.joliciel.jochre.graphics.Paragraph)4 RowOfShapes (com.joliciel.jochre.graphics.RowOfShapes)4 ArrayList (java.util.ArrayList)4 Config (com.typesafe.config.Config)3 StringWriter (java.io.StringWriter)3 DocumentObserver (com.joliciel.jochre.doc.DocumentObserver)2 SourceImage (com.joliciel.jochre.graphics.SourceImage)2 BufferedImage (java.awt.image.BufferedImage)2 InputStream (java.io.InputStream)2 Split (com.joliciel.jochre.boundaries.Split)1 DocumentDao (com.joliciel.jochre.doc.DocumentDao)1 GraphicsDao (com.joliciel.jochre.graphics.GraphicsDao)1 Segmenter (com.joliciel.jochre.graphics.Segmenter)1