Models

Loading a model

After exporting a runtime model from fluxTrainer as a .fluxmdl file, it may be loaded into fluxEngine. fluxEngine supports loading the model directly from disk, as well as parsing a model in memory if the byte sequence of the model was already loaded by the user.

The following example shows how to load a model:

 1 fluxEngine_C_v1_Model* model = NULL;
 2 fluxEngine_C_v1_Error* error = NULL;
 3 int rc = 0;
 4 #if defined(_WIN32)
 5 /* Windows: use wide filenames to be able to cope with characters
 6  * not in the current code page
 7  */
 8 rc = fluxEngine_C_v1_Model_load_file_w(handle, L"sample_model.fluxmdl",
 9                                        &model, &error);
10 #else
11 rc = fluxEngine_C_v1_Model_load_file(handle, "sample_model.fluxmdl",
12                                      &model, &error);
13 #endif
14 if (rc != 0) {
15     fprintf(stderr, "Could not load model: %s\n",
16             fluxEngine_C_v1_Error_get_message(error));
17     fluxEngine_C_v1_Error_free(error);
18     return;
19 }

Extracting information from a model

It is possible obtain information about the groups that were defined in a model and obtain both their name and their color. The following snippet will print the names of all groups and their colors:

 1 fluxEngine_C_v1_Error* error = NULL;
 2 int rc = 0;
 3 int group_count = 0;
 4 int i = 0;
 5 group_count = fluxEngine_C_v1_Model_num_groups(model, &error);
 6 if (group_count < 0) {
 7     fprintf(stderr, "Could not obtain number of groups in model: %s\n",
 8             fluxEngine_C_v1_Error_get_message(error));
 9     fluxEngine_C_v1_Error_free(error);
10     return;
11 }
12 for (i = 0; i < group_count; ++i) {
13     char* name = NULL;
14     uint32_t color = 0xFF000000u;
15     rc = fluxEngine_C_v1_Model_get_group_info(model, i, &name, &color, &error);
16     if (rc != 0) {
17         fprintf(stderr, "Could not obtain information about group %d: %s\n",
18                 i, fluxEngine_C_v1_Error_get_message(error));
19         fluxEngine_C_v1_Error_free(error);
20         return;
21     }
22     printf("Group with name %s has color rgb(%d, %d, %d)\n",
23            name,
24            (int) ((color >> 16u) & 0xffu),
25            (int) ((color >>  8u) & 0xffu)
26            (int) ((color >>  0u) & 0xffu));
27     fluxEngine_C_v1_string_free(name);
28 }