c++ - Modifying functor variable when using incremental spatial searching with cgal -


i've modified example given computational geometry cgal library (link) demonstrates incremental searching on 2d plane (section 49.3.2). example uses functor set spatial bounds searching positive points on plane.

i modify functor k can passed in, demonstrated struct x_not_positive_k. complete example program below below shows modified code , original code.

#include <cgal/simple_cartesian.h> #include <cgal/orthogonal_incremental_neighbor_search.h> #include <cgal/search_traits_2.h>  typedef cgal::simple_cartesian<double> k; typedef k::point_2 point_d; typedef cgal::search_traits_2<k> treetraits; typedef cgal::orthogonal_incremental_neighbor_search<treetraits> nn_incremental_search; typedef nn_incremental_search::iterator nn_iterator; typedef nn_incremental_search::tree tree;  int main() {      tree tree;     tree.insert(point_d(0,0));     tree.insert(point_d(1,1));     tree.insert(point_d(0,1));     tree.insert(point_d(10,110));     tree.insert(point_d(45,0));     tree.insert(point_d(0,2340));     tree.insert(point_d(0,30));      point_d query(0,0);      // functor returns true, iff x-coordinate of dd point not positive     // [original code]     struct x_not_positive {         bool operator()(const nn_iterator& it) { return ((*it).first)[0]<0;  }     };      // [modified code]     // not work when used below.     struct x_not_positive_k {     public:         void assign_k(int k) {this->k = k; }         bool operator()(const nn_iterator& it) { return ((*it).first)[0] < k;  }     private:         int k;     };     x_not_positive_k xk;     xk.assign_k(1);      // iterator enumerates dd points positive x-coordinate     // [original code]     // typedef cgal::filter_iterator<nn_iterator, x_not_positive> nn_positive_x_iterator;      // [modified code]     typedef cgal::filter_iterator<nn_iterator, x_not_positive_k> nn_positive_x_iterator;      nn_incremental_search nn(tree, query);      // [original code]     // nn_positive_x_iterator it(nn.end(), x_not_positive(), nn.begin()), end(nn.end(), x_not_positive());      // [modified code]     nn_positive_x_iterator it(nn.end(), xk(), nn.begin()), end(nn.end(), xk());      // error occurs here      std::cout <<  "the first 5 nearest neighbours positive x-coord are: " << std::endl;     (int j=0; (j < 5)&&(it!=end); ++j,++it)         std::cout <<   (*it).first << "  @ squared distance = " << (*it).second << std::endl;  return 0; } 

however, compiling program (windows 7 visual studio 2010) causes following compiler error. location of error marked in code above.

2>..\main.cpp(56): error c2064: term not evaluate function taking 0 arguments 2>          class not define 'operator()' or user defined conversion operator pointer-to-function or reference-to-function takes appropriate number of arguments 2>..\main.cpp(56): error c2064: term not evaluate function taking 0 arguments 2>          class not define 'operator()' or user defined conversion operator pointer-to-function or reference-to-function takes appropriate number of arguments 2> 

what can done rid of error? there way able set k variable?

just replace xk() xk in line 56

alternatively replace assign(k) constructor argument, replace xk() x_not_positive_k(1)

actually real trouble functor's name! replace name x_not_positive_k x_less_than - call x_less_than(1) looks nice in line 56

like this:

struct x_less_than { public:     x_less_than(int i)       : k(i)     {     }     bool operator()(const nn_iterator& it) { return ((*it).first)[0] < k;  } private:     int k; }; 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -