Chapter 21   Introducing HDevEngine

As the name suggests, HDevEngine is the “engine” of HDevelop. This chapter briefly introduces you to its basic concepts. Chapter “HDevEngine in C++ Applications” explains how to use it in C++ applications, and chapter “HDevEngine in .NET Applications” how to use it in .NET applications (C#, Visual Basic .NET, etc.). Additional information that is independent of the used programming language can be found in chapter “General Information”.

What Can You Do With HDevEngine?

With HDevEngine, you can execute complete HDevelop programs or individual procedures from a C++ application or an application that can integrate .NET objects, e.g., C# or Visual Basic .NET. Thus, you can use HDevelop programs not only for prototyping, but also to completely develop and run the machine vision part of your application.

Because HDevEngine acts as an interpreter, you can modify the HDevelop program or procedure without needing to compile and link the application (if you don't change the procedure's signature), as would be necessary if you export the program or procedure and integrate the code manually. This means that you can easily update the machine vision part of an application by replacing individual HDevelop files.

What HDevEngine Does Not Do

Note that HDevEngine does not implement the complete functionality of HDevelop, only what is necessary to execute programs and procedures. In particular, it does not implement the display of variables and results in the graphics window, i.e., the internal operators like dev_display. However, you can “redirect” these operators to your own implementation. Thus, you can decide which visualization is important and where and how it is to take place in your application.

What is HDevEngine?

HDevEngine is provided as a C++ class library and a .NET assembly. It consists of the following classes:

How to Develop Applications With HDevEngine

With HDevEngine, you can execute complete HDevelop programs or individual local or external HDevelop procedures. Which way is better depends on the stage of development and on your task:

Parallel Programming With HDevEngine

HDevEngine is thread-safe and reentrant. Settings like the procedure path and the implementation of the display operators are managed globally for all threads by the main HDevEngine class. Threads then typically have their own instance of program or procedure calls. They can share instances of the classes for programs and procedures.

Note that HDevEngine does not safely support subthreads (started with par_start) that continue to run after the main procedure call returns to application code. A procedure that is intended as entry point for an HDevEngine application should join all of its started subthreads before returning.

Additionally, please have a look at the general information about parallel programming with HALCON in section “Parallel Programming Using HALCON”, in particular the style guide in section “Program Design Issues for Parallelization”!

Just-in-time Compilation of Procedures in HDevEngine

For optimized performance, HDevEngine can also execute compiled procedures using its built-in just-in-time (JIT) compiler. The compilation is turned on or off using an attribute of the HDevEngine class. If turned on, the compilation will take place implicitly the first time a procedure is called. It is also possible to explicitly compile the used procedures of a HDevelop program. See section “Using the Just-in-time Compiler with HDevEngine/C++” (C++) and section “Using the Just-in-time Compiler with HDevEngine/.NET” (.NET) for more information about using the JIT compiler.

JIT compilation is not supported for procedures that use any of the following features:

If one of these features is found, the corresponding procedure is executed uncompiled as before by HDevEngine.

Notarization for macOS

Starting with macOS 10.15, Apple mandates that all Mac software distributed outside of the Mac App Store must be “notarized”: Before shipping applications, they have to be submitted to Apple's notary service, which then scans them for malicious content and checks for code-signing issues. If everything succeeds, the notary service generates and publishes a Gatekeeper ticket for the application.
For more information about notarization, see the Apple developer documentation.

The HALCON installer is notarized by Apple. However, any application using HDevEngine with enabled JIT compiler that you want to sign yourself with Apple's Hardened Runtime has to set the “Allow Unsigned Executable Memory Entitlement”. Otherwise, the signed user application may crash.
For more information about Hardened Runtime, see the Apple developer documentation.

HDevEngine XL

Like HALCON, the language-dependent versions of HDevEngine are provided in two variants: based on HALCON and based on HALCON XL. The latter use the XL versions of the HALCON library and of HALCON/C++, and HALCON/.NET, respectively.