23 #ifndef __VCG_TRI_UPDATE_SELECTION
24 #define __VCG_TRI_UPDATE_SELECTION
28 #include <vcg/complex/base.h>
29 #include <vcg/simplex/face/topology.h>
41 template <
class ComputeMeshType>
44 typedef typename ComputeMeshType::template PerVertexAttributeHandle< bool > vsHandle;
45 typedef typename ComputeMeshType::template PerEdgeAttributeHandle< bool > esHandle;
46 typedef typename ComputeMeshType::template PerFaceAttributeHandle< bool > fsHandle;
47 typedef typename ComputeMeshType::template PerTetraAttributeHandle< bool > tsHandle;
62 typename ComputeMeshType::VertexIterator vi;
63 for(vi = _m->vert.begin(); vi != _m->vert.end(); ++vi)
64 if( !(*vi).IsD() ) vsH[*vi] = (*vi).IsS() ;
66 typename ComputeMeshType::EdgeIterator ei;
67 for(ei = _m->edge.begin(); ei != _m->edge.end(); ++ei)
68 if( !(*ei).IsD() ) esH[*ei] = (*ei).IsS() ;
70 typename ComputeMeshType::FaceIterator fi;
71 for(fi = _m->face.begin(); fi != _m->face.end(); ++fi)
72 if( !(*fi).IsD() ) fsH[*fi] = (*fi).IsS() ;
74 typename ComputeMeshType::TetraIterator ti;
75 for(ti = _m->tetra.begin(); ti != _m->tetra.end(); ++ti)
76 if( !(*ti).IsD() ) tsH[*ti] = (*ti).IsS() ;
87 return pop(
true,
false);
92 return pop(
false,
true);
99 bool pop(
bool orFlag=
false,
bool andFlag=
false)
101 if(vsV.empty())
return false;
102 if(orFlag && andFlag)
return false;
104 vsHandle vsH = vsV.back();
105 esHandle esH = esV.back();
106 fsHandle fsH = fsV.back();
107 tsHandle tsH = tsV.back();
111 for(
auto vi = _m->vert.begin(); vi != _m->vert.end(); ++vi)
115 if(!andFlag) (*vi).SetS();
117 if(!orFlag) (*vi).ClearS();
121 for(
auto ei = _m->edge.begin(); ei != _m->edge.end(); ++ei)
125 if(!andFlag) (*ei).SetS();
127 if(!orFlag) (*ei).ClearS();
132 for(
auto fi = _m->face.begin(); fi != _m->face.end(); ++fi)
136 if(!andFlag) (*fi).SetS();
138 if(!orFlag) (*fi).ClearS();
142 for (
auto ti = _m->tetra.begin(); ti != _m->tetra.end(); ++ti)
146 if (!andFlag) (*ti).SetS();
148 if (!orFlag) (*ti).ClearS();
166 std::vector<vsHandle> vsV;
167 std::vector<esHandle> esV;
168 std::vector<fsHandle> fsV;
169 std::vector<tsHandle> tsV;
182 template <
class ComputeMeshType>
187 typedef ComputeMeshType MeshType;
188 typedef typename MeshType::ScalarType ScalarType;
189 typedef typename MeshType::VertexType VertexType;
190 typedef typename MeshType::VertexPointer VertexPointer;
191 typedef typename MeshType::VertexIterator VertexIterator;
192 typedef typename MeshType::EdgeIterator EdgeIterator;
193 typedef typename MeshType::EdgeType EdgeType;
194 typedef typename MeshType::FaceType FaceType;
195 typedef typename MeshType::FacePointer FacePointer;
196 typedef typename MeshType::FaceIterator FaceIterator;
197 typedef typename MeshType::TetraType TetraType;
198 typedef typename MeshType::TetraPointer TetraPointer;
199 typedef typename MeshType::TetraIterator TetraIterator;
206 for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi)
207 if( !(*vi).IsD() ) (*vi).SetS();
214 for(EdgeIterator ei = m.edge.begin(); ei != m.edge.end(); ++ei)
215 if( !(*ei).IsD() ) (*ei).SetS();
221 for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
222 if( !(*fi).IsD() ) (*fi).SetS();
239 for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi)
240 if( !(*vi).IsD() ) (*vi).ClearS();
247 for(EdgeIterator ei = m.edge.begin(); ei != m.edge.end(); ++ei)
248 if( !(*ei).IsD() ) (*ei).ClearS();
255 for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
256 if( !(*fi).IsD() ) (*fi).ClearS();
284 if(f.IsS()) ++selCnt;
294 if(e.IsS()) ++selCnt;
304 if(v.IsS()) ++selCnt;
314 if (t.IsS()) ++selCnt;
323 for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
326 if((*fi).IsS()) (*fi).ClearS();
339 for(EdgeIterator ei=m.edge.begin();ei!=m.edge.end();++ei)
342 if((*ei).IsS()) (*ei).ClearS();
355 for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
358 if((*vi).IsS()) (*vi).ClearS();
391 for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
392 if( !(*fi).IsD() && (*fi).IsS())
393 for(
int i = 0; i < (*fi).VN(); ++i)
394 if( !(*fi).V(i)->IsS()) { (*fi).V(i)->SetS(); ++selCnt; }
404 for(EdgeIterator ei = m.edge.begin(); ei != m.edge.end(); ++ei)
405 if( !(*ei).IsD() && (*ei).IsS())
407 if( !(*ei).V(0)->IsS()) { (*ei).V(0)->SetS(); ++selCnt; }
408 if( !(*ei).V(1)->IsS()) { (*ei).V(1)->SetS(); ++selCnt; }
419 if(preserveSelection) ss.push();
421 for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
422 if( !(*fi).IsD() && !(*fi).IsS())
423 for(
int i = 0; i < (*fi).VN(); ++i)
424 (*fi).V(i)->ClearS();
426 if(preserveSelection) ss.popOr();
434 if(preserveSelection) ss.push();
437 for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
441 for(
int i = 0; i < (*fi).VN(); ++i)
442 if(!(*fi).V(i)->IsS())
451 if(preserveSelection) ss.popOr();
460 for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
464 for(
int i = 0; i < (*fi).VN(); ++i)
465 if((*fi).V(i)->IsS())
497 for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi)
512 tri::RequireTriangularMesh(m);
515 for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
519 for(
int i = 0; i < 3; ++i)
520 if((*fi).IsB(i)) bordFlag=
true;
532 static size_t FaceOutOfRangeEdge(MeshType &m, ScalarType MinEdgeThr, ScalarType MaxEdgeThr=(std::numeric_limits<ScalarType>::max)(),
bool preserveSelection=
false)
536 MinEdgeThr=MinEdgeThr*MinEdgeThr;
537 MaxEdgeThr=MaxEdgeThr*MaxEdgeThr;
538 for(FaceIterator fi=m.face.begin(); fi!=m.face.end();++fi)
541 for(
int i=0;i<(*fi).VN();++i)
543 const ScalarType squaredEdge=SquaredDistance((*fi).V0(i)->cP(),(*fi).V1(i)->cP());
544 if((squaredEdge<=MinEdgeThr) || (squaredEdge>=MaxEdgeThr) )
559 RequireFFAdjacency(m);
562 std::deque<FacePointer> visitStack;
564 for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
565 if( !(*fi).IsD() && (*fi).IsS() && !(*fi).IsV() )
566 visitStack.push_back(&*fi);
568 while(!visitStack.empty())
570 FacePointer fp = visitStack.front();
571 visitStack.pop_front();
574 for(
int i=0;i<fp->VN();++i) {
575 FacePointer ff = fp->FFp(i);
580 visitStack.push_back(ff);
592 RequirePerFaceQuality(m);
593 for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
596 if( (*fi).Q()>=minq && (*fi).Q()<=maxq )
610 RequirePerVertexQuality(m);
611 for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
614 if( (*vi).Q()>=minq && (*vi).Q()<=maxq )
628 for (VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi)
if(!(*vi).IsD())
630 if(bb.
IsIn((*vi).cP()) ) {
644 SimpleTempData<typename MeshType::VertContainer, ScalarType > angleSumH(m.vert,0);
646 for(
auto vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!(*vi).IsD())
649 for(
auto fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
651 for(
int i=0;i<(*fi).VN();++i)
655 for(
auto vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!(*vi).IsD())
657 if(angleSumH[vi]<angleRad && vi->IsB())
667 void VertexNonManifoldEdges(MeshType &m,
bool preserveSelection=
false)
669 tri::RequireFFAdjacency(m);
672 for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
if (!fi->IsD())
674 for(
int i=0;i<fi->VN();++i)
675 if(!IsManifold(*fi,i)){
bool IsIn(const Point3< BoxScalarType > &p) const
Definition: box3.h:194
Class to safely add and delete elements in a mesh.
Definition: allocate.h:97
A stack for saving and restoring selection.
Definition: selection.h:43
bool pop(bool orFlag=false, bool andFlag=false)
Definition: selection.h:99
Management, updating and computation of per-vertex and per-face flags (like border flags).
Definition: flag.h:44
Management, updating and conditional computation of selections (per-vertex, per-edge,...
Definition: selection.h:184
static size_t FaceFromVertexStrict(MeshType &m, bool preserveSelection=false)
Select ONLY the faces with ALL the vertices selected.
Definition: selection.h:431
static size_t FaceErode(MeshType &m)
This function erode the face selection by simply first selecting only the vertices completely surroun...
Definition: selection.h:485
static size_t VertexInvert(MeshType &m)
This function inverts the selection flag for all the vertices.
Definition: selection.h:352
static size_t TetraAll(MeshType &m)
This function select all the tetras.
Definition: selection.h:227
static size_t VertexCount(const MeshType &m)
This function returns the number of selected vertices.
Definition: selection.h:300
static size_t FaceFromQualityRange(MeshType &m, float minq, float maxq, bool preserveSelection=false)
Select the faces whose quality is in the specified closed interval.
Definition: selection.h:588
static size_t FaceOutOfRangeEdge(MeshType &m, ScalarType MinEdgeThr, ScalarType MaxEdgeThr=(std::numeric_limits< ScalarType >::max)(), bool preserveSelection=false)
This function select the faces that have an edge outside the given range. You can skip the second par...
Definition: selection.h:532
static void Clear(MeshType &m)
This function clears the selection flag for all the elements of a mesh (vertices, edges,...
Definition: selection.h:271
static size_t EdgeClear(MeshType &m)
This function clears the selection flag for all the edges.
Definition: selection.h:245
static size_t VertexFromFaceStrict(MeshType &m, bool preserveSelection=false)
Select ONLY the vertices that are touched ONLY by selected faces.
Definition: selection.h:416
static size_t FaceConnectedFF(MeshType &m)
This function expand current selection to cover the whole connected component.
Definition: selection.h:556
static size_t VertexFromBorderFlag(MeshType &m, bool preserveSelection=false)
This function select the vertices with the border flag set.
Definition: selection.h:493
static size_t EdgeCount(const MeshType &m)
This function returns the number of selected edges.
Definition: selection.h:290
static size_t TetraCount(const MeshType &m)
This function returns the number of selected tetras.
Definition: selection.h:310
static size_t VertexClear(MeshType &m)
This function clear the selection flag for all the vertices.
Definition: selection.h:237
static size_t TetraClear(MeshType &m)
This function clears the selection flag for all the tetras.
Definition: selection.h:261
static size_t VertexFromQualityRange(MeshType &m, float minq, float maxq, bool preserveSelection=false)
Select the vertices whose quality is in the specified closed interval.
Definition: selection.h:606
static size_t FaceFromBorderFlag(MeshType &m, bool preserveSelection=false)
This function select the faces that have an edge with the border flag set.
Definition: selection.h:510
static size_t FaceCount(const MeshType &m)
This function returns the number of selected faces.
Definition: selection.h:280
static size_t EdgeAll(MeshType &m)
This function select all the edges.
Definition: selection.h:212
static size_t VertexCornerBorder(MeshType &m, ScalarType angleRad, bool preserveSelection=false)
Select the border vertices that form a corner along the border with an angle that is below a certain ...
Definition: selection.h:641
static size_t FaceDilate(MeshType &m)
This function dilate the face selection by simply first selecting all the vertices touched by the fac...
Definition: selection.h:477
static size_t VertexFromEdgeLoose(MeshType &m, bool preserveSelection=false)
Select all the vertices that are touched by at least a single selected edge.
Definition: selection.h:399
static size_t FaceAll(MeshType &m)
This function select all the faces.
Definition: selection.h:219
static size_t VertexAll(MeshType &m)
This function select all the vertices.
Definition: selection.h:204
static size_t EdgeInvert(MeshType &m)
This function inverts the selection flag for all the edges.
Definition: selection.h:336
static size_t FaceClear(MeshType &m)
This function clears the selection flag for all the faces.
Definition: selection.h:253
static size_t VertexInBox(MeshType &m, const Box3Type &bb, bool preserveSelection=false)
Select the vertices contained in the specified Box.
Definition: selection.h:624
static size_t FaceFromVertexLoose(MeshType &m, bool preserveSelection=false)
Select all the faces with at least one selected vertex.
Definition: selection.h:456
static size_t TetraInvert(MeshType &m)
This function inverts the selection flag for all the tetras.
Definition: selection.h:368
static size_t FaceInvert(MeshType &m)
This function inverts the selection flag for all the faces.
Definition: selection.h:320
static size_t VertexFromFaceLoose(MeshType &m, bool preserveSelection=false)
Select all the vertices that are touched by at least a single selected faces.
Definition: selection.h:386
void ForEachTetra(const MeshType &m, Callable action)
Definition: foreach.h:270
void ForEachEdge(const MeshType &m, Callable action)
Definition: foreach.h:222
void ForEachFace(const MeshType &m, Callable action)
Definition: foreach.h:78
void ForEachVertex(const MeshType &m, Callable action)
Definition: foreach.h:126
FaceType::ScalarType WedgeAngleRad(FaceType &f, const int i)
Return the internal angle (in radians) of the i-th wedge of the triangle.
Definition: topology.h:118
Definition: namespaces.dox:6