我在大学有一个comp-sci项目让我有点难过。 1 [项目链接]此链接将带您进入网站,该项目是名为“LiDAR数据和3D阵列”的PDF。 该项目的基本前提是能够读取数据并将数据存储到3D char数组中,然后以图片的格式显示实际数据。这是我的代码,其中包含我们在类array3d中分配的3个方法。
#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;
}
}
}
// -----------------------------------------------------------------
这是MakeFile的代码,我们也应该创建
##
## 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
对于makefile,我们已经获得了main.o文件,但是无法访问它。库文件也在另一个目录中,因此我们必须使用许多不同的cmd行选项来访问它。
当我运行我的代码并执行zview时,最终发生的是它打开了应该显示图片的程序,但它上面没有图片,只是图片程序的标题和其他一些选项。基本上,我不知道我的问题是什么,但任何帮助将不胜感激。此外,请不要只给我答案,我想真正理解为什么这不起作用,所以任何建设性的帮助将不胜感激。