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
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.
Input format: Disc cx cy radius colorVariables cx and cy: the coordinate of the centerVariable radius: the radius of the circleVariable color: a 3d vector (for red/green/blue color channels)
Input format: Rectangle x1 y1 x2 y2 colorVariables 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)
Input format: HollowRectangle x1 y1 x2 y2 colorVariables 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)
Input format: Rectangle x1 y1 x2 y2 value colorVariables 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)
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 orderVariable 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
Make sure that you have installed CMake. If not, run the following commands in your terminal:
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.
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:
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
(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?