00001
00002
00003
00004
00005
00006 #ifndef MI_H_HAS_BEEN_INCLUDED
00007 #define MI_H_HAS_BEEN_INCLUDED
00008
00009 #include "std/run_avg.H"
00010
00011 #include "mesh/bfilters.H"
00012 #include "mesh/lmesh.H"
00013
00014
00015
00016
00017 inline Wvec
00018 get_norm(CBsimplex* s, bool debug=false)
00019 {
00020 if (is_edge(s)) return ((Bedge*)s)->norm();
00021 if (is_vert(s)) return ((Bvert*)s)->norm();
00022 if (is_face(s)) return ((Bface*)s)->norm();
00023 return Wvec::null();
00024 }
00025
00026
00027
00028
00029 inline double
00030 avg_edge_len(Bface* f)
00031 {
00032 if (!f) return 0;
00033 return (f->e1()->length() + f->e2()->length() + f->e3()->length())/3;
00034 }
00035
00036 inline double
00037 avg_face_edge_len(CBedge* e)
00038 {
00039 if (!e) return 0;
00040 if (e->is_polyline())
00041 return e->length();
00042 RunningAvg<double> avg(0);
00043 Bface* f=0;
00044 if ((f = e->f1()))
00045 avg.add(f->is_quad() ? f->quad_avg_dim() : avg_edge_len(f));
00046 if ((f = e->f2()))
00047 avg.add(f->is_quad() ? f->quad_avg_dim() : avg_edge_len(f));
00048 return avg.val();
00049 }
00050
00051
00052
00053
00054 inline double
00055 avg_strong_len(CBvert* v)
00056 {
00057
00058
00059 if (!v)
00060 return 0;
00061
00062 RunningAvg<double> avg(0);
00063 Bedge* e=0;
00064 for (int i=0; i<v->degree(); i++)
00065 if ((e = v->e(i))->is_strong())
00066 avg.add(e->length());
00067 return avg.val();
00068 }
00069
00070
00071
00072
00073 inline Wvec
00074 weighted_vnorm(CBface* f, CBvert* v)
00075 {
00076 if (!f->contains(v))
00077 return Wvec(0.0, 0.0, 0.0);
00078
00079 Bvert* a = next_vert_ccw(f,v);
00080 Bvert* b = next_vert_ccw(f,a);
00081
00082
00083
00084
00085
00086
00087 return (f->norm()*fabs(f->area())*2.0)
00088 / ((a->loc() - v->loc()).length_sqrd()
00089 * (b->loc() - v->loc()).length_sqrd());
00090
00091 }
00092
00093 inline double
00094 norm_angle(CBedge* e)
00095 {
00096 return (e && e->nfaces() == 2) ? e->f1()->norm().angle(e->f2()->norm()) : 0;
00097 }
00098
00099
00100
00101 Wvec
00102 vert_normal(CBvert* v, CBface* f, CSimplexFilter& filter);
00103
00104
00105
00106
00107 inline Bface*
00108 rewind_cw(CBvert* v, CBface* start, CSimplexFilter& filter)
00109 {
00110 Bface* ret = (Bface*)start;
00111 if (!(start && v && start->contains(v)))
00112 return 0;
00113 if (v->degree(filter) == 0)
00114 return ret;
00115
00116 Bface* f = ret;
00117 Bedge* e = 0;
00118 while ((e = f->edge_from_vert(v)) &&
00119 (f = e->other_face(ret)) &&
00120 !filter.accept(e))
00121 ret = f;
00122
00123 return ret;
00124 }
00125
00126
00127
00128
00129 Bface_list
00130 leading_faces(CBvert* v, CSimplexFilter& filter);
00131
00132
00133
00134 inline Bface*
00135 lookup_quad(Bvert* v1, Bvert* v2, Bvert* v3)
00136 {
00137 Bface* f = lookup_face(v1, v2, v3);
00138 return (f && f->is_quad()) ? f : 0;
00139 }
00140
00141
00142
00143 inline Bface*
00144 lookup_quad(Bvert* v1, Bvert* v2, Bvert* v3, Bvert* v4)
00145 {
00146 if (!(v1 && v2 && v3 && v4))
00147 return 0;
00148 Bface* f = 0;
00149 if ((f = lookup_quad(v1, v2, v3)) && f->quad_vert() == v4)
00150 return f;
00151 if ((f = lookup_quad(v1, v2, v4)) && f->quad_vert() == v3)
00152 return f;
00153 if ((f = lookup_quad(v1, v3, v4)) && f->quad_vert() == v2)
00154 return f;
00155 return 0;
00156 }
00157
00158
00159
00160 inline Bedge*
00161 get_quad_weak_edge(Bvert* v1, Bvert* v2, Bvert* v3, Bvert* v4)
00162 {
00163 Bface* f = lookup_quad(v1, v2, v3, v4);
00164 return f ? f->weak_edge() : 0;
00165 }
00166
00167 inline double
00168 avg_strong_edge_len(CBface* f)
00169 {
00170
00171
00172 if (!f) return 0;
00173
00174 RunningAvg<double> avg(0);
00175 if (f->e1()->is_strong()) avg.add(f->e1()->length());
00176 if (f->e2()->is_strong()) avg.add(f->e2()->length());
00177 if (f->e3()->is_strong()) avg.add(f->e3()->length());
00178 return avg.val();
00179 }
00180
00181
00182
00183
00184 inline void
00185 set_adjacent_edges(CBvert_list& verts, uchar b)
00186 {
00187 for (int i=0; i<verts.num(); i++)
00188 verts[i]->get_adj().set_flags(b);
00189 }
00190
00191
00192
00193
00194 inline double
00195 avg_strong_edge_len(CBedge_list& edges)
00196 {
00197 return edges.filter(StrongEdgeFilter()).avg_len();
00198 }
00199
00200 inline bool
00201 is_maximal(CBedge_list& edges)
00202 {
00203
00204
00205
00206 Bvert_list verts = edges.get_verts();
00207 verts.clear_flag02();
00208 edges.set_flags(1);
00209
00210
00211 return verts.all_satisfy(VertDegreeFilter(0, SimplexFlagFilter(0)));
00212 }
00213
00214
00215
00216
00217 #ifndef log2
00218 #ifndef macosx
00219 inline double
00220 log2(double x)
00221 {
00222
00223
00224
00225 assert(x > 0);
00226
00227 return log(x) / M_LN2;
00228 }
00229 #endif // macosx
00230 #endif // log2
00231
00232 #endif // MI_H_HAS_BEEN_INCLUDED
00233
00234