Skip to content

Commit ea0517c

Browse files
PlyCodec
- Fixed texture in ASCII format
1 parent 1aa05af commit ea0517c

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

main/boofcv-io/src/main/java/boofcv/io/points/impl/PlyCodec.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static void saveAscii( PlyWriter data, Writer outputWriter ) throws IOExc
5656
var v = new Point3D_F64();
5757
for (int i = 0; i < data.getVertexCount(); i++) {
5858
data.getVertex(i, p);
59-
outputWriter.write(String.format("%f %f %f", p.x, p.y, p.z));
59+
outputWriter.write(String.format("%.6f %.6f %.6f", p.x, p.y, p.z));
6060
if (data.isVertexNormals()) {
6161
data.getVertexNormal(i, v);
6262
outputWriter.write(String.format(" %f %f %f", v.x, v.y, v.z));
@@ -88,7 +88,7 @@ public static void saveAscii( PlyWriter data, Writer outputWriter ) throws IOExc
8888
BoofMiscOps.checkEq(size, data.getTextureCoors(i, arrayF));
8989
outputWriter.write(" " + (size*2));
9090
for (int idx = 0; idx < size*2; idx++) {
91-
outputWriter.write(" " + arrayF[idx]);
91+
outputWriter.write(String.format(" %.6f", arrayF[idx]));
9292
}
9393
}
9494

@@ -554,19 +554,39 @@ private static void readAscii( PlyReader output, InputStream reader, Header head
554554
output.stopVertex();
555555
}
556556

557-
int[] indexes = new int[100];
558-
for (int i = 0; i < header.triangleCount; i++) {
557+
var indexes = new int[100];
558+
var texture = new float[100];
559+
for (int idxTriangle = 0; idxTriangle < header.triangleCount; idxTriangle++) {
559560
String line = readNextPly(reader, true, buffer);
560561
String[] words = line.split("\\s+");
561-
int n = Integer.parseInt(words[0]);
562-
if (words.length != n + 1) {
563-
throw new RuntimeException("Unexpected number of words.");
564-
}
565-
for (int wordIdx = 1; wordIdx <= n; wordIdx++) {
566-
indexes[wordIdx - 1] = Integer.parseInt(words[i]);
567-
}
562+
int idxWord = 0;
563+
564+
for (int idxProperty = 0; idxProperty < header.properties.size(); idxProperty++) {
565+
PropertyList prop = header.properties.get(idxProperty);
566+
int n = Integer.parseInt(words[idxWord++]);
567+
if (words.length < n + idxWord) {
568+
throw new RuntimeException("Unexpected number of words. " + words.length + " vs " + (n + 1));
569+
}
568570

569-
output.addPolygon(indexes, 0, n);
571+
switch (prop.label) {
572+
case "vertex_indices" -> {
573+
for (int i = 0; i < n; i++) {
574+
indexes[i] = Integer.parseInt(words[idxWord++]);
575+
}
576+
output.addPolygon(indexes, 0, n);
577+
}
578+
case "texcoord" -> {
579+
for (int i = 0; i < n; i++) {
580+
texture[i] = Float.parseFloat(words[idxWord++]);
581+
}
582+
output.addTexture(n/2, texture);
583+
}
584+
default -> {
585+
idxWord += n;
586+
System.err.println("Unknown property type " + prop.label);
587+
}
588+
}
589+
}
570590
}
571591
}
572592

@@ -646,7 +666,6 @@ private static void readCloudBinary( PlyReader output, InputStream reader, Heade
646666
output.setVertexNormal(nx, ny, nz);
647667
}
648668
output.stopVertex();
649-
//System.out.printf("vertex: %.1e %.1e %.1e | %2x %2x %2x\n", x, y, z, r, g, b);
650669
}
651670

652671
var arrayI = new int[100];

0 commit comments

Comments
 (0)