Drawing and Graphical Interactions

Introduction

  • Whenever relevant, the eVision tools provide methods Draw to render their contents and/or configuration. This is, for instance, the contents of an EImage or the frame of an EROI.

  • A given tool can have multiple methods Draw, usually one for each feature available.

  • The Draw methods take an instance of EDrawAdapter .NET Python as their main parameter, and additional parameters for zoom and pan:

    Tool.Draw(EDrawAdapter* adapter, float zoomX, float zoomY, float panX, float panY);

    • zoomX and zoomY are expressed in percentage, 1 is the default value and means no zoom.

    • It can be different in the horizontal and vertical directions (which can be useful in the case of non-square pixels for instance).

    • If you don’t provide a vertical zoom, or set it to 0, it will be set identical to the horizontal one.

    • panX and panY are expressed in pixels, but in image coordinates. It means that the value you pass to panX and panY are multiplied by the corresponding zoom before being applied.

Example: How to draw an image and a ROI frame on a window in C++ under Windows:

EImageBW8 image;
EROIBW8 roi;
EWindowsDrawAdapter adapter(windowHdc);
image.Draw(adapter);
roi.DrawFrame(adapter);

Graphical interactions

  • You can configure some of the eVision tools graphically and use the provided methods to put your configuration in place.

  • Graphical Interaction-enabled tools provide special parameters to some of their methods Draw to draw handles on the tool representation.

  • To capture the user interactions with those handles, these tools also provide two specialized methods:

    • HitTest detects if a handle is under the mouse when providing it with the current cursor coordinates. You typically use this test during a mouse button down event.

    • Drag moves the detected handle to the given coordinates. This in turn modifies the tool configuration to match the new handle position. Drag is typically associated with the mouse button up event.

    Note

    HitTest and Drag use the same zoom and pan parameters as Draw. You must set them the same way (with the same values) to achieve the desired result.

  • Use Easy::GetHandleSize .NET Python to change the handle size.

    • This value influences the drawing and the hit area.

    • By default, the handle size is equal to 8 pixels.

Draw adapters

Standard draw adapters

eVision provides a set of off-the-shelf draw adapters that you can use in different situations:

  • EWindowsDrawAdapter .NET Python allows to draw on Windows systems. To draw on a window, provide the window’s HDC to its constructor, or, to draw in an EImage buffer, provide that EImage.

    • It relies on GDI and GDI+ to provide its services.

    • This is the preferred way to draw on Windows using C++.

  • ESystemDrawingDrawAdapterallows to draw on Windows systems using .NET. To draw on a window, provide the window’s Graphics object to its constructor.

    • This is the preferred way to draw on Windows when using .NET.

  • QtDrawAdapter allows you to draw using Qt on a QPainter context. To draw on a QPainter context, provide the QPainter to the constructor, or, to draw on an EImage buffer, provide that EImage.

    • You can use the QtDrawAdapter both on Windows and Linux.

    • This is the preferred way to draw on Linux.

      Note

      QtDrawAdapter is using an external resource (namely Qt) and as such is provided as source code in its own header rather than in the global eVision header. For more information about external and custom draw adapters, see below.

  • EGenericDrawAdapter .NET Python is a draw adapter that can only render on an EImage, but it can do it in a consistent manner on all supported OSes.

    • It is available on both Windows and Linux.

Drawing in an EImage

  • As said above, you can draw in an EImage (usually an EImageBW8 or EImageC24A) by initializing a draw adapter with that image and using either the eVision methods Draw or the draw adapter drawing primitives. EGenericDrawAdapter .NET Python is the recommended way to draw in an image.

EImageC24A image;
EMatrixCode code;
EGenericDrawAdapter adapter(image);
code.DrawPosition(adapter);