00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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 class face;
00029
00030
00031
00032
00033
00034
00035
00036
00037
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
00049 typedef face<double, default_env, point<double> > Face;
00050 };
00051
00052 template<class C, class V=default_env, class POINT= point<C,3,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
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
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
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
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
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
00254 foreach(Point* p1,l1) f0->insert(p1);
00255 }
00256
00257
00258
00259 } ;
00260 } ;
00261
00262 # undef TMPL
00263 # undef TMPL1
00264 # undef SELF
00265 # undef VIEWER
00266 # endif // shape_face_hpp