added DoRay and Closest Point queries
This commit is contained in:
parent
8909e9205a
commit
3c6625d060
|
@ -24,7 +24,8 @@
|
||||||
#ifndef __VCGLIB_GRID_CLOSEST
|
#ifndef __VCGLIB_GRID_CLOSEST
|
||||||
#define __VCGLIB_GRID_CLOSEST
|
#define __VCGLIB_GRID_CLOSEST
|
||||||
|
|
||||||
#include <vcg/space/index/space_iterators.h>
|
#include <vcg/space/index/index2D/space_iterators_2D.h>
|
||||||
|
#include <vcg/space/intersection2.h>
|
||||||
|
|
||||||
namespace vcg{
|
namespace vcg{
|
||||||
|
|
||||||
|
@ -60,77 +61,139 @@ namespace vcg{
|
||||||
{
|
{
|
||||||
typename SPATIALINDEXING::ObjPtr elem=&(**l);
|
typename SPATIALINDEXING::ObjPtr elem=&(**l);
|
||||||
vcg::Box2<typename SPATIALINDEXING::ScalarType> box_elem;
|
vcg::Box2<typename SPATIALINDEXING::ScalarType> box_elem;
|
||||||
elem->GetBBox(box_elem);
|
box_elem=elem->BBox();
|
||||||
if(( ! _marker.IsMarked(elem))&&(box_elem.Collide(_bbox))){
|
if (update_global_mark)
|
||||||
|
{
|
||||||
|
if(( ! _marker.IsMarked(elem))&&(box_elem.Collide(_bbox)))
|
||||||
|
{
|
||||||
_objectPtrs.push_back(elem);
|
_objectPtrs.push_back(elem);
|
||||||
_marker.Mark(elem);
|
_marker.Mark(elem);
|
||||||
}
|
}
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
if(box_elem.Collide(_bbox))
|
||||||
|
_objectPtrs.push_back(elem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (static_cast<unsigned int>(_objectPtrs.size()));
|
return (static_cast<unsigned int>(_objectPtrs.size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*template <class SPATIALINDEXING,class OBJMARKER, class OBJPTRCONTAINER>
|
template <class SPATIAL_INDEX, class OBJPOINTDISTFUNCTOR, class OBJMARKER>
|
||||||
unsigned int GridGetInBoxes2D(SPATIALINDEXING &_Si,
|
typename SPATIAL_INDEX::ObjPtr GridClosest2D(SPATIAL_INDEX &Si,
|
||||||
|
OBJPOINTDISTFUNCTOR _getPointDistance,
|
||||||
OBJMARKER & _marker,
|
OBJMARKER & _marker,
|
||||||
const std::vector<vcg::Box2<typename SPATIALINDEXING::ScalarType> > &_bbox,
|
const typename OBJPOINTDISTFUNCTOR::QueryType & _p_obj,
|
||||||
OBJPTRCONTAINER & _objectPtrs)
|
const typename SPATIAL_INDEX::ScalarType & _maxDist,
|
||||||
|
typename SPATIAL_INDEX::ScalarType & _minDist,
|
||||||
|
typename SPATIAL_INDEX:: CoordType &_closestPt)
|
||||||
{
|
{
|
||||||
typename SPATIALINDEXING::CellIterator first,last,l;
|
typedef typename SPATIAL_INDEX::ObjPtr ObjPtr;
|
||||||
_objectPtrs.clear();
|
typedef SPATIAL_INDEX SpatialIndex;
|
||||||
|
typedef typename SPATIAL_INDEX::CoordType CoordType;
|
||||||
|
typedef typename SPATIAL_INDEX::ScalarType ScalarType;
|
||||||
|
typedef typename SPATIAL_INDEX::Box2x Box2x;
|
||||||
|
|
||||||
|
Point2<ScalarType> _p = OBJPOINTDISTFUNCTOR::Pos(_p_obj);
|
||||||
|
|
||||||
|
// Initialize min_dist with _maxDist to exploit early rejection test.
|
||||||
|
_minDist = _maxDist;
|
||||||
|
|
||||||
|
ObjPtr winner=NULL;
|
||||||
_marker.UnMarkAll();
|
_marker.UnMarkAll();
|
||||||
for (int i=0;i<_bbox.size();i++)
|
ScalarType newradius = Si.voxel.Norm();
|
||||||
GridGetInBox2D(_Si,_marker,_bbox[i],_objectPtrs,false);
|
ScalarType radius;
|
||||||
return (static_cast<unsigned int>(_objectPtrs.size()));
|
Box2i iboxdone,iboxtodo;
|
||||||
}*/
|
CoordType t_res;
|
||||||
|
typename SPATIAL_INDEX::CellIterator first,last,l;
|
||||||
template <class SPATIALINDEXING,class OBJMARKER, class OBJPTRCONTAINER>
|
if(Si.bbox.IsInEx(_p))
|
||||||
unsigned int GridGetInBoxes2D(SPATIALINDEXING &_Si,
|
|
||||||
OBJMARKER & _marker,
|
|
||||||
const std::vector<vcg::Box2<typename SPATIALINDEXING::ScalarType> > &_bbox,
|
|
||||||
OBJPTRCONTAINER & _objectPtrs)
|
|
||||||
{
|
{
|
||||||
typename SPATIALINDEXING::CellIterator first,last,l;
|
Point2i _ip;
|
||||||
_objectPtrs.clear();
|
Si.PToIP(_p,_ip);
|
||||||
_marker.UnMarkAll();
|
Si.Grid( _ip[0],_ip[1], first, last );
|
||||||
std::vector<vcg::Point2i> cells;
|
|
||||||
|
|
||||||
for (int i=0;i<_bbox.size();i++)
|
|
||||||
{
|
|
||||||
vcg::Box2i ibbox;
|
|
||||||
Box2i Si_ibox(Point2i(0,0),_Si.siz-Point2i(1,1));
|
|
||||||
_Si.BoxToIBox(_bbox[i], ibbox);
|
|
||||||
ibbox.Intersect(Si_ibox);
|
|
||||||
|
|
||||||
if (ibbox.IsNull())continue;
|
|
||||||
int ix,iy;
|
|
||||||
|
|
||||||
for (ix=ibbox.min[0]; ix<=ibbox.max[0]; ix++)
|
|
||||||
for (iy=ibbox.min[1]; iy<=ibbox.max[1]; iy++)
|
|
||||||
cells.push_back(vcg::Point2i(ix,iy));
|
|
||||||
}
|
|
||||||
//printf("%d \n",cells.size());
|
|
||||||
std::sort(cells.begin(),cells.end());
|
|
||||||
std::vector<vcg::Point2i>::iterator it=std::unique(cells.begin(),cells.end());
|
|
||||||
cells.resize( it - cells.begin() );
|
|
||||||
|
|
||||||
for (int i=0;i<cells.size();i++)
|
|
||||||
{
|
|
||||||
_Si.Grid( cells[i].X(), cells[i].Y(), first, last );
|
|
||||||
for(l=first;l!=last;++l)
|
for(l=first;l!=last;++l)
|
||||||
if (!(**l).IsD())
|
|
||||||
{
|
{
|
||||||
typename SPATIALINDEXING::ObjPtr elem=&(**l);
|
ObjPtr elem=&(**l);
|
||||||
|
if (!elem->IsD())
|
||||||
|
{
|
||||||
|
if (_getPointDistance((**l), _p_obj,_minDist, t_res))
|
||||||
|
{
|
||||||
|
winner=elem;
|
||||||
|
_closestPt=t_res;
|
||||||
|
newradius=_minDist; //
|
||||||
|
}
|
||||||
|
_marker.Mark(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iboxdone=Box2i(_ip,_ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ix,iy;
|
||||||
|
Box2i ibox(Point2i(0,0),Si.siz-Point2i(1,1));
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
radius=newradius;
|
||||||
|
Box2x boxtodo=Box2x(_p,radius);
|
||||||
|
//boxtodo.Intersect(Si.bbox);
|
||||||
|
Si.BoxToIBox(boxtodo, iboxtodo);
|
||||||
|
iboxtodo.Intersect(ibox);
|
||||||
|
if(!boxtodo.IsNull())
|
||||||
|
{
|
||||||
|
for (ix=iboxtodo.min[0]; ix<=iboxtodo.max[0]; ix++)
|
||||||
|
for (iy=iboxtodo.min[1]; iy<=iboxtodo.max[1]; iy++)
|
||||||
|
if(ix<iboxdone.min[0] || ix>iboxdone.max[0] || // this test is to avoid to re-process already analyzed cells.
|
||||||
|
iy<iboxdone.min[1] || iy>iboxdone.max[1] )
|
||||||
|
{
|
||||||
|
Si.Grid( ix, iy, first, last );
|
||||||
|
for(l=first;l!=last;++l) if (!(**l).IsD())
|
||||||
|
{
|
||||||
|
ObjPtr elem=&(**l);
|
||||||
|
if (!elem->IsD())
|
||||||
|
{
|
||||||
if( ! _marker.IsMarked(elem))
|
if( ! _marker.IsMarked(elem))
|
||||||
{
|
{
|
||||||
_objectPtrs.push_back(elem);
|
if (_getPointDistance((**l), _p_obj, _minDist, t_res))
|
||||||
|
{
|
||||||
|
winner=elem;
|
||||||
|
_closestPt=t_res;
|
||||||
|
};
|
||||||
_marker.Mark(elem);
|
_marker.Mark(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (static_cast<unsigned int>(_objectPtrs.size()));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(!winner) newradius=radius+Si.voxel.Norm();
|
||||||
|
else newradius = _minDist;
|
||||||
|
iboxdone=iboxtodo;
|
||||||
|
}
|
||||||
|
while (_minDist>radius);
|
||||||
|
|
||||||
|
return winner;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class SPATIALINDEXING,class OBJRAYISECTFUNCTOR, class OBJMARKER>
|
||||||
|
typename SPATIALINDEXING::ObjPtr GridDoRay(SPATIALINDEXING &_Si,
|
||||||
|
OBJRAYISECTFUNCTOR &_rayIntersector,
|
||||||
|
OBJMARKER &_marker,
|
||||||
|
const Ray2<typename SPATIALINDEXING::ScalarType> & _ray,
|
||||||
|
const typename SPATIALINDEXING::ScalarType & _maxDist,
|
||||||
|
typename SPATIALINDEXING::ScalarType & _t)
|
||||||
|
{
|
||||||
|
typedef vcg::RayIterator2D<SPATIALINDEXING,OBJRAYISECTFUNCTOR,OBJMARKER> RayIteratorType;
|
||||||
|
RayIteratorType RayIte=RayIteratorType(_Si,_rayIntersector,_maxDist,_marker);
|
||||||
|
RayIte.Init(_ray);
|
||||||
|
|
||||||
|
if (!RayIte.End())
|
||||||
|
{
|
||||||
|
_t=RayIte.Dist();
|
||||||
|
return(&(*RayIte));
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}//end namespace vcg
|
}//end namespace vcg
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue