1 /**************************************************************************** 2 * MeshLab o o * 3 * An extendible mesh processor o o * 4 * _ O _ * 5 * Copyright(C) 2005, 2009 \/)\/ * 6 * Visual Computing Lab /\/| * 7 * ISTI - Italian National Research Council | * 8 * \ * 9 * All rights reserved. * 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 * This program is distributed in the hope that it will be useful, * 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 20 * for more details. * 21 * * 22 ****************************************************************************/ 23 24 #ifndef SLICE_FUNCTORS 25 #define SLICE_FUNCTORS 26 #include <vcg/space/intersection3.h> 27 #include <vcg/math/matrix44.h> 28 29 30 using namespace vcg; 31 32 enum { VERTEX_LEFT, VERTEX_RIGHT, VERTEX_SLICE }; 33 34 template <class MESH_TYPE> 35 class SlicedEdge 36 { 37 public: SlicedEdge(const Plane3f & _p)38 SlicedEdge(const Plane3f &_p) 39 { 40 p=_p; 41 } operator()42 bool operator()(face::Pos<typename MESH_TYPE::FaceType> ep) 43 { 44 if (Distance(ep.V()->P(),p)<0) 45 ep.V()->Q()=VERTEX_LEFT; 46 else if (Distance(ep.V()->P(),p)>0) 47 ep.V()->Q()=VERTEX_RIGHT; 48 else 49 ep.V()->Q()=VERTEX_SLICE; 50 51 if (Distance(ep.VFlip()->P(),p)<0) 52 ep.VFlip()->Q()=VERTEX_LEFT; 53 else if (Distance(ep.VFlip()->P(),p)>0) 54 ep.VFlip()->Q()=VERTEX_RIGHT; 55 else 56 ep.VFlip()->Q()=VERTEX_SLICE; 57 58 return (ep.V()->Q() != ep.VFlip()->Q()) && (ep.V()->Q()!=VERTEX_SLICE) && (ep.VFlip()->Q()!=VERTEX_SLICE); 59 } 60 61 protected: 62 Plane3f p; 63 }; 64 65 66 template<class MESH_TYPE> 67 struct SlicingFunction : public std::unary_function<face::Pos<typename MESH_TYPE::FaceType> , typename MESH_TYPE::CoordType > 68 { 69 public : SlicingFunctionSlicingFunction70 SlicingFunction(const Plane3f& _p) 71 { 72 p=_p; 73 } 74 operatorSlicingFunction75 void operator()(typename MESH_TYPE::VertexType &nv, face::Pos<typename MESH_TYPE::FaceType> ep) 76 { 77 Segment3f seg(ep.V()->P(),ep.VFlip()->P()); 78 Point3f pp; 79 IntersectionPlaneSegment<typename MESH_TYPE::ScalarType>(p,seg,pp); 80 nv.P()=pp; 81 nv.Q()=VERTEX_SLICE; 82 } 83 84 // raw calculation for wedgeinterp WedgeInterpSlicingFunction85 Color4<typename MESH_TYPE::ScalarType> WedgeInterp(Color4<typename MESH_TYPE::ScalarType> &c0, Color4<typename MESH_TYPE::ScalarType> &c1) 86 { 87 Color4<CMeshO::ScalarType> cc; 88 return cc.lerp(c0,c1,0.5f); 89 } 90 91 template<class FL_TYPE> WedgeInterpSlicingFunction92 TexCoord2<FL_TYPE,1> WedgeInterp(TexCoord2<FL_TYPE,1> &t0, TexCoord2<FL_TYPE,1> &t1) 93 { 94 TexCoord2<FL_TYPE,1> tmp; 95 assert(t0.n()== t1.n()); 96 tmp.n()=t0.n(); 97 tmp.t()=(t0.t()+t1.t())/2.0; 98 return tmp; 99 } 100 protected: 101 Plane3f p; 102 }; 103 104 105 #endif 106