BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
graphVertex.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_STRUCTURE_GRAPHVERTEX_H
6 #define BALL_STRUCTURE_GRAPHVERTEX_H
7 
8 #ifndef BALL_COMMON_H
9 # include <BALL/common.h>
10 #endif
11 
12 #ifndef BALL_DATATYPE_HASHSET_H
13 # include <BALL/DATATYPE/hashSet.h>
14 #endif
15 
16 namespace BALL
17 {
18 
19  template <typename Vertex, typename Edge, typename Face>
20  class GraphEdge;
21 
22  template <typename Vertex, typename Edge, typename Face>
23  class GraphFace;
24 
25  template <typename Vertex, typename Edge, typename Face>
26  class GraphTriangle;
27 
31  template <typename Vertex, typename Edge, typename Face>
32  class GraphVertex
33  {
34  public:
35 
43  friend class GraphEdge<Vertex,Edge,Face>;
44  friend class GraphFace<Vertex,Edge,Face>;
45  friend class GraphTriangle<Vertex,Edge,Face>;
46 
48 
49 
52 
53  typedef typename HashSet<Edge*>::Iterator EdgeIterator;
54  typedef typename HashSet<Edge*>::ConstIterator ConstEdgeIterator;
55  typedef typename HashSet<Face*>::Iterator FaceIterator;
56  typedef typename HashSet<Face*>::ConstIterator ConstFaceIterator;
57 
59 
62 
66  GraphVertex()
67  ;
68 
76  GraphVertex(const GraphVertex<Vertex,Edge,Face>& vertex, bool deep = false)
77  ;
78 
82  virtual ~GraphVertex()
83  ;
85 
89 
97  void set(const GraphVertex<Vertex,Edge,Face>& vertex, bool deep = false)
98  ;
99 
105  GraphVertex<Vertex,Edge,Face>& operator =
106  (const GraphVertex<Vertex,Edge,Face>& vertex)
107  ;
108 
110 
113 
117  void insert(Edge* edge)
118  ;
119 
123  void insert(Face* face)
124  ;
125 
129  void remove(Edge* edge)
130  ;
131 
135  void remove(Face* face)
136  ;
137 
141  Position numberOfEdges() const
142  ;
143 
147  Position numberOfFaces() const
148  ;
149 
153  void setIndex(Index index)
154  ;
155 
159  Index getIndex() const
160  ;
161 
168  bool join(const Vertex& vertex)
169  ;
170 
177  bool substitute(Vertex* vertex)
178  ;
179 
180 
182 
185 
189  virtual bool operator == (const Vertex&) const
190  ;
191 
195  virtual bool operator != (const Vertex&) const
196  ;
197 
201  virtual bool operator *= (const Vertex&) const
202  ;
203 
208  Face* has(Face* face) const
209  ;
210 
215  Edge* has(Edge* edge) const
216  ;
217 
220  bool hasEdges() const
221  ;
222 
225  bool hasFaces() const
226  ;
227 
229 
232 
233  EdgeIterator beginEdge()
234  ;
235  ConstEdgeIterator beginEdge() const
236  ;
237  EdgeIterator endEdge()
238  ;
239  ConstEdgeIterator endEdge() const
240  ;
241  FaceIterator beginFace()
242  ;
243  ConstFaceIterator beginFace() const
244  ;
245  FaceIterator endFace()
246  ;
247  ConstFaceIterator endFace() const
248  ;
249 
251 
252  protected:
253 
254  /*_ @name Attributes
255  */
257 
258  /*_ The RSEdges the RSVetex belongs to
259  */
260  HashSet<Edge*> edges_;
261  /*_ The RSFaces the RSVetex belongs to
262  */
263  HashSet<Face*> faces_;
264  /*_ The index of the GraphVertex
265  */
267 
269 
270  };
271 
272 
273 
274  template <typename Vertex, typename Edge, typename Face>
275  GraphVertex<Vertex,Edge,Face>::GraphVertex()
276 
277  : edges_(),
278  faces_(),
279  index_(-1)
280  {
281  }
282 
283 
284  template <typename Vertex, typename Edge, typename Face>
286  (const GraphVertex<Vertex,Edge,Face>& vertex, bool deep)
287 
288  : edges_(),
289  faces_(),
290  index_(vertex.index_)
291  {
292  if (deep)
293  {
294  edges_ = vertex.edges_;
295  faces_ = vertex.faces_;
296  }
297  }
298 
299 
300  template <typename Vertex, typename Edge, typename Face>
302 
303  {
304  }
305 
306 
307  template <typename Vertex, typename Edge, typename Face>
309  (const GraphVertex<Vertex,Edge,Face>& vertex, bool deep)
310 
311  {
312  if (this != &vertex)
313  {
314  if (deep)
315  {
316  edges_ = vertex.edges_;
317  faces_ = vertex.faces_;
318  }
319  index_ = vertex.index_;
320  }
321  }
322 
323 
324  template <typename Vertex, typename Edge, typename Face>
327 
328  {
329  if (this != &vertex)
330  {
331  edges_ = vertex.edges_;
332  faces_ = vertex.faces_;
333  index_ = vertex.index_;
334  }
335  return *this;
336  }
337 
338 
339  template <typename Vertex, typename Edge, typename Face>
341 
342  {
343  edges_.insert(edge);
344  }
345 
346 
347  template <typename Vertex, typename Edge, typename Face>
349 
350  {
351  faces_.insert(face);
352  }
353 
354 
355  template <typename Vertex, typename Edge, typename Face>
357 
358  {
359  edges_.erase(edge);
360  }
361 
362 
363  template <typename Vertex, typename Edge, typename Face>
365 
366  {
367  faces_.erase(face);
368  }
369 
370 
371  template <typename Vertex, typename Edge, typename Face>
373 
374  {
375  return edges_.size();
376  }
377 
378 
379  template <typename Vertex, typename Edge, typename Face>
381 
382  {
383  return faces_.size();
384  }
385 
386 
387  template <typename Vertex, typename Edge, typename Face>
389 
390  {
391  index_ = index;
392  }
393 
394 
395  template <typename Vertex, typename Edge, typename Face>
397 
398  {
399  return index_;
400  }
401 
402 
403  template <typename Vertex, typename Edge, typename Face>
405 
406  {
407  if (*this *= *vertex)
408  {
409  typename HashSet<Edge*>::Iterator e;
410  for (e = edges_.begin(); e != edges_.end(); e++)
411  {
412  (*e)->substitute((Vertex*)this,vertex);
413  }
414  typename HashSet<Face*>::Iterator f;
415  for (f = faces_.begin(); f != faces_.end(); f++)
416  {
417  (*f)->substitute((Vertex*)this,vertex);
418  }
419  return true;
420  }
421  return false;
422  }
423 
424 
425  template <typename Vertex, typename Edge, typename Face>
427 
428  {
429  if (*this *= vertex)
430  {
432  for (e = vertex.edges_.begin(); e != vertex.edges_.end(); e++)
433  {
434  edges_.insert(*e);
435  }
437  for (f = vertex.faces_.begin(); f != vertex.faces_.end(); f++)
438  {
439  faces_.insert(*f);
440  }
441  return true;
442  }
443  else
444  {
445  return false;
446  }
447  }
448 
449 
450  template <typename Vertex, typename Edge, typename Face>
451  Face* GraphVertex<Vertex,Edge,Face>::has(Face* face) const
452 
453  {
455  for (f = faces_.begin(); f != faces_.end(); f++)
456  {
457  if (*(*f) == *face)
458  {
459  return *f;
460  }
461  }
462  return NULL;
463  }
464 
465 
466  template <typename Vertex, typename Edge, typename Face>
467  Edge* GraphVertex<Vertex,Edge,Face>::has(Edge* edge) const
468 
469  {
471  for (e = edges_.begin(); e != edges_.end(); e++)
472  {
473  if (*(*e) == *edge)
474  {
475  return *e;
476  }
477  }
478  return NULL;
479  }
480 
481 
482  template <typename Vertex, typename Edge, typename Face>
484 
485  {
486  return !edges_.isEmpty();
487  }
488 
489 
490  template <typename Vertex, typename Edge, typename Face>
492 
493  {
494  return !faces_.isEmpty();
495  }
496 
497 
498  template <typename Vertex, typename Edge, typename Face>
501 
502  {
503  return edges_.begin();
504  }
505 
506 
507  template <typename Vertex, typename Edge, typename Face>
510 
511  {
512  return edges_.begin();
513  }
514 
515 
516  template <typename Vertex, typename Edge, typename Face>
519 
520  {
521  return edges_.end();
522  }
523 
524 
525  template <typename Vertex, typename Edge, typename Face>
528 
529  {
530  return edges_.end();
531  }
532 
533 
534  template <typename Vertex, typename Edge, typename Face>
537 
538  {
539  return faces_.begin();
540  }
541 
542 
543  template <typename Vertex, typename Edge, typename Face>
546 
547  {
548  return faces_.begin();
549  }
550 
551 
552  template <typename Vertex, typename Edge, typename Face>
555 
556  {
557  return faces_.end();
558  }
559 
560 
561  template <typename Vertex, typename Edge, typename Face>
564 
565  {
566  return faces_.end();
567  }
568 
569 
570  template <typename Vertex, typename Edge, typename Face>
572 
573  {
574  return true;
575  }
576 
577 
578  template <typename Vertex, typename Edge, typename Face>
580 
581  {
582  return false;
583  }
584 
585 
586  template <typename Vertex, typename Edge, typename Face>
588 
589  {
590  return true;
591  }
592 
593 } // namespace BALL
594 
595 #endif // BALL_STRUCTURE_GRAPHVERTEX_H
#define BALL_CREATE(name)
Definition: create.h:62
FaceIterator endFace()
Definition: graphVertex.h:554
std::pair< Iterator, bool > insert(const ValueType &item)
Definition: hashSet.h:896
bool hasEdges() const
Definition: graphVertex.h:483
Index getIndex() const
Definition: graphVertex.h:396
virtual ~GraphVertex()
Definition: graphVertex.h:301
void setIndex(Index index)
Definition: graphVertex.h:388
Position numberOfFaces() const
Definition: graphVertex.h:380
Iterator end()
Definition: hashSet.h:543
bool substitute(Vertex *vertex)
Definition: graphVertex.h:404
Position numberOfEdges() const
Definition: graphVertex.h:372
void set(const GraphVertex< Vertex, Edge, Face > &vertex, bool deep=false)
Definition: graphVertex.h:309
HashSet< Triangle * >::ConstIterator ConstFaceIterator
Definition: graphVertex.h:56
virtual bool operator==(const Vertex &) const
Definition: graphVertex.h:571
Iterator begin()
Definition: hashSet.h:536
HashSet< TriangleEdge * >::Iterator EdgeIterator
Definition: graphVertex.h:53
HashSet< Face * > faces_
Definition: graphVertex.h:263
EdgeIterator endEdge()
Definition: graphVertex.h:518
Face * has(Face *face) const
Definition: graphVertex.h:451
Size erase(const KeyType &key)
Definition: hashSet.h:927
HashSet< Edge * > edges_
Definition: graphVertex.h:260
virtual bool operator!=(const Vertex &) const
Definition: graphVertex.h:579
EdgeIterator beginEdge()
Definition: graphVertex.h:500
virtual bool operator*=(const Vertex &) const
Definition: graphVertex.h:587
bool hasFaces() const
Definition: graphVertex.h:491
HashSet< TriangleEdge * >::ConstIterator ConstEdgeIterator
Definition: graphVertex.h:54
FaceIterator beginFace()
Definition: graphVertex.h:536
Size size() const
Definition: hashSet.h:862
void remove(Edge *edge)
Definition: graphVertex.h:356
void insert(Edge *edge)
Definition: graphVertex.h:340
bool join(const Vertex &vertex)
Definition: graphVertex.h:426
bool isEmpty() const
Definition: hashSet.h:1127