Prerequisites
To integrate DPF into an existing C++ project, you must have access to the following files of the AWP_ROOT@doc_ansys_ver/dpf/include folder (AWP_ROOT@doc_ansys_ver being an environment variable defining the root of the Ansys Inc or DPF Server product):- dpf_api.h
- dpf_api_i.cpp
Specify location of DPF files
Using Visual Studio
- In the “Properties” of the project, open the “C/C++” tab.
- Switch to the “general” tab. Edit the “Additional Include Directories” section so that it contains the ”$(DPF_HGP_ROOT)” field.
- Ensure the compilation is done for the same platform and the build is done using the configuration where the properties have been updated (for example, if the ‘Release|x64’ properties are modified, build with the ‘Release|x64’ configuration).
Using CMake
Add the following line in the CMakeLists.txt file:Integrate DPF into an existing project
In the header file where the DPF capabilities are used, add the following declarations:Include DPF
This is needed to access DPF capabilities.Declare DPF LibraryHandle
The LibraryHandle object must be alive all the time DPF is used. It should be unique, instantiated once per project. This is why it is declared as static structure:Instantiate DPF LibraryHandle
Before using any DPF capabilities, instantiate the LibraryHandle. This initializes DPF. To proceed, add the following line:Use DPF capabilities
Once the LibraryHandle is instantiated, all the DPF capabilities can be used. The following example adds two vectors by components:Run the application
Once the application is compiled, the environment must be updated before running the application: DPF entry point location must be known by the application, using PATH on Windows or LD_LIBRARY_PATH on Linux. The following command can be used. For Windows:Example full code compiled with Visual Studio on Windows
The following is the complete code showing how to add DPF capabilities in an already existing C++ application which displays"Hello World!".
The following code adds the components of two 3D vectors.
It gathers all the instructions previously provided in this section.
It can be placed into a IntegrateDpfExample.cpp file, compiled and run: