Skip to content

Commit

Permalink
Option struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Jul 18, 2024
1 parent 6701eeb commit d7c6154
Show file tree
Hide file tree
Showing 12 changed files with 1,364 additions and 321 deletions.
140 changes: 77 additions & 63 deletions application/F3DOptionsParser.cxx

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ F3DStarter::F3DStarter()
: Internals(std::make_unique<F3DStarter::F3DInternals>())
{
// Set option outside of command line and config file
this->Internals->DynamicOptions.set(
"ui.dropzone-info", "Drop a file or HDRI to load it\nPress H to show cheatsheet");
this->Internals->DynamicOptions.getStruct().ui.dropzone_info = "Drop a file or HDRI to load it\nPress H to show cheatsheet";

// Initialize dmon
dmon_init();
Expand Down Expand Up @@ -510,9 +509,9 @@ int F3DStarter::Start(int argc, char** argv)
// TODO: add a image::canRead

// Load the file as an HDRI instead of adding it.
this->Internals->Engine->getOptions().set("render.hdri.file", file);
this->Internals->Engine->getOptions().set("render.hdri.ambient", true);
this->Internals->Engine->getOptions().set("render.background.skybox", true);
this->Internals->Engine->getOptions().getStruct().render.hdri.file = file;
this->Internals->Engine->getOptions().getStruct().render.hdri.ambient = true;
this->Internals->Engine->getOptions().getStruct().render.background.skybox = true;

// Rendering now is needed for correct lighting
this->Render();
Expand Down Expand Up @@ -557,13 +556,12 @@ int F3DStarter::Start(int argc, char** argv)

if (!fullPath.empty())
{
this->Internals->Engine->getOptions().set(
"model.scivis.colormap", F3DColorMapTools::Read(fullPath));
this->Internals->Engine->getOptions().getStruct().model.scivis.colormap = F3DColorMapTools::Read(fullPath);
}
else
{
f3d::log::error("Cannot find the colormap ", this->Internals->AppOptions.ColorMapFile);
this->Internals->Engine->getOptions().set("model.scivis.colormap", std::vector<double>{});
this->Internals->Engine->getOptions().getStruct().model.scivis.colormap = std::vector<double>{};
}
}

Expand Down Expand Up @@ -896,8 +894,8 @@ void F3DStarter::LoadFile(int index, bool relativeIndex)
loader.loadGeometry("", true);
}

this->Internals->Engine->getOptions().set("ui.dropzone", !this->Internals->LoadedFile);
this->Internals->Engine->getOptions().set("ui.filename-info", filenameInfo);
this->Internals->Engine->getOptions().getStruct().ui.dropzone = !this->Internals->LoadedFile;
this->Internals->Engine->getOptions().getStruct().ui.filename_info = filenameInfo;
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -949,26 +947,27 @@ void F3DStarter::SaveScreenshot(const std::string& filenameTemplate, bool minima
f3d::options optionsCopy = this->Internals->Engine->getOptions();

bool noBackground = this->Internals->AppOptions.NoBackground;
f3d::options_struct& optionStruct = options.getStruct();
if (minimal)
{
options.set("ui.bar", false);
options.set("ui.cheatsheet", false);
options.set("ui.filename", false);
options.set("ui.fps", false);
options.set("ui.metadata", false);
options.set("ui.animation-progress", false);
options.set("interactor.axis", false);
options.set("render.grid.enable", false);
optionStruct.ui.scalar_bar = false;
optionStruct.ui.cheatsheet = false;
optionStruct.ui.filename = false;
optionStruct.ui.fps = false;
optionStruct.ui.metadata = false;
optionStruct.ui.animation_progress = false;
optionStruct.interactor.axis = false;
optionStruct.render.grid.enable = false;
noBackground = true;
}

f3d::image img = this->Internals->Engine->getWindow().renderToImage(noBackground);
this->Internals->addOutputImageMetadata(img);
img.save(path.string(), f3d::image::SaveFormat::PNG);

options.getAsDoubleRef("render.light.intensity") *= 5;
optionStruct.render.light.intensity = optionStruct.render.light.intensity * 5;
this->Render();

this->Internals->Engine->setOptions(optionsCopy);
this->Render();
}
Expand Down
34 changes: 34 additions & 0 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,40 @@ configure_file(
"${CMAKE_CURRENT_BINARY_DIR}/src/config.cxx"
@ONLY)

function(parse_json_option top_json)
string(JSON options_length LENGTH ${top_json})
MATH(EXPR options_length "${options_length} - 1")
foreach(json_idx RANGE ${options_length})
string(JSON member_name MEMBER ${top_json} ${json_idx})
string(JSON cur_json GET ${top_json} ${member_name})
string(JSON option_type ERROR_VARIABLE type_error GET ${cur_json} "type")
if(type_error STREQUAL "NOTFOUND")
string(JSON option_default_value GET ${cur_json} "default_value")
if(option_type STREQUAL "double_vector")
string(APPEND option_struct "std::vector<double> ${member_name} = {${option_default_value}};\n")
elseif(option_type STREQUAL "string")
string(APPEND option_struct "std::string ${member_name} = \"${option_default_value}\";\n")
else()
string(APPEND option_struct "${option_type} ${member_name} = ${option_default_value};\n")
endif()
else()
string(APPEND option_struct "struct ${member_name} {\n")
parse_json_option(${cur_json})
string(APPEND option_struct "\n} ${member_name};\n")
endif()
endforeach()
set(option_struct "${option_struct}" PARENT_SCOPE)
endfunction()

# Parse options.json and generate headers
set(option_struct "struct options_struct_gene {\n")

## Read the .json file
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/options.json option_json)
parse_json_option(${option_json})
string(APPEND option_struct "\n};")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/public/options_struct.h "${option_struct}")

# Define libf3d target
set(F3D_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/animationManager.cxx
Expand Down
30 changes: 30 additions & 0 deletions library/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"scene": {
"up_direction": {
"type": "string",
"default_value": "+Y"
},
"animation": {
"autoplay": {
"type": "bool",
"default_value": "false"
},
"index": {
"type": "int",
"default_value": "0"
},
"speed_factor": {
"type": "double",
"default_value": "1.0"
}
}
},
"render": {
"grid": {
"color": {
"type": "double_vector",
"default_value": "0.0, 0.0, 0.0"
}
}
}
}
Loading

0 comments on commit d7c6154

Please sign in to comment.