Rasterization

This task is a natural continuation of Lab 1, but because of timimg reasons, it will be evaluated in Lab 2. It consists of creating a raster image of a given pixel resolution and filled with a given color, with the rasterization of a vectorial image. It will be implemented in same it project as for Lab 1.

First, add a new issue to your project consisting of implementing the rasterization of a vectorial image. Create a merge request.

Then, locally, fetch the new branch and check into it:

git fetch
git checkout name_new_branch

Our design of a vectorial image is specified in the class vimage.VImage. It is composed by rectangles (rectangle.Rectangle), circles (circle.Circle) and polygons (polygon.Polygon). These three classes use the class point.Point. A first implementation of these classes is provided for download at the end of the corresponding pages. Download them in your project directory. Then, add them to your project, commit and push:

git add point.py circle.py polygon.py vimage.py
git commit -m "New files for rasterization"
git push

In the class rimage.RImage implement the method rasterization as specified in the lab slides. For that:

  • Add the method bounding_box() to the classes rectangle.Rectangle, circle.Circle and polygon.Polygon. This method will return an instance to a rectangle.Rectangle representing the smallest possible rectangle that fits the figure. In the case of a rectangle.Rectangle, it is the rectangle itself.

  • Add the method bounding_box() to class vimage.VImage: it will be a rectangle bounding all the bounding boxes of the figures (rectangles, circles and polygons) of the vectorial image.

  • Implement the method rasterization() in the three classes (rectangle.Rectangle, circle.Circle and polygon.Polygon ). These methods will have as a parameter the window-to-viewport transformation matrix. They will convert the geometry of the figure to the raster coordinate space using this matrix, and then, applying the methods of the module draw they will get and return a list of pixels corresponding to the rasterization of the figure.

  • In the class Rectangle, implement the method Rectangle.fitting_window(). This method will return a new rectangle adjusted to the given aspect ratio.

  • Implement the class method rasterization() in the class rimage.RImage. This class method will receive as parameters the width, height and color of the raster image to be created, and a vectorial image. It will first compute the 2D window of the rasterization pipeline as the bounding box of the vectorial image by calling the methods implemented in the previous steps. Then, it will modify this window to make it fit the aspect ratio of the raster image to be created (using the method implemented in the previous step). With the window and the raster image dimensions, it will then create the transformation matrix using the method Rectangle.viewport_transform(). Finally, it will traverse all the figures of the vimage.VImage instance, rasterize its figures and set to the pixels of their rasterization the color of the figure.

Slides