Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brainstorm libf3d API #52

Closed
32 tasks done
mwestphal opened this issue Nov 12, 2021 · 23 comments
Closed
32 tasks done

Brainstorm libf3d API #52

mwestphal opened this issue Nov 12, 2021 · 23 comments
Labels
type:enhancement New feature or request
Milestone

Comments

@mwestphal
Copy link
Contributor

mwestphal commented Nov 12, 2021

libf3d was introduced in !259 (closed), let's brainstorm a stable API for it.

Tasklist:

libf3d

  • Introduce f3d::options: Introducing f3d::options #191
  • Refactor F3DLoader and F3D to use f3d::options cleanly
  • Introduce f3d::loader and use it
  • Introduce f3d::window and use it
  • modularize VTK code
  • Add unit test for VTK modules : Add unit test for VTK modules #265
  • sanity check call order with window and interactor
  • transform F3DLog into f3d::log
  • fix Plan the expansion of the options #32 by using categories for options
  • improve f3d_options by providing initialization methods
  • store init value in f3d::options for easier reset ?
  • support std::initializer_list to be able to call options.set("color", { 1., 1., 1. });
  • add a way to inform user when an options does not exist
  • introduce a factory and use it to create classes to hide the private API
  • Add SDK test infrastructure
  • Adress as many TODOs as possible
  • Rework engine for bit flag and init early
  • Add SDK tests
  • (optional) expand f3d_interactor to support user set behavior for many more context
  • add more window types
  • improve all classes from f3d namespaces to ensure all santiy checks are done correctly
  • unit testing of the API and general coverage improvements
  • Add a vtkNoRenderWindow
  • modernization of API
  • constness of API
  • Public Review of the API to anyone willing to help: libf3d API Public Review #351

F3D

  • Rework F3DOptions and F3DOptionsParser to interface with f3d::options
  • (Optional) introduce f3d::config in libf3d ?
  • rewrite F3DStarter from scratch to not depends on VTK

Doc

  • In header doc
  • example doc
  • website doc
@mwestphal
Copy link
Contributor Author

Ignoring completelly how libf3d and f3d are currently implemented, let's consider the fonctionnality we want to provide as a lib.

Features:

  • Set a list of options
  • Read a file
  • Display resuting scene using file and options in a OpenGL context, potentially provided by user

Restrictions:

  • User must not need to find_package VTK to use libf3d or use any vtk* class
  • User does not need to know much about rendering to use libf3d

inputs @Meakk ?

@Meakk
Copy link
Member

Meakk commented Dec 18, 2021

I agree, VTK should be a private dependency of libf3d.
Ideally, f3d executable should only provide the command-line parsing, and config file management.

@mwestphal
Copy link
Contributor Author

So trying to link it with current implementation, we could have the following rough public API

F3DOptions
  SetFoo
  SetBar

F3DFileLoader(F3DOptions)
  AddFile

F3DViewer(F3DOptions, F3DFileLoader)
  Show

@Meakk
Copy link
Member

Meakk commented Dec 21, 2021

Here are my inputs.
libf3d usage should allow the user to call something like that:

f3d::window w = f3d::createWindow(f3d::context ctx); // create window (external, native, android ...)
w.addFile("/path/file.vtp"); // add a file
w.addFolder("/path"); // add all the files in folder
w.setActiveFile(int index); // set the active file
w.setOption("key", "value"); // configure all options using this function (parse the value string inside the function)
w.clear(); // remove all files
w.render(); // render the scene
w.saveTofile("/path/image.png"); // save the rendered image
w.setKeyCallBack([](int keyCode, int modifier) {
  // do something
  });
w.setMouseCallBack([](float dx, float dy, int button) {
  // do something
  });
w.setMotionCallBack([](float whatever) {
  // do something on Android
  });

It also means that the interactor should be moved to the executable, but it makes sense to me.
The API is clear, simple, and it's easy to remove/add options without breaking the compilation on the user side. Maybe providing an equivalent API in C would be useful too.
The list I provided is most likely incomplete.

@mwestphal mwestphal mentioned this issue Dec 25, 2021
10 tasks
@mwestphal
Copy link
Contributor Author

mwestphal commented Dec 25, 2021

I think it would be better to separate loading data and rendering data. here is a proposition:

f3d::options opt;
opt.setOption("key", "value"); // configure all options using this function (parse the value string inside the function)

f3d::loader load;
load.setOptions(opt);
load.addFile("/path/file.vtp"); // add a file
load.addFolder("/path"); // add all the files in folder
load.setActiveFile(int index); // set the active file

f3d::interactor interact
interact.setKeyCallBack([](int keyCode, int modifier) {
  // do something
  });
interact.setMouseCallBack([](float dx, float dy, int button) {
  // do something
  });
interact.setMotionCallBack([](float whatever) {
  // do something on Android
  });

f3d::window win (f3d::context ctx); // create window (external, native, android ...)
win.setOptions(opt)
win.setLoader(load);
win.setInteractor(interact);
win.render(); // render the scene
win.saveTofile("/path/image.png"); // save the rendered image

I dont really care about C bindings, python bindings would be much more important imo.

