Include header cleaning and reordering.

This commit is contained in:
Paolo Cignoni 2013-11-25 10:01:24 +00:00
parent d4eb599a66
commit 84c80a1972
8 changed files with 2080 additions and 2069 deletions

View File

@ -1,46 +1,64 @@
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004-2012 \/)\/ *
* 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. *
* *
****************************************************************************/
#ifndef VCG_TRI_ATTRIBUTE_SEAM_H #ifndef VCG_TRI_ATTRIBUTE_SEAM_H
#define VCG_TRI_ATTRIBUTE_SEAM_H #define VCG_TRI_ATTRIBUTE_SEAM_H
#include <vector>
#include <vcg/complex/allocate.h>
/* /*
// sample extract functor // sample extract functor
void v_extract(const src_mesh_t & wm, const src_face_t & f, int k, const dst_mesh_t & vm, dst_vertex_t & v) void v_extract(const src_mesh_t & wm, const src_face_t & f, int k, const dst_mesh_t & vm, dst_vertex_t & v)
{ {
(void)wm; (void)wm;
(void)vm; (void)vm;
v.P() = f.cP (k); v.P() = f.cP (k);
v.N() = f.cWN(k); v.N() = f.cWN(k);
v.C() = f.cWC(k); v.C() = f.cWC(k);
v.T() = f.cWT(k); v.T() = f.cWT(k);
} }
// sample compare functor // sample compare functor
bool v_compare(const dst_mesh_t & vm, const dst_vertex_t & u, const dst_vertex_t & v) bool v_compare(const dst_mesh_t & vm, const dst_vertex_t & u, const dst_vertex_t & v)
{ {
(void)vm; (void)vm;
return return
( (
(u.cN() == v.cN()) (u.cN() == v.cN())
&& (u.cC() == v.cC()) && (u.cC() == v.cC())
&& (u.cT() == v.cT()) && (u.cT() == v.cT())
); );
} }
// sample copy functor // sample copy functor
void v_copy(const dst_mesh_t & vm, const dst_vertex_t & u, dst_vertex_t & v) void v_copy(const dst_mesh_t & vm, const dst_vertex_t & u, dst_vertex_t & v)
{ {
(void)vm; (void)vm;
v.P() = u.cP(); v.P() = u.cP();
v.N() = u.cN(); v.N() = u.cN();
v.C() = u.cC(); v.C() = u.cC();
v.T() = u.cT(); v.T() = u.cT();
} }
// create seams // create seams
@ -56,310 +74,310 @@ namespace tri
class AttributeSeam class AttributeSeam
{ {
public: public:
typedef AttributeSeam ThisType; typedef AttributeSeam ThisType;
enum ASMask enum ASMask
{ {
POSITION_PER_VERTEX = (1 << 0), POSITION_PER_VERTEX = (1 << 0),
NORMAL_PER_VERTEX = (1 << 1), NORMAL_PER_VERTEX = (1 << 1),
NORMAL_PER_WEDGE = (1 << 2), NORMAL_PER_WEDGE = (1 << 2),
NORMAL_PER_FACE = (1 << 3), NORMAL_PER_FACE = (1 << 3),
COLOR_PER_VERTEX = (1 << 4), COLOR_PER_VERTEX = (1 << 4),
COLOR_PER_WEDGE = (1 << 5), COLOR_PER_WEDGE = (1 << 5),
COLOR_PER_FACE = (1 << 6), COLOR_PER_FACE = (1 << 6),
TEXCOORD_PER_VERTEX = (1 << 7), TEXCOORD_PER_VERTEX = (1 << 7),
TEXCOORD_PER_WEDGE = (1 << 8) TEXCOORD_PER_WEDGE = (1 << 8)
}; };
template <typename src_trimesh_t, typename dst_trimesh_t> template <typename src_trimesh_t, typename dst_trimesh_t>
struct ASExtract struct ASExtract
{ {
const unsigned int mask; const unsigned int mask;
ASExtract(unsigned int vmask = 0) : mask(vmask) 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 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)sm;
(void)dm; (void)dm;
const unsigned int m = this->mask; const unsigned int m = this->mask;
const typename src_trimesh_t::VertexType & u = *(f.cV(k)); 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::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_VERTEX) != 0) v.N() = u.cN ( );
if ((m & AttributeSeam::NORMAL_PER_WEDGE) != 0) v.N() = f.cWN(k); 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::NORMAL_PER_FACE) != 0) v.N() = f.cN ( );
if ((m & AttributeSeam::COLOR_PER_VERTEX) != 0) v.C() = u.cC ( ); 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_WEDGE) != 0) v.C() = f.cWC(k);
if ((m & AttributeSeam::COLOR_PER_FACE) != 0) v.C() = f.cC ( ); 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_VERTEX) != 0) v.T() = u.cT ( );
if ((m & AttributeSeam::TEXCOORD_PER_WEDGE) != 0) v.T() = f.cWT(k); if ((m & AttributeSeam::TEXCOORD_PER_WEDGE) != 0) v.T() = f.cWT(k);
} }
}; };
template <typename dst_trimesh_t> template <typename dst_trimesh_t>
struct ASCompare struct ASCompare
{ {
const unsigned int mask; const unsigned int mask;
ASCompare(unsigned int vmask = 0) : mask(vmask) 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 bool operator () (const dst_trimesh_t & sm, const typename dst_trimesh_t::VertexType & u, const typename dst_trimesh_t::VertexType & v) const
{ {
(void)sm; (void)sm;
const unsigned int m = this->mask; const unsigned int m = this->mask;
/* /*
if ((m & (AttributeSeam::POSITION_PER_VERTEX)) != 0) if ((m & (AttributeSeam::POSITION_PER_VERTEX)) != 0)
{ {
if (u.cP() != v.cP()) return false; if (u.cP() != v.cP()) return false;
} }
*/ */
if ((m & (AttributeSeam::NORMAL_PER_VERTEX | AttributeSeam::NORMAL_PER_WEDGE | AttributeSeam::NORMAL_PER_FACE)) != 0) if ((m & (AttributeSeam::NORMAL_PER_VERTEX | AttributeSeam::NORMAL_PER_WEDGE | AttributeSeam::NORMAL_PER_FACE)) != 0)
{ {
if (u.cN() != v.cN()) return false; if (u.cN() != v.cN()) return false;
} }
if ((m & (AttributeSeam::COLOR_PER_VERTEX | AttributeSeam::COLOR_PER_WEDGE | AttributeSeam::COLOR_PER_FACE)) != 0) if ((m & (AttributeSeam::COLOR_PER_VERTEX | AttributeSeam::COLOR_PER_WEDGE | AttributeSeam::COLOR_PER_FACE)) != 0)
{ {
if (u.cC() != v.cC()) return false; if (u.cC() != v.cC()) return false;
} }
if ((m & (AttributeSeam::TEXCOORD_PER_VERTEX | AttributeSeam::TEXCOORD_PER_WEDGE)) != 0) if ((m & (AttributeSeam::TEXCOORD_PER_VERTEX | AttributeSeam::TEXCOORD_PER_WEDGE)) != 0)
{ {
if (u.cT() != v.cT()) return false; if (u.cT() != v.cT()) return false;
} }
return true; return true;
} }
}; };
// in-place version // in-place version
template <typename src_trimesh_t, typename extract_wedge_attribs_t, typename compare_vertex_attribs_t> template <typename src_trimesh_t, typename extract_wedge_attribs_t, typename compare_vertex_attribs_t>
static inline bool SplitVertex(src_trimesh_t & src, extract_wedge_attribs_t v_extract, compare_vertex_attribs_t & v_compare) static inline bool SplitVertex(src_trimesh_t & src, extract_wedge_attribs_t v_extract, compare_vertex_attribs_t & v_compare)
{ {
typedef typename src_trimesh_t::VertexType src_vertex_t; typedef typename src_trimesh_t::VertexType src_vertex_t;
typedef typename src_trimesh_t::VertexIterator src_vertex_i; typedef typename src_trimesh_t::VertexIterator src_vertex_i;
typedef typename src_trimesh_t::FaceType src_face_t; typedef typename src_trimesh_t::FaceType src_face_t;
typedef typename src_trimesh_t::FaceIterator src_face_i; typedef typename src_trimesh_t::FaceIterator src_face_i;
typedef typename src_trimesh_t::VertContainer src_vertex_container_t; typedef typename src_trimesh_t::VertContainer src_vertex_container_t;
typedef vcg::tri::Allocator<src_trimesh_t> src_mesh_allocator_t; typedef vcg::tri::Allocator<src_trimesh_t> src_mesh_allocator_t;
typedef typename src_mesh_allocator_t :: template PointerUpdater<typename src_trimesh_t::VertexPointer> src_pointer_updater_t; typedef typename src_mesh_allocator_t :: template PointerUpdater<typename src_trimesh_t::VertexPointer> src_pointer_updater_t;
if ((src.vn <= 0) || (src.fn <= 0)) if ((src.vn <= 0) || (src.fn <= 0))
{ {
return true; return true;
} }
src_pointer_updater_t pt_upd; src_pointer_updater_t pt_upd;
src_vertex_i vi = src_mesh_allocator_t::AddVertices(src, 1, pt_upd); src_vertex_i vi = src_mesh_allocator_t::AddVertices(src, 1, pt_upd);
src_vertex_t * vtx = &(*vi); src_vertex_t * vtx = &(*vi);
src_vertex_t * vtxbase = &(src.vert[0]); src_vertex_t * vtxbase = &(src.vert[0]);
const size_t vertex_count = src.vert.size(); const size_t vertex_count = src.vert.size();
const size_t vertex_pool_size = vertex_count; const size_t vertex_pool_size = vertex_count;
std::vector<int> vloc; std::vector<int> vloc;
vloc.reserve(vertex_pool_size); vloc.reserve(vertex_pool_size);
vloc.resize(vertex_count, -2); vloc.resize(vertex_count, -2);
int vcount = int(src.vert.size()); int vcount = int(src.vert.size());
int idx = 0; int idx = 0;
for (src_face_i it=src.face.begin(); it!=src.face.end(); ++it) for (src_face_i it=src.face.begin(); it!=src.face.end(); ++it)
{ {
src_face_t & f = (*it); src_face_t & f = (*it);
if (f.IsD()) continue; if (f.IsD()) continue;
for (int k=0; k<3; ++k) for (int k=0; k<3; ++k)
{ {
idx = (f.cV(k) - vtxbase); idx = (f.cV(k) - vtxbase);
v_extract(src, f, k, src, *vtx); v_extract(src, f, k, src, *vtx);
if (vloc[idx] == -2) if (vloc[idx] == -2)
{ {
vloc[idx] = -1; vloc[idx] = -1;
src.vert[idx].ImportData(*vtx); src.vert[idx].ImportData(*vtx);
} }
else else
{ {
int vidx = idx; int vidx = idx;
do do
{ {
if (v_compare(src, src.vert[vidx], *vtx)) break; if (v_compare(src, src.vert[vidx], *vtx)) break;
vidx = vloc[vidx]; vidx = vloc[vidx];
} while (vidx >= 0); } while (vidx >= 0);
if (vidx < 0) if (vidx < 0)
{ {
vloc.push_back(vloc[idx]); vloc.push_back(vloc[idx]);
vloc[idx] = vcount; vloc[idx] = vcount;
vi = src_mesh_allocator_t::AddVertices(src, 1, pt_upd); vi = src_mesh_allocator_t::AddVertices(src, 1, pt_upd);
pt_upd.Update(vtx); pt_upd.Update(vtx);
pt_upd.Update(vtxbase); pt_upd.Update(vtxbase);
(*vi).ImportData(*vtx); (*vi).ImportData(*vtx);
idx = vcount; idx = vcount;
vcount++; vcount++;
} }
else else
{ {
idx = vidx; idx = vidx;
} }
} }
f.V(k) = &(src.vert[idx]); f.V(k) = &(src.vert[idx]);
} }
} }
src_mesh_allocator_t::DeleteVertex(src, *vtx); src_mesh_allocator_t::DeleteVertex(src, *vtx);
return true; return true;
} }
// out-of-place version // out-of-place version
template <typename src_trimesh_t, typename dst_trimesh_t, typename extract_wedge_attribs_t, typename compare_vertex_attribs_t, typename copy_vertex_t> template <typename src_trimesh_t, typename dst_trimesh_t, typename extract_wedge_attribs_t, typename compare_vertex_attribs_t, typename copy_vertex_t>
static inline bool SplitVertex(const src_trimesh_t & src, dst_trimesh_t & dst, extract_wedge_attribs_t & v_extract, compare_vertex_attribs_t & v_compare, copy_vertex_t & v_copy) static inline bool SplitVertex(const src_trimesh_t & src, dst_trimesh_t & dst, extract_wedge_attribs_t & v_extract, compare_vertex_attribs_t & v_compare, copy_vertex_t & v_copy)
{ {
typedef typename src_trimesh_t::VertexType src_vertex_t; typedef typename src_trimesh_t::VertexType src_vertex_t;
typedef typename src_trimesh_t::FaceType src_face_t; typedef typename src_trimesh_t::FaceType src_face_t;
typedef typename src_trimesh_t::ConstFaceIterator src_face_ci; typedef typename src_trimesh_t::ConstFaceIterator src_face_ci;
typedef typename dst_trimesh_t::VertContainer dst_vertex_container_t; typedef typename dst_trimesh_t::VertContainer dst_vertex_container_t;
typedef typename dst_trimesh_t::VertexType dst_vertex_t; typedef typename dst_trimesh_t::VertexType dst_vertex_t;
typedef typename dst_trimesh_t::VertexIterator dst_vertex_i; typedef typename dst_trimesh_t::VertexIterator dst_vertex_i;
typedef typename dst_trimesh_t::FaceType dst_face_t; typedef typename dst_trimesh_t::FaceType dst_face_t;
typedef typename dst_trimesh_t::FaceIterator dst_face_i; typedef typename dst_trimesh_t::FaceIterator dst_face_i;
typedef vcg::tri::Allocator<dst_trimesh_t> dst_mesh_allocator_t; typedef vcg::tri::Allocator<dst_trimesh_t> dst_mesh_allocator_t;
/* GCC gets in troubles and need some hints ("template") to parse the following line */ /* GCC gets in troubles and need some hints ("template") to parse the following line */
typedef typename dst_mesh_allocator_t :: template PointerUpdater<typename dst_trimesh_t::VertexPointer> dst_pointer_updater_t; typedef typename dst_mesh_allocator_t :: template PointerUpdater<typename dst_trimesh_t::VertexPointer> dst_pointer_updater_t;
if (reinterpret_cast<const void *>(&src) == reinterpret_cast<const void *>(&dst)) if (reinterpret_cast<const void *>(&src) == reinterpret_cast<const void *>(&dst))
{ {
return false; return false;
} }
dst.Clear(); dst.Clear();
if ((src.vn <= 0) || (src.fn <= 0)) if ((src.vn <= 0) || (src.fn <= 0))
{ {
return true; return true;
} }
const size_t vertex_count = src.vert.size(); const size_t vertex_count = src.vert.size();
const size_t vertex_pool_size = vertex_count; const size_t vertex_pool_size = vertex_count;
const src_vertex_t * vtxbase = &(src.vert[0]); const src_vertex_t * vtxbase = &(src.vert[0]);
std::vector<int> vloc; std::vector<int> vloc;
vloc.reserve(vertex_pool_size); vloc.reserve(vertex_pool_size);
vloc.resize(vertex_count, -2); vloc.resize(vertex_count, -2);
dst_vertex_i vv; dst_vertex_i vv;
dst_pointer_updater_t pt_upd; dst_pointer_updater_t pt_upd;
pt_upd.preventUpdateFlag = true; pt_upd.preventUpdateFlag = true;
dst_mesh_allocator_t::AddVertices(dst, 1 + int(vertex_count), pt_upd); dst_mesh_allocator_t::AddVertices(dst, 1 + int(vertex_count), pt_upd);
dst_vertex_t * vtx = &(dst.vert[0]); dst_vertex_t * vtx = &(dst.vert[0]);
dst_face_i fbase = dst_mesh_allocator_t::AddFaces(dst, src.fn); dst_face_i fbase = dst_mesh_allocator_t::AddFaces(dst, src.fn);
dst_face_i fi = fbase; dst_face_i fi = fbase;
int vcount = int(dst.vert.size()); int vcount = int(dst.vert.size());
int idx = 0; int idx = 0;
for (src_face_ci it=src.face.begin(); it!=src.face.end(); ++it) for (src_face_ci it=src.face.begin(); it!=src.face.end(); ++it)
{ {
const src_face_t & wf = (*it); const src_face_t & wf = (*it);
if (wf.IsD()) continue; if (wf.IsD()) continue;
dst_face_t & vf = (*fi); dst_face_t & vf = (*fi);
for (int k=0; k<3; ++k) for (int k=0; k<3; ++k)
{ {
idx = (wf.cV(k) - vtxbase); idx = (wf.cV(k) - vtxbase);
v_extract(src, wf, k, dst, *vtx); v_extract(src, wf, k, dst, *vtx);
if (vloc[idx] == -2) if (vloc[idx] == -2)
{ {
vloc[idx] = -1; vloc[idx] = -1;
v_copy(dst, *vtx, dst.vert[idx]); v_copy(dst, *vtx, dst.vert[idx]);
} }
else else
{ {
int vidx = idx; int vidx = idx;
do do
{ {
if (v_compare(dst, dst.vert[vidx], *vtx)) break; if (v_compare(dst, dst.vert[vidx], *vtx)) break;
vidx = vloc[vidx]; vidx = vloc[vidx];
} while (vidx >= 0); } while (vidx >= 0);
if (vidx < 0) if (vidx < 0)
{ {
vloc.push_back(vloc[idx]); vloc.push_back(vloc[idx]);
vloc[idx] = vcount; vloc[idx] = vcount;
vv = dst_mesh_allocator_t::AddVertices(dst, 1, pt_upd); vv = dst_mesh_allocator_t::AddVertices(dst, 1, pt_upd);
pt_upd.Update(vtx); pt_upd.Update(vtx);
v_copy(dst, *vtx, *vv); v_copy(dst, *vtx, *vv);
idx = vcount; idx = vcount;
vcount++; vcount++;
} }
else else
{ {
idx = vidx; idx = vidx;
} }
} }
vf.V(k) = reinterpret_cast<dst_vertex_t *>(idx); vf.V(k) = reinterpret_cast<dst_vertex_t *>(idx);
} }
fi++; fi++;
} }
{ {
std::vector<int> tmp; std::vector<int> tmp;
vloc.swap(tmp); vloc.swap(tmp);
} }
dst_vertex_t * vstart = &(dst.vert[0]); dst_vertex_t * vstart = &(dst.vert[0]);
for (dst_face_i it=fbase; it!=dst.face.end(); ++it) for (dst_face_i it=fbase; it!=dst.face.end(); ++it)
{ {
dst_face_t & vf = (*it); dst_face_t & vf = (*it);
vf.V(0) = vstart + reinterpret_cast<const int>(vf.V(0)); vf.V(0) = vstart + reinterpret_cast<const int>(vf.V(0));
vf.V(1) = vstart + reinterpret_cast<const int>(vf.V(1)); vf.V(1) = vstart + reinterpret_cast<const int>(vf.V(1));
vf.V(2) = vstart + reinterpret_cast<const int>(vf.V(2)); vf.V(2) = vstart + reinterpret_cast<const int>(vf.V(2));
} }
dst_mesh_allocator_t::DeleteVertex(dst, *vtx); dst_mesh_allocator_t::DeleteVertex(dst, *vtx);
return true; return true;
} }
}; };
} // end namespace tri } // end namespace tri

