corrected bugs in ClosestIterator class : last element of Elems now is accessed with Elems.back()

corrected bug in ClosestIterator::Refresh() : when grid is called, *last have to be considered
corrected bug in ClosestIterator::End() : only coordinates strictly bigger than siz must be discarded
added several comments
This commit is contained in:
Paolo Cignoni 2006-08-23 14:53:50 +00:00
parent 9bc7cd795f
commit ac9e757551
1 changed files with 45 additions and 52 deletions

View File

@ -20,10 +20,14 @@
* for more details. * * for more details. *
* * * *
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.14 2006/06/01 20:53:56 cignoni
added missing header
****************************************************************************/ ****************************************************************************/
#ifndef __VCGLIB_SPATIAL_ITERATORS #ifndef __VCGLIB_SPATIAL_ITERATORS
#define __VCGLIB_SPATIAL_ITERATORS #define __VCGLIB_SPATIAL_ITERATORS
@ -85,7 +89,7 @@ namespace vcg{
dist=(r.Origin()-goal).Norm(); dist=(r.Origin()-goal).Norm();
const float LocalMaxScalar = std::numeric_limits<float>::max(); const float LocalMaxScalar = std::numeric_limits<float>::(max)();
const float EPSILON = 1e-50f; const float EPSILON = 1e-50f;
/* Parametri della linea */ /* Parametri della linea */
@ -313,7 +317,7 @@ namespace vcg{
///control the end of scanning ///control the end of scanning
bool _EndGrid() bool _EndGrid()
{ {
if ((explored.min==vcg::Point3i(0,0,0))&&(explored.max==Si.siz-vcg::Point3i(1,1,1))) if ((explored.min==vcg::Point3i(0,0,0))&&(explored.max>Si.siz/*-vcg::Point3i(1,1,1)*/))
end =true; end =true;
return end; return end;
} }
@ -340,14 +344,14 @@ namespace vcg{
/*b3d.Intersect(Si.bbox); /*b3d.Intersect(Si.bbox);
Si.BoxToIBox(b3d,to_explore);*/ Si.BoxToIBox(b3d,to_explore);*/
Si.BoxToIBox(b3d,to_explore); Si.BoxToIBox(b3d,to_explore);
Box3i ibox(Point3i(0,0,0),Si.siz-Point3i(1,1,1)); Box3i ibox(Point3i(0,0,0),Si.siz/*-Point3i(1,1,1)*/);
to_explore.Intersect(ibox); to_explore.Intersect(ibox);
if (!to_explore.IsNull()) if (!to_explore.IsNull())
{ {
assert(!( to_explore.min.X()<0 || to_explore.max.X()>=Si.siz[0] || /* assert(!( to_explore.min.X()<0 || to_explore.max.X()>Si.siz[0] ||
to_explore.min.Y()<0 || to_explore.max.Y()>=Si.siz[1] || to_explore.min.Z()<0 to_explore.min.Y()<0 || to_explore.max.Y()>Si.siz[1] || to_explore.min.Z()<0
|| to_explore.max.Z()>=Si.siz[2] )); || to_explore.max.Z()>Si.siz[2] ));
return true; */ return true;
} }
return false; return false;
} }
@ -371,14 +375,13 @@ namespace vcg{
///initialize the Itarator ///initialize the Itarator
void Init(CoordType _p,const ScalarType &_max_dist) void Init(CoordType _p,const ScalarType &_max_dist)
{ {
explored.SetNull(); explored.SetNull(); // box currently searched
to_explore.SetNull(); to_explore.SetNull();
p=_p; p=_p; // p is the CoordType point from which the search begin
max_dist=_max_dist; max_dist=_max_dist; // max_dist is the maximal distance where the search stops
Elems.clear(); Elems.clear(); // set of Entry_Type elements where to search
end=false; end=false;
tm.UnMarkAll(); tm.UnMarkAll();
//step_size=Si.voxel.X();
step_size=Si.voxel.Norm(); step_size=Si.voxel.Norm();
radius=0; radius=0;
@ -396,10 +399,8 @@ namespace vcg{
Refresh(); Refresh();
} }
//set to the last element ..the nearest if (!Elems.empty())
CurrentElem=Elems.end(); std::sort(Elems.begin(), Elems.end());
CurrentElem--;
} }
//return true if the scan is complete //return true if the scan is complete
@ -424,7 +425,8 @@ namespace vcg{
typename Spatial_Idexing::CellIterator first,last,l; typename Spatial_Idexing::CellIterator first,last,l;
Si.Grid(ix,iy,iz,first,last); Si.Grid(ix,iy,iz,first,last);
for(l=first;l!=last;++l)
for(l=first;l!=(last + 1);++l)
{ {
ObjType *elem=&(**l); ObjType *elem=&(**l);
if (!tm.IsMarked(elem)) if (!tm.IsMarked(elem))
@ -437,52 +439,47 @@ namespace vcg{
tm.Mark(elem); tm.Mark(elem);
} }
} }
}
}
} }
std::sort(Elems.begin(),Elems.end()); if (!Elems.empty())
std::sort(Elems.begin(), Elems.end());
CurrentElem=Elems.end();
CurrentElem--;
} }
void operator ++() void operator ++()
{ {
/*if (Dist()<=radius) if (!Elems.empty())
{
CurrentElem--;
Elems.pop_back(); Elems.pop_back();
}
while ((!End())&&(Dist()>radius))
if (_NextShell()&&!_EndGrid())
Refresh();*/
if (Elems.size()>0)
{
CurrentElem--;
Elems.pop_back();
}
while ((!End())&&(Dist()>radius)) while ((!End())&&(Dist()>radius))
if (_NextShell()&&!_EndGrid()) if (_NextShell()&&!_EndGrid())
Refresh(); Refresh();
} }
ObjType &operator *(){return *((*CurrentElem).elem);} ObjType &operator *()
{
assert (!Elems.empty());
return *(Elems.back().elem);
}
//return distance of the element form the point if no element //return distance of the element form the point if no element
//are in the vector then return max dinstance //are in the vector then return max dinstance
ScalarType Dist() ScalarType Dist()
{ {
if (Elems.size()>0) if (!Elems.empty())
return ((*CurrentElem).dist); return (Elems.back()).dist;
else else
return ((ScalarType)FLT_MAX); return ((ScalarType)FLT_MAX);
} }
CoordType NearestPoint() CoordType NearestPoint()
{return ((*CurrentElem).intersection);} {
assert (!Elems.empty());
return (Elems.back().intersection);
}
protected: protected:
@ -507,22 +504,18 @@ namespace vcg{
CoordType intersection; CoordType intersection;
}; };
CoordType p; //initial point CoordType p; // initial point
Spatial_Idexing &Si; //reference to spatial index algorithm Spatial_Idexing &Si; // reference to spatial index structure
bool end; //true if the scan is terminated bool end; // true if the scan is terminated
ScalarType max_dist; //max distance when the scan terminate ScalarType max_dist; // max distance when the scan terminate
vcg::Box3i explored; //current bounding box explored vcg::Box3i explored; // current bounding box explored
vcg::Box3i to_explore; //current bounding box explored vcg::Box3i to_explore;
ScalarType radius; //curret radius for sphere expansion ScalarType radius; // current radius of the volume sphere where to scan
ScalarType step_size; //radius step ScalarType step_size; // step fro incrementing the radius
std::vector<Entry_Type> Elems; //element loaded from the current sphere std::vector<Entry_Type> Elems; // set of elements contained in the current sphere
DISTFUNCTOR &dist_funct; DISTFUNCTOR &dist_funct;
TMARKER tm; TMARKER tm;
typedef typename std::vector<Entry_Type>::iterator ElemIterator;
ElemIterator CurrentElem; //iterator to current element
}; };
} }