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

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