Skip to content

Commit

Permalink
fix zGround conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Dec 12, 2024
1 parent 7506f38 commit 2ba6b9b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.noise_planet.noisemodelling.pathfinder.profilebuilder;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.LineSegment;
Expand Down Expand Up @@ -37,9 +36,9 @@ public class CutPointWall extends CutPoint {
/** This point encounter this kind of limit
* - We can enter or exit a polygon
* - pass a line (a wall without width) */
public enum INTERSECTION_TYPE { AREA_ENTER, AREA_EXIT, LINE_ENTER_EXIT}
public enum INTERSECTION_TYPE {BUILDING_ENTER, BUILDING_EXIT, THIN_WALL_ENTER_EXIT}

public INTERSECTION_TYPE intersectionType = INTERSECTION_TYPE.LINE_ENTER_EXIT;
public INTERSECTION_TYPE intersectionType = INTERSECTION_TYPE.THIN_WALL_ENTER_EXIT;

/** Database primary key value of the obstacle */
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,36 +171,46 @@ public static List<Coordinate> computePtsGround(List<CutPoint> pts, List<Integer
if(pts.isEmpty()) {
return pts2D;
}
// keep track of the obstacle under our current position. If -1 there is only ground below
int overObstacleIndex = pts.get(0) instanceof CutPointWall ? ((CutPointWall)pts.get(0)).processedWallIndex : -1;
for (int i=0; i < pts.size(); i++) {
CutPoint cut = pts.get(i);
// keep track of the obstacle under our current position.
boolean overArea = false;
for (CutPoint cut : pts) {
if (cut instanceof CutPointWall) {
CutPointWall cutPointWall = (CutPointWall) cut;
if (cutPointWall.intersectionType.equals(CutPointWall.INTERSECTION_TYPE.BUILDING_EXIT)) {
overArea = true;
} else {
break;
}
}
}
for (CutPoint cut : pts) {
if (cut instanceof CutPointGroundEffect) {
if(index != null) {
if (index != null) {
index.add(pts2D.size() - 1);
}
continue;
}
Coordinate coordinate;
if (cut instanceof CutPointWall) {
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 = ((CutPointWall) cut).processedWallIndex;
} else {
overObstacleIndex = -1;
}
// Z ground profile must add intermediate ground points before adding the top level of building/wall
CutPointWall cutPointWall = (CutPointWall) cut;
if (cutPointWall.intersectionType.equals(CutPointWall.INTERSECTION_TYPE.BUILDING_ENTER) ||
cutPointWall.intersectionType.equals(CutPointWall.INTERSECTION_TYPE.THIN_WALL_ENTER_EXIT)) {
pts2D.add(new Coordinate(cut.getCoordinate().x, cut.getCoordinate().y, cut.getzGround()));
overArea = true;
}
pts2D.add(new Coordinate(cut.getCoordinate().x, cut.getCoordinate().y, cut.getCoordinate().z));
if (cutPointWall.intersectionType.equals(CutPointWall.INTERSECTION_TYPE.BUILDING_EXIT) ||
cutPointWall.intersectionType.equals(CutPointWall.INTERSECTION_TYPE.THIN_WALL_ENTER_EXIT)) {
pts2D.add(new Coordinate(cut.getCoordinate().x, cut.getCoordinate().y, cut.getzGround()));
overArea = false;
}
// 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 && cut instanceof CutPointTopography)) {
pts2D.add(coordinate);
// we will ignore topographic point if we are over a building
if (!(overArea && cut instanceof CutPointTopography)) {
pts2D.add(new Coordinate(cut.getCoordinate().x, cut.getCoordinate().y, cut.getzGround()));
}
}
if(index != null) {
if (index != null) {
index.add(pts2D.size() - 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.locationtech.jts.algorithm.Angle;
import org.locationtech.jts.algorithm.CGAlgorithms3D;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateSequence;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
Expand Down Expand Up @@ -1025,7 +1024,7 @@ private boolean processWall(int processedWallIndex, Coordinate intersection, Wal

CutPointWall cutPointWall = new CutPointWall(processedWallIndex,
intersection, facetLine.getLineSegment(), facetLine.alphas);
cutPointWall.intersectionType = CutPointWall.INTERSECTION_TYPE.LINE_ENTER_EXIT;
cutPointWall.intersectionType = CutPointWall.INTERSECTION_TYPE.THIN_WALL_ENTER_EXIT;
if(facetLine.primaryKey >= 0) {
cutPointWall.setPk(facetLine.primaryKey);
}
Expand Down Expand Up @@ -1059,9 +1058,9 @@ private boolean processBuilding(int processedWallIndex, Coordinate intersection,
Coordinate exteriorPoint = exteriorVector.add(Vector2D.create(intersection)).toCoordinate();
// exterior point closer to source so we know that we enter the building
if(exteriorPoint.distance(fullLine.p0) < intersection.distance(fullLine.p0)) {
wallCutPoint.intersectionType = CutPointWall.INTERSECTION_TYPE.AREA_ENTER;
wallCutPoint.intersectionType = CutPointWall.INTERSECTION_TYPE.BUILDING_ENTER;
} else {
wallCutPoint.intersectionType = CutPointWall.INTERSECTION_TYPE.AREA_EXIT;
wallCutPoint.intersectionType = CutPointWall.INTERSECTION_TYPE.BUILDING_EXIT;
}

if (zRayReceiverSource <= intersection.z) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.noise_planet.noisemodelling.pathfinder.PathFinderTest.assertZProfil;

/**
* Test class dedicated to {@link ProfileBuilder}.
Expand Down Expand Up @@ -294,6 +296,62 @@ public void testRelativeSourceLineProjection() throws ParseException {
new Coordinate(120.0, 33.16, 1.0),
new Coordinate(185.0, 46.84, 11.0),
new Coordinate(200.0, 50.0, 11.0));
PathFinderTest.assertZProfil(expectedProfile, Arrays.asList(scene.sourceGeometries.get(0).getCoordinates()));
assertZProfil(expectedProfile, Arrays.asList(scene.sourceGeometries.get(0).getCoordinates()));
}


@Test
public void test2DGroundProfile() {

//Profile building (from TC15)
ProfileBuilder profileBuilder = new ProfileBuilder()
.addBuilding(new Coordinate[]{
new Coordinate(55.0, 5.0, 8),
new Coordinate(65.0, 5.0, 8),
new Coordinate(65.0, 15.0, 8),
new Coordinate(55.0, 15.0, 8),
})
.addBuilding(new Coordinate[]{
new Coordinate(70.0, 14.5, 12),
new Coordinate(80.0, 10.2, 12),
new Coordinate(80.0, 20.2, 12),
})
.addBuilding(new Coordinate[]{
new Coordinate(90.1, 19.5, 10),
new Coordinate(93.3, 17.8, 10),
new Coordinate(87.3, 6.6, 10),
new Coordinate(84.1, 8.3, 10),
});
profileBuilder.addGroundEffect(0, 100, 0.0, 150, 0.5);
profileBuilder.setzBuildings(true);
profileBuilder.finishFeeding();

CutProfile cutProfile = profileBuilder.getProfile(new Coordinate(50,10,1), new Coordinate(100, 15, 5));

assertEquals(9, cutProfile.cutPoints.size());

List<Coordinate> zProfile = cutProfile.computePts2DGround();

/* Table 148 */
List<Coordinate> expectedZProfile = new ArrayList<>();
expectedZProfile.add(new Coordinate(0.00, 0.00));
expectedZProfile.add(new Coordinate(5.02, 0.00));
expectedZProfile.add(new Coordinate(5.02, 8.00));
expectedZProfile.add(new Coordinate(15.07, 8.0));
expectedZProfile.add(new Coordinate(15.08, 0.0));
expectedZProfile.add(new Coordinate(24.81, 0.0));
expectedZProfile.add(new Coordinate(24.81, 12.0));
expectedZProfile.add(new Coordinate(30.15, 12.0));
expectedZProfile.add(new Coordinate(30.15, 0.00));
expectedZProfile.add(new Coordinate(37.19, 0.0));
expectedZProfile.add(new Coordinate(37.19, 10.0));
expectedZProfile.add(new Coordinate(41.52, 10.0));
expectedZProfile.add(new Coordinate(41.52, 0.0));
expectedZProfile.add(new Coordinate(50.25, 0.0));

//Assertion
assertZProfil(expectedZProfile, zProfile);


}
}

0 comments on commit 2ba6b9b

Please sign in to comment.