Added QualityMidPointFunctor and QualityEdgePredicate; Two classes (functor and the predicate) that you need for using the refine framework to cut a mesh along a linear interpolation of the quality. This can be used for example to slice a mesh with a plane.

This commit is contained in:
Paolo Cignoni 2011-06-02 21:31:30 +00:00
parent 27d9cfd6cb
commit 477767ab77
1 changed files with 45 additions and 34 deletions

View File

@ -722,34 +722,40 @@ face::Pos<typename MESH_TYPE::FaceType> he(ep.f,ep.z,ep.f->V(ep.z));
} }
}; };
/* /* The two following classes are the functor and the predicate that you need for using the refine framework to cut a mesh along a linear interpolation of the quality.
// Nuovi punti (e.g. midpoint) This can be used for example to slice a mesh with a plane. Just set the quality value as distance from plane and then functor and predicate
template<class MESH_TYPE> initialized 0 and invoke the refine
struct OddPointLoop : public std::unary_function<face::Pos<typename MESH_TYPE::FaceType> , typename MESH_TYPE::CoordType>
{
MyMesh A;
tri::UpdateQuality:MyMesh>::VertexFromPlane(plane);
QualityMidPointFunctor<MyMesh> slicingfunc(0.0);
QualityEdgePredicate<MyMesh> slicingpred(0.0);
tri::UpdateTopology<MyMesh>::FaceFace(A);
RefineE<MyMesh, QualityMidPointFunctor<MyMesh>, QualityEdgePredicate<MyMesh> > (A, slicingfunc, slicingpred, false);
} Note that they store in the vertex quality the plane distance.
*/
// vecchi punti
template<class MESH_TYPE>
struct EvenPointLoop : public std::unary_function<face::Pos<typename MESH_TYPE::FaceType> , typename MESH_TYPE::CoordType>
{
}
*/
template<class MESH_TYPE> template<class MESH_TYPE>
struct MidPointPlane : public std::unary_function<face::Pos<typename MESH_TYPE::FaceType> , typename MESH_TYPE::CoordType> class QualityMidPointFunctor : public std::unary_function<face::Pos<typename MESH_TYPE::FaceType> , typename MESH_TYPE::CoordType>
{ {
Plane3<typename MESH_TYPE::ScalarType> pl; public:
typedef Point3<typename MESH_TYPE::ScalarType> Point3x; typedef Point3<typename MESH_TYPE::ScalarType> Point3x;
typedef typename MESH_TYPE::ScalarType ScalarType;
ScalarType thr;
QualityMidPointFunctor(ScalarType _thr):thr(_thr){}
void operator()(typename MESH_TYPE::VertexType &nv, face::Pos<typename MESH_TYPE::FaceType> ep){ void operator()(typename MESH_TYPE::VertexType &nv, const face::Pos<typename MESH_TYPE::FaceType> &ep){
Point3x &p0=ep.f->V0(ep.z)->P(); Point3x p0=ep.f->V0(ep.z)->P();
Point3x &p1=ep.f->V1(ep.z)->P(); Point3x p1=ep.f->V1(ep.z)->P();
double pp= Distance(p0,pl)/(Distance(p0,pl) - Distance(p1,pl)); ScalarType q0=ep.f->V0(ep.z)->Q()-thr;
ScalarType q1=ep.f->V1(ep.z)->Q()-thr;
double pp= q0/(q0-q1);
nv.P()=p1*pp + p0*(1.0-pp); nv.P()=p1*pp + p0*(1.0-pp);
nv.Q()=thr;
} }
Color4<typename MESH_TYPE::ScalarType> WedgeInterp(Color4<typename MESH_TYPE::ScalarType> &c0, Color4<typename MESH_TYPE::ScalarType> &c1) Color4<typename MESH_TYPE::ScalarType> WedgeInterp(Color4<typename MESH_TYPE::ScalarType> &c0, Color4<typename MESH_TYPE::ScalarType> &c1)
@ -770,20 +776,25 @@ struct MidPointPlane : public std::unary_function<face::Pos<typename MESH_TYPE::
}; };
template <class FLT> template <class MESH_TYPE>
class EdgeSplPlane class QualityEdgePredicate
{ {
public: public:
Plane3<FLT> pl; typedef Point3<typename MESH_TYPE::ScalarType> Point3x;
bool operator()(const Point3<FLT> &p0, const Point3<FLT> &p1) const typedef typename MESH_TYPE::ScalarType ScalarType;
{ ScalarType thr;
if(Distance(pl,p0)>0) { QualityEdgePredicate(const ScalarType &thr):thr(thr) {}
if(Distance(pl,p1)>0) return false; bool operator()(face::Pos<typename MESH_TYPE::FaceType> ep)
else return true; {
} ScalarType q0=ep.f->V0(ep.z)->Q()-thr;
else if(Distance(pl,p1)<=0) return false; ScalarType q1=ep.f->V1(ep.z)->Q()-thr;
return true; if(q0>q1) swap(q0,q1);
} if ( q0*q1 > 0) return false;
// now a small check to be sure that we do not make too thin crossing.
double pp= q0/(q0-q1);
if(fabs(pp)< 0.001) return false;
return true;
}
}; };