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
00026
00027
00028
00029 #ifndef __VCG_EDGEMESH_CLOSEST
00030 #define __VCG_EDGEMESH_CLOSEST
00031 #include <math.h>
00032
00033 #include <vcg/space/point3.h>
00034 #include <vcg/space/box3.h>
00035 #include <vcg/space/point4.h>
00036 #include <vcg/math/base.h>
00037 #include <vcg/simplex/edge/distance.h>
00038 #include <vcg/simplex/vertex/distance.h>
00039 #include <vcg/space/intersection3.h>
00040 #include <vcg/space/index/space_iterators.h>
00041
00042 namespace vcg {
00043 namespace edgemesh {
00044
00045
00046 template <class MESH_TYPE,class OBJ_TYPE>
00047 class Tmark
00048 {
00049 MESH_TYPE *m;
00050 public:
00051 Tmark(){}
00052 void UnMarkAll(){m->UnMarkAll();}
00053 bool IsMarked(OBJ_TYPE* obj){return (m->IsMarked(obj));}
00054 void Mark(OBJ_TYPE* obj){m->Mark(obj);}
00055 void SetMesh(MESH_TYPE *_m)
00056 {m=_m;}
00057 };
00058
00059 template <class MESH_TYPE>
00060 class EdgeTmark:public Tmark<MESH_TYPE,typename MESH_TYPE::EdgeType>
00061 {};
00062
00063 template <class MESH_TYPE>
00064 class VertTmark:public Tmark<MESH_TYPE,typename MESH_TYPE::VertexType>
00065 {};
00066
00067
00068
00069 template <class MESH, class GRID>
00070 typename MESH::EdgeType * GetClosestEdge( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p,
00071 const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist,
00072 typename GRID::CoordType &_closestPt)
00073 {
00074 typedef typename GRID::ScalarType ScalarType;
00075 typedef Point3<ScalarType> Point3x;
00076 typedef EdgeTmark<MESH> MarkerEdge;
00077 MarkerEdge mf;
00078 mf.SetMesh(&mesh);
00079 vcg::edge::PointDistanceFunctor<ScalarType> PDistFunct;
00080 _minDist=_maxDist;
00081 return (gr.GetClosest(PDistFunct,mf,_p,_maxDist,_minDist,_closestPt));
00082 }
00083
00084 template <class MESH, class GRID>
00085 typename MESH::VertexType * GetClosestVertex( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p,
00086 const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist )
00087 {
00088 typedef typename GRID::ScalarType ScalarType;
00089 typedef Point3<ScalarType> Point3x;
00090 typedef VertTmark<MESH> MarkerVert;
00091 MarkerVert mv;
00092 mv.SetMesh(&mesh);
00093 typedef vcg::vertex::PointDistanceFunctor<ScalarType> VDistFunct;
00094 _minDist=_maxDist;
00095 Point3x _closestPt;
00096 return (gr.GetClosest(VDistFunct(),mv,_p,_maxDist,_minDist,_closestPt));
00097 }
00098
00099 template <class MESH, class GRID, class OBJPTRCONTAINER,class DISTCONTAINER, class POINTCONTAINER>
00100 unsigned int GetKClosestEdge(MESH & mesh,GRID & gr, const unsigned int _k,
00101 const typename GRID::CoordType & _p, const typename GRID::ScalarType & _maxDist,
00102 OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points)
00103 {
00104 typedef typename GRID::ScalarType ScalarType;
00105 typedef EdgeTmark<MESH> MarkerEdge;
00106 MarkerEdge mf;
00107 mf.SetMesh(&mesh);
00108 vcg::face::PointDistanceFunctor<ScalarType> FDistFunct;
00109 return (gr.GetKClosest
00110 (FDistFunct,mf,_k,_p,_maxDist,_objectPtrs,_distances,_points));
00111 }
00112
00113 template <class MESH, class GRID, class OBJPTRCONTAINER,class DISTCONTAINER, class POINTCONTAINER>
00114 unsigned int GetKClosestVertex(MESH & mesh,GRID & gr, const unsigned int _k,
00115 const typename GRID::CoordType & _p, const typename GRID::ScalarType & _maxDist,
00116 OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points)
00117 {
00118 typedef typename GRID::ScalarType ScalarType;
00119 typedef VertTmark<MESH> MarkerVert;
00120 MarkerVert mv;
00121 mv.SetMesh(&mesh);
00122 typedef vcg::vertex::PointDistanceFunctor<ScalarType> VDistFunct;
00123 return (gr.GetKClosest
00124 (VDistFunct(),mv,_k,_p,_maxDist,_objectPtrs,_distances,_points));
00125 }
00126
00127
00128 template <class MESH, class GRID, class OBJPTRCONTAINER, class DISTCONTAINER, class POINTCONTAINER>
00129 unsigned int GetInSphereVertex(MESH & mesh,
00130 GRID & gr,
00131 const typename GRID::CoordType & _p,
00132 const typename GRID::ScalarType & _r,
00133 OBJPTRCONTAINER & _objectPtrs,
00134 DISTCONTAINER & _distances,
00135 POINTCONTAINER & _points)
00136 {
00137 typedef typename GRID::ScalarType ScalarType;
00138 typedef VertTmark<MESH> MarkerVert;
00139 MarkerVert mv;
00140 mv.SetMesh(&mesh);
00141 typedef vcg::vertex::PointDistanceFunctor<ScalarType> VDistFunct;
00142 return (gr.GetInSphere
00143 (VDistFunct(),mv,_p,_r,_objectPtrs,_distances,_points));
00144 }
00145
00146 template <class MESH, class GRID, class OBJPTRCONTAINER>
00147 unsigned int GetInBoxEdge(MESH & mesh,
00148 GRID & gr,
00149 const vcg::Box3<typename GRID::ScalarType> _bbox,
00150 OBJPTRCONTAINER & _objectPtrs)
00151 {
00152 typedef EdgeTmark<MESH> EdgeTmark;
00153 EdgeTmark mf;
00154 mf.SetMesh(&mesh);
00155 return(gr.GetInBox(mf,_bbox,_objectPtrs));
00156 }
00157
00158 template <class MESH, class GRID, class OBJPTRCONTAINER>
00159 unsigned int GetInBoxVertex(MESH & mesh,
00160 GRID & gr,
00161 const vcg::Box3<typename GRID::ScalarType> _bbox,
00162 OBJPTRCONTAINER & _objectPtrs)
00163 {
00164 typedef VertTmark<MESH> MarkerVert;
00165 MarkerVert mv;
00166 mv.SetMesh(&mesh);
00167 return(gr.GetInBox(mv,_bbox,_objectPtrs));
00168 }
00169
00170
00171 }
00172 }
00173
00174 #endif