Package com.irurueta.geometry.io
Class LoaderOBJ
java.lang.Object
com.irurueta.geometry.io.Loader
com.irurueta.geometry.io.LoaderOBJ
- All Implemented Interfaces:
Closeable,AutoCloseable
Loads an OBJ file.
If a LoaderListenerOBJ is provided, this class might also attempt to load the
associated material file if available.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classInternal listener to be notified when loading process finishes.private classLoader iterator in charge of loading file data in small chunks. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanTo allow faster file loading, it might be allowed to repeat points in a chunk.List containing comments contained in the file.private booleanDetermines if file loading should continue even if the triangulation of a polygon fails.static final booleanConstant indicating that duplicated vertices are allowed by default, which allows faster loading.static final booleanIndicates that loading should continue even if triangulation of some polygons fails.static final intMaximum number of stream positions to be cached by default.static final intConstant defining the default value of maximum number of vertices to keep in a chunk.private LoaderOBJ.LoaderIteratorOBJIterator to load OBJ file data in small chunks.Collection of materials contained in the material's file associated to an OBJ file.private longMaximum number of file stream positions to be cached.private intMaximum number of vertices allowed in a chunk.static final intMinimum allowed value for maximum number of vertices in chunk, which is one.static final intMinimum allowed number of stream positions.static final floatAmount of progress variation (1%) used to notify progress.private static final StringIdentifies materials. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.LoaderOBJ(int maxVerticesInChunk) Constructor.LoaderOBJ(int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk) Constructor.LoaderOBJ(int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk, long maxStreamPositions) Constructor.LoaderOBJ(LoaderListener listener) Constructor.LoaderOBJ(LoaderListener listener, int maxVerticesInChunk) Constructor.LoaderOBJ(LoaderListener listener, int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk) Constructor.LoaderOBJ(LoaderListener listener, int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk, long maxStreamPositions) Constructor.Constructor.Constructor.Constructor.LoaderOBJ(File f, int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk, long maxStreamPositions) Constructor.LoaderOBJ(File f, LoaderListener listener) Constructor.LoaderOBJ(File f, LoaderListener listener, int maxVerticesInChunk) Constructor.LoaderOBJ(File f, LoaderListener listener, int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk) Constructor.LoaderOBJ(File f, LoaderListener listener, int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk, long maxStreamPositions) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns boolean indicating if repeated vertices in a chunk are allowed to provide faster file loading.Returns a list of the comments contained in the file.Gets collection of materials contained in the materials file associated to an OBJ file.longReturns maximum number of file stream positions to be cached.intReturns maximum number of vertices allowed in a chunk.Returns mesh format supported by this class, which is MESH_FORMAT_OBJ.private voidinternalSetMaxStreamPositions(long maxStreamPositions) Internal method to set maximum number of file stream positions to be cached.private voidinternalSetMaxVerticesInChunk(int maxVerticesInChunk) Internal method to set maximum number of vertices allowed in a chunk.booleanReturns boolean indicating if file loading should continue even if the triangulation of a polygon fails.booleanisReady()If loader is ready to start loading a file.booleanDetermines if provided file is a valid file that can be read by this loader.load()Starts the loading process of provided file.voidsetAllowDuplicateVerticesInChunk(boolean allow) Sets boolean indicating if repeated vertices in a chunk are allowed to provide faster file loading.voidsetContinueIfTriangulationError(boolean continueIfTriangulationError) Sets boolean indicating if file loading should continue even if the triangulation of a polygon fails.voidsetMaxStreamPositions(long maxStreamPositions) Sets maximum number of file stream positions to be cached.voidsetMaxVerticesInChunk(int maxVerticesInChunk) Sets maximum number of vertices allowed in a chunk.Methods inherited from class com.irurueta.geometry.io.Loader
close, getFileSizeLimitToKeepInMemory, getListener, hasFile, isLocked, setFile, setFileSizeLimitToKeepInMemory, setListener, setLocked
-
Field Details
-
DEFAULT_MAX_VERTICES_IN_CHUNK
public static final int DEFAULT_MAX_VERTICES_IN_CHUNKConstant defining the default value of maximum number of vertices to keep in a chunk. This is 65535, which corresponds to the maximum value allowed by graphical layer such as OpenGL when working with Vertex Buffer Objects.- See Also:
-
MIN_MAX_VERTICES_IN_CHUNK
public static final int MIN_MAX_VERTICES_IN_CHUNKMinimum allowed value for maximum number of vertices in chunk, which is one.- See Also:
-
DEFAULT_ALLOW_DUPLICATE_VERTICES_IN_CHUNK
public static final boolean DEFAULT_ALLOW_DUPLICATE_VERTICES_IN_CHUNKConstant indicating that duplicated vertices are allowed by default, which allows faster loading.- See Also:
-
DEFAULT_MAX_STREAM_POSITIONS
public static final int DEFAULT_MAX_STREAM_POSITIONSMaximum number of stream positions to be cached by default.- See Also:
-
MIN_STREAM_POSITIONS
public static final int MIN_STREAM_POSITIONSMinimum allowed number of stream positions.- See Also:
-
PROGRESS_DELTA
public static final float PROGRESS_DELTAAmount of progress variation (1%) used to notify progress.- See Also:
-
DEFAULT_CONTINUE_IF_TRIANGULATION_ERROR
public static final boolean DEFAULT_CONTINUE_IF_TRIANGULATION_ERRORIndicates that loading should continue even if triangulation of some polygons fails.- See Also:
-
USEMTL
Identifies materials.- See Also:
-
loaderIterator
Iterator to load OBJ file data in small chunks. Usually data is divided in chunks that can be directly loaded by graphic layers such as OpenGL. -
maxVerticesInChunk
private int maxVerticesInChunkMaximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created. -
allowDuplicateVerticesInChunk
private boolean allowDuplicateVerticesInChunkTo allow faster file loading, it might be allowed to repeat points in a chunk. When representing data graphically, this has no visual. consequences but chunks will take up more memory. This value represents a trade-off between loading speed and memory usage. -
maxStreamPositions
private long maxStreamPositionsMaximum number of file stream positions to be cached. This class keeps a cache of positions in the file to allow faster file loading at the expense of larger memory usage. If the geometry of a file reuses a large number of points, keeping a large cache will increase the speed of loading a file, otherwise the impact of this parameter will be low. The default value will work fine for most cases. -
comments
List containing comments contained in the file. -
materials
Collection of materials contained in the material's file associated to an OBJ file. -
continueIfTriangulationError
private boolean continueIfTriangulationErrorDetermines if file loading should continue even if the triangulation of a polygon fails. The triangulation of a polygon might fail if the polygon is degenerate or has invalid numerical values such as NaN of infinity. If true, loading will continue but the result will lack the polygons that failed.
-
-
Constructor Details
-
LoaderOBJ
public LoaderOBJ()Constructor. -
LoaderOBJ
public LoaderOBJ(int maxVerticesInChunk) Constructor.- Parameters:
maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.
-
LoaderOBJ
public LoaderOBJ(int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk) Constructor.- Parameters:
maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.allowDuplicateVerticesInChunk- indicates if repeated vertices in a chunk are allowed to provide faster file loading. When representing data graphically, this has no visual consequences but chunks will take up more memory.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.
-
LoaderOBJ
public LoaderOBJ(int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk, long maxStreamPositions) Constructor.- Parameters:
maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.allowDuplicateVerticesInChunk- indicates if repeated vertices in a chunk are allowed to provide faster file loading. When representing data graphically, this has no visual consequences but chunks will take up more memory.maxStreamPositions- Maximum number of file stream positions to be cached.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.
-
LoaderOBJ
Constructor.- Parameters:
f- file to be loaded.- Throws:
IOException- if an I/O error occurs.
-
LoaderOBJ
Constructor.- Parameters:
f- file to be loaded.maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.IOException- if an I/O error occurs.
-
LoaderOBJ
public LoaderOBJ(File f, int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk) throws IOException Constructor.- Parameters:
f- file to be loaded.maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.allowDuplicateVerticesInChunk- indicates if repeated vertices in a chunk are allowed to provide faster file loading. When representing data graphically, this has no visual consequences but chunks will take up more memory.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.IOException- if an I/O error occurs.
-
LoaderOBJ
public LoaderOBJ(File f, int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk, long maxStreamPositions) throws IOException Constructor.- Parameters:
f- file to be loaded.maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.allowDuplicateVerticesInChunk- indicates if repeated vertices in a chunk are allowed to provide faster file loading. When representing data graphically, this has no visual consequences but chunks will take up more memory.maxStreamPositions- Maximum number of file stream positions to be cached.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.IOException- if an I/O error occurs.
-
LoaderOBJ
Constructor.- Parameters:
listener- listener to be notified of loading progress and when loading process starts or finishes.
-
LoaderOBJ
Constructor.- Parameters:
listener- listener to be notified of loading progress and when loading process starts or finishes.maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.
-
LoaderOBJ
public LoaderOBJ(LoaderListener listener, int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk) Constructor.- Parameters:
listener- listener to be notified of loading progress and when loading process starts or finishes.maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.allowDuplicateVerticesInChunk- indicates if repeated vertices in a chunk are allowed to provide faster file loading. When representing data graphically, this has no visual consequences but chunks will take up more memory.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.
-
LoaderOBJ
public LoaderOBJ(LoaderListener listener, int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk, long maxStreamPositions) Constructor.- Parameters:
listener- listener to be notified of loading progress and when loading process starts or finishes.maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.allowDuplicateVerticesInChunk- indicates if repeated vertices in a chunk are allowed to provide faster file loading. When representing data graphically, this has no visual consequences but chunks will take up more memory.maxStreamPositions- Maximum number of file stream positions to be cached.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.
-
LoaderOBJ
Constructor.- Parameters:
f- file to be loaded.listener- listener to be notified of loading progress and when loading process starts or finishes.- Throws:
IOException- if an I/O error occurs.
-
LoaderOBJ
Constructor.- Parameters:
f- file to be loaded.listener- listener to be notified of loading progress and when loading process starts or finishes.maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.IOException- if an I/O error occurs.
-
LoaderOBJ
public LoaderOBJ(File f, LoaderListener listener, int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk) throws IOException Constructor.- Parameters:
f- file to be loaded.listener- listener to be notified of loading progress and when loading process starts or finishes.maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.allowDuplicateVerticesInChunk- indicates if repeated vertices in a chunk are allowed to provide faster file loading. When representing data graphically, this has no visual consequences but chunks will take up more memory.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.IOException- if an I/O error occurs.
-
LoaderOBJ
public LoaderOBJ(File f, LoaderListener listener, int maxVerticesInChunk, boolean allowDuplicateVerticesInChunk, long maxStreamPositions) throws IOException Constructor.- Parameters:
f- file to be loaded.listener- listener to be notified of loading progress and when loading process starts or finishes.maxVerticesInChunk- Maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.allowDuplicateVerticesInChunk- indicates if repeated vertices in a chunk are allowed to provide faster file loading. When representing data graphically, this has no visual consequences but chunks will take up more memory.maxStreamPositions- Maximum number of file stream positions to be cached.- Throws:
IllegalArgumentException- if maximum number of vertices allowed in a chunk is lower than 1.IOException- if an I/O error occurs.
-
-
Method Details
-
getMaxVerticesInChunk
public int getMaxVerticesInChunk()Returns maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.- Returns:
- maximum number of vertices allowed in a chunk.
-
setMaxVerticesInChunk
Sets maximum number of vertices allowed in a chunk. Once this value is exceeded when loading a file, a new chunk of data is created.- Parameters:
maxVerticesInChunk- maximum allowed number of vertices to be set.- Throws:
IllegalArgumentException- if provided value is lower than 1.LockedException- if this loader is currently loading a file.
-
areDuplicateVerticesInChunkAllowed
public boolean areDuplicateVerticesInChunkAllowed()Returns boolean indicating if repeated vertices in a chunk are allowed to provide faster file loading. When representing data graphically, this has no visual consequences but chunks will take up more memory.- Returns:
- true if duplicate vertices are allowed, false otherwise.
-
setAllowDuplicateVerticesInChunk
Sets boolean indicating if repeated vertices in a chunk are allowed to provide faster file loading. When representing data graphically, this has no visual consequences but chunks will take up more memory.- Parameters:
allow- true if duplicate vertices are allowed, false otherwise.- Throws:
LockedException- if this loader is currently loading a file.
-
getMaxStreamPositions
public long getMaxStreamPositions()Returns maximum number of file stream positions to be cached. This class keeps a cache of positions in the file to allow faster file loading at the expense of larger memory usage. If the geometry of a file reuses a large number of points, keeping a large cache will increase the speed of loading a file, otherwise the impact of this parameter will be low. The default value will work fine for most cases.- Returns:
- maximum number of file stream positions to be cached.
-
setMaxStreamPositions
Sets maximum number of file stream positions to be cached. This class keeps a cache of positions in the file to allow faster file loading at the expense of larger memory usage. If the geometry of a file reuses a large number of points, keeping a large cache will increase the speed of loading a file, otherwise the impact of this parameter will be low. The default value will work fine for most cases.- Parameters:
maxStreamPositions- maximum number of file stream positions to be set.- Throws:
IllegalArgumentException- if provided value is lower than 1.LockedException- if this loader is currently loading a file.
-
isContinueIfTriangulationError
public boolean isContinueIfTriangulationError()Returns boolean indicating if file loading should continue even if the triangulation of a polygon fails. The triangulation of a polygon might fail if the polygon is degenerate or has invalid numerical values such as NaN of infinity.- Returns:
- If true, loading will continue but the result will lack the polygons that failed.
-
setContinueIfTriangulationError
public void setContinueIfTriangulationError(boolean continueIfTriangulationError) Sets boolean indicating if file loading should continue even if the triangulation of a polygon fails. The triangulation of a polygon might fail if the polygon is degenerate or has invalid numerical values such as NaN or infinity.- Parameters:
continueIfTriangulationError- if ture, loading will continue but the result will lack the polygons that failed.
-
getComments
Returns a list of the comments contained in the file.- Returns:
- list of the comments contained in the file.
-
getMaterials
Gets collection of materials contained in the materials file associated to an OBJ file.- Returns:
- collection of material.
-
isReady
public boolean isReady()If loader is ready to start loading a file. This is true once a file has been provided. -
getMeshFormat
Returns mesh format supported by this class, which is MESH_FORMAT_OBJ.- Specified by:
getMeshFormatin classLoader- Returns:
- mesh format supported by this class.
-
isValidFile
Determines if provided file is a valid file that can be read by this loader.- Specified by:
isValidFilein classLoader- Returns:
- true if file is valid, false otherwise.
- Throws:
LockedException- raised if this instance is already locked.IOException- if an I/O error occurs..
-
load
public LoaderIterator load() throws LockedException, NotReadyException, IOException, LoaderExceptionStarts the loading process of provided file. This method returns a LoaderIterator to start the iterative process to load a file in small chunks of data.- Specified by:
loadin classLoader- Returns:
- a loader iterator to read the file in a step-by-step process.
- Throws:
LockedException- raised if this instance is already locked.NotReadyException- raised if this instance is not yet ready.IOException- if an I/O error occurs.LoaderException- if file is corrupted or cannot be interpreted.
-
internalSetMaxVerticesInChunk
private void internalSetMaxVerticesInChunk(int maxVerticesInChunk) Internal method to set maximum number of vertices allowed in a chunk. This method is reused both in the constructor and in the setter of maximum number of vertices allowed in a chunk.- Parameters:
maxVerticesInChunk- maximum allowed number of vertices to be set.- Throws:
IllegalArgumentException- if provided value is lower than 1.
-
internalSetMaxStreamPositions
private void internalSetMaxStreamPositions(long maxStreamPositions) Internal method to set maximum number of file stream positions to be cached. This method is reused both in the constructor and in the setter of maximum number stream positions.- Parameters:
maxStreamPositions- maximum number of file stream positions to be cached.- Throws:
IllegalArgumentException- if provided value is lower than 1.
-