Drawing GraphicsCognex VisionPro

This topic contains the following sections.

VisionPro provides many basic shapes that you can add to a CogDisplay, such as the CogCircle, CogRectangle, CogEllipse, and CogRectangleAffine. These shapes can be interactive graphics that the user can manipulate with the mouse, or static shapes that the user cannot change.

See the topic Displaying An Image for more information on using a Cognex Display control. To draw graphics on a CogDisplay control, you need to add a reference to the Cognex.VisionPro, Cognex.VisionPro.Core, and the Cognex.VisionPro.Display.Controls assemblies in your Visual Studio.NET application.

Creating Shapes and Setting Shape Properties

The following programming statements create an instance of a CogRectangle and a CogCircle, sets their properties, and adds them to a CogDisplay control.

using Cognex.VisionPro;
using Cognex.VisionPro.Display;

private void InitializeShapes()
{
        cgRect = new CogRectangle();
        cgCirc = new CogCircle();

        cgRect.X = 150;
        cgRect.Y = 150;
        cgRect.Color = CogColorConstants.Green;
        cgRect.SelectedSpaceName = "*";
        cgRect.Interactive = true;

        // Allow user to change the size only
        cgRect.GraphicDOFEnable = CogRectangleDOFConstants.Size;

        cgCirc.CenterX = 220;
        cgCirc.CenterY = 220;
        cgCirc.Color = CogColorConstants.Blue;
        cgCirc.SelectedSpaceName = "*";
        cgCirc.Interactive = true;

        // Allow the user to change the radius only
        cgCirc.GraphicDOFEnable = CogCircleDOFConstants.Radius;

        cogDisplay1.InteractiveGraphics.Add(cgCirc, null, false);
        cogDisplay1.InteractiveGraphics.Add(cgRect, null, false);
}
Graphics Performance

If you have several graphics to add to a display, you can set the DrawingEnabled property to false to postpone drawing until all the shapes are added to the CogDisplay control. Another method, [M:Cognex.VisionPro.Display.CogInteractiveGraphicsContainer.AddList((Cognex.VisionPro.CogGraphicInteractiveCollection,System.String,System.Boolean)], allows you to add an entire list of graphics all at once.