\( \newcommand{\E}{\mathrm{E}} \) \( \newcommand{\A}{\mathrm{A}} \) \( \newcommand{\R}{\mathrm{R}} \) \( \newcommand{\N}{\mathrm{N}} \) \( \newcommand{\Q}{\mathrm{Q}} \) \( \newcommand{\Z}{\mathrm{Z}} \) \( \def\ccSum #1#2#3{ \sum_{#1}^{#2}{#3} } \def\ccProd #1#2#3{ \sum_{#1}^{#2}{#3} }\)
CGAL 4.11 - Interval Skip List
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
User Manual

Author
Andreas Fabri

Definition

An interval skip list is a data structure for finding all intervals that contain a point, and for stabbing queries, that is for answering the question whether a given point is contained in an interval or not. The implementation we provide is dynamic, that is the user can freely mix calls to the methods insert(..), remove(..), find_intervals(..), and is_contained(..)

The interval skip list class is parameterized with an interval class.

The data structure was introduced by Hanson [1], and it is called interval skip list, because it is an extension of the randomized list structure known as skip list [2].

Example Programs

We give two examples. The first one uses a basic interval class. In the second example we create an interval skip list for the \( z\)-ranges of the faces of a terrain, allowing to answer level queries.

First Example with Simple Interval

The first example reads two numbers n and d from std::cin. It creates n intervals of length d with the left endpoint at n. It then reads out the intervals for the 1-dimensional points with coordinates \( 0 ... n+d\).

The interval skip list class has as template argument an interval class. In this example we use the class Interval_skip_list_interval.


File Interval_skip_list/intervals.cpp

#include <CGAL/Interval_skip_list.h>
#include <CGAL/Interval_skip_list_interval.h>
#include <vector>
#include <list>
#include <iostream>
typedef CGAL::Interval_skip_list<Interval> Interval_skip_list;
int main()
{
Interval_skip_list isl;
int i, n, d;
n = 10;
d = 3;
//std::cin >> n >> d;
std::vector<Interval> intervals(n);
for(i = 0; i < n; i++) {
intervals[i] = Interval(i, i+d);
}
std::random_shuffle(intervals.begin(), intervals.end());
isl.insert(intervals.begin(), intervals.end());
for(i = 0; i < n+d; i++) {
std::list<Interval> L;
isl.find_intervals(i, std::back_inserter(L));
for(std::list<Interval>::iterator it = L.begin(); it != L.end(); it++){
std::cout << *it;
}
std::cout << std::endl;
}
for(i = 0; i < n; i++) {
isl.remove(intervals[i]);
}
return 0;
}

Example with Faces of a Triangulated Terrain

The second example creates an interval skip list that allows to find all the faces of a terrain intersected by an horizontal plane at a given height. The data points for the terrain are read from a file.

As model for the interval concept, we use a class that is a wrapper around a face handle of a triangulated terrain. Lower and upper bound of the interval are smallest and largest \( z\)-coordinate of the face.


File Interval_skip_list/isl_terrain.cpp

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Projection_traits_xy_3.h>
#include <CGAL/Interval_skip_list.h>
#include <CGAL/Level_interval.h>
#include <iostream>
#include <fstream>
typedef EIK::Point_3 Point_3;
typedef CGAL::Delaunay_triangulation_2<K> Delaunay;
typedef Delaunay::Face_handle Face_handle;
typedef Delaunay::Finite_faces_iterator Finite_faces_iterator;
typedef CGAL::Interval_skip_list<Interval> Interval_skip_list;
int main()
{
std::ifstream fin("terrain.pts"); // elevation ranges from 0 to 100
Delaunay dt;
dt.insert(std::istream_iterator<Point_3>(fin),
std::istream_iterator<Point_3>());
Interval_skip_list isl;
for(Finite_faces_iterator fh = dt.finite_faces_begin();
fh != dt.finite_faces_end();
++fh){
isl.insert(Interval(fh));
}
std::list<Interval> level;
isl.find_intervals(50, std::back_inserter(level));
for(std::list<Interval>::iterator it = level.begin();
it != level.end();
++it){
std::cout << dt.triangle(it->face_handle()) << std::endl;
}
return 0;
}