00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __VCGLIB_APPEND
00025 #define __VCGLIB_APPEND
00026
00027 #include <vcg/complex/trimesh/allocate.h>
00028 #include <vcg/complex/trimesh/update/flag.h>
00029
00030 namespace vcg {
00031 namespace tri {
00032
00033 template<class MeshLeft, class MeshRight>
00034 class Append
00035 {
00036 public:
00037 typedef typename MeshLeft::ScalarType ScalarLeft;
00038 typedef typename MeshLeft::CoordType CoordLeft;
00039 typedef typename MeshLeft::VertexType VertexLeft;
00040 typedef typename MeshLeft::EdgeType EdgeLeft;
00041 typedef typename MeshLeft::FaceType FaceLeft;
00042 typedef typename MeshLeft::HEdgeType HEdgeLeft;
00043 typedef typename MeshLeft::VertexPointer VertexPointerLeft;
00044 typedef typename MeshLeft::VertexIterator VertexIteratorLeft;
00045 typedef typename MeshLeft::EdgeIterator EdgeIteratorLeft;
00046 typedef typename MeshLeft::HEdgeIterator HEdgeIteratorLeft;
00047 typedef typename MeshLeft::FaceIterator FaceIteratorLeft;
00048
00049
00050 typedef typename MeshRight::ScalarType ScalarRight;
00051 typedef typename MeshRight::CoordType CoordRight;
00052 typedef typename MeshRight::VertexType VertexRight;
00053 typedef typename MeshRight::EdgeType EdgeRight;
00054 typedef typename MeshRight::HEdgeType HEdgeRight;
00055 typedef typename MeshRight::FaceType FaceRight;
00056 typedef typename MeshRight::VertexPointer VertexPointerRight;
00057 typedef typename MeshRight::VertexIterator VertexIteratorRight;
00058 typedef typename MeshRight::EdgeIterator EdgeIteratorRight;
00059 typedef typename MeshRight::HEdgeIterator HEdgeIteratorRight;
00060 typedef typename MeshRight::FaceIterator FaceIteratorRight;
00061 typedef typename MeshRight::FacePointer FacePointerRight;
00062
00063 struct Remap{
00064 std::vector<int> vert,face,edge, hedge;
00065 };
00066
00067 static void ImportVertexAdj(MeshLeft &ml, MeshRight &mr, VertexLeft &vl, VertexRight &vr, Remap &remap){
00068
00069 if(vcg::tri::HasVEAdjacency(ml) && vcg::tri::HasVEAdjacency(mr)){
00070 size_t i = Index(mr,vr.cVEp());
00071 vl.VEp() = (i>ml.edge.size())? 0 : &ml.edge[remap.edge[i]];
00072 vl.VEi() = vr.VEi();
00073 }
00074
00075
00076 if(vcg::tri::HasPerVertexVFAdjacency(ml) && vcg::tri::HasPerVertexVFAdjacency(mr) &&
00077 vcg::tri::HasPerFaceVFAdjacency(ml) && vcg::tri::HasPerFaceVFAdjacency(mr)
00078 ){
00079 size_t i = Index(mr,vr.cVFp());
00080 vl.VFp() = (i>ml.face.size())? 0 :&ml.face[remap.face[i]];
00081 vl.VFi() = vr.VFi();
00082 }
00083
00084
00085 if(vcg::tri::HasVHAdjacency(ml) && vcg::tri::HasVHAdjacency(mr)){
00086 vl.VHp() = &ml.hedge[remap.hedge[Index(mr,vr.cVHp())]];
00087 vl.VHi() = vr.VHi();
00088 }
00089 }
00090
00091 static void ImportEdgeAdj(MeshLeft &ml, MeshRight &mr, EdgeLeft &el, const EdgeRight &er, Remap &remap){
00092
00093
00094 if(vcg::tri::HasEVAdjacency(ml) && vcg::tri::HasEVAdjacency(mr)){
00095 el.EVp(0) = &ml.vert[remap.vert[Index(mr,er.cEVp(0))]];
00096 el.EVp(1) = &ml.vert[remap.vert[Index(mr,er.cEVp(1))]];
00097 }
00098
00099
00100 if(vcg::tri::HasEEAdjacency(ml) && vcg::tri::HasEEAdjacency(mr))
00101 for(unsigned int vi = 0; vi < 2; ++vi)
00102 {
00103 size_t i = Index(mr,er.cEEp(vi));
00104 el.EEp(i) = (i>ml.edge.size())? 0 : &ml.edge[remap.edge[i]];
00105 el.EEi(i) = er.cEEi(i);
00106 }
00107
00108
00109 if(vcg::tri::HasEFAdjacency(ml) && vcg::tri::HasEFAdjacency(mr)){
00110 size_t i = Index(mr,er.cEFp());
00111 el.EFp() = (i>ml.face.size())? 0 :&ml.face[remap.face[i]];
00112 el.EFi() = er.cEFi();
00113 }
00114
00115
00116 if(vcg::tri::HasEHAdjacency(ml) && vcg::tri::HasEHAdjacency(mr))
00117 el.EHp() = &ml.hedge[remap.hedge[Index(mr,er.cEHp())]];
00118 }
00119
00120
00121 static void ImportFaceAdj(MeshLeft &ml, MeshRight &mr, FaceLeft &fl, const FaceRight &fr, Remap &remap){
00122
00123 if(vcg::tri::HasFVAdjacency(ml) && vcg::tri::HasFVAdjacency(mr)){
00124 assert(fl.VN() == fr.VN());
00125 for( int i = 0; i < fl.VN(); ++i )
00126 fl.V(i) = &ml.vert[remap.vert[Index(mr,fr.V(i))]];
00127 }
00128
00129
00130 if(vcg::tri::HasFEAdjacency(ml) && vcg::tri::HasFEAdjacency(mr)){
00131 assert(fl.VN() == fr.VN());
00132 for( int vi = 0; vi < fl.VN(); ++vi ){
00133 size_t i = Index(mr,fr.cFEp(vi));
00134 fl.FEp(i) = (i>ml.edge.size())? 0 : &ml.edge[remap.edge[i]];
00135 }
00136 }
00137
00138
00139 if(vcg::tri::HasFFAdjacency(ml) && vcg::tri::HasFFAdjacency(mr)){
00140 assert(fl.VN() == fr.VN());
00141 for( int vi = 0; vi < fl.VN(); ++vi ){
00142 size_t i = Index(mr,fr.cFFp(vi));
00143 fl.FFp(vi) = (i>ml.face.size()) ? 0 :&ml.face[remap.face[i]];
00144 fl.FFi(vi) = fr.cFFi(vi);
00145 }
00146 }
00147
00148
00149 if(vcg::tri::HasFHAdjacency(ml) && vcg::tri::HasFHAdjacency(mr))
00150 fl.FHp() = &ml.hedge[remap.hedge[Index(mr,fr.cFHp())]];
00151 }
00152
00153 static void ImportHEdgeAdj(MeshLeft &ml, MeshRight &mr, HEdgeLeft &hl, const HEdgeRight &hr, Remap &remap){
00154
00155 if(vcg::tri::HasHVAdjacency(ml) && vcg::tri::HasHVAdjacency(mr))
00156 hl.HVp() = &ml.vert[remap.vert[Index(mr,hr.cHVp())]];
00157
00158
00159 if(vcg::tri::HasHEAdjacency(ml) && vcg::tri::HasHEAdjacency(mr)){
00160 size_t i = Index(mr,hr.cHEp()) ;
00161 hl.HEp() = (i>ml.edge.size())? 0 : &ml.edge[remap.edge[i]];
00162 }
00163
00164
00165 if(vcg::tri::HasHFAdjacency(ml) && vcg::tri::HasHFAdjacency(mr)){
00166 size_t i = Index(mr,hr.cHFp());
00167 hl.HFp() = (i>ml.face.size())? 0 :&ml.face[remap.face[i]];
00168 }
00169
00170
00171
00172 if(vcg::tri::HasHOppAdjacency(ml) && vcg::tri::HasHOppAdjacency(mr))
00173 hl.HOp() = &ml.hedge[remap.hedge[Index(mr,hr.cHOp())]];
00174
00175
00176 if(vcg::tri::HasHNextAdjacency(ml) && vcg::tri::HasHNextAdjacency(mr))
00177 hl.HNp() = &ml.hedge[remap.hedge[Index(mr,hr.cHNp())]];
00178
00179
00180 if(vcg::tri::HasHPrevAdjacency(ml) && vcg::tri::HasHPrevAdjacency(mr))
00181 hl.HPp() = &ml.hedge[remap.hedge[Index(mr,hr.cHPp())]];
00182 }
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 static void Mesh(MeshLeft& ml, MeshRight& mr, const bool selected = false){
00203
00204
00205
00206
00207 Remap remap;
00208
00209
00210 remap.vert.resize(mr.vert.size(),-1);
00211 VertexIteratorRight vi;
00212 for(vi=mr.vert.begin();vi!=mr.vert.end();++vi)
00213 if(!selected || (*vi).IsS())
00214 {
00215 int ind=Index(mr,*vi);
00216 if(remap.vert[ind]==-1){
00217 VertexIteratorLeft vp;
00218 vp=Allocator<MeshLeft>::AddVertices(ml,1);
00219 (*vp).ImportData(*(vi));
00220 remap.vert[ind]=Index(ml,*vp);
00221 }
00222 }
00223
00224
00225 remap.edge.resize(mr.edge.size(),-1);
00226 EdgeIteratorRight ei;
00227 for(ei=mr.edge.begin(); ei!=mr.edge.end();++ei)
00228 if(!selected || (*ei).IsS())
00229 {
00230 int ind=Index(mr,*ei);
00231 if(remap.edge[ind]==-1){
00232 EdgeIteratorLeft ep;
00233 ep=Allocator<MeshLeft>::AddEdges(ml,1);
00234 (*ep).ImportData(*(ei));
00235 remap.edge[ind]=Index(ml,*ep);
00236 }
00237 }
00238
00239
00240 remap.face.resize(mr.face.size(),-1);
00241 FaceIteratorRight fi;
00242 for(fi=mr.face.begin();fi!=mr.face.end();++fi)
00243 if(!selected || (*fi).IsS())
00244 {
00245 int ind=Index(mr,*fi);
00246 if(remap.face[ind]==-1){
00247 FaceIteratorLeft fp;
00248 fp=Allocator<MeshLeft>::AddFaces(ml,1);
00249 (*fp).ImportData(*(fi));
00250 remap.face[ind]=Index(ml,*fp);
00251 }
00252 }
00253
00254
00255 remap.hedge.resize(mr.hedge.size(),-1);
00256 HEdgeIteratorRight hi;
00257 for(hi=mr.hedge.begin();hi!=mr.hedge.end();++hi)
00258 if(!selected || (*hi).IsS())
00259 {
00260 int ind=Index(mr,*hi);
00261 if(remap.hedge[ind]==-1){
00262 HEdgeIteratorLeft hp;
00263 hp=Allocator<MeshLeft>::AddHEdges(ml,1);
00264 (*hp).ImportData(*(hi));
00265 remap.hedge[ind]=Index(ml,*hp);
00266 }
00267 }
00268
00269
00270
00271
00272
00273 for(vi=mr.vert.begin();vi!=mr.vert.end();++vi)
00274 if(!selected || (*vi).IsS()){
00275 ml.vert[remap.vert[Index(mr,*vi)]].ImportData(*vi);
00276 ImportVertexAdj(ml,mr,ml.vert[remap.vert[Index(mr,*vi)]],*vi,remap);
00277 }
00278
00279
00280 for(ei=mr.edge.begin();ei!=mr.edge.end();++ei)
00281 if(!selected || (*ei).IsS()){
00282 ml.edge[remap.edge[Index(mr,*ei)]].ImportData(*ei);
00283 ImportEdgeAdj(ml,mr,ml.edge[remap.edge[Index(mr,*ei)]],*ei,remap);
00284 }
00285
00286
00287 for(fi=mr.face.begin();fi!=mr.face.end();++fi)
00288 if(!selected || (*fi).IsS()){
00289 ml.face[remap.face[Index(mr,*fi)]].ImportData(*fi);
00290 ImportFaceAdj(ml,mr,ml.face[remap.face[Index(mr,*fi)]],*fi,remap);
00291 }
00292
00293
00294 for(hi=mr.hedge.begin();hi!=mr.hedge.end();++hi)
00295 if(!selected || (*hi).IsS()){
00296 ml.hedge[remap.hedge[Index(mr,*hi)]].ImportData(*hi);
00297 ImportHEdgeAdj(ml,mr,ml.hedge[remap.hedge[Index(mr,*hi)]],*hi,remap);
00298 }
00299
00300
00301
00302
00303
00304 ml.textures.insert(ml.textures.end(),mr.textures.begin(),mr.textures.end());
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 }
00319
00320
00321 static void Selected(MeshLeft& ml, MeshRight& mr)
00322 {
00323 Mesh(ml,mr,true);
00324 }
00325
00326 };
00327
00328
00329
00330
00331
00332 }
00333 }
00334
00335
00336 #endif
00337
00338