📄 searchengine.java
字号:
out.write("<CENTER>\n"); out.write("<TABLE BORDER=0 WIDTH=100% CELLPADDING=3 CELLSPACING=3>\n"); int i; GeometryMetadata data; DecimalFormat f1 = new DecimalFormat("0000000"); DecimalFormat f2 = new DecimalFormat("00"); long modelId; String filename, fullpath; for ( i = start; i < similarModels.size() && i < start + size; i++ ) { modelId = similarModels.get(i).getId(); if ( i % 4 == 0 ) { out.write("<TR>\n"); } out.write("<TD WIDTH=25% VALIGN=CENTER ALIGN=CENTER>\n"); data = shapeDatabase.searchEntryById(modelId); if ( data != null ) { out.write("<A HREF=\"ServletConsole?session=" + sessionId + "&input=model_detail&id=" + modelId + "\">\n"); out.write("<IMG BORDER=1 SRC=\"" + dir + "/previews/" + f1.format(modelId, new StringBuffer(""), new FieldPosition(0)).toString() + "/" + f2.format(0, new StringBuffer(""), new FieldPosition(0)).toString() + "small.jpg" + "\"></IMG>\n"); } else { out.write("<B>No metadata descriptor for ID " + similarModels.get(i).getId() + "\n"); } fullpath = similarModels.get(i).getFilename().toString(); filename = fullpath.substring(searchLastSlash(fullpath)); out.write("</A><BR>"+ (i+1) + ". <B>" + filename + "</B>"); out.write("<BR>Distance: " + VSDK.formatDouble(similarModels.get(i).getDistance()) + "<BR>"); out.write("<A HREF=\"ServletConsole?session=" + sessionId + "&input=retrieve_sh&id=" + modelId + "\">Find similar shapes</A>"); out.write("</TD>\n"); if ( i % 4 == 3 ) { out.write("</TR>\n"); } } if ( i % 4 != 0 ) { out.write("</TR>\n"); } out.write("</TABLE>\n"); out.write("</CENTER>\n"); //- Footer -------------------------------------------------------- if ( similarModels.size() > 0 ) { out.write("<FONT SIZE=\"-1\">\n"); writePreviousNextAsHtml(out, similarModels, sessionId, start, size); out.write("</FONT>\n"); } out.write("<P>This page was automatically generated by VITRAL\n"); out.write("More information available at <A HREF=\"http://sophia.javeriana.edu.co/~ochavarr\">http://sophia.javeriana.edu.co/~ochavarr</A>\n"); out.write("</HTML>\n"); } public void reportTimers() { int i; TimeReport r; double totalTime = 0; double totalSum = 0; System.out.println("= TIMERS REPORT ==========================================================="); System.out.println("Following a report of different stage timers for program operations:"); Set<String> s = timers.keySet(); for ( String e : s ) { r = timers.get(e); if ( r.getLabel().equals("TOTAL") ) { totalTime = r.getTime(); } else { System.out.println(" - " + r); totalSum += r.getTime(); } } System.out.println(" - " + timers.get("TOTAL")); System.out.printf(" - Other timers (%f total - %f summed): %f\n", totalTime, totalSum, totalTime - totalSum); System.out.println("Other timers stand for:"); System.out.println(" - Garbage collection"); System.out.println(" - Errors in time metrics"); System.out.println(" - Control operations"); System.out.println(" - Time used for console to scroll text"); System.out.println(" - Time used for redirected console to save log files"); System.out.println("Note that current figures stands for ELLAPSED (no CPU) times (java limitation)"); } private void exportDatabase(String command[], ShapeDatabase shapeDatabase, int op) { int j, k; timers.get("WRITE_DATABASE").start(); System.out.println("Exporting database with " + shapeDatabase.getNumEntries() + " fields!"); System.out.println("Depending on database size, this could take some time..."); GeometryMetadata m; ArrayList<ShapeDescriptor> d; ShapeDescriptor s; double arr[]; String stringSegment = null; try { //--------------------------------------------------------- File fd = new File(command[1]); FileOutputStream fos; BufferedOutputStream writer; fd = new File(command[1]); fos = new FileOutputStream(fd); writer = new BufferedOutputStream(fos); //--------------------------------------------------------- byte barr[]; ProgressMonitorConsole reporter; reporter = new ProgressMonitorConsole(); reporter.begin(); long index; long N; N = shapeDatabase.getMaxEntryId(); for ( index = 0; index <= N; index++ ) { m = shapeDatabase.searchEntryById(index); if ( m != null ) { d = m.getDescriptors(); if ( op == 1 ) { stringSegment = "[" + m.getId() + "]\t" + m.getFilename() + "\t"; for ( j = 0; j < d.size(); j++ ) { s = d.get(j); stringSegment += s.getLabel() + "\t"; barr = stringSegment.getBytes(); writer.write(barr, 0, barr.length); arr = s.getFeatureVector(); for ( k = 0; k < arr.length; k++ ) { stringSegment = arr[k] + "\t"; barr = stringSegment.getBytes(); writer.write(barr, 0, barr.length); } } stringSegment = "EOL\n"; } else if ( op == 2 ) { DecimalFormat f1 = new DecimalFormat("0000000"); stringSegment = "convert ./output/previews/" + f1.format(m.getId(), new StringBuffer(""), new FieldPosition(0)).toString() + "/00.jpg " + m.getFilename() + "_preview.png\n"; } barr = stringSegment.getBytes(); writer.write(barr, 0, barr.length); } reporter.update(0, N, index); } reporter.end(); writer.close(); fos.close(); } catch ( Exception e ) { System.out.println("Error exporting database!"); } timers.get("WRITE_DATABASE").stop(); } public ArrayList <Result> runCommand( GL gl, JoglShapeMatchingOfflineRenderer offlineRenderer, GLCanvas canvas, JoglProjectedViewRenderer projectedViewRenderer, String command[], ShapeDatabase shapeDatabase, int distanceFieldSide) { ArrayList <Result> similarModels = null; int i; timers.get("TOTAL").start(); //----------------------------------------------------------------- if ( command[0].equals("add") ) { System.out.println("Processing command add..."); indexFiles(gl, command, shapeDatabase, distanceFieldSide, canvas, offlineRenderer, projectedViewRenderer); syncDatabase(shapeDatabase); } //----------------------------------------------------------------- else if ( command[0].equals("addList") ) { String list[] = null; try { File fd; FileReader fr; BufferedInputStream bis; BufferedReader reader; InputStreamReader isr; int tokenType; i = 0; //- Count filenames ------------------------------------------ int count = 0; fd = new File(command[1]); fr = new FileReader(fd); reader = new BufferedReader(fr); String line; do { line = reader.readLine(); if ( line == null ) break; count++; } while ( true ); fr.close(); //- Load filenames ------------------------------------------- System.out.println("Processing " + count + " files."); list = new String[count]; fd = new File(command[1]); fr = new FileReader(fd); reader = new BufferedReader(fr); i = 0; do { line = reader.readLine(); if ( line == null ) break; list[i] = new String(line); i++; } while ( true ); fr.close(); } catch ( Exception e ) { System.err.println("Error building file list."); e.printStackTrace(); System.exit(1); } indexFiles(gl, list, shapeDatabase, distanceFieldSide, canvas, offlineRenderer, projectedViewRenderer); syncDatabase(shapeDatabase); } //----------------------------------------------------------------- else if ( command[0].equals("searchModel") ) { similarModels = matchModelSphericalHarmonics(command[1], shapeDatabase, 1, distanceFieldSide); } //----------------------------------------------------------------- else if ( command[0].equals("searchDistanceField") ) { IndexedColorImage distanceField = readIndexedColorImage(command[1], distanceFieldSide); if ( distanceField == null ) { System.err.println("Error importing distance field. Program aborted."); System.exit(1); } similarModels = matchSketch(distanceField, shapeDatabase, 5, 0); } //----------------------------------------------------------------- else if ( command[0].equals("searchSketch") ) { IndexedColorImage outline = readIndexedColorImage(command[1], distanceFieldSide); if ( outline == null ) { System.err.println("Error importing distance field. Program aborted."); System.exit(1); } IndexedColorImage distanceField; distanceField = new IndexedColorImage(); distanceField.init(distanceFieldSide, distanceFieldSide); ImageProcessing.processDistanceFieldWithArray(outline, distanceField, 1); similarModels = matchSketch(distanceField, shapeDatabase, 5, 0); } //----------------------------------------------------------------- else if ( command[0].equals("exportDatabase") ) { if ( command.length != 2 ) { System.err.println("ERROR: exportDatabase command must specified a text filename to export."); System.err.println("Database exporting aborted."); } else { System.out.println("Processing command exportDatabase ..."); exportDatabase(command, shapeDatabase, 1); System.out.println("Done exporting database."); } } //----------------------------------------------------------------- else if ( command[0].equals("exportPreviews") ) { if ( command.length != 2 ) { System.err.println("ERROR: exportPreviews command must specified a text filename to export."); System.err.println("Database exporting aborted."); } else { System.out.println("Processing command exportPreviews ..."); exportDatabase(command, shapeDatabase, 2); System.out.println("Done exporting database."); } } //----------------------------------------------------------------- else { System.err.println("Invalid command [" + command[0] + "]"); } //----------------------------------------------------------------- timers.get("TOTAL").stop(); return similarModels; }}//===========================================================================//= EOF =//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -