1 import java.io.StreamTokenizer;
3 import java.io.IOException;
7 * Description: STL files loader (Supports ASCII and binary files) for Java3D
8 * Needs JDK 1.4 due to endian problems
9 * Copyright: Copyright (c) 2001
10 * Company: Universidad del Pais Vasco (UPV/EHU)
11 * @author: Carlos Pedrinaci Godoy
14 * Contact : xenicp@yahoo.es
17 * Extends StreamTokenizer
19 * Each token returned is checked in StlFile.java
20 * Format of an ASCII STL file:
22 * solid /users/vis/dru/wedge.stl
33 * endsolid /users/vis/dru/wedge.stl
35 * That Class is necessary because scientific numbers are not correctly readed by Tokenizer
36 * we must then extend that class and define another getNumber
39 public class StlFileParser extends StreamTokenizer
42 * Constructor: object creation and setup
44 * @param r The Reader instance
46 public StlFileParser(Reader r)
53 * Method that sets some params of the Tokenizer for reading the file correctly
58 eolIsSignificant(true); // The End Of Line is important
61 // All printable ascii characters
64 whitespaceChars(' ', ' ');
65 whitespaceChars('\n', '\n');
66 whitespaceChars('\r', '\r');
67 whitespaceChars('\t', '\t');
71 * Gets a number from the stream. Note that we don't recognize
72 * numbers in the tokenizer automatically because numbers might be in
73 * scientific notation, which isn't processed correctly by
74 * StreamTokenizer. The number is returned in nval.
85 throw new IOException("Expected number on line " + lineno());
86 nval = (Double.valueOf(sval)).doubleValue();
88 catch (IOException e) {
89 System.err.println(e.getMessage());
92 catch (NumberFormatException e) {
93 System.err.println(e.getMessage());
99 }// End of StlFileParser