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,3,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
00059 if (m_s[0]==0)
00060 return u-eps>(bx)(m_var[0],0);
00061 else
00062 return u+eps<(bx)(m_var[0],1);
00063 } else {
00064 if (m_s[0]==1)
00065 return u-eps>(bx)(m_var[0],0);
00066 else
00067 return u+eps<(bx)(m_var[0],1);
00068 }
00069 }
00070
00071 bool is_valid_scale (double u, double eps) const {
00072 if(m_var[0]==0)
00073 return u-eps>0;
00074 else
00075 return u+eps<1;
00076 }
00077
00078 bool is_valid (const Point& p, const BoundingBox & bx, double eps=0.000001) const {
00079
00080 if (m_s[0] ==0 && p[m_v[0]]<bx(m_v[0],0)-eps) return false;
00081 if (m_s[0] ==1 && p[m_v[0]]>bx(m_v[0],1)+eps) return false;
00082 return true;
00083 }
00084
00085
00086 int cvar(unsigned i) const { return m_v[i]; }
00087 int side(unsigned i) const { return m_s[i]; }
00088 int fvar(unsigned i) const { return m_var[i]; }
00089
00090 double lower(const BoundingBox & bx) const {
00091 return (bx)(m_var[0],0);
00092 }
00093 double upper(const BoundingBox & bx) const {
00094 return (bx)(m_var[0],1);
00095 }
00096
00097 public:
00098 Seq<int> m_v, m_s, m_var;
00099 };
00100
00101
00102
00103 }
00104 }
00105 # undef TMPL
00106 # undef SELF
00107 # endif //shape_box_face_hpp