due Tuesday, March 23rd, 1:30 pm
This assignment is not accepted late.
The goal of this assignment is to give you practice using the Standard Template Library, bitmaps, SFML, and lambda functions. The assignment consists of reading a binary file, storing the data in a map of bitset, flipping bits, moving the data to a vector, loading the vector into an image, loading the image into a texture, using the texture to create a sprite, and displaying the sprite in a RenderWindow. You will need to do some SFML research into how to create an image and how to work with type color Color. Use the sample output as checks to make sure you are proceeding correctly. Your output should look like that that shown below (including formatting).
The input file consists of pairs of unsigned int. Open the input file and count the number of records in the file without reading every record. You'll need to know (save) the number of records in the file.
Read the file and display the first 5 records and the last 5.
Read the file and store the data in a map with an unsigned key and an unsigned value. Note: you will have to pay attention to the way the pairs of unsigned int are stored.
Print the first 5 and the last five elements of the map (this is a good place to use a lambda function).
Copy the map values into a vector of bitset<32>.
Print elements 12058 to 12062 of the vector.
Flip the bits in each element of the vector. Print elements 12058 to 12062 of the vector again.
Print elements 12058 to 12062 of the vector again as unsigned int.
Create an SFML image of size 400 x 400 (you may need some research here).
Load the vector bitset data into the image pixels (you may need some more research and you may have to convert the bitsets to unsigned int or sf::Uint32).
Create a texture using your image.
Create a sprite using your texture.
Display your sprite. You will know if you did this correctly. If it is not oriented correctly, you may have to switch your rows and columns or your x's and y's, or your first and second.
sf::RenderWindow
window(sf::VideoMode(400, 400), "Assignment 7"); sf::Image image; // step 9 image.create(400, 400); // load the bitset data into the image pixels (step 10) ... ? ... sf::Texture texture; // step 11 texture.loadFromImage(image); sf::Sprite sprite(texture); // step 12 while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { window.close(); } } // Add non-event handling code here window.clear(); window.draw(sprite); // step 13 window.display(); } |
Number of
records = 160000 Original input data 0X37401800 0X27100 0X37401800 0X270FF 0X37401800 0X270FE 0X37401800 0X270FD 0X37401800 0X270FC 0XDFF00 0X1A576 0X37401800 0X6FB4 0XDFF00 0X1A577 0X37401800 0X6FB5 0XDFF00 0X1A578 Map data 0X1 0X37401800 0X2 0X37401800 0X3 0X37401800 0X4 0X37401800 0X5 0X37401800 0X270FC 0X37401800 0X270FD 0X37401800 0X270FE 0X37401800 0X270FF 0X37401800 0X27100 0X37401800 Vector data (records 12058 to 12062) <=== Step 6 00110111010000000001100000000000 00000011010001000110010000000000 00001000100011011010111100000000 00001110101101011010111100000000 00010010111000111101101100000000 Vector data after bit flip (records 12058 to 12062) <=== Step 7 11001000101111111110011111111111 11111100101110111001101111111111 11110111011100100101000011111111 11110001010010100101000011111111 11101101000111000010010011111111 Vector data as unsigned (records 12058 to 12062) <=== Step 8 0XC8BFE7FF 0XFCBB9BFF 0XF77250FF 0XF14A50FF 0XED1C24FF |
Your code should be "perfect" - some documentation, no warnings unless they are originated by SFML, use "good" practices.
Your code should contain two or more lambda functions.
Do not write a multiple file application - all of your code should be contained in one file.
Use iterator loops or algorithms for the map. You may use index loops for the vector.