fix append and SplitManifoldComponents when wedge text coords are enabled
This commit is contained in:
parent
1ec2d65a58
commit
c150c3f6b6
|
|
@ -689,6 +689,9 @@ public:
|
||||||
tmpMesh.vert.EnableVFAdjacency();
|
tmpMesh.vert.EnableVFAdjacency();
|
||||||
tmpMesh.face.EnableVFAdjacency();
|
tmpMesh.face.EnableVFAdjacency();
|
||||||
|
|
||||||
|
if (m.face.IsWedgeTexCoordEnabled())
|
||||||
|
tmpMesh.face.EnableWedgeTexCoord();
|
||||||
|
|
||||||
size_t selCnt=0;
|
size_t selCnt=0;
|
||||||
|
|
||||||
for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
|
for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
|
||||||
|
|
|
||||||
|
|
@ -264,215 +264,7 @@ static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false,
|
||||||
tri::UpdateSelection<ConstMeshRight>::VertexFromFaceLoose(mr,true);
|
tri::UpdateSelection<ConstMeshRight>::VertexFromFaceLoose(mr,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// phase 1. allocate on ml vert,edge,face, hedge to accomodat those of mr
|
MeshAppendConst(ml, mr, selected, adjFlag);
|
||||||
// and build the remapping for all
|
|
||||||
|
|
||||||
Remap remap;
|
|
||||||
|
|
||||||
// vertex
|
|
||||||
remap.vert.resize(mr.vert.size(), Remap::InvalidIndex());
|
|
||||||
VertexIteratorLeft vp;
|
|
||||||
size_t svn = UpdateSelection<ConstMeshRight>::VertexCount(mr);
|
|
||||||
if(selected)
|
|
||||||
vp=Allocator<MeshLeft>::AddVertices(ml,int(svn));
|
|
||||||
else
|
|
||||||
vp=Allocator<MeshLeft>::AddVertices(ml,mr.vn);
|
|
||||||
|
|
||||||
for(VertexIteratorRight vi=mr.vert.begin(); vi!=mr.vert.end(); ++vi)
|
|
||||||
{
|
|
||||||
if(!(*vi).IsD() && (!selected || (*vi).IsS()))
|
|
||||||
{
|
|
||||||
size_t ind=Index(mr,*vi);
|
|
||||||
remap.vert[ind]=int(Index(ml,*vp));
|
|
||||||
++vp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// edge
|
|
||||||
remap.edge.resize(mr.edge.size(), Remap::InvalidIndex());
|
|
||||||
EdgeIteratorLeft ep;
|
|
||||||
size_t sen = UpdateSelection<ConstMeshRight>::EdgeCount(mr);
|
|
||||||
if(selected) ep=Allocator<MeshLeft>::AddEdges(ml,sen);
|
|
||||||
else ep=Allocator<MeshLeft>::AddEdges(ml,mr.en);
|
|
||||||
|
|
||||||
for(EdgeIteratorRight ei=mr.edge.begin(); ei!=mr.edge.end(); ++ei)
|
|
||||||
if(!(*ei).IsD() && (!selected || (*ei).IsS())){
|
|
||||||
size_t ind=Index(mr,*ei);
|
|
||||||
remap.edge[ind]=int(Index(ml,*ep));
|
|
||||||
++ep;
|
|
||||||
}
|
|
||||||
|
|
||||||
// face
|
|
||||||
remap.face.resize(mr.face.size(), Remap::InvalidIndex());
|
|
||||||
FaceIteratorLeft fp;
|
|
||||||
size_t sfn = UpdateSelection<ConstMeshRight>::FaceCount(mr);
|
|
||||||
if(selected) fp=Allocator<MeshLeft>::AddFaces(ml,sfn);
|
|
||||||
else fp=Allocator<MeshLeft>::AddFaces(ml,mr.fn);
|
|
||||||
|
|
||||||
for(FaceIteratorRight fi=mr.face.begin(); fi!=mr.face.end(); ++fi)
|
|
||||||
if(!(*fi).IsD() && (!selected || (*fi).IsS())){
|
|
||||||
size_t ind=Index(mr,*fi);
|
|
||||||
remap.face[ind]=int(Index(ml,*fp));
|
|
||||||
++fp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// hedge
|
|
||||||
remap.hedge.resize(mr.hedge.size(),Remap::InvalidIndex());
|
|
||||||
for(HEdgeIteratorRight hi=mr.hedge.begin(); hi!=mr.hedge.end(); ++hi)
|
|
||||||
if(!(*hi).IsD() && (!selected || (*hi).IsS())){
|
|
||||||
size_t ind=Index(mr,*hi);
|
|
||||||
assert(remap.hedge[ind]==Remap::InvalidIndex());
|
|
||||||
HEdgeIteratorLeft hp = Allocator<MeshLeft>::AddHEdges(ml,1);
|
|
||||||
(*hp).ImportData(*(hi));
|
|
||||||
remap.hedge[ind]=Index(ml,*hp);
|
|
||||||
}
|
|
||||||
|
|
||||||
remap.tetra.resize(mr.tetra.size(), Remap::InvalidIndex());
|
|
||||||
for (TetraIteratorRight ti = mr.tetra.begin(); ti != mr.tetra.end(); ++ti)
|
|
||||||
if (!(*ti).IsD() && (!selected || (*ti).IsS())) {
|
|
||||||
size_t idx = Index(mr, *ti);
|
|
||||||
assert (remap.tetra[idx] == Remap::InvalidIndex());
|
|
||||||
TetraIteratorLeft tp = Allocator<MeshLeft>::AddTetras(ml, 1);
|
|
||||||
(*tp).ImportData(*ti);
|
|
||||||
remap.tetra[idx] = Index(ml, *tp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// phase 2.
|
|
||||||
// copy data from mr to its corresponding elements in ml and adjacencies
|
|
||||||
|
|
||||||
// vertex
|
|
||||||
for(VertexIteratorRight vi=mr.vert.begin();vi!=mr.vert.end();++vi)
|
|
||||||
if( !(*vi).IsD() && (!selected || (*vi).IsS())){
|
|
||||||
ml.vert[remap.vert[Index(mr,*vi)]].ImportData(*vi);
|
|
||||||
if(adjFlag) ImportVertexAdj(ml,mr,ml.vert[remap.vert[Index(mr,*vi)]],*vi,remap);
|
|
||||||
}
|
|
||||||
|
|
||||||
// edge
|
|
||||||
for(EdgeIteratorRight ei=mr.edge.begin();ei!=mr.edge.end();++ei)
|
|
||||||
if(!(*ei).IsD() && (!selected || (*ei).IsS())){
|
|
||||||
ml.edge[remap.edge[Index(mr,*ei)]].ImportData(*ei);
|
|
||||||
// Edge to Vertex Adj
|
|
||||||
EdgeLeft &el = ml.edge[remap.edge[Index(mr,*ei)]];
|
|
||||||
if(HasEVAdjacency(ml) && 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
|
|
||||||
const size_t textureOffset = ml.textures.size();
|
|
||||||
bool WTFlag = HasPerWedgeTexCoord(mr) && (textureOffset>0);
|
|
||||||
for(FaceIteratorRight fi=mr.face.begin();fi!=mr.face.end();++fi)
|
|
||||||
if(!(*fi).IsD() && (!selected || (*fi).IsS()))
|
|
||||||
{
|
|
||||||
FaceLeft &fl = ml.face[remap.face[Index(mr,*fi)]];
|
|
||||||
fl.Alloc(fi->VN());
|
|
||||||
if(HasFVAdjacency(ml) && HasFVAdjacency(mr)){
|
|
||||||
for(int i = 0; i < fl.VN(); ++i)
|
|
||||||
fl.V(i) = &ml.vert[remap.vert[Index(mr,fi->cV(i))]];
|
|
||||||
}
|
|
||||||
fl.ImportData(*fi);
|
|
||||||
if(WTFlag)
|
|
||||||
for(int i = 0; i < fl.VN(); ++i)
|
|
||||||
fl.WT(i).n() += short(textureOffset);
|
|
||||||
if(adjFlag) ImportFaceAdj(ml,mr,ml.face[remap.face[Index(mr,*fi)]],*fi,remap);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// hedge
|
|
||||||
for(HEdgeIteratorRight hi=mr.hedge.begin();hi!=mr.hedge.end();++hi)
|
|
||||||
if(!(*hi).IsD() && (!selected || (*hi).IsS())){
|
|
||||||
ml.hedge[remap.hedge[Index(mr,*hi)]].ImportData(*hi);
|
|
||||||
ImportHEdgeAdj(ml,mr,ml.hedge[remap.hedge[Index(mr,*hi)]],*hi,remap,selected);
|
|
||||||
}
|
|
||||||
|
|
||||||
//tetra
|
|
||||||
for(TetraIteratorRight ti = mr.tetra.begin(); ti != mr.tetra.end(); ++ti)
|
|
||||||
if(!(*ti).IsD() && (!selected || (*ti).IsS()))
|
|
||||||
{
|
|
||||||
TetraLeft &tl = ml.tetra[remap.tetra[Index(mr,*ti)]];
|
|
||||||
|
|
||||||
if(HasFVAdjacency(ml) && HasFVAdjacency(mr)){
|
|
||||||
for(int i = 0; i < 4; ++i)
|
|
||||||
tl.V(i) = &ml.vert[remap.vert[Index(mr,ti->cV(i))]];
|
|
||||||
}
|
|
||||||
tl.ImportData(*ti);
|
|
||||||
if(adjFlag) ImportTetraAdj(ml, mr, ml.tetra[remap.tetra[Index(mr,*ti)]], *ti, remap);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// phase 3.
|
|
||||||
// take care of other per mesh data: textures, attributes
|
|
||||||
|
|
||||||
// At the end concatenate the vector with texture names.
|
|
||||||
ml.textures.insert(ml.textures.end(),mr.textures.begin(),mr.textures.end());
|
|
||||||
|
|
||||||
// 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
|
|
||||||
// name and the same type. This may be deceiving because they could in fact have
|
|
||||||
// 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
|
|
||||||
// of the right mesh will be uninitialized
|
|
||||||
|
|
||||||
unsigned int id_r;
|
|
||||||
typename std::set< PointerToAttribute >::iterator al, ar;
|
|
||||||
|
|
||||||
// per vertex attributes
|
|
||||||
for(al = ml.vert_attr.begin(); al != ml.vert_attr.end(); ++al)
|
|
||||||
if(!(*al)._name.empty()){
|
|
||||||
ar = mr.vert_attr.find(*al);
|
|
||||||
if(ar!= mr.vert_attr.end()){
|
|
||||||
id_r = 0;
|
|
||||||
for(VertexIteratorRight vi=mr.vert.begin();vi!=mr.vert.end();++vi,++id_r)
|
|
||||||
if( !(*vi).IsD() && (!selected || (*vi).IsS()))
|
|
||||||
(*al)._handle->CopyValue(remap.vert[Index(mr,*vi)], id_r, (*ar)._handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// per edge attributes
|
|
||||||
for(al = ml.edge_attr.begin(); al != ml.edge_attr.end(); ++al)
|
|
||||||
if(!(*al)._name.empty()){
|
|
||||||
ar = mr.edge_attr.find(*al);
|
|
||||||
if(ar!= mr.edge_attr.end()){
|
|
||||||
id_r = 0;
|
|
||||||
for(EdgeIteratorRight ei=mr.edge.begin();ei!=mr.edge.end();++ei,++id_r)
|
|
||||||
if( !(*ei).IsD() && (!selected || (*ei).IsS()))
|
|
||||||
(*al)._handle->CopyValue(remap.edge[Index(mr,*ei)], id_r, (*ar)._handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// per face attributes
|
|
||||||
for(al = ml.face_attr.begin(); al != ml.face_attr.end(); ++al)
|
|
||||||
if(!(*al)._name.empty()){
|
|
||||||
ar = mr.face_attr.find(*al);
|
|
||||||
if(ar!= mr.face_attr.end()){
|
|
||||||
id_r = 0;
|
|
||||||
for(FaceIteratorRight fi=mr.face.begin();fi!=mr.face.end();++fi,++id_r)
|
|
||||||
if( !(*fi).IsD() && (!selected || (*fi).IsS()))
|
|
||||||
(*al)._handle->CopyValue(remap.face[Index(mr,*fi)], id_r, (*ar)._handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// per tetra attributes
|
|
||||||
for(al = ml.tetra_attr.begin(); al != ml.tetra_attr.end(); ++al)
|
|
||||||
if(!(*al)._name.empty()){
|
|
||||||
ar = mr.tetra_attr.find(*al);
|
|
||||||
if(ar!= mr.tetra_attr.end()){
|
|
||||||
id_r = 0;
|
|
||||||
for(TetraIteratorRight ti = mr.tetra.begin(); ti != mr.tetra.end(); ++ti, ++id_r)
|
|
||||||
if( !(*ti).IsD() && (!selected || (*ti).IsS()))
|
|
||||||
(*al)._handle->CopyValue(remap.tetra[Index(mr, *ti)], id_r, (*ar)._handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// per mesh attributes
|
|
||||||
// if both ml and mr have an attribute with the same name, no action is done
|
|
||||||
// if mr has an attribute that is NOT present in ml, the attribute is added to ml
|
|
||||||
//for(ar = mr.mesh_attr.begin(); ar != mr.mesh_attr.end(); ++ar)
|
|
||||||
// if(!(*ar)._name.empty()){
|
|
||||||
// al = ml.mesh_attr.find(*ar);
|
|
||||||
// if(al== ml.mesh_attr.end())
|
|
||||||
// //...
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -494,180 +286,200 @@ static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false,
|
||||||
* or, use the Mesh function that takes a non-const Right Mesh argument.
|
* or, use the Mesh function that takes a non-const Right Mesh argument.
|
||||||
*/
|
*/
|
||||||
static void MeshAppendConst(
|
static void MeshAppendConst(
|
||||||
MeshLeft& ml,
|
MeshLeft& ml,
|
||||||
const ConstMeshRight& mr,
|
const ConstMeshRight& mr,
|
||||||
const bool selected = false,
|
const bool selected = false,
|
||||||
const bool adjFlag = false)
|
const bool adjFlag = false)
|
||||||
{
|
{
|
||||||
// phase 1. allocate on ml vert,edge,face, hedge to accomodat those of mr
|
// phase 1. allocate on ml vert,edge,face, hedge to accomodat those of mr
|
||||||
// and build the remapping for all
|
// and build the remapping for all
|
||||||
|
|
||||||
Remap remap;
|
Remap remap;
|
||||||
|
|
||||||
// vertex
|
// vertex
|
||||||
remap.vert.resize(mr.vert.size(), Remap::InvalidIndex());
|
remap.vert.resize(mr.vert.size(), Remap::InvalidIndex());
|
||||||
VertexIteratorLeft vp;
|
VertexIteratorLeft vp;
|
||||||
size_t svn = UpdateSelection<ConstMeshRight>::VertexCount(mr);
|
size_t svn = UpdateSelection<ConstMeshRight>::VertexCount(mr);
|
||||||
if(selected)
|
if(selected)
|
||||||
vp=Allocator<MeshLeft>::AddVertices(ml,int(svn));
|
vp=Allocator<MeshLeft>::AddVertices(ml,int(svn));
|
||||||
else
|
else
|
||||||
vp=Allocator<MeshLeft>::AddVertices(ml,mr.vn);
|
vp=Allocator<MeshLeft>::AddVertices(ml,mr.vn);
|
||||||
|
|
||||||
ForEachVertex(mr, [&](const VertexRight& v)
|
ForEachVertex(mr, [&](const VertexRight& v)
|
||||||
{
|
{
|
||||||
if(!selected || v.IsS())
|
if(!selected || v.IsS())
|
||||||
{
|
{
|
||||||
size_t ind=Index(mr,v);
|
size_t ind=Index(mr,v);
|
||||||
remap.vert[ind]=int(Index(ml,*vp));
|
remap.vert[ind]=int(Index(ml,*vp));
|
||||||
++vp;
|
++vp;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// edge
|
// edge
|
||||||
remap.edge.resize(mr.edge.size(), Remap::InvalidIndex());
|
remap.edge.resize(mr.edge.size(), Remap::InvalidIndex());
|
||||||
EdgeIteratorLeft ep;
|
EdgeIteratorLeft ep;
|
||||||
size_t sen = UpdateSelection<ConstMeshRight>::EdgeCount(mr);
|
size_t sen = UpdateSelection<ConstMeshRight>::EdgeCount(mr);
|
||||||
if(selected) ep=Allocator<MeshLeft>::AddEdges(ml,sen);
|
if(selected) ep=Allocator<MeshLeft>::AddEdges(ml,sen);
|
||||||
else ep=Allocator<MeshLeft>::AddEdges(ml,mr.en);
|
else ep=Allocator<MeshLeft>::AddEdges(ml,mr.en);
|
||||||
|
|
||||||
ForEachEdge(mr, [&](const EdgeRight& e)
|
ForEachEdge(mr, [&](const EdgeRight& e)
|
||||||
{
|
{
|
||||||
if(!selected || e.IsS()){
|
if(!selected || e.IsS()){
|
||||||
size_t ind=Index(mr,e);
|
size_t ind=Index(mr,e);
|
||||||
remap.edge[ind]=int(Index(ml,*ep));
|
remap.edge[ind]=int(Index(ml,*ep));
|
||||||
++ep;
|
++ep;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// face
|
// face
|
||||||
remap.face.resize(mr.face.size(), Remap::InvalidIndex());
|
remap.face.resize(mr.face.size(), Remap::InvalidIndex());
|
||||||
FaceIteratorLeft fp;
|
FaceIteratorLeft fp;
|
||||||
size_t sfn = UpdateSelection<ConstMeshRight>::FaceCount(mr);
|
size_t sfn = UpdateSelection<ConstMeshRight>::FaceCount(mr);
|
||||||
if(selected) fp=Allocator<MeshLeft>::AddFaces(ml,sfn);
|
if(selected) fp=Allocator<MeshLeft>::AddFaces(ml,sfn);
|
||||||
else fp=Allocator<MeshLeft>::AddFaces(ml,mr.fn);
|
else fp=Allocator<MeshLeft>::AddFaces(ml,mr.fn);
|
||||||
|
|
||||||
ForEachFace(mr, [&](const FaceRight& f)
|
ForEachFace(mr, [&](const FaceRight& f)
|
||||||
{
|
{
|
||||||
if(!selected || f.IsS()){
|
if(!selected || f.IsS()){
|
||||||
size_t ind=Index(mr,f);
|
size_t ind=Index(mr,f);
|
||||||
remap.face[ind]=int(Index(ml,*fp));
|
remap.face[ind]=int(Index(ml,*fp));
|
||||||
++fp;
|
++fp;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// hedge
|
// hedge
|
||||||
remap.hedge.resize(mr.hedge.size(),Remap::InvalidIndex());
|
remap.hedge.resize(mr.hedge.size(),Remap::InvalidIndex());
|
||||||
|
|
||||||
ForEachHEdge(mr, [&](const HEdgeRight& he)
|
ForEachHEdge(mr, [&](const HEdgeRight& he)
|
||||||
{
|
{
|
||||||
if(!selected || he.IsS()){
|
if(!selected || he.IsS()){
|
||||||
size_t ind=Index(mr,he);
|
size_t ind=Index(mr,he);
|
||||||
assert(remap.hedge[ind]==Remap::InvalidIndex());
|
assert(remap.hedge[ind]==Remap::InvalidIndex());
|
||||||
HEdgeIteratorLeft hp = Allocator<MeshLeft>::AddHEdges(ml,1);
|
HEdgeIteratorLeft hp = Allocator<MeshLeft>::AddHEdges(ml,1);
|
||||||
(*hp).ImportData(he);
|
(*hp).ImportData(he);
|
||||||
remap.hedge[ind]=Index(ml,*hp);
|
remap.hedge[ind]=Index(ml,*hp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
remap.tetra.resize(mr.tetra.size(), Remap::InvalidIndex());
|
remap.tetra.resize(mr.tetra.size(), Remap::InvalidIndex());
|
||||||
|
|
||||||
ForEachTetra(mr, [&](const TetraRight& t)
|
ForEachTetra(mr, [&](const TetraRight& t)
|
||||||
{
|
{
|
||||||
if (!selected || t.IsS()) {
|
if (!selected || t.IsS()) {
|
||||||
size_t idx = Index(mr, t);
|
size_t idx = Index(mr, t);
|
||||||
assert (remap.tetra[idx] == Remap::InvalidIndex());
|
assert (remap.tetra[idx] == Remap::InvalidIndex());
|
||||||
TetraIteratorLeft tp = Allocator<MeshLeft>::AddTetras(ml, 1);
|
TetraIteratorLeft tp = Allocator<MeshLeft>::AddTetras(ml, 1);
|
||||||
(*tp).ImportData(t);
|
(*tp).ImportData(t);
|
||||||
remap.tetra[idx] = Index(ml, *tp);
|
remap.tetra[idx] = Index(ml, *tp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// phase 2.
|
// phase 1.5
|
||||||
// copy data from mr to its corresponding elements in ml and adjacencies
|
// manage textures, creating a new one only when necessary
|
||||||
|
// (not making unuseful duplicates on append) and save a mapping
|
||||||
|
|
||||||
// vertex
|
// for each texture in the right mesh, it maps it to the texture index in the
|
||||||
ForEachVertex(mr, [&](const VertexRight& v)
|
// left mesh
|
||||||
{
|
std::vector<unsigned int> mappingTextures(mr.textures.size());
|
||||||
if(!selected || v.IsS()){
|
|
||||||
ml.vert[remap.vert[Index(mr,v)]].ImportData(v);
|
|
||||||
if(adjFlag) ImportVertexAdj(ml,mr,ml.vert[remap.vert[Index(mr,v)]],v,remap);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// edge
|
unsigned int baseMlT = ml.textures.size();
|
||||||
ForEachEdge(mr, [&](const EdgeRight& e)
|
for (unsigned int i = 0; i < mr.textures.size(); ++i) {
|
||||||
{
|
auto it = std::find(ml.textures.begin(), ml.textures.end(), mr.textures[i]);
|
||||||
if(!selected || e.IsS()){
|
//if the right texture does not exists in the left mesh
|
||||||
ml.edge[remap.edge[Index(mr,e)]].ImportData(e);
|
if (it == ml.textures.end()) {
|
||||||
// Edge to Vertex Adj
|
//add the texture in the left mesh and create the mapping
|
||||||
EdgeLeft &el = ml.edge[remap.edge[Index(mr,e)]];
|
mappingTextures[i] = baseMlT++;
|
||||||
if(HasEVAdjacency(ml) && HasEVAdjacency(mr)){
|
ml.textures.push_back(mr.textures[i]);
|
||||||
el.V(0) = &ml.vert[remap.vert[Index(mr,e.cV(0))]];
|
}
|
||||||
el.V(1) = &ml.vert[remap.vert[Index(mr,e.cV(1))]];
|
else {
|
||||||
}
|
//the ith right texture will map in the texture found in the left mesh
|
||||||
if(adjFlag) ImportEdgeAdj(ml,mr,el,e,remap);
|
mappingTextures[i] = it - ml.textures.begin();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
//ml.textures.insert(ml.textures.end(), mr.textures.begin(),mr.textures.end());
|
||||||
|
|
||||||
// face
|
// phase 2.
|
||||||
const size_t textureOffset = ml.textures.size();
|
// copy data from mr to its corresponding elements in ml and adjacencies
|
||||||
bool WTFlag = HasPerWedgeTexCoord(mr) && (textureOffset>0);
|
|
||||||
ForEachFace(mr, [&](const FaceRight& f)
|
|
||||||
{
|
|
||||||
if(!selected || f.IsS())
|
|
||||||
{
|
|
||||||
FaceLeft &fl = ml.face[remap.face[Index(mr,f)]];
|
|
||||||
fl.Alloc(f.VN());
|
|
||||||
if(HasFVAdjacency(ml) && HasFVAdjacency(mr)){
|
|
||||||
for(int i = 0; i < fl.VN(); ++i)
|
|
||||||
fl.V(i) = &ml.vert[remap.vert[Index(mr,f.cV(i))]];
|
|
||||||
}
|
|
||||||
fl.ImportData(f);
|
|
||||||
if(WTFlag)
|
|
||||||
for(int i = 0; i < fl.VN(); ++i)
|
|
||||||
fl.WT(i).n() += short(textureOffset);
|
|
||||||
if(adjFlag) ImportFaceAdj(ml,mr,ml.face[remap.face[Index(mr,f)]],f,remap);
|
|
||||||
|
|
||||||
}
|
// vertex
|
||||||
});
|
ForEachVertex(mr, [&](const VertexRight& v)
|
||||||
|
{
|
||||||
|
if(!selected || v.IsS()){
|
||||||
|
ml.vert[remap.vert[Index(mr,v)]].ImportData(v);
|
||||||
|
if(adjFlag) ImportVertexAdj(ml,mr,ml.vert[remap.vert[Index(mr,v)]],v,remap);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// hedge
|
// edge
|
||||||
ForEachHEdge(mr, [&](const HEdgeRight& he)
|
ForEachEdge(mr, [&](const EdgeRight& e)
|
||||||
{
|
{
|
||||||
if(!selected || he.IsS()){
|
if(!selected || e.IsS()){
|
||||||
ml.hedge[remap.hedge[Index(mr,he)]].ImportData(he);
|
ml.edge[remap.edge[Index(mr,e)]].ImportData(e);
|
||||||
ImportHEdgeAdj(ml,mr,ml.hedge[remap.hedge[Index(mr,he)]],he,remap,selected);
|
// Edge to Vertex Adj
|
||||||
}
|
EdgeLeft &el = ml.edge[remap.edge[Index(mr,e)]];
|
||||||
});
|
if(HasEVAdjacency(ml) && HasEVAdjacency(mr)){
|
||||||
|
el.V(0) = &ml.vert[remap.vert[Index(mr,e.cV(0))]];
|
||||||
|
el.V(1) = &ml.vert[remap.vert[Index(mr,e.cV(1))]];
|
||||||
|
}
|
||||||
|
if(adjFlag) ImportEdgeAdj(ml,mr,el,e,remap);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//tetra
|
// face
|
||||||
ForEachTetra(mr, [&](const TetraRight& t)
|
bool WTFlag = HasPerWedgeTexCoord(mr);
|
||||||
{
|
ForEachFace(mr, [&](const FaceRight& f)
|
||||||
if(!selected || t.IsS())
|
{
|
||||||
{
|
if(!selected || f.IsS())
|
||||||
TetraLeft &tl = ml.tetra[remap.tetra[Index(mr,t)]];
|
{
|
||||||
|
FaceLeft &fl = ml.face[remap.face[Index(mr,f)]];
|
||||||
|
fl.Alloc(f.VN());
|
||||||
|
if(HasFVAdjacency(ml) && HasFVAdjacency(mr)){
|
||||||
|
for(int i = 0; i < fl.VN(); ++i)
|
||||||
|
fl.V(i) = &ml.vert[remap.vert[Index(mr,f.cV(i))]];
|
||||||
|
}
|
||||||
|
fl.ImportData(f);
|
||||||
|
if(WTFlag)
|
||||||
|
for(int i = 0; i < fl.VN(); ++i)
|
||||||
|
fl.WT(i).n() = mappingTextures[f.WT(i).n()];
|
||||||
|
if(adjFlag) ImportFaceAdj(ml,mr,ml.face[remap.face[Index(mr,f)]],f,remap);
|
||||||
|
|
||||||
if(HasFVAdjacency(ml) && HasFVAdjacency(mr)){
|
}
|
||||||
for(int i = 0; i < 4; ++i)
|
});
|
||||||
tl.V(i) = &ml.vert[remap.vert[Index(mr,t.cV(i))]];
|
|
||||||
}
|
|
||||||
tl.ImportData(t);
|
|
||||||
if(adjFlag) ImportTetraAdj(ml, mr, ml.tetra[remap.tetra[Index(mr,t)]], t, remap);
|
|
||||||
|
|
||||||
}
|
// hedge
|
||||||
});
|
ForEachHEdge(mr, [&](const HEdgeRight& he)
|
||||||
|
{
|
||||||
|
if(!selected || he.IsS()){
|
||||||
|
ml.hedge[remap.hedge[Index(mr,he)]].ImportData(he);
|
||||||
|
ImportHEdgeAdj(ml,mr,ml.hedge[remap.hedge[Index(mr,he)]],he,remap,selected);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// phase 3.
|
//tetra
|
||||||
// take care of other per mesh data: textures, attributes
|
ForEachTetra(mr, [&](const TetraRight& t)
|
||||||
|
{
|
||||||
|
if(!selected || t.IsS())
|
||||||
|
{
|
||||||
|
TetraLeft &tl = ml.tetra[remap.tetra[Index(mr,t)]];
|
||||||
|
|
||||||
// At the end concatenate the vector with texture names.
|
if(HasFVAdjacency(ml) && HasFVAdjacency(mr)){
|
||||||
ml.textures.insert(ml.textures.end(),mr.textures.begin(),mr.textures.end());
|
for(int i = 0; i < 4; ++i)
|
||||||
|
tl.V(i) = &ml.vert[remap.vert[Index(mr,t.cV(i))]];
|
||||||
|
}
|
||||||
|
tl.ImportData(t);
|
||||||
|
if(adjFlag) ImportTetraAdj(ml, mr, ml.tetra[remap.tetra[Index(mr,t)]], t, remap);
|
||||||
|
|
||||||
// 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
|
});
|
||||||
// name and the same type. This may be deceiving because they could in fact have
|
|
||||||
// different semantic, but this is up to the developer.
|
// phase 3.
|
||||||
// If the left mesh has attributes that are not in the right mesh, their values for the elements
|
// take care of other per mesh data: attributes
|
||||||
// of the right mesh will be uninitialized
|
|
||||||
|
// 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
|
||||||
|
// name and the same type. This may be deceiving because they could in fact have
|
||||||
|
// 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
|
||||||
|
// 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;
|
||||||
|
|
@ -740,40 +552,42 @@ static void MeshAppendConst(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
// if mr has an attribute that is NOT present in ml, the attribute is added to ml
|
// if mr has an attribute that is NOT present in ml, the attribute is added to ml
|
||||||
//for(ar = mr.mesh_attr.begin(); ar != mr.mesh_attr.end(); ++ar)
|
//for(ar = mr.mesh_attr.begin(); ar != mr.mesh_attr.end(); ++ar)
|
||||||
// if(!(*ar)._name.empty()){
|
// if(!(*ar)._name.empty()){
|
||||||
// al = ml.mesh_attr.find(*ar);
|
// al = ml.mesh_attr.find(*ar);
|
||||||
// if(al== ml.mesh_attr.end())
|
// if(al== ml.mesh_attr.end())
|
||||||
// //...
|
// //...
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief Copy the second mesh over the first one.
|
/**
|
||||||
The first mesh is destroyed. If requested only the selected elements are copied.
|
* \brief Copy the second mesh over the first one.
|
||||||
*/
|
* The first mesh is destroyed. If requested only the selected elements are copied.
|
||||||
|
*/
|
||||||
static void MeshCopy(MeshLeft& ml, ConstMeshRight& mr, bool selected=false, const bool adjFlag = false)
|
static void MeshCopy(MeshLeft& ml, ConstMeshRight& mr, bool selected=false, const bool adjFlag = false)
|
||||||
{
|
{
|
||||||
ml.Clear();
|
ml.Clear();
|
||||||
Mesh(ml,mr,selected,adjFlag);
|
Mesh(ml,mr,selected,adjFlag);
|
||||||
ml.bbox.Import(mr.bbox);
|
ml.bbox.Import(mr.bbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MeshCopyConst(MeshLeft& ml, const ConstMeshRight& mr, bool selected=false, const bool adjFlag = false)
|
static void MeshCopyConst(MeshLeft& ml, const ConstMeshRight& mr, bool selected=false, const bool adjFlag = false)
|
||||||
{
|
{
|
||||||
ml.Clear();
|
ml.Clear();
|
||||||
MeshAppendConst(ml,mr,selected,adjFlag);
|
MeshAppendConst(ml,mr,selected,adjFlag);
|
||||||
ml.bbox.Import(mr.bbox);
|
ml.bbox.Import(mr.bbox);
|
||||||
}
|
}
|
||||||
/*! \brief %Append only the selected elements of second mesh to the first one.
|
/**
|
||||||
|
* \brief %Append only the selected elements of second mesh to the first one.
|
||||||
It is just a wrap of the main Append::Mesh()
|
*
|
||||||
*/
|
* It is just a wrap of the main Append::Mesh()
|
||||||
|
*/
|
||||||
static void Selected(MeshLeft& ml, ConstMeshRight& mr)
|
static void Selected(MeshLeft& ml, ConstMeshRight& mr)
|
||||||
{
|
{
|
||||||
Mesh(ml,mr,true);
|
Mesh(ml,mr,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // end of class Append
|
}; // end of class Append
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue