From e6f8ac746ff2668d7c56c3a59d58dcb69b31d55d Mon Sep 17 00:00:00 2001 From: nicolas-f Date: Wed, 23 Oct 2024 11:04:17 +0200 Subject: [PATCH] pts2DGround should not return topographic points under the building polygon --- .../noisemodelling/pathfinder/PathFinder.java | 36 +++++++++++++++---- .../pathfinder/PathFinderTest.java | 13 ++++++- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/PathFinder.java b/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/PathFinder.java index eedcedb67..96d7cd379 100644 --- a/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/PathFinder.java +++ b/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/PathFinder.java @@ -437,13 +437,35 @@ private static List computePts2D(List pts) { * @return the computed coordinate list */ List computePts2DGround(CutProfile cutProfile, Scene data) { - List pts2D= cutProfile.getCutPoints().stream() - .filter(cut -> cut.getType() != GROUND_EFFECT) - .map(cut -> BUILDING.equals(cut.getType()) || WALL.equals(cut.getType()) ? - new Coordinate(cut.getCoordinate().x, cut.getCoordinate().y, cut.getCoordinate().z) - : new Coordinate(cut.getCoordinate().x, cut.getCoordinate().y, cut.getzGround()) - ) - .collect(Collectors.toList()); + List pts2D = new ArrayList<>(cutProfile.getCutPoints().size()); + if(cutProfile.getCutPoints().isEmpty()) { + return pts2D; + } + // keep track of the obstacle under our current position. If -1 there is only ground below + int overObstacleIndex = cutProfile.getCutPoints().get(0).getBuildingId(); + for (CutPoint cut : cutProfile.getCutPoints()) { + if (cut.getType() != GROUND_EFFECT) { + Coordinate coordinate; + if (BUILDING.equals(cut.getType()) || WALL.equals(cut.getType())) { + if(Double.compare(cut.getCoordinate().z, cut.getzGround()) == 0) { + // current position is at the ground level in front of or behind the first/last wall + if(overObstacleIndex == -1) { + overObstacleIndex = cut.getId(); + } else { + overObstacleIndex = -1; + } + } + // Take the obstacle altitude instead of the ground level + coordinate = new Coordinate(cut.getCoordinate().x, cut.getCoordinate().y, cut.getCoordinate().z); + } else { + coordinate = new Coordinate(cut.getCoordinate().x, cut.getCoordinate().y, cut.getzGround()); + } + // we will ignore topographic point if we are over a building + if(!(overObstacleIndex >= 0 && TOPOGRAPHY.equals(cut.getType()))) { + pts2D.add(coordinate); + } + } + } return JTSUtility.getNewCoordinateSystem(pts2D); } 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 210f24666..c36ef72a5 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 @@ -498,6 +498,8 @@ public void TC08() { List expectedZ_profile = new ArrayList<>(); expectedZ_profile.add(new Coordinate(0.00, 0.00)); expectedZ_profile.add(new Coordinate(170.49, 0.00)); + expectedZ_profile.add(new Coordinate(170.49, 6.00)); + expectedZ_profile.add(new Coordinate(170.49, 0.00)); expectedZ_profile.add(new Coordinate(194.16, 0.00)); /* Table 42 */ @@ -592,6 +594,8 @@ public void TC09() { expectedZ_profile.add(new Coordinate(0.00, 0.00)); expectedZ_profile.add(new Coordinate(112.41, 0.00)); expectedZ_profile.add(new Coordinate(170.49, 8.74)); + expectedZ_profile.add(new Coordinate(170.49, 16.63)); + expectedZ_profile.add(new Coordinate(170.49, 8.74)); expectedZ_profile.add(new Coordinate(178.84, 10.00)); expectedZ_profile.add(new Coordinate(194.16, 10.00)); @@ -675,6 +679,8 @@ public void TC10() { List expectedZ_profile = new ArrayList<>(); expectedZ_profile.add(new Coordinate(0.00, 0.00)); expectedZ_profile.add(new Coordinate(5, 0.00)); + expectedZ_profile.add(new Coordinate(5, 10.00)); + expectedZ_profile.add(new Coordinate(15, 10)); expectedZ_profile.add(new Coordinate(15, 0)); expectedZ_profile.add(new Coordinate(20, 0)); @@ -754,6 +760,8 @@ public void TC11() { List expectedZ_profile = new ArrayList<>(); expectedZ_profile.add(new Coordinate(0.00, 0.00)); expectedZ_profile.add(new Coordinate(5, 0.00)); + expectedZ_profile.add(new Coordinate(5, 10.00)); + expectedZ_profile.add(new Coordinate(15, 10.00)); expectedZ_profile.add(new Coordinate(15, 0)); expectedZ_profile.add(new Coordinate(20, 0)); @@ -831,6 +839,8 @@ public void TC12() { List expectedZ_profile = new ArrayList<>(); expectedZ_profile.add(new Coordinate(0.00, 0.00)); expectedZ_profile.add(new Coordinate(12.26, 0.00)); + expectedZ_profile.add(new Coordinate(12.26, 10.00)); + expectedZ_profile.add(new Coordinate(18.82, 10)); expectedZ_profile.add(new Coordinate(18.82, 0)); expectedZ_profile.add(new Coordinate(31.62, 0)); @@ -915,7 +925,8 @@ public void TC13() { expectedZ_profile.add(new Coordinate(0.00, 0.00)); expectedZ_profile.add(new Coordinate(112.41, 0.00)); expectedZ_profile.add(new Coordinate(164.07, 7.8)); - expectedZ_profile.add(new Coordinate(178.83, 10)); + expectedZ_profile.add(new Coordinate(164.07, 30.00)); + expectedZ_profile.add(new Coordinate(181.83, 30)); expectedZ_profile.add(new Coordinate(181.83, 10)); expectedZ_profile.add(new Coordinate(194.16, 10));