Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_T4MESH_T4TETRAHEDRON_H
00002 #define OPENTISSUE_CORE_CONTAINERS_T4MESH_T4TETRAHEDRON_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <boost/array.hpp>
00013 #include <cassert>
00014
00015 namespace OpenTissue
00016 {
00017 namespace t4mesh
00018 {
00019
00020 template< typename mesh_type_>
00021 class T4Tetrahedron : public mesh_type_::tetrahedron_traits
00022 {
00023 public:
00024 typedef mesh_type_ mesh_type;
00025 typedef typename mesh_type::node_type node_type;
00026 typedef typename mesh_type::tetrahedron_type tetrahedron_type;
00027 typedef typename mesh_type::index_type index_type;
00028
00029 typedef typename mesh_type::node_iterator node_iterator;
00030 typedef typename mesh_type::const_node_iterator const_node_iterator;
00031
00032 typedef typename mesh_type::tetrahedron_iterator tetrahedron_iterator;
00033 typedef typename node_type::tetrahedron_circulator tetrahedron_circulator;
00034
00035 protected:
00036
00037 index_type m_idx;
00038 mesh_type * m_owner;
00039 boost::array<index_type, 4> m_nodes;
00040
00041 private:
00042
00043 friend class t4mesh_core_access;
00044
00045 void set_index(index_type idx) { m_idx = idx; }
00046 void set_owner(mesh_type * owner) { m_owner = owner; }
00047 void set_node0(index_type idx) { m_nodes[0] = idx; }
00048 void set_node1(index_type idx) { m_nodes[1] = idx; }
00049 void set_node2(index_type idx) { m_nodes[2] = idx; }
00050 void set_node3(index_type idx) { m_nodes[3] = idx; }
00051
00052 public:
00053
00054 T4Tetrahedron()
00055 : m_idx( mesh_type::undefined() )
00056 , m_owner(0)
00057 {
00058 m_nodes.assign( mesh_type::undefined() );
00059 }
00060
00061 public:
00062
00063 index_type idx() const { return m_idx; }
00064
00065 index_type node_idx(index_type const & local_idx) const
00066 {
00067 assert(0<=local_idx);
00068 assert(local_idx<=3);
00069
00070 return m_nodes[local_idx];
00071 }
00072
00073 node_iterator i() { return m_owner->node(m_nodes[0]); }
00074 const_node_iterator i() const { return m_owner->const_node(m_nodes[0]); }
00075 node_iterator j() { return m_owner->node(m_nodes[1]); }
00076 const_node_iterator j() const { return m_owner->const_node(m_nodes[1]); }
00077 node_iterator k() { return m_owner->node(m_nodes[2]); }
00078 const_node_iterator k() const { return m_owner->const_node(m_nodes[2]); }
00079 node_iterator m() { return m_owner->node(m_nodes[3]); }
00080 const_node_iterator m() const { return m_owner->const_node(m_nodes[3]); }
00081
00082 tetrahedron_iterator jkm() const
00083 {
00084 node_iterator a = j();
00085 node_iterator b = k();
00086 node_iterator c = m();
00087 for(tetrahedron_circulator it = a->begin();it!=a->end();++it)
00088 if(it->has_face(c,b,a))
00089 return m_owner->tetrahedron(it->idx());
00090 return m_owner->tetrahedron_end();
00091 }
00092
00093 tetrahedron_iterator ijm()const
00094 {
00095 node_iterator a = i();
00096 node_iterator b = j();
00097 node_iterator c = m();
00098 for(tetrahedron_circulator it = a->begin();it!=a->end();++it)
00099 if(it->has_face(c,b,a))
00100 return m_owner->tetrahedron(it->idx());
00101 return m_owner->tetrahedron_end();
00102 }
00103
00104 tetrahedron_iterator kim()const
00105 {
00106 node_iterator a = k();
00107 node_iterator b = i();
00108 node_iterator c = m();
00109 for(tetrahedron_circulator it = a->begin();it!=a->end();++it)
00110 if(it->has_face(c,b,a))
00111 return m_owner->tetrahedron(it->idx());
00112 return m_owner->tetrahedron_end();
00113 }
00114
00115 tetrahedron_iterator ikj()const
00116 {
00117 node_iterator a = i();
00118 node_iterator b = k();
00119 node_iterator c = j();
00120 for(tetrahedron_circulator it = a->begin();it!=a->end();++it)
00121 if(it->has_face(c,b,a))
00122 return m_owner->tetrahedron(it->idx());
00123 return m_owner->tetrahedron_end();
00124 }
00125
00126 mesh_type * owner() { return m_owner; }
00127 mesh_type const * owner() const { return m_owner; }
00128
00129
00130 node_iterator node(index_type local_idx)
00131 {
00132 return m_owner->node( this->local2global( local_idx) );
00133 }
00134
00135 const_node_iterator node(index_type local_idx) const
00136 {
00137 return m_owner->const_node( this->local2global( local_idx ) );
00138 }
00139
00140 index_type local2global(index_type local_idx) const
00141 {
00142 assert(0<=local_idx);
00143 assert(local_idx<=3);
00144 return m_nodes[local_idx];
00145 }
00146
00147 index_type global2local(index_type global_idx) const
00148 {
00149 if(global_idx==m_nodes[0])
00150 return 0;
00151 if(global_idx==m_nodes[1])
00152 return 1;
00153 if(global_idx==m_nodes[2])
00154 return 2;
00155 if(global_idx==m_nodes[3])
00156 return 3;
00157 return mesh_type::undefined();
00158 }
00159
00160 bool has_face(node_iterator a,node_iterator b,node_iterator c) const
00161 {
00162 index_type i = m_nodes[0];
00163 index_type j = m_nodes[1];
00164 index_type k = m_nodes[2];
00165 index_type m = m_nodes[3];
00166 if(
00167 ( i == a->idx() && j == b->idx() && m == c->idx() )||
00168 ( j == a->idx() && k == b->idx() && m == c->idx() )||
00169 ( k == a->idx() && i == b->idx() && m == c->idx() )||
00170 ( i == a->idx() && k == b->idx() && j == c->idx() )||
00171 ( i == b->idx() && j == c->idx() && m == a->idx() )||
00172 ( j == b->idx() && k == c->idx() && m == a->idx() )||
00173 ( k == b->idx() && i == c->idx() && m == a->idx() )||
00174 ( i == b->idx() && k == c->idx() && j == a->idx() )||
00175 ( i == c->idx() && j == a->idx() && m == b->idx() )||
00176 ( j == c->idx() && k == a->idx() && m == b->idx() )||
00177 ( k == c->idx() && i == a->idx() && m == b->idx() )||
00178 ( i == c->idx() && k == a->idx() && j == b->idx() )
00179 )
00180 return true;
00181 return false;
00182 }
00183
00184 };
00185
00186 }
00187 }
00188
00189
00190 #endif