直接上代码吧!
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
std::string read(std::string& fs,size_t& index,size_t num)
{
std::string ret = fs.substr(index, num);
index += num;
return ret;
}
template<typename T>
T read(std::string& fs, size_t& index) {
T value;
std::memcpy(&value, fs.data() + index, sizeof(T));
index += sizeof(T);
return value;
}
int main()
{
size_t index = 0;
std::ifstream file("C:\\Users\\Deny\\Desktop\\src\\bool10.slc",std::ios::binary);
std::ostringstream ss;
std::string fs;
ss << file.rdbuf();
fs = ss.str();
index = fs.find("\x0d\x0a\x1a") + 3;
index = index + 256; //定位到头部信息之后
uint8_t size = read<uint8_t>(fs, index);
for (size_t i = 0; i < static_cast<int>(size); i++)
{
float z = read<float>(fs, index); //层高
float thick = read<float>(fs, index); //层厚
float lineWidth = read<float>(fs, index); //线宽
float remainSize = read<float>(fs, index); //保留字段
}
while (true)
{
float height = read<float>(fs, index); //读取层高
uint32_t boundariesNum = read<uint32_t>(fs, index); //读取有多少个轮廓
if (boundariesNum == 0xffffffff) //读取到尾部退出
{
break;
}
for (size_t i = 0; i < boundariesNum; i++)
{
uint32_t verticesNum = read<uint32_t>(fs, index); //读取每个轮廓有多少个点
uint32_t gapsNum = read<uint32_t>(fs, index);
for (size_t j = 0; j < verticesNum; j++)
{
float x = read<float>(fs, index);
float y = read<float>(fs, index);
}
}
}
return 0;
}