net.von_gagern.martin.confoo.mesh
Class ObjFormat

java.lang.Object
  extended by net.von_gagern.martin.confoo.mesh.ObjFormat
All Implemented Interfaces:
Iterable<CorneredTriangle<Integer>>, CombinatoricMesh<Integer>, LocatedMesh<Integer>, MetricMesh<Integer>

public class ObjFormat
extends Object
implements LocatedMesh<Integer>, Iterable<CorneredTriangle<Integer>>

Bare bones interoperability with obj file format.

This class facililiates interaction with the Object File Format introduced by Wavefront Technologies for the description of 3D objects, including meshes.

The implementation provides both read and write access to said format, but only considers meshes at the moment. Other lines will be disregarded on input and not generated on output.

Since:
1.0
Author:
Martin von Gagern
See Also:
Obj Specification

Constructor Summary
ObjFormat(BufferedReader in)
          Construct from object file text.
ObjFormat(InputStream in)
          Construct from object file input stream.
ObjFormat(LocatedMesh<Integer> mesh)
          Construct from integer mesh.
ObjFormat(LocatedMesh<V> mesh, Map<V,Integer> vertexMap)
          Construct from arbitrary located mesh.
ObjFormat(Reader in)
          Construct from object file text.
 
Method Summary
 double edgeLength(Integer v1, Integer v2)
          Determine edge length.
 double getX(Integer v)
          Get x coordinate of vertex.
 double getY(Integer v)
          Get y coordinate of vertex.
 double getZ(Integer v)
          Get z coordinate of vertex.
 MeshIterator<Integer> iterator()
          Get iterator over all triangles.
 void write(Appendable out)
          Write out object file text.
 void write(OutputStream out)
          Write out object file stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjFormat

public ObjFormat(BufferedReader in)
          throws IOException
Construct from object file text.

Parameters:
in - a reader over some object file
Throws:
IOException

ObjFormat

public ObjFormat(Reader in)
          throws IOException
Construct from object file text.

Parameters:
in - a reader over some object file
Throws:
IOException

ObjFormat

public ObjFormat(InputStream in)
          throws IOException
Construct from object file input stream. Input will be decoded using latin1 encoding, as this will avoid encoding related errors and texts elements will be disregarded in any case.

Parameters:
in - an input stream over some object file
Throws:
IOException

ObjFormat

public ObjFormat(LocatedMesh<V> mesh,
                 Map<V,Integer> vertexMap)
Construct from arbitrary located mesh.

A map can be provided to map vertices to indices. It must assign indices continuously, starting from 1. Vertices not present in the map will be added to the map and cann therefore be obtained from the map after this function returns. If the caller is not interested in this information, he may pass null as the vertexMap.

Parameters:
mesh - the mesh to construct the object file from
vertexMap - the vertex map as described above or null

ObjFormat

public ObjFormat(LocatedMesh<Integer> mesh)
Construct from integer mesh.

The integers identifying vertices in the undrlying mesh must start at 1 and form a continuous range.

Parameters:
mesh - the mesh to construct the object file from
Method Detail

write

public void write(Appendable out)
           throws IOException
Write out object file text.

Parameters:
out - the appendable to which the object file will be written
Throws:
IOException - if an I/O error occurs

write

public void write(OutputStream out)
           throws IOException
Write out object file stream.

Parameters:
out - the strem to which the object file will be written
Throws:
IOException - if an I/O error occurs

edgeLength

public double edgeLength(Integer v1,
                         Integer v2)
Determine edge length.

Specified by:
edgeLength in interface MetricMesh<Integer>
Parameters:
v1 - index of first vertex
v2 - index of second vertex
Returns:
the distance as calculated from the vertex coordinates

getX

public double getX(Integer v)
Get x coordinate of vertex.

Specified by:
getX in interface LocatedMesh<Integer>
Parameters:
v - index of a vertex
Returns:
the x coordinate of that vertex

getY

public double getY(Integer v)
Get y coordinate of vertex.

Specified by:
getY in interface LocatedMesh<Integer>
Parameters:
v - index of a vertex
Returns:
the y coordinate of that vertex

getZ

public double getZ(Integer v)
Get z coordinate of vertex.

Specified by:
getZ in interface LocatedMesh<Integer>
Parameters:
v - index of a vertex
Returns:
the z coordinate of that vertex

iterator

public MeshIterator<Integer> iterator()
Get iterator over all triangles.

Specified by:
iterator in interface Iterable<CorneredTriangle<Integer>>
Specified by:
iterator in interface CombinatoricMesh<Integer>
Returns:
an iterator over all triangles in the mesh
See Also:
Iterable.iterator(), MeshIterator


Copyright © 2008 Martin von Gagern. All Rights Reserved.