我试图从一个文件中读取一个结构,到2048年的块中。但我不明白该怎么做,我自己累了,但它只读了一个块,我该怎么办?实现它?
我有这个:
int chunks = ceil(lasHeader.Legacy_Number_of_Point_Records / 2048);
for (unsigned long i = 0; i < chunks; i++)
{
LASPOINT * pts = new LASPOINT[2048];
fread(pts, sizeof LASPOINT, 2048, of);
for (int j = 0; j < 2048; j++)
{
LASPOINT pt = *pts;
pt.X = pt.X * lasHeader.X_Scale_Factor + lasHeader.X_Offset;
pt.Y = pt.Y * lasHeader.Y_Scale_Factor + lasHeader.Y_Offset;
pt.Z = pt.Z * lasHeader.Z_Scale_Factor + lasHeader.Z_Offset;
pt.X = (pt.X - scalex) / 1.0;
pt.Y = (pt.Y - scaley) / 1.0;
pt.Z = (pt.Z - 0.0) / 1.0;
ret.points.push_back(pt.X);
ret.points.push_back(pt.Z);
ret.points.push_back(pt.Y);
pts++;
}
}
这是我的完整代码:
#define LAS_1_4
#include "LasLoader.h"
const char* file_mode = "r";
LASHEADER lasHeader;
LasData LoadQuickData(const char* file)
{
LasData ret;
FILE* of;
int size_p = sizeof(lasHeader);
__asm
{
push ebp
push file_mode
push file
call fopen
mov of, eax
mov esi, esp
mov eax, DWORD PTR of
push eax
push 1
push size_p
lea ecx, DWORD PTR lasHeader
push ecx
call DWORD PTR fread
}
///////////////////////////THIS WORKS ///////////////////////////////////////////////
//LASPOINT * pts = new LASPOINT[lasHeader.Legacy_Number_of_Point_Records];
//fseek(of, lasHeader.Offset_To_Point_Data, 0);
//fread(pts, (int)lasHeader.Legacy_Number_of_Point_Records, sizeof LASPOINT, of);
//////////////////////////////////////////////////////////////////////////////////////.
//THIS DOES NOT WORK:
//---------------------------------------------------------------------------------
float scalex = (float)lasHeader.Min_X;
float scaley = (float)(lasHeader.Min_Y + (lasHeader.Max_Y - lasHeader.Min_Y));
int chunks = ceil(lasHeader.Legacy_Number_of_Point_Records / 2048);
long offset = lasHeader.Offset_To_Point_Data;
fseek(of, lasHeader.Offset_To_Point_Data, 0);
for (unsigned long i = 0; i < chunks; i++)
{
LASPOINT * pts = new LASPOINT[2048];
long size = fread(pts, sizeof LASPOINT, 2048, of);
cout << size << endl;
for (int j = 0; j < 2048; j++)
{
LASPOINT pt = *pts;
pt.X = pt.X * lasHeader.X_Scale_Factor + lasHeader.X_Offset;
pt.Y = pt.Y * lasHeader.Y_Scale_Factor + lasHeader.Y_Offset;
pt.Z = pt.Z * lasHeader.Z_Scale_Factor + lasHeader.Z_Offset;
pt.X = (pt.X - scalex) / 1.0;
pt.Y = (pt.Y - scaley) / 1.0;
pt.Z = (pt.Z - 0.0) / 1.0;
ret.points.push_back(pt.X);
ret.points.push_back(pt.Z);
ret.points.push_back(pt.Y);
pts++;
}
fseek(of, offset += 2048, 0);
}
__asm
{
mov eax, of
push eax
call fclose
add esp, 28
pop ebp
}
cout << file << endl;
cout << "-----------------------------------------" << endl;
cout << lasHeader.Legacy_Number_of_Point_Records << " Points Loaded." << endl;
cout << lasHeader.Generating_Software << endl;
ret.Header = lasHeader;
return ret;
}