0.條條大路
前面介紹的使用WPF自己撰寫算法實現點數據的三角划分以圖實現輪廓的三維重構。
但簡單的算法以及不加其他處理效果不佳,對於點數據的三角划分在查閱了一些論文后發現有:
基於圖的最短路徑、Delaunay、角點匹配后的等比例三角划分、插值、平滑等操作。
恰好師姐的老公便是研究三維重建這塊,這就叫好運道吧,纏着賴着請劉石堅師兄做了一番指導,
並查看了他說做的實驗的一些結果like this:
OMG相對於我自己實現的效果一個是天蓬一個是高老庄老豬!
更要命的是這個效果僅僅需要調用一些函數即可!
於是,性喜偷懶的我立馬調轉草頭轉入VTK陣營。
1.Force Of OpenSource
下面是VTK官網的簡介:
The Visualization ToolKit (VTK) is an open source, freely available software system for 3D computer graphics,image processing, and visualization used by thousands of researchers and developers around the world. VTK consists of a C++ class library, and several interpreted interface layers including Tcl/Tk, Java, and Python. Professional support and products for VTK are provided by Kitware, Inc. (www.kitware.com) VTK supports a wide variety of visualization algorithms including scalar, vector, tensor, texture, and volumetric methods; and advanced modeling techniques such as implicit modelling, polygon reduction, mesh smoothing, cutting, contouring, and Delaunay triangulation. In addition, dozens of imaging algorithms have been directly integrated to allow the user to mix 2D imaging / 3D graphics algorithms and data.
這里是一個VTK相關論壇
http://www.vislab.cn/bbs/forumdisplay.php?fid=19
感謝OpenSource參與人,你們讓世界更和諧;感謝互聯網讓這么多好用的庫得以發展壯大。
VTK下載安裝請參考:(64bit WIN7 & VS2012)
http://blog.csdn.net/shenlan282/article/details/8262232
(注:本人並沒按博主所說做第二步
2. 用 vc++2010打開 D:\VTK\VTKbin\Utilities\MaterialLibrary目錄下的 MaterialLibrary.sln 文件,右鍵點擊All_Build選擇重新生成。
也成功了,說明這步是可以跳過的吧,或者影響不是全局的)
VTK的安裝需要預先CMAKE然后再編譯因此還是有一些步驟需要處理,上面文章介紹很好,感謝博主。
本人由於是64bit WIN8 & VS2012安裝起來又有一些不同。這里做簡單介紹:
vtk_data_root,瀏覽到例子數據所在位置,如“d:\vtk\vtkdata”
這里是用於將實例程序的數據路徑指定到下載的vtkdata文件夾,如果沒有在cmake時候選擇這一個那么很多實例就
不會出效果,奈何呢,因為程序參數里面沒有指定路徑呀,因此如果你需要編譯實驗測試例子的話還請記得加上這個!
然后就是出現This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended.
的錯誤,對於WIN8來說需要將幾個頁面的define修改成(注意,整個VTKsolution有很5個文件需要修改!所以別指望修改了一個編譯就可通過哦)
關於為什么修改成類似0x0602請參考MSDN
http://msdn.microsoft.com/zh-cn/library/windows/desktop/aa383745(v=vs.85).aspx
// Modify the following defines if you have to target a platform prior to the ones specified below. // Refer to MSDN for the latest info on corresponding values for different platforms. #ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later. #define WINVER 0x0602 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. #endif #ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later. #define _WIN32_WINNT 0x0602 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. #endif #if _MSC_VER >= 1300 #ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. #endif #endif #ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later. #define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later. #endif
在對build_all成功后可以運行coneX這幾個實例看看效果,但是通常實例會一閃而過,因為程序並沒做等待用戶控制才結束的情況!
里面實例很多很多,相信大家把他們啃完就會畫龍懂描蛇鳥~~
順便說一下,VTK的.NET版本,由於當時找了好幾個都是網友做的,都停留在很老的版本里,所以這里附上我找到最好的版本:
而這也是維護VTK的kitware說維護的版本因此更新快,質量好,目前是到5.8.0,不過郁悶的是.NET下只能支持到VS2008 by Now。
所以我的2012就費了...
VTK.NET之ACTIVIZ.NET
http://www.vtk.org/Wiki/VTK/CSharp/ActiViz.NET
Activiz.NET例子
http://www.vtk.org/Wiki/VTK/Examples/CSharp
在安裝好后剩下的就是生成輪廓,並實現三維模型的任意平面切割了。