geometrytype.hh

Go to the documentation of this file.
00001 #ifndef DUNE_GEOMETRY_TYPE_HH
00002 #define DUNE_GEOMETRY_TYPE_HH
00003 
00008 #include <dune/common/exceptions.hh>
00009 
00010 namespace Dune {
00011 
00019     class GeometryType
00020     {
00021     public:
00024         enum BasicType {
00025                   simplex,   
00026                   cube,      
00027                   pyramid,   
00028                   prism      
00029                 };
00030 
00031     private:
00032 
00034         BasicType basicType_;
00035 
00037         unsigned int dim_;
00038 
00039     public:
00041         GeometryType ()
00042  {}
00043 
00045         GeometryType(BasicType basicType, unsigned int dim)
00046             : basicType_(basicType), dim_(dim)
00047         {}
00048 
00052         explicit GeometryType(unsigned int dim)
00053             : basicType_(cube), dim_(dim)
00054         {}
00055 
00058 
00060         void makeVertex() {dim_ = 0;}
00061         
00063         void makeLine() {dim_ = 1;}
00064         
00066         void makeTriangle() {basicType_ = simplex; dim_ = 2;}
00067         
00069         void makeQuadrilateral() {basicType_ = cube; dim_ = 2;}
00070         
00072         void makeTetrahedron() {basicType_ = simplex; dim_ = 3;}
00073         
00075         void makePyramid() {basicType_ = pyramid;}
00076         
00078         void makePrism() {basicType_ = prism;}
00079         
00081         void makeHexahedron() {basicType_ = cube; dim_ = 3;}
00082         
00084         void makeSimplex(unsigned int dim) {basicType_ = simplex; dim_ = dim;}
00085         
00087         void makeCube(unsigned int dim) {basicType_ = cube; dim_ = dim;}
00088         
00095         bool isVertex() const {return dim_==0;}
00096         
00098         bool isLine() const {return dim_==1;}
00099         
00101         bool isTriangle() const {return basicType_==simplex && dim_==2;}
00102         
00104         bool isQuadrilateral() const {return basicType_==cube && dim_==2;}
00105         
00107         bool isTetrahedron() const {return basicType_==simplex && dim_==3;}
00108         
00110         bool isPyramid() const {return basicType_==pyramid;}
00111         
00113         bool isPrism() const {return basicType_==prism;}
00114         
00116         bool isHexahedron() const {return basicType_==cube && dim_==3;}
00117         
00119         bool isSimplex() const {return basicType_==simplex || dim_ < 2;}
00120         
00122         bool isCube() const {return basicType_==cube || dim_ < 2;}
00123         
00125         unsigned int dim() const {return dim_;}
00126 
00128         BasicType basicType() const {return basicType_;}
00129 
00135         bool operator==(const GeometryType& other) const {
00136             return ( (dim()==0 && other.dim()==0) 
00137                      || (dim()==1 && other.dim()==1)
00138                      || (dim()==other.dim() && basicType_==other.basicType_) );
00139         }
00140 
00142         bool operator!=(const GeometryType& other) const {
00143             return ! ((*this)==other);
00144         }
00145 
00147         bool operator < (const GeometryType& other) const {         
00148             if (dim() != other.dim())
00149                 return dim() < other.dim();
00150             else if (dim()==0 || dim()==1)
00151                 return false;
00152             
00153             return basicType_ < other.basicType_;
00154         }
00155 
00157         friend std::ostream& operator<< (std::ostream& s, const GeometryType& a)
00158         {
00159             switch (a.basicType_) {
00160             case simplex:   
00161                 s << "(simplex, " << a.dim_ << ")";
00162                 break;
00163             case cube:      
00164                 s << "(cube, " << a.dim_ << ")";
00165                 break;
00166             case pyramid:
00167                 s << "pyramid"; 
00168                 break;
00169             case prism:
00170                 s << "prism";
00171             }
00172             
00173             return s;
00174         }
00175 
00176     };
00177 
00179     inline std::ostream& operator<< (std::ostream& s, GeometryType::BasicType type)
00180     {
00181       switch (type) {
00182       case GeometryType::simplex: s << "simplex"; break;
00183       case GeometryType::cube:    s << "cube";    break;
00184       case GeometryType::pyramid: s << "pyramid"; break;
00185       case GeometryType::prism:   s << "prism";   break;
00186       default: s << "[unknown GeometryType::BasicType: " << int(type) << "]";
00187       }
00188       return s;
00189     }
00190 }
00191 
00192 #endif

Generated on 12 Dec 2007 with Doxygen (ver 1.5.1)