Skip to content

Commit

Permalink
not done yet but getting closer
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Sep 14, 2024
1 parent 122ba81 commit 7cf94b0
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 20 deletions.
12 changes: 10 additions & 2 deletions application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct CLIGroup
/**
* Declaration of all F3D CLI options except `--input` using above structs
* Order of groups matters in the context of `--help`
* TODO update help text for optional values
*/
// clang-format off
#if F3D_MODULE_RAYTRACING
Expand Down Expand Up @@ -82,7 +83,7 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
{ "up", "", "Up direction", "{-X, +X, -Y, +Y, -Z, +Z}", "" },
{ "axis", "x", "Show axes", "<bool>", "1" }, { "grid", "g", "Show grid", "<bool>", "1" },
{ "grid-absolute", "", "Position grid at the absolute origin instead of below the model", "<bool>", "1" },
{ "grid-unit", "", "Size of grid unit square, set to a non-positive value for automatic computation", "<value>", "" },
{ "grid-unit", "", "Size of grid unit square, automatically computed by default", "<value>", "" },
{ "grid-subdivisions", "", "Number of grid subdivisions", "<value>", "" },
{ "grid-color", "", "Color of main grid lines", "<R,G,B>", "" },
{ "edges", "e", "Show cell edges", "<bool>", "1" },
Expand Down Expand Up @@ -451,7 +452,14 @@ F3DOptionsTools::OptionsDict F3DOptionsTools::ParseCLIOptions(
if (libIter != F3DOptionsTools::LibOptionsNames.end())
{
f3d::options opt;
defaultValue = opt.getAsString(std::string(libIter->second));
try
{
defaultValue = opt.getAsString(std::string(libIter->second));
}
catch (const f3d::options::unset_exception&)
{
// let defaultValue empty for unset options
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion application/F3DOptionsTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static inline const std::map<std::string_view, std::string_view> LibOptionsNames
{ "animation-frame-rate", "scene.animation.frame_rate" },
{ "font-file", "ui.font_file" },
{ "point-sprites", "model.point_sprites.enable" },
{ "point-sprites-type", "model.point_sprites.type" },
{ "point-sprites-type", "model.point_sprites.shape" },
{ "point-sprites-size", "model.point_sprites.size" },
{ "point-size", "render.point_size" },
{ "line-width", "render.line_width" },
Expand Down
4 changes: 2 additions & 2 deletions application/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ int main(int argc, char** argv)
// exit with error when needed
exit(EXIT_FAILURE);
}
catch (const std::exception& ex)
/* catch (const std::exception& ex)
{
f3d::log::error("F3D encountered an unexpected exception:");
f3d::log::error(ex.what());
f3d::log::waitForUser();
exit(EXIT_FAILURE);
}
}*/

return res;
}
Expand Down
8 changes: 4 additions & 4 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ f3d_test(NAME TestGridColor DATA suzanne.ply ARGS -g --grid-color=1,1,1)
f3d_test(NAME TestAxis DATA suzanne.ply ARGS -x)
f3d_test(NAME TestBackfaceVisible DATA backface.vtp ARGS --backface-type=visible)
f3d_test(NAME TestBackfaceHidden DATA backface.vtp ARGS --backface-type=hidden)
f3d_test(NAME TestPointCloud DATA pointsCloud.vtp ARGS -o --point-size=20)
f3d_test(NAME TestPointCloudBar DATA pointsCloud.vtp ARGS -sob --point-size=20)
f3d_test(NAME TestPointCloudUG DATA pointsCloud.vtu ARGS -o --point-size=20)
f3d_test(NAME TestPointCloud DATA pointsCloud.vtp ARGS -o --point-sprites-size=20)
f3d_test(NAME TestPointCloudBar DATA pointsCloud.vtp ARGS -sob --point-sprites-size=20)
f3d_test(NAME TestPointCloudUG DATA pointsCloud.vtu ARGS -o --point-sprites-size=20)
f3d_test(NAME TestPointCloudVolume DATA bluntfin.vts ARGS -sob)
f3d_test(NAME TestPointCloudDefaultScene DATA pointsCloud.vtp ARGS --point-size=20)
f3d_test(NAME Test3DSImporter DATA iflamigm.3ds ARGS --up=+Z)
Expand Down Expand Up @@ -721,7 +721,7 @@ f3d_test(NAME TestInteractionCycleCell DATA waveletArrays.vti INTERACTION) #VCCC
f3d_test(NAME TestInteractionCycleComp DATA dragon.vtu INTERACTION) #SYYYY
f3d_test(NAME TestInteractionCycleScalars DATA dragon.vtu INTERACTION) #BSSSS
f3d_test(NAME TestInteractionVolumeInverse DATA HeadMRVolume.mhd ARGS --camera-position=127.5,-400,127.5 --camera-view-up=0,0,1 INTERACTION) #VI
f3d_test(NAME TestInteractionPointCloud DATA pointsCloud.vtp ARGS --point-size=20 INTERACTION) #O
f3d_test(NAME TestInteractionPointCloud DATA pointsCloud.vtp ARGS --point-sprites-size=20 INTERACTION) #O
f3d_test(NAME TestInteractionDirectory DATA mb INTERACTION ARGS --scalar-coloring) #Right;Right;Right;Left;Up;
f3d_test(NAME TestInteractionDirectoryLoop DATA mb INTERACTION ARGS --scalar-coloring) #Left;Left;Left;
f3d_test(NAME TestInteractionDirectoryEmpty DATA mb INTERACTION NO_DATA_FORCE_RENDER) #Right;Right;Right;
Expand Down
30 changes: 22 additions & 8 deletions library/private/options_tools.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,17 @@ void set(options& opt, const std::string& name, const option_variant_t& value)
*/
option_variant_t get(const options& opt, const std::string& name)
{
// clang-format off
${_options_getter};
// clang-format on
else throw options::inexistent_exception("Option " + name + " does not exist");
try
{
// clang-format off
${_options_getter};
// clang-format on
else throw options::inexistent_exception("Option " + name + " does not exist");
}
catch (const std::bad_optional_access&)
{
throw options::unset_exception("Trying to get " + name + " before it was set");
}
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -277,10 +284,17 @@ void setAsString(options& opt, const std::string& name, const std::string& str)
*/
std::string getAsString(const options& opt, const std::string& name)
{
// clang-format off
${_options_string_getter};
// clang-format on
else throw options::inexistent_exception("Option " + name + " does not exist");
try
{
// clang-format off
${_options_string_getter};
// clang-format on
else throw options::inexistent_exception("Option " + name + " does not exist");
}
catch (const std::bad_optional_access&)
{
throw options::unset_exception("Trying to get " + name + " before it was set");
}
}
} // option_tools
} // f3d
Expand Down
12 changes: 12 additions & 0 deletions library/public/options.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public:
/**
* Get an option as a variant based on its name
* Throw an options::inexistent_exception if option does not exist.
* Throw an options::unset_exception if option has not been set.
*/
option_variant_t get(const std::string& name) const;
#endif
Expand All @@ -73,13 +74,15 @@ public:
/**
* Get an option as a string based on its name
* Throw an options::inexistent_exception if option does not exist.
* Throw an options::unset_exception if option has not been set.
*/
std::string getAsString(const std::string& name) const;

/**
* A boolean option specific method to toggle it.
* Throw an options::inexistent_exception if option does not exist.
* Throw an options::incompatible_exception if option is not boolean.
* Throw an options::unset_exception if option has not been set.
*/
options& toggle(const std::string& name);

Expand Down Expand Up @@ -145,6 +148,15 @@ public:
explicit inexistent_exception(const std::string& what = "");
};

/**
* An exception that can be thrown by the options
* when a provided option is accessed before being set.
*/
struct unset_exception : public exception
{
explicit unset_exception(const std::string& what = "");
};

#ifndef F3D_DISABLE_CXX17_API
/**
* The complete generated options struct
Expand Down
2 changes: 1 addition & 1 deletion library/src/animationManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool animationManager::Initialize(
{
log::warn("An animation index has been specified but there are no animation available.");
}
if (options->scene.animation.time != 0)
if (options->scene.animation.time.has_value())
{
log::warn("No animation available, cannot load a specific animation time");
}
Expand Down
31 changes: 30 additions & 1 deletion library/src/options.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,30 @@ options& options::toggle(const std::string& name)
//----------------------------------------------------------------------------
bool options::isSame(const options& other, const std::string& name) const
{
return options_tools::get(*this, name) == options_tools::get(other, name);
option_variant_t ownVal;
option_variant_t otherVal;
bool ownUnset = false;
bool otherUnset = false;

try
{
ownVal = options_tools::get(*this, name);
}
catch (const f3d::options::unset_exception&)
{
ownUnset = true;
}

try
{
otherVal = options_tools::get(other, name);
}
catch (const f3d::options::unset_exception&)
{
otherUnset = true;
}

return ownUnset == otherUnset && ownVal == otherVal;
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -141,4 +164,10 @@ options::inexistent_exception::inexistent_exception(const std::string& what)
: exception(what)
{
}

//----------------------------------------------------------------------------
options::unset_exception::unset_exception(const std::string& what)
: exception(what)
{
}
}
2 changes: 1 addition & 1 deletion vtkext/private/module/vtkF3DRendererWithColoring.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void vtkF3DRendererWithColoring::ConfigureColoringActorsProperties()
//----------------------------------------------------------------------------
void vtkF3DRendererWithColoring::SetPointSpritesProperties(SplatType type, double pointSpritesSize)
{
// this->SetPointSize(pointSize); TODO
// this->SetPointSize(pointSpritesSize); TODO

if (!this->Importer)
{
Expand Down

0 comments on commit 7cf94b0

Please sign in to comment.