Class LoaderSTL

java.lang.Object
com.irurueta.geometry.io.Loader
com.irurueta.geometry.io.LoaderSTL
All Implemented Interfaces:
Closeable, AutoCloseable

public class LoaderSTL extends Loader
  • Field Details

    • DEFAULT_MAX_VERTICES_IN_CHUNK

      public static final int DEFAULT_MAX_VERTICES_IN_CHUNK
      Constant 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_CHUNK
      Minimum allowed value for maximum number of vertices in chunk, which is one.
      See Also:
    • PROGRESS_DELTA

      public static final float PROGRESS_DELTA
      Amount of progress variation (1%) used to notify progress.
      See Also:
    • loaderIterator

      private LoaderSTL.LoaderIteratorSTL loaderIterator
    • maxVerticesInChunk

      private int maxVerticesInChunk
  • Constructor Details

    • LoaderSTL

      public LoaderSTL()
      Constructor.
    • LoaderSTL

      public LoaderSTL(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.
    • LoaderSTL

      public LoaderSTL(File f) throws IOException
      Constructor.
      Parameters:
      f - file to be loaded.
      Throws:
      IOException - if an I/O error occurs.
    • LoaderSTL

      public LoaderSTL(File f, int maxVerticesInChunk) 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.
      Throws:
      IllegalArgumentException - if maximum number of vertices allowed in a chunk is lower than 1.
      IOException - if an I/O error occurs.
    • LoaderSTL

      public LoaderSTL(LoaderListener listener)
      Constructor.
      Parameters:
      listener - listener to be notified of loading progress and when loading process starts or finishes.
    • LoaderSTL

      public LoaderSTL(LoaderListener listener, int maxVerticesInChunk)
      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.
    • LoaderSTL

      public LoaderSTL(File f, LoaderListener listener) throws IOException
      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.
    • LoaderSTL

      public LoaderSTL(File f, LoaderListener listener, int maxVerticesInChunk) 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.
      Throws:
      IllegalArgumentException - if maximum number of vertices allowed in a chunk is lower than 1.
      IOException - if an I/O error occurs.
  • Method Details

    • setMaxVerticesInChunk

      public void setMaxVerticesInChunk(int maxVerticesInChunk) throws LockedException
      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.
    • 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.
    • isReady

      public boolean isReady()
      If loader is ready to start loading a file. This is true once a file has been provided.
      Specified by:
      isReady in class Loader
      Returns:
      true if ready to start loading a file, false otherwise.
    • getMeshFormat

      public MeshFormat getMeshFormat()
      Returns mesh format supported by this class, which is MESH_FORMAT_STL.
      Specified by:
      getMeshFormat in class Loader
      Returns:
      mesh format supported by this class.
    • isValidFile

      public boolean isValidFile() throws LockedException, IOException
      Determines if provided file is a valid file that can be read by this loader.
      Specified by:
      isValidFile in class Loader
      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

      Starts 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:
      load in class Loader
      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.
    • getSolidName

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

      protected Long getNumberOfVertices()
      Gets number of vertices contained in the file.
      Returns:
      number of vertices contained in the file.
    • 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.