Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Flow Read the data into a 2D vector Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade

Program Flow Read the data into a 2D vector Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of gray for each cell in the map Produce the output file in the specified format (PPM) View your image result Step 1 - Read the data into a 2D vector Your first goal is to read the values into a 2D vector (i.e., a matrix) of ints from a data file. Note: You should use vector_name.at(index) to access the elements of the vector to benefit from the additional runtime checks. This data file contains, in plain text, data representing the average elevations of patches of land (roughly 700x700 meters) in the US. The user of your program will provide as input three values (your program will read these values from standard input, i.e., using cin, and do so in the following order): The number of rows in the map; (The height of the image to be produced.) The number of columns in the map; (The width of the image to be produced.) The name of the file containing the map data. After reading these data items from the user, you should read the elevation data from the specified file. We provide several sample data files containing elevation data for most of the state of Colorado (mountains!). Other input files can be obtained from the National Oceanic and Atmospheric Administration (http://maps.ngdc.noaa.gov/viewers/wcs-client/). A data file comes as one large, space-separated list of integers. A file representing a 480-row by 844-col grid contains 405,120 integers (480*844). Each integer is the average elevation in meters of each cell in the grid. The data is listed in row-major order, i.e., first the 844 numbers for row 0, then the 844 numbers for row 1, etc. Hints/Warnings: The data is given as a continuous stream of numbers - there may be no line breaks in the file. You should validate the input from the user (number of rows and columns), and you should also validate that the input file exists and that it contains all the data for the expected numbers of rows and columns. It is ok to exit the program execution with an error message if there is an input error, i.e., you do not need to give the user a chance to enter corrected data. Start all error messages with Error: (note the colon). Then exit the program with a non-zero exit code (just an integer) to indicate you are exiting the program with an error. You can call exit(n) where n is the exit code. Returning a value from main will do the same thing. You may want to make sure that you are reading the data correctly before you move to the next step of this project. Implement code to print your map data and try out your code with a file containing a small map first (you can create an input file corresponding to 4 rows and 4 columns, for example.) Then check what happens when you read the sample map data files: (100 by 100, 480 by 480, 844 by 480). You can download the example map data files (shown below) packaged together (in zip format) via https://drive.google.com/open?id=0B_ouNNuWgNZCRWwyVFVVTGpNb3M (note: will needed to be logged into TAMU Google account for access). Download Link for Map Data Files Resulting Image 100X100 480X480 844X480 Step 2 - Find the min and max values In order to draw the map with a gray scale that indicates the elevation, you will need to determine which scale to use, i.e., which will be shown as a dark area (with low elevation) and which ones will be shown as bright areas (high elevation). This means you need to find the min and max values in the map first, so that you know which values to associate with the brightest and darkest colors. You can compute the min and max elevation values by writing code that scans the entire map data and keeps track of the smallest and largest values found so far. Test this functionality to make sure youre getting the correct values for min and max, before you proceed to implement the rest of the program. You may want to check with a friend or colleagues in the Piazza forum to see if other students are getting the same min and max values for the provided input files. Step 3 - Compute the color for each part of the map and store For each value in the vector of elevation data, you will calculate the shade of grey that corresponds to that elevation point using the following equation: Use the min and max elevations calculated from Step 2. Also round the value you get to the nearest whole number since RGB values are integers. As you compute the shade of grey, store that value in three parallel vectors for R, G and B. Putting the same value for R, G and B will result in grey. The structure of the vector should mirror the vector with the elevation data. This structure is required in the next part of the homework. If you use an alternative structure, then you will have to redo that part in the next homework. Search the zyBook for more information about parallel vectors searching for multiple vectors. Unfortunately, the zyBook uses this more ambiguous term.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions