using ForEach. add const ForEach and ForEachHEdge
This commit is contained in:
parent
1144dfbae4
commit
6014f75b60
|
|
@ -514,16 +514,15 @@ static void MeshAppendConst(
|
||||||
else
|
else
|
||||||
vp=Allocator<MeshLeft>::AddVertices(ml,mr.vn);
|
vp=Allocator<MeshLeft>::AddVertices(ml,mr.vn);
|
||||||
|
|
||||||
for (auto v : mr.vert)
|
ForEachVertex(mr, [&](const VertexRight& v)
|
||||||
//for(VertexIteratorRight vi=mr.vert.begin(); vi!=mr.vert.end(); ++vi)
|
|
||||||
{
|
{
|
||||||
if(!v.IsD() && (!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;
|
||||||
|
|
@ -531,13 +530,14 @@ static void MeshAppendConst(
|
||||||
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);
|
||||||
|
|
||||||
for (auto e : mr.edge)
|
ForEachEdge(mr, [&](const EdgeRight& e)
|
||||||
//for(EdgeIteratorRight ei=mr.edge.begin(); ei!=mr.edge.end(); ++ei)
|
{
|
||||||
if(!e.IsD() && (!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());
|
||||||
|
|
@ -546,52 +546,58 @@ static void MeshAppendConst(
|
||||||
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);
|
||||||
|
|
||||||
for (auto f : mr.face)
|
ForEachFace(mr, [&](const FaceRight& f)
|
||||||
//for(FaceIteratorRight fi=mr.face.begin(); fi!=mr.face.end(); ++fi)
|
{
|
||||||
if(!f.IsD() && (!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());
|
||||||
for (auto he : mr.hedge)
|
|
||||||
//for(HEdgeIteratorRight hi=mr.hedge.begin(); hi!=mr.hedge.end(); ++hi)
|
ForEachHEdge(mr, [&](const HEdgeRight& he)
|
||||||
if(!he.IsD() && (!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());
|
||||||
for (auto t : mr.tetra)
|
|
||||||
//for (TetraIteratorRight ti = mr.tetra.begin(); ti != mr.tetra.end(); ++ti)
|
ForEachTetra(mr, [&](const TetraRight& t)
|
||||||
if (!t.IsD() && (!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 2.
|
||||||
// copy data from mr to its corresponding elements in ml and adjacencies
|
// copy data from mr to its corresponding elements in ml and adjacencies
|
||||||
|
|
||||||
// vertex
|
// vertex
|
||||||
for (auto v: mr.vert)
|
ForEachVertex(mr, [&](const VertexRight& v)
|
||||||
//for(VertexIteratorRight vi=mr.vert.begin();vi!=mr.vert.end();++vi)
|
{
|
||||||
if( !v.IsD() && (!selected || v.IsS())){
|
if(!selected || v.IsS()){
|
||||||
ml.vert[remap.vert[Index(mr,v)]].ImportData(v);
|
ml.vert[remap.vert[Index(mr,v)]].ImportData(v);
|
||||||
if(adjFlag) ImportVertexAdj(ml,mr,ml.vert[remap.vert[Index(mr,v)]],v,remap);
|
if(adjFlag) ImportVertexAdj(ml,mr,ml.vert[remap.vert[Index(mr,v)]],v,remap);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// edge
|
// edge
|
||||||
for (auto e: mr.edge)
|
ForEachEdge(mr, [&](const EdgeRight& e)
|
||||||
//for(EdgeIteratorRight ei=mr.edge.begin();ei!=mr.edge.end();++ei)
|
{
|
||||||
if(!e.IsD() && (!selected || e.IsS())){
|
if(!selected || e.IsS()){
|
||||||
ml.edge[remap.edge[Index(mr,e)]].ImportData(e);
|
ml.edge[remap.edge[Index(mr,e)]].ImportData(e);
|
||||||
// Edge to Vertex Adj
|
// Edge to Vertex Adj
|
||||||
EdgeLeft &el = ml.edge[remap.edge[Index(mr,e)]];
|
EdgeLeft &el = ml.edge[remap.edge[Index(mr,e)]];
|
||||||
|
|
@ -601,13 +607,14 @@ static void MeshAppendConst(
|
||||||
}
|
}
|
||||||
if(adjFlag) ImportEdgeAdj(ml,mr,el,e,remap);
|
if(adjFlag) ImportEdgeAdj(ml,mr,el,e,remap);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// face
|
// face
|
||||||
const size_t textureOffset = ml.textures.size();
|
const size_t textureOffset = ml.textures.size();
|
||||||
bool WTFlag = HasPerWedgeTexCoord(mr) && (textureOffset>0);
|
bool WTFlag = HasPerWedgeTexCoord(mr) && (textureOffset>0);
|
||||||
for (auto f: mr.face)
|
ForEachFace(mr, [&](const FaceRight& f)
|
||||||
//for(FaceIteratorRight fi=mr.face.begin();fi!=mr.face.end();++fi)
|
{
|
||||||
if(!f.IsD() && (!selected || f.IsS()))
|
if(!selected || f.IsS())
|
||||||
{
|
{
|
||||||
FaceLeft &fl = ml.face[remap.face[Index(mr,f)]];
|
FaceLeft &fl = ml.face[remap.face[Index(mr,f)]];
|
||||||
fl.Alloc(f.VN());
|
fl.Alloc(f.VN());
|
||||||
|
|
@ -622,19 +629,21 @@ static void MeshAppendConst(
|
||||||
if(adjFlag) ImportFaceAdj(ml,mr,ml.face[remap.face[Index(mr,f)]],f,remap);
|
if(adjFlag) ImportFaceAdj(ml,mr,ml.face[remap.face[Index(mr,f)]],f,remap);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// hedge
|
// hedge
|
||||||
for (auto he : mr.hedge)
|
ForEachHEdge(mr, [&](const HEdgeRight& he)
|
||||||
//for(HEdgeIteratorRight hi=mr.hedge.begin();hi!=mr.hedge.end();++hi)
|
{
|
||||||
if(!he.IsD() && (!selected || he.IsS())){
|
if(!selected || he.IsS()){
|
||||||
ml.hedge[remap.hedge[Index(mr,he)]].ImportData(he);
|
ml.hedge[remap.hedge[Index(mr,he)]].ImportData(he);
|
||||||
ImportHEdgeAdj(ml,mr,ml.hedge[remap.hedge[Index(mr,he)]],he,remap,selected);
|
ImportHEdgeAdj(ml,mr,ml.hedge[remap.hedge[Index(mr,he)]],he,remap,selected);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//tetra
|
//tetra
|
||||||
for (auto t: mr.tetra)
|
ForEachTetra(mr, [&](const TetraRight& t)
|
||||||
//for(TetraIteratorRight ti = mr.tetra.begin(); ti != mr.tetra.end(); ++ti)
|
{
|
||||||
if(!t.IsD() && (!selected || t.IsS()))
|
if(!selected || t.IsS())
|
||||||
{
|
{
|
||||||
TetraLeft &tl = ml.tetra[remap.tetra[Index(mr,t)]];
|
TetraLeft &tl = ml.tetra[remap.tetra[Index(mr,t)]];
|
||||||
|
|
||||||
|
|
@ -646,6 +655,7 @@ static void MeshAppendConst(
|
||||||
if(adjFlag) ImportTetraAdj(ml, mr, ml.tetra[remap.tetra[Index(mr,t)]], t, remap);
|
if(adjFlag) ImportTetraAdj(ml, mr, ml.tetra[remap.tetra[Index(mr,t)]], t, remap);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// phase 3.
|
// phase 3.
|
||||||
// take care of other per mesh data: textures, attributes
|
// take care of other per mesh data: textures, attributes
|
||||||
|
|
@ -670,7 +680,6 @@ static void MeshAppendConst(
|
||||||
if(ar!= mr.vert_attr.end()){
|
if(ar!= mr.vert_attr.end()){
|
||||||
id_r = 0;
|
id_r = 0;
|
||||||
for (auto v: mr.vert){
|
for (auto v: mr.vert){
|
||||||
//for(VertexIteratorRight vi=mr.vert.begin();vi!=mr.vert.end();++vi,++id_r)
|
|
||||||
if( !v.IsD() && (!selected || v.IsS()))
|
if( !v.IsD() && (!selected || v.IsS()))
|
||||||
(*al)._handle->CopyValue(remap.vert[Index(mr,v)], id_r, (*ar)._handle);
|
(*al)._handle->CopyValue(remap.vert[Index(mr,v)], id_r, (*ar)._handle);
|
||||||
++id_r;
|
++id_r;
|
||||||
|
|
@ -685,7 +694,6 @@ static void MeshAppendConst(
|
||||||
if(ar!= mr.edge_attr.end()){
|
if(ar!= mr.edge_attr.end()){
|
||||||
id_r = 0;
|
id_r = 0;
|
||||||
for (auto e: mr.edge){
|
for (auto e: mr.edge){
|
||||||
//for(EdgeIteratorRight ei=mr.edge.begin();ei!=mr.edge.end();++ei,++id_r)
|
|
||||||
if( !e.IsD() && (!selected || e.IsS()))
|
if( !e.IsD() && (!selected || e.IsS()))
|
||||||
(*al)._handle->CopyValue(remap.edge[Index(mr,e)], id_r, (*ar)._handle);
|
(*al)._handle->CopyValue(remap.edge[Index(mr,e)], id_r, (*ar)._handle);
|
||||||
++id_r;
|
++id_r;
|
||||||
|
|
@ -700,7 +708,6 @@ static void MeshAppendConst(
|
||||||
if(ar!= mr.face_attr.end()){
|
if(ar!= mr.face_attr.end()){
|
||||||
id_r = 0;
|
id_r = 0;
|
||||||
for (auto f: mr.face) {
|
for (auto f: mr.face) {
|
||||||
//for(FaceIteratorRight fi=mr.face.begin();fi!=mr.face.end();++fi,++id_r)
|
|
||||||
if( !f.IsD() && (!selected || f.IsS()))
|
if( !f.IsD() && (!selected || f.IsS()))
|
||||||
(*al)._handle->CopyValue(remap.face[Index(mr,f)], id_r, (*ar)._handle);
|
(*al)._handle->CopyValue(remap.face[Index(mr,f)], id_r, (*ar)._handle);
|
||||||
++id_r;
|
++id_r;
|
||||||
|
|
@ -715,13 +722,13 @@ static void MeshAppendConst(
|
||||||
if(ar!= mr.tetra_attr.end()){
|
if(ar!= mr.tetra_attr.end()){
|
||||||
id_r = 0;
|
id_r = 0;
|
||||||
for (auto t: mr.tetra) {
|
for (auto t: mr.tetra) {
|
||||||
//for(TetraIteratorRight ti = mr.tetra.begin(); ti != mr.tetra.end(); ++ti, ++id_r)
|
|
||||||
if( !t.IsD() && (!selected || t.IsS()))
|
if( !t.IsD() && (!selected || t.IsS()))
|
||||||
(*al)._handle->CopyValue(remap.tetra[Index(mr, t)], id_r, (*ar)._handle);
|
(*al)._handle->CopyValue(remap.tetra[Index(mr, t)], id_r, (*ar)._handle);
|
||||||
++id_r;
|
++id_r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,22 @@ namespace tri {
|
||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
template <class MeshType>
|
||||||
|
inline void ForEachFacePos(const MeshType &m, std::function<void (const typename face::Pos<typename MeshType::FaceType> &)> action)
|
||||||
|
{
|
||||||
|
typedef typename face::Pos<typename MeshType::FaceType> PosType;
|
||||||
|
|
||||||
|
for(auto fi=m.face.begin();fi!=m.face.end();++fi)
|
||||||
|
if(!(*fi).IsD())
|
||||||
|
{
|
||||||
|
for(int i=0;i<3;++i)
|
||||||
|
{
|
||||||
|
PosType pi(&*fi,i);
|
||||||
|
action(pi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <class MeshType>
|
template <class MeshType>
|
||||||
inline void ForEachFacePos(MeshType &m, std::function<void (typename face::Pos<typename MeshType::FaceType> &)> action)
|
inline void ForEachFacePos(MeshType &m, std::function<void (typename face::Pos<typename MeshType::FaceType> &)> action)
|
||||||
{
|
{
|
||||||
|
|
@ -108,6 +124,25 @@ inline void ForEachFace(MeshType &m, std::function<void (typename MeshType::Face
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
template <class MeshType>
|
||||||
|
inline void ForEachVertex(const MeshType &m, std::function<void (const typename MeshType::VertexType &)> action)
|
||||||
|
{
|
||||||
|
if(m.vn == (int) m.vert.size())
|
||||||
|
{
|
||||||
|
for(auto vi=m.vert.begin();vi!=m.vert.end();++vi) {
|
||||||
|
action(*vi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(auto vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
|
if(!(*vi).IsD())
|
||||||
|
{
|
||||||
|
action(*vi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <class MeshType>
|
template <class MeshType>
|
||||||
inline void ForEachVertex(MeshType &m, std::function<void (typename MeshType::VertexType &)> action)
|
inline void ForEachVertex(MeshType &m, std::function<void (typename MeshType::VertexType &)> action)
|
||||||
{
|
{
|
||||||
|
|
@ -127,6 +162,54 @@ inline void ForEachVertex(MeshType &m, std::function<void (typename MeshType::Ve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ForEachHEdge Helper
|
||||||
|
* to traverse all the half edges of a mesh you can simply write something like:
|
||||||
|
*
|
||||||
|
* ForEachHEdge(m, [&](const HEdgeType &he){
|
||||||
|
* MakeSomethingWithHEdge(he);
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <class MeshType>
|
||||||
|
inline void ForEachHEdge(const MeshType &m, std::function<void (const typename MeshType::HEdgeType &)> action)
|
||||||
|
{
|
||||||
|
if(m.hn == (int) m.hedge.size())
|
||||||
|
{
|
||||||
|
for(auto hei=m.hedge.begin();hei!=m.hedge.end();++hei) {
|
||||||
|
action(*hei);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(auto hei=m.hedge.begin();hei!=m.hedge.end();++hei)
|
||||||
|
if(!(*hei).IsD())
|
||||||
|
{
|
||||||
|
action(*hei);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class MeshType>
|
||||||
|
inline void ForEachHEdge(MeshType &m, std::function<void (typename MeshType::HEdgeType &)> action)
|
||||||
|
{
|
||||||
|
if(m.hn == (int) m.hedge.size())
|
||||||
|
{
|
||||||
|
for(auto hei=m.hedge.begin();hei!=m.hedge.end();++hei) {
|
||||||
|
action(*hei);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(auto hei=m.hedge.begin();hei!=m.hedge.end();++hei)
|
||||||
|
if(!(*hei).IsD())
|
||||||
|
{
|
||||||
|
action(*hei);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ForEachEdge Helper
|
* ForEachEdge Helper
|
||||||
* to traverse all the vertexes of a mesh you can simply write something like:
|
* to traverse all the vertexes of a mesh you can simply write something like:
|
||||||
|
|
@ -137,6 +220,25 @@ inline void ForEachVertex(MeshType &m, std::function<void (typename MeshType::Ve
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
template <class MeshType>
|
||||||
|
inline void ForEachEdge(const MeshType &m, std::function<void (const typename MeshType::EdgeType &)> action)
|
||||||
|
{
|
||||||
|
if(m.en == (int) m.edge.size())
|
||||||
|
{
|
||||||
|
for(auto ei=m.edge.begin();ei!=m.edge.end();++ei) {
|
||||||
|
action(*ei);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(auto ei=m.edge.begin();ei!=m.edge.end();++ei)
|
||||||
|
if(!(*ei).IsD())
|
||||||
|
{
|
||||||
|
action(*ei);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <class MeshType>
|
template <class MeshType>
|
||||||
inline void ForEachEdge(MeshType &m, std::function<void (typename MeshType::EdgeType &)> action)
|
inline void ForEachEdge(MeshType &m, std::function<void (typename MeshType::EdgeType &)> action)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue