.. _rasterization: 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 :py:class:`vimage.VImage`. It is composed by rectangles (:py:class:`rectangle.Rectangle`), circles (:py:class:`circle.Circle`) and polygons (:py:class:`polygon.Polygon`). These three classes use the class :py: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 :py:class:`rimage.RImage` implement the method rasterization as specified in the lab slides. For that: - Add the method :py:meth:`bounding_box` to the classes :py:class:`rectangle.Rectangle`, :py:class:`circle.Circle` and :py:class:`polygon.Polygon`. This method will return an instance to a :py:class:`rectangle.Rectangle` representing the smallest possible rectangle that fits the figure. In the case of a :py:class:`rectangle.Rectangle`, it is the rectangle itself. - Add the method :py:meth:`bounding_box` to class :py: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 :py:meth:`rasterization` in the three classes (:py:class:`rectangle.Rectangle`, :py:class:`circle.Circle` and :py:class:`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 :py:meth:`Rectangle.fitting_window`. This method will return a new rectangle adjusted to the given aspect ratio. - Implement the class method :py:meth:`rasterization` in the class :py: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 :py:meth:`Rectangle.viewport_transform`. Finally, it will traverse all the figures of the :py:class:`vimage.VImage` instance, rasterize its figures and set to the pixels of their rasterization the color of the figure. Slides ~~~~~~ * See theory slides: slides-6_ * slides-lab-6_ * slides-lab-8_ .. _slides-6: https://www.cs.upc.edu/~dani/IM/session6.pdf .. _slides-lab-6: https://www.cs.upc.edu/~dani/IM/session6-lab.pdf .. _slides-lab-8: https://www.cs.upc.edu/~dani/IM/session8-lab.pdf .. _PyQt5: https://pypi.org/project/PyQt5 .. _draw: https://scikit-image.org/docs/stable/api/skimage.draw.html