aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-extras/src/main/java/com/ardor3d
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2016-08-20 18:04:25 +0200
committerJulien Gouesse <[email protected]>2016-08-20 18:04:25 +0200
commit5430d5699c791d88dd134784b6ddd83be5c576d6 (patch)
treeb52856652376be5b9ec85ccf81296ab16a108d50 /ardor3d-extras/src/main/java/com/ardor3d
parent0a07ac2f112dea679de95ac4a352a02bd663ea36 (diff)
Reads the header of the binary file in the PLY importer
Diffstat (limited to 'ardor3d-extras/src/main/java/com/ardor3d')
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyImporter.java570
1 files changed, 280 insertions, 290 deletions
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyImporter.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyImporter.java
index 36c9d23..4b505f6 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyImporter.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyImporter.java
@@ -12,7 +12,6 @@ package com.ardor3d.extension.model.ply;
import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StreamTokenizer;
@@ -560,326 +559,317 @@ public class PlyImporter {
public PlyGeometryStore load(final ResourceSource resource, final FileHelper fileHelper,
final GeometryTool geometryTool) {
final boolean isAscii = fileHelper.isFilePureAscii(resource);
+ FormatWithVersionNumber formatWithVersionNumber = null;
final PlyGeometryStore store = createGeometryStore(geometryTool);
- if (isAscii) { // Ascii file
- try (final BufferedReader reader = new BufferedReader(new InputStreamReader(resource.openStream()))) {
- final PlyFileParser parser = new PlyFileParser(reader);
- try {
- // starts reading the header
- parser.nextToken();
- // reads "ply"
- if ("ply".equals(parser.sval)) {
- PlyImporter.LOGGER.log(Level.INFO, "ply keyword on line " + parser.lineno());
- } else {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Ascii file but no ply keyword on line " + parser.lineno());
- }
- // reads the EOL for verifying that the file has a correct format
- parser.nextToken();
- if (parser.ttype != StreamTokenizer.TT_EOL) {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Format Error: expecting End Of Line on line " + parser.lineno());
- }
- parser.nextToken();
- // reads the rest of the header
- FormatWithVersionNumber formatWithVersionNumber = null;
- final Map<ElementWithKeyword, Map.Entry<Integer, Set<AbstractPropertyWithKeyword<?>>>> elementMap = new LinkedHashMap<>();
- while (parser.ttype != StreamTokenizer.TT_EOF && !"end_header".equals(parser.sval)) {
- if (parser.ttype == StreamTokenizer.TT_WORD) {
- final int currentLineNumber = parser.lineno();
- switch (parser.sval) {
- case "comment": {
- parser.nextToken();
- if (parser.ttype == StreamTokenizer.TT_WORD) {
- if ("TextureFile".equals(parser.sval)) {
- parser.nextToken();
- if (parser.ttype == StreamTokenizer.TT_WORD) {
- final String textureName = parser.sval;
- store.setTextureName(textureName);
- final Texture texture;
- if (_textureLocator == null) {
- texture = TextureManager.load(textureName, getMinificationFilter(),
- isUseCompression()
- ? TextureStoreFormat.GuessCompressedFormat
- : TextureStoreFormat.GuessNoCompressedFormat,
- isFlipTextureVertically());
- } else {
- final ResourceSource source = _textureLocator
- .locateResource(textureName);
- texture = TextureManager.load(source, getMinificationFilter(),
- isUseCompression()
- ? TextureStoreFormat.GuessCompressedFormat
- : TextureStoreFormat.GuessNoCompressedFormat,
- isFlipTextureVertically());
- }
- store.setTexture(texture);
+ try (final BufferedReader reader = new BufferedReader(new InputStreamReader(resource.openStream()))) {
+ final PlyFileParser parser = new PlyFileParser(reader);
+ try {
+ // starts reading the header
+ parser.nextToken();
+ // reads "ply"
+ if ("ply".equals(parser.sval)) {
+ PlyImporter.LOGGER.log(Level.INFO, "ply keyword on line " + parser.lineno());
+ } else {
+ PlyImporter.LOGGER.log(Level.SEVERE, "No ply keyword on line " + parser.lineno());
+ }
+ // reads the EOL for verifying that the file has a correct format
+ parser.nextToken();
+ if (parser.ttype != StreamTokenizer.TT_EOL) {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "Format Error: expecting End Of Line on line " + parser.lineno());
+ }
+ parser.nextToken();
+ // reads the rest of the header
+ final Map<ElementWithKeyword, Map.Entry<Integer, Set<AbstractPropertyWithKeyword<?>>>> elementMap = new LinkedHashMap<>();
+ while (parser.ttype != StreamTokenizer.TT_EOF && !"end_header".equals(parser.sval)) {
+ if (parser.ttype == StreamTokenizer.TT_WORD) {
+ final int currentLineNumber = parser.lineno();
+ switch (parser.sval) {
+ case "comment": {
+ parser.nextToken();
+ if (parser.ttype == StreamTokenizer.TT_WORD) {
+ if ("TextureFile".equals(parser.sval)) {
+ parser.nextToken();
+ if (parser.ttype == StreamTokenizer.TT_WORD) {
+ final String textureName = parser.sval;
+ store.setTextureName(textureName);
+ final Texture texture;
+ if (_textureLocator == null) {
+ texture = TextureManager.load(textureName, getMinificationFilter(),
+ isUseCompression() ? TextureStoreFormat.GuessCompressedFormat
+ : TextureStoreFormat.GuessNoCompressedFormat,
+ isFlipTextureVertically());
} else {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "'TextureFile' comment with no texture file on line "
- + currentLineNumber);
+ final ResourceSource source = _textureLocator
+ .locateResource(textureName);
+ texture = TextureManager.load(source, getMinificationFilter(),
+ isUseCompression() ? TextureStoreFormat.GuessCompressedFormat
+ : TextureStoreFormat.GuessNoCompressedFormat,
+ isFlipTextureVertically());
}
+ store.setTexture(texture);
+ } else {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "'TextureFile' comment with no texture file on line "
+ + currentLineNumber);
}
}
- break;
}
- case "format": {
- parser.nextToken();
- if (parser.ttype == StreamTokenizer.TT_WORD) {
- if (formatWithVersionNumber == null) {
- Format format = null;
- try {
- format = Format.valueOf(parser.sval.toUpperCase());
- } catch (final IllegalArgumentException iae) {
- PlyImporter.LOGGER.log(Level.SEVERE, "Unknown format '" + parser.sval
- + "' on line " + currentLineNumber + ": " + iae.getMessage());
+ break;
+ }
+ case "format": {
+ parser.nextToken();
+ if (parser.ttype == StreamTokenizer.TT_WORD) {
+ if (formatWithVersionNumber == null) {
+ Format format = null;
+ try {
+ format = Format.valueOf(parser.sval.toUpperCase());
+ } catch (final IllegalArgumentException iae) {
+ PlyImporter.LOGGER.log(Level.SEVERE, "Unknown format '" + parser.sval
+ + "' on line " + currentLineNumber + ": " + iae.getMessage());
+ }
+ final double versionNumber;
+ if (parser.getNumber()) {
+ versionNumber = parser.nval;
+ if (Double.compare(versionNumber, 1.0d) != 0) {
+ PlyImporter.LOGGER.log(Level.WARNING,
+ "Unsupported format version number '" + parser.nval
+ + "' on line " + currentLineNumber
+ + ". This importer supports only PLY 1.0");
}
- final double versionNumber;
- if (parser.getNumber()) {
- versionNumber = parser.nval;
- if (Double.compare(versionNumber, 1.0d) != 0) {
- PlyImporter.LOGGER.log(Level.WARNING,
- "Unsupported format version number '" + parser.nval
- + "' on line " + currentLineNumber
- + ". This importer supports only PLY 1.0");
- }
- parser.nextToken();
- if (parser.ttype != StreamTokenizer.TT_EOL) {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Format Error: expecting End Of Line on line "
- + currentLineNumber);
- }
- } else {
+ parser.nextToken();
+ if (parser.ttype != StreamTokenizer.TT_EOL) {
PlyImporter.LOGGER.log(Level.SEVERE,
- "Format version number missing on line " + currentLineNumber
- + "\n");
- versionNumber = Double.NaN;
+ "Format Error: expecting End Of Line on line "
+ + currentLineNumber);
}
- formatWithVersionNumber = new FormatWithVersionNumber(format,
- versionNumber);
- PlyImporter.LOGGER.log(Level.INFO,
- "Format '" + (format == null ? "null" : format.name())
- + "' version number '" + versionNumber
- + "' detected on line " + currentLineNumber);
} else {
- PlyImporter.LOGGER.log(Level.WARNING,
- "Format already defined, format declaration ignored on line "
- + currentLineNumber);
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "Format version number missing on line " + currentLineNumber
+ + "\n");
+ versionNumber = Double.NaN;
}
+ formatWithVersionNumber = new FormatWithVersionNumber(format, versionNumber);
+ PlyImporter.LOGGER.log(Level.INFO,
+ "Format '" + (format == null ? "null" : format.name())
+ + "' version number '" + versionNumber + "' detected on line "
+ + currentLineNumber);
} else {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Format type (ascii, binary_big_endian or binary_little_endian) missing on line "
+ PlyImporter.LOGGER.log(Level.WARNING,
+ "Format already defined, format declaration ignored on line "
+ currentLineNumber);
}
- break;
+ } else {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "Format type (ascii, binary_big_endian or binary_little_endian) missing on line "
+ + currentLineNumber);
}
- case "element": {
- parser.nextToken();
- if (parser.ttype == StreamTokenizer.TT_WORD) {
- final String elementName = parser.sval;
- final Element element = Element.get(elementName);
- final ElementWithKeyword elementWithKeyword = new ElementWithKeyword(element,
- elementName);
- if (elementMap.containsKey(element)) {
- PlyImporter.LOGGER.log(Level.WARNING,
- elementWithKeyword
- + " already defined, element declaration ignored on line "
- + currentLineNumber);
- } else {
- final int elementCount;
- if (parser.getNumber()) {
- elementCount = (int) parser.nval;
- if (elementCount < 0) {
- PlyImporter.LOGGER.log(Level.SEVERE,
- elementWithKeyword + " count = " + elementCount
- + " whereas it should be >= 0 on line "
- + currentLineNumber);
- }
- parser.nextToken();
- if (parser.ttype != StreamTokenizer.TT_EOL) {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Format Error: expecting End Of Line on line "
- + currentLineNumber);
- }
- } else {
- PlyImporter.LOGGER.log(Level.SEVERE, elementWithKeyword
- + " count missing on line " + currentLineNumber);
- elementCount = 0;
+ break;
+ }
+ case "element": {
+ parser.nextToken();
+ if (parser.ttype == StreamTokenizer.TT_WORD) {
+ final String elementName = parser.sval;
+ final Element element = Element.get(elementName);
+ final ElementWithKeyword elementWithKeyword = new ElementWithKeyword(element,
+ elementName);
+ if (elementMap.containsKey(element)) {
+ PlyImporter.LOGGER.log(Level.WARNING,
+ elementWithKeyword
+ + " already defined, element declaration ignored on line "
+ + currentLineNumber);
+ } else {
+ final int elementCount;
+ if (parser.getNumber()) {
+ elementCount = (int) parser.nval;
+ if (elementCount < 0) {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ elementWithKeyword + " count = " + elementCount
+ + " whereas it should be >= 0 on line "
+ + currentLineNumber);
}
- elementMap.put(elementWithKeyword,
- new AbstractMap.SimpleEntry<Integer, Set<AbstractPropertyWithKeyword<?>>>(
- Integer.valueOf(elementCount), null));
- PlyImporter.LOGGER.log(Level.INFO,
- elementWithKeyword + " detected on line " + currentLineNumber);
+ parser.nextToken();
+ if (parser.ttype != StreamTokenizer.TT_EOL) {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "Format Error: expecting End Of Line on line "
+ + currentLineNumber);
+ }
+ } else {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ elementWithKeyword + " count missing on line " + currentLineNumber);
+ elementCount = 0;
}
- } else {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Element type (vertex, face or edge) missing on line "
- + currentLineNumber);
+ elementMap.put(elementWithKeyword,
+ new AbstractMap.SimpleEntry<Integer, Set<AbstractPropertyWithKeyword<?>>>(
+ Integer.valueOf(elementCount), null));
+ PlyImporter.LOGGER.log(Level.INFO,
+ elementWithKeyword + " detected on line " + currentLineNumber);
}
- break;
+ } else {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "Element type (vertex, face or edge) missing on line " + currentLineNumber);
}
- case "property": {
- ElementWithKeyword latestInsertedElementWithKeyword = null;
- for (final ElementWithKeyword elementWithKeyword : elementMap.keySet()) {
- latestInsertedElementWithKeyword = elementWithKeyword;
- }
- if (latestInsertedElementWithKeyword == null) {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Property definition not preceded by an element definition on line "
- + currentLineNumber);
- } else {
- parser.nextToken();
- if (parser.ttype == StreamTokenizer.TT_WORD) {
- if ("list".equals(parser.sval)) {
- // list property, for face elements (vertex indices, texture
- // coordinates, ...)
- parser.nextToken();
- if (parser.ttype == StreamTokenizer.TT_WORD) {
- Data countData = null;
- try {
- countData = Data.get(parser.sval);
- } catch (final IllegalArgumentException iae) {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Count data type '" + parser.sval + "' unknown on line "
- + currentLineNumber);
- }
- if (countData != null) {
- parser.nextToken();
- if (parser.ttype == StreamTokenizer.TT_WORD) {
- Data data = null;
- try {
- data = Data.get(parser.sval);
- } catch (final IllegalArgumentException iae) {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Data type '" + parser.sval
- + "' unknown on line "
- + currentLineNumber);
- }
- if (data != null) {
- parser.nextToken();
- if (parser.ttype == StreamTokenizer.TT_WORD) {
- final String listPropertyName = parser.sval;
- final ListProperty listProperty = ListProperty
- .get(listPropertyName);
- final ListPropertyWithKeyword listPropertyWithKeyword = new ListPropertyWithKeyword(
- listProperty, listPropertyName, countData,
- data);
- if (Arrays.asList(listProperty.getElements())
- .contains(latestInsertedElementWithKeyword
- .getEnumKey())) {
- final Entry<Integer, Set<AbstractPropertyWithKeyword<?>>> elementMapEntry = elementMap
- .get(latestInsertedElementWithKeyword);
- Set<AbstractPropertyWithKeyword<?>> propertySet = elementMapEntry
- .getValue();
- if (propertySet == null) {
- propertySet = new LinkedHashSet<>();
- elementMapEntry.setValue(propertySet);
- }
- propertySet.add(listPropertyWithKeyword);
- PlyImporter.LOGGER.log(Level.INFO,
- listPropertyWithKeyword
- + " detected on line "
- + currentLineNumber);
- } else {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Unexpected " + listPropertyWithKeyword
- + " on line "
- + currentLineNumber);
+ break;
+ }
+ case "property": {
+ ElementWithKeyword latestInsertedElementWithKeyword = null;
+ for (final ElementWithKeyword elementWithKeyword : elementMap.keySet()) {
+ latestInsertedElementWithKeyword = elementWithKeyword;
+ }
+ if (latestInsertedElementWithKeyword == null) {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "Property definition not preceded by an element definition on line "
+ + currentLineNumber);
+ } else {
+ parser.nextToken();
+ if (parser.ttype == StreamTokenizer.TT_WORD) {
+ if ("list".equals(parser.sval)) {
+ // list property, for face elements (vertex indices, texture
+ // coordinates, ...)
+ parser.nextToken();
+ if (parser.ttype == StreamTokenizer.TT_WORD) {
+ Data countData = null;
+ try {
+ countData = Data.get(parser.sval);
+ } catch (final IllegalArgumentException iae) {
+ PlyImporter.LOGGER.log(Level.SEVERE, "Count data type '"
+ + parser.sval + "' unknown on line " + currentLineNumber);
+ }
+ if (countData != null) {
+ parser.nextToken();
+ if (parser.ttype == StreamTokenizer.TT_WORD) {
+ Data data = null;
+ try {
+ data = Data.get(parser.sval);
+ } catch (final IllegalArgumentException iae) {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "Data type '" + parser.sval + "' unknown on line "
+ + currentLineNumber);
+ }
+ if (data != null) {
+ parser.nextToken();
+ if (parser.ttype == StreamTokenizer.TT_WORD) {
+ final String listPropertyName = parser.sval;
+ final ListProperty listProperty = ListProperty
+ .get(listPropertyName);
+ final ListPropertyWithKeyword listPropertyWithKeyword = new ListPropertyWithKeyword(
+ listProperty, listPropertyName, countData,
+ data);
+ if (Arrays.asList(listProperty.getElements())
+ .contains(latestInsertedElementWithKeyword
+ .getEnumKey())) {
+ final Entry<Integer, Set<AbstractPropertyWithKeyword<?>>> elementMapEntry = elementMap
+ .get(latestInsertedElementWithKeyword);
+ Set<AbstractPropertyWithKeyword<?>> propertySet = elementMapEntry
+ .getValue();
+ if (propertySet == null) {
+ propertySet = new LinkedHashSet<>();
+ elementMapEntry.setValue(propertySet);
}
+ propertySet.add(listPropertyWithKeyword);
+ PlyImporter.LOGGER.log(Level.INFO,
+ listPropertyWithKeyword
+ + " detected on line "
+ + currentLineNumber);
} else {
PlyImporter.LOGGER.log(Level.SEVERE,
- "List property keyword (vertex_indices, texcoord, ...) missing on line "
- + currentLineNumber);
+ "Unexpected " + listPropertyWithKeyword
+ + " on line " + currentLineNumber);
}
+ } else {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "List property keyword (vertex_indices, texcoord, ...) missing on line "
+ + currentLineNumber);
}
- } else {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Second data type (float32, int8, ...) missing on line "
- + currentLineNumber);
}
+ } else {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "Second data type (float32, int8, ...) missing on line "
+ + currentLineNumber);
}
- } else {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "First data type (float32, int8, ...) missing on line "
- + currentLineNumber);
}
} else {
- // scalar property (vertex coordinates, normal coordinates, ...)
- Data data = null;
- try {
- data = Data.get(parser.sval);
- } catch (final IllegalArgumentException iae) {
- PlyImporter.LOGGER.log(Level.SEVERE, "Data type '" + parser.sval
- + "' unknown on line " + currentLineNumber);
- }
- if (data != null) {
- parser.nextToken();
- if (parser.ttype == StreamTokenizer.TT_WORD) {
- final String scalarPropertyName = parser.sval;
- final ScalarProperty scalarProperty = ScalarProperty
- .get(scalarPropertyName);
- final ScalarPropertyWithKeyword scalarPropertyWithKeyword = new ScalarPropertyWithKeyword(
- scalarProperty, scalarPropertyName, data);
- if (Arrays.asList(scalarProperty.getElements()).contains(
- latestInsertedElementWithKeyword.getEnumKey())) {
- final Entry<Integer, Set<AbstractPropertyWithKeyword<?>>> elementMapValue = elementMap
- .get(latestInsertedElementWithKeyword);
- Set<AbstractPropertyWithKeyword<?>> propertySet = elementMapValue
- .getValue();
- if (propertySet == null) {
- propertySet = new LinkedHashSet<>();
- elementMapValue.setValue(propertySet);
- }
- propertySet.add(scalarPropertyWithKeyword);
- PlyImporter.LOGGER.log(Level.INFO, scalarPropertyWithKeyword
- + " detected on line " + currentLineNumber);
- } else {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Unexpected " + scalarPropertyWithKeyword + " in a "
- + latestInsertedElementWithKeyword
- + " on line " + currentLineNumber);
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "First data type (float32, int8, ...) missing on line "
+ + currentLineNumber);
+ }
+ } else {
+ // scalar property (vertex coordinates, normal coordinates, ...)
+ Data data = null;
+ try {
+ data = Data.get(parser.sval);
+ } catch (final IllegalArgumentException iae) {
+ PlyImporter.LOGGER.log(Level.SEVERE, "Data type '" + parser.sval
+ + "' unknown on line " + currentLineNumber);
+ }
+ if (data != null) {
+ parser.nextToken();
+ if (parser.ttype == StreamTokenizer.TT_WORD) {
+ final String scalarPropertyName = parser.sval;
+ final ScalarProperty scalarProperty = ScalarProperty
+ .get(scalarPropertyName);
+ final ScalarPropertyWithKeyword scalarPropertyWithKeyword = new ScalarPropertyWithKeyword(
+ scalarProperty, scalarPropertyName, data);
+ if (Arrays.asList(scalarProperty.getElements())
+ .contains(latestInsertedElementWithKeyword.getEnumKey())) {
+ final Entry<Integer, Set<AbstractPropertyWithKeyword<?>>> elementMapValue = elementMap
+ .get(latestInsertedElementWithKeyword);
+ Set<AbstractPropertyWithKeyword<?>> propertySet = elementMapValue
+ .getValue();
+ if (propertySet == null) {
+ propertySet = new LinkedHashSet<>();
+ elementMapValue.setValue(propertySet);
}
+ propertySet.add(scalarPropertyWithKeyword);
+ PlyImporter.LOGGER.log(Level.INFO, scalarPropertyWithKeyword
+ + " detected on line " + currentLineNumber);
} else {
PlyImporter.LOGGER.log(Level.SEVERE,
- "Scalar property keyword (x, nx, vertex1, red, ...) missing on line "
+ "Unexpected " + scalarPropertyWithKeyword + " in a "
+ + latestInsertedElementWithKeyword + " on line "
+ currentLineNumber);
}
+ } else {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "Scalar property keyword (x, nx, vertex1, red, ...) missing on line "
+ + currentLineNumber);
}
}
- } else {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Property type (list) or scalar data type (float32, int8, ...) missing on line "
- + currentLineNumber);
}
+ } else {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "Property type (list) or scalar data type (float32, int8, ...) missing on line "
+ + currentLineNumber);
}
- break;
- }
- default: {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "Unknown command '" + parser.sval + "' on line " + currentLineNumber);
- break;
}
+ break;
+ }
+ default: {
+ PlyImporter.LOGGER.log(Level.SEVERE,
+ "Unknown command '" + parser.sval + "' on line " + currentLineNumber);
+ break;
}
- } else {
- PlyImporter.LOGGER.log(Level.SEVERE,
- "No word at the beginning of the line " + parser.lineno());
- }
- // reads the whole line, doesn't look at the content
- while (parser.ttype != StreamTokenizer.TT_EOL) {
- parser.nextToken();
- }
- // if there is still something to read, reads the next token
- if (parser.ttype != StreamTokenizer.TT_EOF) {
- parser.nextToken();
}
+ } else {
+ PlyImporter.LOGGER.log(Level.SEVERE, "No word at the beginning of the line " + parser.lineno());
}
- if ("end_header".equals(parser.sval)) {
- PlyImporter.LOGGER.log(Level.INFO, "End of header on line " + parser.lineno());
- do {
- parser.nextToken();
- } while (parser.ttype != StreamTokenizer.TT_EOL);
+ // reads the whole line, doesn't look at the content
+ while (parser.ttype != StreamTokenizer.TT_EOL) {
+ parser.nextToken();
}
- // reads the lines after the header
+ // if there is still something to read, reads the next token
+ if (parser.ttype != StreamTokenizer.TT_EOF) {
+ parser.nextToken();
+ }
+ }
+ if ("end_header".equals(parser.sval)) {
+ PlyImporter.LOGGER.log(Level.INFO, "End of header on line " + parser.lineno());
+ do {
+ parser.nextToken();
+ } while (parser.ttype != StreamTokenizer.TT_EOL);
+ }
+ // reads the lines after the header
+ if (isAscii) {// Ascii file
final Iterator<Entry<ElementWithKeyword, Entry<Integer, Set<AbstractPropertyWithKeyword<?>>>>> elementMapEntryIterator = elementMap
.entrySet().iterator();
Entry<ElementWithKeyword, Entry<Integer, Set<AbstractPropertyWithKeyword<?>>>> elementMapEntry;
@@ -991,19 +981,19 @@ public class PlyImporter {
parser.nextToken();
}
}
- } catch (final IOException ioe) {
- throw new Exception("IO Error on line " + parser.lineno(), ioe);
+ } else {// Binary file
+ if (formatWithVersionNumber == null || formatWithVersionNumber.getFormat() == null) {
+ throw new Exception(
+ "Cannot determine the endianness of the binary data within the PLY file, missing or malformed format in the header");
+ } else {
+ // TODO
+ }
}
- } catch (final Throwable t) {
- throw new Error("Unable to load ply resource from URL: " + resource, t);
- }
- } else { // Binary file
- try (final InputStream data = resource.openStream()) {
- // TODO
- throw new UnsupportedOperationException("Binary PLY import not implemented");
- } catch (final Throwable t) {
- throw new Error("Unable to load ply resource from URL: " + resource, t);
+ } catch (final IOException ioe) {
+ throw new Exception("IO Error on line " + parser.lineno(), ioe);
}
+ } catch (final Throwable t) {
+ throw new Error("Unable to load ply resource from URL: " + resource, t);
}
store.commitObjects();
store.cleanup();