資源簡介
用一個簡單的控制臺小程序實現對*.ply格式的3D模型文件的讀取和輸出,時要用到ply格式文件處理的程序的基礎,希望有所幫助!
代碼片段和文件信息
/*
Sample?code?showing?how?to?read?and?write?PLY?polygon?files.
Greg?Turk?March?1994
*/
#include
#include?
#include?
#include?“ply.h“
/*?user‘s?vertex?and?face?definitions?for?a?polygonal?object?*/
typedef?struct?Vertex?{
??float?xyz;?????????????/*?the?usual?3-space?position?of?a?vertex?*/
}?Vertex;
typedef?struct?Face?{
??unsigned?char?intensity;?/*?this?user?attaches?intensity?to?faces?*/
??unsigned?char?nverts;????/*?number?of?vertex?indices?in?list?*/
??int?*verts;??????????????/*?vertex?index?list?*/
}?Face;
/*?polygon?description?of?an?object?(a?cube)?*/
Vertex?verts[]?=?{??/*?vertices?*/
??{?0.0?0.0?0.0}
??{?1.0?0.0?0.0}
??{?1.0?1.0?0.0}
??{?0.0?1.0?0.0}
??{?0.0?0.0?1.0}
??{?1.0?0.0?1.0}
??{?1.0?1.0?1.0}
??{?0.0?1.0?1.0}
};
Face?faces[]?=?{??/*?faces?*/
??{?‘\001‘?4?NULL?}??/*?intensity?vertex?list?count?vertex?list?(empty)?*/
??{?‘\004‘?4?NULL?}
??{?‘\010‘?4?NULL?}
??{?‘\020‘?4?NULL?}
??{?‘\144‘?4?NULL?}
??{?‘\377‘?4?NULL?}
};
/*?list?of?vertices?for?each?face?*/
/*?(notice?that?indices?begin?at?zero)?*/
typedef?int?Vertex_Indices[4];
Vertex_Indices?vert_ptrs[]?=?{
??{?0?1?2?3?}
??{?7?6?5?4?}
??{?0?4?5?1?}
??{?1?5?6?2?}
??{?2?6?7?3?}
??{?3?7?4?0?}
};
/*?information?needed?to?describe?the?user‘s?data?to?the?PLY?routines?*/
char?*elem_names[]?=?{?/*?list?of?the?kinds?of?elements?in?the?user‘s?object?*/
??“vertex“?“face“
};
PlyProperty?vert_props[]?=?{?/*?list?of?property?information?for?a?vertex?*/
??{“x“?PLY_FLOAT?PLY_FLOAT?offsetof(Vertexx)?0?0?0?0}
??{“y“?PLY_FLOAT?PLY_FLOAT?offsetof(Vertexy)?0?0?0?0}
??{“z“?PLY_FLOAT?PLY_FLOAT?offsetof(Vertexz)?0?0?0?0}
};
PlyProperty?face_props[]?=?{?/*?list?of?property?information?for?a?vertex?*/
??{“intensity“?PLY_UCHAR?PLY_UCHAR?offsetof(Faceintensity)?0?0?0?0}
??{“vertex_indices“?PLY_INT?PLY_INT?offsetof(Faceverts)
???1?PLY_UCHAR?PLY_UCHAR?offsetof(Facenverts)}
};
write_test();
read_test();
/******************************************************************************
The?main?routine?just?creates?and?then?reads?a?PLY?file.
******************************************************************************/
main()
{
#if?1
??/*?write?a?PLY?file?*/
??write_test();
#endif
#if?1
??/*?read?a?PLY?file?*/
??read_test();
#endif
}
/******************************************************************************
Write?out?a?PLY?file.
******************************************************************************/
write_test()
{
??int?ij;
??PlyFile?*ply;
??int?nelems;
??char?**elist;
??int?file_type;
??float?version;
??int?nverts?=?sizeof?(verts)?/?sizeof?(Vertex);
??int?nfaces?=?sizeof?(faces)?/?sizeof?(Face);
??/*?create?the?vertex?index?lists?for?the?faces?*/
??for?(i?=?0;?i?????faces[i].verts?=?vert_ptrs[i];
??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????6882??2008-10-11?21:58??PLYtest\ply.h
?????文件???????7944??2008-10-11?22:33??PLYtest\plytest.cpp
?????文件???????4417??2011-02-13?17:41??PLYtest\PLYtest.dsp
?????文件????????522??2008-10-11?23:14??PLYtest\PLYtest.dsw
?????文件??????66560??2011-02-13?17:41??PLYtest\PLYtest.ncb
?????文件??????49664??2011-02-13?17:41??PLYtest\PLYtest.opt
?????文件???????6709??2011-02-13?15:40??PLYtest\PLYtest.plg
?????文件????????398??2011-02-13?15:40??PLYtest\test.ply
?????文件??????70744??2008-10-11?22:12??PLYtest\testfile.cpp
?????目錄??????????0??2011-02-15?20:10??PLYtest
-----------?---------??----------?-----??----
???????????????213840????????????????????10
- 上一篇:聯歡會抽獎軟件
- 下一篇:DISKID硬盤序列號查看器
評論
共有 條評論