c ive attached the code for part 1 The first three steps of

c++ ive attached the code for part 1

The first three steps of your program are the same ones from Part I:

Step 1. Read the data into a 2D array

Step 2. Find min and max elevation values

Step 3. Compute the grayscale value for each cell in the map

Complete the following new steps for this homework:

Step 4: Create a function that finds greedy paths and colors them

Create a new function colorPath() with exactly the following function signature/prototype:

int colorPath(const vector< vector<int> >& heightMap,
vector< vector<rgb> >& image,
  rgb path_color,
int start_row);

Your function should do the following:

Modify the 2D vector image to set the color of the cell at column 0 and row start_row to path_color.

Determine the next position (following the rules of the greedy path strategy above) and color it too.

Continue until the last column is reached.

Return the TOTAL elevation change for the path

Use the elevation data in the 2D vector heightMap to compute elevation changes (be sure to use absolute value), and follow the rules (including the tie-breaking rules) of the greedy path strategy to choose the next cell to \"move to\" (HINT: Don\'t forget that your path can\'t go out of the range of the map). Keep track of the running total of elevation changes for all the steps. Your function should return this total, which will be used in Part III to compare different paths.

Note that rgb is a struct containing three ints (one for each color channel: r, g, b), and image is a 2D vector of rgb values. This is the vector storing the pixel data that will be written to the PPM file.

Step 5: Call Function for Three Starting Points

Your program should call the function from Step 4 for each the three rows indicated below. Pass your function the RGB values for this shade of red (R: 252, G: 25, B: 63). Note that your program should call colorPath(), not the user. Do not add any additional user input to the program.

First row (row index 0)

Middle row (row index numRows/2 - don\'t forget this is integer division)

Last row (row index numRows -1)

Steps 6 & 7 (already done)

After coloring the three greedy paths on a map, your program should generate the PPM file for that map (just like in Part I). So when you run your completed program, it should prompt the user for the same input as in Part I, and output a PPM file that visualizes the map (just like in Part I), but with 3 red paths embedded in the image. You can visualize the PPM image with the sameonline tool from Part I to make sure it appears as expected.

Solution

int colorPath(const vector< vector<int> >& heightMap,vector< vector<rgb> >& image,rgb path_color, int start_row)
{
   int colom=0;
   Start_row=path_color;
   int elevChange1, elevChange2, elevChange3;
   for (int i = 0; i < colCount; i++)
{
if (Start_row == 0)
{
elevChange2 = abs(Map[Start_row][colom] - Map[Start_row][colom + 1]);
elevChange3 = abs(Map[Start_row][colom] - Map[Start_row + 1][colom + 1]);
Map[Start_row][colom] = 1;

if (elevChange2 == elevChange3)
{
colom++;
totalElevChange += elevChange2;
} else if (elevChange2 < elevChange3)
{
colom++;
totalElevChange += elevChange2;
} else {
Start_row++;
colom++;
totalElevChange += elevChange3;
}
} else if ( Start_row == 99)
{
elevChange1 = abs(Map[Start_row][colom] - Map[Start_row - 1][colom + 1]);
elevChange2 = abs(Map[Start_row][colom] - Map[Start_row][colom + 1]);
Map[Start_row][colom] = 1;

if (elevChange1 == elevChange2)
{
colom++;
totalElevChange += elevChange2;
} else if (elevChange1 < elevChange2)
{
colom++;
Start_row--;
totalElevChange += elevChange1;
} else {
colom++;
totalElevChange += elevChange2;
}
} else {
elevChange1 = abs(Map[Start_row][colom] - Map[Start_row - 1][colom + 1]);
elevChange2 = abs(Map[Start_row][colom] - Map[Start_row][colom + 1]);
elevChange3 = abs(Map[Start_row][colom] - Map[Start_row + 1][colom + 1]);
Map[Start_row][colom] = 1;

if (elevChange1 == elevChange2 && elevChange2 == elevChange3)
{
colom++;
totalElevChange += elevChange2;
} else if (elevChange2 == elevChange1 && elevChange2 < elevChange3)
{
colom++;
totalElevChange += elevChange2;
} else if (elevChange2 == elevChange3 && elevChange2 < elevChange1)
{
colom++;
totalElevChange += elevChange2;
} else if (elevChange1 == elevChange3 && elevChange1 < elevChange2)
{
int randNum = rand() % 2;
if (randNum == 0)
{
Start_row--;
colom++;
totalElevChange += elevChange1;
} else
{
Start_row++;
colom++;
totalElevChange += elevChange3;
}
} else if (elevChange1 < elevChange2 && elevChange1 < elevChange3)
{
Start_row--;
colom++;
totalElevChange += elevChange1;
} else if (elevChange2 < elevChange1 && elevChange2 < elevChange3)
{
colom++;
totalElevChange += elevChange2;
} else if (elevChange3 < elevChange1 && elevChange3 < elevChange2)
{
Start_row++;
colom++;
totalElevChange += elevChange3;
}
}


}

for (int i = 0; i < rowCount; i++)
{
for (int j = 0; j < colCount; j++)
{
if (Map[i][j] != 1)
{
Map[i][j] = 0;
}
cout << Map[i][j] << \" \";
}
cout << endl;
}

return totalElevChange;
}
int call_function(int r,int b,int g)
{  
   int index,numrow;
`   colorpath(252,25,63)
{
   r=252;
   b=25;
   g=63;
   int first_row(int row=o)
   {
       index=0;
   {
   int Middle_row(int row)
   {
   Index=numrow/2;
   Return;
}
Int last_row(int row)
{
   Index =numrow-1;
   Return;
}
   int main()
{
try {
int r,g,b;
string filename;
getUserInput(r,g,b);

vector< vector<int> > map;
readData(r,g,b);

vector< vector<int> > image;
readData(image);

  

outputPPM(Map filename + \".ppm\");
outputPPM(image filename + \".ppm\");

  
system(\"pause\");
}
catch (runtime_error& e) {
cerr << e.what() << endl;
system(\"pause\");
return 1;
}
}

c++ ive attached the code for part 1 The first three steps of your program are the same ones from Part I: Step 1. Read the data into a 2D array Step 2. Find min
c++ ive attached the code for part 1 The first three steps of your program are the same ones from Part I: Step 1. Read the data into a 2D array Step 2. Find min
c++ ive attached the code for part 1 The first three steps of your program are the same ones from Part I: Step 1. Read the data into a 2D array Step 2. Find min
c++ ive attached the code for part 1 The first three steps of your program are the same ones from Part I: Step 1. Read the data into a 2D array Step 2. Find min

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site