Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/trapezium/chisel/reducers/IFS_PolygonRemover.java


1   /*
2    * @(#)IFS_PolygonRemover.java
3    *
4    * Copyright (c) 1998 by Trapezium Development LLC.  All Rights Reserved.
5    *
6    * The information in this file is the property of Trapezium Development LLC
7    * and may be used only in accordance with the terms of the license granted
8    * by Trapezium.
9    *
10   */
11  package com.trapezium.chisel.reducers;
12  
13  import com.trapezium.chisel.*;
14  
15  import com.trapezium.vrml.VrmlElement;
16  import com.trapezium.vrml.Value;
17  import com.trapezium.vrml.node.Node;
18  import com.trapezium.vrml.node.DEFUSENode;
19  import com.trapezium.vrml.node.space.SpaceStructure;
20  import com.trapezium.vrml.node.space.SpacePrimitive;
21  import com.trapezium.vrml.node.space.SpaceEntitySet;
22  import com.trapezium.vrml.fields.Field;
23  import com.trapezium.vrml.fields.FieldValue;
24  import com.trapezium.vrml.fields.MFFieldValue;
25  import java.util.Vector;
26  import java.io.FileOutputStream;
27  
28  /**
29   *  This is a polygon reduction tool, removes smallest triangles
30   *  in an IndexedFaceSet.
31   */
32  public class IFS_PolygonRemover extends IFS_SpaceStructureLoader {
33      int minNumberFaces;
34      int percentThreshold;
35      boolean preserveColorBoundaries;
36      static final int MINFACE = 0;
37      static final int PERCENT = 1;
38      static final int PRESERVE_COLOR_BOUNDARIES = 2;
39      
40    public IFS_PolygonRemover() {
41      super( "Remove small triangles..." );
42      minNumberFaces = 50;
43      percentThreshold = 10;
44      preserveColorBoundaries = false;
45    }
46  
47      public void replaceCoord( TokenPrinter tp, SpaceStructure ss, int startTokenOffset, int endTokenOffset ) {
48          if ( ss.smallTrianglePolygonReduction( minNumberFaces, percentThreshold, preserveColorBoundaries )) {
49              tp.print( "Coordinate { point [" );
50              SpaceEntitySet ses = ss.getEntitySet( SpacePrimitive.Vertex );
51              int numberVertices = ses.getNumberEntities();
52              for ( int i = 0; i < numberVertices; i++ ) {
53                  SpacePrimitive sp = ses.getEntity( i );
54                  tp.print( (float)sp.getX() );
55                  tp.print( (float)sp.getY() );
56                  tp.print( (float)sp.getZ() );
57              }
58              tp.print( "] }" );
59          } else {
60              tp.printRange( startTokenOffset, endTokenOffset, false );
61          }
62      }
63      
64      /** */
65      public int getNumberOptions() {
66          return( 3 );
67      }
68  
69      /** Get the class for an option */
70      public Class getOptionClass( int offset ) {
71          switch (offset) {
72              case MINFACE:
73              case PERCENT:
74                  try {
75                      return( Integer.TYPE );
76                  } catch (Exception e) {
77                      break;
78                  }
79              case PRESERVE_COLOR_BOUNDARIES:
80                  return( Boolean.TYPE );
81          }
82          return null;
83      }
84  
85      public String getOptionLabel( int offset ) {
86          switch (offset) {
87              case MINFACE:
88                  return( "minimum face count" );
89              case PERCENT:
90                  return( "% smallest faces to remove" );
91              case PRESERVE_COLOR_BOUNDARIES:
92                  return( "preserve color boundaries" );
93          }
94          return null;
95      }
96  
97      public Object getOptionValue( int offset ) {
98          switch (offset) {
99              case MINFACE:
100                 return( intToOptionValue(minNumberFaces) );
101             case PERCENT:
102                 return( intToOptionValue(percentThreshold) );
103             case PRESERVE_COLOR_BOUNDARIES:
104                 return( booleanToOptionValue(preserveColorBoundaries) );
105         }
106         return "";
107     }
108 
109     public void setOptionValue( int offset, Object value ) {
110         switch (offset) {
111             case MINFACE:
112                 minNumberFaces = optionValueToInt(value);
113                 break;
114             case PERCENT:
115                 percentThreshold = optionValueToInt(value);
116                 break;
117             case PRESERVE_COLOR_BOUNDARIES:
118                 preserveColorBoundaries = optionValueToBoolean(value);
119         }
120     }
121 
122     public Object getOptionConstraints( int offset ) {
123         switch (offset) {
124             case MINFACE:
125                 return( new IntegerConstraints(10, 1000, 10 ));
126             case PERCENT:
127                 return( new IntegerConstraints(5, 100, 5 ));
128         }
129         return "";
130     }
131 }
132 
133