diff --git a/pom.xml b/pom.xml
index f08170a..700a76a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.geosiris
energyml-utils
${project.groupId}:${project.artifactId}
- 1.0.10
+ 1.0.11
Geosiris
http://www.geosiris.com
diff --git a/src/main/java/com/geosiris/energyml/data/Mesh.java b/src/main/java/com/geosiris/energyml/data/Mesh.java
index c64884d..5270dc6 100644
--- a/src/main/java/com/geosiris/energyml/data/Mesh.java
+++ b/src/main/java/com/geosiris/energyml/data/Mesh.java
@@ -18,17 +18,22 @@
import com.geosiris.energyml.exception.NotImplementedException;
import com.geosiris.energyml.exception.ObjectNotFoundNotError;
import com.geosiris.energyml.pkg.EPCFile;
+import com.geosiris.energyml.pkg.EpcHdf5FileManager;
import com.geosiris.energyml.utils.EnergymlWorkspace;
import com.geosiris.energyml.utils.ObjectController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
+import static com.geosiris.energyml.data.SurfaceMesh.exportObj;
+import static com.geosiris.energyml.data.SurfaceMesh.exportOff;
import static com.geosiris.energyml.utils.EnergymlWorkspaceHelper.*;
import static com.geosiris.energyml.utils.ObjectController.searchAttributeMatchingNameWithPath;
@@ -318,7 +323,7 @@ public static List readGrid2dRepresentationPoints(Object ene
return meshes;
}
- public static List readTriangulatedSetRepresentation (Object energymlObject, EnergymlWorkspace
+ public static List readTriangulatedSetRepresentation(Object energymlObject, EnergymlWorkspace
workspace) throws NotImplementedException, InvocationTargetException, IllegalAccessException {
List meshes = new ArrayList<>();
try {
@@ -359,7 +364,7 @@ public static List readTriangulatedSetRepresentation (Object energy
pointList.addAll(((List>) pl).stream()
.map(l -> l.stream().map(v -> ((Number) v).doubleValue()).collect(Collectors.toList())).collect(Collectors.toList()));
} else { // pl given flat
- for (int i = 0; i < pl.size() - 2; i++) {
+ for (int i = 0; i < pl.size() - 2; i+=3) {
pointList.add(new ArrayList<>(List.of(
((Number) pl.get(i)).doubleValue(),
((Number) pl.get(i + 1)).doubleValue(),
@@ -382,7 +387,7 @@ public static List readTriangulatedSetRepresentation (Object energy
trianglesList_obj.addAll(((List>)indices).stream()
.map(l -> l.stream().map(v -> ((Number)v).longValue()).collect(Collectors.toList())).collect(Collectors.toList()));
}else{ // indices given flat
- for(int i=0; i(List.of(
((Number)indices.get(i)).longValue(),
((Number)indices.get(i+1)).longValue(),
@@ -417,4 +422,5 @@ public static List readTriangulatedSetRepresentation (Object energy
return meshes;
}
+
}
\ No newline at end of file
diff --git a/src/main/java/com/geosiris/energyml/data/SurfaceMesh.java b/src/main/java/com/geosiris/energyml/data/SurfaceMesh.java
index 4c0566e..3c8fd56 100644
--- a/src/main/java/com/geosiris/energyml/data/SurfaceMesh.java
+++ b/src/main/java/com/geosiris/energyml/data/SurfaceMesh.java
@@ -16,9 +16,13 @@
package com.geosiris.energyml.data;
import com.geosiris.energyml.exception.NotImplementedException;
+import com.geosiris.energyml.pkg.EpcHdf5FileManager;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@@ -110,12 +114,13 @@ public static void exportObjElt(
);
if (colors != null && colors.size() > cpt && colors.get(cpt) != null && !colors.get(cpt).isEmpty())
{
- pointPart.write(String.format("%s",
+ facePart.write(String.format("%s",
colors.get(cpt).stream().map(String::valueOf).collect(Collectors.joining(" "))).getBytes(StandardCharsets.UTF_8)
);
}
- pointPart.write("\n".getBytes(StandardCharsets.UTF_8));
+ facePart.write("\n".getBytes(StandardCharsets.UTF_8));
}
+ cpt++;
}
}
@@ -136,29 +141,34 @@ public static void exportOffElt(
Long pointOffset,
List> colors
) throws IOException {
- Long offsetObj = 1L; // OBJ point indices starts at 1 not 0
for(var p: points) {
if (!p.isEmpty())
pointPart.write(String.format("%s\n",
p.stream().map(String::valueOf).collect(Collectors.joining(" "))).getBytes(StandardCharsets.UTF_8)
);
}
- // cpt = 0
+ int cpt = 0;
for(var face: indices) {
- if(!indices.isEmpty())
+ if(!indices.isEmpty()) {
facePart.write(
- String.format("%s\n",
- face.stream().map(x -> String.valueOf(x + pointOffset + offsetObj)).collect(Collectors.joining(" ")))
+ String.format("%d %s %s\n",
+ face.size(),
+ face.stream().map(x -> String.valueOf(x + pointOffset)).collect(Collectors.joining(" ")),
+ cpt >= colors.size() ? "" : colors.get(cpt).stream().map(String::valueOf).collect(Collectors.joining(" "))
+ )
.getBytes(
StandardCharsets.UTF_8)
);
+ }
+ cpt++;
}
}
public static void exportObj(
List meshList,
OutputStream out,
- String objName
+ String objName,
+ Boolean useOffset
) throws IOException {
out.write("# Generated by energyml-utils a Geosiris python module\n\n".getBytes(StandardCharsets.UTF_8));
if(objName != null){
@@ -173,7 +183,7 @@ public static void exportObj(
out,
(List>) m.pointList,
m.getEdgeIndices(),
- pointOffset,
+ useOffset ? pointOffset : 0,
new ArrayList<>(),
m instanceof PolylineSetMesh ? "l" : "f"
);
@@ -181,4 +191,37 @@ public static void exportObj(
out.write("\n".getBytes(StandardCharsets.UTF_8));
}
}
+
+ public static void exportOff(
+ List meshList,
+ OutputStream out,
+ String objName,
+ Boolean useOffset
+ ) throws IOException {
+ out.write("OFF\n# Generated by energyml-utils a Geosiris python module\n\n".getBytes(StandardCharsets.UTF_8));
+ out.write(String.format("%d %d %d\n",
+ meshList.stream().map(AbstractMesh::getNbPoints).reduce(0L, Long::sum),
+ meshList.stream().map(AbstractMesh::getNbFaces).reduce(0L, Long::sum),
+ meshList.stream().map(AbstractMesh::getNbEdge).reduce(0L, Long::sum)
+ ).getBytes(StandardCharsets.UTF_8)
+ );
+
+ ByteArrayOutputStream out_i = new ByteArrayOutputStream();
+
+ Long pointOffset = 0L;
+ for(var m: meshList){
+ exportOffElt(
+ out,
+ out_i,
+ (List>) m.pointList,
+ m.getEdgeIndices(),
+ useOffset ? pointOffset : 0,
+ new ArrayList<>()
+ );
+ pointOffset += m.pointList.size();
+ out.write("\n".getBytes(StandardCharsets.UTF_8));
+ }
+
+ out_i.writeTo(out);
+ }
}