Class LoaderSTL.LoaderIteratorSTL

java.lang.Object
com.irurueta.geometry.io.LoaderSTL.LoaderIteratorSTL
All Implemented Interfaces:
LoaderIterator
Enclosing class:
LoaderSTL

private class LoaderSTL.LoaderIteratorSTL extends Object implements LoaderIterator
Loader iterator in charge of loading file data in small chunks. Usually data is divided in chunks small enough that can be directly loaded by graphical layers such as OpenGL (which has a limit of 65535 indices when using Vertex Buffer Objects, which increase graphical performance).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Constant defining end of 3D file.
    static final String
    Constant defining end of 3D face (i.e. triangle or polygon).
    static final String
    Constant defining end of loop containing vertices.
    static final String
    Constant defining a face (i.e. triangle or polygon).
    static final String
    Constant defining a loop that will contain vertices.
    static final String
    Constant defining a normal.
    static final String
    Constant defining grouping levels.
    static final String
    Constant defining beginning of 3D file.
    static final String
    Constant defining a vertex.
    static final int
    Header size for binary format.
    private float[]
    Array containing vertices coordinates to be added to current chunk of data.
    private float
    X coordinate of the latest point that has been read.
    private float
    Y coordinate of the latest point that has been read.
    private float
    Z coordinate of the latest point that has been read.
    private long
    Indicates current triangle being read (when available).
    private boolean
    Indicates when end of file has been reached.
    private int
    Number of indices stored in chunk.
    private int[]
    Array containing indices to be added to current chunk of data.
    private int
    Size of indices stored in chunk.
    private boolean
    Indicates if file is in ASCII format or in binary format.
    Reference to the listener of this loader iterator.
    private final LoaderSTL
    Reference to loader loading STL file.
    private float
    X coordinate of the maximum point forming the bounding box in a chunk of data.
    private float
    Y coordinate of the maximum point forming the bounding box in a chunk of data.
    private float
    Z coordinate of the maximum point forming the bounding box in a chunk of data.
    private float
    X coordinate of the minimum point forming the bounding box in a chunk of data.
    private float
    Y coordinate of the minimum point forming the bounding box in a chunk of data.
    private float
    Z coordinate of the minimum point forming the bounding box in a chunk of data.
    private float[]
    Array containing normal coordinates to be added to current chunk of data.
    private long
    Indicates number of triangles that are contained in the file (when available).
    private long
    Contains number of vertices contained in the file.
    private float
    X coordinate of the latest point normal that has been read.
    private float
    Y coordinate of the latest point normal that has been read.
    private float
    Z coordinate of the latest point normal that has been read.
    private String
    Contains name for the 3D object.
    static final int
    Constant defining number of vertices in a triangle.
    private int
    Number of vertices stored in chunk.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Adds data of last vertex being loaded to current chunk of data as a new vertex.
    long
    Gets number of vertices contained in the file.
    Returns name for the 3D object.
    boolean
    Indicates if there is another chunk of data to be loaded.
    private void
    Increases size of arrays of data.
    private void
    Initializes arrays forming current chunk of data.
    Loads and returns next chunk of data, if available.
    private String
    Internal method to read a word from ASCII file.
    void
    Method to set listener of this loader iterator.
    private void
    Setups loader iterator.
    private void
    Trims arrays of data to reduce size of arrays to fit chunk data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • loader

      private final LoaderSTL loader
      Reference to loader loading STL file.
    • coordX

      private float coordX
      X coordinate of the latest point that has been read.
    • coordY

      private float coordY
      Y coordinate of the latest point that has been read.
    • coordZ

      private float coordZ
      Z coordinate of the latest point that has been read.
    • nX

      private float nX
      X coordinate of the latest point normal that has been read.
    • nY

      private float nY
      Y coordinate of the latest point normal that has been read.
    • nZ

      private float nZ
      Z coordinate of the latest point normal that has been read.
    • minX

      private float minX
      X coordinate of the minimum point forming the bounding box in a chunk of data. This value will be updated while the chunk is being filled.
    • minY

      private float minY
      Y coordinate of the minimum point forming the bounding box in a chunk of data. This value will be updated while the chunk is being filled.
    • minZ

      private float minZ
      Z coordinate of the minimum point forming the bounding box in a chunk of data. This value will be updated while the chunk is being filled.
    • maxX

      private float maxX
      X coordinate of the maximum point forming the bounding box in a chunk of data. This value will be updated while the chunk is being filled.
    • maxY

      private float maxY
      Y coordinate of the maximum point forming the bounding box in a chunk of data. This value will be updated while the chunk is being filled.
    • maxZ

      private float maxZ
      Z coordinate of the maximum point forming the bounding box in a chunk of data. This value will be updated while the chunk is being filled.
    • listener

      private LoaderIteratorListener listener
      Reference to the listener of this loader iterator. This listener will be notified when the loading process finishes so that resources can be freed.
    • coordsInChunkArray

      private float[] coordsInChunkArray
      Array containing vertices coordinates to be added to current chunk of data.
    • normalsInChunkArray

      private float[] normalsInChunkArray
      Array containing normal coordinates to be added to current chunk of data.
    • indicesInChunkArray

      private int[] indicesInChunkArray
      Array containing indices to be added to current chunk of data. Notice that these indices are not the original indices appearing in the file. Instead, they are indices referring to data in current chunk, accounting for duplicate points, etc. This way, indices in a chunk can be directly used to draw the chunk of data by the graphical layer.
    • verticesInChunk

      private int verticesInChunk
      Number of vertices stored in chunk.
    • indicesInChunk

      private int indicesInChunk
      Number of indices stored in chunk.
    • indicesInChunkSize

      private int indicesInChunkSize
      Size of indices stored in chunk.
    • isAscii

      private boolean isAscii
      Indicates if file is in ASCII format or in binary format.
    • numberOfTriangles

      private long numberOfTriangles
      Indicates number of triangles that are contained in the file (when available).
    • currentTriangle

      private long currentTriangle
      Indicates current triangle being read (when available).
    • numberOfVertices

      private long numberOfVertices
      Contains number of vertices contained in the file.
    • endOfFileReached

      private boolean endOfFileReached
      Indicates when end of file has been reached.
    • solidName

      private String solidName
      Contains name for the 3D object.
    • ASCII_START

      public static final String ASCII_START
      Constant defining beginning of 3D file.
      See Also:
    • ASCII_END

      public static final String ASCII_END
      Constant defining end of 3D file.
      See Also:
    • ASCII_FACET

      public static final String ASCII_FACET
      Constant defining a face (i.e. triangle or polygon).
      See Also:
    • ASCII_NORMAL

      public static final String ASCII_NORMAL
      Constant defining a normal.
      See Also:
    • ASCII_OUTER

      public static final String ASCII_OUTER
      Constant defining grouping levels.
      See Also:
    • ASCII_LOOP

      public static final String ASCII_LOOP
      Constant defining a loop that will contain vertices.
      See Also:
    • ASCII_VERTEX

      public static final String ASCII_VERTEX
      Constant defining a vertex.
      See Also:
    • ASCII_END_LOOP

      public static final String ASCII_END_LOOP
      Constant defining end of loop containing vertices.
      See Also:
    • ASCII_END_FACET

      public static final String ASCII_END_FACET
      Constant defining end of 3D face (i.e. triangle or polygon).
      See Also:
    • BINARY_HEADER_SIZE

      public static final int BINARY_HEADER_SIZE
      Header size for binary format.
      See Also:
    • VERTICES_PER_TRIANGLE

      public static final int VERTICES_PER_TRIANGLE
      Constant defining number of vertices in a triangle.
      See Also:
  • Constructor Details

  • Method Details

    • setListener

      public void setListener(LoaderIteratorListener listener)
      Method to set listener of this loader iterator. This listener will be notified when the loading process finishes.
      Parameters:
      listener - listener of this loader iterator.
    • hasNext

      public boolean hasNext()
      Indicates if there is another chunk of data to be loaded.
      Specified by:
      hasNext in interface LoaderIterator
      Returns:
      true if there is another chunk of data, false otherwise.
    • next

      Loads and returns next chunk of data, if available.
      Specified by:
      next in interface LoaderIterator
      Returns:
      next chunk of data.
      Throws:
      NotAvailableException - thrown if no more data is available.
      LoaderException - if file data is corrupt or cannot be understood.
      IOException - if an I/O error occurs.
    • getSolidName

      public String getSolidName()
      Returns name for the 3D object.
      Returns:
      name for the 3D object.
    • getNumberOfVertices

      public long getNumberOfVertices()
      Gets number of vertices contained in the file.
      Returns:
      number of vertices contained in the file.
    • readNonEmptyWord

      private String readNonEmptyWord() throws IOException
      Internal method to read a word from ASCII file.
      Returns:
      next word that has been read.
      Throws:
      IOException - if an I/O error occurs.
    • initChunkArrays

      private void initChunkArrays()
      Initializes arrays forming current chunk of data.
    • addNewVertexDataToChunk

      private void addNewVertexDataToChunk()
      Adds data of last vertex being loaded to current chunk of data as a new vertex.
    • increaseIndicesArraySize

      private void increaseIndicesArraySize()
      Increases size of arrays of data. This method is called when needed.
    • trimArrays

      private void trimArrays()
      Trims arrays of data to reduce size of arrays to fit chunk data. This method is loaded just before copying data to chunk being returned.
    • setUp

      private void setUp() throws IOException, LoaderException
      Setups loader iterator. This method is called when constructing this iterator.
      Throws:
      IOException - if an I/O error occurs.
      LoaderException - if data is corrupted or cannot be understood.