CS 791: Assignment 2 - Symmetry and Celtic Knots


Overview

This webpage describes my implementation for part 3 of the assignment for creating Celtic knotwork. The report is organized as follows:

Implementation

My implementation for this assignment was developed under Windows XP using C++. I used openGL for rendering and the Gtkmm libraries for the user interface. The Cairo graphics library is used to generate PDF files.

The Gtk application framework was based on donated code for CS 488 - specifically for assignment 3.

Interface

A simple user interface was created for the celtic knot program:

The menus are shown below:

The File menu allows for opening knot description files and writing knots as PDFs or as knot description files.

The Knot menu sets knot editing options:

  • Grid Size creates a new empty grid of a given size (forced to be even width and height).
  • Interlacing: Odd sets to odd interlacing mode.
  • Interlacing: Even sets to even interlacing mode (opposide of odd mode).
  • Borders On turns on all break markers along the outside edge of the grid.
  • Borders Off turns off all break markers along the outside edge of the grid.
  • Edit Break Markers switches to break marker editing mode.
  • Edit Cells Markers switches to cell editing mode.
  • Edit Square Corners switches to corner editing mode.
  • Clear clears the grid.
The Render menu sets rendering options:
  • The knot can be set to render as lines, ribbons with square corners or ribbons with curved corners.
  • The grid and break markers can be toggled on/off.
  • Rendering with different colours for separate knot strands can be turned on/off.
  • The render property dialog can be displayed which allows editing of knot and border widths and colours.

Algorithm

The technique described in Cromwell's paper is used to render Celtic-style knotwork. Each square in Cromwell's primal grid is split into four cells and the knot is rendered on a cell-by-cell basis. The contents of each cell is determined by how many of the cells edges are blocked by a break marker. Because of the layout of the grid and that break markers cannot intersect, each cell can have 0, 1 or 2 edges blocked, never 3 or 4.

There are four possibilities for cells with no borders, as shown to the right. They are really all just mirror images of each other with different interlacings.

There are 16 variations for cells with only one border - four posibilities (due to interlacing) for each of the four possible cell borders.

There are six variations for cells with two borders - two cases where opposite sides of the cell have a border (creating a "channel") and four where the borders form a corner.

These other cases are shown below.

Implementation Overview

Without getting into the nitty-gritty details, here's a basic summary of the main implementation classes:

Other classes in the implementation handle the UI and store render properties.

Rendering Details

Knots are rendered interactively using polygons and lines in openGL (and their equivalent when writing PDFs with cairo, though curved corners are rendered as paths with bezier curves). The width of a ribbon is specified as a percentage of a cell width (where cells are assumed to be square) and the ribbon border is a percentage of the ribbon width.

When drawing curved knots, the corners are drawn using cubic bezier curves as that is what cairo supports. When setting control points, I take the start, end and the point (where the knot enters and leaves the cell) and calculate where the ribbon lines would intersect for a "mid point"; the middle two control points are then set to be two-thirds of the way from one of the ends to the mid point. This is done both for the outer and inner edges of the knot.

Known Issues

These are as of the time of this writing. Time permitting, some of these may be addressed, but that seems unlikely.

Extensions

As extensions, I implemented a user interface for interactively placing breakmarkers and modifying rendering parameters, I assign different colours to each unique strand in a knotwork, allow for individual cells to be disabled and allow for cells to be forced to draw squared corners.

The extensions are discussed in more detail on the extensions page.

Results

Some images are viewable on the results page.