j3d.org Code

org.j3d.loaders.stl
Class STLFileReader

java.lang.Object
  extended byorg.j3d.loaders.stl.STLFileReader

public class STLFileReader
extends java.lang.Object

Class to read STL (Stereolithography) files.

Usage: First create a STLFileReader object. To obtain the number of objects, name of objects and number of facets for each object use the appropriate methods. Then use the getNextFacet(double[], double[][]) method repetitively to obtain the geometric data for each facet. Call close() to free the resources.

In case that the file uses the binary STL format, no check can be done to assure that the file is in STL format. A wrong format will only be recognized if an invalid amount of data is contained in the file.

Version:
$Revision: 1.2 $
Author:
Dipl. Ing. Paul Szawlowski - University of Vienna, Dept. of Medical Computer Sciences

Constructor Summary
STLFileReader(java.io.File file)
          Creates a STLFileReader object to read a STL file from a file.
STLFileReader(java.io.File file, java.awt.Component parentComponent)
          Creates a STLFileReader object to read a STL file from a file.
STLFileReader(java.lang.String fileName)
          Creates a STLFileReader object to read a STL file from a file.
STLFileReader(java.lang.String fileName, java.awt.Component parentComponent)
          Creates a STLFileReader object to read a STL file from a file.
STLFileReader(java.net.URL url)
          Creates a STLFileReader object to read a STL file from an URL.
STLFileReader(java.net.URL url, java.awt.Component parentComponent)
          Creates a STLFileReader object to read a STL file from an URL.
 
Method Summary
 void close()
          Releases used resources.
 boolean getNextFacet(double[] normal, double[][] vertices)
          Returns the data for a facet.
 int[] getNumOfFacets()
          Get number of facets per object.
 int getNumOfObjects()
          Get number of objects in file.
 java.lang.String[] getObjectNames()
          Get array with object names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

STLFileReader

public STLFileReader(java.io.File file)
              throws java.io.InterruptedIOException,
                     java.io.IOException,
                     java.io.FileNotFoundException
Creates a STLFileReader object to read a STL file from a file. The data may be in ASCII or binary format.

Parameters:
file - File object of STL file to read.

STLFileReader

public STLFileReader(java.lang.String fileName)
              throws java.io.InterruptedIOException,
                     java.io.IOException,
                     java.io.FileNotFoundException
Creates a STLFileReader object to read a STL file from a file. The data may be in ASCII or binary format.

Parameters:
fileName - Name of STL file to read.

STLFileReader

public STLFileReader(java.net.URL url)
              throws java.io.IOException,
                     java.io.FileNotFoundException
Creates a STLFileReader object to read a STL file from an URL. The data may be in ASCII or binary format.

Parameters:
url - URL of STL file to read.

STLFileReader

public STLFileReader(java.net.URL url,
                     java.awt.Component parentComponent)
              throws java.io.InterruptedIOException,
                     java.io.IOException,
                     java.io.FileNotFoundException
Creates a STLFileReader object to read a STL file from an URL. The data may be in ASCII or binary format. A progress monitor will show the progress during reading.

Parameters:
url - URL of STL file to read.
parentComponent - Parent Component of progress monitor. Use null if there is no parent.

STLFileReader

public STLFileReader(java.io.File file,
                     java.awt.Component parentComponent)
              throws java.io.InterruptedIOException,
                     java.io.IOException,
                     java.io.FileNotFoundException
Creates a STLFileReader object to read a STL file from a file. The data may be in ASCII or binary format. A progress monitor will show the progress during reading.

Parameters:
file - File object of STL file to read.
parentComponent - Parent Component of progress monitor. Use null if there is no parent.

STLFileReader

public STLFileReader(java.lang.String fileName,
                     java.awt.Component parentComponent)
              throws java.io.InterruptedIOException,
                     java.io.IOException,
                     java.io.FileNotFoundException
Creates a STLFileReader object to read a STL file from a file. The data may be in ASCII or binary format. A progress monitor will show the progress during reading.

Parameters:
fileName - Name of STL file to read.
parentComponent - Parent Component of progress monitor. Use null if there is no parent.
Method Detail

getNextFacet

public boolean getNextFacet(double[] normal,
                            double[][] vertices)
                     throws java.io.InterruptedIOException,
                            java.io.IOException
Returns the data for a facet. The orientation of the facets (which way is out and which way is in) is specified redundantly. First, the direction of the normal is outward. Second, the vertices are listed in counterclockwise order when looking at the object from the outside (right-hand rule).

Call consecutively until all data is read.

Parameters:
normal - array of size 3 to store the normal vector.
vertices - array of size 3x3 to store the vertex data.
  • first index: vertex
  • second index:
    • 0: x coordinate
    • 1: y coordinate
    • 2: z coordinate
Returns:
True if facet data is contained in normal and vertices. False if end of file is reached. Further calls of this method after the end of file is reached will lead to an IOException.
Throws:
java.io.InterruptedIOException
java.io.IOException

getObjectNames

public java.lang.String[] getObjectNames()
Get array with object names.

Returns:
Array of strings with names of objects. Size of array = number of objects in file. If name is not contained then the appropriate string is null.

getNumOfFacets

public int[] getNumOfFacets()
Get number of facets per object.

Returns:
Array with the number of facets per object. Size of array = number of objects in file.

getNumOfObjects

public int getNumOfObjects()
Get number of objects in file.


close

public void close()
           throws java.io.IOException
Releases used resources. Must be called after finishing reading.

Throws:
java.io.IOException

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org