-
-
Notifications
You must be signed in to change notification settings - Fork 360
Add support for temporal mesh in vtkF3DMemoryMesh and scene API #2561
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
Open
0xfedcafe
wants to merge
4
commits into
f3d-app:master
Choose a base branch
from
0xfedcafe:temporal-mesh-memory
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,6 +296,35 @@ scene& scene_impl::add(const std::vector<fs::path>& filePaths) | |
| } | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| scene& scene_impl::add(const double startTime, const double endTime, MeshCallback&& callback) | ||
| { | ||
| if (startTime > endTime) | ||
| { | ||
| throw scene::load_failure_exception("startTime must be less than or equal to endTime"); | ||
| } | ||
|
|
||
| vtkNew<vtkF3DMemoryMesh> vtkSource; | ||
|
|
||
| auto wrappedCallback = [cb = std::move(callback)](double time, vtkF3DMemoryMesh* vtkMesh) | ||
| { | ||
| mesh_t mesh = cb(time); | ||
| vtkMesh->SetPoints(mesh.points); | ||
| vtkMesh->SetNormals(mesh.normals); | ||
| vtkMesh->SetTCoords(mesh.texture_coordinates); | ||
| vtkMesh->SetFaces(mesh.face_sides, mesh.face_indices); | ||
| }; | ||
|
|
||
| vtkSource->SetAnimatedMesh(startTime, endTime, std::move(wrappedCallback)); | ||
|
|
||
| auto importer = vtkSmartPointer<vtkF3DGenericImporter>::New(); | ||
| importer->SetInternalReader(vtkSource); | ||
|
|
||
| log::debug("Loading animated 3D scene from memory"); | ||
|
|
||
| this->Internals->Load({ importer }); | ||
| return *this; | ||
| } | ||
|
|
||
| scene& scene_impl::add(const mesh_t& mesh) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should be able to call the other method here ? |
||
| { | ||
| // sanity checks | ||
|
|
@@ -306,16 +335,18 @@ scene& scene_impl::add(const mesh_t& mesh) | |
| } | ||
|
|
||
| vtkNew<vtkF3DMemoryMesh> vtkSource; | ||
| auto importer = vtkSmartPointer<vtkF3DGenericImporter>::New(); | ||
|
|
||
| log::debug("Loading 3D scene from memory"); | ||
|
|
||
| vtkSource->SetPoints(mesh.points); | ||
| vtkSource->SetNormals(mesh.normals); | ||
| vtkSource->SetTCoords(mesh.texture_coordinates); | ||
| vtkSource->SetFaces(mesh.face_sides, mesh.face_indices); | ||
|
|
||
| vtkSmartPointer<vtkF3DGenericImporter> importer = vtkSmartPointer<vtkF3DGenericImporter>::New(); | ||
| importer->SetInternalReader(vtkSource); | ||
| Internals->Load({ importer }); | ||
|
|
||
| log::debug("Loading 3D scene from memory"); | ||
| this->Internals->Load({ importer }); | ||
| return *this; | ||
| } | ||
|
|
||
|
|
@@ -327,7 +358,6 @@ scene& scene_impl::clear() | |
|
|
||
| // Clear the window of all actors | ||
| this->Internals->Window.Initialize(); | ||
|
|
||
| return *this; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #include "PseudoUnitTest.h" | ||
|
|
||
| #include <engine.h> | ||
| #include <image.h> | ||
| #include <log.h> | ||
| #include <scene.h> | ||
| #include <window.h> | ||
|
|
||
| #include <cmath> | ||
| #include <sstream> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| int TestSDKSceneTemporalFromMemory([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) | ||
| { | ||
| PseudoUnitTest test; | ||
|
|
||
| f3d::log::setVerboseLevel(f3d::log::VerboseLevel::DEBUG); | ||
| f3d::engine eng = f3d::engine::create(true); | ||
| f3d::scene& sce = eng.getScene(); | ||
| f3d::window& win = eng.getWindow().setSize(300, 300); | ||
|
|
||
| // Define mesh data for two frames | ||
| const std::vector<float> basePoints{ 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 0.f }; | ||
| const std::vector<float> translatedPoints{ 0.25f, 0.f, 0.f, 0.25f, 1.f, 0.f, 1.25f, 0.f, 0.f, | ||
| 1.25f, 1.f, 0.f }; | ||
| const std::vector<float> normals{ 0.f, 0.f, -1.f, 0.f, 0.f, -1.f, 0.f, 0.f, -1.f, 0.f, 0.f, | ||
| -1.f }; | ||
| const std::vector<float> tcoords{ 0.f, 0.f, 0.f, 1.f, 1.f, 0.f, 1.f, 1.f }; | ||
| const std::vector<unsigned int> faceSides{ 3, 3 }; | ||
| const std::vector<unsigned int> faceIndices{ 0, 1, 2, 1, 3, 2 }; | ||
|
|
||
| auto meshCallback = [&](double time) -> f3d::mesh_t | ||
| { | ||
| if (time < 0.5) | ||
| { | ||
| return f3d::mesh_t{ basePoints, normals, tcoords, faceSides, faceIndices }; | ||
| } | ||
| else | ||
| { | ||
| return f3d::mesh_t{ translatedPoints, normals, tcoords, faceSides, faceIndices }; | ||
| } | ||
| }; | ||
|
|
||
| test("add animated mesh with callback", [&]() { sce.add(0.0, 1.0, meshCallback); }); | ||
|
|
||
| test("animation time range", [&]() { | ||
| auto range = sce.animationTimeRange(); | ||
| return std::abs(range.first - 0.0) < 1e-6 && std::abs(range.second - 1.0) < 1e-6; | ||
| }); | ||
|
|
||
| test("quantitative temporal difference", [&]() { | ||
| sce.loadAnimationTime(0.0); | ||
| f3d::image frame0 = win.renderToImage(); | ||
| sce.loadAnimationTime(1.0); | ||
| f3d::image frame1 = win.renderToImage(); | ||
| double error = frame0.compare(frame1); | ||
| return error > 0.01; | ||
| }); | ||
|
|
||
| return test.result(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,38 @@ | ||
| /** | ||
| * @class vtkF3DMemoryMesh | ||
| * @brief create vtkPolyData from vectors. | ||
| * @brief create vtkPolyData from vectors or a callback. | ||
| * | ||
| * Simple source which convert and copy vectors provided by the user | ||
| * to internal structure of vtkPolyData. | ||
| * Does not support point data (normals, tcoords...) nor cell data yet. | ||
| * Simple source which converts vectors provided by the user | ||
| * to internal structure of vtkPolyData, or uses a callback for animated mesh generation. | ||
| */ | ||
| #ifndef vtkF3DMemoryMesh_h | ||
| #define vtkF3DMemoryMesh_h | ||
|
|
||
| #include "vtkPolyDataAlgorithm.h" | ||
|
|
||
| #include <functional> | ||
|
|
||
| class vtkF3DMemoryMesh : public vtkPolyDataAlgorithm | ||
| { | ||
| public: | ||
| static vtkF3DMemoryMesh* New(); | ||
| vtkTypeMacro(vtkF3DMemoryMesh, vtkPolyDataAlgorithm); | ||
|
|
||
| /** | ||
| * Set contiguous list of positions. | ||
| * Callback type for animated meshes. | ||
| * Called with the current time value, should populate the mesh using the Set* methods. | ||
| */ | ||
| using MeshCallback = std::function<void(double time, vtkF3DMemoryMesh* mesh)>; | ||
|
|
||
| /** | ||
| * Set contiguous list of positions for a static mesh. | ||
| * Length of the list must be a multiple of 3. | ||
| * The list is copied internally. | ||
| */ | ||
| void SetPoints(const std::vector<float>& positions); | ||
|
|
||
| /** | ||
| * Set contiguous list of normals. | ||
| * Set contiguous list of normals for a static mesh. | ||
| * Length of the list must be a multiple of 3 (or left empty). | ||
| * Must match the number of points specified in SetPoints. | ||
| * The list is copied internally. | ||
|
|
@@ -34,7 +41,7 @@ class vtkF3DMemoryMesh : public vtkPolyDataAlgorithm | |
| void SetNormals(const std::vector<float>& normals); | ||
|
|
||
| /** | ||
| * Set contiguous list of texture coordinates. | ||
| * Set contiguous list of texture coordinates for a static mesh. | ||
| * Length of the list must be a multiple of 2 (or left empty). | ||
| * Must match the number of points specified in SetPoints. | ||
| * The list is copied internally. | ||
|
|
@@ -43,7 +50,7 @@ class vtkF3DMemoryMesh : public vtkPolyDataAlgorithm | |
| void SetTCoords(const std::vector<float>& tcoords); | ||
|
|
||
| /** | ||
| * Set faces by vertex indices. | ||
| * Set faces by vertex indices for a static mesh. | ||
| * faceSizes contains the size of each face (3 is triangle, 4 is quad, etc...) | ||
| * cellIndices is a contiguous array of all face indices | ||
| * The length of faceIndices should be the sum of all values in faceSizes | ||
|
|
@@ -53,17 +60,30 @@ class vtkF3DMemoryMesh : public vtkPolyDataAlgorithm | |
| void SetFaces( | ||
| const std::vector<unsigned int>& faceSizes, const std::vector<unsigned int>& faceIndices); | ||
|
|
||
| /** | ||
| * Set a callback for animated mesh generation. | ||
| * The callback is invoked at each requested time and should populate the mesh | ||
| * using SetPoints, SetNormals, SetTCoords, and SetFaces methods. | ||
| * This switches the mesh to animated mode with the given time range. | ||
| */ | ||
| void SetAnimatedMesh(double startTime, double endTime, MeshCallback callback); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use std::vector here too |
||
|
|
||
| protected: | ||
| vtkF3DMemoryMesh(); | ||
| ~vtkF3DMemoryMesh() override; | ||
|
|
||
| int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; | ||
| int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; | ||
|
|
||
| private: | ||
| vtkF3DMemoryMesh(const vtkF3DMemoryMesh&) = delete; | ||
| void operator=(const vtkF3DMemoryMesh&) = delete; | ||
|
|
||
| vtkNew<vtkPolyData> Mesh; | ||
| vtkNew<vtkPolyData> StaticMesh; | ||
|
|
||
| MeshCallback AnimatedCallback; | ||
| double TimeRange[2] = { 0.0, 0.0 }; | ||
| bool IsAnimated = false; | ||
| }; | ||
|
|
||
| #endif | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think of this name @Meakk ?