⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphdistancevisualizationthread.java

📁 基于MPEG 7 标准,符合未来语义网架构,很值得参考
💻 JAVA
字号:
/*
 * This file is part of Caliph & Emir.
 *
 * Caliph & Emir is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Caliph & Emir is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Caliph & Emir; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Copyright statement:
 * --------------------
 * (c) 2002-2005 by Mathias Lux (mathias@juggle.at)
 * http://www.juggle.at, http://caliph-emir.sourceforge.net
 */
package at.lux.fotoretrieval;

import at.lux.components.ProgressWindow;
import at.lux.fotoretrieval.lucene.Graph;
import at.lux.fotoretrieval.panels.Visualization2DPanelWithFdp;
import at.lux.fotoretrieval.retrievalengines.LucenePathIndexRetrievalEngine;
import at.lux.retrieval.fastmap.ArrayFastmapDistanceMatrix;
import at.lux.retrieval.fastmap.DistanceCalculator;
import at.lux.retrieval.fastmap.FastMap;
import at.lux.retrieval.fastmap.FastmapDistanceMatrix;
import org.apache.lucene.index.IndexReader;

import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.LinkedList;

/**
 * SimilarImageSearchThread
 *
 * @author Mathias Lux, mathias@juggle.at
 */
public class GraphDistanceVisualizationThread extends Thread {
    String dir;
    RetrievalFrame parent;
    JProgressBar progress;
    DecimalFormat df;
    LinkedList<String> fileList;

    public GraphDistanceVisualizationThread(String directory,
                                            RetrievalFrame frame, JProgressBar progress) {
        this.dir = directory;
        this.parent = frame;
        this.progress = progress;
        df = (DecimalFormat) NumberFormat.getInstance();
        df.setMaximumFractionDigits(2);
        fileList = new LinkedList<String>();
    }

    public void run() {
        if (!dir.endsWith(File.separator)) {
            dir += File.separator;
        }
        // TODO: remove graph list here and put the index in ...
        try {
            String indexDirectory = LucenePathIndexRetrievalEngine.parsePathIndexDirectory(dir);
            if (IndexReader.indexExists(indexDirectory)) {
                IndexReader ir = IndexReader.open(indexDirectory);
                parent.setEnabled(false);
                ProgressWindow pw;
                pw = new ProgressWindow(parent, progress);
                try {
                    pw.pack();
                    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                    pw.setLocation((d.width - pw.getWidth()) / 2, (d.height - pw.getHeight()) / 2);
                    pw.setVisible(true);
                    long stime, ftime;
                    stime = System.currentTimeMillis();
                    parent.setStatus("Loading Graphs");

                    progress.setMinimum(0);
                    progress.setMaximum(3);
                    progress.setValue(0);

                    LinkedList<Graph> graphList = new LinkedList<Graph>();
                    for (int i = 0; i < ir.numDocs(); i++) {
                        Graph g = new Graph(ir.document(i).getValues("graph")[0]);
                        String graphFile = ir.document(i).getValues("file")[0];
                        graphList.add(g);
                        fileList.add(graphFile);
                    }
                    progress.setValue(1);
                    // create matrixFastmapFastmap with mcs distance for graphs.
                    FastmapDistanceMatrix matrixFastmap = new ArrayFastmapDistanceMatrix(graphList, new DistanceCalculator() {
                        public float getDistance(Object o1, Object o2) {
                            Graph g1 = (Graph) o1;
                            Graph g2 = (Graph) o2;
                            return g1.getMcsDistance(g2);
                        }
                    });
                    FastMap fm = new FastMap(matrixFastmap, 2);
                    progress.setValue(2);
                    long ms = System.currentTimeMillis();
                    fm.run();
                    ms = System.currentTimeMillis() - ms;
                    progress.setValue(3);
                    System.out.println("Time for " + matrixFastmap.getDimension() + " images: " + ms + " ms");

//        Vector results = engine.getSimilarImages(ColorLayoutDescriptor, dir, recursive, progress);
                    stime = System.currentTimeMillis() - stime;
                    ftime = System.currentTimeMillis();
                    parent.setStatus("Formatting results ...");
                    Visualization2DPanelWithFdp panel = new Visualization2DPanelWithFdp(fm.getPoints(), matrixFastmap, fileList, true);
//        ResultsPanel rp = new ResultsPanel(results, progress);
                    ftime = System.currentTimeMillis() - ftime;
                    parent.addVisualization(panel);
                    parent.setStatus("Searched for " + df.format(stime / 1000.0) + " s, formatting lasted " + df.format(ftime / 1000.0) + " s");
                } catch (Exception e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                } finally {
                    pw.setVisible(false);
                    parent.setEnabled(true);
                }
            } else {
                JOptionPane.showMessageDialog(parent, "Chosen repositors directory does not exist.");
            }
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -