| 105 | } |
| 106 | |
| 107 | vtkIdType vtkTreeDFSIterator::NextInternal() |
| 108 | { |
| 109 | while (this->Color->GetValue(this->StartVertex) != this->BLACK) |
| 110 | { |
| 111 | while (!this->Internals->Stack.empty()) |
| 112 | { |
| 113 | // Pop the current position off the stack |
| 114 | vtkTreeDFSIteratorPosition pos = this->Internals->Stack.top(); |
| 115 | this->Internals->Stack.pop(); |
| 116 | // std::cout << "popped " << pos.Vertex << "," << pos.Index << " off the stack" << endl; |
| 117 | |
| 118 | vtkIdType nchildren = this->Tree->GetNumberOfChildren(pos.Vertex); |
| 119 | while (pos.Index < nchildren && |
| 120 | this->Color->GetValue(this->Tree->GetChild(pos.Vertex, pos.Index)) != this->WHITE) |
| 121 | { |
| 122 | pos.Index++; |
| 123 | } |
| 124 | if (pos.Index == nchildren) |
| 125 | { |
| 126 | // std::cout << "DFS coloring " << pos.Vertex << " black" << endl; |
| 127 | // Done with this vertex; make it black and leave it off the stack |
| 128 | this->Color->SetValue(pos.Vertex, this->BLACK); |
| 129 | if (this->Mode == this->FINISH) |
| 130 | { |
| 131 | // std::cout << "DFS finished " << pos.Vertex << endl; |
| 132 | return pos.Vertex; |
| 133 | } |
| 134 | // Done with the start vertex, so we are totally done! |
| 135 | if (pos.Vertex == this->StartVertex) |
| 136 | { |
| 137 | return -1; |
| 138 | } |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | // Not done with this vertex; put it back on the stack |
| 143 | this->Internals->Stack.push(pos); |
| 144 | |
| 145 | // Found a white vertex; make it gray, add it to the stack |
| 146 | vtkIdType found = this->Tree->GetChild(pos.Vertex, pos.Index); |
| 147 | // std::cout << "DFS coloring " << found << " gray (adjacency)" << endl; |
| 148 | this->Color->SetValue(found, this->GRAY); |
| 149 | this->Internals->Stack.emplace(found, 0); |
| 150 | if (this->Mode == this->DISCOVER) |
| 151 | { |
| 152 | // std::cout << "DFS adjacent discovery " << found << endl; |
| 153 | return found; |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // Done with this component, so find a white vertex and start a new seedgeh |
| 159 | if (this->Color->GetValue(this->StartVertex) != this->BLACK) |
| 160 | { |
| 161 | while (true) |
| 162 | { |
| 163 | if (this->Color->GetValue(this->CurRoot) == this->WHITE) |
| 164 | { |
no test coverage detected