Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_POLYMESH_CORE_ACCESS_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_POLYMESH_CORE_ACCESS_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <cassert>
00013
00014 namespace OpenTissue
00015 {
00016 namespace polymesh
00017 {
00018 class polymesh_core_access
00019 {
00020 public:
00021
00022 template<typename feature_iterator,typename handle>
00023 static void set_self_handle(feature_iterator feature,handle self) { feature->set_handle(self); }
00024
00025 template<typename feature_iterator,typename mesh_type>
00026 static void set_owner(feature_iterator feature,mesh_type * owner){ feature->set_owner(owner); }
00027
00028 template<typename vertex_iterator,typename halfedge_handle>
00029 static void set_outgoing_halfedge_handle(vertex_iterator v,halfedge_handle h)
00030 {
00031 v->set_outgoing_halfedge_handle(h);
00032 }
00033
00034 template<typename halfedge_iterator,typename halfedge_handle>
00035 static void set_next_handle(halfedge_iterator h,halfedge_handle n)
00036 {
00037 h->set_next_handle(n);
00038 }
00039
00040 template<typename halfedge_iterator,typename face_handle>
00041 static void set_face_handle(halfedge_iterator h,face_handle f)
00042 {
00043 h->set_face_handle(f);
00044 }
00045
00046 template<typename halfedge_iterator,typename halfedge_handle>
00047 static void set_twin_handle(halfedge_iterator h,halfedge_handle t)
00048 {
00049 h->set_twin_handle(t);
00050 }
00051
00052 template<typename halfedge_iterator,typename vertex_handle>
00053 static void set_destination_handle(halfedge_iterator h,vertex_handle v)
00054 {
00055 h->set_destination_handle(v);
00056 }
00057
00058 template<typename face_iterator,typename halfedge_handle>
00059 static void set_border_halfedge_handle(face_iterator f,halfedge_handle h)
00060 {
00061 f->set_border_halfedge_handle(h);
00062 }
00063
00064 template<typename halfedge_iterator,typename edge_handle>
00065 static void set_edge_handle(halfedge_iterator h,edge_handle e){ h->set_edge_handle(e); }
00066
00067 template<typename edge_iterator,typename halfedge_handle>
00068 static void set_halfedge0_handle(edge_iterator e,halfedge_handle h){ e->set_halfedge0_handle(h); }
00069
00070 template<typename edge_iterator,typename halfedge_handle>
00071 static void set_halfedge1_handle(edge_iterator e,halfedge_handle h){ e->set_halfedge1_handle(h); }
00072
00073
00074
00079 template<typename vertex_iterator>
00080 static void adjust_outgoing_halfedge_handle(vertex_iterator v)
00081 {
00082 typedef typename vertex_iterator::value_type vertex_type;
00083 typedef typename vertex_type::mesh_type mesh_type;
00084 typedef typename mesh_type::vertex_halfedge_circulator vertex_halfedge_circulator;
00085
00086 vertex_halfedge_circulator circulator( *v ), end;
00087 for(;circulator!=end;++circulator)
00088 {
00089 if( circulator->get_face_handle().is_null())
00090 {
00091 set_outgoing_halfedge_handle(v,circulator->get_handle());
00092 return;
00093 }
00094 }
00095 }
00096
00104 template<typename halfedge_iterator>
00105 bool unlink(halfedge_iterator h)
00106 {
00107 typedef typename halfedge_iterator::value_type halfedge_type;
00108 typedef typename halfedge_type::mesh_type mesh_type;
00109
00110 typedef typename mesh_type::halfedge_iterator vertex_iterator;
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 if(h.get_destination_handle().is_null())
00126 {
00127 assert(!"unlink(h): Illegal topology!");
00128 return false;
00129 }
00130 mesh_type * owner = h.get_owner();
00131 if(!owner)
00132 {
00133 assert(!"unlink(h): No owner mesh!");
00134 return false;
00135 }
00136
00137 halfedge_iterator h1 = h.get_twin_iterator();
00138 halfedge_iterator h0 = h1->get_twin_itreator();
00139 vertex_iterator v = h.get_destination_iterator();
00140 halfedge_iterator h1_prev = h1->get_prev_iterator();
00141 halfedge_iterator h0_next = h0->get_next_iterator();
00142
00143 if(h1_prev->m_self =! h0->m_self)
00144 {
00145 h1_prev->m_next = h0_next->m_self;
00146 h0_next->m_prev = h1_prev->m_self;
00147 }
00148
00149 if(h1_prev->m_self == h0->m_self)
00150 {
00151 v->m_outgoing_halfedge = owner->null_halfedge_handle();
00152 }
00153
00154 if(h1->m_self == v->m_outgoing_halfedge)
00155 {
00156 v->m_outgoing_halfedge = h0_next->m_self;
00157 }
00158 h0->m_next = owner->null_halfedge_handle();
00159 h0->m_destination = owner->null_vertex_handle();
00160 h1->m_prev = owner->null_halfedge_handle();
00161 adjust_outgoing_halfedge_handle(v);
00162 return true;
00163 }
00164
00173 template<typename halfedge_iterator,typename vertex_iterator>
00174 bool link(halfedge_iterator h0,vertex_iterator v)
00175 {
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 if(!h0->get_destination_handle().is_null())
00195 {
00196 assert(!"link(h,v): Illegal topology, h allready had a destination!");
00197 return false;
00198 };
00199 halfedge_iterator h1 = h0->get_twin_iterator();
00200
00201 if(v->m_outgoing_halfedge.is_null())
00202 {
00203 v->m_outgoing_halfedge = h1->m_self;
00204 h0->m_destination = v->m_self;
00205 h0->m_next = h1->m_self;
00206 h1->m_prev = h0->m_self;
00207 return true;
00208 }
00209
00210 halfedge_iterator h0_next = v->get_outgoing_halfedge_iterator();
00211 if(!h0_next->get_face_handle().is_null())
00212 {
00213 assert(!"link(h,v): vertex v did not have an empty gap");
00214 return false;
00215 }
00216 halfedge_iterator h1_prev = h0_next->get_prev_iterator();
00217 if(!h1_prev->get_face_handle().is_null())
00218 {
00219 assert(!"link(h,v): vertex v did not have an empty gap");
00220 return false;
00221 }
00222
00223
00224 h0->m_next = h0_next->m_self;
00225 h0_next->m_prev = h0->m_self;
00226 h1_prev->m_next = h1->m_self;
00227 h1->m_prev = h1_prev->m_self;
00228 h0->m_destination = v->m_self;
00229
00230 adjust_outgong_edge(v);
00231
00232 return true;
00233 }
00234
00235 };
00236
00237 }
00238 }
00239
00240
00241 #endif