From 7bb3900d3b2d86d231696ea82251913d2fe86547 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Mon, 27 Aug 2012 12:46:31 +0000 Subject: [PATCH] added support for primitive subdivision into cells --- apps/sample/hashing_2D/test_hash2D.cpp | 178 ++++++++++++++++--------- 1 file changed, 113 insertions(+), 65 deletions(-) diff --git a/apps/sample/hashing_2D/test_hash2D.cpp b/apps/sample/hashing_2D/test_hash2D.cpp index 7f89441b..5fad4feb 100644 --- a/apps/sample/hashing_2D/test_hash2D.cpp +++ b/apps/sample/hashing_2D/test_hash2D.cpp @@ -33,32 +33,54 @@ class MySegmentType:public vcg::Segment2 { public: int mark; - bool deleted; + bool deleted; bool IsD(){return deleted;} + typedef vcg::Point2 CoordType; MySegmentType(const vcg::Point2 &_P0, const vcg::Point2 &_P1) { P0()=_P0; P1()=_P1; - mark=0; - } + mark=0; + } void GetBBox(vcg::Box2 &BB2) { //BB2.SetNull(); BB2.Set(P0()); - BB2.Add(P1()); + BB2.Add(P1()); } + void GetSubBBox(const ScalarType &step_size, + std::vector > &RasterBox) + { + //RasterBox.clear(); + ScalarType lenght=(P1()-P0()).Norm(); + CoordType dir=(P1()-P0()); + dir.Normalize(); + int steps= (int)ceil(lenght/(ScalarType)step_size); + RasterBox.resize(steps); + + CoordType currP0=P0(); + CoordType currP1; + for (int i=0;i(currP0,currP1)); + currP0=currP1; + } + RasterBox[steps-1]=(vcg::Box2(currP0,P1())); + } + MySegmentType(){} - MySegmentType(const MySegmentType &s1) + MySegmentType(const MySegmentType &s1):vcg::Segment2(s1) { P0()=s1.P0(); P1()=s1.P1(); mark=s1.mark; - deleted=s1.deleted; + deleted=s1.deleted; } }; @@ -134,7 +156,7 @@ MyScalarType TestBox(int num_test=100000, { //GetInBox(OBJMARKER & _marker,const Box2x _bbox,OBJPTRCONTAINER & _objectPtrs) MyMark.UnMarkAll(); - int t0=clock(); + //int t0=clock(); int num=0; for (int i=0;i result; num+=Hash2D.GetInBox >(MyMark,bbox,result); } - int t1=clock(); + //int t1=clock(); MyScalarType numd=(double)num/(double)num_test; return numd; } -//void TestCorrectNess(int num_sample=1000, -// int num_test=1000, -// MyScalarType SpaceSize=100, -// MyScalarType radius=0.02) -//{ -// -//} - -void GetIntersectingSegments(MySegmentType *S, - std::vector &result) +MyScalarType GetIntersectingSegments(MySegmentType *S, + std::vector &result, + bool subdivide=false) { ///get the bbox result.clear(); - vcg::Box2 bbox; - S->GetBBox(bbox); - ///then get into the grid - std::vector inbox; - int num=Hash2D.GetInBox >(MyMark,bbox,inbox); + ///then get into the grid + std::vector inbox; + int num=0; + if (!subdivide) + { + vcg::Box2 bbox; + S->GetBBox(bbox); + num=Hash2D.GetInBox >(MyMark,bbox,inbox); + } + else + { + std::vector > bbox; + MyScalarType size_cell=Hash2D.cell_size; + + S->GetSubBBox(size_cell,bbox); + num=Hash2D.GetInBoxes >(MyMark,bbox,inbox); + } ///then test intersection for (int j=0;j p_inters; - if (vcg::SegmentSegmentIntersection(*S,*inbox[j],p_inters)) + vcg::Point2 p_inters; + if (vcg::SegmentSegmentIntersection(*S,*inbox[j],p_inters)) result.push_back(inbox[j]); } + return (((MyScalarType)num-result.size())/(MyScalarType)num); } -void GetCloseSegments(MySegmentType *S, +MyScalarType GetCloseSegments(MySegmentType *S, const MyScalarType &radius, - std::vector &result) + std::vector &result, + bool use_sub=false) { ///get the bbox result.clear(); - vcg::Box2 bbox; - S->GetBBox(bbox); - bbox.Offset(radius);//*1.02); - - ///then get into the grid - std::vector inbox; - int num=Hash2D.GetInBox >(MyMark,bbox,inbox); + std::vector inbox; + int num=0; + if (!use_sub) + { + vcg::Box2 bbox; + S->GetBBox(bbox); + bbox.Offset(radius);//*1.02); + ///then get into the grid + num=Hash2D.GetInBox >(MyMark,bbox,inbox); + } + else + { + std::vector > bbox; + MyScalarType size_cell=Hash2D.cell_size; + S->GetSubBBox(size_cell,bbox); + for (int i=0;i >(MyMark,bbox,inbox); + } ///then test intersection for (int j=0;j p_clos; - MyScalarType dist=vcg::Segment2DSegment2DDistance(*S,*inbox[j],p_clos); - if (dist(*S,*inbox[j],p_clos); + if (dist result; - GetIntersectingSegments(&Allocated[i],result); - num_inters+=result.size(); + MyScalarType false_pos_t=GetIntersectingSegments(&Allocated[i],result,use_sub); + false_pos+=false_pos_t; } - return ((MyScalarType)num_inters/(MyScalarType)num_test); + return (false_pos/(MyScalarType)num_test); } -MyScalarType TestClosest(int num_test=1000000, - MyScalarType radius=0.1) +MyScalarType TestClosest(unsigned int num_test=1000000, + MyScalarType radius=0.1, + bool use_sub=false) { - int num_found=0; - for (int i=0;i closer; - GetCloseSegments(S,absRadius,closer); - - num_found+=closer.size(); + MyScalarType false_pos_t=GetCloseSegments(S,absRadius,closer,use_sub); + false_pos+=false_pos_t; } - return ((MyScalarType)num_found/(MyScalarType)num_test); + return (false_pos/(MyScalarType)num_test); } -int TestCorrectIntersect(int num_test=1000) +int TestCorrectIntersect(int num_test=1000,bool use_sub=false) { int num=0; for (int i=0;i