Commit d89e2e20 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[python][sampling] add point samplers for bounding boxes

parent fe9dfdfc
Pipeline #2730 passed with stages
in 9 minutes and 10 seconds
......@@ -24,6 +24,9 @@ class BoxPointSampler:
from frackit.geometry import Point_3
return Point_3(x, y, z)
class BoundingBoxPointSampler(BoxPointSampler):
"""Class to sample random points within a bounding box."""
pass
class CylinderPointSampler:
"""Class to sample random points within a cylinder."""
......@@ -118,6 +121,13 @@ def makePointSampler(geometry,
samplerZ = samplerCreatorBase3(geometry.zMin(), geometry.zMax())
return BoxPointSampler(samplerX, samplerY, samplerZ)
# bounding box point sampler
if geometry.name() == "BoundingBox":
samplerX = samplerCreatorBase1(geometry.xMin(), geometry.xMax())
samplerY = samplerCreatorBase2(geometry.yMin(), geometry.yMax())
samplerZ = samplerCreatorBase3(geometry.zMin(), geometry.zMax())
return BoundingBoxPointSampler(samplerX, samplerY, samplerZ)
# cylinder point sampler
if geometry.name() == "Cylinder":
import math
......@@ -134,7 +144,7 @@ def makePointSampler(geometry,
samplerZ = samplerCreatorBase3(0.0, geometry.height())
return CylinderPointSampler(geometry.fullCylinder(), samplerR2, samplerPhi, samplerZ)
raise NotImplementedError("No point sample creation formula implemented for provided geometry: " + geometry.name())
raise NotImplementedError("No point sampler creation formula implemented for provided geometry: " + geometry.name())
......
......@@ -19,6 +19,7 @@
#include <pybind11/pybind11.h>
#include <frackit/geometry/box.hh>
#include <frackit/geometry/boundingbox.hh>
#include <frackit/geometry/cylinder.hh>
#include <frackit/geometry/hollowcylinder.hh>
#include <frackit/sampling/makeuniformpointsampler.hh>
......@@ -35,6 +36,11 @@ auto makeUniformBoxPointSampler(const Frackit::Box<ctype>& box)
-> decltype(Frackit::makeUniformPointSampler(box))
{ return Frackit::makeUniformPointSampler(box); }
template<class ctype>
auto makeUniformBoundingBoxPointSampler(const Frackit::BoundingBox<ctype>& box)
-> decltype(Frackit::makeUniformPointSampler(box))
{ return Frackit::makeUniformPointSampler(box); }
template<class ctype>
auto makeUniformCylinderPointSampler(const Frackit::Cylinder<ctype>& cylinder)
-> decltype(Frackit::makeUniformPointSampler(cylinder))
......@@ -51,6 +57,8 @@ void registerPointSamplerCreatorFunctions(pybind11::module& module)
using namespace pybind11::literals;
module.def("makeUniformPointSampler", &makeUniformBoxPointSampler<ctype>,
"box"_a, "returns a uniform point sampler on the given box");
module.def("makeUniformPointSampler", &makeUniformBoundingBoxPointSampler<ctype>,
"boundingBox"_a, "returns a uniform point sampler on the given bounding box");
module.def("makeUniformPointSampler", &makeUniformCylinderPointSampler<ctype>,
"cylinder"_a, "returns a uniform point sampler on the given cylinder");
module.def("makeUniformPointSampler", &makeUniformHollowCylinderPointSampler<ctype>,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment