Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __VCG_TRI_UPDATE_EDGES
00024 #define __VCG_TRI_UPDATE_EDGES
00025
00026 #include <vcg/space/plane3.h>
00027
00028 namespace vcg {
00029 namespace tri {
00030
00032
00034 template <class ComputeMeshType>
00035 class UpdateComponentEP
00036 {
00037
00038 public:
00039 typedef ComputeMeshType MeshType;
00040 typedef typename MeshType::VertexType VertexType;
00041 typedef typename MeshType::VertexPointer VertexPointer;
00042 typedef typename MeshType::VertexIterator VertexIterator;
00043 typedef typename MeshType::FaceType FaceType;
00044 typedef typename MeshType::FacePointer FacePointer;
00045 typedef typename MeshType::FaceIterator FaceIterator;
00046 typedef typename MeshType::FaceType::CoordType::ScalarType ScalarType;
00047
00048 static void ComputeEdgePlane(FaceType &f)
00049 {
00050 f.Flags() = f.Flags() & (~(FaceType::NORMX|FaceType::NORMY|FaceType::NORMZ));
00051
00052
00053 f.Edge(0) = f.V(1)->P(); f.Edge(0) -= f.V(0)->P();
00054 f.Edge(1) = f.V(2)->P(); f.Edge(1) -= f.V(1)->P();
00055 f.Edge(2) = f.V(0)->P(); f.Edge(2) -= f.V(2)->P();
00056
00057 f.Plane().SetDirection(f.Edge(0)^f.Edge(1));
00058 f.Plane().SetOffset(f.Plane().Direction().dot(f.V(0)->P()));
00059 f.Plane().Normalize();
00060
00061 ScalarType nx = math::Abs(f.Plane().Direction()[0]);
00062 ScalarType ny = math::Abs(f.Plane().Direction()[1]);
00063 ScalarType nz = math::Abs(f.Plane().Direction()[2]);
00064 ScalarType d;
00065 if(nx>ny && nx>nz) { f.Flags() |= FaceType::NORMX; d = 1/f.Plane().Direction()[0]; }
00066 else if(ny>nz) { f.Flags() |= FaceType::NORMY; d = 1/f.Plane().Direction()[1]; }
00067 else { f.Flags() |= FaceType::NORMZ; d = 1/f.Plane().Direction()[2]; }
00068
00069
00070 f.Edge(0)*=d;
00071 f.Edge(1)*=d;
00072 f.Edge(2)*=d;
00073 }
00074
00075 static void Set(ComputeMeshType &m)
00076 {
00077 if(!FaceType::HasEdgePlane()) throw vcg::MissingComponentException("PerFaceEdgePlane");
00078 for(FaceIterator f = m.face.begin(); f!=m.face.end(); ++f)
00079 if(!(*f).IsD())
00080 ComputeEdgePlane(*f);
00081 }
00082
00083 };
00084
00085 }
00086 }
00087
00088
00089 #endif