void create_S(graph_t* S, graph_t* A)
{
	std::vector<int>
		component(num_vertices(*A)),
		discover_time(num_vertices(*A));

//	const int num = strong_components(*A, &component[0]);
TODO: const int num = boost::strong_components(*A,
		      			boost::make_iterator_property_map(component.begin(), boost::get(boost::vertex_index, *A), component[0]));

	// now, create new graph
	for(unsigned int i=0; i<num;i++)
	 boost::add_vertex(*S);

	// get the property map for vertex indices
	typedef property_map<graph_t, vertex_index_t>::type IndexMap;
	IndexMap index = get(vertex_index, *A);

	graph_traits<graph_t>::edge_iterator ei, ei_end;
	for (tie(ei, ei_end) = edges(*A); ei != ei_end; ++ei)
	{
		const int source_comp = component[index[source(*ei, *A)]];
		const int target_comp = component[index[target(*ei, *A)]];

		if(source_comp != target_comp)
		 add_edge(source_comp, target_comp,*S);
	}

	assert(boyer_myrvold_planarity_test(*S));
}
Beispiel #2
0
 bool isPlanar(const Graph & g)
 {
     //We need to convert g into an adjacency_list because
     //the function of boost does not work correctly
     //on adjacency_matrix
     typedef boost::adjacency_list<boost::vecS, boost::vecS,
                                   boost::undirectedS> AdjList;
     typedef typename boost::graph_traits<Graph>::edge_iterator eiter;
     AdjList h(order(g));
     std::pair<eiter, eiter> ep;
     for (ep = edges(g); ep.first != ep.second; ++ep.first)
     {
         int u = source(*ep.first,g), v = target(*ep.first,g);
         add_edge(u,v,h);
     }
     return boyer_myrvold_planarity_test(h);
 }
int main() {
  Mat_<Vec<uchar,3> > imageRGB = imread(ACI_SOURCE_DIR "/aci/test/mickey.png");
  Mat_<Vec<uchar,3> > image;
  cvtColor(imageRGB, image, CV_RGB2Lab);
  Mat_<Vec<uchar,3> > smoothed;
  GaussianBlur(image, smoothed, Size(0,0), 0.8);
  WeightedGraph grid = gridGraph(smoothed, CONNECTIVITY_4);
  DisjointSetForest segmentation = felzenszwalbSegment(150, grid, 50);
  LabelledGraph<Mat> segGraph = segmentationGraph<Mat>(smoothed, segmentation, grid);
  Mat_<Vec<uchar,3> > segmentationImage = segmentation.toRegionImage(image);
  adjacency_list<vecS,vecS,bidirectionalS,property<vertex_index_t, int> > 
    boostGraph = segGraph.toBoostGraph();
  bool isPlanar = boyer_myrvold_planarity_test(boostGraph);
  cout<<"Planarity: "<<isPlanar<<endl;
  assert(isPlanar);
  segGraph.drawGraph(segmentCenters(image,segmentation), segmentationImage);
  imshow("segmentation graph", segmentationImage);
  waitKey(0);

  return 0;
}
Beispiel #4
0
void CPlanarGraph::DetectFaces()
{
	// Based on the example in (http://www.boost.org/doc/libs/1_47_0/libs/graph/example/planar_face_traversal.cpp)
	int numOfNodes = GetNumOfNodes();
	Graph g(numOfNodes);

	int numOfEdges = GetNumOfEdges();
	for ( int i=0; i<numOfEdges; i++ )
	{
		int idx0 = GetEdge(i).GetIdx0();
		int idx1 = GetEdge(i).GetIdx1();
		add_edge(idx0, idx1, g);
	}

	// Initialize the interior edge index
	property_map<Graph, edge_index_t>::type e_index = get(edge_index, g);
	graph_traits<Graph>::edges_size_type edge_count = 0;
	graph_traits<Graph>::edge_iterator ei, ei_end;
	for ( boost::tuples::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei )
	{
		put(e_index, *ei, edge_count++);
	}

	typedef std::vector< graph_traits<Graph>::edge_descriptor > vec_t;
	std::vector<vec_t> embedding(num_vertices(g));
#if 0
	// Test for planarity - we know it is planar, we just want to 
	// compute the planar embedding as a side-effect
	if ( boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
		boyer_myrvold_params::embedding = &embedding[0]	) )
	{
		std::cout << "Input graph is planar" << std::endl;
	}
	else
	{
		std::cout << "Input graph is not planar" << std::endl;
	}
#else
	// Compute the planar embedding based on node positions...
	VertexIterator vi, vi_end;
	for ( boost::tie(vi, vi_end) = boost::vertices(g); vi != vi_end; ++vi )
	{
		OutEdgeIterator ei, ei_end;
		std::vector<EdgeDescriptor> adjacentEdges;
		for ( boost::tie(ei, ei_end) = boost::out_edges(*vi, g); ei != ei_end; ++ei )
		{
			VertexDescriptor v1 = boost::source(*ei, g);
			VertexDescriptor v2 = boost::target(*ei, g);
			adjacentEdges.push_back(*ei);
		}
		SortAdjacentVertices(g, *vi, adjacentEdges);
		for(int i = 0; i < adjacentEdges.size(); ++i)
		{
			std::cout << *vi << " -> " << adjacentEdges[i] << std::endl;
		}
		if(adjacentEdges.size()>0)
			std::cout << std::endl;
		embedding[*vi] = adjacentEdges;
	}
