00001 #ifndef __VCGTEST_VOLUME 00002 #define __VCGTEST_VOLUME 00003 00004 #include "ImplicitSphere.h" 00005 #include "SphereUnion.h" 00006 #include "SphereDifference.h" 00007 00008 class Volume 00009 { 00010 public: 00011 Volume() 00012 { 00013 ImplicitSphere s1(vcg::Point3f(-5.0, 0.0, 0.0), 10.0); 00014 ImplicitSphere s2(vcg::Point3f( 5.0, 5.0, 3.0), 7.0); 00015 ImplicitSphere s3(vcg::Point3f( 1.0, 0.0, 10.0), 6.0); 00016 SphereUnion sphere_union(s1, s2); 00017 SphereDifference sphere_difference(sphere_union, s3); 00018 _sphere_diff = sphere_difference; 00019 } 00020 00021 float V(const int pi, const int pj, const int pk) 00022 { 00023 return _sphere_diff.V(pi, pj, pk); 00024 } 00025 00026 void GetXIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v) 00027 { 00028 vcg::Point3f p, n; 00029 float d; 00030 if (_sphere_diff.DirectedDistance(p1, p2, p, n, d)) 00031 { 00032 v->P() = p; 00033 v->N() = n; 00034 } 00035 else 00036 { 00037 float f1 = V(p1.X(), p1.Y(), p1.Z()); 00038 float f2 = V(p2.X(), p2.Y(), p2.Z()); 00039 float u = (float) f1/(f1-f2); 00040 v->P().X() = (float) p1.X()*(1-u) + u*p2.X(); 00041 v->P().Y() = (float) p1.Y(); 00042 v->P().Z() = (float) p1.Z(); 00043 00044 } 00045 } 00046 void GetYIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v) 00047 { 00048 vcg::Point3f p, n; 00049 float d; 00050 if (_sphere_diff.DirectedDistance(p1, p2, p, n, d)) 00051 { 00052 v->P() = p; 00053 v->N() = n; 00054 } 00055 else 00056 { 00057 float f1 = V(p1.X(), p1.Y(), p1.Z()); 00058 float f2 = V(p2.X(), p2.Y(), p2.Z()); 00059 float u = (float) f1/(f1-f2); 00060 v->P().X() = (float) p1.X(); 00061 v->P().Y() = (float) p1.Y()*(1-u) + u*p2.Y(); 00062 v->P().Z() = (float) p1.Z(); 00063 00064 } 00065 } 00066 void GetZIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v) 00067 { 00068 vcg::Point3f p, n; 00069 float d; 00070 if (_sphere_diff.DirectedDistance(p1, p2, p, n, d)) 00071 { 00072 v->P() = p; 00073 v->N() = n; 00074 } 00075 else 00076 { 00077 float f1 = V(p1.X(), p1.Y(), p1.Z()); 00078 float f2 = V(p2.X(), p2.Y(), p2.Z()); 00079 float u = (float) f1/(f1-f2); 00080 v->P().X() = (float) p1.X(); 00081 v->P().Y() = (float) p1.Y(); 00082 v->P().Z() = (float) p1.Z()*(1-u) + u*p2.Z(); 00083 00084 } 00085 } 00086 00087 private: 00088 SphereDifference _sphere_diff; 00089 }; 00090 00091 #endif // __VCGTEST_VOLUME