Skip to content
Snippets Groups Projects
Commit 632fd730 authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

Première version du projet.

parent 1ebc96ed
Branches
No related tags found
No related merge requests found
# Représentation d'images en couleurs # Gestion de tâches dans une ferme de machines
## Description du projet ## Description du projet
On va considérer quatre manières de représenter une image en couleur et donc quatre classes d'images : Vous allez travailler dans cet examen à la gestion d'une ferme de nœuds (*nodes*) représentant
des ordinateurs qui mettent à disposition de la mémoire (*memory*) exprimée en octets (o) et
- `BruteRasterImage` d'un nombre d'opérations exprimé en FLOP qui peut être consommées par des tâches (*job*).
- `PaletteRasterImage` L'objectif est de proposer un ordonnanceur (*scheduler*) qui place un ensemble de tâches
- `SparseRasterImage` sur les nœuds de manière à maximiser l'utilisation de la mémoire et du nombre d'opérations.
- `VectorImage`
## Membres du projet ## Membres du projet
......
plugins { plugins {
id 'application' id 'application'
id "org.openjfx.javafxplugin" version "0.0.10"
} }
javafx {
version = "17"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
repositories { repositories {
mavenCentral() mavenCentral()
...@@ -23,5 +18,5 @@ test { ...@@ -23,5 +18,5 @@ test {
} }
application { application {
mainClassName = "viewer.Main" mainClassName = "cluster.App"
} }
\ No newline at end of file
rootProject.name = 'color-image' rootProject.name = 'cluster'
package cluster;
public class App {
public static void main(String[] args) throws Exception{
// TODO : décommenter pour tester le main.
/*
Job job1 = new Job(1000, 1000);
Job job2 = new Job(3000, 1000);
Node node = new Node("Calcul", 10000, 3000);
node.acceptJob(job1);
node.acceptJob(job2);
node.printJobs();
*/
}
}
package image;
import javafx.scene.paint.Color;
public class BlankImage implements Image{
private final int width;
private final int height;
public BlankImage(int width, int height) {
this.width = width;
this.height = height;
}
@Override
public Color getPixelColor(int x, int y) {
return Color.WHITE;
}
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
}
package image;
public class BlankImageFactory implements ImageFactory {
@Override
public Image makeImage() {
return new BlankImage(1000, 800);
}
}
package image;
import javafx.scene.paint.Color;
public interface Image {
Color getPixelColor(int x, int y);
int getWidth();
int getHeight();
}
package image;
public interface ImageFactory {
Image makeImage();
}
package image;
import java.util.Objects;
/**
* Created by Arnaud Labourel on 09/11/2018.
*/
public class Point {
public final int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Point point)) return false;
return x == point.x &&
y == point.y;
}
@Override
public final int hashCode() {
return Objects.hash(x, y);
}
}
package image;
import javafx.scene.paint.Color;
public interface Shape {
/**
* Tests if a specified Point is inside the boundary of the Shape.
*
* @return true if the point is inside the shape and false otherwise.
*/
boolean contains(Point point);
/**
* Return the color of the interior of the Shape.
*
* @return the color of the shape.
*/
Color getColor();
}
package util;
import java.util.Objects;
/**
* Created by Arnaud Labourel on 23/11/2018.
*/
public class Matrices {
/**
* Ensures that the given matrix does not have null parts : itself being null, having null row or having
* null values.
*
* @throws NullPointerException if there are null parts in the matrix.
* @param matrix the matrix to be tested.
*/
public static void requiresNonNull(Object[][] matrix) {
Objects.requireNonNull(matrix, "The matrix must not be null.");
for (int x = 0; x < getRowCount(matrix); x++) {
Objects.requireNonNull(matrix[x], "The matrix must not have rows equals to null.");
for (int y = 0; y < matrix[x].length; y++) {
Objects.requireNonNull(matrix[x][y], "The matrix must not have values equals to null.");
}
}
}
/**
* Ensures that the given matrix (assumed to be rectangular) does not have zero rows or zero columns.
*
* @throws IllegalArgumentException if the matrix have zero rows or zero columns.
* @param matrix the matrix to be tested.
*/
public static void requiresNonZeroDimensions(Object[][] matrix) {
if (getRowCount(matrix) == 0) {
throw new IllegalArgumentException("The matrix must not have zero rows.");
}
if (getColumnCount(matrix) == 0) {
throw new IllegalArgumentException("The matrix must not have zero columns.");
}
}
/**
* Ensures that the given matrix is rectangular, i.e., all rows have the same size.
*
* @throws IllegalArgumentException if the matrix have rows with different sizes.
* @param matrix the matrix to be tested.
*/
public static void requiresRectangularMatrix(Object[][] matrix) {
for (int x = 1; x < getRowCount(matrix); x++) {
if (matrix[x].length != matrix[0].length)
throw new IllegalArgumentException("The matrix must be rectangular.");
}
}
/**
* Give the number of rows of a matrix.
*
* @param matrix the matrix.
* @return the number of rows of the matrix.
*/
public static int getRowCount(Object[][] matrix){
return matrix.length;
}
/**
* Give the number of columns of a matrix (assumed to be rectangular).
*
* @param matrix the matrix.
* @return the number of rows of the matrix.
*/
public static int getColumnCount(Object[][] matrix){
return matrix[0].length;
}
}
package viewer;
import image.*;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.PixelWriter;
import javafx.scene.paint.Color;
import java.net.URL;
import java.util.ResourceBundle;
public class Display implements Initializable {
@FXML
private Canvas canvas;
private Image image;
@Override
public void initialize(URL location, ResourceBundle resources) {
ImageFactory imageFactory = new BlankImageFactory();
// TODO : changer la fabrique d'image pour construire des images.
this.image = imageFactory.makeImage();
render();
}
private void render() {
int pixelWidth = image.getWidth();
int pixelHeight = image.getHeight();
canvas.setWidth(pixelWidth);
canvas.setHeight(pixelHeight);
GraphicsContext graphicsContext = canvas.getGraphicsContext2D();
PixelWriter pixelWriter = graphicsContext.getPixelWriter();
for (int i = 0; i < pixelWidth; i++) {
for (int j = 0; j < pixelHeight; j++) {
renderPixel(i, j, pixelWriter);
}
}
}
private void renderPixel(int x, int y, PixelWriter pixelWriter) {
pixelWriter.setColor(x, y, image.getPixelColor(x, y));
}
}
package viewer;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.Objects;
public class Main extends Application
{
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getClassLoader().getResource("fxml/Display.fxml")));
primaryStage.setTitle("Image display");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}
import image.BlankImage;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class BlankImageTest {
@Test
public void testBlankImageGetWidth(){
BlankImage blankImage = new BlankImage(200, 300);
assertThat(blankImage.getWidth()).isEqualTo(200);
}
@Test
public void testBlankImageGetHeight(){
BlankImage blankImage = new BlankImage(200, 300);
assertThat(blankImage.getHeight()).isEqualTo(300);
}
@Test
public void testBlankImageGetPixelColor(){
BlankImage blankImage = new BlankImage(200, 300);
assertThat(blankImage.getPixelColor(0,0)).isEqualTo(Color.WHITE);
assertThat(blankImage.getPixelColor(100,100)).isEqualTo(Color.WHITE);
assertThat(blankImage.getPixelColor(199,299)).isEqualTo(Color.WHITE);
}
}
package cluster;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
public class TestJob {
//TODO : décommenter pour tester la classe Job
/*
@Test
void testToString(){
// Test with Junit
Job job1 = new Job(100, 100);
String expectedStringRepresentation1 = "Job " + job1.getId() + " (100FLOP, 100o)";
assertEquals(expectedStringRepresentation1, job1.toString());
// Test with assertJ
Job job2 = new Job(1, 10);
String expectedStringRepresentation2 = "Job " + job2.getId() + " (10FLOP, 1o)";
assertThat(job2.toString()).isEqualTo(expectedStringRepresentation2);
}
@Test
void testResetJobCount(){
Job.resetJobCount();
Job job = new Job(10, 1000);
assertThat(job.getId()).isEqualTo(0);
}
@Test
void testGetId(){
int[] memories = {10, 1000};
for(int memory : memories){
Job job = new Job(memory, 1000);
assertThat(job.getMemory()).isEqualTo(memory);
}
}
@Test
void testGetJobCount(){
Job.resetJobCount();
for(int jobCount = 1; jobCount < 4; jobCount++){
Job job = new Job(10, 1000);
assertThat(Job.getJobCount()).isEqualTo(jobCount);
}
}
*/
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment