/usr/include/BALL/STRUCTURE/graphEdge.h is in libball1.4-dev 1.4.1+20111206-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | // -*- 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;
/** Generic GraphEdge Class.
\ingroup Surface
*/
template <typename Vertex, typename Edge, typename Face>
class GraphEdge
{
public:
/** @name Class friends
- class GraphVertex<Vertex,Edge,Face>;
- class GraphFace<Vertex,Edge,Face>;
- class GraphTriangle<Vertex,Edge,Face>;
*/
friend class GraphVertex<Vertex,Edge,Face>;
friend class GraphFace<Vertex,Edge,Face>;
friend class GraphTriangle<Vertex,Edge,Face>;
BALL_CREATE(GraphEdge)
/** @name Constructors and Destructors
*/
//@{
/** Default constructor.
This method creates a new GraphEdge object.
*/
GraphEdge();
/** Copy constructor.
Create a new GraphEdge object from another.
@param edge the GraphEdge object to be copied
@param deep if deep = false, all pointers are set to NULL (default).
Otherwise the new GraphEdge object is linked to the
neighbours of the old GraphEdge object.
*/
GraphEdge(const GraphEdge<Vertex,Edge,Face>& edge, bool deep = false);
/** Detailled constructor.
Create a new GraphEdge object from a lot of nice objects
@param vertex1 assigned to the first vertex
@param vertex2 assigned to the second vertex
@param face1 assigned to the first face
@param face2 assigned to the second face
@param index assigned to the index
*/
GraphEdge(Vertex* vertex1,
Vertex* vertex2,
Face* face1,
Face* face2,
Index index);
/** Destructor.
Destructs the GraphEdge object.
The neighboured faces and vertices are {/bf not} destructed.
*/
virtual ~GraphEdge();
//@}
/** @name Assignment
*/
//@{
/** Assign from another GraphEdge.
@param edge the GraphEdge object to assign from
@param deep if deep = false, all pointers are set to NULL (default).
Otherwise the GraphEdge object is linked to the
neighbours of the GraphEdge object to assign from.
*/
void set(const GraphEdge<Vertex,Edge,Face>& edge, bool deep = false);
/** Assign from another GraphEdge.
The GraphEdge object is linked to the neighbours of the GraphEdge
object to assign from.
@param edge the GraphEdge object to assign from
*/
GraphEdge<Vertex,Edge,Face>& operator =
(const GraphEdge<Vertex,Edge,Face>& edge);
/** Assign from a lot of nice objects
@param vertex0 assigned to the first vertex
@param vertex1 assigned to the second vertex
@param face0 assigned to the first face
@param face1 assigned to the second face
@param index assigned to the index
*/
void set(Vertex* vertex0,
Vertex* vertex1,
Face* face0,
Face* face1,
Index index);
//@}
/** @name Accessors
*/
//@{
/** Set one of the two vertices of the GraphEdge.
@param i the first vertex is changed if i = 0, the second
otherwise
@param vertex a pointer to the new vertex
*/
void setVertex(Position i, Vertex* vertex);
/** Return one of the two vertices of the GraphEdge.
@param i
@return Vertex* a pointer to the first vertex if i = 0,
a pointer to the second vertex otherwise
*/
Vertex* getVertex(Position i) const;
/** Set one of the two faces of the GraphEdge.
@param i change the first face, if i = 0, the second otherwise
@param face a pointer to the new face
*/
void setFace(Position i, Face* face);
/** Return one of the two faces of the GraphEdge.
@param i
@return Face* a pointer to the first face if i = 0,
a pointer to the second face otherwise
*/
Face* getFace(Position i) const;
/** Set the index of the GraphEdge.
@param index the new index
*/
void setIndex(Index index);
/** Return the index of the GraphEdge.
@return Index the index of the GraphEdge
*/
Index getIndex() const;
/** Return a pointer to the other vertex of the GraphEdge.
If the given vertex is not incident to the GraphEdge, an exception is
thrown.
@param vertex one of the vertices of the GraphEdge
@return Vertex* the other vertex
*/
Vertex* other(const Vertex* vertex) const
throw(Exception::GeneralException);
/** Return a pointer to the other face of the GraphEdge.
If the given face is not neighboured to the GraphEdge, an exception is
thrown.
@param face one of the faces of the GraphEdge
@return Face* the other face
*/
Face* other(const Face* face) const
throw(Exception::GeneralException);
/** Substitute a vertex by an other one.
@param old_vertex the vertex that has to be substituted
@param new_vertex the new vertex
@return bool <b>true</b>, if the vertex can be substituted,
<b>false</b> otherwise
*/
bool substitute(const Vertex* old_vertex, Vertex* new_vertex);
/** Substitute a face by an other one.
@param old_vertex the face that has to be substituted
@param new_vertex the new face
@return bool <b>true</b>, if the face can be substituted,
<b>false</b> otherwise
*/
bool substitute(const Face* old_vertex, Face* new_vertex);
/** Delete a face of the GraphEdge.
If the second face of the GraphEdge should be deleted, it is set to
NULL. If the first one should be deleted, the second one is copied to
first position and then set to NULL.
@param face the face to delete
@return Face* a pointer to the other face
*/
Face* remove(const Face* face);
/* Swap the two vertices of the GraphEdge
*/
void revert();
//@}
/** @name Predicates
*/
//@{
/** Equality operator.
@return bool, <b>true</b>
*/
virtual bool operator == (const Edge&) const;
/** Inequality operator.
@return bool <b>false</b>
*/
virtual bool operator != (const Edge&) const;
/** Similarity operator.
@return bool <b>true</b>
*/
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
throw(Exception::GeneralException)
{
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
throw(Exception::GeneralException)
{
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
|