Skip to content

Commit

Permalink
bugfix for closed polylines (#30)
Browse files Browse the repository at this point in the history
bugfix for closed polylines
  • Loading branch information
valentin-gauthier-geosiris authored Dec 12, 2024
1 parent ccbc011 commit 5dfb9e6
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 25 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ target/*
pom-test.xml
rc/*log4j2.properties
logs
src/test/manip*
src/test/manip*

src/main/java/sample
11 changes: 8 additions & 3 deletions src/main/java/com/geosiris/energyml/data/Mesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ public static String meshNameMapping(String arrayTypeName) {

public static List<AbstractMesh> readMeshObject(Object energymlObject, EnergymlWorkspace workspace) throws InvocationTargetException, IllegalAccessException {
if (energymlObject instanceof List) {
return (List<AbstractMesh>) energymlObject;
List<AbstractMesh> meshes = new ArrayList<>();
for(var m: (List<?>) energymlObject){
meshes.addAll(readMeshObject(m, workspace));
}
return meshes;
}
String arrayTypeName = meshNameMapping(energymlObject.getClass().getSimpleName());

Expand Down Expand Up @@ -219,13 +223,14 @@ public static List<PolylineSetMesh> readPolylineRepresentation(Object energymlOb
for (Long nbNode : nodeCountsList) {
pointIndices.add(IntStream.range((int) idx, (int) idx + nbNode.intValue())
.boxed().map(Long::valueOf).collect(Collectors.toList()));
if (closePoly != null && closePoly.size() > polyIdx && closePoly.get(polyIdx) != null) {
if (closePoly != null && closePoly.size() > polyIdx && closePoly.get(polyIdx) != null && ((boolean)closePoly.get(polyIdx))) {
pointIndices.get(pointIndices.size() - 1).add(idx);
}
idx += nbNode;
polyIdx++;
}
} catch (IndexOutOfBoundsException ignore) {
} catch (IndexOutOfBoundsException err) {
logger.error(err);
}

if(isZReversed(crs)){
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/geosiris/energyml/pkg/EPCPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public JAXBElement<?> parseXmlContent(String xmlContent, boolean alternateDevVer
logger.debug("Success reading with '" + this.packagePath + "' object class : "
+ result.getValue().getClass().getName());
} else {
logger.error("error reading with package " + this.packagePath);
logger.error("error reading with package " + this.packagePath); // + " --> " + xmlContent);
}

long ticEnd = System.currentTimeMillis();
Expand Down
32 changes: 27 additions & 5 deletions src/main/java/com/geosiris/energyml/pkg/EpcHdf5FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -38,7 +39,7 @@
public class EpcHdf5FileManager implements EnergymlWorkspace {
public static Logger logger = LogManager.getLogger(EpcHdf5FileManager.class);

private EPCFile epcFile = null;
private final EPCFile epcFile;

private EpcHdf5FileManager(EPCFile epc){
super();
Expand Down Expand Up @@ -127,7 +128,8 @@ public static List<String> getHdf5PathFromExternalPath(
Object rootObj,
EPCFile epc
) {
if (externalPathObj instanceof String) {
logger.debug("{} {}", externalPathObj, pathInRoot);
if (externalPathObj instanceof String && pathInRoot != null) {
// externalPathObj is maybe an attribute of an ExternalDataArrayPart, now search upper in the object
String upperPath = pathInRoot.substring(0, pathInRoot.lastIndexOf("."));
return getHdf5PathFromExternalPath(
Expand All @@ -145,6 +147,7 @@ public static List<String> getHdf5PathFromExternalPath(
} else {
List<Object> hdfProxyLst = searchAttributeMatchingName(externalPathObj, "HdfProxy");
List<Object> extFileProxyLst = searchAttributeMatchingName(externalPathObj, "ExternalFileProxy");
List<Object> extDataArrayPart = searchAttributeMatchingName(externalPathObj, "ExternalDataArrayPart");

// resqml 2.0.1
if (!hdfProxyLst.isEmpty()) {
Expand Down Expand Up @@ -175,9 +178,28 @@ public static List<String> getHdf5PathFromExternalPath(
);
return getH5PathPossibilities((String) ObjectController.getObjectAttributeValue(extPartRefObj, "Filename"), epc);
}

// resqml 2.2
if(!extDataArrayPart.isEmpty()){
logger.debug(extDataArrayPart);
List<String> result = new ArrayList<>();
for(var edap: extDataArrayPart){
result.addAll(getHdf5PathFromExternalPath(
edap,
null,
rootObj,
epc
));
}
return result;
}

// Nothing found here, try with epc name
String epcPath = epc.getFilePath();
return List.of(epcPath.substring(0, epcPath.length()-4) + ".h5");
}

return null;
return new ArrayList<>();
}

public EPCFile getEpcFile() {
Expand All @@ -203,13 +225,13 @@ public Object getObjectByUUID(String uuid) {
public List<?> readExternalArray(Object energyml_array, Object energymlObject, String pathInHDF) throws ObjectNotFoundNotError {
List<String> h5filePaths;
try {
h5filePaths = getHdf5PathFromExternalPath(energymlObject, null, energymlObject, this.epcFile);
h5filePaths = getHdf5PathFromExternalPath(energyml_array, null, energymlObject, this.epcFile);
}catch (Exception e){
logger.error(e);
throw e;
}
String pathInExternal = getHdfReference(energyml_array).get(0);

logger.debug(h5filePaths);
List<?> resultArray = null;
assert h5filePaths != null;
for(String hdf5Path: h5filePaths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,30 @@ public static List<?> readPoint3dZValueArray(Object energymlArray, Object rootOb
workspace
);
Object zvalues = ObjectController.getObjectAttributeValue(energymlArray, "ZValues");
List<?> zvaluesArray = readArray(
zvalues,
rootObj,
pathInRoot + ".ZValues",
workspace
);
List<?> zvaluesArray = new ArrayList<>();

List<Double> zvalueFlat = null;
if(zvaluesArray.get(0) instanceof Collection){
zvalueFlat = ((List<List<?>>)zvaluesArray).stream().flatMap(List::stream).map(z-> z instanceof String ? Double.parseDouble((String) z) : ((Number)z).doubleValue()).collect(Collectors.toList());
}else{
zvalueFlat = zvaluesArray.stream().map(z-> z instanceof String ? Double.parseDouble((String) z) : ((Number)z).doubleValue()).collect(Collectors.toList());
try {
zvaluesArray = readArray(
zvalues,
rootObj,
pathInRoot + ".ZValues",
workspace
);
}catch (InvocationTargetException e){
logger.error("Failed to read Z values for {}", energymlArray);
}
// logger.info("supGeomArray : {}", (((List<?>)supGeomArray.get(0)).get(0)));
// logger.info("zvaluesArrayNotFlat");

if(!zvaluesArray.isEmpty()) {
List<Double> zvalueFlat = null;
if(zvaluesArray.get(0) instanceof Collection){
zvalueFlat = ((List<List<?>>)zvaluesArray).stream().flatMap(List::stream).map(z-> z instanceof String ? Double.parseDouble((String) z) : ((Number)z).doubleValue()).collect(Collectors.toList());
}else{
zvalueFlat = zvaluesArray.stream().map(z-> z instanceof String ? Double.parseDouble((String) z) : ((Number)z).doubleValue()).collect(Collectors.toList());
}
// logger.info("supGeomArray : {}", (((List<?>)supGeomArray.get(0)).get(0)));
// logger.info("zvaluesArrayNotFlat");


if(supGeomArray.get(0) instanceof Collection && !(((List<?>)supGeomArray.get(0)).get(0) instanceof Collection)){
// supGeom is List<List<Double>>, a list of points
// final int colSize = ((List<List<?>>)supGeomArray).get(0).size();
Expand Down Expand Up @@ -484,7 +491,7 @@ public static List<List<List<Double>>> readPoint3dLatticeArray(
}catch (Exception e){
logger.error(e);
}
logger.error(result);
logger.debug(result);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;


public class EPCPackageTest {
public static Logger logger = LogManager.getLogger(EPCPackage.class);

@Test
void testPkgInformation() throws EPCPackageInitializationException {
EPCPackage pkg22 = new EPCPackage("energyml.resqml2_2", "");

assert pkg22.getDomainVersion().compareTo("2.2") == 0;
assert pkg22.getVersionNum().compareTo("2.2") == 0;
assert pkg22.getPackagePath().compareTo("energyml.resqml2_2") == 0;
Expand Down

0 comments on commit 5dfb9e6

Please sign in to comment.