Heavy restructuring of the append function. Now it is hopefully must more efficient.

Added a parameter for requesting the copy of the non trivial topology. (e.g. all the adjacency relations beyond FV and EV).
This commit is contained in:
Paolo Cignoni 2012-04-04 10:11:46 +00:00
parent b0d7d5c52e
commit 5aed57a364
1 changed files with 127 additions and 129 deletions

View File

@ -66,7 +66,7 @@ public:
std::vector<int> vert,face,edge, hedge;
};
static void ImportVertexAdj(MeshLeft &ml, ConstMeshRight &mr, VertexLeft &vl, VertexRight &vr, Remap &remap, bool sel ){
static void ImportVertexAdj(MeshLeft &ml, ConstMeshRight &mr, VertexLeft &vl, VertexRight &vr, Remap &remap ){
// Vertex to Edge Adj
if(vcg::tri::HasVEAdjacency(ml) && vcg::tri::HasVEAdjacency(mr) && vr.cVEp() != 0){
size_t i = Index(mr,vr.cVEp());
@ -74,11 +74,8 @@ public:
vl.VEi() = vr.VEi();
}
if(!sel){
// Vertex to Face Adj
if(vcg::tri::HasPerVertexVFAdjacency(ml) && vcg::tri::HasPerVertexVFAdjacency(mr) &&
vcg::tri::HasPerFaceVFAdjacency(ml) && vcg::tri::HasPerFaceVFAdjacency(mr) && vr.cVFp() != 0
){
if(vcg::tri::HasPerVertexVFAdjacency(ml) && vcg::tri::HasPerVertexVFAdjacency(mr) && vr.cVFp() != 0 ){
size_t i = Index(mr,vr.cVFp());
vl.VFp() = (i>ml.face.size())? 0 :&ml.face[remap.face[i]];
vl.VFi() = vr.VFi();
@ -90,18 +87,9 @@ public:
vl.VHi() = vr.VHi();
}
}
}
static void ImportEdgeAdj(MeshLeft &ml, ConstMeshRight &mr, EdgeLeft &el, const EdgeRight &er, Remap &remap, bool sel )
static void ImportEdgeAdj(MeshLeft &ml, ConstMeshRight &mr, EdgeLeft &el, const EdgeRight &er, Remap &remap)
{
// Edge to Vertex Adj
if(vcg::tri::HasEVAdjacency(ml) && vcg::tri::HasEVAdjacency(mr)){
el.V(0) = &ml.vert[remap.vert[Index(mr,er.cV(0))]];
el.V(1) = &ml.vert[remap.vert[Index(mr,er.cV(1))]];
}
if(!sel){
// Edge to Edge Adj
if(vcg::tri::HasEEAdjacency(ml) && vcg::tri::HasEEAdjacency(mr))
for(unsigned int vi = 0; vi < 2; ++vi)
@ -122,19 +110,10 @@ public:
if(vcg::tri::HasEHAdjacency(ml) && vcg::tri::HasEHAdjacency(mr))
el.EHp() = &ml.hedge[remap.hedge[Index(mr,er.cEHp())]];
}
}
static void ImportFaceAdj(MeshLeft &ml, ConstMeshRight &mr, FaceLeft &fl, const FaceRight &fr, Remap &remap, bool sel )
static void ImportFaceAdj(MeshLeft &ml, ConstMeshRight &mr, FaceLeft &fl, const FaceRight &fr, Remap &remap )
{
// Face to Vertex Adj
if(vcg::tri::HasFVAdjacency(ml) && vcg::tri::HasFVAdjacency(mr)){
assert(fl.VN() == fr.VN());
for( int i = 0; i < fl.VN(); ++i )
fl.V(i) = &ml.vert[remap.vert[Index(mr,fr.V(i))]];
}
if(!sel){
// Face to Edge Adj
if(vcg::tri::HasFEAdjacency(ml) && vcg::tri::HasFEAdjacency(mr)){
assert(fl.VN() == fr.VN());
@ -158,7 +137,6 @@ public:
if(vcg::tri::HasFHAdjacency(ml) && vcg::tri::HasFHAdjacency(mr))
fl.FHp() = &ml.hedge[remap.hedge[Index(mr,fr.cFHp())]];
}
}
static void ImportHEdgeAdj(MeshLeft &ml, ConstMeshRight &mr, HEdgeLeft &hl, const HEdgeRight &hr, Remap &remap, bool /*sel*/ ){
// HEdge to Vertex Adj
@ -195,14 +173,15 @@ public:
// Append::Mesh(ml, mr) is equivalent to ml += mr.
// Note MeshRigth could be costant...
static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false){
static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false, const bool adjFlag = false)
{
// Note that if the the selection of the vertexes is not consistent with the face selection
// the append could build faces referencing non existent vertices
// so it is mandatory that the selection of the vertices reflects the loose selection
// from edges and faces (e.g. if a face is selected all its vertices must be selected).
if(selected)
{
assert(adjFlag == false); // It is rather meaningless to partially copy adj relations.
tri::UpdateSelection<ConstMeshRight>::VertexFromEdgeLoose(mr,true);
tri::UpdateSelection<ConstMeshRight>::VertexFromFaceLoose(mr,true);
}
@ -215,41 +194,46 @@ static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false){
// vertex
remap.vert.resize(mr.vert.size(),-1);
VertexIteratorRight vi;
VertexIteratorLeft vp;
int svn = UpdateSelection<ConstMeshRight>::VertexCount(mr);
if(selected) vp=Allocator<MeshLeft>::AddVertices(ml,svn);
else vp=Allocator<MeshLeft>::AddVertices(ml,mr.vn);
for(vi=mr.vert.begin();vi!=mr.vert.end();++vi)
if(!(*vi).IsD() && (!selected || (*vi).IsS())){
int ind=Index(mr,*vi);
assert(remap.vert[ind]==-1);
VertexIteratorLeft vp;
vp=Allocator<MeshLeft>::AddVertices(ml,1);
(*vp).ImportData(*(vi));
remap.vert[ind]=Index(ml,*vp);
++vp;
}
// edge
remap.edge.resize(mr.edge.size(),-1);
EdgeIteratorRight ei;
EdgeIteratorLeft ep;
int sen = UpdateSelection<ConstMeshRight>::EdgeCount(mr);
if(selected) ep=Allocator<MeshLeft>::AddEdges(ml,sen);
else ep=Allocator<MeshLeft>::AddEdges(ml,mr.en);
for(ei=mr.edge.begin(); ei!=mr.edge.end();++ei)
if(!(*ei).IsD() && (!selected || (*ei).IsS())){
int ind=Index(mr,*ei);
assert(remap.edge[ind]==-1);
EdgeIteratorLeft ep;
ep=Allocator<MeshLeft>::AddEdges(ml,1);
(*ep).ImportData(*(ei));
remap.edge[ind]=Index(ml,*ep);
++ep;
}
// face
vcg::tri::Allocator<ConstMeshRight>::CompactFaceVector(mr);
remap.face.resize(mr.face.size(),-1);
FaceIteratorRight fi;
FaceIteratorLeft fp;
int sfn = UpdateSelection<ConstMeshRight>::FaceCount(mr);
if(selected) fp=Allocator<MeshLeft>::AddFaces(ml,sfn);
else fp=Allocator<MeshLeft>::AddFaces(ml,mr.fn);
for(fi=mr.face.begin();fi!=mr.face.end();++fi)
if(!(*fi).IsD() && (!selected || (*fi).IsS())){
int ind=Index(mr,*fi);
assert(remap.face[ind]==-1);
FaceIteratorLeft fp;
fp=Allocator<MeshLeft>::AddFaces(ml,1);
(*fp).ImportData(*(fi));
remap.face[ind]=Index(ml,*fp);
++fp;
}
// hedge
@ -272,25 +256,39 @@ static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false){
for(vi=mr.vert.begin();vi!=mr.vert.end();++vi)
if( !(*vi).IsD() && (!selected || (*vi).IsS())){
ml.vert[remap.vert[Index(mr,*vi)]].ImportData(*vi);
ImportVertexAdj(ml,mr,ml.vert[remap.vert[Index(mr,*vi)]],*vi,remap,selected);
if(adjFlag) ImportVertexAdj(ml,mr,ml.vert[remap.vert[Index(mr,*vi)]],*vi,remap);
}
// edge
for(ei=mr.edge.begin();ei!=mr.edge.end();++ei)
if(!(*ei).IsD() && (!selected || (*ei).IsS())){
ml.edge[remap.edge[Index(mr,*ei)]].ImportData(*ei);
ImportEdgeAdj(ml,mr,ml.edge[remap.edge[Index(mr,*ei)]],*ei,remap,selected);
// Edge to Vertex Adj
EdgeLeft &el = ml.edge[remap.edge[Index(mr,*ei)]];
if(vcg::tri::HasEVAdjacency(ml) && vcg::tri::HasEVAdjacency(mr)){
el.V(0) = &ml.vert[remap.vert[Index(mr,ei->cV(0))]];
el.V(1) = &ml.vert[remap.vert[Index(mr,ei->cV(1))]];
}
if(adjFlag) ImportEdgeAdj(ml,mr,el,*ei,remap);
}
// face
bool wedgetexcoord = vcg::tri::HasPerWedgeTexCoord(mr);
const int textureOffset = ml.textures.size();
bool WTFlag = vcg::tri::HasPerWedgeTexCoord(mr) && (textureOffset>0);
for(fi=mr.face.begin();fi!=mr.face.end();++fi)
if(!(*fi).IsD() && (!selected || (*fi).IsS())){
if(wedgetexcoord)
for(int i = 0; i < (*fi).VN(); ++i)
(*fi).WT(i).n() += ml.textures.size();
if(!(*fi).IsD() && (!selected || (*fi).IsS()))
{
FaceLeft &fl = ml.face[remap.face[Index(mr,*fi)]];
if(WTFlag)
for(int i = 0; i < 3; ++i)
fl.WT(i).n() +=textureOffset;
if(vcg::tri::HasFVAdjacency(ml) && vcg::tri::HasFVAdjacency(mr)){
fl.V(0) = &ml.vert[remap.vert[Index(mr,fi->cV(0))]];
fl.V(1) = &ml.vert[remap.vert[Index(mr,fi->cV(1))]];
fl.V(2) = &ml.vert[remap.vert[Index(mr,fi->cV(2))]];
}
ml.face[remap.face[Index(mr,*fi)]].ImportData(*fi);
ImportFaceAdj(ml,mr,ml.face[remap.face[Index(mr,*fi)]],*fi,remap,selected);
if(adjFlag) ImportFaceAdj(ml,mr,ml.face[remap.face[Index(mr,*fi)]],*fi,remap);
}