zoukankan      html  css  js  c++  java
  • STL文件格式研究

    一、介绍

    STL文件格式(stereolithography,光固化立体造型术的缩写)是由3D SYSTEMS 公司于1988 年制定的一个接口协议,是一种为快速原型制造技术服务的三维图形文件格式。STL 文件由多个三角形面片的定义组成,每个三角形面片的定义包括三角形各个定点的三维坐标及三角形面片的法矢量。本文介绍如何通过C语言读取STL格式文件。

    二、STL格式

    在快速成型和分层制造领域,STL文件被广泛应用于实体的表述。其原理是
    将复杂的表面用有限个三角面片来拟合。其实和缝足球差不多,只不过足球
    多用五边形和六边形。由于STL文件和具体的CAD系统无关,也就是说几乎所
    有CAD系统都提供将各自特定格式的实体表示转换成STL文件的功能,所以非
    常好用。
    STL文件具有两种格式ASCII格式和二进制格式,但二进制格式文件的长度
    较前者小得多,一般为其1/6。现介绍如下:
    ASCII格式:
    solid <name>
    facet normal ni nj nk
    outer loop
    vertex v1x v1y v1z
    vertex v2x v2y v2z
    vertex v3x v3y v3z
    endloop
    endfacet
    ......
    endsolid<name>
    二进制格式:
    结构为:84个字节(byte)组成的题头,其中前80个字节用于表示有关文
    件、作者姓名和注释的信息,最后4个字节用于表示小三角形面面片的数目。
    对于每一个小三角形面片,有48个字节用于表示其法向量的X,Y和Z的分量
    以及三角形每个顶点的X,Y,Z的坐标,其中每个坐标用4个字节表示。最后
    有2个不用的字节。
    STL文件的二进制码输出形式是用IEEE整数和浮点数来表示的。结构如下:
    <Binary STL file>::=<Binary STL file header>{Facet storage}...
    <Binary STL file header>::=<80 bytes of solid name. Filled by
    SPACE character><4-byte-integer of
    facet number>
    <Facet storage>::=<Normal Vector><Vetex1><Vetex2><Vetex3>
    <Normal Vector>::=<4-byte-float of x><4-byte-float of y>
    <4-byte-float of z>
    <Vetex>::=<4-byte-float of x coordinate>
    <4-byte-float of y coordinate>
    <4-byte-float of z coordinate>
    有了这些格式的描述,就可以用一段程序方便地将这些数据读出来并进行
    处理了。

    三、示例代码

     1 #include <fstream>
     2 #include <iostream>
     3  using namespace std;
     4  
     5  int main()
     6  {
     7   int i,ns,ntr;
     8   float data;
     9   ifstream infile;
    10   infile.open("C:\E.STL",ios::binary);
    11   ntr = 100;   //Segy文件总道数
    12  
    13   infile.seekg(84,ios::beg);    //跳过84字节的卷头
    14   for(i=0;i<ntr;i++){
    15    
    16     infile.read((char*)&data,sizeof(float));
    17   
    18     cout<<data<<"
    ";
    19   
    20   }
    21   infile.close();
    22   return 0;
    23  }

    四、总结

    通过解析STL格式文件,我们可以开发接口读取STL文件导入模型到PDMS,或者从PDMS中输出STL格式文件到其他软件。

  • 相关阅读:
    HDU 1495 非常可乐
    ja
    Codeforces Good Bye 2016 E. New Year and Old Subsequence
    The 2019 Asia Nanchang First Round Online Programming Contest
    Educational Codeforces Round 72 (Rated for Div. 2)
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)
    AtCoder Regular Contest 102
    AtCoder Regular Contest 103
    POJ1741 Tree(点分治)
    洛谷P2634 [国家集训队]聪聪可可(点分治)
  • 原文地址:https://www.cnblogs.com/jevon1982/p/9532393.html
Copyright © 2011-2022 走看看