------------------------------------------------------------------------------
| 1840 | |
| 1841 | //------------------------------------------------------------------------------ |
| 1842 | bool 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 | //------------------------------------------------------------------------------ |
| 1890 | bool vtkGraph::ToUndirectedGraph(vtkUndirectedGraph* g) |