I have a comp-sci project at university that has me somewhat stumped. 1[Project Link]This link will take you to the website, and the project is the PDF called "LiDAR Data and 3D arrays". The basic premise of the project is to be able to read and store data into a 3D char array, and then show the actual data in the format of a picture. Here is my code that contains the 3 methods we were assigned to write in the class array3d.
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <fstream>
using namespace std ;
// -----------------------------------------------------------------
// array3d class with variables for 3D Matrix boundaries, 3D Matrix itself,
// Methods to store data in 3D Matrix, and display LiDAR data
class array3d
{
private:
int m, n, p;
int a, b, c;
char *** G;
public:
array3d();
~array3d();
bool read(char * fname);//Method to read file and store data in 3D Matrix
void get_sizes(int & a, int & b, int & c);//Method to fine values of m, n, and p
int get_zmap_value(int x, int y);// Method to return highest occupied cell for pos. x, y
};
// -----------------------------------------------------------------
bool array3d::read(char * fname)
{
//Read the data into a 3D matrix
ifstream ifs;
ifs.open(fname);
if(!ifs.is_open())
{
cerr << "Can not open (read) file '" << fname << "'" << endl;
return false;
}
ifs >> m;
ifs >> n;
ifs >> p;
G = new (nothrow) char **[m];
for(int i = 0; i < m; i++)
{
G[n] = new (nothrow) char *[n];
for(int j = 0; j < n; j++)
{
G[n][p] = new (nothrow) char [p];
for(int k = 0; k < p; k++)
{
ifs >> G[m][n][p];
}
}
}
ifs.close();
return true;
}
// -----------------------------------------------------------------
void array3d::get_sizes(int & a, int & b, int & c)
{
//Get values for m, n, and p using pass-by-reference semantics
a = m;
b = n;
c = p;
}
// -----------------------------------------------------------------
int array3d::get_zmap_value(int x, int y)
{
//Returns the highest occupied cell (z-index) for pos. x, y in the ground plane
for(int z = 0; z < p; z++)
{
if(G[x][y][z] == 1)
{
return z;
}
}
}
// -----------------------------------------------------------------
And here is the code for the MakeFile we are also supposed to create
##
## FILE: MakeFile
##
zview: array3d.o main.o
g++ -o zview array3d.o main.o -L/user/local/lib -lppm_graphic
##
array3d.o: array3d.cc
g++ -c array3d.cc
##
##
clean:
/bin/rm array3d.o main.o zview
For the makefile, we have been given the main.o file, but are unable to access it. Also the library file is in another directory, so we have to access that using a number of different cmd line options.
What ends up happening when I run my code, and do zview, is that it opens the program that is supposed to show pictures, but there is no picture on it, just the title of the picture program and some other options. Basically, I am not sure what my problem is here, but any help would be appreciated. Also, please don't just give me the answer, I would like to actually understand why this is not working, so any constructive help would be greatly appreciated.