Skip to content

Commit

Permalink
ACN: Fix images generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Slashgear committed Apr 22, 2015
1 parent e14a9b5 commit 71d61a4
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions Core/src/main/java/com/polytech4A/cuttingstock/core/save/ToImg.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.polytech4A.cuttingstock.core.model.PlacedBox;
import com.polytech4A.cuttingstock.core.model.Solution;
import com.polytech4A.cuttingstock.core.model.Vector;
import com.polytech4A.cuttingstock.core.model.Box;
import org.apache.log4j.Logger;

import javax.imageio.ImageIO;
Expand All @@ -33,9 +32,8 @@
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Optional;
import java.util.NoSuchElementException;

/**
* Created by Antoine CARON on 24/03/2015.
Expand Down Expand Up @@ -207,6 +205,27 @@ public static void drawRectangle(BufferedImage img, int x, int y, int width, int
graph.dispose();
}

public static String getLabel(PlacedBox currentBox, Pattern pattern) {
try {
int index = pattern.getAmounts().indexOf(pattern.
getAmounts().parallelStream()
.filter(b -> b.equals(currentBox))
.findFirst()
.get());
String label = String.valueOf(index);
if (currentBox.isRotation()) {
label += "*";
}
return label;
} catch (NoSuchElementException ex) {
int index = pattern.getPlacedBoxes().indexOf(currentBox);
String label = String.valueOf(index);
if (currentBox.isRotation()) {
label += "*";
}
return label;
}
}

/**
* Save Method.
Expand All @@ -233,11 +252,11 @@ public void save(String contextId, Solution solution) {
Vector size = placedBox.getSize();
if (!placedBox.isRotation()) {
drawRectangle(img, (int) (position.getX() * coeff), (int) (position.getY() * coeff),
(int) (size.getX() * coeff), (int) (size.getY() * coeff), getLabel(placedBox, cur_patt.getAmounts()),
(int) (size.getX() * coeff), (int) (size.getY() * coeff), getLabel(placedBox, cur_patt),
getColor(i, cur_patt.getPlacedBoxes().size()));
} else {
drawRectangle(img, (int) (position.getX() * coeff), (int) (position.getY() * coeff),
(int) (size.getY() * coeff), (int) (size.getX() * coeff), getLabel(placedBox, cur_patt.getAmounts()),
(int) (size.getY() * coeff), (int) (size.getX() * coeff), getLabel(placedBox, cur_patt),
getColor(i, cur_patt.getPlacedBoxes().size()));
}
i++;
Expand All @@ -258,14 +277,5 @@ public void save(String contextId, Solution solution) {
}
}

public static String getLabel(PlacedBox currentBox, ArrayList<Box> boxes) {
int index = boxes.indexOf(boxes.parallelStream().filter(b -> b.equals(currentBox)).findFirst().get());
String label = String.valueOf(index);
if(currentBox.isRotation()) {
label += "*";
}
return label;
}


}

0 comments on commit 71d61a4

Please sign in to comment.