#endif

	std::cout << std::endl << "Vertices on the faces: " << std::endl;
	vertex_output_visitor v_vis;
	planar_face_traversal(g, &embedding[0], v_vis);

	std::cout << std::endl << "Edges on the faces: " << std::endl;
	edge_output_visitor e_vis;
	planar_face_traversal(g, &embedding[0], e_vis);

	RemoveTheOutsideFace();
}
Beispiel #5
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  mwIndex n, nz, *ia, *ja; /* sparse matrix */
  int test_type = 0, rval=-1;

  load_graph_arg(nrhs, prhs, 0, -1, -1, 0, &n, &nz, &ia, &ja, NULL);
  test_type = (int)load_scalar_double_arg(nrhs, prhs, 1);

  /* [is_planar ksubgraph embedding] = planar_test_mex(A,0)
   * [is_kuratowski] = planar_test_mex(A,1)
   * [is_straight_line] = planar_test_mex(A,2,X)
   */

  plhs[0]= mxCreateDoubleMatrix(1,1,mxREAL);

  if (test_type == 0)
  {
    /* get planar subgraph information */
    int is_planar = 0;

    if (nlhs <= 1) {
      /* just test for the planar graph */
      rval= boyer_myrvold_planarity_test(n, ja, ia, &is_planar,
          NULL, NULL, NULL, NULL, NULL);
    } else if (nlhs <= 3) {
      /* test for the planar graph and the kuratowski subgraph */
      double *ki, *kj;
      mwIndex nedges= n>5 ? 3*n-6 : 10;
      plhs[1]= mxCreateDoubleMatrix(nedges,1,mxREAL); ki=mxGetPr(plhs[1]);
      plhs[2]= mxCreateDoubleMatrix(nedges,1,mxREAL); kj=mxGetPr(plhs[2]);
      nedges= 0;
      rval= boyer_myrvold_planarity_test(n, ja, ia, &is_planar,
          (mwIndex*)ki, (mwIndex*)kj, &nedges, NULL, NULL);
      expand_index_to_double((mwIndex*)ki, ki, nedges, 1.0);
      expand_index_to_double((mwIndex*)kj, kj, nedges, 1.0);
      mxSetM(plhs[1], nedges);
      mxSetM(plhs[2], nedges);
    } else if (nlhs > 3) {
      /* test for the planar graph and the edge order */
      double *eip, *eie;
      double *ki, *kj;
      mwIndex nedges= n>5 ? 3*n-6 : 10;
      plhs[1]= mxCreateDoubleMatrix(nedges,1,mxREAL); ki=mxGetPr(plhs[1]);
      plhs[2]= mxCreateDoubleMatrix(nedges,1,mxREAL); kj=mxGetPr(plhs[2]);
      nedges= 0;
      plhs[3]= mxCreateDoubleMatrix(n+1,1,mxREAL); eip= mxGetPr(plhs[3]);
      plhs[4]= mxCreateDoubleMatrix(nz,1,mxREAL); eie= mxGetPr(plhs[4]);
      rval= boyer_myrvold_planarity_test(n, ja, ia, &is_planar,
          (mwIndex*)ki, (mwIndex*)kj, &nedges, (mwIndex*)eip, (mwIndex*)eie);
      expand_index_to_double((mwIndex*)ki, ki, nedges, 1.0);
      expand_index_to_double((mwIndex*)kj, kj, nedges, 1.0);
      mxSetM(plhs[1], nedges);
      mxSetM(plhs[2], nedges);
      expand_index_to_double((mwIndex*)eip, eip, n+1, 1.0);
      expand_index_to_double((mwIndex*)eie, eie, nz, 1.0);
    }
    expand_int_to_double(&is_planar, mxGetPr(plhs[0]), 1, 0.0);
  }
  else if (test_type == 1)
  {
    /* test for a kuratowski subgraph */
    int is_ksubgraph= 0;
    rval= is_kuratowski_subgraph(n, ja, ia, &is_ksubgraph);
    expand_int_to_double(&is_ksubgraph, mxGetPr(plhs[0]), 1, 0.0);
  }
  else if (test_type == 2)
  {
    /** Test for a straight line embedding */
    int is_sldrawing= 0;
    double* X= load_matrix_double_arg(nrhs,prhs,2,"X",1,NULL,NULL,1,n,2);
    rval= is_straight_line_drawing(n, ja, ia, X, &is_sldrawing);
    if (rval==-11) {
      mexErrMsgIdAndTxt("matlab_bgl:callFailed",
          "is_straight_line_drawing requires positive positions.");
    }
    expand_int_to_double(&is_sldrawing, mxGetPr(plhs[0]), 1, 0.0);
  }

  if (rval != 0) {
    mexErrMsgIdAndTxt("matlab_bgl:callFailed",
        "The libmbgl call failed with rval=%i", rval);
  }
}