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                   none       
00030                 };
00031 
00032     private:
00033 
00035         BasicType basicType_;
00036 
00038         unsigned int dim_;
00039 
00040     public:
00042         GeometryType ()
00043         {}
00044 
00046         GeometryType(BasicType basicType, unsigned int dim)
00047             : basicType_(basicType), dim_(dim)
00048         {}
00049 
00053         explicit GeometryType(unsigned int dim)
00054             : basicType_(cube), dim_(dim)
00055         {}
00056 
00059 
00061         void makeVertex() {dim_ = 0;}
00062         
00064         void makeLine() {dim_ = 1;}
00065         
00067         void makeTriangle() {basicType_ = simplex; dim_ = 2;}
00068         
00070         void makeQuadrilateral() {basicType_ = cube; dim_ = 2;}
00071         
00073         void makeTetrahedron() {basicType_ = simplex; dim_ = 3;}
00074         
00076         void makePyramid() {basicType_ = pyramid;  dim_ = 3;}
00077         
00079         void makePrism() {basicType_ = prism;  dim_ = 3;}
00080         
00082         void makeHexahedron() {basicType_ = cube; dim_ = 3;}
00083         
00085         void makeSimplex(unsigned int dim) {basicType_ = simplex; dim_ = dim;}
00086         
00088         void makeCube(unsigned int dim) {basicType_ = cube; dim_ = dim;}
00089         
00091         void makeNone(unsigned int dim) {basicType_ = none; dim_ = dim;}
00092         
00099         bool isVertex() const {return dim_==0;}
00100         
00102         bool isLine() const {return dim_==1;}
00103         
00105         bool isTriangle() const {return basicType_==simplex && dim_==2;}
00106         
00108         bool isQuadrilateral() const {return basicType_==cube && dim_==2;}
00109         
00111         bool isTetrahedron() const {return basicType_==simplex && dim_==3;}
00112         
00114         bool isPyramid() const {return basicType_==pyramid;}
00115         
00117         bool isPrism() const {return basicType_==prism;}
00118         
00120         bool isHexahedron() const {return basicType_==cube && dim_==3;}
00121         
00123         bool isSimplex() const {return basicType_==simplex || dim_ < 2;}
00124         
00126         bool isCube() const {return basicType_==cube || dim_ < 2;}
00127         
00129         bool isNone() const {return basicType_==none;}
00130         
00132         unsigned int dim() const {return dim_;}
00133 
00135         BasicType basicType() const {return basicType_;}
00136 
00142         bool operator==(const GeometryType& other) const {
00143             return ( (dim()==0 && other.dim()==0) 
00144                      || (dim()==1 && other.dim()==1)
00145                      || (dim()==other.dim() && basicType_==other.basicType_) );
00146         }
00147 
00149         bool operator!=(const GeometryType& other) const {
00150             return ! ((*this)==other);
00151         }
00152 
00154         bool operator < (const GeometryType& other) const {         
00155             if (dim() != other.dim())
00156                 return dim() < other.dim();
00157             else if (dim()==0 || dim()==1)
00158                 return false;
00159             
00160             return basicType_ < other.basicType_;
00161         }
00162 
00164         friend std::ostream& operator<< (std::ostream& s, const GeometryType& a)
00165         {
00166             switch (a.basicType_) {
00167             case simplex:   
00168                 s << "(simplex, " << a.dim_ << ")";
00169                 break;
00170             case cube:      
00171                 s << "(cube, " << a.dim_ << ")";
00172                 break;
00173             case pyramid:
00174                 s << "pyramid"; 
00175                 break;
00176             case prism:
00177                 s << "prism";
00178                 break;
00179             case none:
00180                 s << "(none, " << a.dim_ << ")";
00181                 break;
00182             default:
00183                 s << "invalid geometry type";
00184             }
00185             
00186             return s;
00187         }
00188 
00189     };
00190 
00192     inline std::ostream& operator<< (std::ostream& s, GeometryType::BasicType type)
00193     {
00194       switch (type) {
00195       case GeometryType::simplex: s << "simplex"; break;
00196       case GeometryType::cube:    s << "cube";    break;
00197       case GeometryType::pyramid: s << "pyramid"; break;
00198       case GeometryType::prism:   s << "prism";   break;
00199       case GeometryType::none:    s << "none";    break;
00200       default: s << "[unknown GeometryType::BasicType: " << int(type) << "]";
00201       }
00202       return s;
00203     }
00204 }
00205 
00206 #endif
Generated on Mon Apr 26 10:45:21 2010 for dune-common by  doxygen 1.6.3