From 38a4636b51ca2838bdf1eecd5749e04ec5d6e175 Mon Sep 17 00:00:00 2001 From: dibenedetto Date: Mon, 29 Mar 2010 16:27:41 +0000 Subject: [PATCH] added generic functors to attribute seam. --- vcg/complex/trimesh/attribute_seam.h | 91 ++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/vcg/complex/trimesh/attribute_seam.h b/vcg/complex/trimesh/attribute_seam.h index e35c43a1..5804713f 100644 --- a/vcg/complex/trimesh/attribute_seam.h +++ b/vcg/complex/trimesh/attribute_seam.h @@ -60,6 +60,97 @@ class AttributeSeam typedef AttributeSeam ThisType; + enum ASMask + { + POSITION_PER_VERTEX = (1 << 0), + + NORMAL_PER_VERTEX = (1 << 1), + NORMAL_PER_WEDGE = (1 << 2), + NORMAL_PER_FACE = (1 << 3), + + COLOR_PER_VERTEX = (1 << 4), + COLOR_PER_WEDGE = (1 << 5), + COLOR_PER_FACE = (1 << 6), + + TEXCOORD_PER_VERTEX = (1 << 7), + TEXCOORD_PER_WEDGE = (1 << 8) + }; + + template + struct ASExtract + { + const unsigned int mask; + + ASExtract(unsigned int vmask = 0) : mask(vmask) + { + ; + } + + void operator () (const src_trimesh_t & sm, const typename src_trimesh_t::FaceType & f, int k, const dst_trimesh_t & dm, typename dst_trimesh_t::VertexType & v) const + { + (void)sm; + (void)dm; + + const unsigned int m = this->mask; + const typename src_trimesh_t::VertexType & u = *(f.cV(k)); + + if ((m & AttributeSeam::POSITION_PER_VERTEX) != 0) v.P() = f.cP (k); + + if ((m & AttributeSeam::NORMAL_PER_VERTEX) != 0) v.N() = u.cN ( ); + if ((m & AttributeSeam::NORMAL_PER_WEDGE) != 0) v.N() = f.cWN(k); + if ((m & AttributeSeam::NORMAL_PER_FACE) != 0) v.N() = f.cN ( ); + + if ((m & AttributeSeam::COLOR_PER_VERTEX) != 0) v.C() = u.cC ( ); + if ((m & AttributeSeam::COLOR_PER_WEDGE) != 0) v.C() = f.cWC(k); + if ((m & AttributeSeam::COLOR_PER_FACE) != 0) v.C() = f.cC ( ); + + if ((m & AttributeSeam::TEXCOORD_PER_VERTEX) != 0) v.T() = u.cT ( ); + if ((m & AttributeSeam::TEXCOORD_PER_WEDGE) != 0) v.T() = f.cWT(k); + } + }; + + template + struct ASCompare + { + const unsigned int mask; + + ASCompare(unsigned int vmask = 0) : mask(vmask) + { + ; + } + + bool operator () (const dst_trimesh_t & sm, const typename dst_trimesh_t::VertexType & u, const typename dst_trimesh_t::VertexType & v) const + { + (void)sm; + + const unsigned int m = this->mask; + + /* + if ((m & (AttributeSeam::POSITION_PER_VERTEX)) != 0) + { + if (u.cP() != v.cP()) return false; + } + */ + + if ((m & (AttributeSeam::NORMAL_PER_VERTEX | AttributeSeam::NORMAL_PER_WEDGE | AttributeSeam::NORMAL_PER_FACE)) != 0) + { + if (u.cN() != v.cN()) return false; + } + + if ((m & (AttributeSeam::COLOR_PER_VERTEX | AttributeSeam::COLOR_PER_WEDGE | AttributeSeam::COLOR_PER_FACE)) != 0) + { + if (u.cC() != v.cC()) return false; + } + + if ((m & (AttributeSeam::TEXCOORD_PER_VERTEX | AttributeSeam::TEXCOORD_PER_WEDGE)) != 0) + { + if (u.cT() != v.cT()) return false; + } + + return true; + } + }; + // in-place version template static inline bool SplitVertex(src_trimesh_t & src, extract_wedge_attribs_t v_extract, compare_vertex_attribs_t & v_compare)