Homework 2: Line Segment Intersections & Adjacency Data Structures
Part 1: Book Problems
Prepare a PDF file named hw2_intersection_and_adjacency.pdf with your
answers to the book problems below. You may use Latex, Google Docs
(export/save as PDF), MS Word (export/save as PDF),
and/or legibly handwrite on paper and scan to PDF.
From
"Computational Geometry: Algorithms and Applications", de Berg, Cheong, van Kreveld, and Overmars.
You may discuss these problems with your classmates, but you must
write up your solutions individually. Note the names of anyone you
talked to or collaborated with in your hw2_intersection_and_adjacency.pdf writeup.
Please do not search for solutions or notes published by the
authors or any instructor or notes or solutions shared by other
students on the internet. Any use of these types of materials is
considered a violation of Academic Integrity for this course.
2.1
Let S be a set of n disjoint line segments whose upper endpoints lie on the
line y = 1 and whose lower endpoints lie on the line y = 0. These segments
partition the horizontal strip [ ∞ : - ∞ ] X [ 0 : 1 ] into n+1 regions. Give an
O(n log n) time algorithm to build a binary search tree on the segments
in S such that the region containing a query point can be determined in
O(log n) time. Also describe the query algorithm in detail.
2.8
Give pseudocode for an algorithm that lists all vertices adjacent to a
given vertex v in a doubly-connected edge list. Also, give pseudocode
for an algorithm that lists all edges that bound a face in a not necessarily
connected subdivision.
2.11
Let S be a set of n circles in the plane. Describe a plane sweep algorithm
to compute all intersection points between the circles. (Because we deal
with circles, not discs, two circles do not intersect if one lies entirely
inside the other.) Your algorithm should run in O((n + k) log n) time,
where k is the number of intersection points.
Part 2: CGAL Programming Task
-
Your task is implement and debug the algorithm requested for CGAA Book
Problem 2.9 using
the CGAL
Surface Mesh data structure, an implementation of a Half Edge Data Structure.
2.9
Suppose that a doubly-connected edge list of a connected subdivision is
given. Give pseudocode for an algorithm that lists all faces with vertices
that appear on the outer boundary.
-
We recommend you start coding from the
"Draw a Surface Mesh" example, which is part of the CGAL demos &
examples you downloaded for Homework 1:
CGAL-5.3.1/examples/Surface_mesh
Here is
the finished
CMakeList.txt file for the instructor's solution. (You may
edit this file if needed.)
-
Your program will take as an input a 2D or 3D polygonal mesh
stored in
the "Object
File Format" .off. This file format stores
vertices and faces. Each face refers to 3 or more vertices by
index, ordered in a counter-clockwise loop. Below is a sample .off file that stores 17 vertices (a
2D mesh with all vertices in the z=0 plane), 11 faces (5
triangles, 4 quads, 1 pentagon and 1 hexagon). This file with
the left image below.
sample.off
OFF
17 11 0
4 0 0
7 0 0
2 2 0
4 3 0
6 3 0
8 2 0
0 3 0
0 5 0
2 6 0
4 5 0
6 5 0
8 6 0
9 4 0
3 9 0
5 8 0
7 9 0
5 10 0
3 0 1 4
3 0 3 2
3 0 4 3
3 1 5 4
6 3 9 8 7 6 2
4 10 9 3 4
5 11 10 4 5 12
4 13 8 9 14
4 13 14 15 16
4 10 11 15 14
3 10 14 9
The image on the above right shows only the faces that have a vertex
that is on the outer boundary.
-
Your program can be run in two different ways. First, it may be
run with 3 arguments, the input mesh .off file, and two output files.
The first output, the edges text file, will list all boundary
edges on the boundary in a clockwise traversal (starting
at any edge). If there multiple cycles of edges (if the mesh
has an interior hole) the cycles will be listed separately. The
second output is a new mesh .off file storing only the faces
that have at least one vertex on the boundary of the mesh.
./identify_boundary_faces ../src/sample.off output_edges.off output_sample.off
Second, it may be run with 5 arguments, the input .off file, two
output files, and two integers that index into the vertex list.
These vertices specify an edge on the boundary of the mesh, in
the example use case below, the leftmost edge of the hexagon face. The two
output files are the same as above -- except it will only
include the edges and faces on the boundary cycle that is
specified by the input edge.
./identify_boundary_faces ../src/sample.off output_edges.txt output_sample.off 7 6
For the simple example above, with a single cycle of boundary
edges, both command lines will produce the same output. Note
that the running time for the second version of the program
should be output-sensitive; that is, faster for complex
meshes when the specified boundary is a small fraction of the
entire mesh.
-
IMPORTANT NOTE: You are expected to write the loops that walk
over the the mesh traversing "next" and "opposite" half edge
pointers. Even if you find a CGAL built-in function that loops and
gathers the necessary information for you... we encourage you
to re-write the traversal algorithm on your own for
practice.
-
The output_edges.txt file will contain the number of
boundary edge cycles detected, and then the edges in each cycle,
ordered in a clockwise walk along the boundary, starting at any
edge in the cycle.
output_edges.txt
Found 1 cycle(s)
CYCLE with 12 edges:
v7 -> v8
v8 -> v13
v13 -> v16
v16 -> v15
v15 -> v11
v11 -> v12
v12 -> v5
v5 -> v1
v1 -> v0
v0 -> v2
v2 -> v6
v6 -> v7
-
The output_sample.off file contains the boundary faces
in the "Object File Format" .off.
This file is shown in the image above right. It is the same as
the sample.off input file, except it is missing the two interior faces.
output_sample.off
OFF
17 9 0
4 0 0
7 0 0
2 2 0
4 3 0
6 3 0
8 2 0
0 3 0
0 5 0
2 6 0
4 5 0
6 5 0
8 6 0
9 4 0
3 9 0
5 8 0
7 9 0
5 10 0
3 4 0 1
3 2 0 3
3 3 0 4
3 4 1 5
6 2 3 9 8 7 6
5 12 11 10 4 5
4 14 13 8 9
4 16 13 14 15
4 14 10 11 15
-
Additional input files:
closed_box.off
open_box.off
open_tube.off
hypersheet.off
Additional sample command lines:
./identify_boundary_faces ../src/open_tube.off output_all_tube_edges.txt output_tube.off
./identify_boundary_faces ../src/open_tube.off output_select_tube_edges.txt output_selected_tube.off 12 14
Additional sample output:
output_all_tube_edges.txt
output_tube.off
output_select_tube_edges.txt
output_selected_tube.off
-
After your program has finished saving the output files, your program should launch
a CGAL Qt window that draws the surface mesh containing only the desired boundary faces.
Use the CGAL::draw function call, which is used in the
draw_surface_mesh example. Note that this function
is blocking, so make sure you have finished writing the output
files before calling this function.
Part 3: Analysis of Implementation
Analyze the running time and additional memory used to run
the two versions of your algorithm to collect and save the faces on
the boundary. Do not include the file to parse/load the input file or
the memory used to store the mesh data. Write your answer in terms
of n, the number of edges in the input mesh; f, the
number of faces in the input mesh; b, the number of edges on
the selected boundary; and o, the number of faces on the boundary
that are output.
Add this analysis to your PDF file
named hw2_intersection_and_adjacency.pdf.