001: /*
002: * $RCSfile: GeometryStatistics.java,v $
003: *
004: * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistribution of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * - Redistribution in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * Neither the name of Sun Microsystems, Inc. or the names of
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * This software is provided "AS IS," without a warranty of any
023: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026: * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGES.
035: *
036: * You acknowledge that this software is not designed, licensed or
037: * intended for use in the design, construction, operation or
038: * maintenance of any nuclear facility.
039: *
040: * $Revision: 1.2 $
041: * $Date: 2007/02/09 17:17:02 $
042: * $State: Exp $
043: */
044:
045: package org.jdesktop.j3d.utils.scenegraph.traverser;
046:
047: /**
048: *
049: * @author paulby
050: * @version
051: *
052: * Provide statistics on the Geometry in a given scene graph
053: */
054: public class GeometryStatistics extends Object {
055:
056: /**
057: * Print the geometry statistics for the all SceneGraph in treeRoots to
058: * stdout. Information on all geometry nodes in the Scene Graph will
059: * be used, even nodes under disabled Switch nodes.
060: *
061: * treeRoot and all of it's children must be non-live and non-compiled
062: * if they are not an error message will be displayed
063: */
064: public static void printStatistics(javax.media.j3d.Node[] treeRoots) {
065: GeometrySizeProcessor processor = new GeometrySizeProcessor();
066: TreeScan scan = new TreeScan();
067: int triangleCount = 0;
068: int quadCount = 0;
069: int lineCount = 0;
070: int pointCount = 0;
071:
072: try {
073: Class geometryClass = Class
074: .forName("javax.media.j3d.Shape3D");
075:
076: for (int i = 0; i < treeRoots.length; i++) {
077: scan.findNode(treeRoots[i], geometryClass, processor,
078: false, false);
079: }
080:
081: System.out.println("Triangle Count : "
082: + processor.getTriangleCount());
083: System.out.println("Quad Count : "
084: + processor.getQuadCount());
085: System.out.println("Line Count : "
086: + processor.getLineCount());
087: System.out.println("Point Count : "
088: + processor.getPointCount());
089:
090: System.out.println("Percentage of Vertex in Strips "
091: + processor.getStripPercentage() + "%");
092: System.out.println("Average Strip Length "
093: + processor.getAverageStripLength());
094:
095: int[] dist = processor.getTriangleStripDistribution();
096:
097: System.out.println("Triangle Strip size distribution");
098: System.out.println("1 " + dist[1]);
099: System.out.println("2 " + dist[2]);
100: System.out.println("3 " + dist[3]);
101: System.out.println("4 " + dist[4]);
102: System.out.println("5 " + dist[5]);
103: System.out.println("6 " + dist[6]);
104: System.out.println("7 " + dist[7]);
105: System.out.println("8 " + dist[8]);
106: System.out.println("9 " + dist[9]);
107: System.out.println("10-19 " + dist[10]);
108: System.out.println("20-49 " + dist[11]);
109: System.out.println("50-99 " + dist[12]);
110: System.out.println("100-999 " + dist[13]);
111: System.out.println(">1000 " + dist[14]);
112: } catch (javax.media.j3d.CapabilityNotSetException e) {
113: System.out
114: .println("Error, SceneGraph is either live or compiled");
115: } catch (ClassNotFoundException ex) {
116: ex.printStackTrace();
117: System.exit(1);
118: }
119: }
120:
121: /**
122: * Print the geometry statistics for the SceneGraph treeRoot to
123: * stdout. Information on all geometry nodes in the Scene Graph will
124: * be used, even nodes under disabled Switch nodes.
125: *
126: * treeRoot and all of it's children must be non-live and non-compiled
127: * if they are not an error message will be displayed
128: */
129: public static void printStatistics(javax.media.j3d.Node treeRoot) {
130: printStatistics(new javax.media.j3d.Node[] { treeRoot });
131: }
132:
133: }
|