/**************************************************************************** * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * * Copyright(C) 2004 \/)\/ * * 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 $ ****************************************************************************/ #ifndef __VCGLIB_FACEFUNCTORS #define __VCGLIB_FACEFUNCTORS // vcg headers #include #include #include #include #include namespace vcg { class FaceBarycenterFunctor { public: template inline void operator () (const FACETYPE & f, COORDTYPE & b) { b = COORDTYPE::Construct(f.Barycenter()); } }; class FaceBoxFunctor { public: template inline void operator () (const FACETYPE & f, BOXTYPE & b) { b.Set(Point3::Construct(f.P(0))); b.Add(Point3::Construct(f.P(1))); b.Add(Point3::Construct(f.P(2))); } }; class FacePointDistanceFunctor { public: template inline bool operator () (const FACETYPE & f, const COORDTYPE & p, typename COORDTYPE::ScalarType & minDist, COORDTYPE & q) { const Point3 fp = Point3::Construct(p); Point3 fq; typename FACETYPE::ScalarType md = (typename FACETYPE::ScalarType)(minDist); const bool ret = face::PointDistance(f, fp, md, fq); minDist = (typename COORDTYPE::ScalarType)(md); q = COORDTYPE::Construct(fq); return (ret); } }; template class FaceRayIntersectFunctor { public: template inline bool operator () (const FACETYPE & f, const COORDTYPE & rayOrigin, const COORDTYPE & rayDirection, typename COORDTYPE::ScalarType & t, COORDTYPE & q) { typedef typename COORDTYPE::ScalarType ScalarType; Line3 ln(rayOrigin, rayDirection); ScalarType a; ScalarType b; bool bret = Intersection(ln, f.P(0), f.P(1), f.P(2), a, b, t); if (BACKFACETEST) { if (!bret) { bret = Intersection(ln, f.P(0), f.P(2), f.P(1), a, b, t); } } if (bret) { q = rayOrigin + rayDirection * t; return (true); } return (false); } }; } // end namespace vcg #endif // #ifndef __VCGLIB_FACEFUNCTORS