mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-05-16 10:54:53 +03:00
The copying permission statements at the beginning of source files updated to refer to LGPL. Copyright dates extended till 2014 in advance.
201 lines
5.1 KiB
Plaintext
201 lines
5.1 KiB
Plaintext
// Created on: 1991-10-23
|
|
// Created by: Denis PASCAL
|
|
// Copyright (c) 1991-1999 Matra Datavision
|
|
// Copyright (c) 1999-2014 OPEN CASCADE SAS
|
|
//
|
|
// This file is part of Open CASCADE Technology software library.
|
|
//
|
|
// This library is free software; you can redistribute it and / or modify it
|
|
// under the terms of the GNU Lesser General Public version 2.1 as published
|
|
// by the Free Software Foundation, with special exception defined in the file
|
|
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
|
// distribution for complete text of the license and disclaimer of any warranty.
|
|
//
|
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
|
// commercial license or contractual agreement.
|
|
|
|
// <dp>
|
|
|
|
#include <Standard_DomainError.hxx>
|
|
#include <Standard_NoMoreObject.hxx>
|
|
#include <Standard_NoSuchObject.hxx>
|
|
#include <TColStd_SequenceOfInteger.hxx>
|
|
|
|
|
|
|
|
//=======================================================================
|
|
//function : GraphTools_SortedStrgCmptsFromIterator
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
GraphTools_SortedStrgCmptsFromIterator::
|
|
GraphTools_SortedStrgCmptsFromIterator ()
|
|
{
|
|
myNowIndex = 0;
|
|
}
|
|
|
|
|
|
//=======================================================================
|
|
//function : FromVertex
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
void GraphTools_SortedStrgCmptsFromIterator::FromVertex (const Vertex& V)
|
|
{
|
|
#ifdef DEB
|
|
Standard_Integer index =
|
|
#endif
|
|
myVertices.Add (V,0);
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
//function : Perform
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
void GraphTools_SortedStrgCmptsFromIterator::Perform (const Graph& G)
|
|
{
|
|
myNowIndex = 0;
|
|
mySort.Clear();
|
|
Standard_Integer visited;
|
|
Standard_Integer temp;
|
|
Standard_Integer index = 1;
|
|
while (index <= myVertices.Extent()) {
|
|
visited = myVertices.FindFromIndex(index);
|
|
if (visited == 0) temp = Visit(index,G);
|
|
index ++;
|
|
}
|
|
myIterator.Initialize(mySort);
|
|
}
|
|
|
|
|
|
//=======================================================================
|
|
//function : Reset
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
void GraphTools_SortedStrgCmptsFromIterator::Reset ()
|
|
{
|
|
myVertices.Clear();
|
|
myNowIndex = 0;
|
|
myStack.Clear();
|
|
mySort.Clear();
|
|
}
|
|
|
|
|
|
//=======================================================================
|
|
//function : More
|
|
//purpose : declenche l'algorithme de recherche des Strong Components
|
|
//=======================================================================
|
|
|
|
Standard_Boolean GraphTools_SortedStrgCmptsFromIterator::More() const
|
|
{
|
|
return myIterator.More();
|
|
}
|
|
|
|
|
|
//=======================================================================
|
|
//function : Next
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
void GraphTools_SortedStrgCmptsFromIterator::Next()
|
|
{
|
|
myIterator.Next();
|
|
}
|
|
|
|
|
|
//=======================================================================
|
|
//function : NbVertices
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
Standard_Integer GraphTools_SortedStrgCmptsFromIterator::NbVertices() const
|
|
{
|
|
return myIterator.Value().Length();
|
|
}
|
|
|
|
|
|
//=======================================================================
|
|
//function : Value
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
const Vertex& GraphTools_SortedStrgCmptsFromIterator::Value
|
|
(const Standard_Integer I) const
|
|
{
|
|
Standard_Integer indexvertex = myIterator.Value().Value(I);
|
|
return myVertices.FindKey (indexvertex);
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : Visit
|
|
//purpose : private
|
|
//=======================================================================
|
|
|
|
Standard_Integer GraphTools_SortedStrgCmptsFromIterator::Visit
|
|
(const Standard_Integer k, const Graph& G)
|
|
{
|
|
Standard_Integer MIN;
|
|
Standard_Integer M;
|
|
myNowIndex++;
|
|
myVertices(k) = myNowIndex;
|
|
MIN = myNowIndex;
|
|
myStack.Push(k);
|
|
Standard_Integer currentVisited;
|
|
currentVisited = myVertices.FindFromIndex (k);
|
|
Standard_Integer adjacentIndex;
|
|
Standard_Integer adjacentVisited;
|
|
for (VIterator itV (G,myVertices.FindKey(k)); itV.More(); itV.Next()) {
|
|
adjacentIndex = myVertices.FindIndex(itV.Value());
|
|
if (adjacentIndex == 0) {
|
|
adjacentIndex = myVertices.Add (itV.Value(),0);
|
|
adjacentVisited = 0;
|
|
}
|
|
else adjacentVisited = myVertices.FindFromIndex (adjacentIndex);
|
|
if (adjacentVisited == 0) M = Visit(adjacentIndex,G);
|
|
else M = adjacentVisited;
|
|
if (M < MIN) MIN = M;
|
|
}
|
|
if (MIN == currentVisited) {
|
|
TColStd_SequenceOfInteger theSequence;
|
|
mySort.Prepend(theSequence);
|
|
TColStd_SequenceOfInteger& newSC = mySort.First();
|
|
Standard_Boolean more;
|
|
do {
|
|
newSC.Append(myStack.Top());
|
|
myVertices(myStack.Top()) = IntegerLast();
|
|
more = myStack.Top() != k;
|
|
myStack.Pop() ;
|
|
}
|
|
while (more);
|
|
}
|
|
return MIN;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|