Skip to content

Commit

Permalink
Fix 11 24 (#29)
Browse files Browse the repository at this point in the history
* bugfix in pointSet loading

* reading resqml22.Grid2DRepresentation in mesh
  • Loading branch information
valentin-gauthier-geosiris authored Dec 3, 2024
1 parent 93071c9 commit ccbc011
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/geosiris/energyml/data/Mesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.geosiris.energyml.exception.NotImplementedException;
import com.geosiris.energyml.exception.ObjectNotFoundNotError;
import com.geosiris.energyml.utils.EPCGenericManager;
import com.geosiris.energyml.utils.EnergymlWorkspace;
import com.geosiris.energyml.utils.EnergymlWorkspaceHelper;
import com.geosiris.energyml.utils.ObjectController;
Expand Down Expand Up @@ -266,6 +267,9 @@ public static List<SurfaceMesh> readGrid2dRepresentationHolable(Object energymlO

long patchIdx = 0;
var patchPathInObjMap = searchAttributeMatchingNameWithPath(energymlObject, "Grid2dPatch");
if(EPCGenericManager.getObjectQualifiedType(energymlObject).contains("resqml22.")){
patchPathInObjMap.put("", energymlObject); // Resqml 22
}
for (Map.Entry<String, Object> e : patchPathInObjMap.entrySet()) {
String patchPath = e.getKey();
Object patch = e.getValue();
Expand Down Expand Up @@ -346,6 +350,9 @@ public static List<GridedPointSetMesh> readGrid2dRepresentationPoints(Object ene

long patchIdx = 0;
var patchPathInObjMap = searchAttributeMatchingNameWithPath(energymlObject, "Grid2dPatch");
if(EPCGenericManager.getObjectQualifiedType(energymlObject).contains("resqml22.")){
patchPathInObjMap.put("", energymlObject); // Resqml 22
}
for (Map.Entry<String, Object> e : patchPathInObjMap.entrySet()) {
String patchPath = e.getKey();
Object patch = e.getValue();
Expand Down Expand Up @@ -480,4 +487,5 @@ public static List<SurfaceMesh> readTriangulatedSetRepresentation(Object energym

return meshes;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static List<String> getHdf5PathFromExternalPath(
}
Object extPartRefObj = epc.getObjectByIdentifier(
EPCFile.getIdentifier(
ObjectController.getObjectAttributeValueRgx(extFileProxy, "epcExternalPartReference")
ObjectController.getObjectAttributeValueRgx(extFileProxy, "epcExternalPartReference").get(0)
)
);
return getH5PathPossibilities((String) ObjectController.getObjectAttributeValue(extPartRefObj, "Filename"), epc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static Object getCrsObj(
EnergymlWorkspace workspace
) throws ObjectNotFoundNotError {
if (workspace == null) {
System.out.println("@get_crs_obj no Epc file given");
logger.error("@get_crs_obj no Epc file given");
} else {
List<Object> crsList = searchAttributeMatchingName(contextObj, "\\.*Crs", Pattern.CASE_INSENSITIVE, "", false, true);
if (!crsList.isEmpty()) {
Expand Down Expand Up @@ -111,10 +111,13 @@ public static Object getCrsObj(
}

public static List<Double> pointAsArray(Object point) {
Object c1 = ObjectController.getObjectAttributeValue(point, "coordinate1");
Object c2 = ObjectController.getObjectAttributeValue(point, "coordinate2");
Object c3 = ObjectController.getObjectAttributeValue(point, "coordinate3");
return new ArrayList<>(Arrays.asList(
Double.valueOf(String.valueOf(ObjectController.getObjectAttributeValue(point, "coordinate1"))),
Double.valueOf(String.valueOf(ObjectController.getObjectAttributeValue(point, "coordinate2"))),
Double.valueOf(String.valueOf(ObjectController.getObjectAttributeValue(point, "coordinate3")))
c1 != null ? Double.valueOf(String.valueOf(c1)) : null,
c2 != null ? Double.valueOf(String.valueOf(c2)) : null,
c3 != null ? Double.valueOf(String.valueOf(c3)) : null
));
}

Expand Down Expand Up @@ -143,7 +146,7 @@ public static boolean isZReversed(Object crs) {
}

public static List<Double> prodNTab(Double val, List<Double> tab) {
return tab.stream().map(x -> x * val).collect(Collectors.toList());
return tab.stream().map(x -> val != null && x != null ? x * val: null).collect(Collectors.toList());
}

public static List<Double> sumLists(List<Double> l1, List<Double> l2) {
Expand Down Expand Up @@ -361,9 +364,9 @@ public static List<?> readGrid2dPatch(
EnergymlWorkspace workspace
) throws InvocationTargetException, IllegalAccessException, NotImplementedException {
Map<String, Object> pointsPathAndPointsObj = ObjectController.searchAttributeMatchingNameWithPath(patch, "Geometry.Points");
pointsPathAndPointsObj.putAll(ObjectController.searchAttributeMatchingNameWithPath(patch, "Points"));
String pointsPath = pointsPathAndPointsObj.keySet().stream().findFirst().get();
Object pointsObj = pointsPathAndPointsObj.get(pointsPath);

return readArray(pointsObj, grid2d, pathInRoot + pointsPath, workspace);
}

Expand All @@ -376,18 +379,17 @@ public static List<List<List<Double>>> readPoint3dLatticeArray(
List<List<List<Double>>> result = new ArrayList<>();
try {
List<Double> origin = pointAsArray(ObjectController.getObjectAttributeValue(energymlArray, "origin"));
List<Object> offset = (List<Object>) ObjectController.getObjectAttributeValue(energymlArray, "offset");
if (offset.size() == 2) {
Object slowest = offset.get(0);
Object fastest = offset.get(1);
List<?> offset = ObjectController.getObjectAttributeValueRgx(energymlArray, "offset|dimension");
if (((List<?>)offset.get(0)).size() == 2) {
Object slowest = ((List<?>)offset.get(0)).get(0);
Object fastest = ((List<?>)offset.get(0)).get(1);

List<Integer> crsSaCount = ((List<Number>) searchAttributeInUpperMatchingName(energymlArray, "SlowestAxisCount", rootObj, pathInRoot)).stream()
.map(n -> n.intValue())
.collect(Collectors.toList());
List<Integer> crsFaCount = ((List<Number>) searchAttributeInUpperMatchingName(energymlArray, "FastestAxisCount", rootObj, pathInRoot)).stream()
.map(n -> n.intValue())
.collect(Collectors.toList());

Object crs = null;
try {
crs = getCrsObj(energymlArray, pathInRoot, rootObj, workspace);
Expand All @@ -397,15 +399,16 @@ public static List<List<List<Double>>> readPoint3dLatticeArray(

boolean zIncreasingDownward = isZReversed(crs);

List<Double> slowestVec = pointAsArray(ObjectController.getObjectAttributeValue(slowest, "offset"));
List<Double> slowestVec = pointAsArray(ObjectController.getObjectAttributeValueRgx(slowest, "offset|direction").get(0));

// List<Double> slowestSpacing = (List<Double>) readArray(ObjectController.getObjectAttributeValue(slowest, "spacing"));
List<Double> slowestSpacing = (List<Double>) readArray(ObjectController.getObjectAttributeValue(zIncreasingDownward ? fastest: slowest, "spacing"));
List<List<Double>> slowestTable = new ArrayList<>();
for (Object spacing : slowestSpacing) {
slowestTable.add(prodNTab(Double.valueOf(String.valueOf(spacing)), slowestVec));
for (Double spacing : slowestSpacing) {
slowestTable.add(prodNTab(spacing, slowestVec));
}

List<Double> fastestVec = pointAsArray(ObjectController.getObjectAttributeValue(fastest, "offset"));
List<Double> fastestVec = pointAsArray(ObjectController.getObjectAttributeValueRgx(fastest, "offset|direction").get(0));
// List<Double> fastestSpacing = (List<Double>) readArray(ObjectController.getObjectAttributeValue(fastest, "spacing"));
List<Double> fastestSpacing = (List<Double>) readArray(ObjectController.getObjectAttributeValue(zIncreasingDownward ? slowest: fastest, "spacing"));
List<List<Double>> fastestTable = new ArrayList<>();
Expand Down Expand Up @@ -481,6 +484,7 @@ public static List<List<List<Double>>> readPoint3dLatticeArray(
}catch (Exception e){
logger.error(e);
}
logger.error(result);

return result;
}
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/com/geosiris/energyml/utils/ObjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,11 @@ public static Object getObjectAttributeValue(Object obj, String pathAttribute) {

public static List<Method> getAttributeAccessMethodRgx(Object obj, String attributeRgx){
List<Method> res = new ArrayList<>();
Pattern pat = Pattern.compile("(get|is)?" + attributeRgx, Pattern.CASE_INSENSITIVE);
Pattern pat = Pattern.compile("(get|is)?(" + attributeRgx +")", Pattern.CASE_INSENSITIVE);
for(Method m : obj.getClass().getMethods()){
if (m.getParameterCount() == 0) {
Matcher matcher = pat.matcher(m.getName());
if (matcher.find()) {
if (matcher.matches()) {
res.add(m);
}
}
Expand All @@ -757,7 +757,7 @@ public static List<Method> getAttributeAccessMethodRgx(Object obj, String attrib
}

public static List<Object> getObjectAttributeValueRgx(Object obj, String pathAttribute) {
if(obj == null) return null;
if(obj == null) return new ArrayList<>();
String attribute = pathAttribute;
while (attribute.startsWith(".")) {
attribute = attribute.substring(1);
Expand Down Expand Up @@ -806,9 +806,10 @@ public static List<Object> getObjectAttributeValueRgx(Object obj, String pathAtt
}

if (pathAttribute.contains(".")) {
final String nextAttribt = pathAttribute.substring(attribute.length() + 1);
final String nextAttrib = pathAttribute.substring(attribute.length() + 1);
List<Object> flatten = new ArrayList<>();
result.stream().map(r -> getObjectAttributeValueRgx(r, nextAttribt)).forEach(l -> flatten.addAll((List<Object>) l));
// return result.stream().map(r -> getObjectAttributeValueRgx(r, nextAttrib)).flatMap(List::stream).collect(Collectors.toList());
result.stream().map(r -> getObjectAttributeValueRgx(r, nextAttrib)).filter(l -> l != null).forEach(l -> flatten.addAll((List<Object>) l));
return flatten;
} else {
return result;
Expand Down Expand Up @@ -1261,7 +1262,7 @@ public static Object searchAttributeInUpperMatchingName(
return eltList;
}

if (obj != rootObj) {
if (!currentPath.isEmpty()){ //(obj != rootObj) {
String upperPath = currentPath.substring(0, currentPath.lastIndexOf("."));
if (!upperPath.isEmpty()) {
return searchAttributeInUpperMatchingName(
Expand All @@ -1271,6 +1272,14 @@ public static Object searchAttributeInUpperMatchingName(
reFlags,
upperPath
);
}else{
return searchAttributeInUpperMatchingName(
rootObj,
nameRgx,
rootObj,
reFlags,
upperPath
);
}
}

Expand Down

0 comments on commit ccbc011

Please sign in to comment.