Class LoaderPLY.LoaderIteratorPLY

java.lang.Object
com.irurueta.geometry.io.LoaderPLY.LoaderIteratorPLY
All Implemented Interfaces:
LoaderIterator
Enclosing class:
LoaderPLY

private class LoaderPLY.LoaderIteratorPLY extends Object implements LoaderIterator
Internal implementation of a loader iterator for PLY files.
  • Field Details

    • loader

      private final LoaderPLY loader
      Reference to a LoaderPLY.
    • listElems

      private int listElems
      Number of elements in a list property.
    • coordX

      private float coordX
      Last x vertex coordinate that was read.
    • coordY

      private float coordY
      Last y vertex coordinate that was read.
    • coordZ

      private float coordZ
      Last z vertex coordinate that was read.
    • red

      private short red
      Last red color component that was read.
    • green

      private short green
      Last green color component that was read.
    • blue

      private short blue
      Last blue color component that was read.
    • alpha

      private short alpha
      Last alpha color component that was read.
    • nX

      private float nX
      Last normal x component that was red.
    • nY

      private float nY
      Last normal y component that was read.
    • nZ

      private float nZ
      Last normal z component that was read.
    • index

      private long index
      Last vertex index that was read.
    • minX

      private float minX
      Minimum x coordinate of all vertices that have been read so far in current chunk of data.
    • minY

      private float minY
      Minimum y coordinate of all vertices that have been read so far in current chunk of data.
    • minZ

      private float minZ
      Minimum z coordinate of all vertices that have been read so far in current chunk of data.
    • maxX

      private float maxX
      Maximum x coordinate of all vertices that have been read so far in current chunk of data.
    • maxY

      private float maxY
      Maximum y coordinate of all vertices that have been read so far in current chunk of data.
    • maxZ

      private float maxZ
      Maximum z coordinate of all vertices that have been read so far in current chunk of data.
    • verticesAvailable

      private boolean verticesAvailable
      Indicates whether file contains vertices.
    • colorsAvailable

      private boolean colorsAvailable
      Indicates whether file contains colors.
    • indicesAvailable

      private boolean indicesAvailable
      Indicates whether file contains vertex indices.
    • normalsAvailable

      private boolean normalsAvailable
      Indicates whether file contains normals.
    • colorComponents

      private int colorComponents
      Indicates number of color components of vertices.
    • endHeaderStreamPosition

      private long endHeaderStreamPosition
      Stores position where header of file finishes.
    • numberOfVertices

      private long numberOfVertices
      Number of vertices contained in the file.
    • numberOfFaces

      private long numberOfFaces
      Number of faces (triangles or polygons) contained in the file.
    • firstVertexStreamPosition

      private long firstVertexStreamPosition
      Stores position where first vertex is located.
    • firstVertexStreamPositionAvailable

      private boolean firstVertexStreamPositionAvailable
      Indicates whether first vertex position has already been read and is available.
    • vertexDataSize

      private long vertexDataSize
      Indicates size of vertex data.
    • firstFaceStreamPosition

      private long firstFaceStreamPosition
      Stores position where first vertex index containing a triangle or polygon is located.
    • firstFaceStreamPositionAvailable

      private boolean firstFaceStreamPositionAvailable
      Indicates whether first vertex index position has already been read and is available.
    • currentStreamPosition

      private long currentStreamPosition
      Stores current position in file stream.
    • totalInstances

      private long totalInstances
      Number of instances of a given element in the header of the file (i.e. number of vertices or faces).
    • vertexElement

      private ElementPLY vertexElement
      A header element that contains vertex properties.
    • faceElement

      private ElementPLY faceElement
      A header element that contains face (triangles/polygons) properties.
    • currentFace

      private long currentFace
      Current triangle/polygon being read from all faces available in the file.
    • fetchVertexListener

      private VertexFetcherListener fetchVertexListener
      Listener to fetch a vertex position in the stream of data based on its vertex index. There are implementations for binary and text (ascii) fetchers.
    • listener

      private LoaderIteratorListener listener
      Listener of this iterator that notifies the loader when the iterator has finished loading the file, so that the loader becomes unlocked again.
    • coordsInChunkArray

      private float[] coordsInChunkArray
      Array containing vertex coordinates in current chunk of data. Data is stored sequentially as x1, y1, z1, x2, y2, z2, etc.
    • colorsInChunkArray

      private short[] colorsInChunkArray
      Array containing vertex colors in current chunk of data. Data is stored sequentially depending on the number of color components. For instance, for RGB this would be: r1, g1, b1, r2, g2, b2, etc.
    • indicesInChunkArray

      private int[] indicesInChunkArray
      Indices of vertices in current chunk. Indices are stored sequentially in sets of 3 forming triangles like this: t1a, t1b, t1c, t2a, t2b, t2c, etc.
    • originalIndicesInChunkArray

      private long[] originalIndicesInChunkArray
      Indices of vertices in file. Original indices might differ of indices numeration in current chunk because for each chunk indices start again at zero. Indices are stored sequentially in sets of 3 forming triangles like: t1a, t1b, t1c, t2a, t2b, t2c, etc.
    • normalsInChunkArray

      private float[] normalsInChunkArray
      Normals of vertices in current chunk. Normals are stored sequentially for each vertex like this: n1x, n1y, n1z, n2x, n2y, n2z, etc.
    • verticesInChunk

      private int verticesInChunk
      Number of vertices currently stored in chunk. This is used to determine when no more vertices can be stored in a chunk and an additional chunk needs to be loaded.
    • indicesInChunk

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

      private int indicesInChunkSize
      Number of indices used as a default to initialize arrays. When the number of indices exceeds this value arrays will be resized.
    • vertexStreamPosition

      private long vertexStreamPosition
      Stores current stream position so that vertices positions can be cached.
    • indicesMap

      private final TreeMap<Long,Integer> indicesMap
      Map containing relations between original indices of the stream (key) and their corresponding index in the chunk (value).
    • verticesStreamPositionsMap

      private final TreeMap<Long,Long> verticesStreamPositionsMap
      Map relating original indices in stream (key) and stream positions (value).
  • Constructor Details

  • Method Details

    • setListener

      public void setListener(LoaderIteratorListener listener)
      Sets listener to notify when this iterator has finished loading the PLY file.
      Parameters:
      listener - listener to notify when this iterator has finished loading the PLY file.
    • hasNext

      public boolean hasNext()
      Indicates if there are still more chunks of data to be read on this PLY file.
      Specified by:
      hasNext in interface LoaderIterator
      Returns:
      True if there are more chunks of data, false otherwise.
    • next

      Reads next chunk of data from PLY file.
      Specified by:
      next in interface LoaderIterator
      Returns:
      A chunk of data containing vertex coordinates, colors, vertex normals, textures, etc.
      Throws:
      NotAvailableException - Raised if no more chunks are available.
      LoaderException - Raised if file is corrupted and cannot be loaded.
      IOException - Raised if an I/O error occurs.
    • buildTriangulatedIndices

      private long[] buildTriangulatedIndices(List<com.irurueta.geometry.Point3D> polygonVertices, long[] plyIndices) throws com.irurueta.geometry.TriangulatorException
      Triangulates provided polygon having vertices corresponding to provided indices and returns an array of indices corresponding to the triangles forming the polygon.
      Parameters:
      polygonVertices - vertices forming a polygon to be triangulated.
      plyIndices - indices corresponding to provided polygon.
      Returns:
      array of indices corresponding to the triangles forming the polygon.
      Throws:
      com.irurueta.geometry.TriangulatorException - if triangulation fails because polygon is degenerate or vertices contains invalid values such as NaN or infinity.
    • initChunkArrays

      private void initChunkArrays()
      Initializes arrays where chunk data will be stored.
    • searchIndexInChunk

      private int searchIndexInChunk(long originalIndex)
      Searches corresponding index in chunk for provided stream vertex index.
      Parameters:
      originalIndex - Index in original stream of data.
      Returns:
      Vertex index in current chunk of data.
    • addVertexPositionToMap

      private void addVertexPositionToMap(long originalIndex, long streamPosition)
      Caches provided vertex index to relate it to given stream position where vertex data can be found. This method only has effect for ASCII PLY files.
      Parameters:
      originalIndex - Vertex index in original stream of data.
      streamPosition - Stream position where vertex is found.
    • addNewVertexDataToChunk

      private void addNewVertexDataToChunk()
      Adds data of last vertex that has been read to the arrays of current chunk of data.
    • addExistingVertexToChunk

      private void addExistingVertexToChunk(int existingIndex)
      Adds provided vertex index into chunk of data. This method is only called when duplicate vertices are allowed in chunks of data.
      Parameters:
      existingIndex - Index to be added into chunk.
    • increaseIndicesArraySize

      private void increaseIndicesArraySize()
      This method increases the size of arrays containing data of current chunk. This method is called when arrays get full and need to be enlarged.
    • trimArrays

      private void trimArrays()
      This method removes unnecessary data of arrays. This method is called when finishing the processing of current chunk of data.
    • setUp

      private void setUp() throws LoaderException, IOException
      Reads header data to set up listeners capable of reading stream data according to data types contained in header.
      Throws:
      LoaderException - Raised if file is corrupted (header is invalid).
      IOException - if an I/O error occurs.
    • sizeForDataType

      private long sizeForDataType(DataTypePLY type)
      Returns size in bytes for a given data type.
      Parameters:
      type - A data type.
      Returns:
      Size in bytes for a given data type.
    • findFirstVertexAndFaceStreamPosition

      private void findFirstVertexAndFaceStreamPosition() throws LoaderException, NotAvailableException, IOException
      Finds in file stream the location of the first vertex and face.
      Throws:
      LoaderException - Raised if file is corrupted and location of first vertex or face cannot be found.
      NotAvailableException - Raised if header does not contain a given element.
      IOException - if an I/O error occurs.
    • setReadValueFromStreamListener

      private void setReadValueFromStreamListener(PropertyPLY property, PLYStorageMode storageMode) throws NotAvailableException
      Sets the listener to read data from the file stream for a given PLY header property and using provided storage mode.
      Parameters:
      property - A PLY header property.
      storageMode - Storage mode of file.
      Throws:
      NotAvailableException - Raised if the listener cannot be set for provided property and storage mode.
    • setReadLengthValueFromStreamListener

      private void setReadLengthValueFromStreamListener(PropertyPLY property, PLYStorageMode storageMode) throws NotAvailableException
      Sets the listener to read length value of a property from the file stream for a given PLY header property and using provided storage mode.
      Parameters:
      property - A PLY header property.
      storageMode - Storage mode of file.
      Throws:
      NotAvailableException - Raised if the listener cannot be set for provided property and storage mode.
    • getReadFromStreamListener

      private PLYReadValueFromStreamListener getReadFromStreamListener(DataTypePLY dataType, PLYStorageMode storageMode)
      Returns a listener to read data from the file stream using provided data type (int8, uint8, int16, uint16, etc.) and storage mode (ascii, little endian or big endian).
      Parameters:
      dataType - Data type to read.
      storageMode - Storage mode of file.
      Returns:
      A listener.
    • setReadLengthValueFromBufferListener

      private void setReadLengthValueFromBufferListener(PropertyPLY property) throws NotAvailableException
      Sets the listener to read length value from temporal buffer to provided property.
      Parameters:
      property - A PLY header property.
      Throws:
      NotAvailableException - Raised if a listener cannot be set for given property because its data type is not supported.