shape_doc 0.1
|
00001 /***************************************************************************** 00002 * M a t h e m a g i x 00003 ***************************************************************************** 00004 * topology 00005 * 2008-05-16 00006 * Julien Wintz & Bernard Mourrain 00007 ***************************************************************************** 00008 * Copyright (C) 2006 INRIA Sophia-Antipolis 00009 ***************************************************************************** 00010 * Comments : 00011 ****************************************************************************/ 00012 00013 # ifndef TOPOLOGY_H 00014 # define TOPOLOGY_H 00015 #include <realroot/Seq.hpp> 00016 #include <shape/point_with_idx.hpp> 00017 #include <shape/face.hpp> 00018 #include <shape/edge.hpp> 00019 #include <shape/cell.hpp> 00020 #include <shape/bounding_box.hpp> 00021 00022 # define TMPL template<class C, class V> 00023 # define SHAPE geometric<V> 00024 # define SELF topology<C,V> 00025 00026 //==================================================================== 00027 namespace mmx { 00028 namespace shape { 00029 00030 TMPL struct topology; 00031 00032 //-------------------------------------------------------------------- 00033 struct topology_def {}; 00034 00035 template<>struct use<topology_def> 00036 :public use<vertex_def> 00037 { 00038 typedef use<scalar_def>::Scalar Scalar; 00039 typedef use<shape_def>::Shape Shape; 00040 00041 typedef with_idx<double> W; 00042 typedef vertex<Scalar> Point; 00043 typedef edge<Scalar,default_env,Point> Edge; 00044 typedef face<Scalar,default_env,Point> Face; 00045 00046 typedef use<cell_def>::BoundingBox BoundingBox; 00047 typedef use<cell_def>::Cell Cell; 00048 00049 typedef topology<Scalar,double> Topology; 00050 }; 00051 00052 00053 template<class C, class V=default_env> 00054 class topology : public SHAPE_OF(V) { 00055 00056 public: 00057 typedef typename SHAPE_OF(V) Shape; 00058 typedef with_idx<V> W; 00059 typedef vertex<C,V> Point; 00060 typedef edge<C,V, Point> Edge; 00061 typedef face<C,V, Point> Face; 00062 00063 typedef bounding_box<C,REF_OF(V)> BoundingBox; 00064 typedef cell<C,REF_OF(V)> Cell; 00065 00066 topology(){}; 00067 topology(const BoundingBox& bx); 00068 virtual ~topology(void) ; 00069 00070 //virtual void run(void) = 0 ; 00071 virtual void insert(Point*) = 0 ; 00072 virtual void insert(Edge *) = 0 ; 00073 virtual void insert(BoundingBox*,bool); 00074 virtual void insert_singular(Point*) = 0 ; 00075 00076 //virtual Point* vertices(int) = 0 ; 00077 00078 void set_precision (double); 00079 void set_smoothness(double); 00080 00081 void push_back(Shape * s) { m_objects.push_back(s); } 00082 void operator<<(Shape * s) { m_objects.push_back(s); } 00083 00084 unsigned count(void) { return m_objects.size(); } 00085 00086 public: 00087 00088 double m_maxprec ; 00089 double m_minprec ; 00090 00091 BoundingBox m_bbx; 00092 Seq<Shape*> m_objects; 00093 00094 }; 00095 00096 00097 TMPL SELF::topology(const typename SELF::BoundingBox& bx): m_maxprec(0.1), m_minprec(0.01), m_bbx(bx) 00098 { 00099 00100 } 00101 TMPL SELF::~topology(void) {} 00102 00103 TMPL void SELF::set_smoothness(double eps) { 00104 m_maxprec = eps; 00105 } 00106 00107 TMPL void SELF::set_precision(double eps) { 00108 m_minprec = eps; 00109 } 00110 00111 TMPL void SELF::insert(BoundingBox *bx, bool cross=false) { 00112 Point 00113 *p0= new Point(bx->xmin(),bx->ymin(),bx->zmin()), 00114 *p1= new Point(bx->xmin(),bx->ymax(),bx->zmin()), 00115 *p2= new Point(bx->xmax(),bx->ymax(),bx->zmin()), 00116 *p3= new Point(bx->xmax(),bx->ymin(),bx->zmin()); 00117 00118 this->insert(p0);this->insert(p1); this->insert(new Edge(p0,p1)); 00119 this->insert(p1);this->insert(p2); this->insert(new Edge(p1,p2)); 00120 this->insert(p2);this->insert(p3); this->insert(new Edge(p2,p3)); 00121 this->insert(p3);this->insert(p0); this->insert(new Edge(p3,p0)); 00122 00123 Point 00124 *q0= new Point(bx->xmin(),bx->ymin(),bx->zmax()), 00125 *q1= new Point(bx->xmin(),bx->ymax(),bx->zmax()), 00126 *q2= new Point(bx->xmax(),bx->ymax(),bx->zmax()), 00127 *q3= new Point(bx->xmax(),bx->ymin(),bx->zmax()); 00128 00129 this->insert(q0);this->insert(q1); this->insert(new Edge(q0,q1)); 00130 this->insert(q1);this->insert(q2); this->insert(new Edge(q1,q2)); 00131 this->insert(q2);this->insert(q3); this->insert(new Edge(q2,q3)); 00132 this->insert(q3);this->insert(q0); this->insert(new Edge(q3,q0)); 00133 00134 this->insert(p0);this->insert(q0);this->insert(new Edge(p0,q0)); 00135 this->insert(p1);this->insert(q1);this->insert(new Edge(p1,q1)); 00136 this->insert(p2);this->insert(q2);this->insert(new Edge(p2,q2)); 00137 this->insert(p3);this->insert(q3);this->insert(new Edge(p3,q3)); 00138 00139 if(cross) { 00140 Point 00141 *r0= new Point(bx->xmin(),bx->ymin(),bx->zmax()), 00142 *r1= new Point(bx->xmin(),bx->ymax(),bx->zmax()), 00143 *r2= new Point(bx->xmax(),bx->ymax(),bx->zmax()), 00144 *r3= new Point(bx->xmax(),bx->ymin(),bx->zmax()); 00145 00146 this->insert(r0);this->insert(r2);this->insert(new Edge(r0,r2)); 00147 this->insert(r1);this->insert(r3);this->insert(new Edge(r1,r3)); 00148 } 00149 } 00150 00151 } ; // namespace shape 00152 } ; // namespace mmx 00153 00154 # undef TMPL 00155 # undef Shape 00156 # undef SELF 00157 # endif