• No results found

Surface and Volumetric Data Rendering and Visualisation

N/A
N/A
Protected

Academic year: 2021

Share "Surface and Volumetric Data Rendering and Visualisation"

Copied!
38
0
0

Loading.... (view fulltext now)

Full text

(1)

Sergio Benini

Department of Information Engineering Faculty of Engineering University of Brescia Via Branze, 38 – 25231 Brescia - ITALY

Surface and Volumetric Data

Rendering and Visualisation

THE Qt TOOLKIT

1 Università degli Studi di Brescia - 2011/12

(2)

What is Qt?

• “Qt is a cross platform development framework written in C++.”

• C++ framework – bindings for other languages

– Python, Ruby, C#, etc.

• Cross platform applications built from one source

• Originally used for interfaces, now for everything

– Databases, XML, WebKit, multimedia, networking, OpenGL, scripting,

non-GUI...

(3)

Sergio Benini

What is Qt?

3 Università degli Studi di Brescia - 2011/12

• Qt is made up of modules

– All modules have a common scheme and are built from the same API

design ideas

(4)

Desktop target platforms

• Windows

(5)

Sergio Benini

Embedded target platforms

5 Università degli Studi di Brescia - 2011/12

• Windows CE

• Symbian

• Maemo

• Embedded Linux

(6)

The history of Qt

• 1991 – Haavard Nord and Eirik Chambe-Eng begin to develop what will be

Qt supporting X11 and Windows

• 1993 – They produced Qt's first graphics kernel and could implement

their own widget

• 1994 – The company Trolltech was formed

• 1996 – The KDE project was started by Matthias Ettrich (now works for

Nokia Qt Development Frameworks)

• 2001 – Added support for Mac OS X

(7)

Sergio Benini

The Qt Community

7 Università degli Studi di Brescia - 2011/12

• QtCentre (www.qtcentre.org)

– Forum, news, wiki

• Qt labs (labs.trolltech.com)

– developer blogs, research projects

• #qt at freenode

– IRC channel, has wiki at qtnode.net

• Mailing lists (lists.trolltech.com)

(8)

Getting Qt

• Installers and snapshots are downloaded from

– qt.nokia.com/downloads

(9)

Sergio Benini

Windows Installation

9 Università degli Studi di Brescia - 2011/12

• 1.Download the Qt SDK for Windows

• 2.Run the downloaded installer

• 3.Click through the installer

(10)

Mac OS X installation

• 1.Download the Qt SDK for Mac OS X

• 2.Run the downloaded installer package

• 3.Click through the installer

(11)

Sergio Benini

X11 installation

11 Università degli Studi di Brescia - 2011/12

• If possible, use the package manager from your distribution

– (K)ubuntu – qt-sdk from universe

– Debian – qtcreator

– OpenSUSE – qt-creator

– Gentoo – qt-creator

– Arch Linux – qt qt-doc qt-creator

– ...

(12)

X11 installation

• 1.Download the Qt SDK for your Linux version

• 2.Make the installer executable

chmod u+x qt-sdk-linux-*.bin

3.Run the installer and click your way through it

(13)

Sergio Benini

Hello World

13 Università degli Studi di Brescia - 2011/12

• Open Qt Creator

(14)

Hello World

(15)

Sergio Benini

Hello World

15 Università degli Studi di Brescia - 2011/12

#include <QApplication> #include <QWidget>

int main(int argc, char *argv[])

{

QApplication app(argc, argv); QWidget window;

window.resize(250, 150);

window.setWindowTitle("Hello World!"); window.show();

return app.exec(); }

(16)

Hello World

#include <QApplication>

#include <QWidget>

int main(int argc, char *argv[])

