1 // Implementation: Testprogram for 3-dimensional Segment Trees
2 // A three dimensional Segment Tree is defined in this class.
3 // Ti is the type of each dimension of the tree.
4 
5 
6 #include <CGAL/Segment_tree_k.h>
7 #include "include/Tree_Traits.h"
8 #include <iostream>
9 #include <vector>
10 #include <iterator>
11 #include <list>
12 
13 typedef CGAL::Segment_tree_3<CGAL::Tree_traits_3> Segment_tree_3_type;
14 
main()15 int main()
16 {
17   typedef CGAL::Tree_traits_3::Interval Interval;
18   typedef CGAL::Tree_traits_3::Key Key;
19   // definition of the two-dimensional segment tree
20   std::list<Interval> InputList, OutputList, N;
21 
22   // insertion of the tree elements into the sequence container
23   InputList.push_back(Interval(Key(1, 3, 5), Key(2,5,7)));
24   InputList.push_back(Interval(Key(2,6.7,5), Key(4,6.9, 8)));
25   InputList.push_back(Interval(Key(2,4.55, 8), Key(5, 7.88, 10)));
26   InputList.push_back(Interval(Key(2, 4.66, 5), Key(6, 8.99, 8)));
27 
28   // creation of the segment tree
29   std::list<Interval>::iterator first = InputList.begin();
30   std::list<Interval>::iterator last = InputList.end();
31 
32   Segment_tree_3_type Segment_tree_3(first,last);
33 
34   // perform a window query
35   Interval a(Key(3,4.88, 6), Key(6, 8.999, 9));
36   Segment_tree_3.window_query(a,std::back_inserter(OutputList));
37 
38   // output of the querey elements on stdout
39   std::list<Interval>::iterator j = OutputList.begin();
40   std::cerr << "\n window_query (3,4.88, 6),(6, 8.999, 9)\n";
41   while(j!=OutputList.end())
42   {
43     std::cerr << (*j).first.key_1 << "," << (*j).first.key_2 << ", "
44          << (*j).first.key_3 << "-" << (*j).second.key_1 << ","
45          << (*j).second.key_2 << ", " << (*j).second.key_3 << std::endl;
46     j++;
47   }
48   Interval b(Key(2,6.8,9),Key(3,7,10));
49   Segment_tree_3.enclosing_query(b,std::back_inserter(N));
50   j = N.begin();
51   std::cerr << "\n enclosing_query(2,6.8,9),(3,7,10)\n";
52   while(j!=N.end())
53   {
54     std::cerr << (*j).first.key_1 << "," << (*j).first.key_2 << ", "
55          << (*j).first.key_3 << "-" << (*j).second.key_1 << ","
56          << (*j).second.key_2 << ", " << (*j).second.key_3 << std::endl;
57     j++;
58   }
59   if(Segment_tree_3.segment_tree_3->is_valid())
60     std::cerr << "Tree is valid\n";
61   else
62     std::cerr << "Tree is not valid\n";
63   return 0;
64 }
65