00001
00002
00003
00004
00005
00006
00007
00008 #ifndef ELEMID_HPP_
00009 #define ELEMID_HPP_
00010
00011 #include"defs.h"
00012 #include"fv_compiler.h"
00013 #include<stdexcept>
00014 #include<cstring>
00015 #include<type_traits>
00016
00017
00018 namespace FemViewer {
00019
00020 #define EL_ID_ATTRIB(Tid) struct{ Tid eid : 24, etype : 1, faces : 5, active : 1, bound : 1; }
00021 #define FA_ID_ATTRIB(Tid) struct{ Tid fid : 31, ftype : 1; }
00022
00023 template<typename T>
00024 struct BaseId {
00025 union {
00026 T id;
00027 union {
00028 EL_ID_ATTRIB(T);
00029 FA_ID_ATTRIB(T);
00030 };
00031 };
00032 };
00033
00034
00035 template<typename T>
00036 class Id : public BaseId<T>
00037 {
00038 public:
00039 Id(const T id_ = T(0)) { this->id = id_; }
00040 Id(const BaseId<T>& ref) { this->id = ref.id; }
00041 Id& operator=(const BaseId<T>& rhs) { this->id = rhs.id; return *this; }
00042
00043 inline bool is_bit(T bit) const { return IS_BIT_SET(this->id,bit); }
00044 inline bool is_bit_not(T bit) const {return !is_bit(bit); }
00045
00046 };
00047
00048 template<typename T>
00049 class ElemId : public Id<T>
00050 {
00051 public:
00052 typedef T value_type;
00053
00054 ElemId(const T id_ = T(0)) : Id<T>(id_) {}
00055 ElemId(const BaseId<T>& ref) : Id<T>(ref) {}
00056 ElemId(const T eid_,
00057 const int type_,
00058 const bool f0 = false,
00059 const bool f1 = false,
00060 const bool f2 = false,
00061 const bool f3 = false,
00062 const bool f4 = false,
00063 const bool act = false,
00064 const bool bnd = false);
00065 ElemId& operator=(const BaseId<T>& rhs) { this->id = rhs.id; return *this; }
00066
00067
00068
00069 bool is_prism() const { return this->is_bit(ELTYPE_BIT_POS(this->id)); }
00070 bool is_tetra() const { return !this->is_prism(); }
00071
00072 bool operator < (const Id<T>& rhs) const {
00073 return (this->eid < rhs.eid);
00074 }
00075
00076
00077 };
00078
00079 template<typename T>
00080 ElemId<T>::ElemId(const T eid_, const int type_,
00081 const bool f0, const bool f1, const bool f2,
00082 const bool f3, const bool f4, const bool act, const bool bnd)
00083 : Id<T>()
00084 {
00085 this->id = eid_;
00086 if (type_) SET_PRISM(this->id);
00087 if (f0) SET_FACE0(this->id);
00088 if (f1) SET_FACE1(this->id);
00089 if (f2) SET_FACE2(this->id);
00090 if (f3) SET_FACE3(this->id);
00091 if (f4) SET_FACE4(this->id);
00092 if (act) SET_ACTIVE(this->id);
00093 if (bnd) SET_BOUND(this->id);
00094 }
00095
00096
00097 template<typename T>
00098 struct FaceId : public Id<T> {
00099 public:
00100 typedef T value_type;
00101 FaceId(const T id_ = T(0)) : Id<T>(id_) {}
00102 FaceId(const BaseId<T>& ref) : Id<T>(ref) {}
00103 FaceId& operator=(const BaseId<T>& rhs) { this->id = rhs.id; return *this; }
00104
00105
00106
00107 bool is_triangle() const { return this->is_bit(FACE_TYPE_POS(this->id)); }
00108 bool is_quad() const { return !this->is_triangle(); }
00109
00110 bool operator < (const Id<T>& rhs) const {
00111 return (this->fid < rhs.fid);
00112 }
00113 };
00114
00115 #undef EL_ID_ATTRIB
00116 #undef FA_ID_ATTRIB
00117
00118 template <typename T>
00119 struct CompareBndAct {
00120 bool operator() (T* el1, T* el2)
00121 {
00122 return (ELEM_ID(el1->id) < ELEM_ID(el2->id));
00123 }
00124 };
00125
00126 template<typename T>
00127 bool compare_func(T* it1, T* it2) { return (ELEM_ID(it1->el_id) < ELEM_ID(it2->el_id)); }
00128
00129 struct ElemInfo : public ElemId<id_t>
00130 {
00131 int nodes[7];
00132
00133 ElemInfo() : ElemId<id_t>() {
00134 memset(nodes,0x0,sizeof(nodes));
00135 }
00136
00137 bool operator==(const ElemInfo& rh) {
00138 bool result = (nodes[0] == rh.nodes[0]) ? this->eid == rh.eid : false;
00139 return result;
00140 }
00141
00142 };
00143
00144 FV_STATIC_ASSERT(ElemInfo,8);
00145
00146
00147 }
00148
00149 #endif