{

QApplication app(argc, argv); QWidget window;

window.resize(250, 150);

window.setWindowTitle("Hello World!"); window.show();

We include necessary header files.

(17)

Sergio Benini

Hello World

17 Università degli Studi di Brescia - 2011/12

#include <QApplication> #include <QWidget>

int main(int argc, char *argv[])

{

QApplication app(argc, argv);

QWidget window;

window.resize(250, 150);

window.setWindowTitle("Hello World!"); window.show();

return app.exec(); }

This is the application object. Each application programmed in Qt4 must have this object.

(18)

Hello World

#include <QApplication> #include <QWidget>

int main(int argc, char *argv[])

{

QApplication app(argc, argv);

QWidget window;

window.resize(250, 150);

window.setWindowTitle("Hello World!"); window.show();

(19)

Sergio Benini

Hello World

19 Università degli Studi di Brescia - 2011/12

#include <QApplication> #include <QWidget>

int main(int argc, char *argv[])

{

QApplication app(argc, argv); QWidget window; window.resize(250, 150); window.setWindowTitle("Hello World!"); window.show(); return app.exec(); }

Here we resize the widget. Set a title for our main window. In this case, the QWidget is our main window. And finally show the widget on the screen.

(20)

Hello World

#include <QApplication> #include <QWidget>

int main(int argc, char *argv[])

{

QApplication app(argc, argv); QWidget window;

window.resize(250, 150);

window.setWindowTitle("Hello World!"); window.show();

We start the main loop of the application.

(21)

Sergio Benini

Hello World

21 Università degli Studi di Brescia - 2011/12

(22)

The QObject

• QObject is the base class of almost all Qt classes and all widgets

– Exception:

• Classes that need to be lightweight such as graphical primitives

• Data containers (QString, QList, QChar, etc)

• Classes that needs to be copyable, as

QObjects cannot be copied

• It contains many of the mechanisms that make up Qt

– events

(23)

Sergio Benini

Memory Management

23 Università degli Studi di Brescia - 2011/12

• QObject can have parent and children

– When a parent object is deleted, it deletes its children

#include <QApplication>

#include <QWidget>

#include <QLabel>

int main(int argc, char *argv[])

{

QApplication app(argc, argv);

QWidget *parent = new QWidget;

parent->resize(250, 150);

parent->setWindowTitle("Hello World!");

QLabel *mylabel = new QLabel("Hello World!!!",parent);

mylabel->move(80,60); parent->show();

return app.exec(); }

(24)

Memory Management

• QObject can have parent and children

(25)

Sergio Benini

Signals and Slots

25 Università degli Studi di Brescia - 2011/12

• The signals and slots are what makes the different Qt components as reusable as they are.

• They provide a mechanism through which it is possible to expose interfaces that can be freely interconnected (a menu item, push button, tool-bar button, …, can expose signal corresponding to "activated", "clicked" or any other

appropriate event).

• By connecting such a signal to a slot of any other item, the event automatically calls the slots.

• The key advantage of the signals and slots is that the caller does not have to know anything about the receiver and vice versa.

• You can connect as many signals as you want to a single slot, and a signal can be connected to as many slots as you need. It is even possible to connect a signal directly to another signal. (This will emit the second signal immediately

(26)

Signals and Slots

• In order to be able to use the signals and slots each class has to be declared in a header file. The implementation is best placed in a separate cpp file.

• The header file is then passed through a Qt tool known as the moc. The moc produces a cpp containing the code that makes the signals and slots happen (and more).

• The figure illustrates this flow. Notice the naming convention used (the moc_ prefix) in the figure.

(27)

Sergio Benini

Signals and Slots

27 Università degli Studi di Brescia - 2011/12

• Qt's widgets have many predefined signals, but we can always subclass widgets to add our own signals to them.

(28)

A More Complex Example

(29)

Sergio Benini

A More Complex Example

29 Università degli Studi di Brescia - 2011/12

(30)

A More Complex Example

(31)

Sergio Benini

A More Complex Example

31 Università degli Studi di Brescia - 2011/12

(32)

A More Complex Example

(33)

Sergio Benini

A More Complex Example

33 Università degli Studi di Brescia - 2011/12

• 5 Files: widget.cpp and widget.h files We talk about them later→ • 5 Files: widget.ui double click on it: it should start the Qt Designer→

(34)

A More Complex Example

• Add a Text Browser (double-click it for setting the default text)

• Add 2 Push Buttons (call them through the inspector my_button and quit)

(35)

Sergio Benini

A More Complex Example

35 Università degli Studi di Brescia - 2011/12

• widget.h #ifndef WIDGET_H #define WIDGET_H #include <QWidget> namespace Ui { class Widget;}

class Widget : public Qwidget { Q_OBJECT

public:

explicit Widget(QWidget *parent = 0); ~Widget(); public slots: void rewrite_text(); void quit(); private: Ui::Widget *ui;}; #endif // WIDGET_H

We define the slots that we want to be executed when a certain signal is emitted.

(36)

A More Complex Example

• widget.cpp

#include "widget.h"

#include "ui_widget.h"

void Widget::rewrite_text(){

ui->textBrowser->setText("You have clicked the button!!!");}

void Widget::quit(){ qApp->quit();}

Widget::Widget(QWidget *parent) : QWidget(parent),ui(new Ui::Widget){ ui->setupUi(this);

connect(ui->my_button, SIGNAL(clicked()),this,SLOT(rewrite_text())); connect(ui->quit, SIGNAL(clicked()),this,SLOT(quit()));

(37)

Sergio Benini

A More Complex Example

37 Università degli Studi di Brescia - 2011/12

• widget.cpp

And obviously the implementation of the slots.

#include "widget.h"

#include "ui_widget.h"

void Widget::rewrite_text(){

ui->textBrowser->setText("You have clicked the button!!!");}

void Widget::quit(){ qApp->quit();}

Widget::Widget(QWidget *parent) : QWidget(parent),ui(new Ui::Widget){ ui->setupUi(this);

connect(ui->my_button, SIGNAL(clicked()),this,SLOT(rewrite_text())); connect(ui->quit, SIGNAL(clicked()),this,SLOT(quit()));

}

Widget::~Widget(){ delete ui;}

(38)

Documentation

References

Related documents

It is also possible, of course, to determine the logic value by sensing the absolute voltage level of one input signal, called a single-ended input.. Single- ended signals are used

802.11b is typically deployed as one more more access points connected to a single wired backbone network, wireless clients connect to the access point with the strongest signal and

Adhoc Mode : Select Adhoc mode when you want to connect the camera wirelessly directly to your computer. Infrastructure Mode : Select Infrastructure mode when the camera is

In split mode operation, the IN3214 / IN3218 can be used to amplify two separate composite video signals or to amplify a single S-Video signal, with the Y (luminance) signal

It is not possible to &#34;inject&#34; a SPDIF digital audio signal directly into a DVI to HDMI adapter as the audio signal is transmitted along with the video information in a

x If possible, connect the HDTV transmitter and receiver directly to a wall outlet and avoid using a power strip and extension cord, since these may seriously weaken the

For verification of high-speed signal transmis- sion, we connected output optical signals from a pseudo-server blade equipped with a 25 Gb/s optical transceiver through

• If you are using a cable signal splitter so that you can connect the modem to other devices, remove the splitter and reconnect the cables so that the modem is connected directly