00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 # ifndef shape_topology_surface_hpp_H
00014 # define shape_topology_surface_hpp_H
00015
00016 # include <shape/graphic.hpp>
00017 # include <shape/vertex.hpp>
00018 # include <shape/edge.hpp>
00019 # include <shape/face.hpp>
00020 # include <shape/kdtree.hpp>
00021 # include <shape/list.hpp>
00022 # include <shape/topology.hpp>
00023 # include <shape/bcell3d_factory.hpp>
00024 # include <algorithm>
00025
00026 # define TMPL template<class C,class V>
00027 # define TMPL1 template<class V>
00028 # define Viewer viewer<axel,V>
00029 # define SELF tpl3d<C,V>
00030
00031 namespace mmx {
00032 namespace shape {
00033
00034
00035 struct tpl3d_def {};
00036
00037 template<>
00038 struct use<tpl3d_def>
00039 :public use<topology_def>
00040 ,public use<surface_def>
00041 {
00042
00043 typedef graphic<double> Graphic;
00044
00045
00046
00047 template<class VIEWER, class TOPOLOGY>
00048 static VIEWER& print_as_graphic(VIEWER& out, const TOPOLOGY& tp) {
00049
00050 typedef typename TOPOLOGY::Point Point;
00051 typedef typename TOPOLOGY::Edge Edge;
00052 typedef typename TOPOLOGY::Face Face;
00053
00054 out<<"<mesh type=\"off\" color=\"255 10 0\">\n";
00055 out<< tp.nbv() <<" "<< tp.nbe() <<" "<< tp.nbf() <<"\n";
00056
00057 foreach(Point* p, tp.vertices()) {
00058 out <<" "<<p->x()<<" "<<p->y()<<" "<<p->z()<<"\n";
00059 }
00060 foreach(Edge* e, tp.edges()) {
00061 out <<e->source()->index()<<" "<<e->destination()->index()<<"\n";
00062 }
00063
00064 foreach(Face* f, tp.faces()) {
00065
00066 out<<f->size();
00067 foreach(Point* p, f->points())
00068 {
00069 out <<" "<<p->index();
00070 }
00071 out <<"\n";
00072 out<<"</mesh>\n";
00073 }
00074 out<<"</mesh>\n";
00075
00076 return out;
00077 }
00078 };
00079
00080 TMPL class bcell_list ;
00081 TMPL1 class surface ;
00082 template <class CELL> class node;
00083 template <class CELL> class kdtree;
00084
00085
00086 template<class C,class V=default_env>
00087 class tpl3d : public topology<C,V> {
00088 public:
00089 typedef topology<C,V> Topology;
00090 typedef REF_OF(V) Ref;
00091 typedef typename Topology::Point Point;
00092 typedef typename Topology::Edge Edge;
00093 typedef typename Topology::Face Face;
00094 typedef bcell<C,Ref> Cell;
00095
00096 typedef surface<Ref> Surface;
00097 typedef typename Cell::BoundingBox BoundingBox;
00098
00099 tpl3d();
00100 tpl3d(const BoundingBox & bx);
00101 ~tpl3d(void) ;
00102
00104 virtual void clear();
00105
00106 virtual void insert(Point*);
00107 virtual void insert_edge(Point*, Point*);
00108 virtual void insert(Edge *);
00109 virtual void insert(Face *);
00110
00111 void push_back_vertex(Point* p) {this->insert(p);}
00112 void push_back_edge(int b, int e) {this->insert_edge(this->vertex(b), this->vertex(e));}
00113
00114 virtual void insert_singular(Point*);
00115 virtual void insert_singular(BoundingBox*);
00116
00117 int nbv() const { return m_vertices.size(); }
00118 int nbe() const { return m_edges.size(); }
00119 int nbf() const { return m_faces.size(); }
00120
00121 inline Seq<Point *> vertices(void) const { return m_vertices ; }
00122 inline Seq<Edge *> edges(void) const { return m_edges ; }
00123 inline Seq<Face *> faces(void) const { return m_faces ; }
00124
00125 virtual Point* vertex(int i) { return m_vertices[i] ; }
00126 virtual Edge* edge (int i) { return m_edges[i] ; }
00127 virtual Face* face (int i) { return m_faces[i] ; }
00128
00129
00130 bool insert_regular (Cell * bcell);
00131
00132
00133
00134 Seq<Point *> m_vertices ;
00135 Seq<Edge *> m_edges ;
00136 Seq<Face *> m_faces ;
00137
00138 int m_nbv;
00139 };
00140
00141 TMPL SELF::tpl3d(void) : m_nbv(0) {
00142
00143 }
00144
00145 TMPL SELF::tpl3d(const BoundingBox & bx) : m_nbv(0), Topology(bx) {
00146 }
00147
00148 TMPL SELF::~tpl3d(void) {
00149 }
00150
00151
00152 TMPL bool
00153 SELF::insert_regular(Cell* cl) {
00154
00155 return cl->insert_regular(this);
00156
00157 }
00158
00159
00160 TMPL void
00161 SELF::insert(Point * p) {
00162
00163 if (p->index()<0) {
00164 p->set_index(m_nbv);
00165 m_vertices << p;
00166 m_nbv++;
00167 }
00168 }
00169
00170
00171 TMPL void
00172 SELF::insert_edge(Point * p1, Point * p2) {
00173 if (p1->index()<0) this->insert(p1);
00174 if (p2->index()<0) this->insert(p2);
00175 m_edges<< new Edge(p1,p2);
00176 }
00177
00178
00179 TMPL void
00180 SELF::insert(Edge* e) {
00181 m_edges<<e;
00182 }
00183
00184 TMPL void
00185 SELF::insert(Face * f) {
00186 m_faces<<f;
00187 }
00188
00189 TMPL void
00190 SELF::insert_singular(BoundingBox * ) {
00191 }
00192
00193 TMPL void
00194 SELF::insert_singular(Point * ) {
00195
00196 }
00197
00198 TMPL void
00199 SELF::clear() {
00200
00201 m_faces.resize( 0 );
00202 m_edges.resize( 0 );
00203 m_vertices.resize( 0 );
00204 }
00205
00206
00207 TMPL Viewer&
00208 operator<<(Viewer& out, const SELF& tp) {
00209 use<tpl3d_def,C,V>::print_as_graphic(out,tp);
00210 return out;
00211 }
00212 TMPL Viewer&
00213 operator<<(Viewer& out, SELF* tp) {
00214 use<tpl3d_def,C,V>::print_as_graphic(out,*tp);
00215 return out;
00216 }
00217
00218 TMPL graphic<C,V>*
00219 as_graphic(const SELF& tp) {
00220
00221 typedef graphic<C,V> Graphic;
00222 typedef typename SELF::Point Point;
00223 typedef typename SELF::Edge Edge;
00224 typedef typename SELF::Face Face;
00225
00226
00227
00228 Graphic* res = new Graphic (tp.nbv(), tp.nbe(), tp.nbf());
00229
00230 int c=0;
00231
00232 foreach(Point* p, tp.vertices()) {
00233 res->vertices[c] =p->x();
00234 res->vertices[c+1]=p->y();
00235 res->vertices[c+2]=p->z();
00236 c+=3;
00237 }
00238
00239 if( tp.nbe()>0){
00240
00241 int c=0;
00242 foreach(Edge* e, tp.edges()) {
00243 res->edges[c] = e->source()->index();
00244 res->edges[c+1] = e->destination()->index();
00245 c+=2;
00246 }
00247 }
00248
00249 if( tp.nbf()>0){
00250 int c=0;
00251 foreach(Face* f, tp.faces()) {
00252 res->faces[c] = f->points(0)->index();
00253 res->faces[c+1] = f->points(1)->index();
00254 res->faces[c+2] = f->points(2)->index();
00255 c+=3;
00256 }
00257 }
00258 return res;
00259
00260 }
00261
00262 } ;
00263 } ;
00264
00265 # undef TMPL
00266 # undef TMPL1
00267 # undef AlgebraicCurve
00268 # undef AlgebraicSurface
00269 # undef Cell
00270 # undef Cell3dAlgebraicCurve
00271 # undef Cell3dAlgebraicSurface
00272 # undef Cell3dParametricCurve
00273 # undef Cell3dList
00274 # undef Cell3dFactory
00275 # undef Shape
00276 # undef Viewer
00277 # undef Graphic
00278 # undef SELF
00279 # endif