Assignment 7 - STL / Bitmaps / SFML / Lambda functions

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).

Input file

Program Steps

  1. 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.

  2. Read the file and display the first 5 records and the last 5.

  3. 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.

  4. Print the first 5 and the last five elements of the map (this is a good place to use a lambda function).

  5. Copy the map values into a vector of bitset<32>.

  6. Print elements 12058 to 12062 of the vector.

  7. Flip the bits in each element of the vector.  Print elements 12058 to 12062 of the vector again.

  8. Print elements 12058 to 12062 of the vector again as unsigned int.

  9. Create an SFML image of size 400 x 400 (you may need some research here).

  10. 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).

  11. Create a texture using your image.

  12. Create a sprite using your texture.

  13. 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.

Suggested SFML code

         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

    sf::Sprite sprite(texture);    // step 12
    while (window.isOpen())
        sf::Event event;
        while (window.pollEvent(event))
            if (event.type == sf::Event::Closed)
        // Add non-event handling code here
        window.draw(sprite);       // step 13

Program Output

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

Vector data after bit flip (records 12058 to 12062)
   <=== Step 7

Vector data as unsigned (records 12058 to 12062)
     <=== Step 8

Program Requirements