update: 2012/10/03
reference:
1. OpenMesh: First Steps - Building a cube
A. 新增專案
1. Visual Studio 2010 > 檔案 > 新增 > 專案
2. Visual C++ > Win32 > Win32 主控台應用程式
名稱: OpenMesh_Cube
位置: C:\Lanli\projects
為方案建立目錄: 取消勾選
> 確定
3. 下一步
> 空專案: 勾選
> 完成
-----------------------------------------------------------------------------------
B. 專案屬性設定
1. 點選 "OpenMesh_Cube" 專案 > 滑鼠右鍵 > 屬性:
組態屬性 > VC++ 目錄 >
Include 目錄: C:\Program Files (x86)\OpenMesh 2.2\include
程式庫目錄: C:\Program Files (x86)\OpenMesh 2.2\lib
> 確定
組態屬性 > 連結器 > 輸入:
其他相依性: OpenMeshCored.lib
OpenMeshToolsd.lib
> 確定
其中 2. 的 "其他相依性", 改成: (沒有 d 的版本)
OpenMeshCore.lib
OpenMeshTools.lib
-----------------------------------------------------------------------------------
C. 撰寫程式碼
1. 點選 "OpenMesh_Cube" 專案 > 滑鼠右鍵 > 加入 > 新增項目:
Visual C++ > C++ 檔 (.cpp)
名稱: main.cpp
> 新增
#include <iostream>
// -------------------- OpenMesh
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
// ----------------------------------------------------------------------------
typedef OpenMesh::PolyMesh_ArrayKernelT<> MyMesh;
// ----------------------------------------------------------------------------
// Build a simple cube and write it to std::cout
int main()
{
MyMesh mesh;
// generate vertices
MyMesh::VertexHandle vhandle[8];
vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, -1, 1));
vhandle[1] = mesh.add_vertex(MyMesh::Point( 1, -1, 1));
vhandle[2] = mesh.add_vertex(MyMesh::Point( 1, 1, 1));
vhandle[3] = mesh.add_vertex(MyMesh::Point(-1, 1, 1));
vhandle[4] = mesh.add_vertex(MyMesh::Point(-1, -1, -1));
vhandle[5] = mesh.add_vertex(MyMesh::Point( 1, -1, -1));
vhandle[6] = mesh.add_vertex(MyMesh::Point( 1, 1, -1));
vhandle[7] = mesh.add_vertex(MyMesh::Point(-1, 1, -1));
// generate (quadrilateral) faces
std::vector<MyMesh::VertexHandle> face_vhandles;
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[3]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[4]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[5]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[6]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[7]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[4]);
mesh.add_face(face_vhandles);
// write mesh to output.off
try
{
if ( !OpenMesh::IO::write_mesh(mesh, "output.off") )
{
std::cerr << "Cannot write mesh to file 'output.off'" << std::endl;
return 1;
}
}
catch( std::exception& x )
{
std::cerr << x.what() << std::endl;
return 1;
}
return 0;
}
3. 建置 > 建置方案
錯誤訊息:
"You have to define _USE_MATH_DEFINES in the compiler settings!"
4. 解決方式: (同時對 Debug 與 Release 版本作修改)
點選 "OpenMesh_Cube" 專案 > 滑鼠右鍵 > 屬性:
組態屬性 > C/C++ > 前置處理器:
_USE_MATH_DEFINES
> 確定
偵錯 > 啟動但不偵錯
(Debug 與 Release 版皆成功)
6.檢視結果:
用文字編輯器開啟專案根目錄下的 output.off 檔案, 如下所示:
OFF
8 6 0
-1 -1 1
1 -1 1
1 1 1
-1 1 1
-1 -1 -1
1 -1 -1
1 1 -1
-1 1 -1
4 0 1 2 3
4 7 6 5 4
4 1 0 4 5
4 2 1 5 6
4 3 2 6 7
4 0 3 7 4
-----------------------------------------------------------------------------------
D. 檢視 3D 圖形 (update: 2012/09/03)
1. 下載: MeshLab 並安裝.
2. 用 MeshLab 開啟 output.off 檔案.
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。