23 #ifndef __VCG_TRI_UPDATE_FLAGS
24 #define __VCG_TRI_UPDATE_FLAGS
26 #include <vcg/simplex/face/pos.h>
27 #include <vcg/simplex/tetrahedron/pos.h>
28 #include <vcg/simplex/edge/pos.h>
42 template <
class UpdateMeshType>
47 typedef UpdateMeshType MeshType;
48 typedef typename MeshType::ScalarType ScalarType;
49 typedef typename MeshType::VertexType VertexType;
50 typedef typename MeshType::VertexPointer VertexPointer;
51 typedef typename MeshType::VertexIterator VertexIterator;
52 typedef typename MeshType::EdgeType EdgeType;
53 typedef typename MeshType::EdgePointer EdgePointer;
54 typedef typename MeshType::EdgeIterator EdgeIterator;
55 typedef typename MeshType::FaceType FaceType;
56 typedef typename MeshType::FacePointer FacePointer;
57 typedef typename MeshType::FaceIterator FaceIterator;
58 typedef typename MeshType::TetraType TetraType;
59 typedef typename MeshType::TetraPointer TetraPointer;
60 typedef typename MeshType::TetraIterator TetraIterator;
66 if(HasPerVertexFlags(m) )
67 for(VertexIterator vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
69 if(HasPerEdgeFlags(m) )
70 for(EdgeIterator ei=m.edge.begin(); ei!=m.edge.end(); ++ei)
72 if(HasPerFaceFlags(m) )
73 for(FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi)
75 if(HasPerTetraFlags(m) )
76 for(TetraIterator ti=m.tetra.begin(); ti!=m.tetra.end(); ++ti)
81 static void VertexClear(MeshType &m,
unsigned int FlagMask = 0xffffffff)
83 RequirePerVertexFlags(m);
84 int andMask = ~FlagMask;
85 for(VertexIterator vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
86 if(!(*vi).IsD()) (*vi).Flags() &= andMask ;
89 static void EdgeClear(MeshType &m,
unsigned int FlagMask = 0xffffffff)
91 RequirePerEdgeFlags(m);
92 int andMask = ~FlagMask;
93 for(EdgeIterator ei=m.edge.begin(); ei!=m.edge.end(); ++ei)
94 if(!(*ei).IsD()) (*ei).Flags() &= andMask ;
97 static void FaceClear(MeshType &m,
unsigned int FlagMask = 0xffffffff)
99 RequirePerFaceFlags(m);
100 int andMask = ~FlagMask;
101 for(FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi)
102 if(!(*fi).IsD()) (*fi).Flags() &= andMask ;
105 static void TetraClear(MeshType &m,
unsigned int FlagMask = 0xffffffff)
107 RequirePerTetraFlags(m);
108 int andMask = ~FlagMask;
109 for(TetraIterator ti=m.tetra.begin(); ti!=m.tetra.end(); ++ti)
110 if(!(*ti).IsD()) (*ti).Flags() &= andMask ;
113 static void VertexSet(MeshType &m,
unsigned int FlagMask)
115 RequirePerVertexFlags(m);
116 for(VertexIterator vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
117 if(!(*vi).IsD()) (*vi).Flags() |= FlagMask ;
120 static void EdgeSet(MeshType &m,
unsigned int FlagMask)
122 RequirePerEdgeFlags(m);
123 for(EdgeIterator ei=m.edge.begin(); ei!=m.edge.end(); ++ei)
124 if(!(*ei).IsD()) (*ei).Flags() |= FlagMask ;
127 static void FaceSet(MeshType &m,
unsigned int FlagMask)
129 RequirePerFaceFlags(m);
130 for(FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi)
131 if(!(*fi).IsD()) (*fi).Flags() |= FlagMask ;
134 static void TetraSet(MeshType &m,
unsigned int FlagMask)
136 RequirePerTetraFlags(m);
137 for(TetraIterator ti=m.tetra.begin(); ti!=m.tetra.end(); ++ti)
138 if(!(*ti).IsD()) (*ti).Flags() |= FlagMask ;
143 static void VertexClearV(MeshType &m) { VertexClear(m,VertexType::VISITED);}
144 static void VertexClearS(MeshType &m) { VertexClear(m,VertexType::SELECTED);}
145 static void VertexClearB(MeshType &m) { VertexClear(m,VertexType::BORDER);}
146 static void EdgeClearV(MeshType &m) { EdgeClear(m,EdgeType::VISITED);}
147 static void FaceClearV(MeshType &m) { FaceClear(m,FaceType::VISITED);}
148 static void FaceClearB(MeshType &m) { FaceClear(m,FaceType::BORDER012);}
149 static void FaceClearS(MeshType &m) {FaceClear(m,FaceType::SELECTED);}
150 static void FaceClearF(MeshType &m) { FaceClear(m,FaceType::FAUX012);}
151 static void FaceClearFaceEdgeS(MeshType &m) { FaceClear(m,FaceType::FACEEDGESEL012 ); }
153 static void EdgeSetV(MeshType &m) { EdgeSet(m,EdgeType::VISITED);}
154 static void VertexSetV(MeshType &m) { VertexSet(m,VertexType::VISITED);}
155 static void VertexSetS(MeshType &m) { VertexSet(m,VertexType::SELECTED);}
156 static void VertexSetB(MeshType &m) { VertexSet(m,VertexType::BORDER);}
157 static void FaceSetV(MeshType &m) { FaceSet(m,FaceType::VISITED);}
158 static void FaceSetB(MeshType &m) { FaceSet(m,FaceType::BORDER);}
159 static void FaceSetF(MeshType &m) { FaceSet(m,FaceType::FAUX012);}
160 static void TetraClearV(MeshType &m) { TetraClear(m, TetraType::VISITED); }
161 static void TetraClearS(MeshType &m) { TetraClear(m, TetraType::SELECTED); }
162 static void TetraClearB(MeshType &m) { TetraClear(m, TetraType::BORDER0123); }
163 static void TetraSetV(MeshType &m) { TetraSet(m, TetraType::VISITED); }
164 static void TetraSetS(MeshType &m) { TetraSet(m, TetraType::SELECTED); }
165 static void TetraSetB(MeshType &m) { TetraSet(m, TetraType::BORDER0123); }
172 RequirePerFaceFlags(m);
173 RequireFFAdjacency(m);
175 for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
176 for(
int j=0;j<fi->VN();++j)
179 else (*fi).ClearB(j);
189 RequirePerTetraFlags(m);
190 RequireTTAdjacency(m);
192 for(TetraIterator ti=m.tetra.begin(); ti!=m.tetra.end(); ++ti)
194 for(
int j = 0; j < 4; ++j)
196 if (IsTTBorder(*ti,j)) (*ti).SetB(j);
197 else (*ti).ClearB(j);
201 static void VertexBorderFromTT(MeshType &m)
203 RequirePerVertexFlags(m);
204 RequireTTAdjacency(m);
208 for(TetraIterator ti=m.tetra.begin(); ti!=m.tetra.end(); ++ti)
210 for(
int j = 0; j < 4; ++j)
212 if (IsTTBorder(*ti,j))
214 for (
int i = 0; i < 3; ++i)
215 ti->V(Tetra::VofF(j, i))->SetB();
221 static void FaceBorderFromVF(MeshType &m)
223 RequirePerFaceFlags(m);
224 RequireVFAdjacency(m);
227 int visitedBit=VertexType::NewBitFlag();
233 const int BORDERFLAG[3]={FaceType::BORDER0, FaceType::BORDER1, FaceType::BORDER2};
235 for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
238 for(face::VFIterator<FaceType> vfi(&*vi) ; !vfi.End(); ++vfi )
240 vfi.f->V1(vfi.z)->ClearUserBit(visitedBit);
241 vfi.f->V2(vfi.z)->ClearUserBit(visitedBit);
243 for(face::VFIterator<FaceType> vfi(&*vi) ; !vfi.End(); ++vfi )
245 if(vfi.f->V1(vfi.z)->IsUserBit(visitedBit)) vfi.f->V1(vfi.z)->ClearUserBit(visitedBit);
246 else vfi.f->V1(vfi.z)->SetUserBit(visitedBit);
247 if(vfi.f->V2(vfi.z)->IsUserBit(visitedBit)) vfi.f->V2(vfi.z)->ClearUserBit(visitedBit);
248 else vfi.f->V2(vfi.z)->SetUserBit(visitedBit);
250 for(face::VFIterator<FaceType> vfi(&*vi) ; !vfi.End(); ++vfi )
252 if(vfi.f->V(vfi.z)< vfi.f->V1(vfi.z) && vfi.f->V1(vfi.z)->IsUserBit(visitedBit))
253 vfi.f->Flags() |= BORDERFLAG[vfi.z];
254 if(vfi.f->V(vfi.z)< vfi.f->V2(vfi.z) && vfi.f->V2(vfi.z)->IsUserBit(visitedBit))
255 vfi.f->Flags() |= BORDERFLAG[(vfi.z+2)%3];
258 VertexType::DeleteBitFlag(visitedBit);
273 void Set(
const FacePointer pf,
const int nz )
280 v[1] = pf->V((nz+1)%3);
281 assert(v[0] != v[1]);
283 if( v[0] > v[1] ) std::swap(v[0],v[1]);
288 inline bool operator < (
const EdgeSorter & pe )
const {
289 if( v[0]<pe.v[0] )
return true;
290 else if( v[0]>pe.v[0] )
return false;
291 else return v[1] < pe.v[1];
294 inline bool operator == (
const EdgeSorter & pe )
const
296 return v[0]==pe.v[0] && v[1]==pe.v[1];
298 inline bool operator != (
const EdgeSorter & pe )
const
300 return v[0]!=pe.v[0] || v[1]!=pe.v[1];
307 static void VertexBorderFromNone(MeshType &m)
309 RequirePerVertexFlags(m);
311 std::vector<EdgeSorter> e;
312 typename UpdateMeshType::FaceIterator pf;
313 typename std::vector<EdgeSorter>::iterator p;
320 for(pf=m.face.begin();pf!=m.face.end();++pf)
329 sort(e.begin(), e.end());
331 typename std::vector<EdgeSorter>::iterator pe,ps;
332 for(ps = e.begin(), pe = e.begin(); pe < e.end(); ++pe)
334 if( pe==e.end() || *pe != *ps )
355 RequirePerFaceFlags(m);
357 std::vector<EdgeSorter> e;
358 typename UpdateMeshType::FaceIterator pf;
359 typename std::vector<EdgeSorter>::iterator p;
361 for(VertexIterator v=m.vert.begin();v!=m.vert.end();++v)
369 for(fi = m.face.begin(); fi != m.face.end(); ++fi)
if(! (*fi).IsD()) n_edges+=(*fi).VN();
373 for(pf=m.face.begin();pf!=m.face.end();++pf)
375 for(
int j=0;j<(*pf).VN();++j)
382 sort(e.begin(), e.end());
384 typename std::vector<EdgeSorter>::iterator pe,ps;
385 ps = e.begin();pe=e.begin();
388 if( pe==e.end() || *pe != *ps )
399 if(pe==e.end())
break;
408 RequirePerFaceFlags(m);
409 RequirePerVertexFlags(m);
410 RequireFFAdjacency(m);
414 for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
418 for(
int z=0;z<(*fi).VN();++z)
430 RequirePerFaceFlags(m);
431 RequirePerVertexFlags(m);
433 for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
436 for(
int z=0;z<(*fi).VN();++z)
440 (*fi).V((*fi).Next(z))->SetB();
448 RequirePerVertexFlags(m);
449 RequireEEAdjacency(m);
452 for (EdgeIterator ei=m.edge.begin();ei!=m.edge.end();++ei)
455 for (
int z=0; z<2; ++z)
456 if (edge::IsEdgeBorder(*ei, z))
474 RequirePerFaceFlags(m);
475 RequireFFAdjacency(m);
477 FaceClearFaceEdgeS(m);
479 for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
481 for(
int z=0;z<(*fi).VN();++z)
485 ScalarType angle = DihedralAngleRad(*fi,z);
486 if(angle<AngleRadNeg || angle>AngleRadPos)
487 (*fi).SetFaceEdgeS(z);
491 if(MarkBorderFlag) (*fi).SetFaceEdgeS(z);
501 RequirePerFaceFlags(m);
502 RequireFFAdjacency(m);
504 FaceClearFaceEdgeS(m);
505 for (FaceIterator fi=m.face.begin(); fi!=m.face.end();++fi)
508 for (
int z=0; z<(*fi).VN(); ++z)
Management, updating and computation of per-vertex and per-face flags (like border flags).
Definition: flag.h:44
static void VertexBorderFromFaceAdj(MeshType &m)
Compute the PerVertex Border flag deriving it from the face-face adjacency.
Definition: flag.h:406
static void FaceEdgeSelSignedCrease(MeshType &m, float AngleRadNeg, float AngleRadPos, bool MarkBorderFlag=false)
Marks feature edges according to two signed dihedral angles. Actually it uses the face_edge selection...
Definition: flag.h:472
static void Clear(MeshType &m)
Reset all the mesh flags (vertexes edge faces) setting everithing to zero (the default value for flag...
Definition: flag.h:64
static void FaceEdgeSelCrease(MeshType &m, float AngleRad)
Marks feature edges according to a given angle Actually it uses the face_edge selection bit on faces,...
Definition: flag.h:521
static void FaceBorderFromNone(MeshType &m)
Definition: flag.h:353
static void VertexBorderFromFaceBorder(MeshType &m)
Compute the PerVertex Border flag deriving it from the border flag of faces.
Definition: flag.h:428
static void FaceBorderFromFF(MeshType &m)
Compute the border flags for the faces using the Face-Face Topology.
Definition: flag.h:170
static void TetraBorderFromTT(MeshType &m)
Compute the border flags for the tetras using the Tetra-Tetra Topology.
Definition: flag.h:187
static void FaceEdgeSelBorder(MeshType &m)
Selects feature edges according to Face adjacency.
Definition: flag.h:499
static void VertexBorderFromEdgeAdj(MeshType &m)
Compute the PerVertex Border flag deriving it from the Edge-Edge adjacency (made for edgemeshes)
Definition: flag.h:446
bool IsBorder(FaceType const &f, const int j)
Definition: topology.h:55
Definition: namespaces.dox:6