Source code: com/trapezium/chisel/condensers/ResolutionMaker.java
1 /*
2 * @(#)ResolutionMaker.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.condensers;
12
13 import com.trapezium.vrml.VrmlElement;
14 import com.trapezium.vrml.Value;
15 import com.trapezium.vrml.node.Node;
16 import com.trapezium.vrml.node.DEFUSENode;
17 import com.trapezium.vrml.fields.Field;
18 import com.trapezium.vrml.fields.FieldValue;
19 import com.trapezium.vrml.fields.MFFieldValue;
20 import com.trapezium.chisel.*;
21
22 /**
23 * This adjusts coordinate resolution to a specific number of places
24 * beyond the decimal point.
25 */
26 public class ResolutionMaker extends ResolutionAdjuster {
27 int coordResolution;
28 int colorResolution;
29 int texCoordResolution;
30 int normalResolution;
31 int elevationGridResolution;
32 int extrusionResolution;
33 static final int COORD_RESOLUTION = 0;
34 static final int COLOR_RESOLUTION = 1;
35 static final int TEXCOORD_RESOLUTION = 2;
36 static final int NORMAL_RESOLUTION = 3;
37 static final int ELEVATION_GRID_RESOLUTION = 4;
38 static final int EXTRUSION_RESOLUTION = 5;
39
40 public ResolutionMaker() {
41 super( "IndexedFaceSet", "Adjusting numeric resolution..." );
42 coordResolution = 3;
43 colorResolution = 3;
44 texCoordResolution = 3;
45 normalResolution = 3;
46 elevationGridResolution = 3;
47 extrusionResolution = 3;
48 addAdditionalNode( "IndexedLineSet" );
49 addAdditionalNode( "PointSet" );
50 addAdditionalNode( "ElevationGrid" );
51 addAdditionalNode( "Extrusion" );
52 }
53
54 public void attemptOptimization( Node n ) {
55 // for IndexedFaceSet
56 Field coord = n.getField( "coord" );
57 if (( coord != null ) && ( coordResolution != 0 )) {
58 replaceRange( coord.getFirstTokenOffset(), coord.getLastTokenOffset(), new Integer( coordResolution ));
59 }
60 Field color = n.getField( "color" );
61 if (( color != null ) && ( colorResolution != 0 )) {
62 replaceRange( color.getFirstTokenOffset(), color.getLastTokenOffset(), new Integer( colorResolution ));
63 }
64 Field normal = n.getField( "normal" );
65 if (( normal != null ) && ( normalResolution != 0 )) {
66 replaceRange( normal.getFirstTokenOffset(), normal.getLastTokenOffset(), new Integer( normalResolution ));
67 }
68 Field texCoord = n.getField( "texCoord" );
69 if (( texCoord != null ) && ( texCoordResolution != 0 )) {
70 replaceRange( texCoord.getFirstTokenOffset(), texCoord.getLastTokenOffset(), new Integer( texCoordResolution ));
71 }
72 // for ElevationGrid
73 Field height = n.getField( "height" );
74 if (( height != null ) && ( elevationGridResolution != 0 )) {
75 replaceRange( height.getFirstTokenOffset(), height.getLastTokenOffset(), new Integer( elevationGridResolution ));
76 }
77 // for Extrusion
78 Field crossSection = n.getField( "crossSection" );
79 if (( crossSection != null ) && ( extrusionResolution != 0 )) {
80 replaceRange( crossSection.getFirstTokenOffset(), crossSection.getLastTokenOffset(), new Integer( extrusionResolution ));
81 }
82 Field spine = n.getField( "spine" );
83 if (( spine != null ) && ( extrusionResolution != 0 )) {
84 replaceRange( spine.getFirstTokenOffset(), spine.getLastTokenOffset(), new Integer( extrusionResolution ));
85 }
86 }
87
88 /** control over 6 resolution levels */
89 public int getNumberOptions() {
90 return( 6 );
91 }
92
93 /** Get the class for an option */
94 public Class getOptionClass( int offset ) {
95 return( Integer.TYPE );
96 }
97
98 public String getOptionLabel( int offset ) {
99 switch (offset) {
100 case COORD_RESOLUTION:
101 return( "coordinate resolution" );
102 case COLOR_RESOLUTION:
103 return( "color resolution" );
104 case NORMAL_RESOLUTION:
105 return( "normal resolution" );
106 case TEXCOORD_RESOLUTION:
107 return( "texture coordinate resolution" );
108 case ELEVATION_GRID_RESOLUTION:
109 return( "elevation grid resolution" );
110 case EXTRUSION_RESOLUTION:
111 return( "extrusion resolution" );
112 default:
113 return( null );
114 }
115 }
116
117 public Object getOptionValue( int offset ) {
118 switch (offset) {
119 case COORD_RESOLUTION:
120 return( intToOptionValue( coordResolution ));
121 case COLOR_RESOLUTION:
122 return( intToOptionValue( colorResolution ));
123 case NORMAL_RESOLUTION:
124 return( intToOptionValue( normalResolution ));
125 case TEXCOORD_RESOLUTION:
126 return( intToOptionValue( texCoordResolution ));
127 case ELEVATION_GRID_RESOLUTION:
128 return( intToOptionValue( elevationGridResolution ));
129 case EXTRUSION_RESOLUTION:
130 return( intToOptionValue( extrusionResolution ));
131 }
132 return "";
133 }
134
135 public void setOptionValue( int offset, Object value ) {
136 switch (offset) {
137 case COORD_RESOLUTION:
138 coordResolution = optionValueToInt( value );
139 break;
140 case COLOR_RESOLUTION:
141 colorResolution = optionValueToInt( value );
142 break;
143 case NORMAL_RESOLUTION:
144 normalResolution = optionValueToInt( value );
145 break;
146 case TEXCOORD_RESOLUTION:
147 texCoordResolution = optionValueToInt( value );
148 break;
149 case ELEVATION_GRID_RESOLUTION:
150 elevationGridResolution = optionValueToInt( value );
151 break;
152 case EXTRUSION_RESOLUTION:
153 extrusionResolution = optionValueToInt( value );
154 break;
155 }
156 }
157
158 public Object getOptionConstraints( int offset ) {
159 return( new IntegerConstraints(1, 10, 1 ));
160 }
161 }