Main Page   Namespace List   Class Hierarchy   Compound List   File List   Header Files   Sources   Namespace Members   Compound Members   File Members  

delaunay.h

00001 //$Header: /home/ben/Mapper/include/RCS/delaunay.h,v 6.15 2002/07/07 11:38:02 ben Exp $
00002 #ifndef DELAUNAY_H
00003 #define DELAUNAY_H
00004 // Copyright Benedict Adamson 2002.
00005 // This file is part of Mapper.
00006 
00007 // Mapper is free software; you can redistribute it and/or modify
00008 // it under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation; either version 2 of the License, or
00010 // (at your option) any later version.
00011 
00012 // Mapper is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License
00018 // along with Mapper; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00029 #include <vector>
00030 
00031 #include "vector2.h"
00032 
00038 namespace delaunay {
00039 
00043    class edge{
00044       public: //Construction and destruction
00045          
00058          inline edge(
00059             const vector2 &v0,
00060             const vector2 &v1
00061             );
00062 
00063          inline ~edge(void);
00064 
00065       public: //Attributes
00066          
00079          inline const vector2 &vertex(
00080             const unsigned i
00081             ) const;
00082 
00100          inline friend bool operator==(
00101             const edge &a,
00102             const edge &b
00103             );
00104 
00105       private:
00106          vector2 vertex_[2];
00107          
00108    };
00109 
00110 
00111 
00126    class triangle{
00127       public: //Construction and destruction
00128          
00143          triangle(
00144             const vector2 &v0,
00145             const vector2 &v1,
00146             const vector2 &v2
00147             );
00148 
00159          triangle(
00160             const triangle &t
00161             );
00162 
00163          inline ~triangle(void);
00164 
00165       public: //Attributes
00166 
00179          inline const vector2 &vertex(
00180             const unsigned i
00181             ) const;
00182 
00190          inline const vector2 &circumcentre(void) const;
00191 
00199          const double circumradius(void) const;
00200 
00209          bool circumcircle_contains(
00210             const vector2 &p
00211             ) const;
00212 
00213       public: //messages
00214          //None
00215 
00216       public:
00217 
00236          inline friend bool operator==(
00237             const triangle &a,
00238             const triangle &b
00239             );
00240 
00241       private:
00242          vector2 vertex_[3];
00243          vector2 circumcentre_;
00244          double circumradius2;
00245 
00246          void calculate_circumcircle(void);
00247 
00248    };
00249 
00250 
00251 
00276    class triangulation{
00277       public://Construction and destruction
00278 
00333          triangulation(
00334             const double l,
00335             const double r,
00336             const double t,
00337             const double b
00338             );
00339 
00340          virtual ~triangulation(void);
00341 
00342       public: //attributes
00343 
00347          const double left;
00348 
00352          const double right;
00353 
00357          const double top;
00358 
00362          const double bottom;
00363 
00367          const vector2 tl;
00368 
00372          const vector2 tr;
00373 
00377          const vector2 br;
00378 
00382          const vector2 bl;
00383 
00402          inline bool corner_point(
00403             const vector2 &p
00404             ) const;
00405 
00416          inline bool border_triangle(
00417             const triangle &t
00418             ) const;
00419 
00438          bool contains(
00439             const vector2 &p
00440             ) const;
00441 
00442       public: //associations
00443 
00450          const vector< triangle > &triangles(void) const {
00451             return this->triangles_;
00452          }
00453 
00454       public: //messages
00455 
00482          void add_point(
00483             const vector2 &p
00484             );
00485 
00486       private:
00487 
00488          vector< triangle > triangles_;
00489          
00490    };
00491 
00492 };
00493    
00494 
00495 
00496 inline delaunay::edge::edge(
00497    const vector2 &v0,
00498    const vector2 &v1
00499    )
00500 {
00501    this->vertex_[0] = v0;
00502    this->vertex_[1] = v1;
00503    {//Postconditions:
00504       //assert( this->vertex(0) == v0 );
00505       //assert( this->vertex(1) == v1 );
00506    };
00507 }
00508 
00509 
00510 
00511 inline delaunay::edge::~edge(void)
00512 {
00513    //Do nothing
00514 }
00515 
00516 
00517    
00518 inline const vector2 &delaunay::edge::vertex(
00519    const unsigned i
00520    ) const
00521 {
00522    {//Preconditions:
00523       //assert( i == 0 || i == 1 );
00524    };
00525    return this->vertex_[i];
00526 }
00527 
00528 
00529 inline bool delaunay::operator==(
00530    const edge &a,
00531    const edge &b
00532    )
00533 {
00534    return
00535    (a.vertex_[0] == b.vertex_[0] && a.vertex_[1] == b.vertex_[1]) ||
00536    (a.vertex_[0] == b.vertex_[1] && a.vertex_[1] == b.vertex_[0]);
00537 }
00538 
00539 
00540 
00541 inline delaunay::triangle::~triangle(void)
00542 {
00543    //Do nothing
00544 }
00545 
00546 
00547 
00548 inline const vector2 &delaunay::triangle::vertex(
00549    const unsigned i
00550    ) const
00551 {
00552    {//Preconditions:
00553       //assert( 0 <= i && i <= 2 );
00554    };
00555    return this->vertex_[i];
00556 }
00557 
00558 
00559 inline const vector2 &delaunay::triangle::circumcentre(void) const
00560 {
00561    return this->circumcentre_;
00562 }
00563 
00564 
00565 inline bool delaunay::operator==(
00566    const triangle &a,
00567    const triangle &b
00568    )
00569 {
00570    return
00571    (a.vertex_[0] == b.vertex_[0] &&
00572     a.vertex_[1] == b.vertex_[1] &&
00573     a.vertex_[2] == b.vertex_[2]) ||
00574    (a.vertex_[0] == b.vertex_[1] &&
00575     a.vertex_[1] == b.vertex_[2] &&
00576     a.vertex_[2] == b.vertex_[0]) ||
00577    (a.vertex_[0] == b.vertex_[2] &&
00578     a.vertex_[1] == b.vertex_[0] &&
00579     a.vertex_[2] == b.vertex_[1]);
00580    //assert( triangle(a, b, c) == triangle(a, b, c) );
00581    //assert( triangle(a, b, c) == triangle(b, c, a) );
00582    //assert( triangle(a, b, c) == triangle(c, a, b) );
00583 }
00584 
00585 inline bool delaunay::triangulation::corner_point(
00586    const vector2 &p
00587    ) const
00588 {
00589    return
00590       p == this->tl ||
00591       p == this->tr ||
00592       p == this->br ||
00593       p == this->bl;
00594    //assert( this->corner_point( &(this->tl) ) );
00595    //assert( this->corner_point( &(this->tr) ) );
00596    //assert( this->corner_point( &(this->br) ) );
00597    //assert( this->corner_point( &(this->bl) ) );
00598 }
00599 
00600 
00601 
00602 inline bool delaunay::triangulation::border_triangle(
00603    const triangle &t
00604    ) const
00605 {
00606    //Returns true iff a vertex of the triangle is a corner point.
00607    return
00608       this->corner_point( t.vertex(0) ) ||
00609       this->corner_point( t.vertex(1) ) ||
00610       this->corner_point( t.vertex(2) );
00611 }
00612 
00613 #endif

Generated at Sun Jul 14 20:38:07 2002 for Mapper by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999