BALL  1.5.0
graphEdge.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_GRAPHEDGE_H
6 #define BALL_STRUCTURE_GRAPHEDGE_H
7 
8 #ifndef BALL_COMMON_H
9 # include <BALL/common.h>
10 #endif
11 
12 #include <vector>
13 
14 namespace BALL
15 {
16 
17  template <typename Vertex, typename Edge, typename Face>
18  class GraphVertex;
19 
20  template <typename Vertex, typename Edge, typename Face>
21  class GraphFace;
22 
23  template <typename Vertex, typename Edge, typename Face>
24  class GraphTriangle;
25 
29  template <typename Vertex, typename Edge, typename Face>
30  class GraphEdge
31  {
32  public:
33 
41  friend class GraphVertex<Vertex,Edge,Face>;
42  friend class GraphFace<Vertex,Edge,Face>;
43  friend class GraphTriangle<Vertex,Edge,Face>;
44 
46 
47 
50 
51 
55 
63  GraphEdge(const GraphEdge<Vertex,Edge,Face>& edge, bool deep = false);
64 
73  GraphEdge(Vertex* vertex1,
74  Vertex* vertex2,
75  Face* face1,
76  Face* face2,
77  Index index);
78 
83  virtual ~GraphEdge();
84 
86 
89 
96  void set(const GraphEdge<Vertex,Edge,Face>& edge, bool deep = false);
97 
103  GraphEdge<Vertex,Edge,Face>& operator =
104  (const GraphEdge<Vertex,Edge,Face>& edge);
105 
113  void set(Vertex* vertex0,
114  Vertex* vertex1,
115  Face* face0,
116  Face* face1,
117  Index index);
118 
120 
123 
129  void setVertex(Position i, Vertex* vertex);
130 
137 
142  void setFace(Position i, Face* face);
143 
149  Face* getFace(Position i) const;
150 
154  void setIndex(Index index);
155 
159  Index getIndex() const;
160 
168  Vertex* other(const Vertex* vertex) const;
169 
177  Face* other(const Face* face) const;
178 
185  bool substitute(const Vertex* old_vertex, Vertex* new_vertex);
186 
193  bool substitute(const Face* old_vertex, Face* new_vertex);
194 
202  Face* remove(const Face* face);
203 
204  /* Swap the two vertices of the GraphEdge
205  */
206  void revert();
207 
209 
210 
214 
218  virtual bool operator == (const Edge&) const;
219 
223  virtual bool operator != (const Edge&) const;
224 
228  virtual bool operator *= (const Edge&) const;
229 
231 
232  protected:
233 
234  /*_ @name Attributes
235  */
237 
238  /*_ The vertices of the GraphEdge
239  */
241  /*_ The faces of the GraphEdge
242  */
243  Face* face_[2];
244  /*_ The index of the GraphEdge
245  */
247 
249 
250  };
251 
252 
253 
254  template <typename Vertex, typename Edge, typename Face>
255  GraphEdge<Vertex,Edge,Face>::GraphEdge()
256  : index_(-1)
257  {
258  vertex_[0] = NULL;
259  vertex_[1] = NULL;
260  face_[0] = NULL;
261  face_[1] = NULL;
262  }
263 
264 
265  template <typename Vertex, typename Edge, typename Face>
267  GraphEdge(const GraphEdge<Vertex,Edge,Face>& edge, bool deep)
268  : index_(edge.index_)
269  {
270  if (deep)
271  {
272  vertex_[0] = edge.vertex_[0];
273  vertex_[1] = edge.vertex_[1];
274  face_[0] = edge.face_[0];
275  face_[1] = edge.face_[1];
276  }
277  else
278  {
279  vertex_[0] = NULL;
280  vertex_[1] = NULL;
281  face_[0] = NULL;
282  face_[1] = NULL;
283  }
284  }
285 
286 
287  template <typename Vertex, typename Edge, typename Face>
289  (Vertex* vertex1,
290  Vertex* vertex2,
291  Face* face1,
292  Face* face2,
293  Index index)
294  : index_(index)
295  {
296  vertex_[0] = vertex1;
297  vertex_[1] = vertex2;
298  face_[0] = face1;
299  face_[1] = face2;
300  }
301 
302 
303  template <typename Vertex, typename Edge, typename Face>
305  {
306  }
307 
308 
309  template <typename Vertex, typename Edge, typename Face>
311  (const GraphEdge<Vertex,Edge,Face>& edge, bool deep)
312  {
313  if (this != &edge)
314  {
315  if (deep)
316  {
317  vertex_[0] = edge.vertex_[0];
318  vertex_[1] = edge.vertex_[1];
319  face_[0] = edge.face_[0];
320  face_[1] = edge.face_[1];
321  }
322  else
323  {
324  vertex_[0] = NULL;
325  vertex_[1] = NULL;
326  face_[0] = NULL;
327  face_[1] = NULL;
328  }
329  index_ = edge.index_;
330  }
331  }
332 
333 
334  template <typename Vertex, typename Edge, typename Face>
336  (const GraphEdge<Vertex,Edge,Face>& edge)
337  {
338  if (this != &edge)
339  {
340  vertex_[0] = edge.vertex_[0];
341  vertex_[1] = edge.vertex_[1];
342  face_[0] = edge.face_[0];
343  face_[1] = edge.face_[1];
344  index_ = edge.index_;
345  }
346  return *this;
347  }
348 
349 
350  template <typename Vertex, typename Edge, typename Face>
352  (Vertex* vertex0,
353  Vertex* vertex1,
354  Face* face0,
355  Face* face1,
356  Index index)
357  {
358  vertex_[0] = vertex0;
359  vertex_[1] = vertex1;
360  face_[0] = face0;
361  face_[1] = face1;
362  index_ = index;
363  }
364 
365 
366  template <typename Vertex, typename Edge, typename Face>
368  {
369  if (i == 0)
370  {
371  vertex_[0] = vertex;
372  }
373  else
374  {
375  vertex_[1] = vertex;
376  }
377  }
378 
379 
380  template <typename Vertex, typename Edge, typename Face>
382  {
383  if (i == 0)
384  {
385  return vertex_[0];
386  }
387  else
388  {
389  return vertex_[1];
390  }
391  }
392 
393 
394  template <typename Vertex, typename Edge, typename Face>
396  {
397  if (i == 0)
398  {
399  face_[0] = face;
400  }
401  else
402  {
403  face_[1] = face;
404  }
405  }
406 
407 
408  template <typename Vertex, typename Edge, typename Face>
410  {
411  if (i == 0)
412  {
413  return face_[0];
414  }
415  else
416  {
417  return face_[1];
418  }
419  }
420 
421 
422  template <typename Vertex, typename Edge, typename Face>
424  {
425  index_ = index;
426  }
427 
428 
429  template <typename Vertex, typename Edge, typename Face>
431  {
432  return index_;
433  }
434 
435 
436  template <typename Vertex, typename Edge, typename Face>
438  {
439  if (vertex_[0] == vertex)
440  {
441  return vertex_[1];
442  }
443  else
444  {
445  if (vertex_[1] == vertex)
446  {
447  return vertex_[0];
448  }
449  else
450  {
451  throw Exception::GeneralException(__FILE__, __LINE__);
452  }
453  }
454  }
455 
456 
457  template <typename Vertex, typename Edge, typename Face>
458  Face* GraphEdge<Vertex,Edge,Face>::other(const Face* face) const
459  {
460  if (face_[0] == face)
461  {
462  return face_[1];
463  }
464  else
465  {
466  if (face_[1] == face)
467  {
468  return face_[0];
469  }
470  else
471  {
472  throw Exception::GeneralException(__FILE__, __LINE__);
473  }
474  }
475  }
476 
477 
478  template <typename Vertex, typename Edge, typename Face>
480  (const Vertex* old_vertex, Vertex* new_vertex)
481  {
482  if (vertex_[0] == old_vertex)
483  {
484  vertex_[0] = new_vertex;
485  }
486  else
487  {
488  if (vertex_[1] == old_vertex)
489  {
490  vertex_[1] = new_vertex;
491  }
492  else
493  {
494  return false;
495  }
496  }
497  return true;
498  }
499 
500 
501  template <typename Vertex, typename Edge, typename Face>
503  (const Face* old_face, Face* new_face)
504  {
505  if (face_[0] == old_face)
506  {
507  face_[0] = new_face;
508  }
509  else
510  {
511  if (face_[1] == old_face)
512  {
513  face_[1] = new_face;
514  }
515  else
516  {
517  return false;
518  }
519  }
520  return true;
521  }
522 
523 
524  template <typename Vertex, typename Edge, typename Face>
525  Face* GraphEdge<Vertex,Edge,Face>::remove(const Face* face)
526  {
527  if (face_[1] == face)
528  {
529  face_[1] = NULL;
530  }
531  else
532  {
533  if (face_[0] == face)
534  {
535  face_[0] = face_[1];
536  face_[1] = NULL;
537  }
538  }
539  return face_[0];
540  }
541 
542 
543  template <typename Vertex, typename Edge, typename Face>
545  {
546  Vertex* tmp = vertex_[0];
547  vertex_[0] = vertex_[1];
548  vertex_[1] = tmp;
549  }
550 
551 
552  template <typename Vertex, typename Edge, typename Face>
554  {
555  return true;
556  }
557 
558 
559  template <typename Vertex, typename Edge, typename Face>
561  {
562  return false;
563  }
564 
565 
566  template <typename Vertex, typename Edge, typename Face>
568  {
569  return true;
570  }
571 
572 
573 
574 } // namespace BALL
575 
576 #endif // BALL_STRUCTURE_GRAPHEDGE_H
#define BALL_CREATE(name)
Definition: create.h:62
Definition: constants.h:13
BALL_INDEX_TYPE Index
void setFace(Position i, Face *face)
Definition: graphEdge.h:395
Vertex * vertex_[2]
Definition: graphEdge.h:240
Vertex * other(const Vertex *vertex) const
Definition: graphEdge.h:437
Vertex * getVertex(Position i) const
Definition: graphEdge.h:381
virtual bool operator*=(const Edge &) const
Definition: graphEdge.h:567
bool substitute(const Vertex *old_vertex, Vertex *new_vertex)
Definition: graphEdge.h:480
void setIndex(Index index)
Definition: graphEdge.h:423
Face * face_[2]
Definition: graphEdge.h:243
Face * remove(const Face *face)
Definition: graphEdge.h:525
void setVertex(Position i, Vertex *vertex)
Definition: graphEdge.h:367
virtual bool operator!=(const Edge &) const
Definition: graphEdge.h:560
Index getIndex() const
Definition: graphEdge.h:430
virtual ~GraphEdge()
Definition: graphEdge.h:304
Face * getFace(Position i) const
Definition: graphEdge.h:409
virtual bool operator==(const Edge &) const
Definition: graphEdge.h:553
void set(const GraphEdge< Vertex, Edge, Face > &edge, bool deep=false)
Definition: graphEdge.h:311