00001
00002
00003
00004
00005
00006
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028 #ifndef CHAININGITERATORS_H
00029 # define CHAININGITERATORS_H
00030
00031 # include <iostream>
00032 # include "../view_map/ViewMap.h"
00033 # include "../view_map/ViewMapIterators.h"
00034 # include "../view_map/ViewMapAdvancedIterators.h"
00035 # include "Predicates1D.h"
00036
00037
00038
00039
00040
00041
00043 class LIB_STROKE_EXPORT AdjacencyIterator{
00044 protected:
00045 ViewVertexInternal::orientedViewEdgeIterator _internalIterator;
00046 bool _restrictToSelection;
00047 bool _restrictToUnvisited;
00048 public:
00049 AdjacencyIterator(){
00050 _restrictToSelection = true;
00051 _restrictToUnvisited = true;
00052 }
00053 AdjacencyIterator(ViewVertex *iVertex, bool iRestrictToSelection = true, bool iRestrictToUnvisited = true){
00054 _restrictToSelection = iRestrictToSelection;
00055 _restrictToUnvisited = iRestrictToUnvisited;
00056 _internalIterator = iVertex->edgesBegin();
00057 while((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first)))
00058 ++_internalIterator;
00059 }
00060 AdjacencyIterator(const AdjacencyIterator& iBrother){
00061 _internalIterator = iBrother._internalIterator;
00062 _restrictToSelection = iBrother._restrictToSelection;
00063 _restrictToUnvisited = iBrother._restrictToUnvisited;
00064 }
00065 AdjacencyIterator& operator=(const AdjacencyIterator& iBrother) {
00066 _internalIterator = iBrother._internalIterator;
00067 _restrictToSelection = iBrother._restrictToSelection;
00068 _restrictToUnvisited = iBrother._restrictToUnvisited;
00069 return *this;
00070 }
00071 virtual ~AdjacencyIterator(){
00072 }
00073
00074 inline bool isEnd(){
00075 return _internalIterator.isEnd();
00076 }
00077 inline bool isBegin(){
00078 return _internalIterator.isBegin();
00079 }
00083 bool isIncoming() const ;
00084
00086 virtual ViewEdge* operator*() ;
00087 virtual ViewEdge* operator->() {return operator*();}
00088 virtual AdjacencyIterator& operator++() {
00089 increment();
00090 return *this;
00091 }
00092 virtual AdjacencyIterator operator++(int) {
00093 AdjacencyIterator tmp(*this);
00094 increment();
00095 return tmp;
00096 }
00097 void increment();
00098
00099 protected:
00100 bool isValid(ViewEdge* edge);
00101 };
00102
00103
00104
00105
00107
00121 class LIB_STROKE_EXPORT ChainingIterator : public ViewEdgeInternal::ViewEdgeIterator{
00122 protected:
00123 bool _restrictToSelection;
00124 bool _restrictToUnvisited;
00125 bool _increment;
00126
00127 public:
00142 ChainingIterator(bool iRestrictToSelection = true, bool iRestrictToUnvisited = true, ViewEdge* begin = 0, bool orientation = true)
00143 : ViewEdgeIterator(begin, orientation) {
00144 _restrictToSelection = iRestrictToSelection;
00145 _restrictToUnvisited = iRestrictToUnvisited;
00146 _increment = true;
00147 }
00148
00150 ChainingIterator(const ChainingIterator& brother)
00151 : ViewEdgeIterator(brother) {
00152 _restrictToSelection = brother._restrictToSelection;
00153 _restrictToUnvisited = brother._restrictToUnvisited;
00154 _increment = brother._increment;
00155 }
00156
00158 virtual string getExactTypeName() const {
00159 return "ChainingIterator";
00160 }
00161
00169 virtual void init(){}
00170
00182 virtual ViewEdge * traverse(const AdjacencyIterator &it){
00183 cerr << "Warning: the traverse method was not defined" << endl;
00184 return 0;
00185 }
00186
00187
00191
00193 inline ViewVertex * getVertex() {
00194 if(_increment){
00195 if(_orientation){
00196 return _edge->B();
00197 }else{
00198 return _edge->A();
00199 }
00200 }else{
00201 if(_orientation){
00202 return _edge->A();
00203 }else{
00204 return _edge->B();
00205 }
00206 }
00207 }
00208
00210 inline bool isIncrementing() const{
00211 return _increment;
00212 }
00213
00214
00215 virtual void increment() ;
00216 virtual void decrement() ;
00217 };
00218
00219
00220
00221
00223
00232 class LIB_STROKE_EXPORT ChainSilhouetteIterator : public ChainingIterator
00233 {
00234 public:
00248 ChainSilhouetteIterator(bool iRestrictToSelection = true, ViewEdge* begin = NULL, bool orientation = true)
00249 : ChainingIterator(iRestrictToSelection, true, begin, orientation) {}
00250
00252 ChainSilhouetteIterator(const ChainSilhouetteIterator& brother)
00253 : ChainingIterator(brother) {}
00254
00256 virtual string getExactTypeName() const {
00257 return "ChainSilhouetteIterator";
00258 }
00259
00265 virtual ViewEdge * traverse(const AdjacencyIterator& it);
00266
00267 };
00268
00269
00270
00271
00273
00284 class LIB_STROKE_EXPORT ChainPredicateIterator : public ChainingIterator
00285 {
00286 protected:
00287 BinaryPredicate1D *_binary_predicate;
00288 UnaryPredicate1D *_unary_predicate;
00289 public:
00290
00306 ChainPredicateIterator(bool iRestrictToSelection = true, bool iRestrictToUnvisited = true, ViewEdge* begin = NULL, bool orientation = true)
00307 : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation) {
00308 _binary_predicate = 0;
00309 _unary_predicate = 0;
00310 }
00311
00332 ChainPredicateIterator(UnaryPredicate1D& upred, BinaryPredicate1D& bpred, bool iRestrictToSelection = true, bool iRestrictToUnvisited = true, ViewEdge* begin = NULL, bool orientation = true)
00333 : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation) {
00334 _unary_predicate = &upred;
00335 _binary_predicate = &bpred;
00336 }
00337
00339 ChainPredicateIterator(const ChainPredicateIterator& brother)
00340 : ChainingIterator(brother){
00341 _unary_predicate = brother._unary_predicate;
00342 _binary_predicate = brother._binary_predicate;
00343 }
00344
00346 virtual ~ChainPredicateIterator(){
00347 _unary_predicate = 0;
00348 _binary_predicate = 0;
00349 }
00350
00352 virtual string getExactTypeName() const {
00353 return "ChainPredicateIterator";
00354 }
00355
00361 virtual ViewEdge * traverse(const AdjacencyIterator &it);
00362 };
00363
00364 #endif // CHAININGITERATORS_H