shape_doc 0.1
|
00001 /***************************************************************************** 00002 * M a t h e m a g i x 00003 ***************************************************************************** 00004 * Edge 00005 * 2008-03-21 00006 * Julien Wintz & Bernard Mourrain 00007 ***************************************************************************** 00008 * Copyright (C) 2006 INRIA Sophia-Antipolis 00009 ***************************************************************************** 00010 * Comments : 00011 ****************************************************************************/ 00012 # ifndef shape_face_hpp 00013 # define shape_face_hpp 00014 //==================================================================== 00015 # include <realroot/Seq.hpp> 00016 # include <shape/shape.hpp> 00017 # include <shape/point.hpp> 00018 # include <shape/edge.hpp> 00019 00020 # define TMPL template<class C, class V, class POINT> 00021 # define TMPL1 template<class K> 00022 # define SELF face<C,V,POINT> 00023 # define Viewer viewer<axel,I> 00024 //==================================================================== 00025 namespace mmx { 00026 namespace shape { 00027 00028 TMPL struct face; 00029 00030 // TMPL1 struct with_face { 00031 // typedef face<K,typename with_point<K>::Point> Face;}; 00032 00033 // TMPL1 struct face_def 00034 // :public with_shape<K> 00035 // ,public with_point<K> 00036 // ,public with_edge<K> 00037 // ,public with_face<K> {}; 00038 00039 struct face_def {}; 00040 00041 TMPL1 struct use<face_def,K> { 00042 typedef face<typename use<scalar_def,K>::Scalar, default_env, 00043 typename use<point_def,K>::Point> Face; 00044 }; 00045 00046 template<> struct use<face_def> 00047 { 00048 // typedef typename use<point_def,K>::Point Point; 00049 typedef face<double, default_env, point<double> > Face; 00050 }; 00051 00052 template<class C, class V=default_env, class POINT= point<C,V> > 00053 class face : public use<shape_def,V>::Shape 00054 { 00055 public: 00056 typedef typename use<shape_def,V>::Shape Shape; 00057 typedef POINT Point; 00058 typedef edge<C,V,POINT> Edge; 00059 // typedef edge<typename use<scalar_def,K>::Scalar,POINT> Edge; 00060 typedef typename Seq<Point*>::const_iterator const_iterator; 00061 00062 face(void) : m_index(0) { }; 00063 face(Point * p1, Point * p2, Point * p3): Shape() { 00064 m_points<<p1; 00065 m_points<<p2; 00066 m_points<<p3; 00067 m_index=0; 00068 }; 00069 00070 const_iterator begin() const {return m_points.begin();} 00071 const_iterator end() const {return m_points.end();} 00072 00073 unsigned size() const {return m_points.size();} 00074 Seq<Point*>& points() {return m_points;} 00075 Point* points(int i) {return m_points[i];} 00076 Point* operator[](int i) {return m_points[i];} 00077 void insert (Point * p) { m_points<<p; } ; 00078 void push_vertex(Point * p) { m_points<<p; } ; 00079 00080 void set_index(const int & i) { m_index=i; } ; 00081 int get_index() { return m_index; } ; 00082 00083 bool is_ccw(); 00084 00086 void reverse() { m_points.reverse(); } ; 00087 00089 // void refine(Edge &a, Edge& b); 00090 00091 Point * not_on(Edge * a) 00092 { 00093 foreach( Point * p, m_points) 00094 if ( !equal( a->destination(), p ) && 00095 !equal( a->source() , p ) ) 00096 return p; 00097 std::cout<<" ! not_on(Edge) not found"<<std::endl; 00098 return NULL;}; 00099 00100 private: 00101 Seq<Point*> m_points; 00102 int m_index; 00103 00104 inline bool equal( Point * u, Point * v ) 00105 { return ( u->x() == v->x() && 00106 u->y() == v->y() ); } 00107 }; 00108 00109 00110 // // Splits exsisting edge a by inserting edge b 00111 // TMPL void 00112 // SELF::refine(Edge &a, Edge& b) 00113 // { 00114 // unsigned i= m_points.search( a.source() ); 00115 // //unsigned j= (i==m_points.size()-1 ? 0 : i+1 ); 00116 // unsigned j= m_points.search( a.destination() ); 00117 00118 // // std::cout<<" "<< a.source() << " -> " 00119 // // << a.destination() <<std::endl; 00120 // // std::cout<< a.source()->x() <<","<<a.source()->y() <<" --->" 00121 // // << a.destination()->x()<<","<<a.destination()->y() <<"\n"; 00122 // // std::cout<<" "<< b.source() << " -> " 00123 // // << b.destination() <<std::endl; 00124 // // std::cout<< b.source()->x() <<","<<b.source()->y() <<" --->" 00125 // // << b.destination()->x()<<","<<b.destination()->y() <<"\n"; 00126 // std::cout<<"inds="<<i<<" "<<j<<std::endl; 00127 00128 // if ( equal(b.source(),m_points[i]) && 00129 // !equal( b.destination(),m_points[j]) ) 00130 // // if ( b.source()==m_points[i] ) 00131 // // if ( b.destination()!=m_points[j] ) 00132 // { 00133 // insert_vertex( b.destination(), i); 00134 // return; 00135 // } 00136 // if ( equal(b.destination(),m_points[i]) && 00137 // !equal( b.source(),m_points[i]) ) 00138 // // if ( b.destination()==m_points[i] ) 00139 // // if ( b.source()!=m_points[i] ) 00140 // { 00141 // insert_vertex( b.source(), i); 00142 // return; 00143 // } 00144 // if ( equal(b.destination(),m_points[j]) && 00145 // !equal( b.source(),m_points[i]) ) 00146 // // if ( b.destination()==m_points[j] ) 00147 // // if ( b.source()!=m_points[i] ) 00148 // { 00149 // insert_vertex( b.source(), i); 00150 // return; 00151 // } 00152 // if ( equal(b.source(),m_points[j]) && 00153 // !equal( b.destination(),m_points[i]) ) 00154 // // if ( b.source()==m_points[j] ) 00155 // // if ( b.destination()!=m_points[i] ) 00156 // { 00157 // insert_vertex( b.destination(), i); 00158 00159 // return; 00160 // } 00161 // std::cout<<"not refined." <<std::endl; 00162 // // exit(0); 00163 // } 00164 00165 00166 00167 00168 // TMPL void 00169 // SELF::insert_vertex(Point*v, unsigned& k) 00170 // {// insert v at position k+1 00171 // Seq<Point*> t; 00172 00173 // if (k!=0) 00174 // std::cout<<"inserting vertex at position "<< k <<std::endl; 00175 00176 // for ( unsigned n=0;n<=k;n++ ) 00177 // t<< m_points[n]; 00178 // t<< v; 00179 // for ( unsigned n=k+1;n< m_points.size();n++ ) 00180 // t<< m_points[n]; 00181 00182 // m_points.clear(); 00183 // m_points=t; 00184 // } 00185 00186 TMPL bool 00187 SELF::is_ccw() 00188 { 00189 double z(0); 00190 int n=this->size(); 00191 00192 if (n < 3) 00193 return(0); 00194 n--; 00195 for (int i=0;i<n;i++) 00196 { 00197 z+= m_points[i ]->x() * m_points[i+1]->y() - 00198 m_points[i+1]->x() * m_points[i ]->y() ; 00199 } 00200 z+= m_points[n]->x() * m_points[0]->y() - 00201 m_points[0]->x() * m_points[n]->y() ; 00202 00203 return (z>0); 00204 } 00205 00206 //-------------------------------------------------------------------- 00207 template<class C,class V> struct viewer; struct axel; 00208 00209 template<class C, class V, class I, class POINT> Viewer& 00210 operator<<(Viewer& out, SELF* p) { 00211 using namespace shape; 00212 00213 out<<"<domain type=\"mesh\" name=\"face_" 00214 << p->get_index()<<"\"color=\"" 00215 << out.color.r <<" " 00216 << out.color.g <<" " 00217 << out.color.r <<"\">\n"; 00218 00219 out<<"<off>\n"; 00220 out<<p->size()<<" "<<1<<" "<<0<<"\n"; 00221 //foreach(Point* pt, *p) 00222 for (unsigned i=0;i<p->size();i++) 00223 { 00224 out<<(*p)[i]->x()<<" "<<(*p)[i]->y()<<" "<<(*p)[i]->z()<<"\n"; 00225 } 00226 out<<p->size(); 00227 for (unsigned i=0;i<p->size();i++) 00228 out<<" "<<i; 00229 out<<"\n</off>\n"; 00230 out<<"</domain>\n"; 00231 return out; 00232 } 00233 //-------------------------------------------------------------------- 00234 TMPL void 00235 face_refine(SELF* f0, SELF* f1, double s, int v) { 00236 00237 typedef typename SELF::Point Point; 00238 Seq<Point*> l1; 00239 for(unsigned j=0;j<3;j++) 00240 if ( ((*f1->points(j))[v]==s) ) 00241 for(unsigned i=0;i<3;i++) { 00242 if ( ((*f0->points(i))[v]==s) && 00243 (i+1<f0->size()) && 00244 ((*f0->points(i+1))[v]==s) ) { 00245 l1<<(f1->points(j)); 00246 } 00247 if ( (i==(f0->size()-1)) && 00248 ((*f0->points(i))[v]==s) && 00249 ((*f0->points(0))[v]==s) ){ 00250 l1<<(f1->points(j)); 00251 } 00252 } 00253 // std::cout<<"Add "<<l1.size()<<" point(s) to face of size "<<f0->size()<<std::endl; 00254 foreach(Point* p1,l1) f0->insert(p1); 00255 } 00256 00257 00258 00259 } ; // namespace shape 00260 } ; // namespace mmx 00261 //==================================================================== 00262 # undef TMPL 00263 # undef TMPL1 00264 # undef SELF 00265 # undef Viewer 00266 # endif // shape_face_hpp