00001 /********************************************************************** 00002 * ledge_strip.C: 00003 **********************************************************************/ 00004 #include "mesh/ledge_strip.H" 00005 #include "mesh/lmesh.H" 00006 00007 int 00008 LedgeStrip::cur_level() const 00009 { 00010 LMESH* m = lmesh(); 00011 return m ? m->cur_level() : 0; 00012 } 00013 00014 int 00015 LedgeStrip::rel_cur_level() const 00016 { 00017 LMESH* m = lmesh(); 00018 return m ? m->rel_cur_level() : 0; 00019 } 00020 00021 bool 00022 LedgeStrip::need_rebuild() const 00023 { 00024 if (!_substrip) 00025 return false; 00026 return num()*2 != _substrip->num(); 00027 } 00028 00029 void 00030 LedgeStrip::draw(int level, StripCB* cb) 00031 { 00032 if (level < 0) 00033 return; 00034 else if (level == 0) 00035 EdgeStrip::draw(cb); // draw this one 00036 else { 00037 generate_substrip(); // draw the substrip (or lower) 00038 _substrip->draw(level-1, cb); 00039 } 00040 } 00041 00042 // Filter for checking which edges can be added to a substrip: 00043 class EdgeStripFilter : public SimplexFilter { 00044 public: 00045 virtual bool accept(CBsimplex* s) const { 00046 if (!is_edge(s)) 00047 return false; 00048 Bedge* e = (Bedge*)s; 00049 return (BMESH::show_secondary_faces() ? true : 00050 e->is_polyline() ? !e->is_multi() : 00051 e->is_primary()); 00052 } 00053 }; 00054 00055 void 00056 LedgeStrip::generate_substrip() 00057 { 00058 // if the substrip is out of date, delete it and rebuild it 00059 if (need_rebuild()) 00060 delete_substrip(); 00061 00062 // the convention is: if the substrip is allocated, 00063 // it's also filled in w/ data 00064 if (_substrip) 00065 return; // all set 00066 00067 // allocate it ... 00068 _substrip = new LedgeStrip; 00069 00070 // ... and fill it in 00071 EdgeStripFilter f; 00072 for (int i=0; i<_verts.num(); i++) { 00073 Bvert *first = ((Lvert*)_verts[i])->subdiv_vertex(); 00074 Bvert *middle = ((Ledge*)_edges[i])->subdiv_vertex(); 00075 Bvert *last = ((Lvert*)next_vert(i))->subdiv_vertex(); 00076 00077 Bedge* e = lookup_edge(first,middle); 00078 if (f.accept(e)) 00079 _substrip->add(first, e ); 00080 e = lookup_edge(middle, last); 00081 if (f.accept(e)) 00082 _substrip->add(middle, e); 00083 } 00084 } 00085 00086 void 00087 LedgeStrip::clear_subdivision(int level) 00088 { 00089 // Subdivision elements at the given level have been deleted. 00090 // The strip one level above should delete its substrip. 00091 // If level == 0 the strip is invalidated. 00092 00093 if (level <= 0) { 00094 delete_substrip(); 00095 reset(); 00096 } else if (level == 1) { 00097 delete_substrip(); 00098 } else if (_substrip) { 00099 _substrip->clear_subdivision(level - 1); 00100 } 00101 } 00102 00103 /* end of file ledge_strip.C */