Question: Programming Assignment 6: Mountain paths Assigned: 2/26 Due: 3/12 by email before the start of class Libraries you may use: iostream fstream string cstdlib ctime

Programming Assignment 6: Mountain paths

Assigned: 2/26 Due: 3/12 by email before the start of class

Libraries you may use:

iostream

fstream

string

cstdlib

ctime

NOTE: You do not need all of these in every file. The use of any other libraries will result in the loss of points.

What you need for Wednesday Checkin (2/28): Start a new project, your main should prompt the user for your topographical input file. You should use that information to create a GISMap object, then save your map converted to grayscale to disk. Demo this by reading in a sample image file (etopo1.asc, good.asc). Show that it works by viewing the image you have generated in IrfanView(will reqire a quick download on the lab machines if you do not still have it from last time).

For this assignment, we will be revisiting out mountain assignment from before, this time with classes. In addition, we will also be plotting a path through the mountains, and tracing it across our generated image. For this assignment we will be creating a GISMap class. It will store the data in a pixel struct, which you will use to find a path across the montain. We will be displaying this data in a PPM image. Unlike the PGM format we used before, this format requires tuples of data: red, green, and blue values. These values will need to be scaled beetween 0 and 255. If all 3 values are the same, you will get a gray-scale image. We will start by creating that, and then overlaying red lines on our mountain. You can turn a pixel red by maxing out the red value of the pixel.

Your pixel structure consists of 3 integers:

int red - this will eventually hold the red value which will be attributed to your image

int green - this will eventually hold the green value which will be attributed to your image

int blue - this will eventually hold the blue value which will be attributed to your image

NOTE: they will eventually hold values from 0-255, but you will likely want to designate at least one of these to start off holding your raw data from disk (before you scale it down).

Your GISMap class will minimally require the following attributes:

pixel data[MAX_ROWS][MAX_COLS] - the 2D array that holds your topographical data

int rows - the actual number of rows used in this map.

int cols - the actual number of columns used in this map.

Your GISMap class should also minimally contain the following member functions:

GISMap(string infile) - parameterized constructor. Note, there should be no default constructor. Open the file specified by infile, and read in the data. Remember, the first 2 integers in the file are the rows and columns of the data.

void scaleData() - this will walk through your data, and perform an in-place modification to convert all inputs to values from 0 through 255. This is effectively creating a gray-scale image.

void plotPath() - this function will find walkable paths over the mountain range you have loaded. You will likely want to call this before scaling your data (could make it easier). Pseudocode for this algorithm is below.

void saveToDisk(string outfile) - this function generates a full ppm file from your array of pixels. See ppm notes below

Don't forget, you will want to use symbolic constants for your data dimensions. You can assume that no image will have more than 500 rows and 1000 columns. You will want to declare this information in your header file. Feel free to add additional helper functions if you find it necessary.

Your main file will be very sparse for this assignment: Start by asking the name of the file to load. You will use this information to create a GISMap object. Your main will then need to plot paths over the mountains via the plotPath function, convert it via the scaleData function, and then finally save it via the saveToDisk function after prompting the user for an output file path. As such, you will not need to implement any further function in your main (unless you feel it would be helpful).

Sample outputs for these files can be found here: etopo1.ppm, good.ppm. Remember, there is an element of randomness to this, so yours may not look exactly the same.

Notes:

Mountain climbing:

We will be using a simple approach for this part of the assignment. Your algorithm should start from every pixel on the left hand side, and find a path across the map to the right hand side. For each pixel, look at the 3 pixels adjacent in the next column. Choose to move to the pixel that results in the lowest elevation change. If there is a tie, flip a coin to choose which direction to move. As this walk will need to be done in place, it is suggested that you mark any position as being visited by making it negative (multiply by -1). Pseudocode:

 for every row: currentCol := 0 while currentCol is less than max_cols: #note, a negative value means the position has already been visited # if the current position has been visited, you are done val := currentPosition up := checkUp() down := checkDown() across := checkAcross() markAsVisited(currentPosition) #mark the current position as being visited if across is minimum: move across #update currentCol accordingly else if up equals down: flip a coin to choose #update currentCol and currentRow correctly else: choose the minimum #update currentCol and currentRow correctly start from the next row down 
NOTE: I have chosen to make things look like functions here. You are not required to create additional functions. If you do, make sure to fully document your new functions.

Generating a PPM -

PPMs are very simple graphics files. To create a file in PPM format, you will need to first write out the following data:

 P3 # filename here COLUMNS ROWS 255 
After this, you will need to print out your data array. PPMs expect triplets (sets of 3) in the form of R(ed) G(reen) B(lue) values. For a sample file of
0 125 255
13 100 98
your generated PPM will look like this:
 P3 # sample.ppm 3 2 255 0 0 0 125 125 125 255 255 255 13 13 13 100 100 100 98 98 98 
To mark a visited pixel red (remember, after visiting it, it should be marked negative), simply set the R value (the first number) to the maximum value (255)

What to turn in:

A zip file containing:

GISMap.h - your topographical map header file.

GISMap.cpp - your implementation of your topographical map

main.cpp - your driver cpp

mountains.cbp - the code blocks project for this assignment

README - this is a simple text file. It should minimally contain: your name, the date, the name of the project, and a brief description of the project. Additionally, this is where you add implementation notes: did you have any modifications to the assignment? What default values did you assign in the constructor(s)? Why did you decide on the default values? Did you run into any problems? Did you attempt any extra credit? READMEs are a chance for you to pass on extra information about your work to whoever looks at it next (possibly future you!)

elev. change elev. change elev. change elev, change 96 4 00 1055 1044 109 9 109 9 973 100 107 7 00973 0097| 3 105 5 1055 105 5 elev. change elev. change elev. change elev, change 96 4 00 1055 1044 109 9 109 9 973 100 107 7 00973 0097| 3 105 5 1055 105 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!