00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __VCG_VERTEXMESH_CLOSEST
00026 #define __VCG_VERTEXMESH_CLOSEST
00027 #include <math.h>
00028
00029 #include <vcg/space/point3.h>
00030 #include <vcg/space/box3.h>
00031 #include <vcg/space/point4.h>
00032 #include <vcg/math/base.h>
00033 #include <vcg/simplex/face/distance.h>
00034 #include <vcg/simplex/vertex/distance.h>
00035 #include <vcg/space/intersection3.h>
00036 #include <vcg/space/index/space_iterators.h>
00037
00038 namespace vcg {
00039 namespace vrt {
00040
00041
00042 template <class MESH_TYPE,class OBJ_TYPE>
00043 class Tmark
00044 {
00045 MESH_TYPE *m;
00046 public:
00047 Tmark(){}
00048 void UnMarkAll(){m->UnMarkAll();}
00049 bool IsMarked(OBJ_TYPE* obj){return (m->IsMarked(obj));}
00050 void Mark(OBJ_TYPE* obj){m->Mark(obj);}
00051 void SetMesh(MESH_TYPE *_m)
00052 {m=_m;}
00053 };
00054
00055
00056 template <class MESH_TYPE>
00057 class VertTmark:public Tmark<MESH_TYPE,typename MESH_TYPE::VertexType>
00058 {};
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 template <class MESH, class GRID>
00077 typename MESH::VertexType * GetClosestVertex( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p,
00078 const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist )
00079 {
00080 typedef typename GRID::ScalarType ScalarType;
00081 typedef Point3<ScalarType> Point3x;
00082 typedef VertTmark<MESH> MarkerVert;
00083 MarkerVert mv;
00084 mv.SetMesh(&mesh);
00085 typedef PointDistanceFunctor VDistFunct;
00086 _minDist=_maxDist;
00087 Point3x _closestPt;
00088 return (gr.GetClosest(PointDistanceFunctor(),mv,_p,_maxDist,_minDist,_closestPt));
00089 }
00090
00091
00092 template <class MESH, class GRID, class OBJPTRCONTAINER,class DISTCONTAINER, class POINTCONTAINER>
00093 unsigned int GetKClosestVertex(MESH & mesh,GRID & gr, const unsigned int _k,
00094 const typename GRID::CoordType & _p, const typename GRID::ScalarType & _maxDist,
00095 OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points)
00096 {
00097 typedef VertTmark<MESH> MarkerVert;
00098 MarkerVert mv;
00099 mv.SetMesh(&mesh);
00100 typedef vcg::vert::PointDistanceFunctor VDistFunct;
00101 return (gr.GetKClosest
00102 (VDistFunct(),mv,_k,_p,_maxDist,_objectPtrs,_distances,_points));
00103 }
00104
00105 template <class MESH, class GRID, class OBJPTRCONTAINER, class DISTCONTAINER, class POINTCONTAINER>
00106 unsigned int GetInSphereVertex(MESH & mesh,
00107 GRID & gr,
00108 const typename GRID::CoordType & _p,
00109 const typename GRID::ScalarType & _r,
00110 OBJPTRCONTAINER & _objectPtrs,
00111 DISTCONTAINER & _distances,
00112 POINTCONTAINER & _points)
00113 {
00114 typedef VertTmark<MESH> MarkerVert;
00115 MarkerVert mv;
00116 mv.SetMesh(&mesh);
00117 typedef vcg::vert::PointDistanceFunctor VDistFunct;
00118 return (gr.GetInSphere
00119 (VDistFunct(),mv,_p,_r,_objectPtrs,_distances,_points));
00120 }
00121
00122
00123 template <class MESH, class GRID, class OBJPTRCONTAINER>
00124 unsigned int GetInBoxVertex(MESH & mesh,
00125 GRID & gr,
00126 const vcg::Box3<typename GRID::ScalarType> _bbox,
00127 OBJPTRCONTAINER & _objectPtrs)
00128 {
00129 typedef VertTmark<MESH> MarkerVert;
00130 MarkerVert mv;
00131 mv.SetMesh(&mesh);
00132 return(gr.GetInBox(mv,_bbox,_objectPtrs));
00133 }
00134
00135
00136
00137
00138 template <class GRID,class MESH>
00139 class ClosestVertexIterator:public vcg::ClosestIterator<GRID,vcg::vert::PointDistanceFunctor, VertTmark<MESH> >
00140 {
00141 public:
00142 typedef GRID GridType;
00143 typedef MESH MeshType;
00144 typedef VertTmark<MESH> MarkerVert;
00145 typedef vcg::vert::PointDistanceFunctor VDistFunct;
00146 typedef vcg::ClosestIterator<GRID,VDistFunct, VertTmark<MESH> > ClosestBaseType;
00147
00148 ClosestVertexIterator(GridType &_Si):ClosestBaseType(_Si,VDistFunct()){}
00149
00150 void SetMesh(MeshType *m)
00151 {tm.SetMesh(m);}
00152 };
00153
00154
00155 }
00156 }
00157
00158 #endif