MCPcopy Create free account
hub / github.com/Kitware/VTK / ToDirectedGraph

Method ToDirectedGraph

Common/DataModel/vtkGraph.cxx:1842–1887  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1840
1841//------------------------------------------------------------------------------
1842bool vtkGraph::ToDirectedGraph(vtkDirectedGraph* g)
1843{
1844 // This function will convert a vtkUndirectedGraph to a
1845 // vtkDirectedGraph. It copies all of the data associated
1846 // with the graph by calling CopyInternal. Only one directed
1847 // edge is added for each input undirected edge.
1848
1849 if (this->IsA("vtkDirectedGraph"))
1850 {
1851 // Return the status of CheckedShallowCopy
1852 return g->CheckedShallowCopy(this);
1853 }
1854 else if (this->IsA("vtkUndirectedGraph"))
1855 {
1856 vtkSmartPointer<vtkMutableDirectedGraph> m = vtkSmartPointer<vtkMutableDirectedGraph>::New();
1857 for (vtkIdType i = 0; i < this->GetNumberOfVertices(); i++)
1858 {
1859 m->AddVertex();
1860 }
1861
1862 // Need to add edges in the same order by index.
1863 // vtkEdgeListIterator does not guarantee this, so we cannot use it.
1864 for (vtkIdType i = 0; i < this->GetNumberOfEdges(); i++)
1865 {
1866 m->AddEdge(this->GetSourceVertex(i), this->GetTargetVertex(i));
1867 }
1868
1869 if (g->IsStructureValid(m))
1870 {
1871 // Force full copy from this, internals will be invalid
1872 g->CopyInternal(this, false);
1873
1874 // Make internals valid
1875 g->SetInternals(m->Internals);
1876 return true;
1877 }
1878 else
1879 {
1880 return false;
1881 }
1882 }
1883 else
1884 {
1885 return false;
1886 }
1887}
1888
1889//------------------------------------------------------------------------------
1890bool vtkGraph::ToUndirectedGraph(vtkUndirectedGraph* g)

Callers 1

TestToDirectedGraphFunction · 0.80

Calls 11

GetNumberOfVerticesMethod · 0.95
GetNumberOfEdgesMethod · 0.95
GetSourceVertexMethod · 0.95
GetTargetVertexMethod · 0.95
IsAMethod · 0.80
CopyInternalMethod · 0.80
NewFunction · 0.50
CheckedShallowCopyMethod · 0.45
AddVertexMethod · 0.45
AddEdgeMethod · 0.45
IsStructureValidMethod · 0.45

Tested by 1

TestToDirectedGraphFunction · 0.64