-
Notifications
You must be signed in to change notification settings - Fork 14
Adding example #227
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
magnoxemo
wants to merge
14
commits into
xdg-org:main
Choose a base branch
from
magnoxemo:examples
base: main
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
Adding example #227
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
958fef3
setting build files
magnoxemo b98aa8d
using compiler directive to determinte which mesh manager to use to a…
magnoxemo d092b43
fix cmake build file to allow CI to compile this example
magnoxemo 44a254a
fix CMake
magnoxemo 8b19cfb
fixing CMake (hope fully) and adding the whole example
magnoxemo 16eef4b
don't add example subdir before moab is found
magnoxemo 25fc114
Update examples/ray_segments.cpp
magnoxemo 77a991f
adding argument parser and set up CLI args to determine which mesh+RT…
magnoxemo 029ac44
making it a volume estimation example
magnoxemo 08d3d61
remove mesh_managers include
magnoxemo 767724e
fix fmt link error
magnoxemo 4a9cb01
Merge branch 'xdg-org:main' into examples
magnoxemo cdbecf3
Merge branch 'xdg-org:main' into examples
magnoxemo 394dee0
Merge branch 'xdg-org:main' into examples
magnoxemo 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # ============================================================================= | ||
| # Examples for how to use XDG C++ APIs | ||
| # ============================================================================= | ||
|
|
||
| add_executable(element_volume_estimation element_volume_estimation.cpp) | ||
| target_link_libraries(element_volume_estimation PRIVATE xdg) | ||
|
|
||
|
|
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,52 @@ | ||
| #include <iostream> | ||
| #include <iomanip> | ||
| #include <random> | ||
|
|
||
| #include "xdg/xdg.h" | ||
|
|
||
| int main(int argc, char* argv[]) | ||
| { | ||
| if (argc < 2) { | ||
| std::cerr << "Usage: " << argv[0] << " <mesh_file>\n"; | ||
| return 1; | ||
| } | ||
| const std::string mesh_file = argv[1]; | ||
|
|
||
| std::shared_ptr<xdg::XDG> xdg = xdg::XDG::create(); | ||
| const auto& mesh_manager = xdg->mesh_manager(); | ||
| mesh_manager->load_file(mesh_file); | ||
| mesh_manager->init(); | ||
| xdg->prepare_raytracer(); | ||
|
pshriwise marked this conversation as resolved.
|
||
|
|
||
| xdg::BoundingBox bbox = mesh_manager->global_bounding_box(); | ||
| double bbox_volume = (bbox.max_x - bbox.min_x) | ||
| * (bbox.max_y - bbox.min_y) | ||
| * (bbox.max_z - bbox.min_z); | ||
|
|
||
| std::mt19937 gen(42); | ||
| std::uniform_real_distribution<double> x_dist(bbox.min_x, bbox.max_x); | ||
| std::uniform_real_distribution<double> y_dist(bbox.min_y, bbox.max_y); | ||
| std::uniform_real_distribution<double> z_dist(bbox.min_z, bbox.max_z); | ||
|
|
||
| constexpr size_t n_samples = 100000; | ||
|
|
||
| std::cout << std::setw(10) << "Volume ID" | ||
| << std::setw(20) << "MC Volume Estimate" | ||
| << std::setw(20) << "Hits / Samples\n"; | ||
| std::cout << std::string(50, '-') << "\n"; | ||
|
|
||
| for (xdg::MeshID volume : mesh_manager->volumes()) { | ||
| size_t hits = 0; | ||
| for (size_t i = 0; i < n_samples; ++i) { | ||
| xdg::Position sample = {x_dist(gen), y_dist(gen), z_dist(gen)}; | ||
| if (xdg->point_in_volume(volume, sample)) | ||
| hits++; | ||
| } | ||
| const double mc_volume = bbox_volume * static_cast<double>(hits) / n_samples; | ||
| std::cout << std::setw(10) << volume | ||
| << std::setw(20) << std::fixed << std::setprecision(4) << mc_volume | ||
| << std::setw(14) << hits << " / " << n_samples << "\n"; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
Oops, something went wrong.
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.
Can you remind me why this is necessary again?
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.
The issue was that
fmtwas linked privately toxdg. As a result, when a library or executable linked againstxdg, thefmtdependency was not propagated to it. That caused the linker error we were seeing at that time.