EIE111: Object-Oriented Programming


Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due


EIE111: Object-Oriented Programming
Homework 8: Draw a Picture

Project Structure

In the previous homework, we learned to print simple shapes like rectangles and circles on the screen. Here we will study how to draw shapes on a picture. Your results will be saved as image files.

There are many files in this project. Please start reading from src/main.cpp and try to understand the organization of the project. Most files are complete and should not be modified. For example, the programs in the folder deps define useful functions for linear algebra. The files include/image.hpp and src/image.cpp provide methods to modify an image and save it on the computer.

You should complete some code segments (see the TODO label in corresponding files) in include/element.hpp and src/canvas_parser.cpp. We define a shape (disc, rectangle,hollow  rectangle, digit, and triangle) as a derived class of the base class Element. The virtual function draw must be implemented to draw a specific shape on the picture. We provide an example in the Rectangle class. You can call the SetPixel method to modify the color of pixel (x, y). For other shapes, you need to select and paint the correct pixels. In folder testcases, you can see some input files that describe the shapes you need to draw. The program will load shapes from an input file and save the picture in the folder output. Here are the descriptions of shapes used in this homework.

Disc:
Input format: Disc cx cy radius color
Variables cx and cy: the coordinate of the center
Variable radius: the radius of the circle
Variable color: a 3d vector (for red/green/blue color channels)
Rectangle:
Input format: Rectangle x1 y1 x2 y2 color
Variables x1, y1, x2, y2: upper left corner (x1, y1), lower right corner (x2, y2)
Variable color: a 3d vector (for red/green/blue color channels)
HollowRectangle:
Input format: HollowRectangle x1 y1 x2 y2 color
Variables x1, y1, x2, y2: upper left corner (x1, y1), lower right corner (x2, y2)
Variable color: a 3d vector (for red/green/blue color channels)
Digit:
Input format: Rectangle x1 y1 x2 y2 value color
Variables x1, y1, x2, y2: upper left corner (x1, y1), lower right corner (x2, y2)
Variable value: the digit to display (0~9)
Variable color: a 3d vector (for red/green/blue color channels)
Triangle:
Input format: Rectangle x1 y1 x2 y2 x3 y3 colorVariables x1, y1: vertex (x1, y1)
Variables x2, y2: vertex (x2, y2)
Variables x3, y3: vertex (x3, y3)
We ensure that the vertices are listed in clockwise order
Variable color: a 3d vector (for red/green/blue color channels)

In the folder expected_output, you can view the correct outputs. You should obtain these files in a new folder output by running the complete program. Note that we hide the input file that creates the emoji picture. Please write an input file canvas_emoji.txt that can be converted to an approximate picture and add it in the testcases folder.

Compilation and Running

This project will be built using CMake (see https://cmake.org/getting-started/ for reference). We suggest you compile and run the project on an Ubuntu system. The compilation and running process are put in one file run_all.sh, you can check this file and execute the commands one by one. For example, you may execute your program in the terminal with a new input file name and a new output file name.
Ubuntu system:

Make sure that you have installed CMake. If not, run the following commands in your terminal:

sudo apt-get update
sudo apt-get install cmake
You can execute
bash ./run_all.sh

to compile the project and run the test cases. There are 3 steps: (1) run CMake to obtain the makefile; (2) run make to compile the programs and obtain the executable file; (3) run the executable file with test cases. You can also modify the commands in this file to select some test cases.

MacOS:
The operations are almost the same as in an Ubuntu system. To install CMake, try
brew install cmake
Windows system:

We recommend WSL (Windows Subsystem for Linux) for Windows users. You can install it from the Microsoft Store for free (select an Ubuntu system) or just using PowerShell commands. See the following links to learn how to use it:

https://learn.microsoft.com/zh-cn/windows/wsl/install
https://www.sysgeek.cn/install-wsl-2-windows/

In WSL, you can compile and run the code as if using an Ubuntu system. If you preferusing Visual Studio, you can create an MSVC project, put all source files into the project, and set the dependencies. Note that if you use Visual Studio, you don’t need the file run_all.sh.

Submission

Please submit all the source code and files (even if they are unchanged). Recall that you need to
(1) complete include/element.hpp;
(2) complete src/canvas_parser.cpp;
(3) design an input file canvas_emoji.txt.

You should also submit a README.pdf file explaining:

(1) How did you implement the drawing functions?
(2) The problems you met when you designed the algorithm.
(3) Have you ever discussed the problems with peer students?
(4) Have you ever searched online or asked AI models?
(5) Are there any possiblebugs in your program?

发表评论

电子邮件地址不会被公开。 必填项已用*标注