shape_doc 0.1
|
00001 #ifndef shape_boxface_hpp 00002 #define shape_boxface_hpp 00003 00004 # include <realroot/Seq.hpp> 00005 # include <shape/vertex.hpp> 00006 # include <shape/bounding_box.hpp> 00007 # include <shape/point_with_idx.hpp> 00008 00009 # define TMPL template<class C, class V> 00010 # define SELF box_face<C,V> 00011 //==================================================================== 00012 namespace mmx { 00013 namespace shape { 00014 00015 TMPL 00016 struct box_face { 00017 typedef vertex<C,V> Point; 00018 typedef bounding_box<C,V> BoundingBox; 00019 box_face() { 00020 m_v<<2;m_s<<0;m_var<<0<<1; 00021 } 00022 box_face(int v1, int i1) { 00023 m_v<<v1; m_s<<i1; 00024 switch(v1) { 00025 case 0: 00026 m_var<<1<<2; 00027 case 1: 00028 m_var<<0<<2; 00029 default: 00030 m_var<<0<<1; 00031 } 00032 } 00033 00034 box_face(int v1, int i1, int v2, int i2) { 00035 m_v<<v1<<v2; 00036 m_s<<i1<<i2; 00037 m_var<<(3-v1-v2); 00038 } 00039 00040 Point* new_point(const BoundingBox & bx, double u) const { 00041 double pt[3]; 00042 pt[m_var[0]]= u; 00043 pt[m_v[0]] = (bx)(m_v[0],m_s[0]); 00044 pt[m_v[1]] = (bx)(m_v[1],m_s[1]); 00045 return new Point(pt[0],pt[1],pt[2]); 00046 } 00047 00048 Point* new_point(const BoundingBox & bx, double u, double v) const { 00049 double pt[3]; 00050 pt[m_var[0]]= bx(m_var[0],0)+ u*(bx(m_var[0],1)-bx(m_var[0],0)); 00051 pt[m_var[1]]= bx(m_var[1],0)+ v*(bx(m_var[1],1)-bx(m_var[1],0)); 00052 pt[m_v[0]] = (bx)(m_v[0],m_s[0]); 00053 return new Point(pt[0],pt[1],pt[2], m_v[0]); 00054 } 00055 00056 bool is_valid (const BoundingBox & bx, double u, double eps) const { 00057 if(m_var[0]==0) 00058 return u-eps>(bx)(m_var[0],0); 00059 else 00060 return u+eps<(bx)(m_var[0],1); 00061 } 00062 00063 bool is_valid_scale (double u, double eps) const { 00064 if(m_var[0]==0) 00065 return u-eps>0; 00066 else 00067 return u+eps<1; 00068 } 00069 00070 bool is_valid (const Point& p, const BoundingBox & bx, double eps=0.000001) const { 00071 00072 if (m_s[0] ==0 && p[m_v[0]]<bx(m_v[0],0)-eps) return false; 00073 if (m_s[0] ==1 && p[m_v[0]]>bx(m_v[0],1)+eps) return false; 00074 00075 return true; 00076 } 00077 00078 00079 int cvar(unsigned i) const { return m_v[i]; } 00080 int side(unsigned i) const { return m_s[i]; } 00081 int fvar(unsigned i) const { return m_var[i]; } 00082 00083 double lower(const BoundingBox & bx) const { 00084 return (bx)(m_var[0],0); 00085 } 00086 double upper(const BoundingBox & bx) const { 00087 return (bx)(m_var[0],1); 00088 } 00089 00090 public: 00091 Seq<int> m_v, m_s, m_var; 00092 }; 00093 00094 00095 00096 }//namespace shape 00097 }//namespace mmx; 00098 # undef TMPL 00099 # undef SELF 00100 # endif //shape_box_face_hpp