Loading...
Searching...
No Matches
graphEdge.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_STRUCTURE_GRAPHEDGE_H
#define BALL_STRUCTURE_GRAPHEDGE_H
#ifndef BALL_COMMON_H
# include <BALL/common.h>
#endif
#include <vector>
namespace BALL
{
template <typename Vertex, typename Edge, typename Face>
class GraphVertex;
template <typename Vertex, typename Edge, typename Face>
class GraphFace;
template <typename Vertex, typename Edge, typename Face>
class GraphTriangle;
template <typename Vertex, typename Edge, typename Face>
class GraphEdge
{
public:
friend class GraphVertex<Vertex,Edge,Face>;
friend class GraphFace<Vertex,Edge,Face>;
friend class GraphTriangle<Vertex,Edge,Face>;
BALL_CREATE(GraphEdge)
GraphEdge();
GraphEdge(const GraphEdge<Vertex,Edge,Face>& edge, bool deep = false);
GraphEdge(Vertex* vertex1,
Vertex* vertex2,
Face* face1,
Face* face2,
Index index);
virtual ~GraphEdge();
void set(const GraphEdge<Vertex,Edge,Face>& edge, bool deep = false);
GraphEdge<Vertex,Edge,Face>& operator =
(const GraphEdge<Vertex,Edge,Face>& edge);
void set(Vertex* vertex0,
Vertex* vertex1,
Face* face0,
Face* face1,
Index index);
void setVertex(Position i, Vertex* vertex);
Vertex* getVertex(Position i) const;
void setFace(Position i, Face* face);
Face* getFace(Position i) const;
void setIndex(Index index);
Index getIndex() const;
Vertex* other(const Vertex* vertex) const;
Face* other(const Face* face) const;
bool substitute(const Vertex* old_vertex, Vertex* new_vertex);
bool substitute(const Face* old_vertex, Face* new_vertex);
Face* remove(const Face* face);
/* Swap the two vertices of the GraphEdge
*/
void revert();
virtual bool operator == (const Edge&) const;
virtual bool operator != (const Edge&) const;
virtual bool operator *= (const Edge&) const;
protected:
/*_ @name Attributes
*/
/*_ The vertices of the GraphEdge
*/
Vertex* vertex_[2];
/*_ The faces of the GraphEdge
*/
Face* face_[2];
/*_ The index of the GraphEdge
*/
Index index_;
};
template <typename Vertex, typename Edge, typename Face>
GraphEdge<Vertex,Edge,Face>::GraphEdge()
: index_(-1)
{
vertex_[0] = NULL;
vertex_[1] = NULL;
face_[0] = NULL;
face_[1] = NULL;
}
template <typename Vertex, typename Edge, typename Face>
GraphEdge<Vertex,Edge,Face>::
GraphEdge(const GraphEdge<Vertex,Edge,Face>& edge, bool deep)
: index_(edge.index_)
{
if (deep)
{
vertex_[0] = edge.vertex_[0];
vertex_[1] = edge.vertex_[1];
face_[0] = edge.face_[0];
face_[1] = edge.face_[1];
}
else
{
vertex_[0] = NULL;
vertex_[1] = NULL;
face_[0] = NULL;
face_[1] = NULL;
}
}
template <typename Vertex, typename Edge, typename Face>
GraphEdge<Vertex,Edge,Face>::GraphEdge
(Vertex* vertex1,
Vertex* vertex2,
Face* face1,
Face* face2,
Index index)
: index_(index)
{
vertex_[0] = vertex1;
vertex_[1] = vertex2;
face_[0] = face1;
face_[1] = face2;
}
template <typename Vertex, typename Edge, typename Face>
GraphEdge<Vertex,Edge,Face>::~GraphEdge()
{
}
template <typename Vertex, typename Edge, typename Face>
void GraphEdge<Vertex,Edge,Face>::set
(const GraphEdge<Vertex,Edge,Face>& edge, bool deep)
{
if (this != &edge)
{
if (deep)
{
vertex_[0] = edge.vertex_[0];
vertex_[1] = edge.vertex_[1];
face_[0] = edge.face_[0];
face_[1] = edge.face_[1];
}
else
{
vertex_[0] = NULL;
vertex_[1] = NULL;
face_[0] = NULL;
face_[1] = NULL;
}
index_ = edge.index_;
}
}
template <typename Vertex, typename Edge, typename Face>
GraphEdge<Vertex,Edge,Face>& GraphEdge<Vertex,Edge,Face>::operator =
(const GraphEdge<Vertex,Edge,Face>& edge)
{
if (this != &edge)
{
vertex_[0] = edge.vertex_[0];
vertex_[1] = edge.vertex_[1];
face_[0] = edge.face_[0];
face_[1] = edge.face_[1];
index_ = edge.index_;
}
return *this;
}
template <typename Vertex, typename Edge, typename Face>
void GraphEdge<Vertex,Edge,Face>::set
(Vertex* vertex0,
Vertex* vertex1,
Face* face0,
Face* face1,
Index index)
{
vertex_[0] = vertex0;
vertex_[1] = vertex1;
face_[0] = face0;
face_[1] = face1;
index_ = index;
}
template <typename Vertex, typename Edge, typename Face>
void GraphEdge<Vertex,Edge,Face>::setVertex(Position i, Vertex* vertex)
{
if (i == 0)
{
vertex_[0] = vertex;
}
else
{
vertex_[1] = vertex;
}
}
template <typename Vertex, typename Edge, typename Face>
Vertex* GraphEdge<Vertex,Edge,Face>::getVertex(Position i) const
{
if (i == 0)
{
return vertex_[0];
}
else
{
return vertex_[1];
}
}
template <typename Vertex, typename Edge, typename Face>
void GraphEdge<Vertex,Edge,Face>::setFace(Position i, Face* face)
{
if (i == 0)
{
face_[0] = face;
}
else
{
face_[1] = face;
}
}
template <typename Vertex, typename Edge, typename Face>
Face* GraphEdge<Vertex,Edge,Face>::getFace(Position i) const
{
if (i == 0)
{
return face_[0];
}
else
{
return face_[1];
}
}
template <typename Vertex, typename Edge, typename Face>
void GraphEdge<Vertex,Edge,Face>::setIndex(Index index)
{
index_ = index;
}
template <typename Vertex, typename Edge, typename Face>
Index GraphEdge<Vertex,Edge,Face>::getIndex() const
{
return index_;
}
template <typename Vertex, typename Edge, typename Face>
Vertex* GraphEdge<Vertex,Edge,Face>::other(const Vertex* vertex) const
{
if (vertex_[0] == vertex)
{
return vertex_[1];
}
else
{
if (vertex_[1] == vertex)
{
return vertex_[0];
}
else
{
throw Exception::GeneralException(__FILE__, __LINE__);
}
}
}
template <typename Vertex, typename Edge, typename Face>
Face* GraphEdge<Vertex,Edge,Face>::other(const Face* face) const
{
if (face_[0] == face)
{
return face_[1];
}
else
{
if (face_[1] == face)
{
return face_[0];
}
else
{
throw Exception::GeneralException(__FILE__, __LINE__);
}
}
}
template <typename Vertex, typename Edge, typename Face>
bool GraphEdge<Vertex,Edge,Face>::substitute
(const Vertex* old_vertex, Vertex* new_vertex)
{
if (vertex_[0] == old_vertex)
{
vertex_[0] = new_vertex;
}
else
{
if (vertex_[1] == old_vertex)
{
vertex_[1] = new_vertex;
}
else
{
return false;
}
}
return true;
}
template <typename Vertex, typename Edge, typename Face>
bool GraphEdge<Vertex,Edge,Face>::substitute
(const Face* old_face, Face* new_face)
{
if (face_[0] == old_face)
{
face_[0] = new_face;
}
else
{
if (face_[1] == old_face)
{
face_[1] = new_face;
}
else
{
return false;
}
}
return true;
}
template <typename Vertex, typename Edge, typename Face>
Face* GraphEdge<Vertex,Edge,Face>::remove(const Face* face)
{
if (face_[1] == face)
{
face_[1] = NULL;
}
else
{
if (face_[0] == face)
{
face_[0] = face_[1];
face_[1] = NULL;
}
}
return face_[0];
}
template <typename Vertex, typename Edge, typename Face>
void GraphEdge<Vertex,Edge,Face>::revert()
{
Vertex* tmp = vertex_[0];
vertex_[0] = vertex_[1];
vertex_[1] = tmp;
}
template <typename Vertex, typename Edge, typename Face>
bool GraphEdge<Vertex,Edge,Face>::operator == (const Edge&) const
{
return true;
}
template <typename Vertex, typename Edge, typename Face>
bool GraphEdge<Vertex,Edge,Face>::operator != (const Edge&) const
{
return false;
}
template <typename Vertex, typename Edge, typename Face>
bool GraphEdge<Vertex,Edge,Face>::operator *= (const Edge&) const
{
return true;
}
} // namespace BALL
#endif // BALL_STRUCTURE_GRAPHEDGE_H
BALL::Exception::GeneralException
Definition COMMON/exception.h:61
BALL::GraphEdge< RSVertex, RSEdge, RSFace >::setFace
void setFace(Position i, RSFace *face)
Definition graphEdge.h:395
BALL::GraphEdge::vertex_
Vertex * vertex_[2]
Definition graphEdge.h:240
BALL::GraphEdge< RSVertex, RSEdge, RSFace >::other
RSVertex * other(const RSVertex *vertex) const
Definition graphEdge.h:437
BALL::GraphEdge< RSVertex, RSEdge, RSFace >::getVertex
RSVertex * getVertex(Position i) const
Definition graphEdge.h:381
BALL::GraphEdge::operator*=
virtual bool operator*=(const Edge &) const
Definition graphEdge.h:567
BALL::GraphEdge< RSVertex, RSEdge, RSFace >::substitute
bool substitute(const RSVertex *old_vertex, RSVertex *new_vertex)
Definition graphEdge.h:480
BALL::GraphEdge< RSVertex, RSEdge, RSFace >::setIndex
void setIndex(Index index)
Definition graphEdge.h:423
BALL::GraphEdge::face_
Face * face_[2]
Definition graphEdge.h:243
BALL::GraphEdge< RSVertex, RSEdge, RSFace >::remove
RSFace * remove(const RSFace *face)
Definition graphEdge.h:525
BALL::GraphEdge< RSVertex, RSEdge, RSFace >::setVertex
void setVertex(Position i, RSVertex *vertex)
Definition graphEdge.h:367
BALL::GraphEdge::operator!=
virtual bool operator!=(const Edge &) const
Definition graphEdge.h:560
BALL::GraphEdge::GraphEdge
GraphEdge()
Definition graphEdge.h:255
BALL::GraphEdge< RSVertex, RSEdge, RSFace >::getIndex
Index getIndex() const
Definition graphEdge.h:430
BALL::GraphEdge::~GraphEdge
virtual ~GraphEdge()
Definition graphEdge.h:304
BALL::GraphEdge< RSVertex, RSEdge, RSFace >::getFace
RSFace * getFace(Position i) const
Definition graphEdge.h:409
BALL::GraphEdge::index_
Index index_
Definition graphEdge.h:246
BALL::GraphEdge< RSVertex, RSEdge, RSFace >::revert
void revert()
Definition graphEdge.h:544
BALL::GraphEdge::operator==
virtual bool operator==(const Edge &) const
Definition graphEdge.h:553
BALL::GraphEdge< RSVertex, RSEdge, RSFace >::set
void set(const GraphEdge< RSVertex, RSEdge, RSFace > &edge, bool deep=false)
Definition graphEdge.h:311
BALL::GraphFace
Definition graphFace.h:29
BALL::GraphTriangle
Definition graphFace.h:625
BALL::GraphVertex
Definition graphVertex.h:33
common.h
BALL_CREATE
#define BALL_CREATE(name)
Definition create.h:62
BALL
Definition constants.h:13
BALL::Position
BALL_SIZE_TYPE Position
Definition COMMON/global.h:140
BALL::Index
BALL_INDEX_TYPE Index
Definition COMMON/global.h:105