Primitives  Marking and Measuring¶
The plotwidgets itom1DQwtPlot and itom2DQwtPlot supports plotting of geometric primitives by user interaction and script language. This section will give a short introduction about plotting, read /writefunctions and the corresponding plots and the internal geometric element structure.
At last the evaluateGeomtricsplugin for direct evaluation of geometric elements is introduced.
Drawing items into a QwtPlot¶
The plot functionality can be accessed by three different ways. The first way is the GUI based approach by which the user presses the “switch draw mode”button in the buttonbar of the plot. The button represents the current item to be plotted. The red X (“clear button”) will delete all geometric elements within the plot either drawn by hand or by script.
At the moment “itom” only supports “point”, “line”, “rectangle” and “ellipse” but further items, e.g. “circle” and “polygons”, are in preparation. To draw an item simply click into the image space and leftclick the mouse. In case of elements with at least more than a marker, you can now set the size of the element by setting the second point by leftclicking again. During plotting a green lined geometric element appears. After finishing the element color turns to the first inverse color of the current color palette with handles (diamonds or squares) colored with the second inverse color of the current palette.
After creation the geometric elements can be edited by leftclicking one of the element handles which becomes highlighted (squares) and moving the mouse. By pressing the “ctrl”button during mousemovement the element resize behaviour will be changed depending on the element type. Lines will be changed to horizontal or vertical alignment. Rectangles and ellipses will be become squares or circles according to plot coordinates (x/yspace) and not pixel coordinates. To avoid confusion with plot aspect, a button for fixed axis aspect ratio (“1:1”) was added to the plot bar.
Script based pick and plot from / to a Qwtwidget¶
To allow more complex user interaction with scripts, e.g. script based element picking, the plot functionality can be started by script either blocking or nonblocking.
myImage = dataObject.randN([200, 200], 'float32')
[number, handle] = plot(myImage, "itom2dQwtPlot")
# Blocking access which return the values for a single point in myElement
# Structure will be dataObject([8, 1], 'float32') with [[idx], [type], [x], [y], [0], [0], [0],[0]]
myElement = dataObject()
handle.drawAndPickElements(101, myElement, 1)
# None blocking plot
# Structure will be dataObject([1, 11], 'float32') with [idx, type, x, y, 0, 0, 0, 0]
handle.call("userInteractionStart", 101, True, 1)
# > Read out later after plot is finished
myGeometry = handle["geometricElements"]
The blocking code will wait until the selection is done or the selection was aborted by user and will than return the corresponding object. The nonblocking code will return directly. To access the geometric elements the corresponding “signal” for userInteractionDone should be used to noticed the end of the user interaction.
The geometric elements can also be set by script by calling the corresponding slot.
myImage = dataObject.randN([200, 200], 'float32')
[number, handle] = plot(myImage, "itom2dQwtPlot")
# Add the marker to the plot
# marker is filled according to marker style definition
marker = dataObject([8,1],'float32', data = [101.0, 1.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0,0])
handle.call("plotMarkers", marker, "b", "")
# Delete all marker and than plot new marker
# marker is filled according to marker style definition
myGeometry = dataObject([1,11],'float32', data = [101.0, 1.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0,0, 0.0, 0.0, 0.0])
handle["geometricElements"] = myGeometry
The geometric elements can be read any time using the property “geometricElements”.
# Reading geometric elements
myGeometry = handle["geometricElements"]
The object “myGeometry” consists of all geometric elements with in the plot. Each row corresponds to one geometric element while the parameters for each element are align columnwise. This kind of reading differs from the blockingvariant (“drawAndPickElements”). The blockingvariant returns only the data created during the current function call and ignores old geometric elements. In this case the elements are aligned columnwise. This means each column corresponds to on element while its data is stored along the rows. For the differernt definitions of the geometric elements see section “Indexing of Geometric Elements”.
Implemented Functions, Signals and Slots¶
The Qwtplot widgets functions had to be updated. The QwtWidgets got the following properties, respectively setter / getterfunctions related to plotting:
 “geometricElementsCount”, get the number of geometric elements in this plot, READONLY
 “keepAspectRatio”, enable or disable a fixed aspect ratio of 1:1 for the plot canvas.
 “enablePlotting”, enable and disable plotting toolbar
 “selectedGeometry”, set / get the current selected geometric element
In complete theses the functionality of the drawing interface, the following slots have been added to the widgets:
 “plotMarkers” Add markers and geometric elements to plot according to dataObject and style type. For geometric “style is not used”, type in “b”.
 “userInteractionStart” Start a nonblocking user interaction for “multipointpick” or geometric elements with element count.
 “clearGeometricElements” Delete all existing geometric elements within the plot
To register changes in the plot elements and finished user interactions, the following signals where implemented:
 “userInteractionDone”, Emitted, when user interaction is finished or aborted
 “plotItemChanged”, Emitted, when a geometric element was changed and changing is finished. Not fully PythonCompatible.
 “plotItemDeleted”, Emitted, when a specific plot item is deleted
 “plotItemsDeleted”, Emitted, when all plot items are deleted
 “plotItemsFinished”, Emitted, when the plotting function is finished, similar to userInteractionDone
For the blocking connection the plotItemclass got the additional function drawAndPickElements(type, dataObject, count), see plotItem
.
Note
If the plot is embedded in a graphical user interface, the python based access to the plot via its object name returns an instance of uiItem
.
However, you can cast this instance to plotItem
using a python cast operator:
import itom
plot = itom.plotItem(myGui.plotObjectName)
If myGui.plotObjectName is not an instance of plotItem
a runtime error is thrown. This cast is only available for itom > 1.4.0.
Indexing for Geometric Elements¶
The definition of the geometric elements depends on the implementation. The “plotMarker” and its corresponding getter / setterfunction uses a Matlab orientated structure. The structure a dataObject with 8 rows and n columns where n depends on the number of elements. Points are defined by their location, while ellipses and rectangles are defined by their diagonal edges.
The “geometricElements”property uses geometric elements in a more mathematical orientated description. The dataObject structure is defined as “float32” with n by 11 elements. Most setter functions also support “float32” elements. Each of the n rows corresponds to an elements (except polygonshapes). The indexing follows the geometricPrimitivestruct in c++.
The geometricPrimitive is a struct within the cStuctur of the program designed for exchanging the geometric elements from plots to other elements. The structure can be used rowwise as dataObject or float32lists
At the moment only tPoint, tLine, tEllipse and tRectangle are supported.
The cells contain:
 The unique index of the current primitive, castable to int32 with a maximum up to 16bit index values
 Type flag 0000FFFF and further flags e.g. read&write only FFFF0000
 First coordinate with x value
 First coordinate with y value
 First coordinate with z value
All other values depends on the primitive type and may change between each type.
 A point is defined as idx, flags, centerX0, centerY0, centerZ0
 A line is defined as idx, flags, x0, y0, z0, x1, y1, z1
 A ellipse is defined as idx, flags, centerX, centerY, centerZ, r1, r2
 A circle is defined as idx, flags, centerX, centerY, centerZ, r
 A rectangle is defined as idx, flags, x0, y0, z0, x1, y1, z1, alpha
 A square is defined as idx, flags, centerX, centerY, centerZ, a, alpha
 A polygon is defined as idx, flags, posX, posY, posZ, directionX, directionY, directionZ, idx, numIdx

class
ito::PrimitiveContainer
This is a container to store geometric primitives. The enum tPrimitive of this file defines the geometric primitives for all plots.
 Author
 Wolfram Lyda, twip optical solutions GmbH, Stuttgart
 Date
 12.2013
Public Type
 tPrimitive enum
Discribes the different primtive types
 See
 itom1DQwtPlot, itom2DQwtPlot
Values:
tNoType
= 0
tMultiPointPick
= 6
! NoType for pick
tPoint
= 101
! Multi point pick
tLine
= 102
! Element is tPoint or order to pick points
tRectangle
= 103
! Element is tLine or order to pick lines
tSquare
= 104
! Element is tRectangle or order to pick rectangles
tEllipse
= 105
! Element is tSquare or order to pick squares
tCircle
= 106
! Element is tEllipse or order to pick ellipses
tPolygon
= 110
! Element is tCircle or order to pick circles
tMoveLock
= 0x00010000
! Element is tPolygon or order to pick polygon
tRotateLock
= 0x00020000
! Element is readOnly
tResizeLock
= 0x00040000
! Element can not be moved
tTypeMask
= 0x0000FFFF
! Element can not be moved
tFlagMask
= 0xFFFF0000
! Mask for the type space
Evaluation of Geometric Elements¶
The evaluateGeomtricswidget is designed to load geometric definition stored in a float32 dataObject with a columnsize of >10 elements and a row for each geometric element to display. Further more it allows the evaluation of geometric relations between the geometric primitives. See section Custom Designer Widgets for the widget description.
Demo Scripts and Examples¶
uiMeasureToolMain.py
Description: Advanced GUI which enables geometric plotting and measurements within a 2DQWTPlot. This file shows how to autoconnect to signals and how to use buttons. The corresponding uifile is uiMeasureToolMain.ui.demoPickPointsAndMarkers.py
Description: Demo for picking & plotting points and picking & plotting ellipses.