2013-10-21 33 views
2

我目前使用boost幾何/空間索引庫,以便在三維邊界框上執行範圍查詢。例如,我能夠獲得所有邊界框的列表,它們與查詢邊界框重疊。Boost幾何/空間查詢形狀

該文檔(http://www.boost.org/doc/libs/1_54_0_beta1/libs/geometry/doc/html/geometry/spatial_indexes/queries.html)顯示 - 至少在2d中 - 可以使用多邊形代替邊界框作爲查詢對象。是否有可能在3D中使用更高級的查詢形狀?我正在考慮像定向包圍盒,金字塔或相機錐體這樣的對象。如果是這樣的話:我該怎麼做/我可以在哪裏找到一個例子?

感謝

回答

3

簡而言之:這不是因爲支持現在Boost.Geometry OOB,金字塔和截錐體概念不可/支持。

但理論上應該可以執行這樣的查詢。在查詢期間,bgi :: rtree調用在命名空間幾何中定義的足夠的布爾算法,例如,如果調用

rtree.query(bgi::intersects(my_geometry), out_it); 

內部

bg::intersects(xxx, my_geometry); 

被調用,其中xxx爲節點的包圍盒或價值的可轉位(例如也有一個區域)。所以,如果你實現了

namespace boost { namespace geometry { 

template <typename Box> inline 
bool intersects(Box const& b, MyFrustum const& f) 
{ 
    // your implementation 
} 

}} 

理論上它應該工作。雖然沒有測試過。

此外,如果你想開發人員直接聯繫你可能會考慮訂閱Boost.Geometry郵件列表:http://lists.boost.org/mailman/listinfo.cgi/geometry

+0

謝謝您的提示。您發佈的代碼不會立即爲我工作。不知道究竟是什麼缺乏。看看intersects.hpp的源代碼,我也覺得它應該......我會盡量讓它工作 - 如果沒有,我會直接向開發人員詢問,正如你所建議的那樣。 – Dtag

+0

我試過了,並且按照預期調用了這個函數。儘管我沒有實現一個真實的工作示例。你能分享什麼不起作用嗎? –

+0

我爲我的類型「cg :: Frustum」嘗試了這個,並且只寫了一個總是返回true的函數。我得到以下錯誤:/ usr/include/boost/geometry/core/point_type。hpp:45:5:錯誤:沒有匹配函數調用'assertion_failed(mpl _ :: failed ************(boost :: geometry :: traits :: point_type :: NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE :: ************)(mpl _ :: assert _ :: types ))' - 任何建議? –

2

我有同樣的問題,並與@Adam聊天后,他提出了以下解決方案,它固定這個問題對我來說(我在GCC上構建我的代碼,上面的解決方案似乎只在Visual Studio上編譯)。

#include <boost/geometry.hpp> 

struct MyFrustum 
{ 
    MyFrustum(int d) : dummy(d) {} 
    int dummy; 
}; 

namespace boost { namespace geometry { 

// This will be called for Nodes and Values! 

template <typename Box> inline 
bool intersects(Box const& b, MyFrustum const& f) 
{ 
    std::cout << "checking the intersection with " << f.dummy << std::endl; 
    return true; 
} 

}} 

#include <boost/geometry/index/rtree.hpp> 

顯然,這樣編譯器不會退回到它的默認實現(產生尚未實現的誤差),其中東西定義的順序是非常重要的。

希望能夠幫助,再次感謝亞當!

1

這裏的其他答案很好,但我仍然遇到了Xcode的麻煩,無論我包含/聲明瞭什麼東西。我將這個答案發布給那些無法在他們的環境中工作的人。 這裏的其他解決方案在Visual Studio 2013中適用於我,但不適用於Xcode 5.1.1。該編譯器似乎存在重載解決問題。解決方法是避免使用「Box」的模板類型,並直接使用所有具體類型,如下所示:

#include <boost/geometry.hpp> 

namespace bg = boost::geometry; 
using point3d = bg::model::point<float, 3, bg::cs::cartesian>; 
using box3d = bg::model::box<point3d>; 

namespace boost { namespace geometry { 

    template <> inline 
    bool intersects(box3d const& b, MyFrustum const& p) { 
     // your implementation 
     return true; 
    } 
}