Skip to content

Commit

Permalink
simplify function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Dec 11, 2024
1 parent dac6271 commit 7506f38
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -417,10 +418,11 @@ public void generateReceivers(Connection connection, int cellI, int cellJ, Strin

List<Geometry> sourceDelaunayGeometries = data.sourceGeometries;

ArrayList<Building> buildings = new ArrayList<>();
List<Building> buildings = new LinkedList<>();
List<Wall> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -98,39 +100,41 @@ 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<CnossosPath> pathsParameter) {
public double[] addPropagationPaths(CutPointSource source, CutPointReceiver receiver, List<CnossosPath> 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) {
// copy ray for each time period because absorption is different for each period
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -8719,10 +8720,9 @@ public RayOut(boolean keepRays, AttenuationCnossosParameters pathData, DirectPro
}

@Override
public double[] computeCnossosAttenuation(AttenuationCnossosParameters data, long sourceId, double sourceLi, long receiverId, List<CnossosPath> 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<CnossosPath> pathParameters) {
double[] attenuation = super.computeCnossosAttenuation(data, sourceId, sourceLi, pathParameters);
return wToDba(multArray(processData.wjSources.get((int)sourceId), dbaToW(attenuation)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ public RayOut(boolean keepRays, AttenuationCnossosParameters pathData, DirectPat
}

@Override
public double[] computeCnossosAttenuation(AttenuationCnossosParameters data, long sourceId, double sourceLi, long receiverId, List<CnossosPath> 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<CnossosPath> pathParameters) {
double[] attenuation = super.computeCnossosAttenuation(data, sourceId, sourceLi, pathParameters);
return wToDba(multArray(processData.wjSources.get(sourceId), dbaToW(attenuation)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class PathFinderTest {
/**
* Overwrite project resource expected test cases
*/
public boolean overwriteTestCase = true;
public boolean overwriteTestCase = false;

/**
* Error for coordinates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<CnossosPath> path) {
public double[] addPropagationPaths(CutPointSource source, CutPointReceiver receiver, List<CnossosPath> 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];
Expand All @@ -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<CnossosPath> pathParameters) {
public double[] computeCnossosAttenuation(AttenuationCnossosParameters data, int sourceId, double sourceLi, List<CnossosPath> pathParameters) {
if (data == null) {
return new double[0];
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CnossosPath> path) {
double[] aGlobalMeteo = multiThreadParent.computeCnossosAttenuation(attenuationCnossosParameters, sourceId, sourceLi, receiverId, path);
public double[] addPropagationPaths(CutPointSource source, CutPointReceiver receiver, List<CnossosPath> 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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class Path {
private List<PointPath> pointList; // list of points (source, receiver or diffraction and reflection points)
private List<SegmentPath> 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
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 7506f38

Please sign in to comment.