Skip to content

Commit

Permalink
Rename loader into scene (#1660)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal authored Oct 8, 2024
1 parent 1eeaf2c commit 33771c5
Show file tree
Hide file tree
Showing 72 changed files with 333 additions and 343 deletions.
10 changes: 5 additions & 5 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ void F3DStarter::LoadFileGroup(
dynamicOptionsDict, fs::path(), "dynamic options");

// Recover file information
f3d::loader& loader = this->Internals->Engine->getLoader();
f3d::scene& scene = this->Internals->Engine->getScene();
bool unsupported = false;

std::vector<fs::path> localPaths;
Expand All @@ -1088,7 +1088,7 @@ void F3DStarter::LoadFileGroup(

if (clear)
{
loader.clear();
scene.clear();
this->Internals->LoadedFiles.clear();
}

Expand Down Expand Up @@ -1117,7 +1117,7 @@ void F3DStarter::LoadFileGroup(
if (std::find(this->Internals->LoadedFiles.begin(), this->Internals->LoadedFiles.end(),
tmpPath) == this->Internals->LoadedFiles.end())
{
if (loader.supports(tmpPath))
if (scene.supports(tmpPath))
{
// Check the size of the file before loading it
static constexpr int BYTES_IN_MIB = 1048576;
Expand All @@ -1143,15 +1143,15 @@ void F3DStarter::LoadFileGroup(
if (!localPaths.empty())
{
// Add files to the scene
loader.add(localPaths);
scene.add(localPaths);

// Update loaded files
std::copy(
localPaths.begin(), localPaths.end(), std::back_inserter(this->Internals->LoadedFiles));
}
}
}
catch (const f3d::loader::load_failure_exception& ex)
catch (const f3d::scene::load_failure_exception& ex)
{
f3d::log::error("Some of these files could not be loaded: ", ex.what());
for (const fs::path& tmpPath : localPaths)
Expand Down
5 changes: 2 additions & 3 deletions application/F3DStarter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
#ifndef F3DStarter_h
#define F3DStarter_h

#include "loader.h"

#include <filesystem>
#include <memory>
#include <vector>

class F3DStarter
{
public:
/**
* Parse the options and configure a f3d::loader accordingly
* Parse the options and configure a f3d::scene accordingly
*/
int Start(int argc, char** argv);

Expand Down
6 changes: 3 additions & 3 deletions doc/libf3d/BINDINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ eng.options.update({
"render.grid.enable": True,
})

eng.loader.add("f3d/testing/data/dragon.vtu")
eng.scene.add("f3d/testing/data/dragon.vtu")
eng.interactor.start()
```

Expand All @@ -40,8 +40,8 @@ public class F3DExample {

// Always use try-with-resources idiom to ensure the native engine is released
try (Engine engine = new Engine(Window.Type.NATIVE)) {
Loader loader = engine.getLoader();
loader.add("f3d/testing/data/dragon.vtu");
Scene scene = engine.getScene();
scene.add("f3d/testing/data/dragon.vtu");

engine.getWindow().render();
}
Expand Down
8 changes: 4 additions & 4 deletions doc/libf3d/CLASSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ For the complete documentation, please consult the [libf3d doxygen documentation

## Engine class

The engine class is the main class that needs to be instantiated. All other classes instance are provided by the engine using getters, `getLoader`, `getWindow`, `getInteractor`, `getOptions`.
The engine class is the main class that needs to be instantiated. All other classes instance are provided by the engine using getters, `getScene`, `getWindow`, `getInteractor`, `getOptions`.

The engine constructor lets you choose the type of window in its constructor, `NONE`, `NATIVE`, `NATIVE_OFFSCREEN`, `EXTERNAL`. Default is `NATIVE`. See [Window class](#window-class) documentation for more info. Please note that the engine will not provide a interactor with `NONE` and `EXTERNAL`.

A static function `loadPlugin` can also be called to load reader plugins. It must be called before loading any file. An internal plugin containing VTK native readers can be loaded by calling `f3d::engine::loadPlugin("native");`. Other plugins maintained by F3D team are available if their build is enabled: `alembic`, `assimp`, `draco`, `exodus`, `occt` and `usd`.
If CMake option `F3D_PLUGINS_STATIC_BUILD` is enabled, the plugins listed above are also static just like `native` plugin.
All static plugins can be loaded using `f3d::engine::autoloadPlugins()`.

## Loader class
## Scene class

The loader class is responsible to `add` file from the disk into the scene. It supports reading multiple files at the same time and even mesh from memory.
It is possible to `clear` the scene and to check if a file is `supported`.
The scene class is responsible to `add` file from the disk into the scene. It supports reading multiple files at the same time and even mesh from memory.
It is possible to `clear` the scene and to check if the scene `supports` a file.

## Window class

Expand Down
20 changes: 10 additions & 10 deletions doc/libf3d/OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Rendering a file and starting the interaction is very easy:
```cpp
#include <f3d/engine.h>
#include <f3d/interactor.h>
#include <f3d/loader.h>
#include <f3d/scene.h>

// Load VTK native readers
f3d::engine::autoloadPlugins();
Expand All @@ -22,7 +22,7 @@ f3d::engine::autoloadPlugins();
f3d::engine eng();

// Add a file into a scene
eng.getLoader().add("path/to/file.ext");
eng.getScene().add("path/to/file.ext");

// Start rendering and interacting
eng.getInteractor().start();
Expand All @@ -33,7 +33,7 @@ As well as loading multiple files:
```cpp
#include <f3d/engine.h>
#include <f3d/interactor.h>
#include <f3d/loader.h>
#include <f3d/scene.h>

// Load VTK native readers
f3d::engine::autoloadPlugins();
Expand All @@ -42,7 +42,7 @@ f3d::engine::autoloadPlugins();
f3d::engine eng();

// Load multiples geometries
eng.getLoader().add({"path/to/file.ext", "path/to/file2.ext"});
eng.getScene().add({"path/to/file.ext", "path/to/file2.ext"});

// Start rendering and interacting
eng.getInteractor().start();
Expand All @@ -53,7 +53,7 @@ It's also possible to load a geometry from memory buffers:
```cpp
#include <f3d/engine.h>
#include <f3d/interactor.h>
#include <f3d/loader.h>
#include <f3d/scene.h>
// Create a f3d::engine
f3d::engine eng();
Expand All @@ -63,7 +63,7 @@ f3d::mesh_t mesh = {};
mesh.points = { 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 1.f, 0.f, 0.f };
mesh.face_sides = { 3 };
mesh.face_indices = { 0, 1, 2 };
eng.getLoader().add(mesh);
eng.getScene().add(mesh);
// Start rendering and interacting
eng.getInteractor().start();
Expand All @@ -74,7 +74,7 @@ Manipulating the window directly can be done this way:
```cpp
#include <f3d/engine.h>
#include <f3d/image.h>
#include <f3d/loader.h>
#include <f3d/scene.h>
#include <f3d/window.h>

// Load VTK native readers
Expand All @@ -84,7 +84,7 @@ f3d::engine::autoloadPlugins();
f3d::engine eng(f3d::window::Type::NATIVE_OFFSCREEN);

// Load a geometry
eng.getLoader().add("path/to/file.ext");
eng.getScene().add("path/to/file.ext");

// Set the window size and render to an image
f3d::image img = eng.getWindow().setSize(300, 300).renderToImage();
Expand All @@ -99,7 +99,7 @@ Changing some options can be done this way:
#include <f3d/engine.h>
#include <f3d/interactor.h>
#include <f3d/options.h>
#include <f3d/loader.h>
#include <f3d/scene.h>
// Load VTK native readers
f3d::engine::autoloadPlugins();
Expand All @@ -113,7 +113,7 @@ opt.render.effect.ambient_occlusion = true;
opt.render.effect.anti_aliasing = true;
// Standard libf3d usage
eng.getLoader().add("path/to/file.ext");
eng.getScene().add("path/to/file.ext");
eng.getInteractor().start();
```
Most options are dynamic, some are only taken into account when loading a file. See the [options](OPTIONS.md) documentation.
Expand Down
2 changes: 1 addition & 1 deletion examples/libf3d/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(BUILD_TESTING)
endif()

add_subdirectory(check-engine)
add_subdirectory(multi-geom)
add_subdirectory(multi-files)
add_subdirectory(render-image)
add_subdirectory(render-interact)
add_subdirectory(use-options-string)
Expand Down
2 changes: 1 addition & 1 deletion examples/libf3d/cpp/check-engine/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <f3d/export.h>
#include <f3d/image.h>
#include <f3d/interactor.h>
#include <f3d/loader.h>
#include <f3d/log.h>
#include <f3d/options.h>
#include <f3d/scene.h>
#include <f3d/types.h>
#include <f3d/window.h>

Expand Down
21 changes: 21 additions & 0 deletions examples/libf3d/cpp/multi-files/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.5)

project(multi-files)

find_package(f3d REQUIRED COMPONENTS library)

add_executable(multi-files main.cxx)
target_link_libraries(multi-files f3d::libf3d)
set_target_properties(multi-files PROPERTIES CXX_STANDARD 17)

if(UNIX AND NOT APPLE)
target_link_libraries(multi-files stdc++fs)
endif()

# Simple testing
if(BUILD_TESTING)
enable_testing()
add_test(NAME test_multi-files COMMAND "$<TARGET_FILE:multi-files>" "${CMAKE_CURRENT_SOURCE_DIR}/data/")
set_tests_properties(test_multi-files PROPERTIES
PASS_REGULAR_EXPRESSION "Scene bounding box: -0.487464,1,-0.487464,1,-0.5,1")
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ int main(int argc, char** argv)
// Create a native window engine
f3d::engine eng(f3d::window::Type::NATIVE);

// Load all files from provided directory as geometries
f3d::loader& load = eng.getLoader();
// Add all files from provided directory
f3d::scene& sce = eng.getScene();
for (auto& entry : std::filesystem::directory_iterator(argv[1]))
{
load.add(entry.path().string());
sce.add(entry.path().string());
}

// Render
Expand Down
21 changes: 0 additions & 21 deletions examples/libf3d/cpp/multi-geom/CMakeLists.txt

This file was deleted.

4 changes: 2 additions & 2 deletions examples/libf3d/cpp/render-image/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ int main(int argc, char** argv)
// Create a offscreen window engine
f3d::engine eng(f3d::window::Type::NATIVE_OFFSCREEN);

// Load a model
eng.getLoader().add(std::string(argv[1]));
// add a model
eng.getScene().add(std::string(argv[1]));

// Set the window size and render to an image
f3d::image img = eng.getWindow().setSize(300, 300).renderToImage();
Expand Down
4 changes: 2 additions & 2 deletions examples/libf3d/cpp/render-interact/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ int main(int argc, char** argv)
// Create a native window engine
f3d::engine eng(f3d::window::Type::NATIVE);

// Load a model
const f3d::loader& load = eng.getLoader().add(std::string(argv[1]));
// add a model
eng.getScene().add(std::string(argv[1]));

// Render
f3d::window& win = eng.getWindow();
Expand Down
4 changes: 2 additions & 2 deletions examples/libf3d/cpp/use-options-string/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ int main(int argc, char** argv)
.setAsString("render.line_width", "10")
.setAsString("render.grid.enable", "1");

// Load a model
const f3d::loader& load = eng.getLoader().add(std::string(argv[1]));
// add a model
const f3d::scene& sce = eng.getScene().add(std::string(argv[1]));

// Render
f3d::window& win = eng.getWindow();
Expand Down
4 changes: 2 additions & 2 deletions examples/libf3d/cpp/use-options-struct/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ int main(int argc, char** argv)
opt.render.line_width = 10;
opt.render.grid.enable = true;

// Load a model
const f3d::loader& load = eng.getLoader().add(std::string(argv[1]));
// Add a model
eng.getScene().add(std::string(argv[1]));

// Render
f3d::window& win = eng.getWindow();
Expand Down
4 changes: 2 additions & 2 deletions examples/libf3d/cpp/use-options-variant/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ int main(int argc, char** argv)
f3d::options& opt = eng.getOptions();
opt.set("render.show_edges", true).set("render.line_width", 10.0).set("render.grid.enable", true);

// Load a model
const f3d::loader& load = eng.getLoader().add(std::string(argv[1]));
// ad a model
const f3d::scene& sce = eng.getScene().add(std::string(argv[1]));

// Render
f3d::window& win = eng.getWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
files = [f for f in Path(sys.argv[1]).iterdir() if f.is_file()]
for file in files:
try:
eng.loader.load_geometry(str(file))
eng.scene.add(str(file))
except RuntimeError as e:
print(e)

Expand Down
2 changes: 1 addition & 1 deletion examples/libf3d/python/render-image/render_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
f3d.Engine.autoload_plugins()

eng = f3d.Engine(f3d.Window.NATIVE_OFFSCREEN)
eng.loader.load_geometry(sys.argv[1])
eng.scene.add(sys.argv[1])

eng.window.size = 300, 300
img = eng.window.render_to_image()
Expand Down
4 changes: 2 additions & 2 deletions examples/libf3d/python/render-interact/render_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# Create a native window engine
eng = f3d.Engine(f3d.Window.NATIVE)

# Load a model
# Add a model
try:
eng.loader.load_geometry(sys.argv[1])
eng.scene.add(sys.argv[1])
except RuntimeError as e:
print(e)

Expand Down
2 changes: 1 addition & 1 deletion examples/libf3d/python/render-terminal/render_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main():
# setup engine
engine = f3d.Engine(f3d.Window.NATIVE_OFFSCREEN)
engine.options.update(options)
engine.loader.load_geometry(str(model_path))
engine.scene.add(str(model_path))
engine.window.size = rows, cols * 2

# fit view to loaded model and grab computed camera position
Expand Down
2 changes: 1 addition & 1 deletion examples/libf3d/python/tkinter/minimal_tkinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self):
# Initialize F3D
def initgl(self):
self.engine = f3d.Engine(f3d.Window.Type.EXTERNAL)
self.engine.loader.load_geometry(
self.engine.scene.add(
f3d.Mesh(
points=[0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0],
face_sides=[3],
Expand Down
2 changes: 1 addition & 1 deletion java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ endif()
set(F3D_JAVA_SOURCES
Camera.java
Engine.java
Loader.java
Options.java
Scene.java
Window.java)

# Generate JNI headers, and builds a JAR package
Expand Down
Loading

0 comments on commit 33771c5

Please sign in to comment.