Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] How to change Kd-Tree Point extra info

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] How to change Kd-Tree Point extra info


Chronological Thread 
  • From: "Sebastien Loriot (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] How to change Kd-Tree Point extra info
  • Date: Thu, 05 Jan 2012 08:04:40 +0100

After fixing compiling errors in your code it was working fine on my
machine with CGAL 3.9 (see the attached code).

Did you have a look at this section where you can attach info to points stored in the tree by using property maps?

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Spatial_searching/Chapter_main.html#Subsection_60.3.6

Sebastien.



wrote:
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3 Point3;

struct Point:public Point3
{
Point(double dx,double dy,double dz):Point_3(dx,dy,dz)
{

bUsed = false;
}
AcDbObjectId id;

bool bUsed;
};

struct Construct_coord_iterator
{
// Get an iterator for the approximate coordinates. const Point::Cartesian_const_iterator operator() (const Point&
nnp) const
{
return (nnp.cartesian_begin());
}

//Get a past-the-end iterator for the approximate coordinates. const Point::Cartesian_const_iterator operator() (const Point&
nnp, int) const
{
return (nnp.cartesian_end());
}
};

typedef CGAL::Search_traits<K::FT, Point, const
double*,Construct_coord_iterator> Traits;
typedef CGAL::Orthogonal_incremental_neighbor_search<Traits>
NN_incremental_search;
typedef NN_incremental_search::iterator NN_iterator;
typedef NN_incremental_search::Tree Tree;

struct point_not_used{
bool operator()(const NN_iterator& it)
{ return (((*it).first).bUsed);
//return true;
}
};
// An iterator that only enumerates dD points with positive
x-coordinate
typedef CGAL::Filter_iterator<NN_iterator,point_not_used>
NN_positive_x_iterator;

.... //init a Tree ojbect and do the below seach.

NN_incremental_search NN(tree,query);
NN_positive_x_iterator
it(NN.end(),point_not_used(),NN.begin()),end(NN.end(),point_not_used());
for (int j=0;(j<nK)&&(it!=end);++j,++it)
{
const Point& p = (*it).first;
Point& pp = const_cast<Point&>(p);


pp.bUsed = true;// why can this line not change the
tree's point extra info "bUsed".

idArr_Res.append(p.id);
acutPrintf(_T("\nsquard
distance=%g"),CGAL::to_double((*it).second));
}

the code above can be compiled well, but "pp.bUsed = true" did nothing, why
can't change the tree's point extral info.


#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Orthogonal_incremental_neighbor_search.h>
#include <CGAL/Search_traits.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel	    K;
typedef K::Point_3 Point3;

struct Point:public Point3
{
  Point(){}
  Point(double dx,double dy,double dz):Point3(dx,dy,dz)
  {

    bUsed = false;
  }

  bool bUsed;
};

struct Construct_coord_iterator
{
  typedef Point::Cartesian_const_iterator result_type;
  // Get an iterator for the approximate coordinates. 
  Point::Cartesian_const_iterator operator() (const Point& nnp) const
  {
    return (nnp.cartesian_begin());
  }

  //Get a past-the-end iterator for the approximate coordinates. 
  Point::Cartesian_const_iterator operator() (const Point& nnp, int) const
  {
    return (nnp.cartesian_end());
  }
};

typedef CGAL::Search_traits<K::FT, Point, const double*,Construct_coord_iterator> Traits;
typedef CGAL::Orthogonal_incremental_neighbor_search<Traits> NN_incremental_search;
typedef NN_incremental_search::iterator NN_iterator;
typedef NN_incremental_search::Tree Tree;

struct point_not_used{
  bool operator()(const NN_iterator& it)
  { 
    return (((*it).first).bUsed);
    //return true;
  }
};
// An iterator that only enumerates dD points with positive x-coordinate
typedef CGAL::Filter_iterator<NN_iterator,point_not_used> NN_positive_x_iterator;

int main(){

  Tree tree;

  std::list<Point> lst;
  lst.push_back(Point(0,0,0));
  lst.back().bUsed=true;
  lst.push_back(Point(0,0,1));
  lst.back().bUsed=true;
  lst.push_back(Point(0,1,1));
  lst.push_back(Point(1,1,1));
  lst.push_back(Point(2,1,1));
  lst.push_back(Point(2,2,3));
  lst.push_back(Point(2,2,2));

  tree.insert(lst.begin(),lst.end());
  int nK=2;  
    

  Point query(0,0,0.1);

    
  NN_incremental_search NN(tree,query);

  std::cout << NN.begin()->first.bUsed << std::endl;
  std::cout << (++NN.begin())->first.bUsed << std::endl;

  NN_positive_x_iterator it(NN.end(),point_not_used(),NN.begin()),end(NN.end(),point_not_used());
  for (int j=0;(j<nK)&&(it!=end);++j,++it)
  {
    const Point& p = (*it).first;
    Point& pp = const_cast<Point&>(p);
    pp.bUsed = false;// why can this line not change the tree's point extra info "bUsed".
  }
  std::cout << NN.begin()->first.bUsed << std::endl;
  std::cout << (++NN.begin())->first.bUsed << std::endl;

}



Archive powered by MHonArc 2.6.16.

Top of Page