View File

@ -1,5 +1,4 @@
#include <vcg/complex/algorithms/bitquad_support.h> #include <vcg/complex/algorithms/bitquad_support.h>
#include <vcg/complex/allocate.h>
/** BIT-QUAD creation support: /** BIT-QUAD creation support:
a collection of methods that, a collection of methods that,
@ -347,11 +346,11 @@ static bool IsTriOnly(const MeshType &m){
/* returns true if mesh is a pure quad-mesh. */ /* returns true if mesh is a pure quad-mesh. */
static bool IsQuadOnly(const MeshType &m){ static bool IsQuadOnly(const MeshType &m){
for (ConstFaceIterator fi = m.face.begin(); fi!=m.face.end(); fi++) if (!fi->IsD()) { for (ConstFaceIterator fi = m.face.begin(); fi!=m.face.end(); fi++) if (!fi->IsD()) {
int count = 0; int count = 0;
if (fi->IsF(0)) count++; if (fi->IsF(0)) count++;
if (fi->IsF(1)) count++; if (fi->IsF(1)) count++;
if (fi->IsF(2)) count++; if (fi->IsF(2)) count++;
if (count!=1) return false; if (count!=1) return false;
} }
return true; return true;
} }
@ -359,11 +358,11 @@ static bool IsQuadOnly(const MeshType &m){
/* returns true if mesh has only tris and quads (no penta etc) */ /* returns true if mesh has only tris and quads (no penta etc) */
static bool IsTriQuadOnly(const MeshType &m){ static bool IsTriQuadOnly(const MeshType &m){
for (ConstFaceIterator fi = m.face.begin(); fi!=m.face.end(); fi++) if (!fi->IsD()) { for (ConstFaceIterator fi = m.face.begin(); fi!=m.face.end(); fi++) if (!fi->IsD()) {
int count = 0; int count = 0;
if (fi->IsF(0)) count++; if (fi->IsF(0)) count++;
if (fi->IsF(1)) count++; if (fi->IsF(1)) count++;
if (fi->IsF(2)) count++; if (fi->IsF(2)) count++;
if (count>1) return false; if (count>1) return false;
} }
return true; return true;
} }
@ -443,22 +442,22 @@ static void MakePureByRefine(MeshType &m){
assert(nvi!=m.vert.end()); assert(nvi!=m.vert.end());
VertexType *nv = &*nvi; nvi++; VertexType *nv = &*nvi; nvi++;
//*nv = *fi->V0( 0 ); // lazy: copy everything from the old vertex //*nv = *fi->V0( 0 ); // lazy: copy everything from the old vertex
nv->ImportData(*(fi->V0( 0 ))); // lazy: copy everything from the old vertex nv->ImportData(*(fi->V0( 0 ))); // lazy: copy everything from the old vertex
nv->P() = ( fi->V(0)->P() + fi->V(1)->P() + fi->V(2)->P() ) /3.0; nv->P() = ( fi->V(0)->P() + fi->V(1)->P() + fi->V(2)->P() ) /3.0;
FaceType *fa = &*fi; FaceType *fa = &*fi;
FaceType *fb = &*nfi; nfi++; FaceType *fb = &*nfi; nfi++;
FaceType *fc = &*nfi; nfi++; FaceType *fc = &*nfi; nfi++;
fb->ImportData(*fa); CopyTopology(fb,fa); fb->ImportData(*fa); CopyTopology(fb,fa);
fc->ImportData(*fa); CopyTopology(fc,fa); fc->ImportData(*fa); CopyTopology(fc,fa);
fa->V(0) = nv; fa->V(0) = nv;
fb->V(1) = nv; fb->V(1) = nv;
fc->V(2) = nv; fc->V(2) = nv;
fb->FFp(2)=fa->FFp(2); fb->FFi(2)=fa->FFi(2); fb->FFp(2)=fa->FFp(2); fb->FFi(2)=fa->FFi(2);
fc->FFp(0)=fa->FFp(0); fc->FFi(0)=fa->FFi(0); fc->FFp(0)=fa->FFp(0); fc->FFi(0)=fa->FFi(0);
assert( fa->FFp(1)->FFp(fa->FFi(1)) == fa ); assert( fa->FFp(1)->FFp(fa->FFi(1)) == fa );
/* */fb->FFp(2)->FFp(fb->FFi(2)) = fb; /* */fb->FFp(2)->FFp(fb->FFi(2)) = fb;
@ -517,7 +516,7 @@ static void MakePureByRefine(MeshType &m){
assert(nvi!=m.vert.end()); assert(nvi!=m.vert.end());
VertexType *nv = &*nvi; nvi++; VertexType *nv = &*nvi; nvi++;
// *nv = * fa->V0( ea2 ); // *nv = * fa->V0( ea2 );
nv->ImportData(*(fa->V0( ea2 ) )); // lazy: copy everything from the old vertex nv->ImportData(*(fa->V0( ea2 ) )); // lazy: copy everything from the old vertex
//nv->P() = ( fa->V(ea2)->P() + fa->V(ea0)->P() ) /2.0; //nv->P() = ( fa->V(ea2)->P() + fa->V(ea0)->P() ) /2.0;
Interpolator::Apply(*(fa->V(ea2)),*(fa->V(ea0)),0.5,*nv); Interpolator::Apply(*(fa->V(ea2)),*(fa->V(ea0)),0.5,*nv);
// split faces: add 2 faces (one per side) // split faces: add 2 faces (one per side)
@ -526,8 +525,8 @@ static void MakePureByRefine(MeshType &m){
assert(nfi!=m.face.end()); assert(nfi!=m.face.end());
FaceType *fd = &*nfi; nfi++; FaceType *fd = &*nfi; nfi++;
fc->ImportData(*fa ); CopyTopology(fc,fa); // lazy: copy everything from the old vertex fc->ImportData(*fa ); CopyTopology(fc,fa); // lazy: copy everything from the old vertex
fd->ImportData(*fb ); CopyTopology(fd,fb);// lazy: copy everything from the old vertex fd->ImportData(*fb ); CopyTopology(fd,fb);// lazy: copy everything from the old vertex
fa->V(ea2) = fc->V(ea0) = fa->V(ea2) = fc->V(ea0) =
fb->V(eb2) = fd->V(eb0) = nv ; fb->V(eb2) = fd->V(eb0) = nv ;
@ -621,13 +620,13 @@ static void MakePureByRefine(MeshType &m){
// create new vert in center of faux edge // create new vert in center of faux edge
VertexType *nv = &*nvi; nvi++; VertexType *nv = &*nvi; nvi++;
//*nv = * fa->V0( ea2 ); //*nv = * fa->V0( ea2 );
nv->ImportData(*(fa->V0( ea2 ) )); // lazy: copy everything from the old vertex nv->ImportData(*(fa->V0( ea2 ) )); // lazy: copy everything from the old vertex
nv->P() = ( fa->V(ea2)->P() + fa->V(ea0)->P() ) /2.0; nv->P() = ( fa->V(ea2)->P() + fa->V(ea0)->P() ) /2.0;
Interpolator::Apply(*(fa->V(ea2)),*(fa->V(ea0)),0.5,*nv); Interpolator::Apply(*(fa->V(ea2)),*(fa->V(ea0)),0.5,*nv);
// split face: add 1 face // split face: add 1 face
FaceType *fc = &*nfi; nfi++; FaceType *fc = &*nfi; nfi++;
fc->ImportData(*fa);CopyTopology(fc,fa); // lazy: copy everything from the old vertex fc->ImportData(*fa);CopyTopology(fc,fa); // lazy: copy everything from the old vertex
fa->V(ea2) = fc->V(ea0) = nv ; fa->V(ea2) = fc->V(ea0) = nv ;

View File

@ -1,7 +1,5 @@
#ifndef VCG_BITQUAD_SUPPORT #ifndef VCG_BITQUAD_SUPPORT
#define VCG_BITQUAD_SUPPORT #define VCG_BITQUAD_SUPPORT
#include <vector>
#include <set>
#include <vcg/simplex/face/jumping_pos.h> #include <vcg/simplex/face/jumping_pos.h>
#include <vcg/simplex/face/topology.h> #include <vcg/simplex/face/topology.h>
#include <vcg/space/planar_polygon_tessellation.h> #include <vcg/space/planar_polygon_tessellation.h>
@ -811,8 +809,8 @@ static bool CollapseDiag(FaceType &f, ScalarType interpol, MeshType& m, Pos* aff
pf = t; pf = t;
} while ((pf!=fb)); } while ((pf!=fb));
pi = fauxb; pi = fauxb;
pf = fb; pf = fb;
do { do {
pf->V(pi) = va; pf->V(pi) = va;

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@ class FrontEdge {
} }
bool operator==(const FrontEdge& f) const bool operator==(const FrontEdge& f) const
{ {
return ((v0 == f.v0) && (v1 == f.v1) && (v2 == f.v2) ); return ((v0 == f.v0) && (v1 == f.v1) && (v2 == f.v2) );
} }
}; };
template <class MESH> class AdvancingFront { template <class MESH> class AdvancingFront {
@ -79,18 +79,18 @@ template <class MESH> class AdvancingFront {
void BuildMesh(CallBackPos call = NULL, int interval = 512) void BuildMesh(CallBackPos call = NULL, int interval = 512)
{ {
float finalfacesext = mesh.vert.size() * 2.0f; float finalfacesext = mesh.vert.size() * 2.0f;
if(call) call(0, "Advancing front"); if(call) call(0, "Advancing front");
while(1) { while(1) {
for(int i = 0; i < interval; i++) { for(int i = 0; i < interval; i++) {
if(!front.size() && !SeedFace()) return; if(!front.size() && !SeedFace()) return;
AddFace(); AddFace();
if(call) if(call)
{ {
float rap = float(mesh.face.size()) / finalfacesext; float rap = float(mesh.face.size()) / finalfacesext;
int perc = (int) (100.0f * rap); int perc = (int) (100.0f * rap);
(*call)(perc,"Adding Faces"); (*call)(perc,"Adding Faces");
} }
} }
} }
} }
@ -191,8 +191,8 @@ public:
assert(nb[v0] < 10 && nb[v1] < 10); assert(nb[v0] < 10 && nb[v1] < 10);
ResultIterator touch; ResultIterator touch;
touch.first = FRONT; touch.first = FRONT;
touch.second = front.end(); touch.second = front.end();
int v2 = Place(current, touch); int v2 = Place(current, touch);
if(v2 == -1) { if(v2 == -1) {
@ -202,10 +202,10 @@ public:
assert(v2 != v0 && v2 != v1); assert(v2 != v0 && v2 != v1);
if ((touch.first == FRONT) && (touch.second != front.end()) || if ( ( (touch.first == FRONT) && (touch.second != front.end()) ) ||
(touch.first == DEADS) && (touch.second != deads.end())) ( (touch.first == DEADS) && (touch.second != deads.end()) ) )
{ {
//check for orientation and manifoldness //check for orientation and manifoldness
//touch == current.previous? //touch == current.previous?
@ -307,9 +307,9 @@ public:
} }
else if ((touch.first == FRONT) && (touch.second == front.end()) || else if (((touch.first == FRONT) && (touch.second == front.end())) ||
(touch.first == DEADS) && (touch.second == deads.end())) ((touch.first == DEADS) && (touch.second == deads.end())) )
{ {
// assert(CheckEdge(v0, v2)); // assert(CheckEdge(v0, v2));
// assert(CheckEdge(v2, v1)); // assert(CheckEdge(v2, v1));
/* adding a new vertex /* adding a new vertex
@ -425,15 +425,15 @@ protected:
void KillEdge(std::list<FrontEdge>::iterator e) void KillEdge(std::list<FrontEdge>::iterator e)
{ {
if (e->active) if (e->active)
{ {
(*e).active = false; (*e).active = false;
//std::list<FrontEdge>::iterator res = std::find(front.begin(),front.end(),e); //std::list<FrontEdge>::iterator res = std::find(front.begin(),front.end(),e);
FrontEdge tmp = *e; FrontEdge tmp = *e;
deads.splice(deads.end(), front, e); deads.splice(deads.end(), front, e);
std::list<FrontEdge>::iterator newe = std::find(deads.begin(),deads.end(),tmp); std::list<FrontEdge>::iterator newe = std::find(deads.begin(),deads.end(),tmp);
tmp.previous->next = newe; tmp.previous->next = newe;
tmp.next->previous = newe; tmp.next->previous = newe;
} }
} }
void Erase(std::list<FrontEdge>::iterator e) { void Erase(std::list<FrontEdge>::iterator e) {
@ -518,27 +518,27 @@ template <class MESH> class AdvancingTest: public AdvancingFront<MESH> {
int vn = this->mesh.vert.size(); int vn = this->mesh.vert.size();
for(int i = 0; i < this->mesh.vert.size(); i++) for(int i = 0; i < this->mesh.vert.size(); i++)
{ {
if((this->mesh.vert[i].P() - point).Norm() < 0.1) if((this->mesh.vert[i].P() - point).Norm() < 0.1)
{ {
vn = i; vn = i;
//find the border //find the border
assert(this->mesh.vert[i].IsB()); assert(this->mesh.vert[i].IsB());
for(std::list<FrontEdge>::iterator k = this->front.begin(); k != this->front.end(); k++) for(std::list<FrontEdge>::iterator k = this->front.begin(); k != this->front.end(); k++)
if((*k).v0 == i) if((*k).v0 == i)
{ {
touch.first = AdvancingFront<MESH>::FRONT; touch.first = AdvancingFront<MESH>::FRONT;
touch.second = k; touch.second = k;
} }
for(std::list<FrontEdge>::iterator k = this->deads.begin(); k != this->deads.end(); k++) for(std::list<FrontEdge>::iterator k = this->deads.begin(); k != this->deads.end(); k++)
if((*k).v0 == i) if((*k).v0 == i)
if((*k).v0 == i) if((*k).v0 == i)
{ {
touch.first = AdvancingFront<MESH>::FRONT; touch.first = AdvancingFront<MESH>::FRONT;
touch.second = k; touch.second = k;
} }
break; break;
} }
} }
if(vn == this->mesh.vert.size()) { if(vn == this->mesh.vert.size()) {

File diff suppressed because it is too large Load Diff

View File

@ -24,10 +24,6 @@
#ifndef __VCGLIB_APPEND #ifndef __VCGLIB_APPEND
#define __VCGLIB_APPEND #define __VCGLIB_APPEND
#include <vcg/complex/algorithms/update/flag.h>
#include <vcg/complex/algorithms/update/selection.h>
#include <set>
namespace vcg { namespace vcg {
namespace tri { namespace tri {
/** \ingroup trimesh */ /** \ingroup trimesh */
@ -68,7 +64,7 @@ public:
typedef typename ConstMeshRight::FacePointer FacePointerRight; typedef typename ConstMeshRight::FacePointer FacePointerRight;
struct Remap{ struct Remap{
std::vector<int> vert,face,edge, hedge; std::vector<int> vert,face,edge, hedge;
}; };
static void ImportVertexAdj(MeshLeft &ml, ConstMeshRight &mr, VertexLeft &vl, VertexRight &vr, Remap &remap ){ static void ImportVertexAdj(MeshLeft &ml, ConstMeshRight &mr, VertexLeft &vl, VertexRight &vr, Remap &remap ){
@ -316,60 +312,60 @@ static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false,
ImportHEdgeAdj(ml,mr,ml.hedge[remap.hedge[Index(mr,*hi)]],*hi,remap,selected); ImportHEdgeAdj(ml,mr,ml.hedge[remap.hedge[Index(mr,*hi)]],*hi,remap,selected);
} }
// phase 3. // phase 3.
// take care of other per mesh data: textures, attributes // take care of other per mesh data: textures, attributes
// At the end concatenate the vector with texture names. // At the end concatenate the vector with texture names.
ml.textures.insert(ml.textures.end(),mr.textures.begin(),mr.textures.end()); ml.textures.insert(ml.textures.end(),mr.textures.begin(),mr.textures.end());
// Attributes. Copy only those attributes that are present in both meshes // Attributes. Copy only those attributes that are present in both meshes
// Two attributes in different meshes are considered the same if they have the same // Two attributes in different meshes are considered the same if they have the same
// name and the same type. This may be deceiving because they could in fact have // name and the same type. This may be deceiving because they could in fact have
// different semantic, but this is up to the developer. // different semantic, but this is up to the developer.
// If the left mesh has attributes that are not in the right mesh, their values for the elements // If the left mesh has attributes that are not in the right mesh, their values for the elements
// of the right mesh will be uninitialized // of the right mesh will be uninitialized
unsigned int id_r; unsigned int id_r;
typename std::set< PointerToAttribute >::iterator al, ar; typename std::set< PointerToAttribute >::iterator al, ar;
// per vertex attributes // per vertex attributes
for(al = ml.vert_attr.begin(); al != ml.vert_attr.end(); ++al) for(al = ml.vert_attr.begin(); al != ml.vert_attr.end(); ++al)
if(!(*al)._name.empty()){ if(!(*al)._name.empty()){
ar = mr.vert_attr.find(*al); ar = mr.vert_attr.find(*al);
if(ar!= mr.vert_attr.end()){ if(ar!= mr.vert_attr.end()){
id_r = 0; id_r = 0;
for(vi=mr.vert.begin();vi!=mr.vert.end();++vi,++id_r) for(vi=mr.vert.begin();vi!=mr.vert.end();++vi,++id_r)
if( !(*vi).IsD() && (!selected || (*vi).IsS())) if( !(*vi).IsD() && (!selected || (*vi).IsS()))
memcpy((*al)._handle->At(remap.vert[Index(mr,*vi)]),(*ar)._handle->At(id_r), memcpy((*al)._handle->At(remap.vert[Index(mr,*vi)]),(*ar)._handle->At(id_r),
(*al)._handle->SizeOf()); (*al)._handle->SizeOf());
} }
} }
// per edge attributes // per edge attributes
for(al = ml.edge_attr.begin(); al != ml.edge_attr.end(); ++al) for(al = ml.edge_attr.begin(); al != ml.edge_attr.end(); ++al)
if(!(*al)._name.empty()){ if(!(*al)._name.empty()){
ar = mr.edge_attr.find(*al); ar = mr.edge_attr.find(*al);
if(ar!= mr.edge_attr.end()){ if(ar!= mr.edge_attr.end()){
id_r = 0; id_r = 0;
for(ei=mr.edge.begin();ei!=mr.edge.end();++ei,++id_r) for(ei=mr.edge.begin();ei!=mr.edge.end();++ei,++id_r)
if( !(*ei).IsD() && (!selected || (*ei).IsS())) if( !(*ei).IsD() && (!selected || (*ei).IsS()))
memcpy((*al)._handle->At(remap.edge[Index(mr,*ei)]),(*ar)._handle->At(id_r), memcpy((*al)._handle->At(remap.edge[Index(mr,*ei)]),(*ar)._handle->At(id_r),
(*al)._handle->SizeOf()); (*al)._handle->SizeOf());
} }
} }
// per face attributes // per face attributes
for(al = ml.face_attr.begin(); al != ml.face_attr.end(); ++al) for(al = ml.face_attr.begin(); al != ml.face_attr.end(); ++al)
if(!(*al)._name.empty()){ if(!(*al)._name.empty()){
ar = mr.face_attr.find(*al); ar = mr.face_attr.find(*al);
if(ar!= mr.face_attr.end()){ if(ar!= mr.face_attr.end()){
id_r = 0; id_r = 0;
for(fi=mr.face.begin();fi!=mr.face.end();++fi,++id_r) for(fi=mr.face.begin();fi!=mr.face.end();++fi,++id_r)
if( !(*fi).IsD() && (!selected || (*fi).IsS())) if( !(*fi).IsD() && (!selected || (*fi).IsS()))
memcpy((*al)._handle->At(remap.face[Index(mr,*fi)]),(*ar)._handle->At(id_r), memcpy((*al)._handle->At(remap.face[Index(mr,*fi)]),(*ar)._handle->At(id_r),
(*al)._handle->SizeOf()); (*al)._handle->SizeOf());
} }
} }
// per mesh attributes // per mesh attributes
// if both ml and mr have an attribute with the same name, no action is done // if both ml and mr have an attribute with the same name, no action is done

View File

@ -21,21 +21,30 @@
* * * *
****************************************************************************/ ****************************************************************************/
#ifndef __VCG_MESH #ifndef __VCG_MESH_H
#define __VCG_MESH_H
#define __VCG_MESH #define __VCG_MESH
#include <assert.h> #include <assert.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <set> #include <set>
#include <exception> #include <stack>
#include <algorithm>
#include <map>
#include <iostream>
#include <stdexcept>
#include <limits>
#include <set>
#include <vcg/complex/exception.h> #include <vcg/complex/exception.h>
#include <vcg/container/simple_temporary_data.h> #include <vcg/container/simple_temporary_data.h>
#include <vcg/complex/used_types.h> #include <vcg/complex/used_types.h>
#include <vcg/complex/base.h> #include <vcg/complex/base.h>
#include <vcg/complex/allocate.h> #include <vcg/complex/allocate.h>
#include <vcg/complex/algorithms/update/flag.h>
#include <vcg/complex/algorithms/update/selection.h>
#include <vcg/complex/append.h> #include <vcg/complex/append.h>
#undef __VCG_MESH
#endif #endif