Skip to content
Snippets Groups Projects
Commit 23bb021a authored by Leonard Kupper's avatar Leonard Kupper
Browse files

Extended loggin for canvas and rectangle

parent 66fc5fb5
No related branches found
No related tags found
1 merge request!13Feat/rasterizer update 21
......@@ -8,7 +8,9 @@ import de.tudresden.inf.mci.brailleplot.commandline.SettingsWriter;
import de.tudresden.inf.mci.brailleplot.configparser.ConfigurationParser;
import de.tudresden.inf.mci.brailleplot.configparser.JavaPropertiesConfigurationParser;
import de.tudresden.inf.mci.brailleplot.rendering.FunctionalRasterizer;
import de.tudresden.inf.mci.brailleplot.rendering.Image;
import de.tudresden.inf.mci.brailleplot.rendering.ImageRasterizer;
import de.tudresden.inf.mci.brailleplot.rendering.MasterRenderer;
import org.slf4j.Logger;
......@@ -146,6 +148,16 @@ public final class App {
getClass().getClassLoader().getResource("config/default.properties").getFile()
);
MasterRenderer renderer = new MasterRenderer(parser.getPrinter(), parser.getFormat("A4"));
// Replace default Image rasterizer
renderer.getRenderingBase().registerRasterizer(new FunctionalRasterizer<>(
Image.class,
new ImageRasterizer(
false, false, false,
25
)
));
renderer.rasterize(new Image(
new File(getClass().getClassLoader().getResource("examples/img/2_image_chart.png").toURI())
));
......
......@@ -51,6 +51,7 @@ public abstract class AbstractCanvas {
mLogger.trace("Determined page box: {}", pageBox);
// Create a margin box
mLogger.trace("Cropping edges by defined margins:");
int marginTop = mFormat.getProperty("margin.top").toInt();
int marginLeft = mFormat.getProperty("margin.left").toInt();
int marginBottom = mFormat.getProperty("margin.bottom").toInt();
......
......@@ -26,7 +26,7 @@ public class FunctionalRasterizer<T extends Renderable> implements Rasterizer {
public FunctionalRasterizer(
final Class<T> supportedRenderableClass,
final Rasterizer<T> rasterizer) {
mLogger.info("Creating new FunctionalRasterizer: Binding {} rasterizer {}.",
mLogger.info("Creating new FunctionalRasterizer: Binding rasterizer reference (renderable type {}): {}.",
supportedRenderableClass.getSimpleName(), rasterizer);
mSupportedRenderableClass = supportedRenderableClass;
mRasterizingAlgorithm = rasterizer::rasterize;
......
......@@ -66,7 +66,7 @@ public class FunctionalRenderingBase {
mLogger.trace("Registering new rasterizer {} for type {}", rasterizer,
rasterizer.getSupportedRenderableClass().getSimpleName());
if (mRasterizingAlgorithms.containsKey(rasterizer.getSupportedRenderableClass())) {
mLogger.trace("Already registered rasterizer {} will be overwritten!",
mLogger.warn("Already registered rasterizer {} will be overwritten!",
mRasterizingAlgorithms.get(rasterizer.getSupportedRenderableClass()));
}
......
......@@ -38,7 +38,7 @@ public class ImageRasterizer implements Rasterizer<Image> {
*/
public ImageRasterizer() {
this(true, true, true, DEFAULT_THRESHOLD);
mLogger.trace("Created ImageRasterizer with default settings");
mLogger.trace("ImageRasterizer has been setup with default settings");
}
/**
......@@ -105,7 +105,7 @@ public class ImageRasterizer implements Rasterizer<Image> {
private void linearMapping(final BufferedImage imgBuf, final RasterCanvas canvas) {
mLogger.trace("Apply linear mapping algorithm.");
mLogger.trace("Applying linear mapping algorithm.");
// A canvas is basically a wrapper for multiple representations of printable data, each representing a page.
// These representations can be acquired by either requesting the current page or creating a new page.
......@@ -143,6 +143,7 @@ public class ImageRasterizer implements Rasterizer<Image> {
// This can lead to distortions because the original pixel raster is equidistant, but the output raster
// does not have to be equidistant.
mLogger.trace("Scanning through image pixel values...");
// Scan through each pixel of the original image
for (int x = 0; x < imgBuf.getWidth(); x++) {
// Convert from original pixel x-position to braille dot x-position.
......@@ -158,16 +159,18 @@ public class ImageRasterizer implements Rasterizer<Image> {
}
}
}
mLogger.trace("Done!");
}
private void quantifiedPositionMapping(final BufferedImage imgBuf, final RasterCanvas canvas) {
mLogger.trace("Apply quantified position algorithm.");
mLogger.trace("Applying quantified position algorithm.");
MatrixData<Boolean> data = canvas.getNewPage();
// Instead of using the dot rectangle a rectangle representing the target printing space in millimeters
// is built from the canvas information.
mLogger.trace("Determining available area (in mm):");
Rectangle availableArea = new Rectangle(0, 0, canvas.getPrintableWidth(), canvas.getPrintableHeight());
// Calculate the ratios between original image and target printable area. (mm / pixel)
......@@ -190,6 +193,7 @@ public class ImageRasterizer implements Rasterizer<Image> {
// In a second step, the calculated exact position is quantified to fit a dot position on the raster.
// Distortions can still be introduced but are minimized.
mLogger.trace("Scanning through image pixel values...");
// Scan through all pixels of the original image
for (int x = 0; x < imgBuf.getWidth(); x++) {
// Convert from original pixel x-position to printed dot x-position in millimeters.
......@@ -208,6 +212,7 @@ public class ImageRasterizer implements Rasterizer<Image> {
}
}
}
mLogger.trace("Done!");
}
......
......@@ -113,6 +113,7 @@ public class Rectangle {
* @throws OutOfSpaceException If the requested partition is greater than the underlying rectangle itself.
*/
public Rectangle fromTop(final double height) throws OutOfSpaceException {
mLogger.trace("Getting partition of height {} from top of {}", height, this);
checkHeight(height);
return new Rectangle(getX(), getY(), getWidth(), height);
}
......@@ -124,6 +125,7 @@ public class Rectangle {
* @throws OutOfSpaceException If the requested partition is greater than the underlying rectangle itself.
*/
public Rectangle fromLeft(final double width) throws OutOfSpaceException {
mLogger.trace("Getting partition of width {} from left side of {}", width, this);
checkWidth(width);
return new Rectangle(getX(), getY(), width, getHeight());
}
......@@ -135,6 +137,7 @@ public class Rectangle {
* @throws OutOfSpaceException If the requested partition is greater than the underlying rectangle itself.
*/
public Rectangle fromBottom(final double height) throws OutOfSpaceException {
mLogger.trace("Getting partition of height {} from bottom of {}", height, this);
checkHeight(height);
double newY = (getY() + (getHeight() - height));
return new Rectangle(getX(), newY, getWidth(), height);
......@@ -147,6 +150,7 @@ public class Rectangle {
* @throws OutOfSpaceException If the requested partition is greater than the underlying rectangle itself.
*/
public Rectangle fromRight(final double width) throws OutOfSpaceException {
mLogger.trace("Getting partition of width {} from right side of {}", width, this);
checkWidth(width);
double newX = (getX() + (getWidth() - width));
return new Rectangle(newX, getY(), width, getHeight());
......@@ -262,6 +266,7 @@ public class Rectangle {
* @return New rectangle with scaled position and size.
*/
public Rectangle scaledBy(final double xScale, final double yScale) {
mLogger.trace("Scaling rectangle {} by {}x{}", this, xScale, yScale);
return new Rectangle(mX * xScale, mY * yScale, mW * xScale, mH * yScale);
}
......@@ -271,6 +276,7 @@ public class Rectangle {
* @return New rectangle representing the intersection.
*/
public Rectangle intersectedWith(final Rectangle otherRectangle) {
mLogger.trace("Intersecting rectangles: {} & {}", this, otherRectangle);
double itsctX = max(getX(), otherRectangle.getX());
double itsctY = max(getY(), otherRectangle.getY());
double itsctB = min(getBottom(), otherRectangle.getBottom());
......@@ -285,6 +291,7 @@ public class Rectangle {
* @return A new rectangle representing a translated copy of this rectangle.
*/
public Rectangle translatedBy(final double alongX, final double alongY) {
mLogger.trace("Translating rectangle {} along {},{}", this, alongX, alongY);
return new Rectangle(getX() + alongX, getY() + alongY, getWidth(), getHeight());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment