/**************************************************************************** * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * * Copyright(C) 2005 \/)\/ * * Visual Computing Lab /\/| * * ISTI - Italian National Research Council | * * \ * * All rights reserved. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * for more details. * * * ****************************************************************************/ /**************************************************************************** History $Log: not supported by cvs2svn $ Revision 1.2 2005/09/11 11:46:43 m_di_benedetto First Commit ****************************************************************************/ #ifndef __VCGLIB_AABBBINARYTREEUTILS #define __VCGLIB_AABBBINARYTREEUTILS // vcg headers #include #include /***************************************************************************************/ namespace vcg { /* Class AABBBinaryTreeUtils SAMPLE USAGE: NOTES: */ template class AABBBinaryTreeUtils { public: 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 Point3 ConvertP3(const Point3 & p) { return (ClassType::P3Converter::Convert(p)); } class Face { }; class EmptyClass { }; template class ObjIteratorPtrFunct { public: template inline T * operator () (T & t) { return (&t); } }; template class ObjIteratorPtrFunct { public: inline T * operator () (T * & t) { return (t); } }; static ObjIteratorPtrFunct IteratorPtrFunctor(void) { return (ObjIteratorPtrFunct()); } template class ObjBoxFunct { public: inline Box3 operator () (const OBJ & obj) { (void)obj; Box3 box; box.SetNull(); return (box); } }; template <> class ObjBoxFunct { public: 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) { 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()); } }; /***************************************************************************************/ } // end namespace vcg #endif // #ifndef __VCGLIB_AABBBINARYTREEUTILS