@Meakk
Copy link
Member

Meakk commented Dec 29, 2021

@mwestphal I like it! Regarding bindings, we will need Java bindings too for Android. I will take care of it, don't worry 😛

@mwestphal
Copy link
Contributor Author

Great ! Lets focus on this one when we find the time. We may want to merge into a dedicated branch until it stabilize.

@Meakk
Copy link
Member

Meakk commented Dec 31, 2021

I still think providing C functions can be useful, for C programmers of course, but it will make other bindings easier, like Rust for instance: https://stackoverflow.com/questions/52923460/how-to-call-a-c-dynamic-library-from-rust

@mwestphal
Copy link
Contributor Author

Interesting.

mwestphal added a commit that referenced this issue Jan 13, 2022
In the context of #52 , Introduce a first element, f3d::options and start using it when possible without refactoring the whole of F3D for now.

TODO in other PRs:
- doc
- F3DLoader refacto
- options names #32
@SamuelTallet
Copy link

Hi, I'm also interested by C functions 😃 Given I write my SketchUp plugins in Ruby, I could use Fiddle to call libf3d from Ruby.
Ruby Fiddle Test
To ease language interoperability and type mapping, I suggest to use JSON as string when value passed or returned is structured.

@mwestphal
Copy link
Contributor Author

Haha, nice screenshot 👍

mwestphal added a commit to mwestphal/f3d that referenced this issue Jan 17, 2022
- Separate F3DLoader in F3DLoader and F3DStarter for f3d-app#52
- Remove all mention of F3DOptions from F3DLoader
- Make --no-render F3DStarter specifc and not an actual option
- Separate F3DLoader::loadFile in multiple methods
- Improve testing for right/left key
@mwestphal
Copy link
Contributor Author

mwestphal commented Jan 20, 2022

Discussed API moving forward

f3d::options opt;
opt.setOption("key", "value"); // configure all options using this function (parse the value string inside the function)

f3d::window win (f3d::context ctx); // create window (external, native, android ...)

f3d::loader load;
load.setOptions(opt);
load.setWindow(win);
load.addFile("/path/file.vtp"); // add a file
load.addFolder("/path"); // add all the files in folder
load.setActiveFile(int index); // set the active file

f3d::interactor interact
interact.setMouseCallBack([](float dx, float dy, int button) {
  // do something
  });
interact.setMotionCallBack([](float whatever) {
  // do something on Android
  });

win.setInteractor(interact);
win.render(); // render the scene
win.saveTofile("/path/image.png"); // save the rendered image

interact.loop();

@SamuelTallet
Copy link

SamuelTallet commented Jan 21, 2022

@mwestphal Once model is loaded and rendered, could we access renderer then change things in real time? For instance:

win.render(); // render the scene
ren = win.getRenderer();
cam = ren.getActiveCamera();
cam.setPosition(float x, float y, float z);

@mwestphal
Copy link
Contributor Author

Yes, any options will be changeable dynamically when all is implemented.

@mwestphal
Copy link
Contributor Author

So a very early version of the API is now in master, I'll try to update the issue to identify the remaining work.

@mwestphal
Copy link
Contributor Author

@Meakk updated with your suggestions

@mwestphal
Copy link
Contributor Author

mwestphal commented Mar 25, 2022

Here is how it looks now:

  f3d::engine eng(f3d::engine::WindowTypeEnum::WINDOW_STANDARD);
  f3d::loader& load = eng.getLoader();
  load.addFile(filepath);
  load.loadFile(f3d::loader::LoadFileEnum::LOAD_CURRENT);
  f3d::window& win = eng.getWindow();
  f3d::interactor& inter = eng.getInteractor();
  inter.start();

@mwestphal
Copy link
Contributor Author

For anyone following this. We are close to completion of the first version of the API. stay tuned.

@mwestphal
Copy link
Contributor Author

store init value in f3d::options for easier reset ?

not needed

@mwestphal
Copy link
Contributor Author

(Optional) introduce f3d::config in libf3d ?

not needed

@mwestphal
Copy link
Contributor Author

(optional) expand f3d_interactor to support user set behavior for many more context

Not needed, for now

@mwestphal mwestphal added this to the 1.3.0 milestone Aug 14, 2022
@mwestphal
Copy link
Contributor Author

Doc item in their own issue: #48

@mwestphal
Copy link
Contributor Author

All items have been adressed, closing.

mwestphalnew pushed a commit to mwestphalnew/f3d that referenced this issue Feb 10, 2024
In the context of f3d-app#52 , Introduce a first element, f3d::options and start using it when possible without refactoring the whole of F3D for now.

TODO in other PRs:
- doc
- F3DLoader refacto
- options names f3d-app#32
mwestphalnew pushed a commit to mwestphalnew/f3d that referenced this issue Feb 10, 2024
- Separate F3DLoader in F3DLoader and F3DStarter for f3d-app#52
- Remove all mention of F3DOptions from F3DLoader
- Make --no-render F3DStarter specifc and not an actual option
- Separate F3DLoader::loadFile in multiple methods
- Improve testing for right/left key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants