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

Update to recent rasterizer branch changes

parents 6cd0bc09 5ee5e703
No related branches found
No related tags found
1 merge request!13Feat/rasterizer update 21
......@@ -162,7 +162,7 @@
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<!-- Checks for class design -->
<!-- Checks for class design -->
<!-- See http://checkstyle.sf.net/config_design.html -->
<module name="DesignForExtension">
<!-- Ignore this rule on functions annotated with certain annotations -->
......
......@@ -9,6 +9,7 @@ import de.tudresden.inf.mci.brailleplot.configparser.ConfigurationParser;
import de.tudresden.inf.mci.brailleplot.configparser.JavaPropertiesConfigurationParser;
import de.tudresden.inf.mci.brailleplot.rendering.Image;
import de.tudresden.inf.mci.brailleplot.rendering.MasterRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -150,4 +151,4 @@ public final class App {
return EXIT_SUCCESS;
}
}
\ No newline at end of file
}
......@@ -7,21 +7,21 @@ package de.tudresden.inf.mci.brailleplot.rendering;
* @author Leonard Kupper
* @version 2019.07.20
*/
class FunctionalRasterizer<T extends Renderable> implements Rasterizer {
public class FunctionalRasterizer<T extends Renderable> implements Rasterizer {
private Class<? extends T> mSupportedDiagramClass;
private Class<? extends T> mSupportedRenderableClass;
private ThrowingBiConsumer<T, RasterCanvas, InsufficientRenderingAreaException> mRasterizingAlgorithm;
/**
* Constructor. Creates a new rasterizer from either a given rasterizer implementation or (keep in mind that
* Rasterizer is a functional interface) from a ThrowingBiConsumer&lt;T, RasterCanvas, InsufficientRenderingAreaException&gt; method reference.
* @param supportedDiagramClass A reference to the accepted diagram class (e.g. 'BarChart.class')
* @param supportedRenderableClass A reference to the accepted diagram class (e.g. 'BarChart.class')
* @param rasterizer A reference to a Rasterizer instance.
*/
FunctionalRasterizer(
final Class<T> supportedDiagramClass,
public FunctionalRasterizer(
final Class<T> supportedRenderableClass,
final Rasterizer<T> rasterizer) {
mSupportedDiagramClass = supportedDiagramClass;
mSupportedRenderableClass = supportedRenderableClass;
mRasterizingAlgorithm = rasterizer::rasterize;
}
......@@ -32,8 +32,8 @@ class FunctionalRasterizer<T extends Renderable> implements Rasterizer {
mRasterizingAlgorithm.accept(diagram, canvas);
}
final Class<? extends T> getSupportedDiagramClass() {
return mSupportedDiagramClass;
final Class<? extends T> getSupportedRenderableClass() {
return mSupportedRenderableClass;
}
@SuppressWarnings("unchecked")
......@@ -43,10 +43,10 @@ class FunctionalRasterizer<T extends Renderable> implements Rasterizer {
// Should somebody still force this to happen by intentional tampering, we have no choice but to catch this disgrace.
private T safeCast(final Renderable data) {
try {
return getSupportedDiagramClass().cast(data);
return getSupportedRenderableClass().cast(data);
} catch (ClassCastException e) {
// wow
throw new IllegalArgumentException("Wrong diagram type! This rasterizer is not meant to be used with '"
throw new IllegalArgumentException("Wrong renderable type! This rasterizer is not meant to be used with '"
+ data.getClass().getCanonicalName() + "'", e);
}
}
......
......@@ -22,7 +22,7 @@ public class FunctionalRenderingBase {
public FunctionalRenderingBase() {
mRasterizingAlgorithms = new HashMap<>();
mLogger.info("FunctionalRenderingBase instance [{}] created", hashCode());
mLogger.info("FunctionalRenderingBase instance created");
}
/**
......@@ -34,15 +34,15 @@ public class FunctionalRenderingBase {
* @exception IllegalArgumentException If no rasterizer is registered for the given renderable type.
*/
public void rasterize(final Renderable renderData) throws InsufficientRenderingAreaException {
mLogger.info("[{}] Starting new rasterizing task for {}", hashCode(), renderData.getClass().getSimpleName());
mLogger.info("Starting new rasterizing task for {}", renderData.getClass().getSimpleName());
// First, check if a raster is set. No rasterizing without raster.
if (Objects.isNull(mRaster)) {
mLogger.error("[{}] No raster set.", hashCode());
mLogger.error("No target raster set.");
throw new IllegalStateException("No raster was set. The method 'setRasterCanvas' must be called before invoking the 'rasterize' method.");
}
// Then, look at the type of the renderData
Class<? extends Renderable> renderableClass = renderData.getClass();
mLogger.info("[{}] Selecting FunctionalRasterizer for {}", hashCode(), renderableClass.getSimpleName());
mLogger.info("Selecting FunctionalRasterizer for {}", renderableClass.getSimpleName());
// Is a rasterizer for the given renderData type available?
if (mRasterizingAlgorithms.containsKey(renderableClass)) {
......@@ -50,7 +50,7 @@ public class FunctionalRenderingBase {
FunctionalRasterizer selectedRasterizer = mRasterizingAlgorithms.get(renderableClass);
selectedRasterizer.rasterize(renderData, mRaster);
} else {
mLogger.error("[{}] No rasterizer found for type.", hashCode());
mLogger.error("No rasterizer found for given renderable type.");
throw new IllegalArgumentException("No rasterizer registered for renderData class: '"
+ renderableClass.getCanonicalName() + "'");
}
......@@ -63,9 +63,18 @@ public class FunctionalRenderingBase {
* @param rasterizer The instance of {@link FunctionalRasterizer} to be registered.
*/
public void registerRasterizer(final FunctionalRasterizer<? extends Renderable> rasterizer) {
mRasterizingAlgorithms.put(rasterizer.getSupportedDiagramClass(), rasterizer);
mLogger.info("[{}] FunctionalRasterizer has been registered for renderable type {}", hashCode(),
rasterizer.getSupportedDiagramClass().getSimpleName());
mLogger.trace("Registering new rasterizer {} for type {}", rasterizer,
rasterizer.getSupportedRenderableClass().getSimpleName());
if (mRasterizingAlgorithms.containsKey(rasterizer.getSupportedRenderableClass())) {
mLogger.trace("Already registered rasterizer {} will be overwritten!",
mRasterizingAlgorithms.get(rasterizer.getSupportedRenderableClass()));
}
mRasterizingAlgorithms.put(rasterizer.getSupportedRenderableClass(), rasterizer);
mLogger.info("FunctionalRasterizer has been registered for renderable type {}",
rasterizer.getSupportedRenderableClass().getSimpleName());
mLogger.trace("Current count of registered rasterizers: {}", mRasterizingAlgorithms.size());
}
/**
......@@ -76,7 +85,7 @@ public class FunctionalRenderingBase {
*/
public void setRasterCanvas(final RasterCanvas raster) {
mRaster = Objects.requireNonNull(raster);
mLogger.info("[{}] RasterCanvas has been set to instance [{}]", hashCode(), raster.hashCode());
mLogger.info("RasterCanvas has been set to instance [{}]", raster.hashCode());
}
/**
......
......@@ -29,14 +29,17 @@ public final class MasterRenderer {
mLogger.info("Creating MasterRenderer with default context");
mLogger.trace("Instantiating default rendering base");
// if no rendering base is given, create own rendering base with default set of algorithms
FunctionalRenderingBase renderingBase = new FunctionalRenderingBase();
mLogger.trace("Instantiating default rasterizers");
// Default Algorithms:
// Rasterizer<BarChart> uniformTexture = new UniformTextureBarChartRasterizer();
Rasterizer<Image> linearImageMapping = new ImageRasterizer();
mLogger.trace("Registering default rasterizers");
// renderingBase.registerRasterizer(new FunctionalRasterizer<BarChart>(BarChart.class, uniformTexture));
renderingBase.registerRasterizer(new FunctionalRasterizer<Image>(Image.class, linearImageMapping));
//renderingBase.registerRasterizer(new FunctionalRasterizer<ScatterPlot>(ScatterPlot.class, ScatterPlotRasterizing::fooRasterizing));
......
......@@ -306,6 +306,10 @@ public class Rectangle {
private Rectangle mRectangle;
/**
* Constructor. Creates a wrapper as proxy object for an integer coordinate representation of the given rectangle.
* @param rectangle The rectangle to be wrapped.
*/
public IntWrapper(final Rectangle rectangle) {
this.mRectangle = Objects.requireNonNull(rectangle);
}
......@@ -315,29 +319,62 @@ public class Rectangle {
return Math.toIntExact(round(value));
}
/**
* Gets the rectangles x position.
* @return The x coordinate of the upper left corner.
*/
public int getX() {
return wrapInt(mRectangle.getX());
}
/**
* Gets the rectangles y position.
* @return The y coordinate of the upper left corner.
*/
public int getY() {
return wrapInt(mRectangle.getY());
}
/**
* Gets the rectangles width.
* @return The distance between the rectangles left and right edge.
*/
public int getWidth() {
return wrapInt(mRectangle.getWidth());
}
/**
* Gets the rectangles height.
* @return The distance between the rectangles top and bottom edge.
*/
public int getHeight() {
return wrapInt(mRectangle.getHeight());
}
/**
* Gets the rectangles right edges position (<b>Important:</b> The IntWrapper treats the rectangle as
* representation of a 'whole' area composed of single countable units (e.g. dots or cells) so this method will
* return the position of the rightmost contained coordinate, which is x+width-1)
* @return The x coordinate of the inner contained right edge.
*/
public int getRight() {
return wrapInt(mRectangle.getRight()) - 1;
}
/**
* Gets the rectangles bottom edges position (<b>Important:</b> The IntWrapper treats the rectangle as
* representation of a 'whole' area composed of single countable units (e.g. dots or cells) so this method will
* return the position of the bottommost contained coordinate, which is y+height-1)
* @return The y coordinate of the inner contained bottom edge.
*/
public int getBottom() {
return wrapInt(mRectangle.getBottom()) - 1;
}
/**
* Get the original rectangle, wrapped by this IntWrapper.
* @return The wrapped instance of {@link Rectangle}.
*/
public Rectangle getRectangle() {
return mRectangle;
}
......
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