1 // -*- Mode: C++; tab-width: 2; -*- 2 // vi: set ts=2: 3 // 4 5 #ifndef BALL_STRUCTURE_TRIANGULATEDSURFACE_H 6 #define BALL_STRUCTURE_TRIANGULATEDSURFACE_H 7 8 #ifndef BALL_STRUCTURE_TRIANGLE_H 9 # include <BALL/STRUCTURE/triangle.h> 10 #endif 11 12 #ifndef BALL_STRUCTURE_TRIANGLEEDGE_H 13 # include <BALL/STRUCTURE/triangleEdge.h> 14 #endif 15 16 #ifndef BALL_STRUCTURE_TRIANGLEPOINT_H 17 # include <BALL/STRUCTURE/trianglePoint.h> 18 #endif 19 20 #ifndef BALL_MATHS_PLANE3_H 21 # include <BALL/MATHS/plane3.h> 22 #endif 23 24 #ifndef BALL_MATHS_SURFACE_H 25 # include <BALL/MATHS/surface.h> 26 #endif 27 28 #ifndef BALL_MATHS_VECTOR3_H 29 # include <BALL/MATHS/vector3.h> 30 #endif 31 32 #include <list> 33 #include <vector> 34 35 namespace BALL 36 { 37 /** Generic TriangulatedSurface Class. 38 \ingroup Surface 39 */ 40 class BALL_EXPORT TriangulatedSurface 41 { 42 43 public: 44 45 BALL_CREATE(TriangulatedSurface) 46 47 /** @name Type definitions 48 */ 49 //@{ 50 51 typedef std::list<TrianglePoint*>::iterator 52 PointIterator; 53 typedef std::list<TrianglePoint*>::const_iterator 54 ConstPointIterator; 55 typedef std::list<TriangleEdge*>::iterator 56 EdgeIterator; 57 typedef std::list<TriangleEdge*>::const_iterator 58 ConstEdgeIterator; 59 typedef std::list<Triangle*>::iterator 60 TriangleIterator; 61 typedef std::list<Triangle*>::const_iterator 62 ConstTriangleIterator; 63 64 //@} 65 /** @name Constructors and Destructors 66 */ 67 //@{ 68 69 /** Default constructor. 70 This method creates a new TriangulatedSurface object. 71 */ 72 TriangulatedSurface() 73 ; 74 75 /** Copy constructor. 76 Create a new TriangulatedSurface object from another. 77 @param surface the TriangulatedSurface object to be copied 78 @param bool ignored - just for interface consistency 79 */ 80 TriangulatedSurface(const TriangulatedSurface& surface, bool = true) 81 ; 82 83 /** Destructor. 84 Destructs the TriangulatedSurface object. 85 */ 86 virtual ~TriangulatedSurface() 87 ; 88 //@} 89 90 /** @name Static Members 91 */ 92 //@{ 93 94 /** 95 * A static function that constructs a triangulated tube. The tube is oriented along the 96 * z-axis, starts at z=0, ends at z=1 and has radius 1 97 * 98 * @param num_vertices The amount of vertices of which the base of the tube is composed 99 * @param subdiv Controls the amount of subdivisions along the z-axis. Default: 0 100 * @param closed Should the tube have opend or closed ends? Default: false 101 * @param out Controls whether the normals of the tube are pointing in or outwards. Default: true 102 */ 103 static TriangulatedSurface* createTube(unsigned int num_vertices, unsigned int subdiv = 0, bool closed = false, bool out = true); 104 105 /** 106 * A static function that constructs a triangulated disk. The disk lies in the x-y plane 107 * and has radius 1. 108 * 109 * @param num_vertices The amount of vertices of which the border of the disk is composed 110 * @param out Controls whether the normals of the tube are pointing up or downwards. Default: true 111 */ 112 static TriangulatedSurface* createDisk(unsigned int num_vertices, bool out = true); 113 //@} 114 115 /** @name Assignment 116 */ 117 //@{ 118 119 /** Delete all points, edges and triangles. 120 */ 121 void clear() 122 ; 123 124 /** Assign from another TriangulatedSurface. 125 @param surface the TriangulatedSurface object to assign from 126 @param bool ignored - just for interface consistency 127 */ 128 void set(const TriangulatedSurface& surface, bool = true) 129 ; 130 131 /** Assign from another TriangulatedSurface. 132 @param surface the TriangulatedSurface object to assign from 133 */ 134 TriangulatedSurface& operator = (const TriangulatedSurface& surface) 135 ; 136 137 //@} 138 139 /** @name Accessors 140 */ 141 //@{ 142 143 /** Insert a new point to the TriangulatedSurface. 144 @param point a pointer to the new point 145 */ 146 void insert(TrianglePoint* point); 147 148 /** Insert a new edge to the TriangulatedSurface. 149 @param edge a pointer to the new edge 150 */ 151 void insert(TriangleEdge* edge); 152 153 /** Insert a new triangle to the TriangulatedSurface. 154 @param triangle a pointer to the new triangle 155 */ 156 void insert(Triangle* triangle); 157 158 /** Get the number of points of the TriangulatedSurface. 159 * @deprecated Use TriangulatedSurface::getNumberOfPoints() instead 160 */ 161 BALL_DEPRECATED Size numberOfPoints() const; 162 163 /** Get the number of points of the TriangulatedSurface. 164 * @deprecated Use TriangulatedSurface::getNumberOfPoints() instead 165 */ 166 Size getNumberOfPoints() const; 167 168 /** Get the number of edges of the TriangulatedSurface. 169 * @deprecated Use TriangulatedSurface::getNumberOfEdges() instead 170 */ 171 BALL_DEPRECATED Size numberOfEdges() const; 172 173 /** Get the number of edges of the TriangulatedSurface. 174 */ 175 Size getNumberOfEdges() const; 176 177 /** Get the number of triangles of the TriangulatedSurface. 178 * @deprecated Use TriangulatedSurface::getNumberOfTriangles() instead 179 */ 180 BALL_DEPRECATED Size numberOfTriangles() const; 181 182 /** Get the number of triangles of the TriangulatedSurface. 183 * Use TriangulatedSurface::getNumberOfTriangles() instead 184 */ 185 Size getNumberOfTriangles() const; 186 187 /** Remove a point from the TriangulatedSurface. 188 If deep is true (default) the incidence-structure will be updated. 189 @param point a pointer to the point to delete 190 @param deep look above 191 */ 192 void remove(TrianglePoint* point, bool deep = true); 193 194 /** Remove a point from the TriangulatedSurface. 195 If deep is true (default) the incidence-structure will be updated. 196 @param p an iterator into the list of points of the 197 TriangulatedSurface which indicates the point to delete 198 @param deep look above 199 */ 200 void remove(PointIterator p, bool deep = true); 201 202 /** Remove an edge from the TriangulatedSurface. 203 If deep is true (not default) the incidence-structure will be updated. 204 @param edge a pointer to the edge to delete 205 @param deep look above 206 */ 207 void remove(TriangleEdge* edge, bool deep = true); 208 209 /** Remove an edge from the TriangulatedSurface. 210 If deep is true (not default) the incidence-structure will be updated. 211 @param e an iterator into the list of edges of the 212 TriangulatedSurface which indicates the edge to delete 213 @param deep look above 214 */ 215 void remove(EdgeIterator e, bool deep = true); 216 217 /** Remove a triangle from the TriangulatedSurface. 218 If deep is true (not default) the incidence-structure will be updated. 219 @param triangle a pointer to the triangle to delete 220 @param deep look above 221 */ 222 void remove(Triangle* triangle, bool deep = true); 223 224 /** Remove a triangle from the TriangulatedSurface. 225 If deep is true (not default) the incidence-structure will be updated. 226 @param t an iterator into the list of triangles of the 227 TriangulatedSurface which indicates the triangle to 228 delete 229 @param deep look above 230 */ 231 void remove(TriangleIterator t, bool deep = true); 232 233 /** Create a Surface object from the TriangulatedeSurface. 234 @param surface the created Surface object 235 */ 236 void exportSurface(Surface& surface); 237 238 /** Add a TriangulatedSurface object. 239 The lists of points, edges and triangles of the given 240 TriangulatedSurface objact are appended. The given TriangulatedSurface 241 objact will be unchanged. 242 @param surface the TriangulatedSurface object to add 243 */ 244 TriangulatedSurface& operator += (const TriangulatedSurface& surface); 245 246 /** Add a TriangulatedSurface object. 247 The lists of points, edges and triangles of the given 248 TriangulatedSurface objact are appended. After this operation, the 249 given TriangulatedSurface objact will be empty! 250 @param source the TriangulatedSurface object to add 251 */ 252 void join(TriangulatedSurface& source); 253 254 /** Shift the TriangulatedSurface. 255 All points are shifted by a vector c. 256 @param c the shift vector 257 */ 258 void shift(const TVector3<double>& c); 259 260 /** Blow up th TriangulatedSurface. 261 All points are multiplied by a scalar r. 262 @param r the blow up factor 263 */ 264 void blowUp(const double& r); 265 266 /** Set the indices of all points, edges and triangles. 267 */ 268 void setIndices(); 269 270 /** Set the density used by triangulation algorithms. 271 */ 272 void setDensity(const double& density); 273 274 /** Get the density used by triangulation algorithms. 275 */ 276 double getDensity() const; 277 278 /** Cut the TriangulatedSurface on a plane. 279 @param plane the plane to cut on 280 @param fuzzy 281 */ 282 void cut(const TPlane3<double>& plane, const double& fuzzy = 0); 283 284 /** Delete all triangles on the border of the TriangulatedSurface 285 */ 286 void shrink(); 287 288 /** Delete all isolated edges of the TriangulatedSurface 289 */ 290 void deleteIsolatedEdges(); 291 292 /** Delete all isolated points of the TriangulatedSurface 293 */ 294 void deleteIsolatedPoints(); 295 296 /** Get the border edges of the TriangulatedSurface. 297 Border edges are the edges with only one triangle. 298 @param border a list of the border edges 299 */ 300 void getBorder(std::list<TriangleEdge*>& border); 301 302 //@} 303 /** @name External Iterators 304 */ 305 //@{ 306 307 PointIterator beginPoint(); 308 309 ConstPointIterator beginPoint() const; 310 311 PointIterator endPoint(); 312 313 ConstPointIterator endPoint() const; 314 315 EdgeIterator beginEdge(); 316 317 ConstEdgeIterator beginEdge() const; 318 319 EdgeIterator endEdge(); 320 321 ConstEdgeIterator endEdge() const; 322 323 TriangleIterator beginTriangle(); 324 325 ConstTriangleIterator beginTriangle() const; 326 327 TriangleIterator endTriangle(); 328 329 ConstTriangleIterator endTriangle() const; 330 331 //@} 332 /*_ @name protected help functions 333 */ 334 //@{ 335 336 protected: 337 338 /*_ Test whether a TriangulatedSurface object can be copied 339 */ 340 bool canBeCopied() const; 341 342 /*_ Copy a TriangulatedSurface object 343 */ 344 void copy(const TriangulatedSurface& surface); 345 346 //@} 347 348 protected: 349 350 /*_ @name Attributes 351 */ 352 //@{ 353 354 /*_ the number of points of the triangulated surface 355 */ 356 Size number_of_points_; 357 /*_ the points of the surface. 358 */ 359 std::list<TrianglePoint*> points_; 360 /*_ the number of edges of the triangulated surface 361 */ 362 Size number_of_edges_; 363 /*_ the edges of the surface. 364 */ 365 std::list<TriangleEdge*> edges_; 366 /*_ the number of triangles of the triangulated surface 367 */ 368 Size number_of_triangles_; 369 /*_ the triangles of the surface. 370 */ 371 std::list<Triangle*> triangles_; 372 373 /*_ the density used by triangulation algorithms 374 */ 375 double density_; 376 377 //@} 378 379 }; 380 381 /** @name Storers 382 \ingroup Surface 383 */ 384 //@{ 385 386 /** Output- Operator 387 */ 388 BALL_EXPORT std::ostream& operator << (std::ostream& s, 389 const TriangulatedSurface& surface); 390 391 //@} 392 393 394 395 396 /** Generic TriangulatedSphere Class. 397 \par 398 399 \par 400 \ingroup Surface 401 */ 402 class BALL_EXPORT TriangulatedSphere : public TriangulatedSurface 403 { 404 405 public: 406 407 BALL_CREATE(TriangulatedSphere) 408 409 struct Face 410 { 411 TrianglePoint* p[6]; 412 TriangleEdge* e[9]; 413 Position pcount; 414 Position ecount; 415 }; 416 417 /** @name Constructors and Destructors 418 */ 419 //@{ 420 421 /** Default constructor. 422 This method creates a new TriangulatedSphere object. 423 */ 424 TriangulatedSphere() 425 ; 426 427 /** Copy constructor. 428 Create a new TriangulatedSphere object from another. 429 @param sphere the TriangulatedSphere object to be copied 430 @param bool ignored - just for interface consistency 431 */ 432 TriangulatedSphere(const TriangulatedSphere& sphere, bool = true) 433 ; 434 435 /** Destructor. 436 Destructs the TriangulatedSphere object. 437 */ 438 virtual ~TriangulatedSphere() 439 ; 440 //@} 441 442 /** @name Assignment 443 */ 444 //@{ 445 446 /** Assign from another TriangulatedSphere. 447 @param sphere the TriangulatedSphere object to assign from 448 @param bool ignored - just for interface consistency 449 */ 450 void set(const TriangulatedSphere& sphere, bool = true) 451 ; 452 453 /** Assign from another TriangulatedSphere. 454 @param sphere the TriangulatedSphere object to assign from 455 */ 456 TriangulatedSphere& operator = (const TriangulatedSphere& sphere) 457 ; 458 459 //@} 460 461 /** @name Accessors 462 */ 463 //@{ 464 465 /** Build an icosaeder. 466 If the TriangulatedSphere is not empty, it will be cleared first. 467 The center of the icosaeder will be the origin, the radius will be 1. 468 @param out if out = true the normal vectors will be oriented outside, 469 otherwise they will be oriented inside 470 */ 471 void icosaeder(bool out = true); 472 473 /** Build a pentakis dodecaeder. 474 If the TriangulatedSphere is not empty, it will be cleared first. 475 The center of the dodecaeder will be the origin, the radius will be 1. 476 @param out if out = true the normal vectors will be oriented outside, 477 otherwise they will be oriented inside 478 */ 479 void pentakisDodecaeder(bool out = true); 480 481 /** Refine a triangulated sphere. 482 The center of the sphere must be the origin, the radius must be 1. 483 @param iterations the number of refinement iterations 484 @param out the orientation of the normal vectors 485 */ 486 void refine(Position iterations, bool out = true); 487 488 489 private: 490 491 /*_ Refine a triangulated sphere once. 492 */ 493 void refine(bool out); 494 495 void buildFourTriangles 496 (Face face, 497 Triangle* face0, 498 Triangle* face1, 499 Triangle* face2, 500 Triangle* face3) 501 ; 502 503 /*_ Set the incidences of a refined triangulated sphere. 504 */ 505 void setIncidences(); 506 507 //@} 508 509 }; 510 511 } // namespace BALL 512 513 514 #endif // BALL_STRUCTURE_TRIANGULATEDSURFACE_H 515 516 517