2006-01-11 16:45:21 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2004 \/)\/ *
|
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
2013-11-25 11:01:24 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
2006-01-11 16:45:21 +01:00
|
|
|
* 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 __VCGLIB_APPEND
|
|
|
|
#define __VCGLIB_APPEND
|
|
|
|
|
|
|
|
namespace vcg {
|
|
|
|
namespace tri {
|
2012-10-26 01:37:25 +02:00
|
|
|
/** \ingroup trimesh */
|
|
|
|
/*! \brief Class to safely duplicate and append (portion of) meshes.
|
2006-01-11 16:45:21 +01:00
|
|
|
|
2012-10-26 01:37:25 +02:00
|
|
|
Adding elements to a mesh, like faces and vertices can involve the reallocation of the vectors of the involved elements.
|
|
|
|
This class provide the only safe methods to add elements of a mesh to another one.
|
2012-10-26 01:52:48 +02:00
|
|
|
\sa \ref allocation
|
2012-10-26 01:37:25 +02:00
|
|
|
*/
|
2011-12-15 08:52:51 +01:00
|
|
|
template<class MeshLeft, class ConstMeshRight>
|
2006-01-11 16:45:21 +01:00
|
|
|
class Append
|
|
|
|
{
|
|
|
|
public:
|
2010-06-16 18:30:24 +02:00
|
|
|
typedef typename MeshLeft::ScalarType ScalarLeft;
|
|
|
|
typedef typename MeshLeft::CoordType CoordLeft;
|
|
|
|
typedef typename MeshLeft::VertexType VertexLeft;
|
|
|
|
typedef typename MeshLeft::EdgeType EdgeLeft;
|
|
|
|
typedef typename MeshLeft::FaceType FaceLeft;
|
|
|
|
typedef typename MeshLeft::HEdgeType HEdgeLeft;
|
|
|
|
typedef typename MeshLeft::VertexPointer VertexPointerLeft;
|
|
|
|
typedef typename MeshLeft::VertexIterator VertexIteratorLeft;
|
|
|
|
typedef typename MeshLeft::EdgeIterator EdgeIteratorLeft;
|
|
|
|
typedef typename MeshLeft::HEdgeIterator HEdgeIteratorLeft;
|
|
|
|
typedef typename MeshLeft::FaceIterator FaceIteratorLeft;
|
|
|
|
|
|
|
|
|
2011-12-15 08:52:51 +01:00
|
|
|
typedef typename ConstMeshRight::ScalarType ScalarRight;
|
|
|
|
typedef typename ConstMeshRight::CoordType CoordRight;
|
|
|
|
typedef typename ConstMeshRight::VertexType VertexRight;
|
|
|
|
typedef typename ConstMeshRight::EdgeType EdgeRight;
|
|
|
|
typedef typename ConstMeshRight::HEdgeType HEdgeRight;
|
|
|
|
typedef typename ConstMeshRight::FaceType FaceRight;
|
|
|
|
typedef typename ConstMeshRight::VertexPointer VertexPointerRight;
|
|
|
|
typedef typename ConstMeshRight::VertexIterator VertexIteratorRight;
|
|
|
|
typedef typename ConstMeshRight::EdgeIterator EdgeIteratorRight;
|
|
|
|
typedef typename ConstMeshRight::HEdgeIterator HEdgeIteratorRight;
|
|
|
|
typedef typename ConstMeshRight::FaceIterator FaceIteratorRight;
|
|
|
|
typedef typename ConstMeshRight::FacePointer FacePointerRight;
|
2006-01-11 16:45:21 +01:00
|
|
|
|
2010-06-16 18:30:24 +02:00
|
|
|
struct Remap{
|
2013-11-25 11:01:24 +01:00
|
|
|
std::vector<int> vert,face,edge, hedge;
|
2010-06-16 18:30:24 +02:00
|
|
|
};
|
|
|
|
|
2012-04-04 12:11:46 +02:00
|
|
|
static void ImportVertexAdj(MeshLeft &ml, ConstMeshRight &mr, VertexLeft &vl, VertexRight &vr, Remap &remap ){
|
|
|
|
// Vertex to Edge Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasVEAdjacency(ml) && HasVEAdjacency(mr) && vr.cVEp() != 0){
|
2012-04-04 12:11:46 +02:00
|
|
|
size_t i = Index(mr,vr.cVEp());
|
|
|
|
vl.VEp() = (i>ml.edge.size())? 0 : &ml.edge[remap.edge[i]];
|
|
|
|
vl.VEi() = vr.VEi();
|
|
|
|
}
|
2010-06-16 18:30:24 +02:00
|
|
|
|
2012-04-04 12:11:46 +02:00
|
|
|
// Vertex to Face Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasPerVertexVFAdjacency(ml) && HasPerVertexVFAdjacency(mr) && vr.cVFp() != 0 ){
|
2012-04-04 12:11:46 +02:00
|
|
|
size_t i = Index(mr,vr.cVFp());
|
|
|
|
vl.VFp() = (i>ml.face.size())? 0 :&ml.face[remap.face[i]];
|
|
|
|
vl.VFi() = vr.VFi();
|
|
|
|
}
|
2011-11-21 10:36:21 +01:00
|
|
|
|
2012-04-04 12:11:46 +02:00
|
|
|
// Vertex to HEdge Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasVHAdjacency(ml) && HasVHAdjacency(mr) && vr.cVHp() != 0){
|
2012-04-04 12:11:46 +02:00
|
|
|
vl.VHp() = &ml.hedge[remap.hedge[Index(mr,vr.cVHp())]];
|
|
|
|
vl.VHi() = vr.VHi();
|
2011-11-21 10:36:21 +01:00
|
|
|
}
|
2012-04-04 12:11:46 +02:00
|
|
|
}
|
2011-11-21 10:36:21 +01:00
|
|
|
|
2012-04-04 12:11:46 +02:00
|
|
|
static void ImportEdgeAdj(MeshLeft &ml, ConstMeshRight &mr, EdgeLeft &el, const EdgeRight &er, Remap &remap)
|
|
|
|
{
|
2011-11-21 10:36:21 +01:00
|
|
|
// Edge to Edge Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasEEAdjacency(ml) && HasEEAdjacency(mr))
|
2011-11-21 10:36:21 +01:00
|
|
|
for(unsigned int vi = 0; vi < 2; ++vi)
|
|
|
|
{
|
|
|
|
size_t idx = Index(mr,er.cEEp(vi));
|
|
|
|
el.EEp(vi) = (idx>ml.edge.size())? 0 : &ml.edge[remap.edge[idx]];
|
|
|
|
el.EEi(vi) = er.cEEi(vi);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edge to Face Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasEFAdjacency(ml) && HasEFAdjacency(mr)){
|
2011-11-21 10:36:21 +01:00
|
|
|
size_t idx = Index(mr,er.cEFp());
|
|
|
|
el.EFp() = (idx>ml.face.size())? 0 :&ml.face[remap.face[idx]];
|
|
|
|
el.EFi() = er.cEFi();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edge to HEdge Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasEHAdjacency(ml) && HasEHAdjacency(mr))
|
2011-11-21 10:36:21 +01:00
|
|
|
el.EHp() = &ml.hedge[remap.hedge[Index(mr,er.cEHp())]];
|
2010-06-16 18:30:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-04 12:11:46 +02:00
|
|
|
static void ImportFaceAdj(MeshLeft &ml, ConstMeshRight &mr, FaceLeft &fl, const FaceRight &fr, Remap &remap )
|
2011-11-21 10:36:21 +01:00
|
|
|
{
|
|
|
|
// Face to Edge Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasFEAdjacency(ml) && HasFEAdjacency(mr)){
|
2011-11-21 10:36:21 +01:00
|
|
|
assert(fl.VN() == fr.VN());
|
|
|
|
for( int vi = 0; vi < fl.VN(); ++vi ){
|
|
|
|
size_t idx = Index(mr,fr.cFEp(vi));
|
|
|
|
fl.FEp(vi) = (idx>ml.edge.size())? 0 : &ml.edge[remap.edge[idx]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Face to Face Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasFFAdjacency(ml) && HasFFAdjacency(mr)){
|
2011-11-21 10:36:21 +01:00
|
|
|
assert(fl.VN() == fr.VN());
|
|
|
|
for( int vi = 0; vi < fl.VN(); ++vi ){
|
|
|
|
size_t idx = Index(mr,fr.cFFp(vi));
|
|
|
|
fl.FFp(vi) = (idx>ml.face.size()) ? 0 :&ml.face[remap.face[idx]];
|
|
|
|
fl.FFi(vi) = fr.cFFi(vi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Face to HEedge Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasFHAdjacency(ml) && HasFHAdjacency(mr))
|
2011-11-21 10:36:21 +01:00
|
|
|
fl.FHp() = &ml.hedge[remap.hedge[Index(mr,fr.cFHp())]];
|
2010-06-16 18:30:24 +02:00
|
|
|
}
|
|
|
|
|
2011-12-15 08:52:51 +01:00
|
|
|
static void ImportHEdgeAdj(MeshLeft &ml, ConstMeshRight &mr, HEdgeLeft &hl, const HEdgeRight &hr, Remap &remap, bool /*sel*/ ){
|
2011-11-21 10:36:21 +01:00
|
|
|
// HEdge to Vertex Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasHVAdjacency(ml) && HasHVAdjacency(mr))
|
2011-11-21 10:36:21 +01:00
|
|
|
hl.HVp() = &ml.vert[remap.vert[Index(mr,hr.cHVp())]];
|
|
|
|
|
|
|
|
// HEdge to Edge Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasHEAdjacency(ml) && HasHEAdjacency(mr)){
|
2011-11-21 10:36:21 +01:00
|
|
|
size_t idx = Index(mr,hr.cHEp()) ;
|
|
|
|
hl.HEp() = (idx>ml.edge.size())? 0 : &ml.edge[remap.edge[idx]];
|
|
|
|
}
|
|
|
|
|
|
|
|
// HEdge to Face Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasHFAdjacency(ml) && HasHFAdjacency(mr)){
|
2011-11-21 10:36:21 +01:00
|
|
|
size_t idx = Index(mr,hr.cHFp());
|
|
|
|
hl.HFp() = (idx>ml.face.size())? 0 :&ml.face[remap.face[idx]];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// HEdge to Opposite HEdge Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasHOppAdjacency(ml) && HasHOppAdjacency(mr))
|
2011-11-21 10:36:21 +01:00
|
|
|
hl.HOp() = &ml.hedge[remap.hedge[Index(mr,hr.cHOp())]];
|
|
|
|
|
|
|
|
// HEdge to Next HEdge Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasHNextAdjacency(ml) && HasHNextAdjacency(mr))
|
2011-11-21 10:36:21 +01:00
|
|
|
hl.HNp() = &ml.hedge[remap.hedge[Index(mr,hr.cHNp())]];
|
|
|
|
|
|
|
|
// HEdge to Next HEdge Adj
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasHPrevAdjacency(ml) && HasHPrevAdjacency(mr))
|
2011-11-21 10:36:21 +01:00
|
|
|
hl.HPp() = &ml.hedge[remap.hedge[Index(mr,hr.cHPp())]];
|
2010-06-16 18:30:24 +02:00
|
|
|
}
|
|
|
|
|
2009-04-04 18:58:21 +02:00
|
|
|
// Append Right Mesh to the Left Mesh
|
2013-11-25 11:01:24 +01:00
|
|
|
// Append::Mesh(ml, mr) is equivalent to ml += mr.
|
2009-04-04 18:58:21 +02:00
|
|
|
// Note MeshRigth could be costant...
|
2012-10-26 01:52:48 +02:00
|
|
|
/*! \brief %Append the second mesh to the first one.
|
2012-10-26 01:37:25 +02:00
|
|
|
|
|
|
|
The first mesh is not destroyed and no attempt of avoid duplication of already present elements is done.
|
|
|
|
If requested only the selected elements are appended to the first one.
|
|
|
|
The second mesh is not changed at all (it could be constant) with the exception of the selection (see below note).
|
|
|
|
|
|
|
|
\note 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
|
2014-02-18 12:03:01 +01:00
|
|
|
from edges and faces (e.g. if a face is selected then all its vertices must be selected).
|
|
|
|
|
|
|
|
\note Attributes. This function will copy only those attributes that are present in both meshes.
|
|
|
|
Two attributes in different meshes are considered the same iff 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
|
|
|
|
|
2012-10-26 01:37:25 +02:00
|
|
|
*/
|
2006-01-11 16:45:21 +01:00
|
|
|
|
2012-04-04 12:11:46 +02:00
|
|
|
static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false, const bool adjFlag = false)
|
|
|
|
{
|
2011-12-15 08:52:51 +01:00
|
|
|
// 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).
|
2012-10-26 01:37:25 +02:00
|
|
|
// note the use of the parameter for preserving existing vertex selection.
|
2011-12-15 08:52:51 +01:00
|
|
|
if(selected)
|
|
|
|
{
|
2012-04-04 12:11:46 +02:00
|
|
|
assert(adjFlag == false); // It is rather meaningless to partially copy adj relations.
|
2011-12-15 08:52:51 +01:00
|
|
|
tri::UpdateSelection<ConstMeshRight>::VertexFromEdgeLoose(mr,true);
|
|
|
|
tri::UpdateSelection<ConstMeshRight>::VertexFromFaceLoose(mr,true);
|
|
|
|
}
|
2010-06-16 18:30:24 +02:00
|
|
|
|
2012-04-04 12:11:46 +02:00
|
|
|
// phase 1. allocate on ml vert,edge,face, hedge to accomodat those of mr
|
|
|
|
// and build the remapping for all
|
|
|
|
|
|
|
|
Remap remap;
|
|
|
|
|
|
|
|
// vertex
|
|
|
|
remap.vert.resize(mr.vert.size(),-1);
|
|
|
|
VertexIteratorLeft vp;
|
|
|
|
int svn = UpdateSelection<ConstMeshRight>::VertexCount(mr);
|
|
|
|
if(selected) vp=Allocator<MeshLeft>::AddVertices(ml,svn);
|
|
|
|
else vp=Allocator<MeshLeft>::AddVertices(ml,mr.vn);
|
|
|
|
|
2014-02-18 12:03:01 +01:00
|
|
|
for(VertexIteratorRight vi=mr.vert.begin(); vi!=mr.vert.end(); ++vi)
|
2012-04-04 12:11:46 +02:00
|
|
|
if(!(*vi).IsD() && (!selected || (*vi).IsS())){
|
|
|
|
int ind=Index(mr,*vi);
|
|
|
|
remap.vert[ind]=Index(ml,*vp);
|
|
|
|
++vp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// edge
|
|
|
|
remap.edge.resize(mr.edge.size(),-1);
|
|
|
|
EdgeIteratorLeft ep;
|
|
|
|
int sen = UpdateSelection<ConstMeshRight>::EdgeCount(mr);
|
|
|
|
if(selected) ep=Allocator<MeshLeft>::AddEdges(ml,sen);
|
|
|
|
else ep=Allocator<MeshLeft>::AddEdges(ml,mr.en);
|
|
|
|
|
2014-02-18 12:03:01 +01:00
|
|
|
for(EdgeIteratorRight ei=mr.edge.begin(); ei!=mr.edge.end(); ++ei)
|
2012-04-04 12:11:46 +02:00
|
|
|
if(!(*ei).IsD() && (!selected || (*ei).IsS())){
|
|
|
|
int ind=Index(mr,*ei);
|
|
|
|
remap.edge[ind]=Index(ml,*ep);
|
|
|
|
++ep;
|
|
|
|
}
|
|
|
|
|
|
|
|
// face
|
|
|
|
remap.face.resize(mr.face.size(),-1);
|
|
|
|
FaceIteratorLeft fp;
|
|
|
|
int sfn = UpdateSelection<ConstMeshRight>::FaceCount(mr);
|
|
|
|
if(selected) fp=Allocator<MeshLeft>::AddFaces(ml,sfn);
|
|
|
|
else fp=Allocator<MeshLeft>::AddFaces(ml,mr.fn);
|
|
|
|
|
2014-02-18 12:03:01 +01:00
|
|
|
for(FaceIteratorRight fi=mr.face.begin(); fi!=mr.face.end(); ++fi)
|
2012-04-04 12:11:46 +02:00
|
|
|
if(!(*fi).IsD() && (!selected || (*fi).IsS())){
|
|
|
|
int ind=Index(mr,*fi);
|
|
|
|
remap.face[ind]=Index(ml,*fp);
|
|
|
|
++fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hedge
|
|
|
|
remap.hedge.resize(mr.hedge.size(),-1);
|
2014-02-18 12:03:01 +01:00
|
|
|
for(HEdgeIteratorRight hi=mr.hedge.begin(); hi!=mr.hedge.end(); ++hi)
|
2012-04-04 12:11:46 +02:00
|
|
|
if(!(*hi).IsD() && (!selected || (*hi).IsS())){
|
|
|
|
int ind=Index(mr,*hi);
|
|
|
|
assert(remap.hedge[ind]==-1);
|
2014-02-18 12:03:01 +01:00
|
|
|
HEdgeIteratorLeft hp = Allocator<MeshLeft>::AddHEdges(ml,1);
|
2012-04-04 12:11:46 +02:00
|
|
|
(*hp).ImportData(*(hi));
|
|
|
|
remap.hedge[ind]=Index(ml,*hp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// phase 2.
|
|
|
|
// copy data from ml to its corresponding elements in ml and adjacencies
|
|
|
|
|
|
|
|
// vertex
|
2014-02-18 12:03:01 +01:00
|
|
|
for(VertexIteratorRight vi=mr.vert.begin();vi!=mr.vert.end();++vi)
|
2012-04-04 12:11:46 +02:00
|
|
|
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
|
2014-02-18 12:03:01 +01:00
|
|
|
for(EdgeIteratorRight ei=mr.edge.begin();ei!=mr.edge.end();++ei)
|
2012-04-04 12:11:46 +02:00
|
|
|
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)]];
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasEVAdjacency(ml) && HasEVAdjacency(mr)){
|
2012-04-04 12:11:46 +02:00
|
|
|
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 int textureOffset = ml.textures.size();
|
2012-10-26 01:37:25 +02:00
|
|
|
bool WTFlag = HasPerWedgeTexCoord(mr) && (textureOffset>0);
|
2014-02-18 12:03:01 +01:00
|
|
|
for(FaceIteratorRight fi=mr.face.begin();fi!=mr.face.end();++fi)
|
2012-04-04 12:11:46 +02:00
|
|
|
if(!(*fi).IsD() && (!selected || (*fi).IsS()))
|
|
|
|
{
|
|
|
|
FaceLeft &fl = ml.face[remap.face[Index(mr,*fi)]];
|
2014-02-18 15:12:08 +01:00
|
|
|
fl.Alloc(fi->VN());
|
2012-10-26 01:37:25 +02:00
|
|
|
if(HasFVAdjacency(ml) && HasFVAdjacency(mr)){
|
2014-02-12 11:59:37 +01:00
|
|
|
for(int i = 0; i < fl.VN(); ++i)
|
|
|
|
fl.V(i) = &ml.vert[remap.vert[Index(mr,fi->cV(i))]];
|
2012-04-04 12:11:46 +02:00
|
|
|
}
|
2014-02-18 12:03:01 +01:00
|
|
|
if(WTFlag)
|
|
|
|
for(int i = 0; i < fl.VN(); ++i)
|
|
|
|
fl.WT(i).n() +=textureOffset;
|
2014-02-18 15:12:08 +01:00
|
|
|
fl.ImportData(*fi);
|
2012-04-04 12:11:46 +02:00
|
|
|
if(adjFlag) ImportFaceAdj(ml,mr,ml.face[remap.face[Index(mr,*fi)]],*fi,remap);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// hedge
|
2014-02-18 12:03:01 +01:00
|
|
|
for(HEdgeIteratorRight hi=mr.hedge.begin();hi!=mr.hedge.end();++hi)
|
2012-04-04 12:11:46 +02:00
|
|
|
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);
|
|
|
|
}
|
2010-06-16 18:30:24 +02:00
|
|
|
|
2013-11-25 11:01:24 +01:00
|
|
|
// 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;
|
2014-02-18 12:03:01 +01:00
|
|
|
for(VertexIteratorRight vi=mr.vert.begin();vi!=mr.vert.end();++vi,++id_r)
|
2013-11-25 11:01:24 +01:00
|
|
|
if( !(*vi).IsD() && (!selected || (*vi).IsS()))
|
|
|
|
memcpy((*al)._handle->At(remap.vert[Index(mr,*vi)]),(*ar)._handle->At(id_r),
|
|
|
|
(*al)._handle->SizeOf());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2014-02-18 12:03:01 +01:00
|
|
|
for(EdgeIteratorRight ei=mr.edge.begin();ei!=mr.edge.end();++ei,++id_r)
|
2013-11-25 11:01:24 +01:00
|
|
|
if( !(*ei).IsD() && (!selected || (*ei).IsS()))
|
2013-03-11 12:53:26 +01:00
|
|
|
memcpy((*al)._handle->At(remap.edge[Index(mr,*ei)]),(*ar)._handle->At(id_r),
|
2013-11-25 11:01:24 +01:00
|
|
|
(*al)._handle->SizeOf());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2014-02-18 12:03:01 +01:00
|
|
|
for(FaceIteratorRight fi=mr.face.begin();fi!=mr.face.end();++fi,++id_r)
|
2013-11-25 11:01:24 +01:00
|
|
|
if( !(*fi).IsD() && (!selected || (*fi).IsS()))
|
2013-03-11 12:53:26 +01:00
|
|
|
memcpy((*al)._handle->At(remap.face[Index(mr,*fi)]),(*ar)._handle->At(id_r),
|
2013-11-25 11:01:24 +01:00
|
|
|
(*al)._handle->SizeOf());
|
|
|
|
}
|
|
|
|
}
|
2010-06-16 18:30:24 +02:00
|
|
|
|
2011-06-01 15:39:31 +02:00
|
|
|
// 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())
|
|
|
|
// //...
|
|
|
|
// }
|
2010-06-16 18:30:24 +02:00
|
|
|
}
|
2006-01-11 16:45:21 +01:00
|
|
|
|
2012-10-26 01:37:25 +02:00
|
|
|
/*! \brief Copy the second mesh over the first one.
|
|
|
|
The first mesh is destroyed. If requested only the selected elements are copied.
|
|
|
|
*/
|
2011-12-15 08:52:51 +01:00
|
|
|
static void MeshCopy(MeshLeft& ml, ConstMeshRight& mr, bool selected=false)
|
2011-06-03 16:37:50 +02:00
|
|
|
{
|
|
|
|
ml.Clear();
|
|
|
|
Mesh(ml,mr,selected);
|
2012-11-27 12:52:17 +01:00
|
|
|
ml.bbox.Import(mr.bbox);
|
2011-06-03 16:37:50 +02:00
|
|
|
}
|
2012-10-26 01:52:48 +02:00
|
|
|
/*! \brief %Append only the selected elements of second mesh to the first one.
|
2011-06-01 15:39:31 +02:00
|
|
|
|
2012-10-26 01:37:25 +02:00
|
|
|
It is just a wrap of the main Append::Mesh()
|
|
|
|
*/
|
2011-12-15 08:52:51 +01:00
|
|
|
static void Selected(MeshLeft& ml, ConstMeshRight& mr)
|
2006-01-11 16:45:21 +01:00
|
|
|
{
|
2008-08-07 18:19:31 +02:00
|
|
|
Mesh(ml,mr,true);
|
2006-01-11 16:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}; // end of class Append
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-15 08:52:51 +01:00
|
|
|
} // End Namespace tri
|
2006-01-11 16:45:21 +01:00
|
|
|
} // End Namespace vcg
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|