VCG Library
complex/algorithms/update/topology.h
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004-2016 \/)\/ *
6 * Visual Computing Lab /\/| *
7 * ISTI - Italian National Research Council | *
8 * \ *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
23 
24 #ifndef __VCG_TRI_UPDATE_TOPOLOGY
25 #define __VCG_TRI_UPDATE_TOPOLOGY
26 
27 namespace vcg {
28 namespace tri {
30 
32 
34 
35 template <class UpdateMeshType>
37 {
38 
39 public:
40 typedef UpdateMeshType MeshType;
41 typedef typename MeshType::ScalarType ScalarType;
42 typedef typename MeshType::VertexType VertexType;
43 typedef typename MeshType::VertexPointer VertexPointer;
44 typedef typename MeshType::VertexIterator VertexIterator;
45 typedef typename MeshType::EdgeType EdgeType;
46 typedef typename MeshType::EdgePointer EdgePointer;
47 typedef typename MeshType::EdgeIterator EdgeIterator;
48 typedef typename MeshType::FaceType FaceType;
49 typedef typename MeshType::FacePointer FacePointer;
50 typedef typename MeshType::FaceIterator FaceIterator;
51 typedef typename MeshType::TetraType TetraType;
52 typedef typename MeshType::TetraPointer TetraPointer;
53 typedef typename MeshType::TetraIterator TetraIterator;
54 
55 
57 
59 
63 class PFace
64 {
65 public:
66  VertexPointer v[3]; //three ordered vertex pointers, identify a face
67  TetraPointer t; //the pointer to the tetra where this face belongs
68  int z; //index in [0..3] of the face in the tetra
69  bool isBorder;
70 
71  PFace () {}
72  PFace (TetraPointer tp, const int nz) { this->Set(tp, nz); }
73 
74  void Set (TetraPointer tp /*the tetra pointer*/, const int nz /*the face index*/)
75  {
76  assert (tp != 0);
77  assert (nz >= 0 && nz < 4);
78 
79  v[0] = tp->cV(Tetra::VofF(nz, 0));
80  v[1] = tp->cV(Tetra::VofF(nz, 1));
81  v[2] = tp->cV(Tetra::VofF(nz, 2));
82 
83  assert(v[0] != v[1] && v[1] != v[2]); //no degenerate faces
84 
85  if (v[0] > v[1])
86  std::swap(v[0], v[1]);
87  if (v[1] > v[2])
88  std::swap(v[1], v[2]);
89  if (v[0] > v[1])
90  std::swap(v[0], v[1]);
91 
92  t = tp;
93  z = nz;
94 
95 
96  }
97 
98  inline bool operator < (const PFace & pf) const
99  {
100  if (v[0] < pf.v[0])
101  return true;
102  else
103  {
104  if (v[0] > pf.v[0]) return false;
105 
106  if (v[1] < pf.v[1])
107  return true;
108  else
109  {
110  if (v[1] > pf.v[1]) return false;
111 
112  return (v[2] < pf.v[2]);
113  }
114  }
115  }
116 
117  inline bool operator == (const PFace & pf) const
118  {
119  return v[0] == pf.v[0] && v[1] == pf.v[1] && v[2] == pf.v[2];
120  }
121 };
122 
123 static void FillFaceVector (MeshType & m, std::vector<PFace> & fvec)
124 {
125  ForEachTetra(m, [&fvec] (TetraType & t) {
126  for (int i = 0; i < 4; ++i)
127  fvec.push_back(PFace(&t, i));
128  });
129 }
130 
131 static void FillUniqueFaceVector (MeshType & m, std::vector<PFace> & fvec)
132 {
133  FillFaceVector(m, fvec);
134  std::sort(fvec.begin(), fvec.end());
135  typename std::vector<PFace>::iterator newEnd = std::unique(fvec.begin(), fvec.end());
136 }
137 
139 
142 class PEdge
143 {
144 public:
145 
146  VertexPointer v[2]; // the two Vertex pointer are ordered!
147  FacePointer f; // the face where this edge belong
148  int z; // index in [0..2] of the edge of the face
149  bool isBorder;
150 
151  PEdge() {}
152  PEdge(FacePointer pf, const int nz) { this->Set(pf,nz); }
153  void Set( FacePointer pf, const int nz )
154  {
155  assert(pf!=0);
156  assert(nz>=0);
157  assert(nz<pf->VN());
158 
159  v[0] = pf->V(nz);
160  v[1] = pf->V(pf->Next(nz));
161  assert(v[0] != v[1]); // The face pointed by 'f' is Degenerate (two coincident vertexes)
162 
163  if( v[0] > v[1] ) std::swap(v[0],v[1]);
164  f = pf;
165  z = nz;
166  }
167 
168  inline bool operator < ( const PEdge & pe ) const
169  {
170  if( v[0]<pe.v[0] ) return true;
171  else if( v[0]>pe.v[0] ) return false;
172  else return v[1] < pe.v[1];
173  }
174 
175  inline bool operator == ( const PEdge & pe ) const
176  {
177  return v[0]==pe.v[0] && v[1]==pe.v[1];
178  }
181  inline Point3<ScalarType> EdgeBarycentricToFaceBarycentric(ScalarType u) const
182  {
183  Point3<ScalarType> interp(0,0,0);
184  interp[ this->z ] = u;
185  interp[(this->z+1)%3] = 1.0f-u;
186  return interp;
187  }
188 };
189 
193 
194 static void FillEdgeVector(MeshType &m, std::vector<PEdge> &edgeVec, bool includeFauxEdge=true)
195 {
196  edgeVec.reserve(m.fn*3);
197  for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
198  if( ! (*fi).IsD() )
199  for(int j=0;j<(*fi).VN();++j)
200  if(includeFauxEdge || !(*fi).IsF(j))
201  edgeVec.push_back(PEdge(&*fi,j));
202 }
203 
204 static void FillUniqueEdgeVector(MeshType &m, std::vector<PEdge> &edgeVec, bool includeFauxEdge=true, bool computeBorderFlag=false)
205 {
206  FillEdgeVector(m,edgeVec,includeFauxEdge);
207  sort(edgeVec.begin(), edgeVec.end()); // oredering by vertex
208 
209  if (computeBorderFlag) {
210  for (size_t i=0; i<edgeVec.size(); i++)
211  edgeVec[ i ].isBorder = true;
212  for (size_t i=1; i<edgeVec.size(); i++) {
213  if (edgeVec[i]==edgeVec[i-1])
214  edgeVec[i-1].isBorder = edgeVec[i-1].isBorder = false;
215  }
216  }
217 
218  typename std::vector< PEdge>::iterator newEnd = std::unique(edgeVec.begin(), edgeVec.end());
219 
220  edgeVec.resize(newEnd-edgeVec.begin()); // redundant! remove?
221 }
222 
223 static void FillSelectedFaceEdgeVector(MeshType &m, std::vector<PEdge> &edgeVec)
224 {
225  edgeVec.reserve(m.fn*3);
226  ForEachFace(m, [&](FaceType &f){
227  for(int j=0;j<f.VN();++j)
228  if(f.IsFaceEdgeS(j))
229  edgeVec.push_back(PEdge(&f,j));
230  });
231 
232  sort(edgeVec.begin(), edgeVec.end()); // oredering by vertex
233  edgeVec.erase(std::unique(edgeVec.begin(), edgeVec.end()),edgeVec.end());
234 }
235 
236 
237 
243 static void AllocateEdge(MeshType &m)
244 {
245  // Delete all the edges (if any)
246  for(EdgeIterator ei=m.edge.begin();ei!=m.edge.end();++ei)
249 
250  // Compute and add edges
251  std::vector<PEdge> Edges;
252  FillUniqueEdgeVector(m,Edges,true,tri::HasPerEdgeFlags(m) );
253  assert(m.edge.empty());
254  tri::Allocator<MeshType>::AddEdges(m,Edges.size());
255  assert(m.edge.size()==Edges.size());
256 
257  // Setup adjacency relations
258  if(tri::HasEVAdjacency(m))
259  {
260  for(size_t i=0; i< Edges.size(); ++i)
261  {
262  m.edge[i].V(0) = Edges[i].v[0];
263  m.edge[i].V(1) = Edges[i].v[1];
264  }
265  }
266 
267  if (tri::HasPerEdgeFlags(m)){
268  for(size_t i=0; i< Edges.size(); ++i) {
269  if (Edges[i].isBorder) m.edge[i].SetB(); else m.edge[i].ClearB();
270  }
271  }
272 
273  if(tri::HasEFAdjacency(m)) // Note it is an unordered relation.
274  {
275  for(size_t i=0; i< Edges.size(); ++i)
276  {
277  std::vector<FacePointer> fpVec;
278  std::vector<int> eiVec;
279  face::EFStarFF(Edges[i].f,Edges[i].z,fpVec,eiVec);
280  m.edge[i].EFp() = Edges[i].f;
281  m.edge[i].EFi() = Edges[i].z;
282  }
283  }
284 
285  if(tri::HasFEAdjacency(m))
286  {
287  for(size_t i=0; i< Edges.size(); ++i)
288  {
289  std::vector<FacePointer> fpVec;
290  std::vector<int> eiVec;
291  face::EFStarFF(Edges[i].f,Edges[i].z,fpVec,eiVec);
292  for(size_t j=0;j<fpVec.size();++j)
293  fpVec[j]->FEp(eiVec[j])=&(m.edge[i]);
294 
295 // Edges[i].f->FE(Edges[i].z) = &(m.edge[i]);
296 // Connect in loop the non manifold
297 // FaceType* fpit=fp;
298 // int eit=ei;
299 
300 // do
301 // {
302 // faceVec.push_back(fpit);
303 // indVed.push_back(eit);
304 // FaceType *new_fpit = fpit->FFp(eit);
305 // int new_eit = fpit->FFi(eit);
306 // fpit=new_fpit;
307 // eit=new_eit;
308 // } while(fpit != fp);
309 
310 
311 // m.edge[i].EFp() = Edges[i].f;
312 // m.edge[i].EFi() = ;
313  }
314  }
315 
316 }
317 
320 static void ClearTetraTetra (MeshType & m)
321 {
322  RequireTTAdjacency(m);
323  ForEachTetra(m, [] (TetraType & t) {
324  for (int i = 0; i < 4; ++i)
325  {
326  t.TTp(i) = NULL;
327  t.TTi(i) = -1;
328  }
329  });
330 }
331 
333 static void TetraTetra (MeshType & m)
334 {
335  RequireTTAdjacency(m);
336  if (m.tn == 0) return;
337 
338  std::vector<PFace> fvec;
339  FillFaceVector(m, fvec);
340  std::sort(fvec.begin(), fvec.end());
341 
342  int nf = 0;
343  typename std::vector<PFace>::iterator pback, pfront;
344  pback = fvec.begin();
345  pfront = fvec.begin();
346 
347  do
348  {
349  if (pfront == fvec.end() || !(*pfront == *pback))
350  {
351  typename std::vector<PFace>::iterator q, q_next;
352  for (q = pback; q < pfront - 1; ++q)
353  {
354  assert((*q).z >= 0);
355  q_next = q;
356  ++q_next;
357  assert((*q_next).z >= 0 && (*q_next).z < 4);
358 
359  (*q).t->TTp(q->z) = (*q_next).t;
360  (*q).t->TTi(q->z) = (*q_next).z;
361  }
362 
363  (*q).t->TTp(q->z) = pback->t;
364  (*q).t->TTi(q->z) = pback->z;
365  pback = pfront;
366  ++nf;
367  }
368  if (pfront == fvec.end()) break;
369  ++pfront;
370  } while (true);
371 }
374 static void ClearFaceFace(MeshType &m)
375 {
376  RequireFFAdjacency(m);
377  for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
378  {
379  if( ! (*fi).IsD() )
380  {
381  for(int j=0;j<fi->VN();++j)
382  {
383  fi->FFp(j)=0;
384  fi->FFi(j)=-1;
385  }
386  }
387  }
388 }
389 
391 static void FaceFace(MeshType &m)
392 {
393  RequireFFAdjacency(m);
394  if( m.fn == 0 ) return;
395 
396  std::vector<PEdge> e;
397  FillEdgeVector(m,e);
398  sort(e.begin(), e.end()); // Lo ordino per vertici
399 
400  int ne = 0; // Numero di edge reali
401 
402  typename std::vector<PEdge>::iterator pe,ps;
403  ps = e.begin();pe=e.begin();
404  //for(ps = e.begin(),pe=e.begin();pe<=e.end();++pe) // Scansione vettore ausiliario
405  do
406  {
407  if( pe==e.end() || !(*pe == *ps) ) // Trovo blocco di edge uguali
408  {
409  typename std::vector<PEdge>::iterator q,q_next;
410  for (q=ps;q<pe-1;++q) // Scansione facce associate
411  {
412  assert((*q).z>=0);
413  //assert((*q).z< 3);
414  q_next = q;
415  ++q_next;
416  assert((*q_next).z>=0);
417  assert((*q_next).z< (*q_next).f->VN());
418  (*q).f->FFp(q->z) = (*q_next).f; // Collegamento in lista delle facce
419  (*q).f->FFi(q->z) = (*q_next).z;
420  }
421  assert((*q).z>=0);
422  assert((*q).z< (*q).f->VN());
423  (*q).f->FFp((*q).z) = ps->f;
424  (*q).f->FFi((*q).z) = ps->z;
425  ps = pe;
426  ++ne; // Aggiorno il numero di edge
427  }
428  if(pe==e.end()) break;
429  ++pe;
430  } while(true);
431 }
432 
433 
435 static void VertexTetra(MeshType & m)
436 {
437  RequireVTAdjacency(m);
438 
439 
440  ForEachVertex(m, [] (VertexType & v) {
441  v.VTp() = NULL;
442  v.VTi() = 0;
443  });
444 
445  ForEachTetra(m, [] (TetraType & t) {
446  //this works like this: the first iteration defines the end of the chain
447  //then it backwards chains everything
448  for (int i = 0; i < 4; ++i)
449  {
450  t.VTp(i) = t.V(i)->VTp();
451  t.VTi(i) = t.V(i)->VTi();
452  t.V(i)->VTp() = &t;
453  t.V(i)->VTi() = i;
454  }
455  });
456 }
458 
465 static void VertexFace(MeshType &m)
466 {
467  RequireVFAdjacency(m);
468 
469  for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
470  {
471  (*vi).VFp() = 0;
472  (*vi).VFi() = 0; // note that (0,-1) means uninitiazlied while 0,0 is the valid initialized values for isolated vertices.
473  }
474 
475  for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
476  if( ! (*fi).IsD() )
477  {
478  for(int j=0;j<(*fi).VN();++j)
479  {
480  (*fi).VFp(j) = (*fi).V(j)->VFp();
481  (*fi).VFi(j) = (*fi).V(j)->VFi();
482  (*fi).V(j)->VFp() = &(*fi);
483  (*fi).V(j)->VFi() = j;
484  }
485  }
486 }
487 
488 
490 
492 
496 class PEdgeTex
497 {
498 public:
499 
500  typename FaceType::TexCoordType v[2]; // the two TexCoord are ordered!
501  FacePointer f; // the face where this edge belong
502  int z; // index in [0..2] of the edge of the face
503 
504  PEdgeTex() {}
505 
506  void Set( FacePointer pf, const int nz )
507  {
508  assert(pf!=0);
509  assert(nz>=0);
510  assert(nz<3);
511 
512  v[0] = pf->WT(nz);
513  v[1] = pf->WT(pf->Next(nz));
514  assert(v[0] != v[1]); // The face pointed by 'f' is Degenerate (two coincident vertexes)
515 
516  if( v[1] < v[0] ) std::swap(v[0],v[1]);
517  f = pf;
518  z = nz;
519  }
520 
521  inline bool operator < ( const PEdgeTex & pe ) const
522  {
523  if( v[0]<pe.v[0] ) return true;
524  else if( pe.v[0]<v[0] ) return false;
525  else return v[1] < pe.v[1];
526  }
527  inline bool operator == ( const PEdgeTex & pe ) const
528  {
529  return (v[0]==pe.v[0]) && (v[1]==pe.v[1]);
530  }
531  inline bool operator != ( const PEdgeTex & pe ) const
532  {
533  return (v[0]!=pe.v[0]) || (v[1]!=pe.v[1]);
534  }
535 
536 };
537 
538 
540 
546 static void FaceFaceFromTexCoord(MeshType &m)
547 {
548  RequireFFAdjacency(m);
549  RequirePerFaceWedgeTexCoord(m);
551  for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
552  {
553  if (!(*fi).IsD())
554  {
555  for (int i = 0; i < (*fi).VN(); i++)
556  {
557  if (!vcg::face::IsBorder((*fi), i))
558  {
559  typename MeshType::FacePointer nextFace = (*fi).FFp(i);
560  int nextEdgeIndex = (*fi).FFi(i);
561  bool border = false;
562  if ((*fi).cV(i) == nextFace->cV(nextEdgeIndex))
563  {
564  if ((*fi).WT(i) != nextFace->WT(nextEdgeIndex) || (*fi).WT((*fi).Next(i)) != nextFace->WT(nextFace->Next(nextEdgeIndex)))
565  border = true;
566  }
567  else
568  {
569  if ((*fi).WT(i) != nextFace->WT(nextFace->Next(nextEdgeIndex)) || (*fi).WT((*fi).Next(i)) != nextFace->WT(nextEdgeIndex))
570  border = true;
571  }
572  if (border)
573  vcg::face::FFDetach((*fi), i);
574 
575  }
576  }
577  }
578  }
579 }
580 
582 static void TestVertexEdge(MeshType &m)
583 {
584  std::vector<int> numVertex(m.vert.size(),0);
585 
586  tri::RequireVEAdjacency(m);
587 
588  for(EdgeIterator ei=m.edge.begin();ei!=m.edge.end();++ei)
589  {
590  if (!(*ei).IsD())
591  {
592  assert(tri::IsValidPointer(m,ei->V(0)));
593  assert(tri::IsValidPointer(m,ei->V(1)));
594  if(ei->VEp(0)) assert(tri::IsValidPointer(m,ei->VEp(0)));
595  if(ei->VEp(1)) assert(tri::IsValidPointer(m,ei->VEp(1)));
596  numVertex[tri::Index(m,(*ei).V(0))]++;
597  numVertex[tri::Index(m,(*ei).V(1))]++;
598  }
599  }
600 
601  for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
602  {
603  if (!vi->IsD())
604  {
605  int cnt =0;
606  for(edge::VEIterator<EdgeType> vei(&*vi);!vei.End();++vei)
607  cnt++;
608  assert((numVertex[tri::Index(m,*vi)] == 0) == (vi->VEp()==0) );
609  assert(cnt==numVertex[tri::Index(m,*vi)]);
610  }
611  }
612 }
613 
614 
616 static void TestVertexFace(MeshType &m)
617 {
618  SimpleTempData<typename MeshType::VertContainer, int > numVertex(m.vert,0);
619 
620  assert(tri::HasPerVertexVFAdjacency(m));
621 
622  for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
623  {
624  if (!(*fi).IsD())
625  {
626  numVertex[(*fi).V0(0)]++;
627  numVertex[(*fi).V1(0)]++;
628  numVertex[(*fi).V2(0)]++;
629  }
630  }
631 
632  vcg::face::VFIterator<FaceType> VFi;
633 
634  for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
635  {
636  if (!vi->IsD())
637  if(vi->VFp()!=0) // unreferenced vertices MUST have VF == 0;
638  {
639  int num=0;
640  assert(tri::IsValidPointer(m, vi->VFp()));
641  VFi.f=vi->VFp();
642  VFi.z=vi->VFi();
643  while (!VFi.End())
644  {
645  num++;
646  assert(!VFi.F()->IsD());
647  assert((VFi.F()->V(VFi.I()))==&(*vi));
648  ++VFi;
649  }
650  assert(num==numVertex[&(*vi)]);
651  }
652  }
653 }
654 
656 static void TestFaceFace(MeshType &m)
657 {
658  assert(HasFFAdjacency(m));
659 
660  for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
661  {
662  if (!fi->IsD())
663  {
664  for (int i=0;i<(*fi).VN();i++)
665  {
666  FaceType *ffpi=fi->FFp(i);
667  int e=fi->FFi(i);
668  //invariant property of FF topology for two manifold meshes
669  assert(ffpi->FFp(e) == &(*fi));
670  assert(ffpi->FFi(e) == i);
671 
672  // Test that the two faces shares the same edge
673  // Vertices of the i-th edges of the first face
674  VertexPointer v0i= fi->V0(i);
675  VertexPointer v1i= fi->V1(i);
676  // Vertices of the corresponding edge on the other face
677  VertexPointer ffv0i= ffpi->V0(e);
678  VertexPointer ffv1i= ffpi->V1(e);
679 
680  assert( (ffv0i==v0i) || (ffv0i==v1i) );
681  assert( (ffv1i==v0i) || (ffv1i==v1i) );
682  }
683 
684  }
685  }
686 }
687 
691 {
692 public:
693 
694  VertexPointer v; // the two Vertex pointer are ordered!
695  EdgePointer e; // the edge where this vertex belong
696  int z; // index in [0..1] of the vertex of the edge
697 
698  PVertexEdge( ) {}
699  PVertexEdge( EdgePointer pe, const int nz )
700 {
701  assert(pe!=0);
702  assert(nz>=0);
703  assert(nz<2);
704 
705  v= pe->V(nz);
706  e = pe;
707  z = nz;
708 }
709 inline bool operator < ( const PVertexEdge & pe ) const { return ( v<pe.v ); }
710 inline bool operator == ( const PVertexEdge & pe ) const { return ( v==pe.v ); }
711 inline bool operator != ( const PVertexEdge & pe ) const { return ( v!=pe.v ); }
712 };
713 
714 
715 
716 static void EdgeEdge(MeshType &m)
717 {
718  RequireEEAdjacency(m);
719  std::vector<PVertexEdge> v;
720  if( m.en == 0 ) return;
721 
722 // printf("Inserting Edges\n");
723  for(EdgeIterator pf=m.edge.begin(); pf!=m.edge.end(); ++pf) // Lo riempio con i dati delle facce
724  if( ! (*pf).IsD() )
725  for(int j=0;j<2;++j)
726  {
727 // printf("egde %i ind %i (%i %i)\n",tri::Index(m,&*pf),j,tri::Index(m,pf->V(0)),tri::Index(m,pf->V(1)));
728  v.push_back(PVertexEdge(&*pf,j));
729  }
730 
731 // printf("en = %i (%i)\n",m.en,m.edge.size());
732  sort(v.begin(), v.end()); // Lo ordino per vertici
733 
734  int ne = 0; // Numero di edge reali
735 
736  typename std::vector<PVertexEdge>::iterator pe,ps;
737  // for(ps = v.begin(),pe=v.begin();pe<=v.end();++pe) // Scansione vettore ausiliario
738  ps = v.begin();pe=v.begin();
739  do
740  {
741 // printf("v %i -> e %i\n",tri::Index(m,(*ps).v),tri::Index(m,(*ps).e));
742  if( pe==v.end() || !(*pe == *ps) ) // Trovo blocco di edge uguali
743  {
744  typename std::vector<PVertexEdge>::iterator q,q_next;
745  for (q=ps;q<pe-1;++q) // Scansione edge associati
746  {
747  assert((*q).z>=0);
748  assert((*q).z< 2);
749  q_next = q;
750  ++q_next;
751  assert((*q_next).z>=0);
752  assert((*q_next).z< 2);
753  (*q).e->EEp(q->z) = (*q_next).e; // Collegamento in lista delle facce
754  (*q).e->EEi(q->z) = (*q_next).z;
755  }
756  assert((*q).z>=0);
757  assert((*q).z< 2);
758  (*q).e->EEp((*q).z) = ps->e;
759  (*q).e->EEi((*q).z) = ps->z;
760  ps = pe;
761  ++ne; // Aggiorno il numero di edge
762  }
763  if(pe==v.end()) break;
764  ++pe;
765  } while(true);
766 }
767 
768 static void VertexEdge(MeshType &m)
769 {
770  RequireVEAdjacency(m);
771 
772  for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
773  {
774  (*vi).VEp() = 0;
775  (*vi).VEi() = 0;
776  }
777 
778  for(EdgeIterator ei=m.edge.begin();ei!=m.edge.end();++ei)
779  if( ! (*ei).IsD() )
780  {
781  for(int j=0;j<2;++j)
782  { assert(tri::IsValidPointer(m,ei->V(j)));
783  (*ei).VEp(j) = (*ei).V(j)->VEp();
784  (*ei).VEi(j) = (*ei).V(j)->VEi();
785  (*ei).V(j)->VEp() = &(*ei);
786  (*ei).V(j)->VEi() = j;
787  }
788  }
789 }
790 
791 }; // end class
792 
793 } // End namespace
794 } // End namespace
795 
796 
797 #endif