Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mi.H

Go to the documentation of this file.
00001 /**********************************************************************
00002  * mi.H
00003  *
00004  *      (mesh inline)
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  * Bsimplex:
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  * Bedge:
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  * Bvert:
00053  *****************************************************************/
00054 inline double 
00055 avg_strong_len(CBvert* v)
00056 {
00057    // average length of strong edges adjacent to v
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  * Bface:
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 //    Wvec e1 = a->loc() - v->loc();
00083 //    Wvec e2 = b->loc() - v->loc();
00084 //    
00085 //    return cross(e1, e2) * (1.0 /(e1.length_sqrd() * e2.length_sqrd()));
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 //    return f->norm() * f->angle(v);
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 // get an average normal, not crossing edges accepted by the given
00100 // filter:
00101 Wvec
00102 vert_normal(CBvert* v, CBface* f, CSimplexFilter& filter);
00103 
00104 // given a vertex v and a face f, step clockwise around v
00105 // from one face to the next as long as no edge we step
00106 // across is accepted by the given filter.
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 // return a list of faces, one face per sector in the
00127 // "star" around v, where sectors separated by edges
00128 //  accpted by the filter (or by border edges):
00129 Bface_list
00130 leading_faces(CBvert* v, CSimplexFilter& filter);
00131 
00132 // if the 3 verts form a Bface that is part of a quad,
00133 // return the face:
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 // if the 4 vertices make up a quad, this returns the quad
00142 // face that contains v1 (otherwise null):
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 // if the 4 vertices make up a quad, this returns the weak edge
00159 // of the quad (otherwise null):
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    // returns average length of strong edges in f
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  * Bvert_list:
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  * Bedge_list:
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    // returns true if there are no edges connected to any in
00204    // the given set (other than those in the set):
00205 
00206    Bvert_list verts = edges.get_verts();
00207    verts.clear_flag02();        // clear flags of all adjacent edges
00208    edges.set_flags(1);          // set flags = 1 for edges in set
00209 
00210    // No vertex can have an adjacent edge whose flag is 0:
00211    return verts.all_satisfy(VertDegreeFilter(0, SimplexFlagFilter(0)));
00212 }
00213 
00214 /*****************************************************************
00215  * from inflate.C
00216  *****************************************************************/
00217 #ifndef log2
00218 #ifndef macosx
00219 inline double
00220 log2(double x)
00221 {
00222    // return log base 2 of x
00223 
00224    // XXX - should remove (return NaN):
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 /* end of file mi.H */

Generated on Mon Sep 18 11:39:32 2006 for jot by  doxygen 1.4.4