2016-07-20 20 views
1

我想使用OpenMesh對網格進行抽取。 我跟着的是在該文檔被陳述的非常例如:OpenMesh Decimater不會減少頂點數

cout << "Vertices: " << mesh->n_vertices() << endl; 

    DecimaterT<Mesh> decimater(*mesh); // a decimater object, connected to a mesh 
    ModQuadricT<Mesh>::Handle hModQuadric;  // use a quadric module 

    decimater.add(hModQuadric); // register module at the decimater 
    decimater.initialize();  // let the decimater initialize the mesh and the 
            // modules 
    decimater.decimate_to(15000);   // do decimation 

    cout << "Vertices: " << decimater.mesh().n_vertices() << endl; 

decimate_to方法正確地終止並返回56000,這是應該已經崩潰的頂點的數量。

但是,我可以告訴日誌,網格上的頂點數沒有改變。 這怎麼可能?

回答

2

抽取通過刪除元素(頂點,面等)來更改網格的連通性。在OpenMesh中去除網格元素是通過暫時標記要刪除的元素來實現的(使用mesh.status(handle).deleted()屬性)。刪除元素的實際刪除僅在明確請求時纔會發生,請致電mesh.garbage_collection()。在垃圾回收之前,mesh.n_vertices()仍然包含標記爲刪除其頂點的頂點。

Decimator不會自動提示垃圾收集;它留給用戶來做。在decimater.decimate_to(...)之後插入mesh.garbage_collection()的電話應該可以解決您的問題。

+0

你做了我的一天。謝謝。你有沒有指向在官方文檔中說明這種行爲的地方?^^ – Lake

+1

@Lake對[刪除幾何元素]有一個一般的解釋(http://www.openmesh.org/media/Documentations/OpenMesh-6.2-文檔/ a00060.html)。不幸的是,'decimate_to'不會觸發垃圾回收這一事實似乎只能通過'DecimaterT.cpp'實現中的源代碼註釋來記錄。 – jsb

+1

@Lake從OpenMesh 6.3開始,文檔已相應更新。 – jsb