mr3d.io
Class TriangleBasedModelReader

java.lang.Object
  extended bymr3d.debug.ErrorHandling
      extended bymr3d.io.TriangleBasedModelReader
All Implemented Interfaces:
Debugable, FileReader

public class TriangleBasedModelReader
extends ErrorHandling
implements Debugable, FileReader

The class TriangleBasedModelReader is an implementation of mr3d.io.FileReader for reading 3D models from file. This reader reads triangle based model data according to the mr3d-standard.

The following example shows a sample file, which TriangleBasedModelReader is able to read.

     Author: Manuel Rülke
     Date: 02.09.2004
 
     Description: 
    This file is an example to demonstrate the syntax
     of the m3rd description language. This file 
     constructs a triangular pyramid from four points.

{    
    points
        ReferencePoint(25,25,50)        
        Punkt1(0,0,0)
        Punkt2(100,0,0)
        Punkt3(0,0,100)
        Punkt4(0,100,100)

    end

    edges
        Kante1(Punkt1,Punkt2)
        Kante2(Punkt2,Punkt4)
        Kante3(Punkt4,Punkt1)
        Kante4(Punkt2,Punkt3)
        Kante5(Punkt3,Punkt4)
        Kante6(Punkt4,Punkt2)
        Kante7(Punkt3,Punkt1)
        Kante8(Punkt1,Punkt4)
        Kante9(Punkt4,Punkt3)
        Kante10(Punkt1,Punkt3)
        Kante11(Punkt3,Punkt2)
        Kante12(Punkt2,Punkt1)
    end    
    
    colors
        Farbe1(16700255)    
        Farbe2(9956516)    
        Farbe3(16100878)    
        Farbe4(10100878)    
    end

    planes    
        Fläche1(Kante1, Kante2, Kante3) Farbe1
        Fläche2(Kante4, Kante5, Kante6) Farbe2
        Fläche3(Kante7, Kante8, Kante9) Farbe3
        Fläche4(Kante10, Kante11, Kante12) Farbe4
    end
} 
    footnote: This object an example for is the simplest 
     complete consistent implementation of an 3D model 
     created with the mr3d-standard.
 

Since:
MR3Dv1.0
Version:
10-2004
Author:
Manuel Ruelke

Field Summary
private  int colorsAt
          Line number of the first line of this data part.
private  DynamicStringArray data
          Contains the data read from the file.
private  boolean debugMode
          Is true when debug mode is on.
private  int edgesAt
          Line number of the first line of this data part.
private  boolean errorBreak
          Is true when an error occured.
private  java.lang.String fileName
          Name of the file to be read
private  java.io.InputStream inputFile
          InputStream created from the file specified in fileName.
private  DynamicIntArray linearIndices
          Contains the linear index of the first element of each line.
private  int planesAt
          Line number of the first line of this data part.
private  int pointsAt
          Line number of the first line of this data part.
 
Fields inherited from class mr3d.debug.ErrorHandling
 
Fields inherited from interface mr3d.debug.Debugable
ERROR_INT, ERROR_STRING
 
Constructor Summary
TriangleBasedModelReader(java.lang.String filename)
          Creates a new TriangleBasedModelReader.
TriangleBasedModelReader(java.lang.String filename, java.lang.String debug)
          Creates a new TriangleBasedModelReader with the possibility to set the reader into debug mode.
 
Method Summary
private  void checkData()
           
 void dispose()
          Deletes all data aquired from the file.
private  java.lang.String get(int line, int column)
          Returns the elements stored in the data vector at the specified line and column.
private  int getColorValue(java.lang.String ColorName)
          Returns the color value of the specified color id String
private  java.lang.String getEdgeEndPoint(java.lang.String edgeID)
          Returns the end point of the edge with the specified id String.
private  java.lang.String getEdgeStartPoint(java.lang.String edgeID)
          Returns the start point of the edge with the specified id String.
 int getNrOfPoints()
          Returns the number of points in the object.
 int getNrOfTriangles()
          Returns the number of triangles in the object.
 int[] getPoint(int index)
          Returns the point with the specified index.
private  int getPointIndex(java.lang.String id)
          Returns the linear index of the point within in the data vector having specified identification.
 int[][] getTriangle(int nr)
          Returns data to construct a 3D triangle from.
private  java.lang.String getTriangleID(int index)
          Returns the id of the triangle with the specified index.
 boolean hasErrors()
          Determines if an error occured in processing the object.
private  void readFile()
          Start the reading process to access the data in the file specified in filename.
private  int size()
          Returns the number of elements in the data array.
private  void stopOnError()
          Sets the errorBreak-value to true. hasErrors() returns "true" after this method is called.
 void toConsole()
          Prints the contents of the object to the Java console.
 void toConsole(java.lang.String msgString)
          Prints the contents of the object to the Java console together with an information string.
 
Methods inherited from class mr3d.debug.ErrorHandling
getErrMsg, notifyError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

colorsAt

private int colorsAt
Line number of the first line of this data part. At this line you can find the first entry for each data part such as POINTS, EDGES, PLANES and COLORS.


