diff --git a/vcg/space/index/aabb_binary_tree_utils.h b/vcg/space/index/aabb_binary_tree_utils.h index 2e264a6c..575ebd8e 100644 --- a/vcg/space/index/aabb_binary_tree_utils.h +++ b/vcg/space/index/aabb_binary_tree_utils.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.2 2005/09/11 11:46:43 m_di_benedetto +First Commit + @@ -51,20 +54,44 @@ NOTES: */ -template +template class AABBBinaryTreeUtils { public: - typedef AABBBinaryTreeUtils ClassType; + typedef AABBBinaryTreeUtils ClassType; typedef SCALARTYPE ScalarType; + typedef OBJTYPE ObjType; + + protected: + template + class P3Converter { + public: + static Point3 Convert(const Point3 & p) { + return (Point3(T1(p[0]), T1(p[1]), T1(p[2]))); + } + }; + + template + class P3Converter { + public: + static Point3 Convert(const Point3 & p) { + return (p); + } + }; + + public: template - static inline Point3 ConvertP3(const Point3 & p) { - return (Point3(S(p[0]), S(p[1]), S(p[2]))); + static Point3 ConvertP3(const Point3 & p) { + return (ClassType::P3Converter::Convert(p)); } + class Face { + }; + class EmptyClass { }; + template class ObjIteratorPtrFunct { public: template @@ -72,57 +99,156 @@ class AABBBinaryTreeUtils { return (&t); } - template + }; + + template + class ObjIteratorPtrFunct { + public: inline T * operator () (T * & t) { return (t); } }; - template - class FaceBoxFunct { - public: - typedef FACETYPE FaceType; + static ObjIteratorPtrFunct IteratorPtrFunctor(void) { + return (ObjIteratorPtrFunct()); + } - inline Box3 operator () (const FaceType & f) { + template + class ObjBoxFunct { + public: + inline Box3 operator () (const OBJ & obj) { + (void)obj; Box3 box; box.SetNull(); - - box.Add(AABBBinaryTreeUtils::ConvertP3(f.P(0))); - box.Add(AABBBinaryTreeUtils::ConvertP3(f.P(1))); - box.Add(AABBBinaryTreeUtils::ConvertP3(f.P(2))); - return (box); } }; - template - class ObjBarycenterFunct { + template <> + class ObjBoxFunct { public: - typedef OBJTYPE ObjType; - - inline Point3 operator () (const ObjType & obj) { - return (AABBBinaryTreeUtils::ConvertP3(obj.Barycenter())); + template + inline Box3 operator () (const FACETYPE & f) { + Box3 box; + box.Set(ConvertP3(f.P(0))); + box.Add(ConvertP3(f.P(1))); + box.Add(ConvertP3(f.P(2))); + return (box); } }; + static ObjBoxFunct BoxFunctor(void) { + return (ObjBoxFunct()); + } + + template + class FaceBoxFunct { + public: + typedef FACETYPE FaceType; + inline Box3 operator () (const FaceType & f) { + Box3 box; + box.Set(ConvertP3(f.P(0))); + box.Add(ConvertP3(f.P(1))); + box.Add(ConvertP3(f.P(2))); + return (box); + } + }; + + template + static FaceBoxFunct FaceBoxFunctor(void) { + return (FaceBoxFunct()); + } + + template + class ObjBarycenterFunct { + public: + inline Point3 operator () (const OBJ & obj) { + (void)obj; + printf("GENERAL\n"); + Point3 bc(ScalarType(0), ScalarType(0), ScalarType(0)); + return (bc); + } + }; + + template <> + class ObjBarycenterFunct { + public: + template + inline Point3 operator () (const Face & f) { + printf("FACE\n"); + return (ConvertP3(f.Barycenter())); + } + }; + + static ObjBarycenterFunct BarycenterFunctor(void) { + return (ObjBarycenterFunct()); + } + + template + class FaceBarycenterFunct { + public: + typedef FACETYPE FaceType; + inline Point3 operator () (const FaceType & f) { + return (ConvertP3(f.Barycenter())); + } + }; + + template + static FaceBarycenterFunct FaceBarycenterFunctor(void) { + return (FaceBarycenterFunct()); + } + + template + class ObjPointDistanceFunct { + public: + inline bool operator () (const OBJ & obj, const Point3 & p, ScalarType & minDist, Point3 & res) { + (void)obj; + (void)p; + (void)minDist; + (void)res; + return (false); + } + }; + + template <> + class ObjPointDistanceFunct { + public: + template + inline bool operator () (const FACETYPE & f, const Point3 & p, ScalarType & minDist, Point3 & res) { + Point3 fp = ConvertP3(p); + FACETYPE::ScalarType md = FACETYPE::ScalarType(minDist); + Point3 fres; + const bool bret = face::PointDistance(f, p, md, fres); + minDist = ScalarType(md); + res = ConvertP3(fres); + return (bret); + } + }; + + static ObjPointDistanceFunct PointDistanceFunctor(void) { + return (ObjPointDistanceFunct()); + } + template class FacePointDistanceFunct { public: typedef FACETYPE FaceType; - inline bool operator () (const FaceType & f, const Point3 & p, ScalarType & minDist, Point3 & res) { - FaceType::ScalarType fdist; - const AFace::CoordType fp = ConvertP3(p); - FaceType::CoordType fres; - - const bool br = face::PointDistance(f, fp, fdist, fres); - minDist = (ScalarType)(fdist); - res = ConvertP3(fres); - - return (br); + Point3 fp = ConvertP3(p); + FaceType::ScalarType md = FaceType::ScalarType(minDist); + Point3 fres; + const bool bret = face::PointDistance(f, p, md, fres); + minDist = ScalarType(md); + res = ConvertP3(fres); + return (bret); } }; + template + static FacePointDistanceFunct FacePointDistanceFunctor(void) { + return (FacePointDistanceFunct()); + } + }; /***************************************************************************************/