From 7506f386c25a10b0b590db5332fc1942207be1c4 Mon Sep 17 00:00:00 2001 From: nicolas-f <1382241+nicolas-f@users.noreply.github.com> Date: Wed, 11 Dec 2024 15:20:11 +0100 Subject: [PATCH] simplify function signature --- .../jdbc/DelaunayReceiversMaker.java | 6 ++-- .../noisemodelling/jdbc/NoiseMapInStack.java | 36 ++++++++++--------- .../jdbc/AttenuationCnossosTest.java | 12 +++---- .../noisemodelling/jdbc/Utils.java | 7 ++-- .../pathfinder/PathFinderTest.java | 2 +- .../propagation/Attenuation.java | 26 ++++++-------- .../propagation/AttenuationVisitor.java | 36 +++++++++---------- .../propagation/cnossos/Path.java | 12 +++---- 8 files changed, 66 insertions(+), 71 deletions(-) diff --git a/noisemodelling-jdbc/src/main/java/org/noise_planet/noisemodelling/jdbc/DelaunayReceiversMaker.java b/noisemodelling-jdbc/src/main/java/org/noise_planet/noisemodelling/jdbc/DelaunayReceiversMaker.java index c1717ebd3..19e7c2d70 100644 --- a/noisemodelling-jdbc/src/main/java/org/noise_planet/noisemodelling/jdbc/DelaunayReceiversMaker.java +++ b/noisemodelling-jdbc/src/main/java/org/noise_planet/noisemodelling/jdbc/DelaunayReceiversMaker.java @@ -27,6 +27,7 @@ import org.noise_planet.noisemodelling.pathfinder.delaunay.LayerDelaunayError; import org.noise_planet.noisemodelling.pathfinder.delaunay.LayerTinfour; import org.noise_planet.noisemodelling.pathfinder.profilebuilder.Building; +import org.noise_planet.noisemodelling.pathfinder.profilebuilder.Wall; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -417,10 +418,11 @@ public void generateReceivers(Connection connection, int cellI, int cellJ, Strin List sourceDelaunayGeometries = data.sourceGeometries; - ArrayList buildings = new ArrayList<>(); + List buildings = new LinkedList<>(); + List walls = new LinkedList<>(); Envelope expandedCell = new Envelope(cellEnvelope); expandedCell.expandBy(buildingBuffer); - fetchCellBuildings(connection, cellEnvelope, buildings); + fetchCellBuildings(connection, cellEnvelope, buildings, walls); LayerTinfour cellMesh = new LayerTinfour(); cellMesh.setEpsilon(epsilon); diff --git a/noisemodelling-jdbc/src/main/java/org/noise_planet/noisemodelling/jdbc/NoiseMapInStack.java b/noisemodelling-jdbc/src/main/java/org/noise_planet/noisemodelling/jdbc/NoiseMapInStack.java index b34bed911..7b24ea16a 100644 --- a/noisemodelling-jdbc/src/main/java/org/noise_planet/noisemodelling/jdbc/NoiseMapInStack.java +++ b/noisemodelling-jdbc/src/main/java/org/noise_planet/noisemodelling/jdbc/NoiseMapInStack.java @@ -11,6 +11,8 @@ import org.noise_planet.noisemodelling.pathfinder.IComputePathsOut; import org.noise_planet.noisemodelling.pathfinder.path.Scene; +import org.noise_planet.noisemodelling.pathfinder.profilebuilder.CutPointReceiver; +import org.noise_planet.noisemodelling.pathfinder.profilebuilder.CutPointSource; import org.noise_planet.noisemodelling.pathfinder.profilebuilder.CutProfile; import org.noise_planet.noisemodelling.propagation.cnossos.CnossosPath; import org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions; @@ -86,7 +88,7 @@ public PathSearchStrategy onNewCutPlane(CutProfile cutProfile) { CnossosPath cnossosPath = CnossosPathBuilder.computeAttenuationFromCutProfile(cutProfile, scene.isBodyBarrier(), scene.freq_lvl, scene.gS); if(cnossosPath != null) { - addPropagationPaths(cutProfile.getSource().id, cutProfile.getSource().li, cutProfile.getReceiver().id, + addPropagationPaths(cutProfile.getSource(), cutProfile.getReceiver(), Collections.singletonList(cnossosPath)); } return PathSearchStrategy.CONTINUE; @@ -98,30 +100,32 @@ public PathSearchStrategy onNewCutPlane(CutProfile cutProfile) { * @param sourceLi Source power per meter coefficient * @param pathsParameter Propagation path result */ - public double[] addPropagationPaths(long sourceId, double sourceLi, long receiverId, List pathsParameter) { + public double[] addPropagationPaths(CutPointSource source, CutPointReceiver receiver, List pathsParameter) { + + long receiverId = receiver.receiverPk == -1 ? receiver.id : receiver.receiverPk; + long sourceId = source.sourcePk == -1 ? source.id : source.sourcePk; + noiseMapComputeRaysOut.rayCount.addAndGet(pathsParameter.size()); if(noiseMapComputeRaysOut.exportPaths && !noiseMapComputeRaysOut.exportAttenuationMatrix) { for(CnossosPath cnossosPath : pathsParameter) { // Use only one ray as the ray is the same if we not keep absorption values - if (noiseMapComputeRaysOut.inputData != null && sourceId < noiseMapComputeRaysOut.inputData.sourcesPk.size() && receiverId < noiseMapComputeRaysOut.inputData.receiversPk.size()) { - // Copy path content in order to keep original ids for other method calls - cnossosPath.setIdReceiver(noiseMapComputeRaysOut.inputData.receiversPk.get((int) receiverId).intValue()); - cnossosPath.setIdSource(noiseMapComputeRaysOut.inputData.sourcesPk.get((int) sourceId).intValue()); - this.pathParameters.add(cnossosPath); - } else { - this.pathParameters.add(cnossosPath); - } + // Copy path content in order to keep original ids for other method calls + cnossosPath.setIdReceiver(receiverId); + cnossosPath.setIdSource(sourceId); + this.pathParameters.add(cnossosPath); } } + double[] globalLevel = null; for(NoiseMapParameters.TIME_PERIOD timePeriod : NoiseMapParameters.TIME_PERIOD.values()) { for(CnossosPath pathParameters : pathsParameter) { if (globalLevel == null) { - globalLevel = lDENAttenuationVisitor[timePeriod.ordinal()].addPropagationPaths(sourceId, sourceLi, - receiverId, Collections.singletonList(pathParameters)); + globalLevel = lDENAttenuationVisitor[timePeriod.ordinal()].addPropagationPaths(source, + receiver, Collections.singletonList(pathParameters)); } else { - globalLevel = AcousticIndicatorsFunctions.sumDbArray(globalLevel, lDENAttenuationVisitor[timePeriod.ordinal()].addPropagationPaths(sourceId, sourceLi, - receiverId, Collections.singletonList(pathParameters))); + globalLevel = AcousticIndicatorsFunctions.sumDbArray(globalLevel, + lDENAttenuationVisitor[timePeriod.ordinal()].addPropagationPaths(source, + receiver, Collections.singletonList(pathParameters))); } pathParameters.setTimePeriod(timePeriod.name()); if(noiseMapComputeRaysOut.exportPaths && noiseMapComputeRaysOut.exportAttenuationMatrix) { @@ -129,8 +133,8 @@ public double[] addPropagationPaths(long sourceId, double sourceLi, long receive if (noiseMapComputeRaysOut.inputData != null && sourceId < noiseMapComputeRaysOut.inputData.sourcesPk.size() && receiverId < noiseMapComputeRaysOut.inputData.receiversPk.size()) { // Copy path content in order to keep original ids for other method calls CnossosPath pathParametersPk = new CnossosPath(pathParameters); - pathParametersPk.setIdReceiver(noiseMapComputeRaysOut.inputData.receiversPk.get((int) receiverId).intValue()); - pathParametersPk.setIdSource(noiseMapComputeRaysOut.inputData.sourcesPk.get((int) sourceId).intValue()); + pathParametersPk.setIdReceiver(receiver.receiverPk == -1 ? receiver.id : receiver.receiverPk); + pathParametersPk.setIdSource(source.sourcePk == -1 ? source.id : source.sourcePk); this.pathParameters.add(pathParametersPk); } else { this.pathParameters.add(pathParameters); diff --git a/noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/AttenuationCnossosTest.java b/noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/AttenuationCnossosTest.java index 5cb96152d..66da5d8b1 100644 --- a/noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/AttenuationCnossosTest.java +++ b/noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/AttenuationCnossosTest.java @@ -1772,6 +1772,9 @@ public void TC07() throws IOException { expectedZProfile.add(new Coordinate(170.23, 0.00)); expectedZProfile.add(new Coordinate(194.16, 0.00)); + assertZProfil(expectedZProfile, + Arrays.asList(propDataOut.getPropagationPaths().get(0).getSRSegment().getPoints2DGround())); + /* Table 34 */ Coordinate expectedSPrime =new Coordinate(0.00,-1.00); Coordinate expectedRPrime =new Coordinate(194.16,-4.00); @@ -1796,8 +1799,6 @@ public void TC07() throws IOException { //Assertion - assertZProfil(expectedZProfile, - Arrays.asList(propDataOut.getPropagationPaths().get(0).getSRSegment().getPoints2DGround())); assertPlanes(segmentsMeanPlanes, propDataOut.getPropagationPaths().get(0).getSegmentList()); //Expected values @@ -8719,10 +8720,9 @@ public RayOut(boolean keepRays, AttenuationCnossosParameters pathData, DirectPro } @Override - public double[] computeCnossosAttenuation(AttenuationCnossosParameters data, long sourceId, double sourceLi, long receiverId, List propagationPath) { - double[] attenuation = super.computeCnossosAttenuation(data, sourceId, sourceLi, receiverId, propagationPath); - double[] soundLevel = wToDba(multArray(processData.wjSources.get((int)sourceId), dbaToW(attenuation))); - return soundLevel; + public double[] computeCnossosAttenuation(AttenuationCnossosParameters data, int sourceId, double sourceLi, List pathParameters) { + double[] attenuation = super.computeCnossosAttenuation(data, sourceId, sourceLi, pathParameters); + return wToDba(multArray(processData.wjSources.get((int)sourceId), dbaToW(attenuation))); } } diff --git a/noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/Utils.java b/noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/Utils.java index a790e1234..d63aea2db 100644 --- a/noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/Utils.java +++ b/noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/Utils.java @@ -111,10 +111,9 @@ public RayOut(boolean keepRays, AttenuationCnossosParameters pathData, DirectPat } @Override - public double[] computeCnossosAttenuation(AttenuationCnossosParameters data, long sourceId, double sourceLi, long receiverId, List pathParameters) { - double[] attenuation = super.computeCnossosAttenuation(data, sourceId, sourceLi, receiverId, pathParameters); - double[] soundLevel = wToDba(multArray(processData.wjSources.get((int)sourceId), dbaToW(attenuation))); - return soundLevel; + public double[] computeCnossosAttenuation(AttenuationCnossosParameters data, int sourceId, double sourceLi, List pathParameters) { + double[] attenuation = super.computeCnossosAttenuation(data, sourceId, sourceLi, pathParameters); + return wToDba(multArray(processData.wjSources.get(sourceId), dbaToW(attenuation))); } } diff --git a/noisemodelling-pathfinder/src/test/java/org/noise_planet/noisemodelling/pathfinder/PathFinderTest.java b/noisemodelling-pathfinder/src/test/java/org/noise_planet/noisemodelling/pathfinder/PathFinderTest.java index 084e758b2..4be1ab9b1 100644 --- a/noisemodelling-pathfinder/src/test/java/org/noise_planet/noisemodelling/pathfinder/PathFinderTest.java +++ b/noisemodelling-pathfinder/src/test/java/org/noise_planet/noisemodelling/pathfinder/PathFinderTest.java @@ -49,7 +49,7 @@ public class PathFinderTest { /** * Overwrite project resource expected test cases */ - public boolean overwriteTestCase = true; + public boolean overwriteTestCase = false; /** * Error for coordinates diff --git a/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/Attenuation.java b/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/Attenuation.java index 569508b67..af4591007 100644 --- a/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/Attenuation.java +++ b/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/Attenuation.java @@ -13,6 +13,8 @@ import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.math.Vector3D; import org.noise_planet.noisemodelling.pathfinder.*; +import org.noise_planet.noisemodelling.pathfinder.profilebuilder.CutPointReceiver; +import org.noise_planet.noisemodelling.pathfinder.profilebuilder.CutPointSource; import org.noise_planet.noisemodelling.pathfinder.profilebuilder.CutProfile; import org.noise_planet.noisemodelling.propagation.cnossos.CnossosPath; import org.noise_planet.noisemodelling.pathfinder.path.Scene; @@ -91,8 +93,7 @@ public PathSearchStrategy onNewCutPlane(CutProfile cutProfile) { CnossosPath cnossosPath = CnossosPathBuilder.computeAttenuationFromCutProfile(cutProfile, scene.isBodyBarrier(), scene.freq_lvl, scene.gS); if(cnossosPath != null) { - addPropagationPaths(cutProfile.getSource().id, cutProfile.getSource().li, cutProfile.getReceiver().id, - Collections.singletonList(cnossosPath)); + addPropagationPaths(cutProfile.getSource(), cutProfile.getReceiver(), Collections.singletonList(cnossosPath)); } return PathSearchStrategy.CONTINUE; } @@ -103,23 +104,16 @@ public PathSearchStrategy onNewCutPlane(CutProfile cutProfile) { * @param sourceLi Source power per meter coefficient * @param path Propagation path result */ - public double[] addPropagationPaths(long sourceId, double sourceLi, long receiverId, List path) { + public double[] addPropagationPaths(CutPointSource source, CutPointReceiver receiver, List path) { rayCount.addAndGet(path.size()); if(exportPaths) { pathParameters.addAll(path); propagationPathsSize.addAndGet(path.size()); } - double[] aGlobalMeteo = computeCnossosAttenuation(genericMeteoData, sourceId, sourceLi, receiverId, path); + double[] aGlobalMeteo = computeCnossosAttenuation(genericMeteoData, source.id, source.li, path); if (aGlobalMeteo != null && aGlobalMeteo.length > 0) { - if(inputData != null) { - if(sourceId < inputData.sourcesPk.size()) { - sourceId = inputData.sourcesPk.get((int)sourceId); - } - if(receiverId < inputData.receiversPk.size()) { - receiverId = inputData.receiversPk.get((int)receiverId); - } - } - receiversAttenuationLevels.add(new SourceReceiverAttenuation(receiverId, sourceId, aGlobalMeteo)); + receiversAttenuationLevels.add(new SourceReceiverAttenuation(receiver.receiverPk == -1 ? receiver.id : receiver.receiverPk, + source.sourcePk == -1 ? source.id : source.sourcePk, aGlobalMeteo)); return aGlobalMeteo; } else { return new double[0]; @@ -135,7 +129,7 @@ public double[] addPropagationPaths(long sourceId, double sourceLi, long receive * @param pathParameters * @return double list of attenuation */ - public double[] computeCnossosAttenuation(AttenuationCnossosParameters data, long sourceId, double sourceLi, long receiverId, List pathParameters) { + public double[] computeCnossosAttenuation(AttenuationCnossosParameters data, int sourceId, double sourceLi, List pathParameters) { if (data == null) { return new double[0]; } @@ -327,9 +321,9 @@ public double[] computeCnossosAttenuation(AttenuationCnossosParameters data, lon double[] aGlobalMeteoRay = sumArrayWithPonderation(aGlobalMeteoFav, aGlobalMeteoHom, data.getWindRose()[roseIndex]); // Apply attenuation due to sound direction - if(inputData != null && !inputData.isOmnidirectional((int)sourceId)) { + if(inputData != null && !inputData.isOmnidirectional(sourceId)) { Orientation directivityToPick = proPathParameters.raySourceReceiverDirectivity; - double[] attSource = inputData.getSourceAttenuation((int) sourceId, + double[] attSource = inputData.getSourceAttenuation( sourceId, frequencies, Math.toRadians(directivityToPick.yaw), Math.toRadians(directivityToPick.pitch)); if(exportAttenuationMatrix) { diff --git a/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/AttenuationVisitor.java b/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/AttenuationVisitor.java index 5b268042a..3cac4eeb8 100644 --- a/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/AttenuationVisitor.java +++ b/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/AttenuationVisitor.java @@ -11,6 +11,8 @@ import org.noise_planet.noisemodelling.pathfinder.IComputePathsOut; import org.noise_planet.noisemodelling.pathfinder.path.Scene; +import org.noise_planet.noisemodelling.pathfinder.profilebuilder.CutPointReceiver; +import org.noise_planet.noisemodelling.pathfinder.profilebuilder.CutPointSource; import org.noise_planet.noisemodelling.pathfinder.profilebuilder.CutProfile; import org.noise_planet.noisemodelling.pathfinder.utils.AcousticIndicatorsFunctions; import org.noise_planet.noisemodelling.propagation.cnossos.CnossosPath; @@ -45,39 +47,33 @@ public PathSearchStrategy onNewCutPlane(CutProfile cutProfile) { CnossosPath cnossosPath = CnossosPathBuilder.computeAttenuationFromCutProfile(cutProfile, scene.isBodyBarrier(), scene.freq_lvl, scene.gS); if(cnossosPath != null) { - addPropagationPaths(cutProfile.getSource().id, cutProfile.getSource().li, cutProfile.getReceiver().id, - Collections.singletonList(cnossosPath)); + addPropagationPaths(cutProfile.getSource(), cutProfile.getReceiver(), Collections.singletonList(cnossosPath)); } return PathSearchStrategy.CONTINUE; } /** * Get propagation path result - * @param sourceId Source identifier - * @param sourceLi Source power per meter coefficient + * @param source Source identifier + * @param receiver Receiver identifier * @param path Propagation path result */ - public double[] addPropagationPaths(long sourceId, double sourceLi, long receiverId, List path) { - double[] aGlobalMeteo = multiThreadParent.computeCnossosAttenuation(attenuationCnossosParameters, sourceId, sourceLi, receiverId, path); + public double[] addPropagationPaths(CutPointSource source, CutPointReceiver receiver, List path) { + double[] aGlobalMeteo = multiThreadParent.computeCnossosAttenuation(attenuationCnossosParameters, source.id, source.li, path); multiThreadParent.rayCount.addAndGet(path.size()); if(keepRays) { - if(multiThreadParent.inputData != null && sourceId < multiThreadParent.inputData.sourcesPk.size() && - receiverId < multiThreadParent.inputData.receiversPk.size()) { - for(CnossosPath pathParameter : path) { - // Copy path content in order to keep original ids for other method calls - //CnossosPathParameters pathParametersPk = new CnossosPathParameters(pathParameter); - pathParameter.setIdReceiver(multiThreadParent.inputData.receiversPk.get((int)receiverId).intValue()); - pathParameter.setIdSource(multiThreadParent.inputData.sourcesPk.get((int)sourceId).intValue()); - pathParameter.setSourceOrientation(pathParameter.getSourceOrientation()); - pathParameter.setGs(pathParameter.getGs()); - pathParameters.add(pathParameter); - } - } else { - pathParameters.addAll(path); + for(CnossosPath pathParameter : path) { + // Copy path content in order to keep original ids for other method calls + //CnossosPathParameters pathParametersPk = new CnossosPathParameters(pathParameter); + pathParameter.setIdReceiver(receiver.receiverPk == -1 ? receiver.id : receiver.receiverPk); + pathParameter.setIdSource(source.sourcePk == -1 ? source.id : source.sourcePk); + pathParameter.setSourceOrientation(pathParameter.getSourceOrientation()); + pathParameter.setGs(pathParameter.getGs()); + pathParameters.add(pathParameter); } } if (aGlobalMeteo != null) { - receiverAttenuationLevels.add(new Attenuation.SourceReceiverAttenuation(receiverId, sourceId, aGlobalMeteo)); + receiverAttenuationLevels.add(new Attenuation.SourceReceiverAttenuation(receiver.id, source.id, aGlobalMeteo)); return aGlobalMeteo; } else { return new double[0]; diff --git a/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/cnossos/Path.java b/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/cnossos/Path.java index bb6ec4ea9..2476b29c1 100644 --- a/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/cnossos/Path.java +++ b/noisemodelling-propagation/src/main/java/org/noise_planet/noisemodelling/propagation/cnossos/Path.java @@ -44,8 +44,8 @@ public class Path { private List pointList; // list of points (source, receiver or diffraction and reflection points) private List segmentList; // list of segments [S,O1] and [On-1,R] (O1 and On-1 are respectively the first diffraction point and On-1 the last diffration point) private boolean favorable; // if true, favorable meteorological condition path TODO move to cnossospathparameters - public int idSource; - public int idReceiver; + public long idSource; + public long idReceiver; private String timePeriod=""; // time period if relevant (day, evening, night or other parameters, use LDenConfig.TIME_PERIOD) Orientation sourceOrientation = new Orientation(0,0,0); public Orientation raySourceReceiverDirectivity = new Orientation(); // direction of the source->receiver path relative to the source heading @@ -222,19 +222,19 @@ public String profileAsJSON(int sizeLimitation) throws IOException { return byteArrayOutputStream.toString(StandardCharsets.UTF_8); } - public int getIdSource() { + public long getIdSource() { return idSource; } - public void setIdSource(int idSource) { + public void setIdSource(long idSource) { this.idSource = idSource; } - public int getIdReceiver() { + public long getIdReceiver() { return idReceiver; } - public void setIdReceiver(int idReceiver) { + public void setIdReceiver(long idReceiver) { this.idReceiver = idReceiver; }