Skip to content

Commit

Permalink
remove duplicate code, stop propagation early if horizontal edge diff…
Browse files Browse the repository at this point in the history
…raction is disabled and we found an intersection with topo or buildings/Walls
  • Loading branch information
nicolas-f committed Oct 17, 2024
1 parent d3af39f commit ca5f983
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ public void TC01() throws IOException {
//Run computation
computeRays.run(propDataOut);

assertEquals(1, propDataOut.getPropagationPaths().size());

//Expected values
double[] expectedWH = new double[]{0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00};
double[] expectedCfH = new double[]{194.16, 194.16, 194.16, 194.16, 194.16, 194.16, 194.16, 194.16};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,28 +296,24 @@ public List<CnossosPath> directPath(Coordinate srcCoord, int srcId, Orientation
int rcvId, boolean verticalDiffraction, boolean horizontalDiffraction,
boolean bodyBarrier) {
List<CnossosPath> pathsParameters = new ArrayList<>();
CutProfile cutProfile = data.profileBuilder.getProfile(srcCoord, rcvCoord, data.gS);
CutProfile cutProfile = data.profileBuilder.getProfile(srcCoord, rcvCoord, data.gS, !verticalDiffraction);
cutProfile.setSrcOrientation(orientation);
//If the field is free, simplify the computation
if(cutProfile.isFreeField()) {
pathsParameters.add(computeFreeField(cutProfile, data, true));

if(verticalDiffraction || cutProfile.isFreeField()) {
CnossosPath hEdgePath = computeHEdgeDiffraction(cutProfile, bodyBarrier);
if (hEdgePath != null) {
pathsParameters.add(hEdgePath);
}
}
else if(verticalDiffraction || horizontalDiffraction) {
if (verticalDiffraction) {
CnossosPath pathParameters = computeHEdgeDiffraction(cutProfile, bodyBarrier);
if(pathParameters != null) {
pathsParameters.add(pathParameters);
}

if (horizontalDiffraction) {
CnossosPath vEdgePath = computeVEdgeDiffraction(srcCoord, rcvCoord, data, LEFT, orientation);
if (vEdgePath != null && vEdgePath.getPointList() != null) {
pathsParameters.add(vEdgePath);
}
if (horizontalDiffraction) {
CnossosPath pathParameters = computeVEdgeDiffraction(srcCoord, rcvCoord, data, LEFT, orientation);
if (pathParameters != null && pathParameters.getPointList() != null) {
pathsParameters.add(pathParameters);
}
pathParameters = computeVEdgeDiffraction(srcCoord, rcvCoord, data, RIGHT, orientation);
if (pathParameters != null && pathParameters.getPointList() != null) {
pathsParameters.add(pathParameters);
}
vEdgePath = computeVEdgeDiffraction(srcCoord, rcvCoord, data, RIGHT, orientation);
if (vEdgePath != null && vEdgePath.getPointList() != null) {
pathsParameters.add(vEdgePath);
}
}

Expand Down Expand Up @@ -677,7 +673,7 @@ public CnossosPath computeVEdgeDiffraction(Coordinate rcvCoord, Coordinate srcCo
double d = 0;
List<CutPoint> allCutPoints = new ArrayList<>();
for(int i=0; i<coordinates.size()-1; i++) {
CutProfile profile = data.profileBuilder.getProfile(coordinates.get(i), coordinates.get(i+1), data.gS);
CutProfile profile = data.profileBuilder.getProfile(coordinates.get(i), coordinates.get(i+1), data.gS, false);
profile.setSrcOrientation(orientation);
double dist = coordinates.get(i).distance(coordinates.get(i+1));
g+=profile.getGPath()*dist;
Expand Down Expand Up @@ -1342,7 +1338,7 @@ public List<CnossosPath> computeReflexion(Coordinate rcvCoord, Coordinate srcCoo
for (int idPt = 0; idPt < rayPath.size() - 1; idPt++) {
Coordinate firstPt = rayPath.get(idPt).getReceiverPos();
MirrorReceiver refl = rayPath.get(idPt + 1);
CutProfile profile = data.profileBuilder.getProfile(firstPt, refl.getReceiverPos(), data.gS);
CutProfile profile = data.profileBuilder.getProfile(firstPt, refl.getReceiverPos(), data.gS, true);
if (profile.intersectTopography() || profile.intersectBuilding() ) {
validReflection = false;
break;
Expand Down Expand Up @@ -1446,8 +1442,7 @@ public List<CnossosPath> computeReflexion(Coordinate rcvCoord, Coordinate srcCoo
List<CutPoint> allCutPoints = new ArrayList<>();
List<Double> res = new ArrayList<>();
for(int i=0; i<pts.size()-1; i++) {
CutProfile profile = data.profileBuilder.getProfile(pts.get(i), pts.get(i+1), data.gS);
if(i==0)profile.getSource().setGroundCoef(data.gS);
CutProfile profile = data.profileBuilder.getProfile(pts.get(i), pts.get(i+1), data.gS, false);
topoPts.addAll(profile.getCutPoints().stream()
.filter(cut -> cut.getType().equals(BUILDING) || cut.getType().equals(TOPOGRAPHY) || cut.getType().equals(RECEIVER))
.map(CutPoint::getCoordinate)
Expand Down Expand Up @@ -1606,23 +1601,22 @@ public static double splitLineStringIntoPoints(LineString geom, double segmentSi
* @param profileBuilder
* @return computed lineString
*/
private static LineString splitLineString(LineString lineString, ProfileBuilder profileBuilder) {
private static LineString splitLineSource(LineString lineString, ProfileBuilder profileBuilder) {
List<Coordinate> newGeomCoordinates = new ArrayList<>();
Coordinate[] coordinates = lineString.getCoordinates();
for(int idPoint = 0; idPoint < coordinates.length - 1; idPoint++) {
Coordinate p0 = coordinates[idPoint];
Coordinate p1 = coordinates[idPoint + 1];
double p1p0Length = p1.distance(p0);
List<Coordinate> groundProfileCoordinates = profileBuilder.getTopographicProfile(p0, p1);
List<Coordinate> groundProfileCoordinates = new ArrayList<>();
profileBuilder.fetchTopographicProfile(groundProfileCoordinates, p0, p1, false);
// add first point of source
newGeomCoordinates.add(p0);
// add intermediate points located at the edges of MNT triangle mesh
// but the Z value should be still relative to the ground
// ,so we interpolate the Z (height) values of the source
for(Coordinate intermediatePoint : groundProfileCoordinates) {
Vector2D v = new Vector2D(p0, intermediatePoint);
Coordinate relativePoint = new Coordinate(intermediatePoint.x, intermediatePoint.y,
p0.z + ((v.length() / p1p0Length) * (p1.z - p0.z)));
Coordinate relativePoint = new Coordinate(intermediatePoint);
relativePoint.z = Vertex.interpolateZ(intermediatePoint, p0, p1);
newGeomCoordinates.add(relativePoint);
}
}
Expand All @@ -1640,11 +1634,11 @@ public void makeSourceRelativeZToAbsolute() {

Geometry offsetGeometry = source.copy();
if(source instanceof LineString) {
offsetGeometry = splitLineString((LineString) source, data.profileBuilder);
offsetGeometry = splitLineSource((LineString) source, data.profileBuilder);
} else if(source instanceof MultiLineString) {
LineString[] newGeom = new LineString[source.getNumGeometries()];
for(int idGeom = 0; idGeom < source.getNumGeometries(); idGeom++) {
newGeom[idGeom] = splitLineString((LineString) source.getGeometryN(idGeom),
newGeom[idGeom] = splitLineSource((LineString) source.getGeometryN(idGeom),
data.profileBuilder);
}
offsetGeometry = GEOMETRY_FACTORY.createMultiLineString(newGeom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,39 +235,7 @@ public double getGPath() {
* @return
*/
public boolean isFreeField() {
if(isFreeField == null) {
isFreeField = true;
Coordinate s = getSource().getCoordinate();
Coordinate r = getReceiver().getCoordinate();
List<CutPoint> tmp = new ArrayList<>();
boolean allMatch = true;
for(CutPoint cut : pts) {
if(cut.getType() == BUILDING || cut.getType() == WALL) {
tmp.add(cut);
}
else if(cut.getType() == TOPOGRAPHY) {
tmp.add(cut);
}
if(!(cut.getCoordinate().equals(s) || cut.getCoordinate().equals(r))) {
allMatch = false;
}
}
if(allMatch) {
return true;
}
List<CutPoint> ptsWithouGroundEffect = pts.stream()
.filter(cut -> !cut.getType().equals(GROUND_EFFECT))
.collect(Collectors.toList());
for(CutPoint pt : ptsWithouGroundEffect) {
double[] distanceSRpt = distance3D(source.getCoordinate(), receiver.getCoordinate(), pt.getCoordinate());
if(distanceSRpt[0]>0 && distanceSRpt[1]>0) {
isFreeField = false;
distanceToSR = distanceSRpt[0];
break;
}
}
}
return isFreeField;
return hasBuildingInter || hasTopographyInter;
}

/**
Expand Down
Loading

0 comments on commit ca5f983

Please sign in to comment.