------------------------------------------------------------------------------
| 1888 | |
| 1889 | //------------------------------------------------------------------------------ |
| 1890 | bool 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 | //------------------------------------------------------------------------------ |
| 1939 | void vtkGraph::PrintSelf(ostream& os, vtkIndent indent) |