00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 # ifndef shape_mesher3d_shape_hpp
00012 # define shape_mesher3d_shape_hpp
00013
00014 # include <shape/list.hpp>
00015 # include <shape/subdivision_with_tpl3d.hpp>
00016 # include <shape/tpl3d.hpp>
00017 # include <algorithm>
00018
00019 # define TMPL template<class C,class V>
00020 # define TMPL1 template<class V>
00021 # define Viewer viewer<V>
00022 # define SELF mesher3d_shape<C,V>
00023
00024 namespace mmx {
00025 namespace shape {
00026
00027
00028 template<class C,class V=default_env>
00029 struct mesher3d_shape
00030 : public subdivision<C, with_tpl3d<V>,bcell3d<C,V> > {
00031
00032 typedef tpl3d<C,V> Topology;
00033 typedef subdivision<C, with_tpl3d<V>, bcell3d<C,V> > Subdivision;
00034 typedef use<subdivision_def,V> VRT;
00035
00036 typedef typename SHAPE_OF(V) Shape;
00037 typedef bcell3d_factory<C,V> Cell3dFactory;
00038
00039 typedef typename Topology::Point Point;
00040 typedef typename Topology::Edge Edge;
00041 typedef typename Topology::Face Face;
00042 typedef REF_OF(V) Ref;
00043 typedef bcell3d<C,Ref> Cell;
00044 typedef bcell3d<C,Ref> Cell3d;
00045 typedef surface<Ref> Surface;
00046 typedef typename Cell::BoundingBox BoundingBox;
00047
00048 typedef node<Cell *> Node;
00049 typedef kdtree<Cell *> Kdtree;
00050
00051
00052 mesher3d_shape(double e1= 0.1, double e2=0.01);
00053 mesher3d_shape(Shape* s, const BoundingBox& bx, double e1= 0.1, double e2=0.01);
00054
00055 ~mesher3d_shape(void) ;
00056
00057 void set_input(Cell* cl);
00058 void set_input(Shape* s, const BoundingBox& bx);
00059
00060 bool is_regular (Cell * bcell);
00061 bool insert_regular (Cell * bcell);
00062 bool sing_process(Cell * bcell);
00063 bool subdivide (Cell * bcell, Node * node) ;
00064
00065 void run(void);
00066 void clear(void);
00067 };
00068
00069 TMPL SELF::mesher3d_shape(double e1, double e2): Subdivision(e1, e2) {
00070 }
00071
00072 TMPL SELF::mesher3d_shape(Shape* s0, const BoundingBox& bx0, double e1, double e2)
00073 : Subdivision(e1, e2) {
00074 this->set_input(Cell3dFactory::instance()->create(s0,bx0));
00075 }
00076
00077 TMPL SELF::~mesher3d_shape(void) {
00078
00079 }
00080
00081 TMPL void SELF::set_input(Cell* cl)
00082 {
00083 this->set_input(cl);
00084 }
00085
00086 TMPL void SELF::set_input(Shape* s0, const BoundingBox& bx0)
00087 {
00088 this->set_input(Cell3dFactory::instance()->create(s0,bx0));
00089 }
00090
00091 TMPL bool
00092 SELF::is_regular(Cell* cl) {
00093 return cl->is_regular();
00094 }
00095
00096 TMPL bool
00097 SELF::insert_regular(Cell* cl) {
00098 this->output()->m_leaves <<cl;
00099 return cl->insert_regular(this);
00100
00101 }
00102
00103 TMPL bool
00104 SELF::sing_process(Cell* cl) {
00105 return cl->insert_singular(this) ;
00106 }
00107
00108 TMPL bool
00109 SELF::subdivide(Cell* cl, Node * node) {
00110 Cell * left, * right;
00111 int v = cl->subdivide(left, right) ;
00112 node->m_left = new Node(node, left, Node::LEFT , v) ; this->output()->m_nodes << node->m_left ;
00113 node->m_right= new Node(node, right, Node::RIGHT, v) ; this->output()->m_nodes << node->m_right;
00114 return true ;
00115 }
00116
00117 TMPL void SELF::run(void) {
00118
00119 double maxsz = this->get_smoothness()*this->output()->root()->get_cell()->size();
00120 double minsz = this->get_precision()*this->output()->root()->get_cell()->size();
00121
00122 std::cout<<maxsz<<" "<<minsz<<std::endl;
00123 while(!this->output()->m_nodes.empty()) {
00124 Node* node = this->output()->m_nodes.front() ;
00125 Cell* cl = node->get_cell() ;
00126
00127 if(cl->is_active()) {
00128 if(cl->size() > maxsz)
00129 {
00130 this->subdivide(cl, node) ;
00131 }
00132 else if(cl->is_regular())
00133 {
00134 this->insert_regular(cl) ;
00135 }
00136 else if(cl->size() > minsz )
00137 {
00138
00139 this->subdivide(cl, node) ;
00140 }
00141 else {
00142
00143
00144 }
00145 }
00146 this->output()->m_nodes.pop_front() ;
00147 }
00148
00149 foreach(Cell * cl, this->output()->m_leaves) {
00150 dynamic_cast<Cell3d*>(cl)->topology_regular(this);
00151
00152
00153 }
00154
00155 std::cout<< "leaves="<< this->output()->m_leaves.size()<<"\n";
00156
00157 }
00158
00159 TMPL void SELF::clear(void) {
00160
00161 }
00162
00163
00164
00165 TMPL Viewer&
00166 operator<<(Viewer& out, const SELF& tp) {
00167 use<tpl3d_def,V>::print_as_graphic(out,tp);
00168 return out;
00169 }
00170
00171 TMPL typename use<tpl3d_def,V>::Graphic*
00172 as_graphic(const SELF& tp) {
00173 return use<tpl3d_def,V>::as_graphic(tp);
00174 }
00175
00176 } ;
00177 } ;
00178
00179 # undef TMPL
00180 # undef TMPL1
00181 # undef Shape
00182 # undef Viewer
00183 # undef Graphic
00184 # undef SELF
00185 # endif