-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…bstacles
- Loading branch information
Adrián González Sieira
committed
Nov 8, 2018
1 parent
c364783
commit 043f51e
Showing
1 changed file
with
16 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,18 +37,21 @@ | |
* | ||
* @author Adrián González Sieira {@literal <[email protected]>} | ||
*/ | ||
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; | ||
} | ||
|
||
|