[OpendTect_Developers] Basic Idea about 2D Graphics
Satyaki Maitra
satyaki at opendtect.org
Fri Sep 30 11:25:57 CEST 2011
Hi all
In this post I would share something about some basics of 2D graphics
drawing. My colleague Bruno has already talked about it in previous
posts. But in this post I am going to give you some elementary idea
about how 2D Graphics works. For that, first we need to understand how
the class structure is. As you might know that we use Qt libraries for
the User Interface and the 2D Graphics drawings are no exception.
There are mainly two classes related to the 2D Graphics:
'uiGraphicsView' and 'uiGraphicsScene'. The 'uiGraphicsView' is the main
widget or framework which contains a 'uiGraphicsScene'. The
'uiGraphicsScene'' is the main surface or canvas on which the drawing
takes place. The main function of the 'uiGraphicsView' is to support the
'uiGraphicsScene'. It does not have any information about the drawing
part. But everything related to the framework of the drawing is handled
by the 'uiGraphicsView'. So to manage the 'Scroll-Bar' properties, or to
control the 'DragMode' one has to go via the 'uiGraphicsView'. There are
several related utility functions in include/uiBase/uigraphicsviewbase.h
('uiGraphicsViewBase' is the base class for 'uiGraphicsView').
The 'uiGraphicsScene' can be considered as the canvas where the drawing
takes place. It does not have an existence of its own. It always needs
to be associated with a 'uiGraphicsView'. The creation and handling of
the 'uiGraphicsScene' is done by the 'uiGraphicsView'. In order to draw
anything we need to add 'uiGraphicsItem' to it. A 'uiGraphicsItem' can
be be of different types e.g uiRectItem, uiEllipseItem etc. The
'uiGraphicsScene' has several utility functions regarding this
(include/uiBase/uigraphicsscene.h). You can directly add a
uiGraphicsItem to it ( uiGraphicsScene::addItem() ) or pass in the
dimensions to the 'uiGraphicsScene' and it will return a corresponding
uiGraphicsItem ( uiRectItem* uiGraphicsScene::addRect(float x,float
y,float w,float h) ). Once an item is added to the 'uiGraphicsScene' it
becomes its parent. It should be deleted only after it is removed from
the 'uiGraphicsScene'.
So when we sum , if some one wants have a diagram with a rectangle in a
window, the only thing s/he needs to do is:
/*
uiGraphicsView* viewer = new uiGraphicsView( this, "Rectangle Diagram" );
viewer->scene().addRect( x, y , width, height );
*/
In OD all the classes related to 2D Graphics are based on these classes.
We have developed several specialized classes for them ( e.g
uiDataPointSetCrossPlot for cross-plot, uiFlatViewer to view datapacks
). But if you want to find some simple stuff regarding drawing then you
can look into uiColTabMarkerCanvas in include/uiTools/uicoltabmarker.h
or uiSurvMap in include/uiIo/uisurvmap.h. I hope this will help you.
Happy Programming
Satyaki
--
- Satyaki Maitra
- OpendTect Developer
-
- dGB Earth Sciences
- 304, Gateway Plaza, Hiranandani Gardens,
- Powai, Mumbai 400 076, India
- Phone: +91 22 25704984 , Fax: +91 22 25704977
- Mobile: +91 9930856158
- mailto:satyaki.maitra at opendtect.org
- http://www.opendtect.org
More information about the Developers
mailing list