\subsection{Example ofRange Tree on Map-like Data} \label{sec:range_tree_ex} The following example program uses the predefined \ccc{ Range_tree_2} data structure together with the predefined traits class \ccc{Range_tree_map_traits_2} which has two template arguments specifying the type of the point data in each dimension (\ccc{CGAL::Cartesian}) and the value type of the 2-dimensional point data (\ccc{char}). Therefore the \ccc{ Range_tree_2} is defined on 2-dimensional point data each of which is associated with a character. Then, a few data items are created and put into a list. After that the tree is constructed according to that list, a window query is performed, and the query elements are given out. \begin{verbatim} #include #include #include typedef CGAL::Cartesian K; typedef CGAL::Range_tree_map_traits_2 Traits; typedef CGAL::Range_tree_2 Range_tree_2_type; int main() { typedef Traits::Key Key; typedef Traits::Interval Interval; std::vector InputList, OutputList; InputList.push_back(Key(K::Point_2(8,5.1), 'a')); InputList.push_back(Key(K::Point_2(1,1.1), 'b')); InputList.push_back(Key(K::Point_2(3,2.1), 'c')); Range_tree_2_type Range_tree_2(InputList.begin(),InputList.end()); Interval win(Interval(K::Point_2(4,8.1),K::Point_2(5,8.2))); std::cout << "\n Window Query:\n "; Range_tree_2.window_query(win, std::back_inserter(OutputList)); std::vector::iterator current=OutputList.begin(); while(current!=OutputList.end()){ std::cout << (*current).first.x() << "," << (*current).first.y() << ":" << (*current++).second << std::endl; } } \end{verbatim} \subsection{Example of Range Tree on Set-like Data} This example illustrates the use of the range tree on 2-dimensional point data (no value is associated to a data item). After the definition of the tree, some input data items are created and the tree is constructed according to the input data items. After that, a window query is performed and the query elements are given to standard out. \begin{verbatim} #include #include #include typedef CGAL::Cartesian K; typedef CGAL::Range_segment_tree_set_traits_2 Traits; typedef CGAL::Range_tree_2 Range_tree_2_type; int main() { typedef Traits::Key Key; typedef Traits::Interval Interval; std::vector InputList, OutputList; std::vector::iterator first, last, current; InputList.push_back(Key(8,5.1)); InputList.push_back(Key(1,1.1)); InputList.push_back(Key(3,2.1)); Range_tree_2_type Range_tree_2(InputList.begin(),InputList.end()); Interval win=Interval(Key(4,8.1),Key(5,8.2)); std::cout << std::endl << "Window Query: lower left point: (4.0,5.0),"; std::cout << "upper right point: (8.1,8.2)" << std::endl; Range_tree_2.window_query(win, std::back_inserter(OutputList)); current=OutputList.begin(); while(current!=OutputList.end()){ std::cout << (*current).x()<< "-" << (*current).y() << std::endl; current++; } } \end{verbatim}