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:
parent
b0d7d5c52e
commit
5aed57a364
|
@ -66,7 +66,7 @@ public:
|
||||||
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, bool sel ){
|
static void ImportVertexAdj(MeshLeft &ml, ConstMeshRight &mr, VertexLeft &vl, VertexRight &vr, Remap &remap ){
|
||||||
// Vertex to Edge Adj
|
// Vertex to Edge Adj
|
||||||
if(vcg::tri::HasVEAdjacency(ml) && vcg::tri::HasVEAdjacency(mr) && vr.cVEp() != 0){
|
if(vcg::tri::HasVEAdjacency(ml) && vcg::tri::HasVEAdjacency(mr) && vr.cVEp() != 0){
|
||||||
size_t i = Index(mr,vr.cVEp());
|
size_t i = Index(mr,vr.cVEp());
|
||||||
|
@ -74,11 +74,8 @@ public:
|
||||||
vl.VEi() = vr.VEi();
|
vl.VEi() = vr.VEi();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!sel){
|
|
||||||
// Vertex to Face Adj
|
// Vertex to Face Adj
|
||||||
if(vcg::tri::HasPerVertexVFAdjacency(ml) && vcg::tri::HasPerVertexVFAdjacency(mr) &&
|
if(vcg::tri::HasPerVertexVFAdjacency(ml) && vcg::tri::HasPerVertexVFAdjacency(mr) && vr.cVFp() != 0 ){
|
||||||
vcg::tri::HasPerFaceVFAdjacency(ml) && vcg::tri::HasPerFaceVFAdjacency(mr) && vr.cVFp() != 0
|
|
||||||
){
|
|
||||||
size_t i = Index(mr,vr.cVFp());
|
size_t i = Index(mr,vr.cVFp());
|
||||||
vl.VFp() = (i>ml.face.size())? 0 :&ml.face[remap.face[i]];
|
vl.VFp() = (i>ml.face.size())? 0 :&ml.face[remap.face[i]];
|
||||||
vl.VFi() = vr.VFi();
|
vl.VFi() = vr.VFi();
|
||||||
|
@ -90,18 +87,9 @@ public:
|
||||||
vl.VHi() = vr.VHi();
|
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
|
// Edge to Edge Adj
|
||||||
if(vcg::tri::HasEEAdjacency(ml) && vcg::tri::HasEEAdjacency(mr))
|
if(vcg::tri::HasEEAdjacency(ml) && vcg::tri::HasEEAdjacency(mr))
|
||||||
for(unsigned int vi = 0; vi < 2; ++vi)
|
for(unsigned int vi = 0; vi < 2; ++vi)
|
||||||
|
@ -122,19 +110,10 @@ public:
|
||||||
if(vcg::tri::HasEHAdjacency(ml) && vcg::tri::HasEHAdjacency(mr))
|
if(vcg::tri::HasEHAdjacency(ml) && vcg::tri::HasEHAdjacency(mr))
|
||||||
el.EHp() = &ml.hedge[remap.hedge[Index(mr,er.cEHp())]];
|
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
|
// Face to Edge Adj
|
||||||
if(vcg::tri::HasFEAdjacency(ml) && vcg::tri::HasFEAdjacency(mr)){
|
if(vcg::tri::HasFEAdjacency(ml) && vcg::tri::HasFEAdjacency(mr)){
|
||||||
assert(fl.VN() == fr.VN());
|
assert(fl.VN() == fr.VN());
|
||||||
|
@ -158,7 +137,6 @@ public:
|
||||||
if(vcg::tri::HasFHAdjacency(ml) && vcg::tri::HasFHAdjacency(mr))
|
if(vcg::tri::HasFHAdjacency(ml) && vcg::tri::HasFHAdjacency(mr))
|
||||||
fl.FHp() = &ml.hedge[remap.hedge[Index(mr,fr.cFHp())]];
|
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*/ ){
|
static void ImportHEdgeAdj(MeshLeft &ml, ConstMeshRight &mr, HEdgeLeft &hl, const HEdgeRight &hr, Remap &remap, bool /*sel*/ ){
|
||||||
// HEdge to Vertex Adj
|
// HEdge to Vertex Adj
|
||||||
|
@ -195,14 +173,15 @@ public:
|
||||||
// Append::Mesh(ml, mr) is equivalent to ml += mr.
|
// Append::Mesh(ml, mr) is equivalent to ml += mr.
|
||||||
// Note MeshRigth could be costant...
|
// 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
|
// 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
|
// the append could build faces referencing non existent vertices
|
||||||
// so it is mandatory that the selection of the vertices reflects the loose selection
|
// 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).
|
// from edges and faces (e.g. if a face is selected all its vertices must be selected).
|
||||||
if(selected)
|
if(selected)
|
||||||
{
|
{
|
||||||
|
assert(adjFlag == false); // It is rather meaningless to partially copy adj relations.
|
||||||
tri::UpdateSelection<ConstMeshRight>::VertexFromEdgeLoose(mr,true);
|
tri::UpdateSelection<ConstMeshRight>::VertexFromEdgeLoose(mr,true);
|
||||||
tri::UpdateSelection<ConstMeshRight>::VertexFromFaceLoose(mr,true);
|
tri::UpdateSelection<ConstMeshRight>::VertexFromFaceLoose(mr,true);
|
||||||
}
|
}
|
||||||
|
@ -215,41 +194,46 @@ static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false){
|
||||||
// vertex
|
// vertex
|
||||||
remap.vert.resize(mr.vert.size(),-1);
|
remap.vert.resize(mr.vert.size(),-1);
|
||||||
VertexIteratorRight vi;
|
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)
|
for(vi=mr.vert.begin();vi!=mr.vert.end();++vi)
|
||||||
if(!(*vi).IsD() && (!selected || (*vi).IsS())){
|
if(!(*vi).IsD() && (!selected || (*vi).IsS())){
|
||||||
int ind=Index(mr,*vi);
|
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);
|
remap.vert[ind]=Index(ml,*vp);
|
||||||
|
++vp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// edge
|
// edge
|
||||||
remap.edge.resize(mr.edge.size(),-1);
|
remap.edge.resize(mr.edge.size(),-1);
|
||||||
EdgeIteratorRight ei;
|
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)
|
for(ei=mr.edge.begin(); ei!=mr.edge.end();++ei)
|
||||||
if(!(*ei).IsD() && (!selected || (*ei).IsS())){
|
if(!(*ei).IsD() && (!selected || (*ei).IsS())){
|
||||||
int ind=Index(mr,*ei);
|
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);
|
remap.edge[ind]=Index(ml,*ep);
|
||||||
|
++ep;
|
||||||
}
|
}
|
||||||
|
|
||||||
// face
|
// face
|
||||||
vcg::tri::Allocator<ConstMeshRight>::CompactFaceVector(mr);
|
|
||||||
remap.face.resize(mr.face.size(),-1);
|
remap.face.resize(mr.face.size(),-1);
|
||||||
FaceIteratorRight fi;
|
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)
|
for(fi=mr.face.begin();fi!=mr.face.end();++fi)
|
||||||
if(!(*fi).IsD() && (!selected || (*fi).IsS())){
|
if(!(*fi).IsD() && (!selected || (*fi).IsS())){
|
||||||
int ind=Index(mr,*fi);
|
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);
|
remap.face[ind]=Index(ml,*fp);
|
||||||
|
++fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// hedge
|
// 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)
|
for(vi=mr.vert.begin();vi!=mr.vert.end();++vi)
|
||||||
if( !(*vi).IsD() && (!selected || (*vi).IsS())){
|
if( !(*vi).IsD() && (!selected || (*vi).IsS())){
|
||||||
ml.vert[remap.vert[Index(mr,*vi)]].ImportData(*vi);
|
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
|
// edge
|
||||||
for(ei=mr.edge.begin();ei!=mr.edge.end();++ei)
|
for(ei=mr.edge.begin();ei!=mr.edge.end();++ei)
|
||||||
if(!(*ei).IsD() && (!selected || (*ei).IsS())){
|
if(!(*ei).IsD() && (!selected || (*ei).IsS())){
|
||||||
ml.edge[remap.edge[Index(mr,*ei)]].ImportData(*ei);
|
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
|
// 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)
|
for(fi=mr.face.begin();fi!=mr.face.end();++fi)
|
||||||
if(!(*fi).IsD() && (!selected || (*fi).IsS())){
|
if(!(*fi).IsD() && (!selected || (*fi).IsS()))
|
||||||
if(wedgetexcoord)
|
{
|
||||||
for(int i = 0; i < (*fi).VN(); ++i)
|
FaceLeft &fl = ml.face[remap.face[Index(mr,*fi)]];
|
||||||
(*fi).WT(i).n() += ml.textures.size();
|
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);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue