From 043f51e0500b169786cc3df79b8fe21c4b4927be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Gonz=C3=A1lez=20Sieira?= Date: Thu, 8 Nov 2018 16:18:22 +0100 Subject: [PATCH] #16 and #17 : added parameter to control the level of gray defining obstacles --- ...OCtreeBuilder.java => JOctreeBuilder.java} | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) rename joctomap-core/src/main/java/es/usc/citius/lab/joctomap/module/{JOCtreeBuilder.java => JOctreeBuilder.java} (89%) diff --git a/joctomap-core/src/main/java/es/usc/citius/lab/joctomap/module/JOCtreeBuilder.java b/joctomap-core/src/main/java/es/usc/citius/lab/joctomap/module/JOctreeBuilder.java similarity index 89% rename from joctomap-core/src/main/java/es/usc/citius/lab/joctomap/module/JOCtreeBuilder.java rename to joctomap-core/src/main/java/es/usc/citius/lab/joctomap/module/JOctreeBuilder.java index d90535c..7091f9c 100644 --- a/joctomap-core/src/main/java/es/usc/citius/lab/joctomap/module/JOCtreeBuilder.java +++ b/joctomap-core/src/main/java/es/usc/citius/lab/joctomap/module/JOctreeBuilder.java @@ -37,18 +37,21 @@ * * @author Adrián González Sieira {@literal } */ -public class JOCtreeBuilder extends Module{ +public class JOctreeBuilder extends Module{ @Override public void execute(CommandLine args) { //retrieve input args String[] inputArgs = args.getOptionValues("i"); + String levelString = args.getOptionValue("g", "10"); + int level = Integer.parseInt(levelString); //process the ppm to generate an octree JOctree octree = octreeFromPPM( inputArgs[0], Float.parseFloat(inputArgs[1]), Float.parseFloat(inputArgs[2]), - Integer.parseInt(inputArgs[3]) + Integer.parseInt(inputArgs[3]), + level ); //write octree to file (.ot extension mandatory) String outputPath = args.getOptionValue("o"); @@ -65,7 +68,7 @@ public void execute(CommandLine args) { * @param maxDepthCell number of levels which a cell is allowed to compact * @return new {@link JOctree} with the information of the PPM file */ - public static JOctree octreeFromPPM(String input, float resolution, float sizeX, int maxDepthCell){ + public static JOctree octreeFromPPM(String input, float resolution, float sizeX, int maxDepthCell, int levelGrayObstacle){ //read the ppm file MapFileReader reader = null; //open file and read data from @@ -95,7 +98,7 @@ public static JOctree octreeFromPPM(String input, float resolution, float sizeX, for (float y = 0; y < sizeY; y += octree.getResolution() / 2f) { int[] rgb = reader.getPixels()[Math.round(x / resolutionPPM)][Math.round(y / resolutionPPM)]; //occupied case: one of the color components reaches the maximum value of the file - boolean occupied = rgb[0] < 10 && rgb[1] < 10 && rgb[2] < 10; + boolean occupied = rgb[0] < levelGrayObstacle && rgb[1] < levelGrayObstacle && rgb[2] < levelGrayObstacle; //update occupancy information until we get an absolute value for the occupancy (1 or 0) Double previousOccupancy = null; do { @@ -138,6 +141,15 @@ public Options getModuleOptions() { .argName("ot") .build() ); + op.addOption( + Option.builder("g") + .optionalArg(true) + .desc("Level of gray which defines occupied space") + .hasArg() + .longOpt("gray") + .argName("gray") + .build() + ); return op; }