1 #ifndef __VCGTEST_VOLUME 2 #define __VCGTEST_VOLUME 3 4 #include "ImplicitSphere.h" 5 #include "SphereUnion.h" 6 #include "SphereDifference.h" 7 8 class Volume 9 { 10 public: Volume()11 Volume() 12 { 13 ImplicitSphere s1(vcg::Point3f(-5.0, 0.0, 0.0), 10.0); 14 ImplicitSphere s2(vcg::Point3f( 5.0, 5.0, 3.0), 7.0); 15 ImplicitSphere s3(vcg::Point3f( 1.0, 0.0, 10.0), 6.0); 16 SphereUnion sphere_union(s1, s2); 17 SphereDifference sphere_difference(sphere_union, s3); 18 _sphere_diff = sphere_difference; 19 } 20 V(const int pi,const int pj,const int pk)21 float V(const int pi, const int pj, const int pk) 22 { 23 return _sphere_diff.V(pi, pj, pk); 24 } 25 GetXIntercept(const vcg::Point3i & p1,const vcg::Point3i & p2,VertexPointer & v)26 void GetXIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v) 27 { 28 vcg::Point3f p, n; 29 float d; 30 if (_sphere_diff.DirectedDistance(p1, p2, p, n, d)) 31 { 32 v->P() = p; 33 v->N() = n; 34 } 35 else 36 { 37 float f1 = V(p1.X(), p1.Y(), p1.Z()); 38 float f2 = V(p2.X(), p2.Y(), p2.Z()); 39 float u = (float) f1/(f1-f2); 40 v->P().X() = (float) p1.X()*(1-u) + u*p2.X(); 41 v->P().Y() = (float) p1.Y(); 42 v->P().Z() = (float) p1.Z(); 43 44 } 45 } GetYIntercept(const vcg::Point3i & p1,const vcg::Point3i & p2,VertexPointer & v)46 void GetYIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v) 47 { 48 vcg::Point3f p, n; 49 float d; 50 if (_sphere_diff.DirectedDistance(p1, p2, p, n, d)) 51 { 52 v->P() = p; 53 v->N() = n; 54 } 55 else 56 { 57 float f1 = V(p1.X(), p1.Y(), p1.Z()); 58 float f2 = V(p2.X(), p2.Y(), p2.Z()); 59 float u = (float) f1/(f1-f2); 60 v->P().X() = (float) p1.X(); 61 v->P().Y() = (float) p1.Y()*(1-u) + u*p2.Y(); 62 v->P().Z() = (float) p1.Z(); 63 64 } 65 } GetZIntercept(const vcg::Point3i & p1,const vcg::Point3i & p2,VertexPointer & v)66 void GetZIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v) 67 { 68 vcg::Point3f p, n; 69 float d; 70 if (_sphere_diff.DirectedDistance(p1, p2, p, n, d)) 71 { 72 v->P() = p; 73 v->N() = n; 74 } 75 else 76 { 77 float f1 = V(p1.X(), p1.Y(), p1.Z()); 78 float f2 = V(p2.X(), p2.Y(), p2.Z()); 79 float u = (float) f1/(f1-f2); 80 v->P().X() = (float) p1.X(); 81 v->P().Y() = (float) p1.Y(); 82 v->P().Z() = (float) p1.Z()*(1-u) + u*p2.Z(); 83 84 } 85 } 86 87 private: 88 SphereDifference _sphere_diff; 89 }; 90 91 #endif // __VCGTEST_VOLUME