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

Method ToUndirectedGraph

Common/DataModel/vtkGraph.cxx:1890–1936  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1888
1889//------------------------------------------------------------------------------
1890bool vtkGraph::ToUndirectedGraph(vtkUndirectedGraph* g)
1891{
1892 // This function will convert a vtkDirectedGraph to a
1893 // vtkUndirectedGraph. It copies all of the data associated
1894 // with the graph by calling CopyInternal
1895
1896 if (this->IsA("vtkUndirectedGraph"))
1897 {
1898 // A normal CheckedShallowCopy will work fine.
1899 return g->CheckedShallowCopy(this);
1900 }
1901 else if (this->IsA("vtkDirectedGraph"))
1902 {
1903 vtkSmartPointer<vtkMutableUndirectedGraph> m =
1904 vtkSmartPointer<vtkMutableUndirectedGraph>::New();
1905 for (vtkIdType i = 0; i < this->GetNumberOfVertices(); i++)
1906 {
1907 m->AddVertex();
1908 }
1909
1910 // Need to add edges in the same order by index.
1911 // vtkEdgeListIterator does not guarantee this, so we cannot use it.
1912 for (vtkIdType i = 0; i < this->GetNumberOfEdges(); i++)
1913 {
1914 m->AddEdge(this->GetSourceVertex(i), this->GetTargetVertex(i));
1915 }
1916
1917 if (g->IsStructureValid(m))
1918 {
1919 // Force full copy from this, internals will be invalid
1920 g->CopyInternal(this, false);
1921
1922 // Make internals valid
1923 g->SetInternals(m->Internals);
1924
1925 return true;
1926 }
1927 else
1928 {
1929 return false;
1930 }
1931 }
1932 else
1933 {
1934 return false;
1935 }
1936}
1937
1938//------------------------------------------------------------------------------
1939void vtkGraph::PrintSelf(ostream& os, vtkIndent indent)

Callers 1

TestToUndirectedGraphFunction · 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

TestToUndirectedGraphFunction · 0.64