Optimizing Graphics Performance Cognex VisionPro
This topic contains the following sections:
Disable Graphics Updates Whenever Possible
Minimize Use of Expensive Shapes
Fastest: Rectilinear Shapes
Medium Speed: Curved Shapes
Slowest: Graphics Containing Text
Remove Graphics When Changing Image or Fitting Display
Use Interactive Graphics
Consider Alternatives to CreateResultGraphics()
Optimize the Order of Operations
VisionPro provides a rich set of graphic shapes and functions for displaying these shapes on a CogDisplay. The number and complexity of shapes that your application creates can affect the time and computing resources required to display these graphics. The guidelines described in this topic can help you obtain the best performance possible.
Disable Graphics Updates Whenever Possible
In general, whenever you make a change to a CogDisplay, the display will immediately update its appearance to reflect the change. If you are making multiple changes, such as adding or removing graphics or supplying a new image to display, you can greatly reduce the amount of time required to make these changes by setting DrawingEnabled to false, making all of the changes, then setting DrawingEnabled to true.
Minimize Use of Expensive Shapes
Different types of VisionPro shapes require different amounts of time to display. You can improve display performance by minimizing the use of shapes that are costly to display. When considering the time required for display, VisionPro shapes can be divided into the three categories listed below:
Fastest: Rectilinear Shapes
Shapes made up exclusively of straight lines such as CogLineSegment, CogRectangle, and CogRectangleAffine require the least amount of time to display.
Medium Speed: Curved Shapes
Shapes that contain circular or elliptical shapes such as CogCircle, CogEllipticalArc, and CogEllipticalAnnulusSection take more time to display than rectilinear shapes. For shapes of comparable size and complexity, shapes with circular or elliptical features take about twice as long to display as rectilinear shapes.
Slowest: Graphics Containing Text
Any graphics that include text, such as CogCoordinateAxes, are substantially slower to render than shapes without text. For example, a CogCoordinateAxes graphic might take up to as much as 100 times longer to render than a CogRectangle.
Remove Graphics When Changing Image or Fitting Display
Changing a display’s image or Fit an image to the display region can take two or three times as long to perform if any graphics are present in the CogDisplay’s InteractiveGraphics or StaticGraphics collection.
You can improve the speed of these operations by clearing graphics first, performing the operation, then restoring the graphics.
In addition to changing the displayed image and fitting the image to the display area, the process of zooming or scaling the image takes much longer if graphics are present.
Use Interactive Graphics
The time required to render a VisionPro graphic shape is the same regardless of whether the shape is added to a [T:Cognex.VisionPro.Display/CogDisplay]'s InteractiveGraphics or StaticGraphics collection. The time required to add or remove a graphic, however, is greater for static graphics than for interactive graphics. Therefore, for best performance, add all your graphics to the interactive graphics collection. (You can prevent a user from manipulating a graphic in the interactive collection by setting the graphic’s Interactive property to false.)
Consider Alternatives to CreateResultGraphics()
The CreateResultGraphics method implemented by many tools’ results objects produces a graphics collection that contains result graphics that correspond to each result produced by the tool. You can use the appropriate bits defined in the tool’s ResultGraphicConstants enumeration to limit the graphics that are created, but in many cases the overhead of creating the composite graphics that link all of the graphics associated with a single result and the time required to generate data such as strings for graphic tool tips, can result in slow display performance.
As an alternative, you can consider generating your own custom result graphics based on the data in a tool’s results object. Doing this gives you a finer degree of control over the graphics that are produced for a tool’s results.
Optimize the Order of Operations
As you apply the guidelines in this topic to your application, you should keep in mind that the order in which you perform graphics and display operations determines how much time these operations require. For example, if your application acquires an image, runs a vision tool using that image as input, then wishes to display that image overlaid with result graphics from the tool, it should perform these actions in this order:
Disable display updates (set DrawingEnabled to false).
Remove all graphics from the display.
Update the display with the new image.
Fit the image to the display (if required).
Add the results graphics produced by the last run of the tool.
Enable display updates.
By performing these steps in this order, you minimize the total amount of time required to display the image and graphics.