SLC文件解析

直接上代码吧!

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值