shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/include/shape/subdivision_with_tpl3d.hpp
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * M a t h e m a g i x
00003  *****************************************************************************
00004  * TopologyCurve
00005  * 2008-05-16
00006  * Julien Wintz & Bernard Mourrain
00007  *****************************************************************************
00008  *               Copyright (C) 2006 INRIA Sophia-Antipolis
00009  *****************************************************************************
00010  * Comments :
00011  ****************************************************************************/
00012 # ifndef shape_subdivision_with_tpl3d_hpp
00013 # define shape_subdivision_with_tpl3d_hpp
00014 
00015 # include <shape/subdivision.hpp>
00016 # include <shape/tpl3d.hpp>
00017 
00018 # define TMPL  template<class C,class V, class SURFACE, class CELL>
00019 # define TMPL1 template<class K>
00020 # define SELF  subdivision<C, with_tpl3d<V>,SURFACE,CELL> 
00021 
00022 //====================================================================
00023 namespace mmx {
00024 namespace shape {
00025 
00026 TMPL1 struct with_tpl3d {};
00027 TMPL1 DECLARE_REF_OF(with_tpl3d<K>,REF_OF(K));
00028 
00029 template<class FF, class VV> struct use<FF,with_tpl3d<VV> >: public use<FF,VV> {};
00030 
00031 TMPL1 struct use<subdivision_def, with_tpl3d<K> >
00032   : public use<subdivision_def, K>
00033 {
00034 
00035   template<class Self, class CELL>  static bool 
00036   process_singular(Self* tpl3d, CELL* cl) {
00037 #if 0
00038     BoundingBox* bx=tpl3d;
00039     Point 
00040       *p0= new Point(bx->xmin(),bx->ymin(),bx->zmin()),
00041       *p1= new Point(bx->xmin(),bx->ymax(),bx->zmin()),
00042       *p2= new Point(bx->xmax(),bx->ymax(),bx->zmin()),
00043       *p3= new Point(bx->xmax(),bx->ymin(),bx->zmin());
00044     tpl3d->insert(p0);tpl3d->insert(p1); tpl3d->insert(new Edge(p0,p1));
00045     tpl3d->insert(p1);tpl3d->insert(p2); tpl3d->insert(new Edge(p1,p2));
00046     tpl3d->insert(p2);tpl3d->insert(p3); tpl3d->insert(new Edge(p2,p3));
00047     tpl3d->insert(p3);tpl3d->insert(p0); tpl3d->insert(new Edge(p3,p0));
00048     
00049     Point 
00050       *q0= new Point(bx->xmin(),bx->ymin(),bx->zmax()),
00051       *q1= new Point(bx->xmin(),bx->ymax(),bx->zmax()),
00052       *q2= new Point(bx->xmax(),bx->ymax(),bx->zmax()),
00053       *q3= new Point(bx->xmax(),bx->ymin(),bx->zmax());
00054     tpl3d->insert(q0);tpl3d->insert(q1); tpl3d->insert(new Edge(q0,q1));
00055     tpl3d->insert(q1);tpl3d->insert(q2); tpl3d->insert(new Edge(q1,q2));
00056     tpl3d->insert(q2);tpl3d->insert(q3); tpl3d->insert(new Edge(q2,q3));
00057     tpl3d->insert(q3);tpl3d->insert(q0); tpl3d->insert(new Edge(q3,q0));
00058     
00059     tpl3d->insert(p0);tpl3d->insert(q0);tpl3d->insert(new Edge(p0,q0));
00060     tpl3d->insert(p1);tpl3d->insert(q1);tpl3d->insert(new Edge(p1,q1));
00061     tpl3d->insert(p2);tpl3d->insert(q2);tpl3d->insert(new Edge(p2,q2));
00062     tpl3d->insert(p3);tpl3d->insert(q3);tpl3d->insert(new Edge(p3,q3));
00063 #endif
00064     return true; 
00065   }
00066 
00067   //--------------------------------------------------------------------
00068   template<class Self, class CELL>  static bool 
00069   process_regular(Self* tpl3d, CELL* cl) {
00070 
00071     //    std::cout<<"process regular"<<std::endl;
00072 
00073     // put in the leaves and will be treated at the end
00074     tpl3d->m_leaves <<cl;
00075 
00076     marching_cube::polygonise(*tpl3d,*cl);
00077     
00078     //  if(this->m_idx == 0) 
00079     //  marching_cube::polygonise(*tpl3d, *this); //NOT before topology_regular
00080     //    tpl3d->insert(F);
00081   
00082 #if 0
00083     process_singular(tpl3d,cl);
00084 #endif
00085 
00086     //foreach(Point* p, F->points()) tpl3d->insert(p);
00087     return true; 
00088   }
00089 };
00090 //--------------------------------------------------------------------
00091 TMPL1 struct adapt_tpl3d {};
00092 template<class FF, class VV> struct use<FF,adapt_tpl3d<VV> >: public use<FF,with_tpl3d<VV> > {
00093 
00094   template<class Self, class CELL>  static bool 
00095   process_regular(Self* tpl3d, CELL* cl) {
00096     typedef typename Self::Scalar C;
00097     typedef subdivision<C,with_tpl3d<VV>,typename Self::Cell,typename Self::Surface> Subdivision;
00098     return use<subdivision_def,with_tpl3d<VV> >::process_regular(dynamic_cast<Subdivision*>(tpl3d),cl);
00099   }
00100 
00101   template<class Self, class CELL>  static bool 
00102   process_singular(Self* tpl3d, CELL* cl) {
00103     typedef typename Self::Scalar C;
00104     typedef subdivision<C,with_tpl3d<VV>,typename Self::Cell,typename Self::Surface> Subdivision;
00105     return use<subdivision_def,with_tpl3d<VV> >::process_singular(dynamic_cast<Subdivision*>(tpl3d),cl);
00106   }
00107 
00108 };
00109 //--------------------------------------------------------------------  
00110 template<class C, class V, class SURFACE, class CELL>
00111 struct subdivision<C,with_tpl3d<V>,SURFACE,CELL>
00112   : public subdivision<C,adapt_tpl3d<V>,SURFACE,CELL> 
00113   , public tpl3d<C,V> {
00114 public:
00115 
00116   typedef subdivision<C,adapt_tpl3d<V>,SURFACE,CELL> Subdivision;
00117   typedef tpl3d<C,V>                    Topology3d;
00118   typedef topology<C,V>                 Topology;
00119 
00120   typedef SURFACE Surface;
00121   typedef typename Topology::Point      Point;  
00122   typedef typename Topology::Edge       Edge;
00123   typedef typename Topology::Face       Face;
00124 
00125   typedef CELL                          Cell;
00126   typedef typename Subdivision::Node    Node;
00127   typedef typename Cell::BoundingBox    BoundingBox;
00128 
00129   subdivision(double e1= 0.1, double e2=0.01);
00130 
00131   ~subdivision(void) ;
00132   
00133   void clear(void);
00134   //  void run(void);
00135 
00136   void set_precision (double e){ this->Subdivision::set_precision(e); }
00137   void set_smoothness(double e){ this->Subdivision::set_smoothness(e);}
00138 
00139 //   virtual bool process_regular(Cell* cl)  { 
00140 //     return use<subdivision_def,with_tpl3d<V> >::process_regular(this,cl);
00141 //   }
00142 
00143 //   virtual bool process_singular(Cell* cl) { 
00144 //     return use<subdivision_def,with_tpl3d<V> >::process_singular(this,cl);
00145 //   }
00146 };
00147 //--------------------------------------------------------------------
00148 TMPL SELF::subdivision(double e1, double e2): Subdivision(e1, e2) { 
00149 
00150 }
00151 
00152 //--------------------------------------------------------------------
00153 TMPL SELF::~subdivision(void) {
00154 
00155 }
00156 
00157 //--------------------------------------------------------------------
00158 TMPL void SELF::clear() {  
00159   this->Topology3d::clear();
00160 }
00161 //====================================================================
00162 } ; // namespace shape
00163 } ; // namespace mmx
00164 //====================================================================
00165 # undef TMPL1
00166 # undef TMPL
00167 # undef SELF 
00168 # endif