2014-04-22 1 views
0

부스트 그래프 라이브러리에 문제가 있습니다. (이미지 처리 OTB 라이브러리를 사용연결을 알고있는 부스트 인접 그래프에 인접 꼭지점을 만듭니다.

typedef boost::adjacency_list<boost::vecS, 
           boost::vecS, 
           boost::undirectedS, 
           boost::property<boost::vertex_bundle_t, unsigned int>, 
           boost::property<boost::edge_bundle_t, float>, 
           boost::no_property> GraphType 

I 이미지 정점의 화소마다 작성하는 제 1 루프를 않았다 초기화 단계

는,이 인접 그래프에 이미지를 저장할 , in_iter 이미지의 픽셀에 불과 반복자)입니다 :

unsigned long int curr_id = 0; 
for(in_iter.GoToBegin(); !in_iter.IsAtEnd(); ++in_iter) 
{ 
    boost::add_vertex(curr_id, *_graph); 
    curr_id++; 
} 

그리고 지금은 이웃 (4 connexity)와 정점의 연결을 만들려면 : 내가 이것을 시도했지만 작동하지 않습니다 :

curr_id = 0; 
long int neighbors[4]; 
auto iterBounds = boost::vertices(*_graph); 
for(auto v_iter = iterBounds.first; v_iter != iterBounds.second; v_iter++) 
{ 
    FindNeighboring(curr_id, neighbors, rows, cols); 
    for(short j = 0; j<4; j++) 
    { 
    if(neighbors[j] > -1) 
    { 
     boost::add_vertex(*_graph->m_vertices[curr_id], 
         *_graph->m_vertices[neighbors[j]], 
         std::numeric_limits<float>::max(); 
         *_graph); 
    } 
    } 
} 

해당 위치를 알고있는 정점 설명자에 액세스하려고합니다. BGL에서 그렇게 할 수 있습니까?

도움 주셔서 감사합니다.

답변

0

대답은 "예"입니다.

그래프에 일반 adjacency_list을 사용하는 경우 물론 <coords> <--> <vertex>의 서신을 유지해야합니다. boost :: unordered_map < Point, vertex_descriptor> 또는 boost :: bimap 또는 std :: map으로 제공되는 매핑으로 유지할 수 있습니다. 지도를 채우고 그래프와 함께 유지하는 것은 귀하의 책임입니다.

또는 BGL 내장 클래스 grid_graph을 고려해 볼 수 있습니다.

// Get the vertex associated with vertex_index 
Traits::vertex_descriptor 
vertex(Traits::vertices_size_type vertex_index, 
     const Graph& graph); 

// Get the index associated with vertex 
Traits::vertices_size_type 
get(boost::vertex_index_t, 
    const Graph& graph, 
    Traits::vertex_descriptor vertex); 

(에지와 유사한 기능) : 그것은 당신에게 좌표에서 정점 기술자에 대한 매핑을 제공합니다.

여기에서는 개별 정점을 만들 필요가 없으며 그래프의 치수를 지정하는 순간 BGL에 의해 그래프 생성자에서 만들어집니다.

사용자 정의 속성 맵을 사용하여 픽셀을 각 꼭지점과 연결할 수도 있지만 별도의 스토리입니다.