Skip to content

Commit

Permalink
#16 and #17 : added parameter to control the level of gray defining o…
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.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 043f51e

Please sign in to comment.