Package com.irurueta.geometry.io
Class LoaderSTL.LoaderIteratorSTL
java.lang.Object
com.irurueta.geometry.io.LoaderSTL.LoaderIteratorSTL
- All Implemented Interfaces:
LoaderIterator
- Enclosing class:
- LoaderSTL
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
FieldsModifier and TypeFieldDescriptionstatic final StringConstant defining end of 3D file.static final StringConstant defining end of 3D face (i.e. triangle or polygon).static final StringConstant defining end of loop containing vertices.static final StringConstant defining a face (i.e. triangle or polygon).static final StringConstant defining a loop that will contain vertices.static final StringConstant defining a normal.static final StringConstant defining grouping levels.static final StringConstant defining beginning of 3D file.static final StringConstant defining a vertex.static final intHeader size for binary format.private float[]Array containing vertices coordinates to be added to current chunk of data.private floatX coordinate of the latest point that has been read.private floatY coordinate of the latest point that has been read.private floatZ coordinate of the latest point that has been read.private longIndicates current triangle being read (when available).private booleanIndicates when end of file has been reached.private intNumber of indices stored in chunk.private int[]Array containing indices to be added to current chunk of data.private intSize of indices stored in chunk.private booleanIndicates if file is in ASCII format or in binary format.private LoaderIteratorListenerReference to the listener of this loader iterator.private final LoaderSTLReference to loader loading STL file.private floatX coordinate of the maximum point forming the bounding box in a chunk of data.private floatY coordinate of the maximum point forming the bounding box in a chunk of data.private floatZ coordinate of the maximum point forming the bounding box in a chunk of data.private floatX coordinate of the minimum point forming the bounding box in a chunk of data.private floatY coordinate of the minimum point forming the bounding box in a chunk of data.private floatZ 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 longIndicates number of triangles that are contained in the file (when available).private longContains number of vertices contained in the file.private floatX coordinate of the latest point normal that has been read.private floatY coordinate of the latest point normal that has been read.private floatZ coordinate of the latest point normal that has been read.private StringContains name for the 3D object.static final intConstant defining number of vertices in a triangle.private intNumber of vertices stored in chunk. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidAdds data of last vertex being loaded to current chunk of data as a new vertex.longGets number of vertices contained in the file.Returns name for the 3D object.booleanhasNext()Indicates if there is another chunk of data to be loaded.private voidIncreases size of arrays of data.private voidInitializes arrays forming current chunk of data.next()Loads and returns next chunk of data, if available.private StringInternal method to read a word from ASCII file.voidsetListener(LoaderIteratorListener listener) Method to set listener of this loader iterator.private voidsetUp()Setups loader iterator.private voidTrims arrays of data to reduce size of arrays to fit chunk data.
-
Field Details
-
loader
Reference to loader loading STL file. -
coordX
private float coordXX coordinate of the latest point that has been read. -
coordY
private float coordYY coordinate of the latest point that has been read. -
coordZ
private float coordZZ coordinate of the latest point that has been read. -
nX
private float nXX coordinate of the latest point normal that has been read. -
nY
private float nYY coordinate of the latest point normal that has been read. -
nZ
private float nZZ coordinate of the latest point normal that has been read. -
minX
private float minXX 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 minYY 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 minZZ 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 maxXX 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 maxYY 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 maxZZ 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
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[] coordsInChunkArrayArray containing vertices coordinates to be added to current chunk of data. -
normalsInChunkArray
private float[] normalsInChunkArrayArray containing normal coordinates to be added to current chunk of data. -
indicesInChunkArray
private int[] indicesInChunkArrayArray 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 verticesInChunkNumber of vertices stored in chunk. -
indicesInChunk
private int indicesInChunkNumber of indices stored in chunk. -
indicesInChunkSize
private int indicesInChunkSizeSize of indices stored in chunk. -
isAscii
private boolean isAsciiIndicates if file is in ASCII format or in binary format. -
numberOfTriangles
private long numberOfTrianglesIndicates number of triangles that are contained in the file (when available). -
currentTriangle
private long currentTriangleIndicates current triangle being read (when available). -
numberOfVertices
private long numberOfVerticesContains number of vertices contained in the file. -
endOfFileReached
private boolean endOfFileReachedIndicates when end of file has been reached. -
solidName
Contains name for the 3D object. -
ASCII_START
Constant defining beginning of 3D file.- See Also:
-
ASCII_END
Constant defining end of 3D file.- See Also:
-
ASCII_FACET
Constant defining a face (i.e. triangle or polygon).- See Also:
-
ASCII_NORMAL
Constant defining a normal.- See Also:
-
ASCII_OUTER
Constant defining grouping levels.- See Also:
-
ASCII_LOOP
Constant defining a loop that will contain vertices.- See Also:
-
ASCII_VERTEX
Constant defining a vertex.- See Also:
-
ASCII_END_LOOP
Constant defining end of loop containing vertices.- See Also:
-
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_SIZEHeader size for binary format.- See Also:
-
VERTICES_PER_TRIANGLE
public static final int VERTICES_PER_TRIANGLEConstant defining number of vertices in a triangle.- See Also:
-
-
Constructor Details
-
LoaderIteratorSTL
Constructor.- Parameters:
loader- reference to loader loading binary file.- Throws:
IOException- if an I/O error occurs.LoaderException- if file data is corrupt or cannot be understood.
-
-
Method Details
-
setListener
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:
hasNextin interfaceLoaderIterator- Returns:
- true if there is another chunk of data, false otherwise.
-
next
Loads and returns next chunk of data, if available.- Specified by:
nextin interfaceLoaderIterator- 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
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
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
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.
-