Class PolygonObjParser
- java.lang.Object
-
- org.apache.commons.geometry.io.euclidean.threed.obj.AbstractObjParser
-
- org.apache.commons.geometry.io.euclidean.threed.obj.PolygonObjParser
-
public class PolygonObjParser extends AbstractObjParser
Low-level parser class for reading 3D polygon (face) data in the OBJ file format. This class provides access to OBJ data structures but does not retain any of the parsed data. For example, it is up to callers to store vertices as they are parsed for later reference. This allows callers to determine what values are stored and in what format.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PolygonObjParser.Face
Class representing an OBJ face definition.static class
PolygonObjParser.VertexAttributes
Class representing a set of attributes for a face vertex.
-
Field Summary
Fields Modifier and Type Field Description private boolean
failOnNonPolygonKeywords
If true, parsing will fail when non-polygon keywords are encountered in the OBJ content.private static java.util.Set<java.lang.String>
STANDARD_POLYGON_KEYWORDS
Set containing OBJ keywords commonly used with files containing only polygon content.private int
textureCoordinateCount
Number of texture coordinate keywords encountered in the file so far.private int
vertexCount
Number of vertex keywords encountered in the file so far.private int
vertexNormalCount
Number of vertex normal keywords encountered in the file so far.
-
Constructor Summary
Constructors Constructor Description PolygonObjParser(java.io.Reader reader)
Construct a new instance for parsing OBJ content from the given reader.PolygonObjParser(SimpleTextParser parser)
Construct a new instance for parsing OBJ content from the given text parser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getTextureCoordinateCount()
Get the number oftexture coordinate keywords
parsed so far.int
getVertexCount()
Get the number ofvertex keywords
parsed so far.int
getVertexNormalCount()
Get the number ofvertex normal keywords
parsed so far.protected void
handleKeyword(java.lang.String keywordValue)
Method called when a keyword is encountered in the parsed OBJ content.boolean
isFailOnNonPolygonKeywords()
Return true if the instance is configured to throw anIllegalStateException
when OBJ keywords not commonly used with files containing only polygon data are encountered.PolygonObjParser.Face
readFace()
Read an OBJ face definition from the current line.private PolygonObjParser.VertexAttributes
readFaceVertex()
Read an OBJ face vertex definition from the current parser position.private int
readNormalizedVertexAttributeIndex(java.lang.String type, int available)
Read a vertex attribute index from the current parser position and normalize it to be 0-based and positive.void
setFailOnNonPolygonKeywords(boolean failOnNonPolygonKeywords)
Set the flag determining if the instance should throw anIllegalStateException
when encountering keywords not commonly used with OBJ files containing only polygon data.-
Methods inherited from class org.apache.commons.geometry.io.euclidean.threed.obj.AbstractObjParser
discardDataLine, discardDataLineWhitespace, getCurrentKeyword, getTextParser, nextDataLineContent, nextDouble, nextKeyword, readDataLine, readDoubles, readVector
-
-
-
-
Field Detail
-
STANDARD_POLYGON_KEYWORDS
private static final java.util.Set<java.lang.String> STANDARD_POLYGON_KEYWORDS
Set containing OBJ keywords commonly used with files containing only polygon content.
-
vertexCount
private int vertexCount
Number of vertex keywords encountered in the file so far.
-
vertexNormalCount
private int vertexNormalCount
Number of vertex normal keywords encountered in the file so far.
-
textureCoordinateCount
private int textureCoordinateCount
Number of texture coordinate keywords encountered in the file so far.
-
failOnNonPolygonKeywords
private boolean failOnNonPolygonKeywords
If true, parsing will fail when non-polygon keywords are encountered in the OBJ content.
-
-
Constructor Detail
-
PolygonObjParser
public PolygonObjParser(java.io.Reader reader)
Construct a new instance for parsing OBJ content from the given reader.- Parameters:
reader
- reader to parser content from
-
PolygonObjParser
public PolygonObjParser(SimpleTextParser parser)
Construct a new instance for parsing OBJ content from the given text parser.- Parameters:
parser
- text parser to read content from
-
-
Method Detail
-
getVertexCount
public int getVertexCount()
Get the number ofvertex keywords
parsed so far.- Returns:
- the number of vertex keywords parsed so far
-
getVertexNormalCount
public int getVertexNormalCount()
Get the number ofvertex normal keywords
parsed so far.- Returns:
- the number of vertex normal keywords parsed so far
-
getTextureCoordinateCount
public int getTextureCoordinateCount()
Get the number oftexture coordinate keywords
parsed so far.- Returns:
- the number of texture coordinate keywords parsed so far
-
isFailOnNonPolygonKeywords
public boolean isFailOnNonPolygonKeywords()
Return true if the instance is configured to throw anIllegalStateException
when OBJ keywords not commonly used with files containing only polygon data are encountered. The default value isfalse
, meaning that no keyword validation is performed. When set to true, only the following keywords are accepted:v
vn
vt
f
o
g
s
mtllib
usemtl
- Returns:
- true if the instance is configured to fail when a non-polygon keyword is encountered
-
setFailOnNonPolygonKeywords
public void setFailOnNonPolygonKeywords(boolean failOnNonPolygonKeywords)
Set the flag determining if the instance should throw anIllegalStateException
when encountering keywords not commonly used with OBJ files containing only polygon data. If true, only the following keywords are accepted:v
vn
vt
f
o
g
s
mtllib
usemtl
- Parameters:
failOnNonPolygonKeywords
- new flag value
-
handleKeyword
protected void handleKeyword(java.lang.String keywordValue)
Method called when a keyword is encountered in the parsed OBJ content. Subclasses should use this method to validate the keyword and/or update any internal state.- Specified by:
handleKeyword
in classAbstractObjParser
- Parameters:
keywordValue
- keyword encountered in the OBJ content
-
readFace
public PolygonObjParser.Face readFace()
Read an OBJ face definition from the current line.- Returns:
- OBJ face definition read from the current line
- Throws:
java.lang.IllegalStateException
- if a face definition is not able to be parsedjava.io.UncheckedIOException
- if an I/O error occurs
-
readFaceVertex
private PolygonObjParser.VertexAttributes readFaceVertex()
Read an OBJ face vertex definition from the current parser position.- Returns:
- OBJ face vertex definition
- Throws:
java.lang.IllegalStateException
- if a vertex definition is not able to be parsedjava.io.UncheckedIOException
- if an I/O error occurs
-
readNormalizedVertexAttributeIndex
private int readNormalizedVertexAttributeIndex(java.lang.String type, int available)
Read a vertex attribute index from the current parser position and normalize it to be 0-based and positive.- Parameters:
type
- type of attribute being read; this value is used in error messagesavailable
- number of available values of the given type parsed from the content so far- Returns:
- 0-based positive attribute index
- Throws:
java.lang.IllegalStateException
- if the integer index cannot be parsed or the index is out of range for the number of parsed elements of the given typejava.io.UncheckedIOException
- if an I/O error occurs
-
-