DOC PREVIEW
IUPUI CS 265 - Hilbert Curve

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Problem StatementHilbert CurvesDisplaying a Hilbert CurveEdge SizeDrawing Lines in QtDrawing an Edge in QtDeliverablesGradingAcknowledgementsmain.hmain.cpphilbert.hCSCI 265 Project 8Hilbert Curve40 pointsProblem Statement The purpose of this assignment is to display Hilbert Curves of orders 1 through 8 using Qt.Hilbert Curves Hilbert curves are space-filling curves the visit every point in a two-dimensional space. They were first described by David Hilbert in 1892. They are relevant today, especially in image compression and dithering. Hilbert curves are always defined against a 2n x 2n space where n > 0. The Hilbert curve is defined recursively with the base case defined for n=1, and higher order curves defined recursively.There are eight base case order 1 Hilbert curves, each with a different direction and a different entry and exit point. In practice, only four curves are chosen with directions that work together to make a continuous line. For convenience, we choose to label each curve based on the direction of its opening. For this discussion, an "up" cup is assumed for the first order Hilbert curve.Hilbert(1, UP)Hilbert(1, RIGHT)Hilbert(1, DOWN)Hilbert(1, LEFT)Figure 1. Hilbert(1). Base Cases with four directionsA second order Hilbert curve, one that fills a 4 x 4 point space, is created by connecting the cups together with "join". A join is a single line segment, with one entry and one exit, that connects the ending point of a cup with the entry point of another. Each second order curve has an up, down, left, and right directions, just like the first order curve.Figure 2. Hilbert(n, d). Invoking Hilbert Curves of Order n-1 Connected By Joins With Four DirectionsNotice how the joins mirror that shape of the original cup. Following these rules, it's easy to hand-draw a second order Hilbert curve Hilbert(2, UP) by hand.Page 1 of 10Figure 3. Hilbert(2, UP)We have shown that Hilbert(2, UP) fills a 4 x 4 space. It turns out that the recursive definitions in Figure 2 allow Hilbert(n, d) to fill a space of size 2n. When you project is completed, is should display Hilbert(1, UP) through Hilbert(8, UP).Figure 4. Hilbert(3, UP)Page 2 of 10Figure 5. Hilbert(4, UP)Page 3 of 10Figure 6. Hilbert(5, UP)Page 4 of 10Figure 7. Hilbert(6, UP)Page 5 of 10Figure 8. Hilbert(7, UP)Page 6 of 10Figure 9. Hilbert(8, UP)Displaying a Hilbert CurveEdge SizeThe size of each edge must be scaled in order for a Hilbert curve to be drawn in a window. The number of edges e when there are p points on a side is e = p – 1. If a display window is W pixels wide, the size of each edge is W/(2n-1). Special adjustments are needed to make sure that you do not exceed the window size when n=1, and that the edge size is no smaller than two pixels (otherwise, there is no gap between pixels and the entire square is filled with adjacent lines making it appear black.)Drawing Lines in QtQt allows a program to draw directly on a widget by using its QPainter object. A pointer to the QPainter is obtained using the statement QPainter p(this). Since your main window is a widget, the method function p.drawLine(x1, y1, x2, y2)can be used to draw a line on the main window.Page 7 of 10Drawing an Edge in QtThe Hilbert algorithm refers to movement in terms of moving the length of one edge in the direction UP, DOWN, LEFT, and RIGHT. A enumerated data type is declared to defined named constants for each direction. The function move(QPainter *p, int direction) is written to draw a line in a specified direction. Since the drawLine function uses coordinates, move() keeps track of the prior (x, y) coordinate using data members.DeliverablesIn order to focus on writing the Hilbert class instead of Qt, source code for the Qt portion of the project is provided. Three source files, main.h, main.cpp, and hilbert.h are supplied. It is your responsibility to write hilbert.cpp that conforms to the hilbert.h public interface. Send your hilbert.cpp in Oncourse mail as a file attachment to the Teaching Assistant.GradingCorrect output – 20 points. Programming Style – 20 points.AcknowledgementsThiadmer Riemersma, ITB CompuPhase, 1998-1999, The Netherlands, http://www.compuphase.com.Appendicesmain.h#define QUIT_BUTTON_WIDTH 75#define QUIT_BUTTON_HEIGHT 30#include <qapplication.h>#include <qwidget.h>#include <qpushbutton.h>#include <qfont.h>#include <qpainter.h>#include <qspinbox.h>#include "hilbert.h"class MyWidget : public QWidget{ Q_OBJECTprivate: QSpinBox *mySpinBox; public: MyWidget( QWidget *parent = 0, const char *name = 0 ) ; void paintEvent( QPaintEvent * ) ;public slots: void slotMySpinBoxValueChanged(int value) ;} ;Page 8 of 10main.cpp#include "main.h"MyWidget::MyWidget( QWidget *parent, const char *name ) : QWidget(parent, name){ setMinimumSize(CANVAS_WIDTH, CANVAS_HEIGHT+QUIT_BUTTON_HEIGHT); setMaximumSize(CANVAS_WIDTH, CANVAS_HEIGHT+QUIT_BUTTON_HEIGHT); QPushButton *quit = new QPushButton( "Quit", this, "quit"); quit->setGeometry( CANVAS_WIDTH - QUIT_BUTTON_WIDTH, CANVAS_HEIGHT, QUIT_BUTTON_WIDTH, QUIT_BUTTON_HEIGHT); quit->setFont( QFont( "Times", 18, QFont::Bold)); mySpinBox = new QSpinBox(1, 8, 1, this, "mySpinBox"); mySpinBox->setGeometry( CANVAS_WIDTH - 2*QUIT_BUTTON_WIDTH, CANVAS_HEIGHT, QUIT_BUTTON_WIDTH, QUIT_BUTTON_HEIGHT); mySpinBox->setFont( QFont( "Times", 18, QFont::Bold)); connect( quit, SIGNAL(clicked()), qApp, SLOT(quit())); connect( mySpinBox, SIGNAL(valueChanged(int)), this, SLOT(slotMySpinBoxValueChanged(int))); QPainter p(this); hilbert(&p, 1);}void MyWidget::paintEvent( QPaintEvent * ){ QPainter p(this); hilbert(&p, mySpinBox->value());}void MyWidget::slotMySpinBoxValueChanged(int value){ // cout << "Spin Box Value is " << value << endl; QPainter p(this); p.eraseRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); hilbert(&p, value);}int main( int argc, char **argv){ QApplication a(argc, argv); QPainter p; MyWidget w; w.setGeometry(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT + QUIT_BUTTON_HEIGHT); a.setMainWidget( &w); w.show(); return a.exec();}Page 9 of 10hilbert.h#ifndef __hilbert_h__#define __hilbert_h__#define CANVAS_WIDTH 512#define CANVAS_HEIGHT 512#include "qpainter.h"#include <math.h>#include <iostream>using namespace std;class hilbert{private: int edgeSize; unsigned int currentX, currentY;public: hilbert(QPainter *p, int level); void hilbert::up(QPainter *p, int level); void hilbert::down(QPainter *p, int level); void


View Full Document

IUPUI CS 265 - Hilbert Curve

Download Hilbert Curve
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Hilbert Curve and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Hilbert Curve 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?