data

private DynamicStringArray data
Contains the data read from the file.


debugMode

private boolean debugMode
Is true when debug mode is on. Additional messages will be displayed on the console.


edgesAt

private int edgesAt
Line number of the first line of this data part. At this line you can find the first entry for each data part such as POINTS, EDGES, PLANES and COLORS.


errorBreak

private boolean errorBreak
Is true when an error occured.


fileName

private java.lang.String fileName
Name of the file to be read


inputFile

private java.io.InputStream inputFile
InputStream created from the file specified in fileName.


linearIndices

private DynamicIntArray linearIndices
Contains the linear index of the first element of each line. The index is the positon in the data-vector.


planesAt

private int planesAt
Line number of the first line of this data part. At this line you can find the first entry for each data part such as POINTS, EDGES, PLANES and COLORS.


pointsAt

private int pointsAt
Line number of the first line of this data part. At this line you can find the first entry for each data part such as POINTS, EDGES, PLANES and COLORS.

Constructor Detail

TriangleBasedModelReader

public TriangleBasedModelReader(java.lang.String filename)
                         throws java.io.IOException
Creates a new TriangleBasedModelReader.

Parameters:
filename - name of the file that should be loaded

TriangleBasedModelReader

public TriangleBasedModelReader(java.lang.String filename,
                                java.lang.String debug)
                         throws java.io.IOException
Creates a new TriangleBasedModelReader with the possibility to set the reader into debug mode.

Parameters:
filename - name of the file that should be loaded
debug - if this String equals "debug" the reader will be set into debugging mode.
Method Detail

checkData

private void checkData()

dispose

public void dispose()
Deletes all data aquired from the file.

Specified by:
dispose in interface FileReader

get

private java.lang.String get(int line,
                             int column)
Returns the elements stored in the data vector at the specified line and column.

Parameters:
line - line number of the desired entry
column - column of the the desired entry
Returns:
value stored at the specified position

getColorValue

private int getColorValue(java.lang.String ColorName)
Returns the color value of the specified color id String


getEdgeEndPoint

private java.lang.String getEdgeEndPoint(java.lang.String edgeID)
Returns the end point of the edge with the specified id String.

Parameters:
edgeID - id of the edge as specified in the mr3d-file
Returns:
id String of the end point

getEdgeStartPoint

private java.lang.String getEdgeStartPoint(java.lang.String edgeID)
Returns the start point of the edge with the specified id String.

Parameters:
edgeID - id of the edge as specified in the mr3d-file
Returns:
id String of the start point

getNrOfPoints

public int getNrOfPoints()
Returns the number of points in the object.

Specified by:
getNrOfPoints in interface FileReader

getNrOfTriangles

public int getNrOfTriangles()
Returns the number of triangles in the object.

Specified by:
getNrOfTriangles in interface FileReader

getPoint

public int[] getPoint(int index)
Returns the point with the specified index.

Specified by:
getPoint in interface FileReader
Parameters:
index - index of the point

getPointIndex

private int getPointIndex(java.lang.String id)
Returns the linear index of the point within in the data vector having specified identification. The method returns ERR_INT when no point is found with this id.

Parameters:
id - ID-string of the point

getTriangle

public int[][] getTriangle(int nr)
Description copied from interface: FileReader
Returns data to construct a 3D triangle from. Indexing starts with 0, which is the triangle closest to the beginning of the file.

The array is constructed as follows:

[0][0] = id of start point of edge 1
[0][1] = id of end point of edge 1
[1][0] = id of start point of edge 2
[1][1] = id of end point of edge 2
[2][0] = id of start point of edge 3
[2][1] = id of end point of edge 3
[3][0] = triangle color

Specified by:
getTriangle in interface FileReader
Parameters:
nr - number of the triangle in the file
Returns:
array of int containg the point array indices of the start and end points of the three edges of a triangle.

getTriangleID

private java.lang.String getTriangleID(int index)
Returns the id of the triangle with the specified index. Indexing starts at zero with the first triangle to the top of the file.

Parameters:
index - index of the traingle

hasErrors

public boolean hasErrors()
Determines if an error occured in processing the object.

Specified by:
hasErrors in interface FileReader
Returns:
true if an error has occured, false if everything is ok

readFile

private void readFile()
               throws java.io.IOException
Start the reading process to access the data in the file specified in filename.

Throws:
java.io.IOException

size

private int size()
Returns the number of elements in the data array.


stopOnError

private void stopOnError()
Sets the errorBreak-value to true. hasErrors() returns "true" after this method is called.


toConsole

public void toConsole()
Description copied from interface: Debugable
Prints the contents of the object to the Java console. How the information will be displayed depends on what data the object contains. Depending on structure and contents every implementation of this function produces a different result on the console.

Specified by:
toConsole in interface Debugable

toConsole

public void toConsole(java.lang.String msgString)
Description copied from interface: Debugable
Prints the contents of the object to the Java console together with an information string. How the information will be displayed depends on what data the object contains. Depending on structure and contents every implementation of this function produces a different result on the console.

Specified by:
toConsole in interface Debugable