-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from pshriwise/tools-n-args
More tools w/ arguments
- Loading branch information
Showing
9 changed files
with
284 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,4 +1,15 @@ | ||
|
||
|
||
add_executable(particle-sim particle_sim.cpp) | ||
target_link_libraries(particle-sim xdg) | ||
|
||
set(TOOL_NAMES | ||
particle_sim | ||
ray_fire | ||
find_volume | ||
point_in_volume | ||
) | ||
|
||
foreach(tool ${TOOL_NAMES}) | ||
string(REPLACE "_" "-" tool_exec ${tool}) | ||
add_executable(${tool_exec} ${tool}.cpp) | ||
target_link_libraries(${tool_exec} xdg argparse) | ||
endforeach() |
This file contains 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,73 @@ | ||
#include <iostream> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "xdg/error.h" | ||
#include "xdg/mesh_manager_interface.h" | ||
#include "xdg/moab/mesh_manager.h" | ||
#include "xdg/vec3da.h" | ||
#include "xdg/xdg.h" | ||
|
||
#include "argparse/argparse.hpp" | ||
|
||
using namespace xdg; | ||
|
||
int main(int argc, char** argv) { | ||
|
||
argparse::ArgumentParser args("XDG Find Volume Tool", "1.0", argparse::default_arguments::help); | ||
|
||
args.add_argument("filename") | ||
.help("Path to the input file"); | ||
|
||
args.add_argument("-l", "--list") | ||
.default_value(false) | ||
.implicit_value(true) | ||
.help("List all volumes in the file and exit"); | ||
|
||
args.add_argument("-p", "--position") | ||
.default_value(std::vector<double>{0.0, 0.0, 0.0}) | ||
.help("Ray origin").scan<'g', double>().nargs(3); | ||
|
||
args.add_argument("-d", "--direction") | ||
.default_value(std::vector<double>{0.0, 0.0, 1.0}) | ||
.help("Ray direction").scan<'g', double>().nargs(3); | ||
|
||
try { | ||
args.parse_args(argc, argv); | ||
} | ||
catch (const std::runtime_error& err) { | ||
std::cout << err.what() << std::endl; | ||
std::cout << args; | ||
exit(0); | ||
} | ||
|
||
// create a mesh manager | ||
std::shared_ptr<XDG> xdg = XDG::create(MeshLibrary::MOAB); | ||
const auto& mm = xdg->mesh_manager(); | ||
mm->load_file(args.get<std::string>("filename")); | ||
mm->init(); | ||
mm->parse_metadata(); | ||
xdg->prepare_raytracer(); | ||
|
||
if (args.get<bool>("--list")) { | ||
std::cout << "Volumes: " << std::endl; | ||
for (auto volume : mm->volumes()) { | ||
std::cout << volume << std::endl; | ||
} | ||
exit(0); | ||
} | ||
|
||
Position position = args.get<std::vector<double>>("--position"); | ||
Direction direction = args.get<std::vector<double>>("--direction"); | ||
|
||
MeshID volume = xdg->find_volume(position, direction); | ||
|
||
if (volume == ID_NONE) { | ||
std::cout << "No volume found for position " << position << std::endl; | ||
} else { | ||
std::cout << "Point " << position << " is in Volume " << volume << std::endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains 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 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,75 @@ | ||
#include <iostream> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "xdg/error.h" | ||
#include "xdg/mesh_manager_interface.h" | ||
#include "xdg/moab/mesh_manager.h" | ||
#include "xdg/vec3da.h" | ||
#include "xdg/xdg.h" | ||
|
||
#include "argparse/argparse.hpp" | ||
|
||
using namespace xdg; | ||
|
||
int main(int argc, char** argv) { | ||
|
||
argparse::ArgumentParser args("XDG Point in Volume Tool", "1.0", argparse::default_arguments::help); | ||
|
||
args.add_argument("filename") | ||
.help("Path to the input file"); | ||
|
||
args.add_argument("volume") | ||
.help("Volume ID to query").scan<'i', int>(); | ||
|
||
args.add_argument("-l", "--list") | ||
.default_value(false) | ||
.implicit_value(true) | ||
.help("List all volumes in the file and exit"); | ||
|
||
args.add_argument("-p", "--position") | ||
.default_value(std::vector<double>{0.0, 0.0, 0.0}) | ||
.help("Ray origin").scan<'g', double>().nargs(3); | ||
|
||
args.add_argument("-d", "--direction") | ||
.default_value(std::vector<double>{0.0, 0.0, 1.0}) | ||
.help("Ray direction").scan<'g', double>().nargs(3); | ||
|
||
try { | ||
args.parse_args(argc, argv); | ||
} | ||
catch (const std::runtime_error& err) { | ||
std::cout << err.what() << std::endl; | ||
std::cout << args; | ||
exit(0); | ||
} | ||
|
||
// create a mesh manager | ||
std::shared_ptr<XDG> xdg = XDG::create(MeshLibrary::MOAB); | ||
const auto& mm = xdg->mesh_manager(); | ||
mm->load_file(args.get<std::string>("filename")); | ||
mm->init(); | ||
mm->parse_metadata(); | ||
xdg->prepare_raytracer(); | ||
|
||
if (args.get<bool>("--list")) { | ||
std::cout << "Volumes: " << std::endl; | ||
for (auto volume : mm->volumes()) { | ||
std::cout << volume << std::endl; | ||
} | ||
exit(0); | ||
} | ||
|
||
MeshID volume = args.get<int>("volume"); | ||
Position position = args.get<std::vector<double>>("--position"); | ||
Direction direction = args.get<std::vector<double>>("--direction"); | ||
|
||
if (xdg->point_in_volume(volume, position, &direction)) { | ||
std::cout << "Point " << position << " is in Volume " << volume << " (True)" << std::endl; | ||
} else { | ||
std::cout << "Point " << position << " is not in Volume " << volume << " (False)" << std::endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains 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,75 @@ | ||
#include <iostream> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "xdg/error.h" | ||
#include "xdg/mesh_manager_interface.h" | ||
#include "xdg/moab/mesh_manager.h" | ||
#include "xdg/vec3da.h" | ||
#include "xdg/xdg.h" | ||
|
||
#include "argparse/argparse.hpp" | ||
|
||
using namespace xdg; | ||
|
||
int main(int argc, char** argv) { | ||
|
||
argparse::ArgumentParser args("XDG Ray Fire Tool", "1.0", argparse::default_arguments::help); | ||
|
||
args.add_argument("filename") | ||
.help("Path to the input file"); | ||
|
||
args.add_argument("volume") | ||
.help("Volume ID to query").scan<'i', int>(); | ||
|
||
args.add_argument("-l", "--list") | ||
.default_value(false) | ||
.implicit_value(true) | ||
.help("List all volumes in the file and exit"); | ||
|
||
args.add_argument("-o", "-p", "--origin", "--position") | ||
.default_value(std::vector<double>{0.0, 0.0, 0.0}) | ||
.help("Ray origin/position").scan<'g', double>().nargs(3); | ||
|
||
args.add_argument("-d", "--direction") | ||
.default_value(std::vector<double>{0.0, 0.0, 1.0}) | ||
.help("Ray direction").scan<'g', double>().nargs(3); | ||
|
||
try { | ||
args.parse_args(argc, argv); | ||
} | ||
catch (const std::runtime_error& err) { | ||
std::cout << err.what() << std::endl; | ||
std::cout << args; | ||
exit(0); | ||
} | ||
|
||
|
||
// create a mesh manager | ||
std::shared_ptr<XDG> xdg = XDG::create(MeshLibrary::MOAB); | ||
const auto& mm = xdg->mesh_manager(); | ||
mm->load_file(args.get<std::string>("filename")); | ||
mm->init(); | ||
mm->parse_metadata(); | ||
xdg->prepare_raytracer(); | ||
|
||
if (args.get<bool>("--list")) { | ||
std::cout << "Volumes: " << std::endl; | ||
for (auto volume : mm->volumes()) { | ||
std::cout << volume << std::endl; | ||
} | ||
exit(0); | ||
} | ||
|
||
MeshID volume = args.get<int>("volume"); | ||
Position origin = args.get<std::vector<double>>("--origin"); | ||
Direction direction = args.get<std::vector<double>>("--direction"); | ||
|
||
auto result = xdg->ray_fire(volume, origin, direction); | ||
|
||
std::cout << "Distance: " << result.first << std::endl; | ||
std::cout << "Surface: " << result.second << std::endl; | ||
|
||
return 0; | ||
} |