BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>
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 
54  GraphEdge();
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 
136  Vertex* getVertex(Position i) const;
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 
167  Vertex* other(const Vertex* vertex) const
168  throw(Exception::GeneralException);
169 
176  Face* other(const Face* face) const
177  throw(Exception::GeneralException);
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  */
240  Vertex* vertex_[2];
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>
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>
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>
439  {
440  if (vertex_[0] == vertex)
441  {
442  return vertex_[1];
443  }
444  else
445  {
446  if (vertex_[1] == vertex)
447  {
448  return vertex_[0];
449  }
450  else
451  {
452  throw Exception::GeneralException(__FILE__, __LINE__);
453  }
454  }
455  }
456 
457 
458  template <typename Vertex, typename Edge, typename Face>
459  Face* GraphEdge<Vertex,Edge,Face>::other(const Face* face) const
461  {
462  if (face_[0] == face)
463  {
464  return face_[1];
465  }
466  else
467  {
468  if (face_[1] == face)
469  {
470  return face_[0];
471  }
472  else
473  {
474  throw Exception::GeneralException(__FILE__, __LINE__);
475  }
476  }
477  }
478 
479 
480  template <typename Vertex, typename Edge, typename Face>
482  (const Vertex* old_vertex, Vertex* new_vertex)
483  {
484  if (vertex_[0] == old_vertex)
485  {
486  vertex_[0] = new_vertex;
487  }
488  else
489  {
490  if (vertex_[1] == old_vertex)
491  {
492  vertex_[1] = new_vertex;
493  }
494  else
495  {
496  return false;
497  }
498  }
499  return true;
500  }
501 
502 
503  template <typename Vertex, typename Edge, typename Face>
505  (const Face* old_face, Face* new_face)
506  {
507  if (face_[0] == old_face)
508  {
509  face_[0] = new_face;
510  }
511  else
512  {
513  if (face_[1] == old_face)
514  {
515  face_[1] = new_face;
516  }
517  else
518  {
519  return false;
520  }
521  }
522  return true;
523  }
524 
525 
526  template <typename Vertex, typename Edge, typename Face>
527  Face* GraphEdge<Vertex,Edge,Face>::remove(const Face* face)
528  {
529  if (face_[1] == face)
530  {
531  face_[1] = NULL;
532  }
533  else
534  {
535  if (face_[0] == face)
536  {
537  face_[0] = face_[1];
538  face_[1] = NULL;
539  }
540  }
541  return face_[0];
542  }
543 
544 
545  template <typename Vertex, typename Edge, typename Face>
547  {
548  Vertex* tmp = vertex_[0];
549  vertex_[0] = vertex_[1];
550  vertex_[1] = tmp;
551  }
552 
553 
554  template <typename Vertex, typename Edge, typename Face>
556  {
557  return true;
558  }
559 
560 
561  template <typename Vertex, typename Edge, typename Face>
563  {
564  return false;
565  }
566 
567 
568  template <typename Vertex, typename Edge, typename Face>
570  {
571  return true;
572  }
573 
574 
575 
576 } // namespace BALL
577 
578 #endif // BALL_STRUCTURE_GRAPHEDGE_H
#define BALL_CREATE(name)
Definition: create.h:62
void set(const GraphEdge< Vertex, Edge, Face > &edge, bool deep=false)
Definition: graphEdge.h:311
virtual ~GraphEdge()
Definition: graphEdge.h:304
void setFace(Position i, Face *face)
Definition: graphEdge.h:395
Face * remove(const Face *face)
Definition: graphEdge.h:527
Face * face_[2]
Definition: graphEdge.h:243
Vertex * vertex_[2]
Definition: graphEdge.h:240
Vertex * other(const Vertex *vertex) const
Definition: graphEdge.h:437
virtual bool operator*=(const Edge &) const
Definition: graphEdge.h:569
bool substitute(const Vertex *old_vertex, Vertex *new_vertex)
Definition: graphEdge.h:482
Index getIndex() const
Definition: graphEdge.h:430
void setIndex(Index index)
Definition: graphEdge.h:423
virtual bool operator!=(const Edge &) const
Definition: graphEdge.h:562
Vertex * getVertex(Position i) const
Definition: graphEdge.h:381
Face * getFace(Position i) const
Definition: graphEdge.h:409
void setVertex(Position i, Vertex *vertex)
Definition: graphEdge.h:367
virtual bool operator==(const Edge &) const
Definition: graphEdge.h:555