ctkDependencyGraph.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. #ifndef __ctkDependencyGraph_h
  11. #define __ctkDependencyGraph_h
  12. // Qt includes
  13. #include <QString>
  14. #include <QList>
  15. // CTK includes
  16. #include "CTKCoreExport.h"
  17. class CTK_CORE_EXPORT ctkDependencyGraph
  18. {
  19. public:
  20. ctkDependencyGraph(int nvertices, int nedges);
  21. ~ctkDependencyGraph();
  22. void printAdditionalInfo();
  23. void printGraph();
  24. /// Get the number of vertices associated with current graph
  25. int numberOfVertices();
  26. /// Get the number of edges associated with current graph
  27. int numberOfEdges();
  28. /// Traverse graph and check for cycle
  29. bool checkForCycle();
  30. /// Return true if there is at least one cycle
  31. bool cycleDetected();
  32. /// If a cycle has been detected, return the origin of the cycle otherwise 0.
  33. int cycleOrigin();
  34. /// If a cycle has been detected, return the end of the cycle otherwise 0.
  35. int cycleEnd();
  36. // The traverse of the tree will print information on standard output
  37. void setVerbose(bool verbose);
  38. /// Insert edge
  39. /// (from, to) indicate a relation between two vertices
  40. /// Note also that vertex id should be >= 1
  41. void insertEdge(int from, int to);
  42. /// Retrieve the path between two vertices
  43. void findPath(int from, int to, QList<int>& path);
  44. /// List of edge to exclude
  45. /// An edge is specified using its extremity
  46. void setEdgeListToExclude(const QList<int>& list);
  47. /// The default implementation check if 'edge' is in the list of edge to exclude
  48. /// See setEdgeListToExclude
  49. virtual bool shouldExcludeEdge(int edge);
  50. /// Called each time an edge is visited
  51. virtual void processEdge(int /*from*/, int /*to*/){}
  52. /// Perform a topological search
  53. /// Return false if the graph contains cycles
  54. /// See cycleDetected, cycleOrigin, cycleEnd
  55. bool topologicalSort(QList<int>& sorted);
  56. private:
  57. class ctkInternal;
  58. ctkInternal* Internal;
  59. };
  60. #endif